-
+ 042BA62021E6A33FA5F28447D8D268D4FD9A66D49BD10B904AA5F5C9FB6A30345F5CFEA787FBA1145B328F56E77C39E4D7C3D6DF94CCD4B7696B9FE2C8AA7055
mpi/include/longlong.h
(0 . 0)(1 . 224)
1286 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
1287 Note: I added some stuff for use with gnupg
1288
1289 Copyright (C) 1991, 1992, 1993, 1994, 1996, 1998,
1290 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
1291
1292 This file is free software; you can redistribute it and/or modify
1293 it under the terms of the GNU Lesser General Public License as published by
1294 the Free Software Foundation; either version 2.1 of the License, or (at your
1295 option) any later version.
1296
1297 This file is distributed in the hope that it will be useful, but
1298 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1299 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
1300 License for more details.
1301
1302 You should have received a copy of the GNU Lesser General Public License
1303 along with this file; if not, see <http://www.gnu.org/licenses/>. */
1304
1305
1306 /* You have to define the following before including this file:
1307
1308 UWtype -- An unsigned type, default type for operations (typically a "word")
1309 UHWtype -- An unsigned type, at least half the size of UWtype.
1310 UDWtype -- An unsigned type, at least twice as large a UWtype
1311 W_TYPE_SIZE -- size in bits of UWtype
1312
1313 SItype, USItype -- Signed and unsigned 32 bit types.
1314 DItype, UDItype -- Signed and unsigned 64 bit types.
1315
1316 On a 32 bit machine UWtype should typically be USItype;
1317 on a 64 bit machine, UWtype should typically be UDItype.
1318 */
1319
1320 #define __BITS4 (W_TYPE_SIZE / 4)
1321 #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
1322 #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
1323 #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
1324
1325 /* This is used to make sure no undesirable sharing between different libraries
1326 that use this file takes place. */
1327 #ifndef __MPN
1328 #define __MPN(x) __##x
1329 #endif
1330
1331 /***************************************
1332 *********** Generic Versions ********
1333 ***************************************/
1334 #if !defined (umul_ppmm) && defined (__umulsidi3)
1335 #define umul_ppmm(ph, pl, m0, m1) \
1336 { \
1337 UDWtype __ll = __umulsidi3 (m0, m1); \
1338 ph = (UWtype) (__ll >> W_TYPE_SIZE); \
1339 pl = (UWtype) __ll; \
1340 }
1341 #endif
1342
1343 #if !defined (__umulsidi3)
1344 #define __umulsidi3(u, v) \
1345 ({UWtype __hi, __lo; \
1346 umul_ppmm (__hi, __lo, u, v); \
1347 ((UDWtype) __hi << W_TYPE_SIZE) | __lo; })
1348 #endif
1349
1350 /* If this machine has no inline assembler, use C macros. */
1351
1352 #if !defined (add_ssaaaa)
1353 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1354 do { \
1355 UWtype __x; \
1356 __x = (al) + (bl); \
1357 (sh) = (ah) + (bh) + (__x < (al)); \
1358 (sl) = __x; \
1359 } while (0)
1360 #endif
1361
1362 #if !defined (sub_ddmmss)
1363 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1364 do { \
1365 UWtype __x; \
1366 __x = (al) - (bl); \
1367 (sh) = (ah) - (bh) - (__x > (al)); \
1368 (sl) = __x; \
1369 } while (0)
1370 #endif
1371
1372 #if !defined (umul_ppmm)
1373 #define umul_ppmm(w1, w0, u, v) \
1374 do { \
1375 UWtype __x0, __x1, __x2, __x3; \
1376 UHWtype __ul, __vl, __uh, __vh; \
1377 UWtype __u = (u), __v = (v); \
1378 \
1379 __ul = __ll_lowpart (__u); \
1380 __uh = __ll_highpart (__u); \
1381 __vl = __ll_lowpart (__v); \
1382 __vh = __ll_highpart (__v); \
1383 \
1384 __x0 = (UWtype) __ul * __vl; \
1385 __x1 = (UWtype) __ul * __vh; \
1386 __x2 = (UWtype) __uh * __vl; \
1387 __x3 = (UWtype) __uh * __vh; \
1388 \
1389 __x1 += __ll_highpart (__x0);/* this can't give carry */ \
1390 __x1 += __x2; /* but this indeed can */ \
1391 if (__x1 < __x2) /* did we get it? */ \
1392 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
1393 \
1394 (w1) = __x3 + __ll_highpart (__x1); \
1395 (w0) = (__ll_lowpart (__x1) << W_TYPE_SIZE/2) + __ll_lowpart (__x0);\
1396 } while (0)
1397 #endif
1398
1399 #if !defined (umul_ppmm)
1400 #define smul_ppmm(w1, w0, u, v) \
1401 do { \
1402 UWtype __w1; \
1403 UWtype __m0 = (u), __m1 = (v); \
1404 umul_ppmm (__w1, w0, __m0, __m1); \
1405 (w1) = __w1 - (-(__m0 >> (W_TYPE_SIZE - 1)) & __m1) \
1406 - (-(__m1 >> (W_TYPE_SIZE - 1)) & __m0); \
1407 } while (0)
1408 #endif
1409
1410 /* Define this unconditionally, so it can be used for debugging. */
1411 #define __udiv_qrnnd_c(q, r, n1, n0, d) \
1412 do { \
1413 UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \
1414 __d1 = __ll_highpart (d); \
1415 __d0 = __ll_lowpart (d); \
1416 \
1417 __r1 = (n1) % __d1; \
1418 __q1 = (n1) / __d1; \
1419 __m = (UWtype) __q1 * __d0; \
1420 __r1 = __r1 * __ll_B | __ll_highpart (n0); \
1421 if (__r1 < __m) \
1422 { \
1423 __q1--, __r1 += (d); \
1424 if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
1425 if (__r1 < __m) \
1426 __q1--, __r1 += (d); \
1427 } \
1428 __r1 -= __m; \
1429 \
1430 __r0 = __r1 % __d1; \
1431 __q0 = __r1 / __d1; \
1432 __m = (UWtype) __q0 * __d0; \
1433 __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
1434 if (__r0 < __m) \
1435 { \
1436 __q0--, __r0 += (d); \
1437 if (__r0 >= (d)) \
1438 if (__r0 < __m) \
1439 __q0--, __r0 += (d); \
1440 } \
1441 __r0 -= __m; \
1442 \
1443 (q) = (UWtype) __q1 * __ll_B | __q0; \
1444 (r) = __r0; \
1445 } while (0)
1446
1447 /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
1448 __udiv_w_sdiv (defined in libgcc or elsewhere). */
1449 #if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
1450 #define udiv_qrnnd(q, r, nh, nl, d) \
1451 do { \
1452 UWtype __r; \
1453 (q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d); \
1454 (r) = __r; \
1455 } while (0)
1456 #endif
1457
1458 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
1459 #if !defined (udiv_qrnnd)
1460 #define UDIV_NEEDS_NORMALIZATION 1
1461 #define udiv_qrnnd __udiv_qrnnd_c
1462 #endif
1463
1464 #if !defined (count_leading_zeros)
1465 extern
1466 #ifdef __STDC__
1467 const
1468 #endif
1469 unsigned char __clz_tab[];
1470 #define MPI_INTERNAL_NEED_CLZ_TAB 1
1471 #define count_leading_zeros(count, x) \
1472 do { \
1473 UWtype __xr = (x); \
1474 UWtype __a; \
1475 \
1476 if (W_TYPE_SIZE <= 32) \
1477 { \
1478 __a = __xr < ((UWtype) 1 << 2*__BITS4) \
1479 ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \
1480 : (__xr < ((UWtype) 1 << 3*__BITS4) ? 2*__BITS4 : 3*__BITS4);\
1481 } \
1482 else \
1483 { \
1484 for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
1485 if (((__xr >> __a) & 0xff) != 0) \
1486 break; \
1487 } \
1488 \
1489 (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
1490 } while (0)
1491 /* This version gives a well-defined value for zero. */
1492 #define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
1493 #endif
1494
1495 #if !defined (count_trailing_zeros)
1496 /* Define count_trailing_zeros using count_leading_zeros. The latter might be
1497 defined in asm, but if it is not, the C version above is good enough. */
1498 #define count_trailing_zeros(count, x) \
1499 do { \
1500 UWtype __ctz_x = (x); \
1501 UWtype __ctz_c; \
1502 count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x); \
1503 (count) = W_TYPE_SIZE - 1 - __ctz_c; \
1504 } while (0)
1505 #endif
1506
1507 #ifndef UDIV_NEEDS_NORMALIZATION
1508 #define UDIV_NEEDS_NORMALIZATION 0
1509 #endif