1 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
3 Copyright 1991-2013 Free Software Foundation, Inc.
5 This file is free software; you can redistribute it and/or modify it under the
6 terms of the GNU Lesser General Public License as published by the Free
7 Software Foundation; either version 3 of the License, or (at your option) any
10 This file is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12 PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 You should have received a copy of the GNU Lesser General Public License
16 along with this file. If not, see http://www.gnu.org/licenses/. */
18 /* You have to define the following before including this file:
20 UWtype -- An unsigned type, default type for operations (typically a "word")
21 UHWtype -- An unsigned type, at least half the size of UWtype
22 UDWtype -- An unsigned type, at least twice as large a UWtype
23 W_TYPE_SIZE -- size in bits of UWtype
25 SItype, USItype -- Signed and unsigned 32 bit types
26 DItype, UDItype -- Signed and unsigned 64 bit types
28 On a 32 bit machine UWtype should typically be USItype;
29 on a 64 bit machine, UWtype should typically be UDItype.
33 LONGLONG_STANDALONE -- Avoid code that needs machine-dependent support files
34 NO_ASM -- Disable inline asm
37 CAUTION! Using this version of longlong.h outside of GMP is not safe. You
38 need to include gmp.h and gmp-impl.h, or certain things might not work as
42 #define __BITS4 (W_TYPE_SIZE / 4)
43 #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
44 #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
45 #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
47 /* This is used to make sure no undesirable sharing between different libraries
48 that use this file takes place. */
50 #define __MPN(x) __##x
53 /* Define auxiliary asm macros.
55 1) umul_ppmm(high_prod, low_prod, multiplier, multiplicand) multiplies two
56 UWtype integers MULTIPLIER and MULTIPLICAND, and generates a two UWtype
57 word product in HIGH_PROD and LOW_PROD.
59 2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a
60 UDWtype product. This is just a variant of umul_ppmm.
62 3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
63 denominator) divides a UDWtype, composed by the UWtype integers
64 HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
65 in QUOTIENT and the remainder in REMAINDER. HIGH_NUMERATOR must be less
66 than DENOMINATOR for correct operation. If, in addition, the most
67 significant bit of DENOMINATOR must be 1, then the pre-processor symbol
68 UDIV_NEEDS_NORMALIZATION is defined to 1.
70 4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
71 denominator). Like udiv_qrnnd but the numbers are signed. The quotient
74 5) count_leading_zeros(count, x) counts the number of zero-bits from the
75 msb to the first non-zero bit in the UWtype X. This is the number of
76 steps X needs to be shifted left to set the msb. Undefined for X == 0,
77 unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.
79 6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
80 from the least significant end.
82 7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
83 high_addend_2, low_addend_2) adds two UWtype integers, composed by
84 HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2
85 respectively. The result is placed in HIGH_SUM and LOW_SUM. Overflow
86 (i.e. carry out) is not stored anywhere, and is lost.
88 8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend,
89 high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers,
90 composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and
91 LOW_SUBTRAHEND_2 respectively. The result is placed in HIGH_DIFFERENCE
92 and LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere,
95 If any of these macros are left undefined for a particular CPU,
101 For add_ssaaaa the two high and two low addends can both commute, but
102 unfortunately gcc only supports one "%" commutative in each asm block.
103 This has always been so but is only documented in recent versions
104 (eg. pre-release 3.3). Having two or more "%"s can cause an internal
105 compiler error in certain rare circumstances.
107 Apparently it was only the last "%" that was ever actually respected, so
108 the code has been updated to leave just that. Clearly there's a free
109 choice whether high or low should get it, if there's a reason to favour
110 one over the other. Also obviously when the constraints on the two
111 operands are identical there's no benefit to the reloader in any "%" at
116 /* The CPUs come in alphabetical order below.
118 Please add support for more CPUs here, or improve the current support
119 for the CPUs below! */
122 /* count_leading_zeros_gcc_clz is count_leading_zeros implemented with gcc
123 3.4 __builtin_clzl or __builtin_clzll, according to our limb size.
124 Similarly count_trailing_zeros_gcc_ctz using __builtin_ctzl or
127 These builtins are only used when we check what code comes out, on some
128 chips they're merely libgcc calls, where we will instead want an inline
129 in that case (either asm or generic C).
131 These builtins are better than an asm block of the same insn, since an
132 asm block doesn't give gcc any information about scheduling or resource
133 usage. We keep an asm block for use on prior versions of gcc though.
135 For reference, __builtin_ffs existed in gcc prior to __builtin_clz, but
136 it's not used (for count_leading_zeros) because it generally gives extra
137 code to ensure the result is 0 when the input is 0, which we don't need
140 #ifdef _LONG_LONG_LIMB
141 #define count_leading_zeros_gcc_clz(count,x) \
144 (count) = __builtin_clzll (x); \
147 #define count_leading_zeros_gcc_clz(count,x) \
150 (count) = __builtin_clzl (x); \
154 #ifdef _LONG_LONG_LIMB
155 #define count_trailing_zeros_gcc_ctz(count,x) \
158 (count) = __builtin_ctzll (x); \
161 #define count_trailing_zeros_gcc_ctz(count,x) \
164 (count) = __builtin_ctzl (x); \
169 /* FIXME: The macros using external routines like __MPN(count_leading_zeros)
170 don't need to be under !NO_ASM */
171 #if ! defined (NO_ASM)
173 #if defined (__alpha) && W_TYPE_SIZE == 64
174 /* Most alpha-based machines, except Cray systems. */
175 #if defined (__GNUC__)
176 #if __GMP_GNUC_PREREQ (3,3)
177 #define umul_ppmm(ph, pl, m0, m1) \
179 UDItype __m0 = (m0), __m1 = (m1); \
180 (ph) = __builtin_alpha_umulh (__m0, __m1); \
181 (pl) = __m0 * __m1; \
184 #define umul_ppmm(ph, pl, m0, m1) \
186 UDItype __m0 = (m0), __m1 = (m1); \
187 __asm__ ("umulh %r1,%2,%0" \
189 : "%rJ" (m0), "rI" (m1)); \
190 (pl) = __m0 * __m1; \
194 #else /* ! __GNUC__ */
195 #include <machine/builtins.h>
196 #define umul_ppmm(ph, pl, m0, m1) \
198 UDItype __m0 = (m0), __m1 = (m1); \
199 (ph) = __UMULH (m0, m1); \
200 (pl) = __m0 * __m1; \
203 #ifndef LONGLONG_STANDALONE
204 #define udiv_qrnnd(q, r, n1, n0, d) \
206 __di = __MPN(invert_limb) (d); \
207 udiv_qrnnd_preinv (q, r, n1, n0, d, __di); \
209 #define UDIV_PREINV_ALWAYS 1
210 #define UDIV_NEEDS_NORMALIZATION 1
211 #define UDIV_TIME 220
212 #endif /* LONGLONG_STANDALONE */
214 /* clz_tab is required in all configurations, since mpn/alpha/cntlz.asm
215 always goes into libgmp.so, even when not actually used. */
216 #define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
218 #if defined (__GNUC__) && HAVE_HOST_CPU_alpha_CIX
219 #define count_leading_zeros(COUNT,X) \
220 __asm__("ctlz %1,%0" : "=r"(COUNT) : "r"(X))
221 #define count_trailing_zeros(COUNT,X) \
222 __asm__("cttz %1,%0" : "=r"(COUNT) : "r"(X))
223 #endif /* clz/ctz using cix */
225 #if ! defined (count_leading_zeros) \
226 && defined (__GNUC__) && ! defined (LONGLONG_STANDALONE)
227 /* ALPHA_CMPBGE_0 gives "cmpbge $31,src,dst", ie. test src bytes == 0.
228 "$31" is written explicitly in the asm, since an "r" constraint won't
229 select reg 31. There seems no need to worry about "r31" syntax for cray,
230 since gcc itself (pre-release 3.4) emits just $31 in various places. */
231 #define ALPHA_CMPBGE_0(dst, src) \
232 do { asm ("cmpbge $31, %1, %0" : "=r" (dst) : "r" (src)); } while (0)
233 /* Zero bytes are turned into bits with cmpbge, a __clz_tab lookup counts
234 them, locating the highest non-zero byte. A second __clz_tab lookup
235 counts the leading zero bits in that byte, giving the result. */
236 #define count_leading_zeros(count, x) \
238 UWtype __clz__b, __clz__c, __clz__x = (x); \
239 ALPHA_CMPBGE_0 (__clz__b, __clz__x); /* zero bytes */ \
240 __clz__b = __clz_tab [(__clz__b >> 1) ^ 0x7F]; /* 8 to 1 byte */ \
241 __clz__b = __clz__b * 8 - 7; /* 57 to 1 shift */ \
242 __clz__x >>= __clz__b; \
243 __clz__c = __clz_tab [__clz__x]; /* 8 to 1 bit */ \
244 __clz__b = 65 - __clz__b; \
245 (count) = __clz__b - __clz__c; \
247 #define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
248 #endif /* clz using cmpbge */
250 #if ! defined (count_leading_zeros) && ! defined (LONGLONG_STANDALONE)
251 #if HAVE_ATTRIBUTE_CONST
252 long __MPN(count_leading_zeros
) (UDItype
) __attribute__ ((const));
254 long __MPN(count_leading_zeros
) (UDItype
);
256 #define count_leading_zeros(count, x) \
257 ((count) = __MPN(count_leading_zeros) (x))
258 #endif /* clz using mpn */
261 #if defined (__AVR) && W_TYPE_SIZE == 8
262 #define umul_ppmm(ph, pl, m0, m1) \
264 unsigned short __p = (unsigned short) (m0) * (m1); \
270 #if defined (_CRAY) && W_TYPE_SIZE == 64
271 #include <intrinsics.h>
272 #define UDIV_PREINV_ALWAYS 1
273 #define UDIV_NEEDS_NORMALIZATION 1
274 #define UDIV_TIME 220
275 long __MPN(count_leading_zeros
) (UDItype
);
276 #define count_leading_zeros(count, x) \
277 ((count) = _leadz ((UWtype) (x)))
278 #if defined (_CRAYIEEE) /* I.e., Cray T90/ieee, T3D, and T3E */
279 #define umul_ppmm(ph, pl, m0, m1) \
281 UDItype __m0 = (m0), __m1 = (m1); \
282 (ph) = _int_mult_upper (m0, m1); \
283 (pl) = __m0 * __m1; \
285 #ifndef LONGLONG_STANDALONE
286 #define udiv_qrnnd(q, r, n1, n0, d) \
288 __di = __MPN(invert_limb) (d); \
289 udiv_qrnnd_preinv (q, r, n1, n0, d, __di); \
291 #endif /* LONGLONG_STANDALONE */
292 #endif /* _CRAYIEEE */
295 #if defined (__ia64) && W_TYPE_SIZE == 64
296 /* This form encourages gcc (pre-release 3.4 at least) to emit predicated
297 "sub r=r,r" and "sub r=r,r,1", giving a 2 cycle latency. The generic
298 code using "al<bl" arithmetically comes out making an actual 0 or 1 in a
299 register, which takes an extra cycle. */
300 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
305 (sh) = (ah) - (bh) - 1; \
307 (sh) = (ah) - (bh); \
310 #if defined (__GNUC__) && ! defined (__INTEL_COMPILER)
311 /* Do both product parts in assembly, since that gives better code with
312 all gcc versions. Some callers will just use the upper part, and in
313 that situation we waste an instruction, but not any cycles. */
314 #define umul_ppmm(ph, pl, m0, m1) \
315 __asm__ ("xma.hu %0 = %2, %3, f0\n\txma.l %1 = %2, %3, f0" \
316 : "=&f" (ph), "=f" (pl) \
317 : "f" (m0), "f" (m1))
319 #define count_leading_zeros(count, x) \
321 UWtype _x = (x), _y, _a, _c; \
322 __asm__ ("mux1 %0 = %1, @rev" : "=r" (_y) : "r" (_x)); \
323 __asm__ ("czx1.l %0 = %1" : "=r" (_a) : "r" (-_y | _y)); \
324 _c = (_a - 1) << 3; \
331 (count) = W_TYPE_SIZE - 1 - _c; \
333 /* similar to what gcc does for __builtin_ffs, but 0 based rather than 1
334 based, and we don't need a special case for x==0 here */
335 #define count_trailing_zeros(count, x) \
337 UWtype __ctz_x = (x); \
338 __asm__ ("popcnt %0 = %1" \
340 : "r" ((__ctz_x-1) & ~__ctz_x)); \
343 #if defined (__INTEL_COMPILER)
344 #include <ia64intrin.h>
345 #define umul_ppmm(ph, pl, m0, m1) \
347 UWtype _m0 = (m0), _m1 = (m1); \
348 ph = _m64_xmahu (_m0, _m1, 0); \
352 #ifndef LONGLONG_STANDALONE
353 #define udiv_qrnnd(q, r, n1, n0, d) \
355 __di = __MPN(invert_limb) (d); \
356 udiv_qrnnd_preinv (q, r, n1, n0, d, __di); \
358 #define UDIV_PREINV_ALWAYS 1
359 #define UDIV_NEEDS_NORMALIZATION 1
361 #define UDIV_TIME 220
365 #if defined (__GNUC__)
367 /* We sometimes need to clobber "cc" with gcc2, but that would not be
368 understood by gcc1. Use cpp to avoid major code duplication. */
371 #define __AND_CLOBBER_CC
372 #else /* __GNUC__ >= 2 */
373 #define __CLOBBER_CC : "cc"
374 #define __AND_CLOBBER_CC , "cc"
375 #endif /* __GNUC__ < 2 */
377 #if (defined (__a29k__) || defined (_AM29K)) && W_TYPE_SIZE == 32
378 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
379 __asm__ ("add %1,%4,%5\n\taddc %0,%2,%3" \
380 : "=r" (sh), "=&r" (sl) \
381 : "r" (ah), "rI" (bh), "%r" (al), "rI" (bl))
382 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
383 __asm__ ("sub %1,%4,%5\n\tsubc %0,%2,%3" \
384 : "=r" (sh), "=&r" (sl) \
385 : "r" (ah), "rI" (bh), "r" (al), "rI" (bl))
386 #define umul_ppmm(xh, xl, m0, m1) \
388 USItype __m0 = (m0), __m1 = (m1); \
389 __asm__ ("multiplu %0,%1,%2" \
391 : "r" (__m0), "r" (__m1)); \
392 __asm__ ("multmu %0,%1,%2" \
394 : "r" (__m0), "r" (__m1)); \
396 #define udiv_qrnnd(q, r, n1, n0, d) \
397 __asm__ ("dividu %0,%3,%4" \
398 : "=r" (q), "=q" (r) \
399 : "1" (n1), "r" (n0), "r" (d))
400 #define count_leading_zeros(count, x) \
401 __asm__ ("clz %0,%1" \
404 #define COUNT_LEADING_ZEROS_0 32
405 #endif /* __a29k__ */
407 #if defined (__arc__)
408 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
409 __asm__ ("add.f\t%1, %4, %5\n\tadc\t%0, %2, %3" \
412 : "r" ((USItype) (ah)), \
413 "rIJ" ((USItype) (bh)), \
414 "%r" ((USItype) (al)), \
415 "rIJ" ((USItype) (bl)))
416 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
417 __asm__ ("sub.f\t%1, %4, %5\n\tsbc\t%0, %2, %3" \
420 : "r" ((USItype) (ah)), \
421 "rIJ" ((USItype) (bh)), \
422 "r" ((USItype) (al)), \
423 "rIJ" ((USItype) (bl)))
426 #if defined (__arm__) && W_TYPE_SIZE == 32
427 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
428 __asm__ ("adds\t%1, %4, %5\n\tadc\t%0, %2, %3" \
429 : "=r" (sh), "=&r" (sl) \
430 : "r" (ah), "rI" (bh), "%r" (al), "rI" (bl) __CLOBBER_CC)
431 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
433 if (__builtin_constant_p (al)) \
435 if (__builtin_constant_p (ah)) \
436 __asm__ ("rsbs\t%1, %5, %4\n\trsc\t%0, %3, %2" \
437 : "=r" (sh), "=&r" (sl) \
438 : "rI" (ah), "r" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
440 __asm__ ("rsbs\t%1, %5, %4\n\tsbc\t%0, %2, %3" \
441 : "=r" (sh), "=&r" (sl) \
442 : "r" (ah), "rI" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
444 else if (__builtin_constant_p (ah)) \
446 if (__builtin_constant_p (bl)) \
447 __asm__ ("subs\t%1, %4, %5\n\trsc\t%0, %3, %2" \
448 : "=r" (sh), "=&r" (sl) \
449 : "rI" (ah), "r" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
451 __asm__ ("rsbs\t%1, %5, %4\n\trsc\t%0, %3, %2" \
452 : "=r" (sh), "=&r" (sl) \
453 : "rI" (ah), "r" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
455 else if (__builtin_constant_p (bl)) \
457 if (__builtin_constant_p (bh)) \
458 __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3" \
459 : "=r" (sh), "=&r" (sl) \
460 : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
462 __asm__ ("subs\t%1, %4, %5\n\trsc\t%0, %3, %2" \
463 : "=r" (sh), "=&r" (sl) \
464 : "rI" (ah), "r" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
466 else /* only bh might be a constant */ \
467 __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3" \
468 : "=r" (sh), "=&r" (sl) \
469 : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC);\
471 #if 1 || defined (__arm_m__) /* `M' series has widening multiply support */
472 #define umul_ppmm(xh, xl, a, b) \
473 __asm__ ("umull %0,%1,%2,%3" : "=&r" (xl), "=&r" (xh) : "r" (a), "r" (b))
475 #define smul_ppmm(xh, xl, a, b) \
476 __asm__ ("smull %0,%1,%2,%3" : "=&r" (xl), "=&r" (xh) : "r" (a), "r" (b))
477 #ifndef LONGLONG_STANDALONE
478 #define udiv_qrnnd(q, r, n1, n0, d) \
480 __di = __MPN(invert_limb) (d); \
481 udiv_qrnnd_preinv (q, r, n1, n0, d, __di); \
483 #define UDIV_PREINV_ALWAYS 1
484 #define UDIV_NEEDS_NORMALIZATION 1
486 #endif /* LONGLONG_STANDALONE */
488 #define umul_ppmm(xh, xl, a, b) \
489 __asm__ ("%@ Inlined umul_ppmm\n" \
490 " mov %|r0, %2, lsr #16\n" \
491 " mov %|r2, %3, lsr #16\n" \
492 " bic %|r1, %2, %|r0, lsl #16\n" \
493 " bic %|r2, %3, %|r2, lsl #16\n" \
494 " mul %1, %|r1, %|r2\n" \
495 " mul %|r2, %|r0, %|r2\n" \
496 " mul %|r1, %0, %|r1\n" \
497 " mul %0, %|r0, %0\n" \
498 " adds %|r1, %|r2, %|r1\n" \
499 " addcs %0, %0, #65536\n" \
500 " adds %1, %1, %|r1, lsl #16\n" \
501 " adc %0, %0, %|r1, lsr #16" \
502 : "=&r" (xh), "=r" (xl) \
506 #ifndef LONGLONG_STANDALONE
507 #define udiv_qrnnd(q, r, n1, n0, d) \
509 (q) = __MPN(udiv_qrnnd) (&__r, (n1), (n0), (d)); \
512 extern UWtype
__MPN(udiv_qrnnd
) (UWtype
*, UWtype
, UWtype
, UWtype
);
513 #define UDIV_TIME 200
514 #endif /* LONGLONG_STANDALONE */
516 /* This is a bizarre test, but GCC doesn't define useful common symbol. */
517 #if defined (__ARM_ARCH_5__) || defined (__ARM_ARCH_5T__) || \
518 defined (__ARM_ARCH_5E__) || defined (__ARM_ARCH_5TE__)|| \
519 defined (__ARM_ARCH_6__) || defined (__ARM_ARCH_6J__) || \
520 defined (__ARM_ARCH_6K__) || defined (__ARM_ARCH_6Z__) || \
521 defined (__ARM_ARCH_6ZK__)|| defined (__ARM_ARCH_6T2__)|| \
522 defined (__ARM_ARCH_6M__) || defined (__ARM_ARCH_7__) || \
523 defined (__ARM_ARCH_7A__) || defined (__ARM_ARCH_7R__) || \
524 defined (__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__)
525 #define count_leading_zeros(count, x) \
526 __asm__ ("clz\t%0, %1" : "=r" (count) : "r" (x))
527 #define COUNT_LEADING_ZEROS_0 32
531 #if defined (__aarch64__) && W_TYPE_SIZE == 64
532 /* FIXME: Extend the immediate range for the low word by using both
533 ADDS and SUBS, since they set carry in the same way. */
534 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
535 __asm__ ("adds\t%1, %x4, %5\n\tadc\t%0, %x2, %x3" \
536 : "=r" (sh), "=&r" (sl) \
537 : "rZ" (ah), "rZ" (bh), "%r" (al), "rI" (bl) __CLOBBER_CC)
538 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
539 __asm__ ("subs\t%1, %x4, %5\n\tsbc\t%0, %x2, %x3" \
540 : "=r,r" (sh), "=&r,&r" (sl) \
541 : "rZ,rZ" (ah), "rZ,rZ" (bh), "r,Z" (al), "rI,r" (bl) __CLOBBER_CC)
542 #define umul_ppmm(ph, pl, m0, m1) \
544 UDItype __m0 = (m0), __m1 = (m1); \
545 __asm__ ("umulh\t%0, %1, %2" : "=r" (ph) : "r" (m0), "r" (m1)); \
546 (pl) = __m0 * __m1; \
548 #define count_leading_zeros(count, x) \
549 __asm__ ("clz\t%0, %1" : "=r" (count) : "r" (x))
550 #define COUNT_LEADING_ZEROS_0 64
551 #endif /* __aarch64__ */
553 #if defined (__clipper__) && W_TYPE_SIZE == 32
554 #define umul_ppmm(w1, w0, u, v) \
555 ({union {UDItype __ll; \
556 struct {USItype __l, __h;} __i; \
558 __asm__ ("mulwux %2,%0" \
560 : "%0" ((USItype)(u)), "r" ((USItype)(v))); \
561 (w1) = __x.__i.__h; (w0) = __x.__i.__l;})
562 #define smul_ppmm(w1, w0, u, v) \
563 ({union {DItype __ll; \
564 struct {SItype __l, __h;} __i; \
566 __asm__ ("mulwx %2,%0" \
568 : "%0" ((SItype)(u)), "r" ((SItype)(v))); \
569 (w1) = __x.__i.__h; (w0) = __x.__i.__l;})
570 #define __umulsidi3(u, v) \
572 __asm__ ("mulwux %2,%0" \
573 : "=r" (__w) : "%0" ((USItype)(u)), "r" ((USItype)(v))); \
575 #endif /* __clipper__ */
577 /* Fujitsu vector computers. */
578 #if defined (__uxp__) && W_TYPE_SIZE == 32
579 #define umul_ppmm(ph, pl, u, v) \
581 union {UDItype __ll; \
582 struct {USItype __h, __l;} __i; \
584 __asm__ ("mult.lu %1,%2,%0" : "=r" (__x.__ll) : "%r" (u), "rK" (v));\
585 (ph) = __x.__i.__h; \
586 (pl) = __x.__i.__l; \
588 #define smul_ppmm(ph, pl, u, v) \
590 union {UDItype __ll; \
591 struct {USItype __h, __l;} __i; \
593 __asm__ ("mult.l %1,%2,%0" : "=r" (__x.__ll) : "%r" (u), "rK" (v)); \
594 (ph) = __x.__i.__h; \
595 (pl) = __x.__i.__l; \
599 #if defined (__gmicro__) && W_TYPE_SIZE == 32
600 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
601 __asm__ ("add.w %5,%1\n\taddx %3,%0" \
602 : "=g" (sh), "=&g" (sl) \
603 : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \
604 "%1" ((USItype)(al)), "g" ((USItype)(bl)))
605 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
606 __asm__ ("sub.w %5,%1\n\tsubx %3,%0" \
607 : "=g" (sh), "=&g" (sl) \
608 : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \
609 "1" ((USItype)(al)), "g" ((USItype)(bl)))
610 #define umul_ppmm(ph, pl, m0, m1) \
611 __asm__ ("mulx %3,%0,%1" \
612 : "=g" (ph), "=r" (pl) \
613 : "%0" ((USItype)(m0)), "g" ((USItype)(m1)))
614 #define udiv_qrnnd(q, r, nh, nl, d) \
615 __asm__ ("divx %4,%0,%1" \
616 : "=g" (q), "=r" (r) \
617 : "1" ((USItype)(nh)), "0" ((USItype)(nl)), "g" ((USItype)(d)))
618 #define count_leading_zeros(count, x) \
619 __asm__ ("bsch/1 %1,%0" \
620 : "=g" (count) : "g" ((USItype)(x)), "0" ((USItype)0))
623 #if defined (__hppa) && W_TYPE_SIZE == 32
624 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
625 __asm__ ("add%I5 %5,%r4,%1\n\taddc %r2,%r3,%0" \
626 : "=r" (sh), "=&r" (sl) \
627 : "rM" (ah), "rM" (bh), "%rM" (al), "rI" (bl))
628 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
629 __asm__ ("sub%I4 %4,%r5,%1\n\tsubb %r2,%r3,%0" \
630 : "=r" (sh), "=&r" (sl) \
631 : "rM" (ah), "rM" (bh), "rI" (al), "rM" (bl))
632 #if defined (_PA_RISC1_1)
633 #define umul_ppmm(wh, wl, u, v) \
635 union {UDItype __ll; \
636 struct {USItype __h, __l;} __i; \
638 __asm__ ("xmpyu %1,%2,%0" : "=*f" (__x.__ll) : "*f" (u), "*f" (v)); \
639 (wh) = __x.__i.__h; \
640 (wl) = __x.__i.__l; \
648 #define count_leading_zeros(count, x) \
653 " extru,= %1,15,16,%%r0 ; Bits 31..16 zero?\n" \
654 " extru,tr %1,15,16,%1 ; No. Shift down, skip add.\n" \
655 " ldo 16(%0),%0 ; Yes. Perform add.\n" \
656 " extru,= %1,23,8,%%r0 ; Bits 15..8 zero?\n" \
657 " extru,tr %1,23,8,%1 ; No. Shift down, skip add.\n" \
658 " ldo 8(%0),%0 ; Yes. Perform add.\n" \
659 " extru,= %1,27,4,%%r0 ; Bits 7..4 zero?\n" \
660 " extru,tr %1,27,4,%1 ; No. Shift down, skip add.\n" \
661 " ldo 4(%0),%0 ; Yes. Perform add.\n" \
662 " extru,= %1,29,2,%%r0 ; Bits 3..2 zero?\n" \
663 " extru,tr %1,29,2,%1 ; No. Shift down, skip add.\n" \
664 " ldo 2(%0),%0 ; Yes. Perform add.\n" \
665 " extru %1,30,1,%1 ; Extract bit 1.\n" \
666 " sub %0,%1,%0 ; Subtract it.\n" \
667 : "=r" (count), "=r" (__tmp) : "1" (x)); \
671 /* These macros are for ABI=2.0w. In ABI=2.0n they can't be used, since GCC
672 (3.2) puts longlong into two adjacent 32-bit registers. Presumably this
673 is just a case of no direct support for 2.0n but treating it like 1.0. */
674 #if defined (__hppa) && W_TYPE_SIZE == 64 && ! defined (_LONG_LONG_LIMB)
675 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
676 __asm__ ("add%I5 %5,%r4,%1\n\tadd,dc %r2,%r3,%0" \
677 : "=r" (sh), "=&r" (sl) \
678 : "rM" (ah), "rM" (bh), "%rM" (al), "rI" (bl))
679 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
680 __asm__ ("sub%I4 %4,%r5,%1\n\tsub,db %r2,%r3,%0" \
681 : "=r" (sh), "=&r" (sl) \
682 : "rM" (ah), "rM" (bh), "rI" (al), "rM" (bl))
685 #if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_TYPE_SIZE == 32
686 #if defined (__zarch__) || defined (HAVE_HOST_CPU_s390_zarch)
687 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
689 /* if (__builtin_constant_p (bl)) \
690 __asm__ ("alfi\t%1,%o5\n\talcr\t%0,%3" \
691 : "=r" (sh), "=&r" (sl) \
692 : "0" (ah), "r" (bh), "%1" (al), "n" (bl) __CLOBBER_CC);\
694 */ __asm__ ("alr\t%1,%5\n\talcr\t%0,%3" \
695 : "=r" (sh), "=&r" (sl) \
696 : "0" (ah), "r" (bh), "%1" (al), "r" (bl)__CLOBBER_CC); \
698 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
700 /* if (__builtin_constant_p (bl)) \
701 __asm__ ("slfi\t%1,%o5\n\tslbr\t%0,%3" \
702 : "=r" (sh), "=&r" (sl) \
703 : "0" (ah), "r" (bh), "1" (al), "n" (bl) __CLOBBER_CC); \
705 */ __asm__ ("slr\t%1,%5\n\tslbr\t%0,%3" \
706 : "=r" (sh), "=&r" (sl) \
707 : "0" (ah), "r" (bh), "1" (al), "r" (bl) __CLOBBER_CC); \
709 #if __GMP_GNUC_PREREQ (4,5)
710 #define umul_ppmm(xh, xl, m0, m1) \
712 union {UDItype __ll; \
713 struct {USItype __h, __l;} __i; \
715 __x.__ll = (UDItype) (m0) * (UDItype) (m1); \
716 (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
720 /* FIXME: this fails if gcc knows about the 64-bit registers. Use only
721 with a new enough processor pretending we have 32-bit registers. */
722 #define umul_ppmm(xh, xl, m0, m1) \
724 union {UDItype __ll; \
725 struct {USItype __h, __l;} __i; \
727 __asm__ ("mlr\t%0,%2" \
729 : "%0" (m0), "r" (m1)); \
730 (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
733 #define umul_ppmm(xh, xl, m0, m1) \
735 /* When we have 64-bit regs and gcc is aware of that, we cannot simply use
736 DImode for the product, since that would be allocated to a single 64-bit
737 register, whereas mlr uses the low 32-bits of an even-odd register pair.
739 register USItype __r0 __asm__ ("0"); \
740 register USItype __r1 __asm__ ("1") = (m0); \
741 __asm__ ("mlr\t%0,%3" \
742 : "=r" (__r0), "=r" (__r1) \
743 : "r" (__r1), "r" (m1)); \
744 (xh) = __r0; (xl) = __r1; \
749 /* FIXME: this fails if gcc knows about the 64-bit registers. Use only
750 with a new enough processor pretending we have 32-bit registers. */
751 #define udiv_qrnnd(q, r, n1, n0, d) \
753 union {UDItype __ll; \
754 struct {USItype __h, __l;} __i; \
756 __x.__i.__h = n1; __x.__i.__l = n0; \
757 __asm__ ("dlr\t%0,%2" \
759 : "0" (__x.__ll), "r" (d)); \
760 (q) = __x.__i.__l; (r) = __x.__i.__h; \
763 #define udiv_qrnnd(q, r, n1, n0, d) \
765 register USItype __r0 __asm__ ("0") = (n1); \
766 register USItype __r1 __asm__ ("1") = (n0); \
767 __asm__ ("dlr\t%0,%4" \
768 : "=r" (__r0), "=r" (__r1) \
769 : "r" (__r0), "r" (__r1), "r" (d)); \
770 (q) = __r1; (r) = __r0; \
773 #else /* if __zarch__ */
774 /* FIXME: this fails if gcc knows about the 64-bit registers. */
775 #define smul_ppmm(xh, xl, m0, m1) \
777 union {DItype __ll; \
778 struct {USItype __h, __l;} __i; \
780 __asm__ ("mr\t%0,%2" \
782 : "%0" (m0), "r" (m1)); \
783 (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
785 /* FIXME: this fails if gcc knows about the 64-bit registers. */
786 #define sdiv_qrnnd(q, r, n1, n0, d) \
788 union {DItype __ll; \
789 struct {USItype __h, __l;} __i; \
791 __x.__i.__h = n1; __x.__i.__l = n0; \
792 __asm__ ("dr\t%0,%2" \
794 : "0" (__x.__ll), "r" (d)); \
795 (q) = __x.__i.__l; (r) = __x.__i.__h; \
797 #endif /* if __zarch__ */
800 #if defined (__s390x__) && W_TYPE_SIZE == 64
801 /* We need to cast operands with register constraints, otherwise their types
802 will be assumed to be SImode by gcc. For these machines, such operations
803 will insert a value into the low 32 bits, and leave the high 32 bits with
805 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
807 __asm__ ("algr\t%1,%5\n\talcgr\t%0,%3" \
808 : "=r" (sh), "=&r" (sl) \
809 : "0" ((UDItype)(ah)), "r" ((UDItype)(bh)), \
810 "%1" ((UDItype)(al)), "r" ((UDItype)(bl)) __CLOBBER_CC); \
812 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
814 __asm__ ("slgr\t%1,%5\n\tslbgr\t%0,%3" \
815 : "=r" (sh), "=&r" (sl) \
816 : "0" ((UDItype)(ah)), "r" ((UDItype)(bh)), \
817 "1" ((UDItype)(al)), "r" ((UDItype)(bl)) __CLOBBER_CC); \
819 #define umul_ppmm(xh, xl, m0, m1) \
821 union {unsigned int __attribute__ ((mode(TI))) __ll; \
822 struct {UDItype __h, __l;} __i; \
824 __asm__ ("mlgr\t%0,%2" \
826 : "%0" ((UDItype)(m0)), "r" ((UDItype)(m1))); \
827 (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
829 #define udiv_qrnnd(q, r, n1, n0, d) \
831 union {unsigned int __attribute__ ((mode(TI))) __ll; \
832 struct {UDItype __h, __l;} __i; \
834 __x.__i.__h = n1; __x.__i.__l = n0; \
835 __asm__ ("dlgr\t%0,%2" \
837 : "0" (__x.__ll), "r" ((UDItype)(d))); \
838 (q) = __x.__i.__l; (r) = __x.__i.__h; \
840 #if 0 /* FIXME: Enable for z10 (?) */
841 #define count_leading_zeros(cnt, x) \
843 union {unsigned int __attribute__ ((mode(TI))) __ll; \
844 struct {UDItype __h, __l;} __i; \
846 __asm__ ("flogr\t%0,%1" \
847 : "=r" (__clr_cnt.__ll) \
848 : "r" (x) __CLOBBER_CC); \
849 (cnt) = __clr_cnt.__i.__h; \
854 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
855 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
856 __asm__ ("addl %5,%k1\n\tadcl %3,%k0" \
857 : "=r" (sh), "=&r" (sl) \
858 : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \
859 "%1" ((USItype)(al)), "g" ((USItype)(bl)))
860 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
861 __asm__ ("subl %5,%k1\n\tsbbl %3,%k0" \
862 : "=r" (sh), "=&r" (sl) \
863 : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \
864 "1" ((USItype)(al)), "g" ((USItype)(bl)))
865 #define umul_ppmm(w1, w0, u, v) \
867 : "=a" (w0), "=d" (w1) \
868 : "%0" ((USItype)(u)), "rm" ((USItype)(v)))
869 #define udiv_qrnnd(q, r, n1, n0, dx) /* d renamed to dx avoiding "=d" */\
870 __asm__ ("divl %4" /* stringification in K&R C */ \
871 : "=a" (q), "=d" (r) \
872 : "0" ((USItype)(n0)), "1" ((USItype)(n1)), "rm" ((USItype)(dx)))
874 #if HAVE_HOST_CPU_i586 || HAVE_HOST_CPU_pentium || HAVE_HOST_CPU_pentiummmx
875 /* Pentium bsrl takes between 10 and 72 cycles depending where the most
876 significant 1 bit is, hence the use of the following alternatives. bsfl
877 is slow too, between 18 and 42 depending where the least significant 1
878 bit is, so let the generic count_trailing_zeros below make use of the
879 count_leading_zeros here too. */
881 #if HAVE_HOST_CPU_pentiummmx && ! defined (LONGLONG_STANDALONE)
882 /* The following should be a fixed 14 or 15 cycles, but possibly plus an L1
883 cache miss reading from __clz_tab. For P55 it's favoured over the float
884 below so as to avoid mixing MMX and x87, since the penalty for switching
885 between the two is about 100 cycles.
887 The asm block sets __shift to -3 if the high 24 bits are clear, -2 for
888 16, -1 for 8, or 0 otherwise. This could be written equivalently as
889 follows, but as of gcc 2.95.2 it results in conditional jumps.
891 __shift = -(__n < 0x1000000);
892 __shift -= (__n < 0x10000);
893 __shift -= (__n < 0x100);
895 The middle two sbbl and cmpl's pair, and with luck something gcc
896 generates might pair with the first cmpl and the last sbbl. The "32+1"
897 constant could be folded into __clz_tab[], but it doesn't seem worth
898 making a different table just for that. */
900 #define count_leading_zeros(c,n) \
904 __asm__ ("cmpl $0x1000000, %1\n" \
906 "cmpl $0x10000, %1\n" \
908 "cmpl $0x100, %1\n" \
910 : "=&r" (__shift) : "r" (__n)); \
911 __shift = __shift*8 + 24 + 1; \
912 (c) = 32 + 1 - __shift - __clz_tab[__n >> __shift]; \
914 #define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
915 #define COUNT_LEADING_ZEROS_0 31 /* n==0 indistinguishable from n==1 */
917 #else /* ! pentiummmx || LONGLONG_STANDALONE */
918 /* The following should be a fixed 14 cycles or so. Some scheduling
919 opportunities should be available between the float load/store too. This
920 sort of code is used in gcc 3 for __builtin_ffs (with "n&-n") and is
921 apparently suggested by the Intel optimizing manual (don't know exactly
922 where). gcc 2.95 or up will be best for this, so the "double" is
923 correctly aligned on the stack. */
924 #define count_leading_zeros(c,n) \
931 __u.d = (UWtype) (n); \
932 (c) = 0x3FF + 31 - (__u.a[1] >> 20); \
934 #define COUNT_LEADING_ZEROS_0 (0x3FF + 31)
935 #endif /* pentiummx */
937 #else /* ! pentium */
939 #if __GMP_GNUC_PREREQ (3,4) /* using bsrl */
940 #define count_leading_zeros(count,x) count_leading_zeros_gcc_clz(count,x)
943 /* On P6, gcc prior to 3.0 generates a partial register stall for
944 __cbtmp^31, due to using "xorb $31" instead of "xorl $31", the former
945 being 1 code byte smaller. "31-__cbtmp" is a workaround, probably at the
946 cost of one extra instruction. Do this for "i386" too, since that means
948 #if ! defined (count_leading_zeros) && __GNUC__ < 3 \
949 && (HAVE_HOST_CPU_i386 \
950 || HAVE_HOST_CPU_i686 \
951 || HAVE_HOST_CPU_pentiumpro \
952 || HAVE_HOST_CPU_pentium2 \
953 || HAVE_HOST_CPU_pentium3)
954 #define count_leading_zeros(count, x) \
958 __asm__ ("bsrl %1,%0" : "=r" (__cbtmp) : "rm" ((USItype)(x))); \
959 (count) = 31 - __cbtmp; \
961 #endif /* gcc<3 asm bsrl */
963 #ifndef count_leading_zeros
964 #define count_leading_zeros(count, x) \
968 __asm__ ("bsrl %1,%0" : "=r" (__cbtmp) : "rm" ((USItype)(x))); \
969 (count) = __cbtmp ^ 31; \
971 #endif /* asm bsrl */
973 #if __GMP_GNUC_PREREQ (3,4) /* using bsfl */
974 #define count_trailing_zeros(count,x) count_trailing_zeros_gcc_ctz(count,x)
977 #ifndef count_trailing_zeros
978 #define count_trailing_zeros(count, x) \
981 __asm__ ("bsfl %1,%k0" : "=r" (count) : "rm" ((USItype)(x))); \
983 #endif /* asm bsfl */
985 #endif /* ! pentium */
995 #if defined (__amd64__) && W_TYPE_SIZE == 64
996 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
997 __asm__ ("addq %5,%q1\n\tadcq %3,%q0" \
998 : "=r" (sh), "=&r" (sl) \
999 : "0" ((UDItype)(ah)), "rme" ((UDItype)(bh)), \
1000 "%1" ((UDItype)(al)), "rme" ((UDItype)(bl)))
1001 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1002 __asm__ ("subq %5,%q1\n\tsbbq %3,%q0" \
1003 : "=r" (sh), "=&r" (sl) \
1004 : "0" ((UDItype)(ah)), "rme" ((UDItype)(bh)), \
1005 "1" ((UDItype)(al)), "rme" ((UDItype)(bl)))
1006 #define umul_ppmm(w1, w0, u, v) \
1007 __asm__ ("mulq %3" \
1008 : "=a" (w0), "=d" (w1) \
1009 : "%0" ((UDItype)(u)), "rm" ((UDItype)(v)))
1010 #define udiv_qrnnd(q, r, n1, n0, dx) /* d renamed to dx avoiding "=d" */\
1011 __asm__ ("divq %4" /* stringification in K&R C */ \
1012 : "=a" (q), "=d" (r) \
1013 : "0" ((UDItype)(n0)), "1" ((UDItype)(n1)), "rm" ((UDItype)(dx)))
1014 /* bsrq destination must be a 64-bit register, hence UDItype for __cbtmp. */
1015 #define count_leading_zeros(count, x) \
1018 ASSERT ((x) != 0); \
1019 __asm__ ("bsrq %1,%0" : "=r" (__cbtmp) : "rm" ((UDItype)(x))); \
1020 (count) = __cbtmp ^ 63; \
1022 /* bsfq destination must be a 64-bit register, "%q0" forces this in case
1023 count is only an int. */
1024 #define count_trailing_zeros(count, x) \
1026 ASSERT ((x) != 0); \
1027 __asm__ ("bsfq %1,%q0" : "=r" (count) : "rm" ((UDItype)(x))); \
1031 #if defined (__i860__) && W_TYPE_SIZE == 32
1032 #define rshift_rhlc(r,h,l,c) \
1033 __asm__ ("shr %3,r0,r0\;shrd %1,%2,%0" \
1034 "=r" (r) : "r" (h), "r" (l), "rn" (c))
1037 #if defined (__i960__) && W_TYPE_SIZE == 32
1038 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1039 __asm__ ("cmpo 1,0\;addc %5,%4,%1\;addc %3,%2,%0" \
1040 : "=r" (sh), "=&r" (sl) \
1041 : "dI" (ah), "dI" (bh), "%dI" (al), "dI" (bl))
1042 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1043 __asm__ ("cmpo 0,0\;subc %5,%4,%1\;subc %3,%2,%0" \
1044 : "=r" (sh), "=&r" (sl) \
1045 : "dI" (ah), "dI" (bh), "dI" (al), "dI" (bl))
1046 #define umul_ppmm(w1, w0, u, v) \
1047 ({union {UDItype __ll; \
1048 struct {USItype __l, __h;} __i; \
1050 __asm__ ("emul %2,%1,%0" \
1051 : "=d" (__x.__ll) : "%dI" (u), "dI" (v)); \
1052 (w1) = __x.__i.__h; (w0) = __x.__i.__l;})
1053 #define __umulsidi3(u, v) \
1055 __asm__ ("emul %2,%1,%0" : "=d" (__w) : "%dI" (u), "dI" (v)); \
1057 #define udiv_qrnnd(q, r, nh, nl, d) \
1059 union {UDItype __ll; \
1060 struct {USItype __l, __h;} __i; \
1062 __nn.__i.__h = (nh); __nn.__i.__l = (nl); \
1063 __asm__ ("ediv %d,%n,%0" \
1064 : "=d" (__rq.__ll) : "dI" (__nn.__ll), "dI" (d)); \
1065 (r) = __rq.__i.__l; (q) = __rq.__i.__h; \
1067 #define count_leading_zeros(count, x) \
1070 __asm__ ("scanbit %1,%0" : "=r" (__cbtmp) : "r" (x)); \
1071 (count) = __cbtmp ^ 31; \
1073 #define COUNT_LEADING_ZEROS_0 (-32) /* sic */
1074 #if defined (__i960mx) /* what is the proper symbol to test??? */
1075 #define rshift_rhlc(r,h,l,c) \
1077 union {UDItype __ll; \
1078 struct {USItype __l, __h;} __i; \
1080 __nn.__i.__h = (h); __nn.__i.__l = (l); \
1081 __asm__ ("shre %2,%1,%0" : "=d" (r) : "dI" (__nn.__ll), "dI" (c)); \
1086 #if (defined (__mc68000__) || defined (__mc68020__) || defined(mc68020) \
1087 || defined (__m68k__) || defined (__mc5200__) || defined (__mc5206e__) \
1088 || defined (__mc5307__)) && W_TYPE_SIZE == 32
1089 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1090 __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0" \
1091 : "=d" (sh), "=&d" (sl) \
1092 : "0" ((USItype)(ah)), "d" ((USItype)(bh)), \
1093 "%1" ((USItype)(al)), "g" ((USItype)(bl)))
1094 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1095 __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0" \
1096 : "=d" (sh), "=&d" (sl) \
1097 : "0" ((USItype)(ah)), "d" ((USItype)(bh)), \
1098 "1" ((USItype)(al)), "g" ((USItype)(bl)))
1099 /* The '020, '030, '040 and CPU32 have 32x32->64 and 64/32->32q-32r. */
1100 #if defined (__mc68020__) || defined(mc68020) \
1101 || defined (__mc68030__) || defined (mc68030) \
1102 || defined (__mc68040__) || defined (mc68040) \
1103 || defined (__mcpu32__) || defined (mcpu32) \
1104 || defined (__NeXT__)
1105 #define umul_ppmm(w1, w0, u, v) \
1106 __asm__ ("mulu%.l %3,%1:%0" \
1107 : "=d" (w0), "=d" (w1) \
1108 : "%0" ((USItype)(u)), "dmi" ((USItype)(v)))
1109 #define UMUL_TIME 45
1110 #define udiv_qrnnd(q, r, n1, n0, d) \
1111 __asm__ ("divu%.l %4,%1:%0" \
1112 : "=d" (q), "=d" (r) \
1113 : "0" ((USItype)(n0)), "1" ((USItype)(n1)), "dmi" ((USItype)(d)))
1114 #define UDIV_TIME 90
1115 #define sdiv_qrnnd(q, r, n1, n0, d) \
1116 __asm__ ("divs%.l %4,%1:%0" \
1117 : "=d" (q), "=d" (r) \
1118 : "0" ((USItype)(n0)), "1" ((USItype)(n1)), "dmi" ((USItype)(d)))
1119 #else /* for other 68k family members use 16x16->32 multiplication */
1120 #define umul_ppmm(xh, xl, a, b) \
1121 do { USItype __umul_tmp1, __umul_tmp2; \
1122 __asm__ ("| Inlined umul_ppmm\n" \
1123 " move%.l %5,%3\n" \
1124 " move%.l %2,%0\n" \
1125 " move%.w %3,%1\n" \
1128 " mulu%.w %2,%1\n" \
1129 " mulu%.w %3,%0\n" \
1130 " mulu%.w %2,%3\n" \
1132 " mulu%.w %5,%2\n" \
1135 " add%.l %#0x10000,%0\n" \
1136 "1: move%.l %2,%3\n" \
1142 " addx%.l %2,%0\n" \
1143 " | End inlined umul_ppmm" \
1144 : "=&d" (xh), "=&d" (xl), \
1145 "=d" (__umul_tmp1), "=&d" (__umul_tmp2) \
1146 : "%2" ((USItype)(a)), "d" ((USItype)(b))); \
1148 #define UMUL_TIME 100
1149 #define UDIV_TIME 400
1150 #endif /* not mc68020 */
1151 /* The '020, '030, '040 and '060 have bitfield insns.
1152 GCC 3.4 defines __mc68020__ when in CPU32 mode, check for __mcpu32__ to
1153 exclude bfffo on that chip (bitfield insns not available). */
1154 #if (defined (__mc68020__) || defined (mc68020) \
1155 || defined (__mc68030__) || defined (mc68030) \
1156 || defined (__mc68040__) || defined (mc68040) \
1157 || defined (__mc68060__) || defined (mc68060) \
1158 || defined (__NeXT__)) \
1159 && ! defined (__mcpu32__)
1160 #define count_leading_zeros(count, x) \
1161 __asm__ ("bfffo %1{%b2:%b2},%0" \
1163 : "od" ((USItype) (x)), "n" (0))
1164 #define COUNT_LEADING_ZEROS_0 32
1166 #endif /* mc68000 */
1168 #if defined (__m88000__) && W_TYPE_SIZE == 32
1169 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1170 __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3" \
1171 : "=r" (sh), "=&r" (sl) \
1172 : "rJ" (ah), "rJ" (bh), "%rJ" (al), "rJ" (bl))
1173 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1174 __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3" \
1175 : "=r" (sh), "=&r" (sl) \
1176 : "rJ" (ah), "rJ" (bh), "rJ" (al), "rJ" (bl))
1177 #define count_leading_zeros(count, x) \
1180 __asm__ ("ff1 %0,%1" : "=r" (__cbtmp) : "r" (x)); \
1181 (count) = __cbtmp ^ 31; \
1183 #define COUNT_LEADING_ZEROS_0 63 /* sic */
1184 #if defined (__m88110__)
1185 #define umul_ppmm(wh, wl, u, v) \
1187 union {UDItype __ll; \
1188 struct {USItype __h, __l;} __i; \
1190 __asm__ ("mulu.d %0,%1,%2" : "=r" (__x.__ll) : "r" (u), "r" (v)); \
1191 (wh) = __x.__i.__h; \
1192 (wl) = __x.__i.__l; \
1194 #define udiv_qrnnd(q, r, n1, n0, d) \
1195 ({union {UDItype __ll; \
1196 struct {USItype __h, __l;} __i; \
1198 __x.__i.__h = (n1); __x.__i.__l = (n0); \
1199 __asm__ ("divu.d %0,%1,%2" \
1200 : "=r" (__q.__ll) : "r" (__x.__ll), "r" (d)); \
1201 (r) = (n0) - __q.__l * (d); (q) = __q.__l; })
1203 #define UDIV_TIME 25
1205 #define UMUL_TIME 17
1206 #define UDIV_TIME 150
1207 #endif /* __m88110__ */
1208 #endif /* __m88000__ */
1210 #if defined (__mips) && W_TYPE_SIZE == 32
1211 #if __GMP_GNUC_PREREQ (4,4)
1212 #define umul_ppmm(w1, w0, u, v) \
1214 UDItype __ll = (UDItype)(u) * (v); \
1219 #if !defined (umul_ppmm) && __GMP_GNUC_PREREQ (2,7)
1220 #define umul_ppmm(w1, w0, u, v) \
1221 __asm__ ("multu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
1223 #if !defined (umul_ppmm)
1224 #define umul_ppmm(w1, w0, u, v) \
1225 __asm__ ("multu %2,%3\n\tmflo %0\n\tmfhi %1" \
1226 : "=d" (w0), "=d" (w1) : "d" (u), "d" (v))
1228 #define UMUL_TIME 10
1229 #define UDIV_TIME 100
1232 #if (defined (__mips) && __mips >= 3) && W_TYPE_SIZE == 64
1233 #if __GMP_GNUC_PREREQ (4,4)
1234 #define umul_ppmm(w1, w0, u, v) \
1236 typedef unsigned int __ll_UTItype __attribute__((mode(TI))); \
1237 __ll_UTItype __ll = (__ll_UTItype)(u) * (v); \
1242 #if !defined (umul_ppmm) && __GMP_GNUC_PREREQ (2,7)
1243 #define umul_ppmm(w1, w0, u, v) \
1244 __asm__ ("dmultu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
1246 #if !defined (umul_ppmm)
1247 #define umul_ppmm(w1, w0, u, v) \
1248 __asm__ ("dmultu %2,%3\n\tmflo %0\n\tmfhi %1" \
1249 : "=d" (w0), "=d" (w1) : "d" (u), "d" (v))
1251 #define UMUL_TIME 20
1252 #define UDIV_TIME 140
1255 #if defined (__mmix__) && W_TYPE_SIZE == 64
1256 #define umul_ppmm(w1, w0, u, v) \
1257 __asm__ ("MULU %0,%2,%3" : "=r" (w0), "=z" (w1) : "r" (u), "r" (v))
1260 #if defined (__ns32000__) && W_TYPE_SIZE == 32
1261 #define umul_ppmm(w1, w0, u, v) \
1262 ({union {UDItype __ll; \
1263 struct {USItype __l, __h;} __i; \
1265 __asm__ ("meid %2,%0" \
1267 : "%0" ((USItype)(u)), "g" ((USItype)(v))); \
1268 (w1) = __x.__i.__h; (w0) = __x.__i.__l;})
1269 #define __umulsidi3(u, v) \
1271 __asm__ ("meid %2,%0" \
1273 : "%0" ((USItype)(u)), "g" ((USItype)(v))); \
1275 #define udiv_qrnnd(q, r, n1, n0, d) \
1276 ({union {UDItype __ll; \
1277 struct {USItype __l, __h;} __i; \
1279 __x.__i.__h = (n1); __x.__i.__l = (n0); \
1280 __asm__ ("deid %2,%0" \
1282 : "0" (__x.__ll), "g" ((USItype)(d))); \
1283 (r) = __x.__i.__l; (q) = __x.__i.__h; })
1284 #define count_trailing_zeros(count,x) \
1286 __asm__ ("ffsd %2,%0" \
1288 : "0" ((USItype) 0), "r" ((USItype) (x))); \
1290 #endif /* __ns32000__ */
1292 /* In the past we had a block of various #defines tested
1298 PPC - old gcc, GNU/Linux, SysV
1299 The plain PPC test was not good for vxWorks, since PPC is defined on all
1300 CPUs there (eg. m68k too), as a constant one is expected to compare
1303 At any rate, this was pretty unattractive and a bit fragile. The use of
1304 HAVE_HOST_CPU_FAMILY is designed to cut through it all and be sure of
1305 getting the desired effect.
1307 ENHANCE-ME: We should test _IBMR2 here when we add assembly support for
1308 the system vendor compilers. (Is that vendor compilers with inline asm,
1311 #if (HAVE_HOST_CPU_FAMILY_power || HAVE_HOST_CPU_FAMILY_powerpc) \
1312 && W_TYPE_SIZE == 32
1313 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1315 if (__builtin_constant_p (bh) && (bh) == 0) \
1316 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
1317 : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
1318 else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \
1319 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
1320 : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
1322 __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
1323 : "=r" (sh), "=&r" (sl) \
1324 : "r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \
1326 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1328 if (__builtin_constant_p (ah) && (ah) == 0) \
1329 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
1330 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
1331 else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0) \
1332 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
1333 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
1334 else if (__builtin_constant_p (bh) && (bh) == 0) \
1335 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
1336 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
1337 else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \
1338 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
1339 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
1341 __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
1342 : "=r" (sh), "=&r" (sl) \
1343 : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \
1345 #define count_leading_zeros(count, x) \
1346 __asm__ ("{cntlz|cntlzw} %0,%1" : "=r" (count) : "r" (x))
1347 #define COUNT_LEADING_ZEROS_0 32
1348 #if HAVE_HOST_CPU_FAMILY_powerpc
1349 #if __GMP_GNUC_PREREQ (4,4)
1350 #define umul_ppmm(w1, w0, u, v) \
1352 UDItype __ll = (UDItype)(u) * (v); \
1357 #if !defined (umul_ppmm)
1358 #define umul_ppmm(ph, pl, m0, m1) \
1360 USItype __m0 = (m0), __m1 = (m1); \
1361 __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
1362 (pl) = __m0 * __m1; \
1365 #define UMUL_TIME 15
1366 #define smul_ppmm(ph, pl, m0, m1) \
1368 SItype __m0 = (m0), __m1 = (m1); \
1369 __asm__ ("mulhw %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
1370 (pl) = __m0 * __m1; \
1372 #define SMUL_TIME 14
1373 #define UDIV_TIME 120
1376 #define smul_ppmm(xh, xl, m0, m1) \
1377 __asm__ ("mul %0,%2,%3" : "=r" (xh), "=q" (xl) : "r" (m0), "r" (m1))
1379 #define sdiv_qrnnd(q, r, nh, nl, d) \
1380 __asm__ ("div %0,%2,%4" : "=r" (q), "=q" (r) : "r" (nh), "1" (nl), "r" (d))
1381 #define UDIV_TIME 100
1383 #endif /* 32-bit POWER architecture variants. */
1385 /* We should test _IBMR2 here when we add assembly support for the system
1386 vendor compilers. */
1387 #if HAVE_HOST_CPU_FAMILY_powerpc && W_TYPE_SIZE == 64
1388 #if !defined (_LONG_LONG_LIMB)
1389 /* _LONG_LONG_LIMB is ABI=mode32 where adde operates on 32-bit values. So
1390 use adde etc only when not _LONG_LONG_LIMB. */
1391 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1393 if (__builtin_constant_p (bh) && (bh) == 0) \
1394 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
1395 : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
1396 else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \
1397 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
1398 : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
1400 __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
1401 : "=r" (sh), "=&r" (sl) \
1402 : "r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \
1404 /* We use "*rI" for the constant operand here, since with just "I", gcc barfs.
1405 This might seem strange, but gcc folds away the dead code late. */
1406 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1408 if (__builtin_constant_p (bl) && bl > -0x8000 && bl <= 0x8000) { \
1409 if (__builtin_constant_p (ah) && (ah) == 0) \
1410 __asm__ ("{ai|addic} %1,%3,%4\n\t{sfze|subfze} %0,%2" \
1411 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "*rI" (-bl)); \
1412 else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0) \
1413 __asm__ ("{ai|addic} %1,%3,%4\n\t{sfme|subfme} %0,%2" \
1414 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "*rI" (-bl)); \
1415 else if (__builtin_constant_p (bh) && (bh) == 0) \
1416 __asm__ ("{ai|addic} %1,%3,%4\n\t{ame|addme} %0,%2" \
1417 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "*rI" (-bl)); \
1418 else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \
1419 __asm__ ("{ai|addic} %1,%3,%4\n\t{aze|addze} %0,%2" \
1420 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "*rI" (-bl)); \
1422 __asm__ ("{ai|addic} %1,%4,%5\n\t{sfe|subfe} %0,%3,%2" \
1423 : "=r" (sh), "=&r" (sl) \
1424 : "r" (ah), "r" (bh), "rI" (al), "*rI" (-bl)); \
1426 if (__builtin_constant_p (ah) && (ah) == 0) \
1427 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
1428 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl)); \
1429 else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0) \
1430 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
1431 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl)); \
1432 else if (__builtin_constant_p (bh) && (bh) == 0) \
1433 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
1434 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl)); \
1435 else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \
1436 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
1437 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl)); \
1439 __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
1440 : "=r" (sh), "=&r" (sl) \
1441 : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \
1444 #endif /* ! _LONG_LONG_LIMB */
1445 #define count_leading_zeros(count, x) \
1446 __asm__ ("cntlzd %0,%1" : "=r" (count) : "r" (x))
1447 #define COUNT_LEADING_ZEROS_0 64
1448 #if 0 && __GMP_GNUC_PREREQ (4,4) /* Disable, this results in libcalls! */
1449 #define umul_ppmm(w1, w0, u, v) \
1451 typedef unsigned int __ll_UTItype __attribute__((mode(TI))); \
1452 __ll_UTItype __ll = (__ll_UTItype)(u) * (v); \
1457 #if !defined (umul_ppmm)
1458 #define umul_ppmm(ph, pl, m0, m1) \
1460 UDItype __m0 = (m0), __m1 = (m1); \
1461 __asm__ ("mulhdu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
1462 (pl) = __m0 * __m1; \
1465 #define UMUL_TIME 15
1466 #define smul_ppmm(ph, pl, m0, m1) \
1468 DItype __m0 = (m0), __m1 = (m1); \
1469 __asm__ ("mulhd %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
1470 (pl) = __m0 * __m1; \
1472 #define SMUL_TIME 14 /* ??? */
1473 #define UDIV_TIME 120 /* ??? */
1474 #endif /* 64-bit PowerPC. */
1476 #if defined (__pyr__) && W_TYPE_SIZE == 32
1477 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1478 __asm__ ("addw %5,%1\n\taddwc %3,%0" \
1479 : "=r" (sh), "=&r" (sl) \
1480 : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \
1481 "%1" ((USItype)(al)), "g" ((USItype)(bl)))
1482 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1483 __asm__ ("subw %5,%1\n\tsubwb %3,%0" \
1484 : "=r" (sh), "=&r" (sl) \
1485 : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \
1486 "1" ((USItype)(al)), "g" ((USItype)(bl)))
1487 /* This insn works on Pyramids with AP, XP, or MI CPUs, but not with SP. */
1488 #define umul_ppmm(w1, w0, u, v) \
1489 ({union {UDItype __ll; \
1490 struct {USItype __h, __l;} __i; \
1492 __asm__ ("movw %1,%R0\n\tuemul %2,%0" \
1493 : "=&r" (__x.__ll) \
1494 : "g" ((USItype) (u)), "g" ((USItype)(v))); \
1495 (w1) = __x.__i.__h; (w0) = __x.__i.__l;})
1496 #endif /* __pyr__ */
1498 #if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
1499 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1500 __asm__ ("a %1,%5\n\tae %0,%3" \
1501 : "=r" (sh), "=&r" (sl) \
1502 : "0" ((USItype)(ah)), "r" ((USItype)(bh)), \
1503 "%1" ((USItype)(al)), "r" ((USItype)(bl)))
1504 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1505 __asm__ ("s %1,%5\n\tse %0,%3" \
1506 : "=r" (sh), "=&r" (sl) \
1507 : "0" ((USItype)(ah)), "r" ((USItype)(bh)), \
1508 "1" ((USItype)(al)), "r" ((USItype)(bl)))
1509 #define smul_ppmm(ph, pl, m0, m1) \
1531 : "=r" (ph), "=r" (pl) \
1532 : "%r" ((USItype)(m0)), "r" ((USItype)(m1)) \
1534 #define UMUL_TIME 20
1535 #define UDIV_TIME 200
1536 #define count_leading_zeros(count, x) \
1538 if ((x) >= 0x10000) \
1539 __asm__ ("clz %0,%1" \
1540 : "=r" (count) : "r" ((USItype)(x) >> 16)); \
1543 __asm__ ("clz %0,%1" \
1544 : "=r" (count) : "r" ((USItype)(x))); \
1548 #endif /* RT/ROMP */
1550 #if (defined (__SH2__) || defined (__SH3__) || defined (__SH4__)) && W_TYPE_SIZE == 32
1551 #define umul_ppmm(w1, w0, u, v) \
1552 __asm__ ("dmulu.l %2,%3\n\tsts macl,%1\n\tsts mach,%0" \
1553 : "=r" (w1), "=r" (w0) : "r" (u), "r" (v) : "macl", "mach")
1557 #if defined (__sparc__) && W_TYPE_SIZE == 32
1558 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1559 __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0" \
1560 : "=r" (sh), "=&r" (sl) \
1561 : "rJ" (ah), "rI" (bh),"%rJ" (al), "rI" (bl) \
1563 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1564 __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0" \
1565 : "=r" (sh), "=&r" (sl) \
1566 : "rJ" (ah), "rI" (bh), "rJ" (al), "rI" (bl) \
1568 /* FIXME: When gcc -mcpu=v9 is used on solaris, gcc/config/sol2-sld-64.h
1569 doesn't define anything to indicate that to us, it only sets __sparcv8. */
1570 #if defined (__sparc_v9__) || defined (__sparcv9)
1571 /* Perhaps we should use floating-point operations here? */
1573 /* Triggers a bug making mpz/tests/t-gcd.c fail.
1574 Perhaps we simply need explicitly zero-extend the inputs? */
1575 #define umul_ppmm(w1, w0, u, v) \
1576 __asm__ ("mulx %2,%3,%%g1; srl %%g1,0,%1; srlx %%g1,32,%0" : \
1577 "=r" (w1), "=r" (w0) : "r" (u), "r" (v) : "g1")
1579 /* Use v8 umul until above bug is fixed. */
1580 #define umul_ppmm(w1, w0, u, v) \
1581 __asm__ ("umul %2,%3,%1;rd %%y,%0" : "=r" (w1), "=r" (w0) : "r" (u), "r" (v))
1583 /* Use a plain v8 divide for v9. */
1584 #define udiv_qrnnd(q, r, n1, n0, d) \
1587 __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0" \
1588 : "=r" (__q) : "r" (n1), "r" (n0), "r" (d)); \
1589 (r) = (n0) - __q * (d); \
1593 #if defined (__sparc_v8__) /* gcc normal */ \
1594 || defined (__sparcv8) /* gcc solaris */ \
1595 || HAVE_HOST_CPU_supersparc
1596 /* Don't match immediate range because, 1) it is not often useful,
1597 2) the 'I' flag thinks of the range as a 13 bit signed interval,
1598 while we want to match a 13 bit interval, sign extended to 32 bits,
1599 but INTERPRETED AS UNSIGNED. */
1600 #define umul_ppmm(w1, w0, u, v) \
1601 __asm__ ("umul %2,%3,%1;rd %%y,%0" : "=r" (w1), "=r" (w0) : "r" (u), "r" (v))
1604 #if HAVE_HOST_CPU_supersparc
1605 #define UDIV_TIME 60 /* SuperSPARC timing */
1607 /* Don't use this on SuperSPARC because its udiv only handles 53 bit
1608 dividends and will trap to the kernel for the rest. */
1609 #define udiv_qrnnd(q, r, n1, n0, d) \
1612 __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0" \
1613 : "=r" (__q) : "r" (n1), "r" (n0), "r" (d)); \
1614 (r) = (n0) - __q * (d); \
1617 #define UDIV_TIME 25
1618 #endif /* HAVE_HOST_CPU_supersparc */
1620 #else /* ! __sparc_v8__ */
1621 #if defined (__sparclite__)
1622 /* This has hardware multiply but not divide. It also has two additional
1623 instructions scan (ffs from high bit) and divscc. */
1624 #define umul_ppmm(w1, w0, u, v) \
1625 __asm__ ("umul %2,%3,%1;rd %%y,%0" : "=r" (w1), "=r" (w0) : "r" (u), "r" (v))
1627 #define udiv_qrnnd(q, r, n1, n0, d) \
1628 __asm__ ("! Inlined udiv_qrnnd\n" \
1629 " wr %%g0,%2,%%y ! Not a delayed write for sparclite\n" \
1631 " divscc %3,%4,%%g1\n" \
1632 " divscc %%g1,%4,%%g1\n" \
1633 " divscc %%g1,%4,%%g1\n" \
1634 " divscc %%g1,%4,%%g1\n" \
1635 " divscc %%g1,%4,%%g1\n" \
1636 " divscc %%g1,%4,%%g1\n" \
1637 " divscc %%g1,%4,%%g1\n" \
1638 " divscc %%g1,%4,%%g1\n" \
1639 " divscc %%g1,%4,%%g1\n" \
1640 " divscc %%g1,%4,%%g1\n" \
1641 " divscc %%g1,%4,%%g1\n" \
1642 " divscc %%g1,%4,%%g1\n" \
1643 " divscc %%g1,%4,%%g1\n" \
1644 " divscc %%g1,%4,%%g1\n" \
1645 " divscc %%g1,%4,%%g1\n" \
1646 " divscc %%g1,%4,%%g1\n" \
1647 " divscc %%g1,%4,%%g1\n" \
1648 " divscc %%g1,%4,%%g1\n" \
1649 " divscc %%g1,%4,%%g1\n" \
1650 " divscc %%g1,%4,%%g1\n" \
1651 " divscc %%g1,%4,%%g1\n" \
1652 " divscc %%g1,%4,%%g1\n" \
1653 " divscc %%g1,%4,%%g1\n" \
1654 " divscc %%g1,%4,%%g1\n" \
1655 " divscc %%g1,%4,%%g1\n" \
1656 " divscc %%g1,%4,%%g1\n" \
1657 " divscc %%g1,%4,%%g1\n" \
1658 " divscc %%g1,%4,%%g1\n" \
1659 " divscc %%g1,%4,%%g1\n" \
1660 " divscc %%g1,%4,%%g1\n" \
1661 " divscc %%g1,%4,%%g1\n" \
1662 " divscc %%g1,%4,%0\n" \
1666 "1: ! End of inline udiv_qrnnd" \
1667 : "=r" (q), "=r" (r) : "r" (n1), "r" (n0), "rI" (d) \
1668 : "%g1" __AND_CLOBBER_CC)
1669 #define UDIV_TIME 37
1670 #define count_leading_zeros(count, x) \
1671 __asm__ ("scan %1,1,%0" : "=r" (count) : "r" (x))
1672 /* Early sparclites return 63 for an argument of 0, but they warn that future
1673 implementations might change this. Therefore, leave COUNT_LEADING_ZEROS_0
1675 #endif /* __sparclite__ */
1676 #endif /* __sparc_v8__ */
1677 #endif /* __sparc_v9__ */
1678 /* Default to sparc v7 versions of umul_ppmm and udiv_qrnnd. */
1680 #define umul_ppmm(w1, w0, u, v) \
1681 __asm__ ("! Inlined umul_ppmm\n" \
1682 " wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr\n" \
1683 " sra %3,31,%%g2 ! Don't move this insn\n" \
1684 " and %2,%%g2,%%g2 ! Don't move this insn\n" \
1685 " andcc %%g0,0,%%g1 ! Don't move this insn\n" \
1686 " mulscc %%g1,%3,%%g1\n" \
1687 " mulscc %%g1,%3,%%g1\n" \
1688 " mulscc %%g1,%3,%%g1\n" \
1689 " mulscc %%g1,%3,%%g1\n" \
1690 " mulscc %%g1,%3,%%g1\n" \
1691 " mulscc %%g1,%3,%%g1\n" \
1692 " mulscc %%g1,%3,%%g1\n" \
1693 " mulscc %%g1,%3,%%g1\n" \
1694 " mulscc %%g1,%3,%%g1\n" \
1695 " mulscc %%g1,%3,%%g1\n" \
1696 " mulscc %%g1,%3,%%g1\n" \
1697 " mulscc %%g1,%3,%%g1\n" \
1698 " mulscc %%g1,%3,%%g1\n" \
1699 " mulscc %%g1,%3,%%g1\n" \
1700 " mulscc %%g1,%3,%%g1\n" \
1701 " mulscc %%g1,%3,%%g1\n" \
1702 " mulscc %%g1,%3,%%g1\n" \
1703 " mulscc %%g1,%3,%%g1\n" \
1704 " mulscc %%g1,%3,%%g1\n" \
1705 " mulscc %%g1,%3,%%g1\n" \
1706 " mulscc %%g1,%3,%%g1\n" \
1707 " mulscc %%g1,%3,%%g1\n" \
1708 " mulscc %%g1,%3,%%g1\n" \
1709 " mulscc %%g1,%3,%%g1\n" \
1710 " mulscc %%g1,%3,%%g1\n" \
1711 " mulscc %%g1,%3,%%g1\n" \
1712 " mulscc %%g1,%3,%%g1\n" \
1713 " mulscc %%g1,%3,%%g1\n" \
1714 " mulscc %%g1,%3,%%g1\n" \
1715 " mulscc %%g1,%3,%%g1\n" \
1716 " mulscc %%g1,%3,%%g1\n" \
1717 " mulscc %%g1,%3,%%g1\n" \
1718 " mulscc %%g1,0,%%g1\n" \
1719 " add %%g1,%%g2,%0\n" \
1721 : "=r" (w1), "=r" (w0) : "%rI" (u), "r" (v) \
1722 : "%g1", "%g2" __AND_CLOBBER_CC)
1723 #define UMUL_TIME 39 /* 39 instructions */
1726 #ifndef LONGLONG_STANDALONE
1727 #define udiv_qrnnd(q, r, n1, n0, d) \
1729 (q) = __MPN(udiv_qrnnd) (&__r, (n1), (n0), (d)); \
1732 extern UWtype
__MPN(udiv_qrnnd
) (UWtype
*, UWtype
, UWtype
, UWtype
);
1734 #define UDIV_TIME 140
1736 #endif /* LONGLONG_STANDALONE */
1737 #endif /* udiv_qrnnd */
1738 #endif /* __sparc__ */
1740 #if defined (__sparc__) && W_TYPE_SIZE == 64
1741 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1743 "addcc %r4,%5,%1\n" \
1744 " addccc %r6,%7,%%g0\n" \
1746 : "=r" (sh), "=&r" (sl) \
1747 : "rJ" (ah), "rI" (bh), "%rJ" (al), "rI" (bl), \
1748 "%rJ" ((al) >> 32), "rI" ((bl) >> 32) \
1750 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1752 "subcc %r4,%5,%1\n" \
1753 " subccc %r6,%7,%%g0\n" \
1755 : "=r" (sh), "=&r" (sl) \
1756 : "rJ" (ah), "rI" (bh), "rJ" (al), "rI" (bl), \
1757 "rJ" ((al) >> 32), "rI" ((bl) >> 32) \
1761 #if defined (__vax__) && W_TYPE_SIZE == 32
1762 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1763 __asm__ ("addl2 %5,%1\n\tadwc %3,%0" \
1764 : "=g" (sh), "=&g" (sl) \
1765 : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \
1766 "%1" ((USItype)(al)), "g" ((USItype)(bl)))
1767 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1768 __asm__ ("subl2 %5,%1\n\tsbwc %3,%0" \
1769 : "=g" (sh), "=&g" (sl) \
1770 : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \
1771 "1" ((USItype)(al)), "g" ((USItype)(bl)))
1772 #define smul_ppmm(xh, xl, m0, m1) \
1774 union {UDItype __ll; \
1775 struct {USItype __l, __h;} __i; \
1777 USItype __m0 = (m0), __m1 = (m1); \
1778 __asm__ ("emul %1,%2,$0,%0" \
1779 : "=g" (__x.__ll) : "g" (__m0), "g" (__m1)); \
1780 (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
1782 #define sdiv_qrnnd(q, r, n1, n0, d) \
1784 union {DItype __ll; \
1785 struct {SItype __l, __h;} __i; \
1787 __x.__i.__h = n1; __x.__i.__l = n0; \
1788 __asm__ ("ediv %3,%2,%0,%1" \
1789 : "=g" (q), "=g" (r) : "g" (__x.__ll), "g" (d)); \
1792 /* FIXME: This instruction appears to be unimplemented on some systems (vax
1794 #define count_trailing_zeros(count,x) \
1796 __asm__ ("ffs 0, 31, %1, %0" \
1798 : "g" ((USItype) (x))); \
1801 #endif /* __vax__ */
1803 #if defined (__z8000__) && W_TYPE_SIZE == 16
1804 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1805 __asm__ ("add %H1,%H5\n\tadc %H0,%H3" \
1806 : "=r" (sh), "=&r" (sl) \
1807 : "0" ((unsigned int)(ah)), "r" ((unsigned int)(bh)), \
1808 "%1" ((unsigned int)(al)), "rQR" ((unsigned int)(bl)))
1809 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1810 __asm__ ("sub %H1,%H5\n\tsbc %H0,%H3" \
1811 : "=r" (sh), "=&r" (sl) \
1812 : "0" ((unsigned int)(ah)), "r" ((unsigned int)(bh)), \
1813 "1" ((unsigned int)(al)), "rQR" ((unsigned int)(bl)))
1814 #define umul_ppmm(xh, xl, m0, m1) \
1816 union {long int __ll; \
1817 struct {unsigned int __h, __l;} __i; \
1819 unsigned int __m0 = (m0), __m1 = (m1); \
1820 __asm__ ("mult %S0,%H3" \
1821 : "=r" (__x.__i.__h), "=r" (__x.__i.__l) \
1822 : "%1" (m0), "rQR" (m1)); \
1823 (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
1824 (xh) += ((((signed int) __m0 >> 15) & __m1) \
1825 + (((signed int) __m1 >> 15) & __m0)); \
1827 #endif /* __z8000__ */
1829 #endif /* __GNUC__ */
1834 /* FIXME: "sidi" here is highly doubtful, should sometimes be "diti". */
1835 #if !defined (umul_ppmm) && defined (__umulsidi3)
1836 #define umul_ppmm(ph, pl, m0, m1) \
1838 UDWtype __ll = __umulsidi3 (m0, m1); \
1839 ph = (UWtype) (__ll >> W_TYPE_SIZE); \
1840 pl = (UWtype) __ll; \
1844 #if !defined (__umulsidi3)
1845 #define __umulsidi3(u, v) \
1846 ({UWtype __hi, __lo; \
1847 umul_ppmm (__hi, __lo, u, v); \
1848 ((UDWtype) __hi << W_TYPE_SIZE) | __lo; })
1852 /* Use mpn_umul_ppmm or mpn_udiv_qrnnd functions, if they exist. The "_r"
1853 forms have "reversed" arguments, meaning the pointer is last, which
1854 sometimes allows better parameter passing, in particular on 64-bit
1857 #define mpn_umul_ppmm __MPN(umul_ppmm)
1858 extern UWtype
mpn_umul_ppmm (UWtype
*, UWtype
, UWtype
);
1860 #if ! defined (umul_ppmm) && HAVE_NATIVE_mpn_umul_ppmm \
1861 && ! defined (LONGLONG_STANDALONE)
1862 #define umul_ppmm(wh, wl, u, v) \
1864 UWtype __umul_ppmm__p0; \
1865 (wh) = mpn_umul_ppmm (&__umul_ppmm__p0, (UWtype) (u), (UWtype) (v)); \
1866 (wl) = __umul_ppmm__p0; \
1870 #define mpn_umul_ppmm_r __MPN(umul_ppmm_r)
1871 extern UWtype
mpn_umul_ppmm_r (UWtype
, UWtype
, UWtype
*);
1873 #if ! defined (umul_ppmm) && HAVE_NATIVE_mpn_umul_ppmm_r \
1874 && ! defined (LONGLONG_STANDALONE)
1875 #define umul_ppmm(wh, wl, u, v) \
1877 UWtype __umul_ppmm__p0; \
1878 (wh) = mpn_umul_ppmm_r ((UWtype) (u), (UWtype) (v), &__umul_ppmm__p0); \
1879 (wl) = __umul_ppmm__p0; \
1883 #define mpn_udiv_qrnnd __MPN(udiv_qrnnd)
1884 extern UWtype
mpn_udiv_qrnnd (UWtype
*, UWtype
, UWtype
, UWtype
);
1886 #if ! defined (udiv_qrnnd) && HAVE_NATIVE_mpn_udiv_qrnnd \
1887 && ! defined (LONGLONG_STANDALONE)
1888 #define udiv_qrnnd(q, r, n1, n0, d) \
1890 UWtype __udiv_qrnnd__r; \
1891 (q) = mpn_udiv_qrnnd (&__udiv_qrnnd__r, \
1892 (UWtype) (n1), (UWtype) (n0), (UWtype) d); \
1893 (r) = __udiv_qrnnd__r; \
1897 #define mpn_udiv_qrnnd_r __MPN(udiv_qrnnd_r)
1898 extern UWtype
mpn_udiv_qrnnd_r (UWtype
, UWtype
, UWtype
, UWtype
*);
1900 #if ! defined (udiv_qrnnd) && HAVE_NATIVE_mpn_udiv_qrnnd_r \
1901 && ! defined (LONGLONG_STANDALONE)
1902 #define udiv_qrnnd(q, r, n1, n0, d) \
1904 UWtype __udiv_qrnnd__r; \
1905 (q) = mpn_udiv_qrnnd_r ((UWtype) (n1), (UWtype) (n0), (UWtype) d, \
1906 &__udiv_qrnnd__r); \
1907 (r) = __udiv_qrnnd__r; \
1912 /* If this machine has no inline assembler, use C macros. */
1914 #if !defined (add_ssaaaa)
1915 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1918 __x = (al) + (bl); \
1919 (sh) = (ah) + (bh) + (__x < (al)); \
1924 #if !defined (sub_ddmmss)
1925 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1928 __x = (al) - (bl); \
1929 (sh) = (ah) - (bh) - ((al) < (bl)); \
1934 /* If we lack umul_ppmm but have smul_ppmm, define umul_ppmm in terms of
1936 #if !defined (umul_ppmm) && defined (smul_ppmm)
1937 #define umul_ppmm(w1, w0, u, v) \
1940 UWtype __xm0 = (u), __xm1 = (v); \
1941 smul_ppmm (__w1, w0, __xm0, __xm1); \
1942 (w1) = __w1 + (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1) \
1943 + (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0); \
1947 /* If we still don't have umul_ppmm, define it using plain C.
1949 For reference, when this code is used for squaring (ie. u and v identical
1950 expressions), gcc recognises __x1 and __x2 are the same and generates 3
1951 multiplies, not 4. The subsequent additions could be optimized a bit,
1952 but the only place GMP currently uses such a square is mpn_sqr_basecase,
1953 and chips obliged to use this generic C umul will have plenty of worse
1954 performance problems than a couple of extra instructions on the diagonal
1957 #if !defined (umul_ppmm)
1958 #define umul_ppmm(w1, w0, u, v) \
1960 UWtype __x0, __x1, __x2, __x3; \
1961 UHWtype __ul, __vl, __uh, __vh; \
1962 UWtype __u = (u), __v = (v); \
1964 __ul = __ll_lowpart (__u); \
1965 __uh = __ll_highpart (__u); \
1966 __vl = __ll_lowpart (__v); \
1967 __vh = __ll_highpart (__v); \
1969 __x0 = (UWtype) __ul * __vl; \
1970 __x1 = (UWtype) __ul * __vh; \
1971 __x2 = (UWtype) __uh * __vl; \
1972 __x3 = (UWtype) __uh * __vh; \
1974 __x1 += __ll_highpart (__x0);/* this can't give carry */ \
1975 __x1 += __x2; /* but this indeed can */ \
1976 if (__x1 < __x2) /* did we get it? */ \
1977 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
1979 (w1) = __x3 + __ll_highpart (__x1); \
1980 (w0) = (__x1 << W_TYPE_SIZE/2) + __ll_lowpart (__x0); \
1984 /* If we don't have smul_ppmm, define it using umul_ppmm (which surely will
1985 exist in one form or another. */
1986 #if !defined (smul_ppmm)
1987 #define smul_ppmm(w1, w0, u, v) \
1990 UWtype __xm0 = (u), __xm1 = (v); \
1991 umul_ppmm (__w1, w0, __xm0, __xm1); \
1992 (w1) = __w1 - (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1) \
1993 - (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0); \
1997 /* Define this unconditionally, so it can be used for debugging. */
1998 #define __udiv_qrnnd_c(q, r, n1, n0, d) \
2000 UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \
2002 ASSERT ((d) != 0); \
2003 ASSERT ((n1) < (d)); \
2005 __d1 = __ll_highpart (d); \
2006 __d0 = __ll_lowpart (d); \
2008 __q1 = (n1) / __d1; \
2009 __r1 = (n1) - __q1 * __d1; \
2010 __m = __q1 * __d0; \
2011 __r1 = __r1 * __ll_B | __ll_highpart (n0); \
2014 __q1--, __r1 += (d); \
2015 if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
2017 __q1--, __r1 += (d); \
2021 __q0 = __r1 / __d1; \
2022 __r0 = __r1 - __q0 * __d1; \
2023 __m = __q0 * __d0; \
2024 __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
2027 __q0--, __r0 += (d); \
2030 __q0--, __r0 += (d); \
2034 (q) = __q1 * __ll_B | __q0; \
2038 /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
2039 __udiv_w_sdiv (defined in libgcc or elsewhere). */
2040 #if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
2041 #define udiv_qrnnd(q, r, nh, nl, d) \
2044 (q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d); \
2047 __GMP_DECLSPEC UWtype
__MPN(udiv_w_sdiv
) (UWtype
*, UWtype
, UWtype
, UWtype
);
2050 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
2051 #if !defined (udiv_qrnnd)
2052 #define UDIV_NEEDS_NORMALIZATION 1
2053 #define udiv_qrnnd __udiv_qrnnd_c
2056 #if !defined (count_leading_zeros)
2057 #define count_leading_zeros(count, x) \
2059 UWtype __xr = (x); \
2062 if (W_TYPE_SIZE == 32) \
2064 __a = __xr < ((UWtype) 1 << 2*__BITS4) \
2065 ? (__xr < ((UWtype) 1 << __BITS4) ? 1 : __BITS4 + 1) \
2066 : (__xr < ((UWtype) 1 << 3*__BITS4) ? 2*__BITS4 + 1 \
2071 for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
2072 if (((__xr >> __a) & 0xff) != 0) \
2077 (count) = W_TYPE_SIZE + 1 - __a - __clz_tab[__xr >> __a]; \
2079 /* This version gives a well-defined value for zero. */
2080 #define COUNT_LEADING_ZEROS_0 (W_TYPE_SIZE - 1)
2081 #define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
2082 #define COUNT_LEADING_ZEROS_SLOW
2085 /* clz_tab needed by mpn/x86/pentium/mod_1.asm in a fat binary */
2086 #if HAVE_HOST_CPU_FAMILY_x86 && WANT_FAT_BINARY
2087 #define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
2090 #ifdef COUNT_LEADING_ZEROS_NEED_CLZ_TAB
2091 extern const unsigned char __GMP_DECLSPEC __clz_tab
[129];
2094 #if !defined (count_trailing_zeros)
2095 #if !defined (COUNT_LEADING_ZEROS_SLOW)
2096 /* Define count_trailing_zeros using an asm count_leading_zeros. */
2097 #define count_trailing_zeros(count, x) \
2099 UWtype __ctz_x = (x); \
2101 ASSERT (__ctz_x != 0); \
2102 count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x); \
2103 (count) = W_TYPE_SIZE - 1 - __ctz_c; \
2106 /* Define count_trailing_zeros in plain C, assuming small counts are common.
2107 We use clz_tab without ado, since the C count_leading_zeros above will have
2109 #define count_trailing_zeros(count, x) \
2111 UWtype __ctz_x = (x); \
2114 if (LIKELY ((__ctz_x & 0xff) != 0)) \
2115 (count) = __clz_tab[__ctz_x & -__ctz_x] - 2; \
2118 for (__ctz_c = 8 - 2; __ctz_c < W_TYPE_SIZE - 2; __ctz_c += 8) \
2121 if (LIKELY ((__ctz_x & 0xff) != 0)) \
2125 (count) = __ctz_c + __clz_tab[__ctz_x & -__ctz_x]; \
2131 #ifndef UDIV_NEEDS_NORMALIZATION
2132 #define UDIV_NEEDS_NORMALIZATION 0
2135 /* Whether udiv_qrnnd is actually implemented with udiv_qrnnd_preinv, and
2136 that hence the latter should always be used. */
2137 #ifndef UDIV_PREINV_ALWAYS
2138 #define UDIV_PREINV_ALWAYS 0
2141 /* Give defaults for UMUL_TIME and UDIV_TIME. */
2147 #define UDIV_TIME UMUL_TIME