-
+ 042BA62021E6A33FA5F28447D8D268D4FD9A66D49BD10B904AA5F5C9FB6A30345F5CFEA787FBA1145B328F56E77C39E4D7C3D6DF94CCD4B7696B9FE2C8AA7055
mpi/include/longlong.h
(0 . 0)(1 . 224)
1182 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
1183 Note: I added some stuff for use with gnupg
1184
1185 Copyright (C) 1991, 1992, 1993, 1994, 1996, 1998,
1186 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
1187
1188 This file is free software; you can redistribute it and/or modify
1189 it under the terms of the GNU Lesser General Public License as published by
1190 the Free Software Foundation; either version 2.1 of the License, or (at your
1191 option) any later version.
1192
1193 This file is distributed in the hope that it will be useful, but
1194 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1195 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
1196 License for more details.
1197
1198 You should have received a copy of the GNU Lesser General Public License
1199 along with this file; if not, see <http://www.gnu.org/licenses/>. */
1200
1201
1202 /* You have to define the following before including this file:
1203
1204 UWtype -- An unsigned type, default type for operations (typically a "word")
1205 UHWtype -- An unsigned type, at least half the size of UWtype.
1206 UDWtype -- An unsigned type, at least twice as large a UWtype
1207 W_TYPE_SIZE -- size in bits of UWtype
1208
1209 SItype, USItype -- Signed and unsigned 32 bit types.
1210 DItype, UDItype -- Signed and unsigned 64 bit types.
1211
1212 On a 32 bit machine UWtype should typically be USItype;
1213 on a 64 bit machine, UWtype should typically be UDItype.
1214 */
1215
1216 #define __BITS4 (W_TYPE_SIZE / 4)
1217 #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
1218 #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
1219 #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
1220
1221 /* This is used to make sure no undesirable sharing between different libraries
1222 that use this file takes place. */
1223 #ifndef __MPN
1224 #define __MPN(x) __##x
1225 #endif
1226
1227 /***************************************
1228 *********** Generic Versions ********
1229 ***************************************/
1230 #if !defined (umul_ppmm) && defined (__umulsidi3)
1231 #define umul_ppmm(ph, pl, m0, m1) \
1232 { \
1233 UDWtype __ll = __umulsidi3 (m0, m1); \
1234 ph = (UWtype) (__ll >> W_TYPE_SIZE); \
1235 pl = (UWtype) __ll; \
1236 }
1237 #endif
1238
1239 #if !defined (__umulsidi3)
1240 #define __umulsidi3(u, v) \
1241 ({UWtype __hi, __lo; \
1242 umul_ppmm (__hi, __lo, u, v); \
1243 ((UDWtype) __hi << W_TYPE_SIZE) | __lo; })
1244 #endif
1245
1246 /* If this machine has no inline assembler, use C macros. */
1247
1248 #if !defined (add_ssaaaa)
1249 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1250 do { \
1251 UWtype __x; \
1252 __x = (al) + (bl); \
1253 (sh) = (ah) + (bh) + (__x < (al)); \
1254 (sl) = __x; \
1255 } while (0)
1256 #endif
1257
1258 #if !defined (sub_ddmmss)
1259 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1260 do { \
1261 UWtype __x; \
1262 __x = (al) - (bl); \
1263 (sh) = (ah) - (bh) - (__x > (al)); \
1264 (sl) = __x; \
1265 } while (0)
1266 #endif
1267
1268 #if !defined (umul_ppmm)
1269 #define umul_ppmm(w1, w0, u, v) \
1270 do { \
1271 UWtype __x0, __x1, __x2, __x3; \
1272 UHWtype __ul, __vl, __uh, __vh; \
1273 UWtype __u = (u), __v = (v); \
1274 \
1275 __ul = __ll_lowpart (__u); \
1276 __uh = __ll_highpart (__u); \
1277 __vl = __ll_lowpart (__v); \
1278 __vh = __ll_highpart (__v); \
1279 \
1280 __x0 = (UWtype) __ul * __vl; \
1281 __x1 = (UWtype) __ul * __vh; \
1282 __x2 = (UWtype) __uh * __vl; \
1283 __x3 = (UWtype) __uh * __vh; \
1284 \
1285 __x1 += __ll_highpart (__x0);/* this can't give carry */ \
1286 __x1 += __x2; /* but this indeed can */ \
1287 if (__x1 < __x2) /* did we get it? */ \
1288 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
1289 \
1290 (w1) = __x3 + __ll_highpart (__x1); \
1291 (w0) = (__ll_lowpart (__x1) << W_TYPE_SIZE/2) + __ll_lowpart (__x0);\
1292 } while (0)
1293 #endif
1294
1295 #if !defined (umul_ppmm)
1296 #define smul_ppmm(w1, w0, u, v) \
1297 do { \
1298 UWtype __w1; \
1299 UWtype __m0 = (u), __m1 = (v); \
1300 umul_ppmm (__w1, w0, __m0, __m1); \
1301 (w1) = __w1 - (-(__m0 >> (W_TYPE_SIZE - 1)) & __m1) \
1302 - (-(__m1 >> (W_TYPE_SIZE - 1)) & __m0); \
1303 } while (0)
1304 #endif
1305
1306 /* Define this unconditionally, so it can be used for debugging. */
1307 #define __udiv_qrnnd_c(q, r, n1, n0, d) \
1308 do { \
1309 UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \
1310 __d1 = __ll_highpart (d); \
1311 __d0 = __ll_lowpart (d); \
1312 \
1313 __r1 = (n1) % __d1; \
1314 __q1 = (n1) / __d1; \
1315 __m = (UWtype) __q1 * __d0; \
1316 __r1 = __r1 * __ll_B | __ll_highpart (n0); \
1317 if (__r1 < __m) \
1318 { \
1319 __q1--, __r1 += (d); \
1320 if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
1321 if (__r1 < __m) \
1322 __q1--, __r1 += (d); \
1323 } \
1324 __r1 -= __m; \
1325 \
1326 __r0 = __r1 % __d1; \
1327 __q0 = __r1 / __d1; \
1328 __m = (UWtype) __q0 * __d0; \
1329 __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
1330 if (__r0 < __m) \
1331 { \
1332 __q0--, __r0 += (d); \
1333 if (__r0 >= (d)) \
1334 if (__r0 < __m) \
1335 __q0--, __r0 += (d); \
1336 } \
1337 __r0 -= __m; \
1338 \
1339 (q) = (UWtype) __q1 * __ll_B | __q0; \
1340 (r) = __r0; \
1341 } while (0)
1342
1343 /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
1344 __udiv_w_sdiv (defined in libgcc or elsewhere). */
1345 #if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
1346 #define udiv_qrnnd(q, r, nh, nl, d) \
1347 do { \
1348 UWtype __r; \
1349 (q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d); \
1350 (r) = __r; \
1351 } while (0)
1352 #endif
1353
1354 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
1355 #if !defined (udiv_qrnnd)
1356 #define UDIV_NEEDS_NORMALIZATION 1
1357 #define udiv_qrnnd __udiv_qrnnd_c
1358 #endif
1359
1360 #if !defined (count_leading_zeros)
1361 extern
1362 #ifdef __STDC__
1363 const
1364 #endif
1365 unsigned char __clz_tab[];
1366 #define MPI_INTERNAL_NEED_CLZ_TAB 1
1367 #define count_leading_zeros(count, x) \
1368 do { \
1369 UWtype __xr = (x); \
1370 UWtype __a; \
1371 \
1372 if (W_TYPE_SIZE <= 32) \
1373 { \
1374 __a = __xr < ((UWtype) 1 << 2*__BITS4) \
1375 ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \
1376 : (__xr < ((UWtype) 1 << 3*__BITS4) ? 2*__BITS4 : 3*__BITS4);\
1377 } \
1378 else \
1379 { \
1380 for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
1381 if (((__xr >> __a) & 0xff) != 0) \
1382 break; \
1383 } \
1384 \
1385 (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
1386 } while (0)
1387 /* This version gives a well-defined value for zero. */
1388 #define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
1389 #endif
1390
1391 #if !defined (count_trailing_zeros)
1392 /* Define count_trailing_zeros using count_leading_zeros. The latter might be
1393 defined in asm, but if it is not, the C version above is good enough. */
1394 #define count_trailing_zeros(count, x) \
1395 do { \
1396 UWtype __ctz_x = (x); \
1397 UWtype __ctz_c; \
1398 count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x); \
1399 (count) = W_TYPE_SIZE - 1 - __ctz_c; \
1400 } while (0)
1401 #endif
1402
1403 #ifndef UDIV_NEEDS_NORMALIZATION
1404 #define UDIV_NEEDS_NORMALIZATION 0
1405 #endif