1 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
2 Copyright (C) 1991,92,93,94,96,97,98,99 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 /* You have to define the following before including this file:
22 UWtype -- An unsigned type, default type for operations (typically a "word")
23 UHWtype -- An unsigned type, at least half the size of UWtype.
24 UDWtype -- An unsigned type, at least twice as large a UWtype
25 W_TYPE_SIZE -- size in bits of UWtype
27 SItype, USItype -- Signed and unsigned 32 bit types.
28 DItype, UDItype -- Signed and unsigned 64 bit types.
30 On a 32 bit machine UWtype should typically be USItype;
31 on a 64 bit machine, UWtype should typically be UDItype.
34 #define __BITS4 (W_TYPE_SIZE / 4)
35 #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
36 #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
37 #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
39 /* This is used to make sure no undesirable sharing between different libraries
40 that use this file takes place. */
42 #define __MPN(x) __##x
46 # if defined __GNUC__ || (defined (__STDC__) && __STDC__) \
47 || defined (__cplusplus)
48 # define __P(args) args
54 /* Define auxiliary asm macros.
56 1) umul_ppmm(high_prod, low_prod, multipler, multiplicand) multiplies two
57 UWtype integers MULTIPLER and MULTIPLICAND, and generates a two UWtype
58 word product in HIGH_PROD and LOW_PROD.
60 2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a
61 UDWtype product. This is just a variant of umul_ppmm.
63 3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
64 denominator) divides a UDWtype, composed by the UWtype integers
65 HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
66 in QUOTIENT and the remainder in REMAINDER. HIGH_NUMERATOR must be less
67 than DENOMINATOR for correct operation. If, in addition, the most
68 significant bit of DENOMINATOR must be 1, then the pre-processor symbol
69 UDIV_NEEDS_NORMALIZATION is defined to 1.
71 4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
72 denominator). Like udiv_qrnnd but the numbers are signed. The quotient
75 5) count_leading_zeros(count, x) counts the number of zero-bits from the
76 msb to the first non-zero bit in the UWtype X. This is the number of
77 steps X needs to be shifted left to set the msb. Undefined for X == 0,
78 unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.
80 6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
81 from the least significant end.
83 7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
84 high_addend_2, low_addend_2) adds two UWtype integers, composed by
85 HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2
86 respectively. The result is placed in HIGH_SUM and LOW_SUM. Overflow
87 (i.e. carry out) is not stored anywhere, and is lost.
89 8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend,
90 high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers,
91 composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and
92 LOW_SUBTRAHEND_2 respectively. The result is placed in HIGH_DIFFERENCE
93 and LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere,
96 If any of these macros are left undefined for a particular CPU,
99 /* The CPUs come in alphabetical order below.
101 Please add support for more CPUs here, or improve the current support
102 for the CPUs below! */
104 #if defined (__GNUC__) && !defined (NO_ASM)
106 /* We sometimes need to clobber "cc" with gcc2, but that would not be
107 understood by gcc1. Use cpp to avoid major code duplication. */
110 #define __AND_CLOBBER_CC
111 #else /* __GNUC__ >= 2 */
112 #define __CLOBBER_CC : "cc"
113 #define __AND_CLOBBER_CC , "cc"
114 #endif /* __GNUC__ < 2 */
116 #if (defined (__a29k__) || defined (_AM29K)) && W_TYPE_SIZE == 32
117 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
118 __asm__ ("add %1,%4,%5
120 : "=r" ((USItype)(sh)), \
121 "=&r" ((USItype)(sl)) \
122 : "%r" ((USItype)(ah)), \
123 "rI" ((USItype)(bh)), \
124 "%r" ((USItype)(al)), \
125 "rI" ((USItype)(bl)))
126 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
127 __asm__ ("sub %1,%4,%5
129 : "=r" ((USItype)(sh)), \
130 "=&r" ((USItype)(sl)) \
131 : "r" ((USItype)(ah)), \
132 "rI" ((USItype)(bh)), \
133 "r" ((USItype)(al)), \
134 "rI" ((USItype)(bl)))
135 #define umul_ppmm(xh, xl, m0, m1) \
137 USItype __m0 = (m0), __m1 = (m1); \
138 __asm__ ("multiplu %0,%1,%2" \
139 : "=r" ((USItype)(xl)) \
142 __asm__ ("multmu %0,%1,%2" \
143 : "=r" ((USItype)(xh)) \
147 #define udiv_qrnnd(q, r, n1, n0, d) \
148 __asm__ ("dividu %0,%3,%4" \
149 : "=r" ((USItype)(q)), \
150 "=q" ((USItype)(r)) \
151 : "1" ((USItype)(n1)), \
152 "r" ((USItype)(n0)), \
154 #define count_leading_zeros(count, x) \
155 __asm__ ("clz %0,%1" \
156 : "=r" ((USItype)(count)) \
157 : "r" ((USItype)(x)))
158 #define COUNT_LEADING_ZEROS_0 32
159 #endif /* __a29k__ */
161 #if defined (__alpha) && W_TYPE_SIZE == 64
162 #define umul_ppmm(ph, pl, m0, m1) \
164 UDItype __m0 = (m0), __m1 = (m1); \
165 __asm__ ("umulh %r1,%2,%0" \
166 : "=r" ((UDItype) ph) \
169 (pl) = __m0 * __m1; \
172 #ifndef LONGLONG_STANDALONE
173 #define udiv_qrnnd(q, r, n1, n0, d) \
175 (q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \
178 extern UDItype __udiv_qrnnd __P ((UDItype *, UDItype, UDItype, UDItype));
179 #define UDIV_TIME 220
180 #endif /* LONGLONG_STANDALONE */
183 #if defined (__arm__) && W_TYPE_SIZE == 32
184 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
185 __asm__ ("adds %1, %4, %5
187 : "=r" ((USItype)(sh)), \
188 "=&r" ((USItype)(sl)) \
189 : "%r" ((USItype)(ah)), \
190 "rI" ((USItype)(bh)), \
191 "%r" ((USItype)(al)), \
192 "rI" ((USItype)(bl)))
193 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
194 __asm__ ("subs %1, %4, %5
196 : "=r" ((USItype)(sh)), \
197 "=&r" ((USItype)(sl)) \
198 : "r" ((USItype)(ah)), \
199 "rI" ((USItype)(bh)), \
200 "r" ((USItype)(al)), \
201 "rI" ((USItype)(bl)))
203 #define umul_ppmm(xh, xl, a, b) \
204 __asm__ ("%@ Inlined umul_ppmm
205 mov %|r0, %2, lsr #16
206 mov %|r2, %3, lsr #16
207 bic %|r1, %2, %|r0, lsl #16
208 bic %|r2, %3, %|r2, lsl #16
213 adds %|r1, %|r2, %|r1
215 adds %1, %1, %|r1, lsl #16
216 adc %0, %0, %|r1, lsr #16" \
217 : "=&r" ((USItype)(xh)), \
218 "=r" ((USItype)(xl)) \
219 : "r" ((USItype)(a)), \
223 #define UDIV_TIME 100
227 #if defined (__clipper__) && W_TYPE_SIZE == 32
228 #define umul_ppmm(w1, w0, u, v) \
229 ({union {UDItype __ll; \
230 struct {USItype __l, __h;} __i; \
232 __asm__ ("mulwux %2,%0" \
234 : "%0" ((USItype)(u)), \
235 "r" ((USItype)(v))); \
236 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
237 #define smul_ppmm(w1, w0, u, v) \
238 ({union {DItype __ll; \
239 struct {SItype __l, __h;} __i; \
241 __asm__ ("mulwx %2,%0" \
243 : "%0" ((SItype)(u)), \
244 "r" ((SItype)(v))); \
245 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
246 #define __umulsidi3(u, v) \
248 __asm__ ("mulwux %2,%0" \
250 : "%0" ((USItype)(u)), \
251 "r" ((USItype)(v))); \
253 #endif /* __clipper__ */
255 #if defined (__gmicro__) && W_TYPE_SIZE == 32
256 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
257 __asm__ ("add.w %5,%1
259 : "=g" ((USItype)(sh)), \
260 "=&g" ((USItype)(sl)) \
261 : "%0" ((USItype)(ah)), \
262 "g" ((USItype)(bh)), \
263 "%1" ((USItype)(al)), \
265 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
266 __asm__ ("sub.w %5,%1
268 : "=g" ((USItype)(sh)), \
269 "=&g" ((USItype)(sl)) \
270 : "0" ((USItype)(ah)), \
271 "g" ((USItype)(bh)), \
272 "1" ((USItype)(al)), \
274 #define umul_ppmm(ph, pl, m0, m1) \
275 __asm__ ("mulx %3,%0,%1" \
276 : "=g" ((USItype)(ph)), \
277 "=r" ((USItype)(pl)) \
278 : "%0" ((USItype)(m0)), \
280 #define udiv_qrnnd(q, r, nh, nl, d) \
281 __asm__ ("divx %4,%0,%1" \
282 : "=g" ((USItype)(q)), \
283 "=r" ((USItype)(r)) \
284 : "1" ((USItype)(nh)), \
285 "0" ((USItype)(nl)), \
287 #define count_leading_zeros(count, x) \
288 __asm__ ("bsch/1 %1,%0" \
290 : "g" ((USItype)(x)), \
294 #if defined (__hppa) && W_TYPE_SIZE == 32
295 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
296 __asm__ ("add %4,%5,%1
298 : "=r" ((USItype)(sh)), \
299 "=&r" ((USItype)(sl)) \
300 : "%rM" ((USItype)(ah)), \
301 "rM" ((USItype)(bh)), \
302 "%rM" ((USItype)(al)), \
303 "rM" ((USItype)(bl)))
304 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
305 __asm__ ("sub %4,%5,%1
307 : "=r" ((USItype)(sh)), \
308 "=&r" ((USItype)(sl)) \
309 : "rM" ((USItype)(ah)), \
310 "rM" ((USItype)(bh)), \
311 "rM" ((USItype)(al)), \
312 "rM" ((USItype)(bl)))
313 #if defined (_PA_RISC1_1)
314 #define umul_ppmm(wh, wl, u, v) \
316 union {UDItype __ll; \
317 struct {USItype __h, __l;} __i; \
319 __asm__ ("xmpyu %1,%2,%0" \
320 : "=*f" (__xx.__ll) \
321 : "*f" ((USItype)(u)), \
322 "*f" ((USItype)(v))); \
323 (wh) = __xx.__i.__h; \
324 (wl) = __xx.__i.__l; \
332 #ifndef LONGLONG_STANDALONE
333 #define udiv_qrnnd(q, r, n1, n0, d) \
335 (q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \
338 extern USItype __udiv_qrnnd ();
339 #endif /* LONGLONG_STANDALONE */
340 #define count_leading_zeros(count, x) \
345 extru,= %1,15,16,%%r0 ; Bits 31..16 zero?
346 extru,tr %1,15,16,%1 ; No. Shift down, skip add.
347 ldo 16(%0),%0 ; Yes. Perform add.
348 extru,= %1,23,8,%%r0 ; Bits 15..8 zero?
349 extru,tr %1,23,8,%1 ; No. Shift down, skip add.
350 ldo 8(%0),%0 ; Yes. Perform add.
351 extru,= %1,27,4,%%r0 ; Bits 7..4 zero?
352 extru,tr %1,27,4,%1 ; No. Shift down, skip add.
353 ldo 4(%0),%0 ; Yes. Perform add.
354 extru,= %1,29,2,%%r0 ; Bits 3..2 zero?
355 extru,tr %1,29,2,%1 ; No. Shift down, skip add.
356 ldo 2(%0),%0 ; Yes. Perform add.
357 extru %1,30,1,%1 ; Extract bit 1.
358 sub %0,%1,%0 ; Subtract it.
359 " : "=r" (count), "=r" (__tmp) : "1" (x)); \
363 #if (defined (__i370__) || defined (__mvs__)) && W_TYPE_SIZE == 32
364 #define umul_ppmm(xh, xl, m0, m1) \
366 union {UDItype __ll; \
367 struct {USItype __h, __l;} __i; \
369 USItype __m0 = (m0), __m1 = (m1); \
370 __asm__ ("mr %0,%3" \
371 : "=r" (__xx.__i.__h), \
372 "=r" (__xx.__i.__l) \
375 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
376 (xh) += ((((SItype) __m0 >> 31) & __m1) \
377 + (((SItype) __m1 >> 31) & __m0)); \
379 #define smul_ppmm(xh, xl, m0, m1) \
381 union {DItype __ll; \
382 struct {USItype __h, __l;} __i; \
384 __asm__ ("mr %0,%3" \
385 : "=r" (__xx.__i.__h), \
386 "=r" (__xx.__i.__l) \
389 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
391 #define sdiv_qrnnd(q, r, n1, n0, d) \
393 union {DItype __ll; \
394 struct {USItype __h, __l;} __i; \
396 __xx.__i.__h = n1; __xx.__i.__l = n0; \
397 __asm__ ("dr %0,%2" \
399 : "0" (__xx.__ll), "r" (d)); \
400 (q) = __xx.__i.__l; (r) = __xx.__i.__h; \
404 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
405 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
408 : "=r" ((USItype)(sh)), \
409 "=&r" ((USItype)(sl)) \
410 : "%0" ((USItype)(ah)), \
411 "g" ((USItype)(bh)), \
412 "%1" ((USItype)(al)), \
414 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
417 : "=r" ((USItype)(sh)), \
418 "=&r" ((USItype)(sl)) \
419 : "0" ((USItype)(ah)), \
420 "g" ((USItype)(bh)), \
421 "1" ((USItype)(al)), \
423 #define umul_ppmm(w1, w0, u, v) \
425 : "=a" ((USItype)(w0)), \
426 "=d" ((USItype)(w1)) \
427 : "%0" ((USItype)(u)), \
429 #define udiv_qrnnd(q, r, n1, n0, d) \
431 : "=a" ((USItype)(q)), \
432 "=d" ((USItype)(r)) \
433 : "0" ((USItype)(n0)), \
434 "1" ((USItype)(n1)), \
436 #define count_leading_zeros(count, x) \
439 __asm__ ("bsrl %1,%0" \
440 : "=r" (__cbtmp) : "rm" ((USItype)(x))); \
441 (count) = __cbtmp ^ 31; \
443 #define count_trailing_zeros(count, x) \
444 __asm__ ("bsfl %1,%0" : "=r" (count) : "rm" ((USItype)(x)))
453 #if defined (__i860__) && W_TYPE_SIZE == 32
454 #define rshift_rhlc(r,h,l,c) \
455 __asm__ ("shr %3,r0,r0\;shrd %1,%2,%0" \
456 "=r" (r) : "r" (h), "r" (l), "rn" (c))
459 #if defined (__i960__) && W_TYPE_SIZE == 32
460 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
461 __asm__ ("cmpo 1,0\;addc %5,%4,%1\;addc %3,%2,%0" \
462 : "=r" ((USItype)(sh)), \
463 "=&r" ((USItype)(sl)) \
464 : "%dI" ((USItype)(ah)), \
465 "dI" ((USItype)(bh)), \
466 "%dI" ((USItype)(al)), \
467 "dI" ((USItype)(bl)))
468 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
469 __asm__ ("cmpo 0,0\;subc %5,%4,%1\;subc %3,%2,%0" \
470 : "=r" ((USItype)(sh)), \
471 "=&r" ((USItype)(sl)) \
472 : "dI" ((USItype)(ah)), \
473 "dI" ((USItype)(bh)), \
474 "dI" ((USItype)(al)), \
475 "dI" ((USItype)(bl)))
476 #define umul_ppmm(w1, w0, u, v) \
477 ({union {UDItype __ll; \
478 struct {USItype __l, __h;} __i; \
480 __asm__ ("emul %2,%1,%0" \
482 : "%dI" ((USItype)(u)), \
483 "dI" ((USItype)(v))); \
484 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
485 #define __umulsidi3(u, v) \
487 __asm__ ("emul %2,%1,%0" \
489 : "%dI" ((USItype)(u)), \
490 "dI" ((USItype)(v))); \
492 #define udiv_qrnnd(q, r, nh, nl, d) \
494 union {UDItype __ll; \
495 struct {USItype __l, __h;} __i; \
497 __nn.__i.__h = (nh); __nn.__i.__l = (nl); \
498 __asm__ ("ediv %d,%n,%0" \
500 : "dI" (__nn.__ll), \
501 "dI" ((USItype)(d))); \
502 (r) = __rq.__i.__l; (q) = __rq.__i.__h; \
504 #define count_leading_zeros(count, x) \
507 __asm__ ("scanbit %1,%0" \
509 : "r" ((USItype)(x))); \
510 (count) = __cbtmp ^ 31; \
512 #define COUNT_LEADING_ZEROS_0 (-32) /* sic */
513 #if defined (__i960mx) /* what is the proper symbol to test??? */
514 #define rshift_rhlc(r,h,l,c) \
516 union {UDItype __ll; \
517 struct {USItype __l, __h;} __i; \
519 __nn.__i.__h = (h); __nn.__i.__l = (l); \
520 __asm__ ("shre %2,%1,%0" \
521 : "=d" (r) : "dI" (__nn.__ll), "dI" (c)); \
526 #if (defined (__mc68000__) || defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) && W_TYPE_SIZE == 32
527 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
528 __asm__ ("add%.l %5,%1
530 : "=d" ((USItype)(sh)), \
531 "=&d" ((USItype)(sl)) \
532 : "%0" ((USItype)(ah)), \
533 "d" ((USItype)(bh)), \
534 "%1" ((USItype)(al)), \
536 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
537 __asm__ ("sub%.l %5,%1
539 : "=d" ((USItype)(sh)), \
540 "=&d" ((USItype)(sl)) \
541 : "0" ((USItype)(ah)), \
542 "d" ((USItype)(bh)), \
543 "1" ((USItype)(al)), \
545 #if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
546 #define umul_ppmm(w1, w0, u, v) \
547 __asm__ ("mulu%.l %3,%1:%0" \
548 : "=d" ((USItype)(w0)), \
549 "=d" ((USItype)(w1)) \
550 : "%0" ((USItype)(u)), \
551 "dmi" ((USItype)(v)))
553 #define udiv_qrnnd(q, r, n1, n0, d) \
554 __asm__ ("divu%.l %4,%1:%0" \
555 : "=d" ((USItype)(q)), \
556 "=d" ((USItype)(r)) \
557 : "0" ((USItype)(n0)), \
558 "1" ((USItype)(n1)), \
559 "dmi" ((USItype)(d)))
561 #define sdiv_qrnnd(q, r, n1, n0, d) \
562 __asm__ ("divs%.l %4,%1:%0" \
563 : "=d" ((USItype)(q)), \
564 "=d" ((USItype)(r)) \
565 : "0" ((USItype)(n0)), \
566 "1" ((USItype)(n1)), \
567 "dmi" ((USItype)(d)))
568 #define count_leading_zeros(count, x) \
569 __asm__ ("bfffo %1{%b2:%b2},%0" \
570 : "=d" ((USItype)(count)) \
571 : "od" ((USItype)(x)), "n" (0))
572 #define COUNT_LEADING_ZEROS_0 32
573 #else /* not mc68020 */
574 #define umul_ppmm(xh, xl, a, b) \
575 do { USItype __umul_tmp1, __umul_tmp2; \
576 __asm__ ("| Inlined umul_ppmm
597 | End inlined umul_ppmm" \
598 : "=&d" ((USItype)(xh)), "=&d" ((USItype)(xl)), \
599 "=d" (__umul_tmp1), "=&d" (__umul_tmp2) \
600 : "%2" ((USItype)(a)), "d" ((USItype)(b))); \
602 #define UMUL_TIME 100
603 #define UDIV_TIME 400
604 #endif /* not mc68020 */
607 #if defined (__m88000__) && W_TYPE_SIZE == 32
608 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
609 __asm__ ("addu.co %1,%r4,%r5
610 addu.ci %0,%r2,%r3" \
611 : "=r" ((USItype)(sh)), \
612 "=&r" ((USItype)(sl)) \
613 : "%rJ" ((USItype)(ah)), \
614 "rJ" ((USItype)(bh)), \
615 "%rJ" ((USItype)(al)), \
616 "rJ" ((USItype)(bl)))
617 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
618 __asm__ ("subu.co %1,%r4,%r5
619 subu.ci %0,%r2,%r3" \
620 : "=r" ((USItype)(sh)), \
621 "=&r" ((USItype)(sl)) \
622 : "rJ" ((USItype)(ah)), \
623 "rJ" ((USItype)(bh)), \
624 "rJ" ((USItype)(al)), \
625 "rJ" ((USItype)(bl)))
626 #define count_leading_zeros(count, x) \
629 __asm__ ("ff1 %0,%1" \
631 : "r" ((USItype)(x))); \
632 (count) = __cbtmp ^ 31; \
634 #define COUNT_LEADING_ZEROS_0 63 /* sic */
635 #if defined (__m88110__)
636 #define umul_ppmm(wh, wl, u, v) \
638 union {UDItype __ll; \
639 struct {USItype __h, __l;} __i; \
641 __asm__ ("mulu.d %0,%1,%2" \
643 : "r" ((USItype)(u)), \
644 "r" ((USItype)(v))); \
645 (wh) = __xx.__i.__h; \
646 (wl) = __xx.__i.__l; \
648 #define udiv_qrnnd(q, r, n1, n0, d) \
649 ({union {UDItype __ll; \
650 struct {USItype __h, __l;} __i; \
653 __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
654 __asm__ ("divu.d %0,%1,%2" \
657 "r" ((USItype)(d))); \
658 (r) = (n0) - __q * (d); (q) = __q; })
663 #define UDIV_TIME 150
664 #endif /* __m88110__ */
665 #endif /* __m88000__ */
667 #if defined (__mips__) && W_TYPE_SIZE == 32
668 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 7
669 #define umul_ppmm(w1, w0, u, v) \
670 __asm__ ("multu %2,%3" \
671 : "=l" ((USItype)(w0)), \
672 "=h" ((USItype)(w1)) \
673 : "d" ((USItype)(u)), \
676 #define umul_ppmm(w1, w0, u, v) \
677 __asm__ ("multu %2,%3
680 : "=d" ((USItype)(w0)), \
681 "=d" ((USItype)(w1)) \
682 : "d" ((USItype)(u)), \
686 #define UDIV_TIME 100
687 #endif /* __mips__ */
689 #if (defined (__mips) && __mips >= 3) && W_TYPE_SIZE == 64
690 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 7
691 #define umul_ppmm(w1, w0, u, v) \
692 __asm__ ("dmultu %2,%3" \
693 : "=l" ((UDItype)(w0)), \
694 "=h" ((UDItype)(w1)) \
695 : "d" ((UDItype)(u)), \
698 #define umul_ppmm(w1, w0, u, v) \
699 __asm__ ("dmultu %2,%3
702 : "=d" ((UDItype)(w0)), \
703 "=d" ((UDItype)(w1)) \
704 : "d" ((UDItype)(u)), \
708 #define UDIV_TIME 140
709 #endif /* __mips__ */
711 #if defined (__ns32000__) && W_TYPE_SIZE == 32
712 #define umul_ppmm(w1, w0, u, v) \
713 ({union {UDItype __ll; \
714 struct {USItype __l, __h;} __i; \
716 __asm__ ("meid %2,%0" \
718 : "%0" ((USItype)(u)), \
719 "g" ((USItype)(v))); \
720 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
721 #define __umulsidi3(u, v) \
723 __asm__ ("meid %2,%0" \
725 : "%0" ((USItype)(u)), \
726 "g" ((USItype)(v))); \
728 #define udiv_qrnnd(q, r, n1, n0, d) \
729 ({union {UDItype __ll; \
730 struct {USItype __l, __h;} __i; \
732 __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
733 __asm__ ("deid %2,%0" \
736 "g" ((USItype)(d))); \
737 (r) = __xx.__i.__l; (q) = __xx.__i.__h; })
738 #define count_trailing_zeros(count,x) \
740 __asm__ ("ffsd %2,%0" \
741 : "=r" ((USItype) (count)) \
742 : "0" ((USItype) 0), \
743 "r" ((USItype) (x))); \
745 #endif /* __ns32000__ */
747 #if (defined (_ARCH_PPC) || defined (_IBMR2)) && W_TYPE_SIZE == 32
748 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
750 if (__builtin_constant_p (bh) && (bh) == 0) \
751 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
752 : "=r" ((USItype)(sh)), \
753 "=&r" ((USItype)(sl)) \
754 : "%r" ((USItype)(ah)), \
755 "%r" ((USItype)(al)), \
756 "rI" ((USItype)(bl))); \
757 else if (__builtin_constant_p (bh) && (bh) ==~(USItype) 0) \
758 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
759 : "=r" ((USItype)(sh)), \
760 "=&r" ((USItype)(sl)) \
761 : "%r" ((USItype)(ah)), \
762 "%r" ((USItype)(al)), \
763 "rI" ((USItype)(bl))); \
765 __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
766 : "=r" ((USItype)(sh)), \
767 "=&r" ((USItype)(sl)) \
768 : "%r" ((USItype)(ah)), \
769 "r" ((USItype)(bh)), \
770 "%r" ((USItype)(al)), \
771 "rI" ((USItype)(bl))); \
773 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
775 if (__builtin_constant_p (ah) && (ah) == 0) \
776 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
777 : "=r" ((USItype)(sh)), \
778 "=&r" ((USItype)(sl)) \
779 : "r" ((USItype)(bh)), \
780 "rI" ((USItype)(al)), \
781 "r" ((USItype)(bl))); \
782 else if (__builtin_constant_p (ah) && (ah) ==~(USItype) 0) \
783 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
784 : "=r" ((USItype)(sh)), \
785 "=&r" ((USItype)(sl)) \
786 : "r" ((USItype)(bh)), \
787 "rI" ((USItype)(al)), \
788 "r" ((USItype)(bl))); \
789 else if (__builtin_constant_p (bh) && (bh) == 0) \
790 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
791 : "=r" ((USItype)(sh)), \
792 "=&r" ((USItype)(sl)) \
793 : "r" ((USItype)(ah)), \
794 "rI" ((USItype)(al)), \
795 "r" ((USItype)(bl))); \
796 else if (__builtin_constant_p (bh) && (bh) ==~(USItype) 0) \
797 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
798 : "=r" ((USItype)(sh)), \
799 "=&r" ((USItype)(sl)) \
800 : "r" ((USItype)(ah)), \
801 "rI" ((USItype)(al)), \
802 "r" ((USItype)(bl))); \
804 __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
805 : "=r" ((USItype)(sh)), \
806 "=&r" ((USItype)(sl)) \
807 : "r" ((USItype)(ah)), \
808 "r" ((USItype)(bh)), \
809 "rI" ((USItype)(al)), \
810 "r" ((USItype)(bl))); \
812 #define count_leading_zeros(count, x) \
813 __asm__ ("{cntlz|cntlzw} %0,%1" \
814 : "=r" ((USItype)(count)) \
815 : "r" ((USItype)(x)))
816 #define COUNT_LEADING_ZEROS_0 32
817 #if defined (_ARCH_PPC)
818 #define umul_ppmm(ph, pl, m0, m1) \
820 USItype __m0 = (m0), __m1 = (m1); \
821 __asm__ ("mulhwu %0,%1,%2" \
822 : "=r" ((USItype) ph) \
825 (pl) = __m0 * __m1; \
828 #define smul_ppmm(ph, pl, m0, m1) \
830 SItype __m0 = (m0), __m1 = (m1); \
831 __asm__ ("mulhw %0,%1,%2" \
832 : "=r" ((SItype) ph) \
835 (pl) = __m0 * __m1; \
838 #define UDIV_TIME 120
840 #define umul_ppmm(xh, xl, m0, m1) \
842 USItype __m0 = (m0), __m1 = (m1); \
843 __asm__ ("mul %0,%2,%3" \
844 : "=r" ((USItype)(xh)), \
845 "=q" ((USItype)(xl)) \
848 (xh) += ((((SItype) __m0 >> 31) & __m1) \
849 + (((SItype) __m1 >> 31) & __m0)); \
852 #define smul_ppmm(xh, xl, m0, m1) \
853 __asm__ ("mul %0,%2,%3" \
854 : "=r" ((SItype)(xh)), \
855 "=q" ((SItype)(xl)) \
859 #define sdiv_qrnnd(q, r, nh, nl, d) \
860 __asm__ ("div %0,%2,%4" \
861 : "=r" ((SItype)(q)), "=q" ((SItype)(r)) \
862 : "r" ((SItype)(nh)), "1" ((SItype)(nl)), "r" ((SItype)(d)))
863 #define UDIV_TIME 100
865 #endif /* Power architecture variants. */
867 #if defined (__pyr__) && W_TYPE_SIZE == 32
868 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
871 : "=r" ((USItype)(sh)), \
872 "=&r" ((USItype)(sl)) \
873 : "%0" ((USItype)(ah)), \
874 "g" ((USItype)(bh)), \
875 "%1" ((USItype)(al)), \
877 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
880 : "=r" ((USItype)(sh)), \
881 "=&r" ((USItype)(sl)) \
882 : "0" ((USItype)(ah)), \
883 "g" ((USItype)(bh)), \
884 "1" ((USItype)(al)), \
886 /* This insn works on Pyramids with AP, XP, or MI CPUs, but not with SP. */
887 #define umul_ppmm(w1, w0, u, v) \
888 ({union {UDItype __ll; \
889 struct {USItype __h, __l;} __i; \
891 __asm__ ("movw %1,%R0
893 : "=&r" (__xx.__ll) \
894 : "g" ((USItype) (u)), \
895 "g" ((USItype)(v))); \
896 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
899 #if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
900 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
903 : "=r" ((USItype)(sh)), \
904 "=&r" ((USItype)(sl)) \
905 : "%0" ((USItype)(ah)), \
906 "r" ((USItype)(bh)), \
907 "%1" ((USItype)(al)), \
909 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
912 : "=r" ((USItype)(sh)), \
913 "=&r" ((USItype)(sl)) \
914 : "0" ((USItype)(ah)), \
915 "r" ((USItype)(bh)), \
916 "1" ((USItype)(al)), \
918 #define umul_ppmm(ph, pl, m0, m1) \
920 USItype __m0 = (m0), __m1 = (m1); \
942 : "=r" ((USItype)(ph)), \
943 "=r" ((USItype)(pl)) \
947 (ph) += ((((SItype) __m0 >> 31) & __m1) \
948 + (((SItype) __m1 >> 31) & __m0)); \
951 #define UDIV_TIME 200
952 #define count_leading_zeros(count, x) \
954 if ((x) >= 0x10000) \
955 __asm__ ("clz %0,%1" \
956 : "=r" ((USItype)(count)) \
957 : "r" ((USItype)(x) >> 16)); \
960 __asm__ ("clz %0,%1" \
961 : "=r" ((USItype)(count)) \
962 : "r" ((USItype)(x))); \
968 #if defined (__sh2__) && W_TYPE_SIZE == 32
969 #define umul_ppmm(w1, w0, u, v) \
974 : "=r" ((USItype)(w1)), \
975 "=r" ((USItype)(w0)) \
976 : "r" ((USItype)(u)), \
982 #if defined (__sparc__) && W_TYPE_SIZE == 32
983 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
984 __asm__ ("addcc %r4,%5,%1
986 : "=r" ((USItype)(sh)), \
987 "=&r" ((USItype)(sl)) \
988 : "%rJ" ((USItype)(ah)), \
989 "rI" ((USItype)(bh)), \
990 "%rJ" ((USItype)(al)), \
991 "rI" ((USItype)(bl)) \
993 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
994 __asm__ ("subcc %r4,%5,%1
996 : "=r" ((USItype)(sh)), \
997 "=&r" ((USItype)(sl)) \
998 : "rJ" ((USItype)(ah)), \
999 "rI" ((USItype)(bh)), \
1000 "rJ" ((USItype)(al)), \
1001 "rI" ((USItype)(bl)) \
1003 #if defined (__sparc_v8__)
1004 /* Don't match immediate range because, 1) it is not often useful,
1005 2) the 'I' flag thinks of the range as a 13 bit signed interval,
1006 while we want to match a 13 bit interval, sign extended to 32 bits,
1007 but INTERPRETED AS UNSIGNED. */
1008 #define umul_ppmm(w1, w0, u, v) \
1009 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
1010 : "=r" ((USItype)(w1)), \
1011 "=r" ((USItype)(w0)) \
1012 : "r" ((USItype)(u)), \
1015 #ifndef SUPERSPARC /* SuperSPARC's udiv only handles 53 bit dividends */
1016 #define udiv_qrnnd(q, r, n1, n0, d) \
1019 __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0" \
1020 : "=r" ((USItype)(__q)) \
1021 : "r" ((USItype)(n1)), \
1022 "r" ((USItype)(n0)), \
1023 "r" ((USItype)(d))); \
1024 (r) = (n0) - __q * (d); \
1027 #define UDIV_TIME 25
1028 #endif /* SUPERSPARC */
1029 #else /* ! __sparc_v8__ */
1030 #if defined (__sparclite__)
1031 /* This has hardware multiply but not divide. It also has two additional
1032 instructions scan (ffs from high bit) and divscc. */
1033 #define umul_ppmm(w1, w0, u, v) \
1034 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
1035 : "=r" ((USItype)(w1)), \
1036 "=r" ((USItype)(w0)) \
1037 : "r" ((USItype)(u)), \
1040 #define udiv_qrnnd(q, r, n1, n0, d) \
1041 __asm__ ("! Inlined udiv_qrnnd
1042 wr %%g0,%2,%%y ! Not a delayed write for sparclite
1079 1: ! End of inline udiv_qrnnd" \
1080 : "=r" ((USItype)(q)), \
1081 "=r" ((USItype)(r)) \
1082 : "r" ((USItype)(n1)), \
1083 "r" ((USItype)(n0)), \
1084 "rI" ((USItype)(d)) \
1085 : "%g1" __AND_CLOBBER_CC)
1086 #define UDIV_TIME 37
1087 #define count_leading_zeros(count, x) \
1088 __asm__ ("scan %1,0,%0" \
1089 : "=r" ((USItype)(x)) \
1090 : "r" ((USItype)(count)))
1091 /* Early sparclites return 63 for an argument of 0, but they warn that future
1092 implementations might change this. Therefore, leave COUNT_LEADING_ZEROS_0
1094 #endif /* __sparclite__ */
1095 #endif /* __sparc_v8__ */
1096 /* Default to sparc v7 versions of umul_ppmm and udiv_qrnnd. */
1098 #define umul_ppmm(w1, w0, u, v) \
1099 __asm__ ("! Inlined umul_ppmm
1100 wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr
1101 sra %3,31,%%g2 ! Don't move this insn
1102 and %2,%%g2,%%g2 ! Don't move this insn
1103 andcc %%g0,0,%%g1 ! Don't move this insn
1139 : "=r" ((USItype)(w1)), \
1140 "=r" ((USItype)(w0)) \
1141 : "%rI" ((USItype)(u)), \
1142 "r" ((USItype)(v)) \
1143 : "%g1", "%g2" __AND_CLOBBER_CC)
1144 #define UMUL_TIME 39 /* 39 instructions */
1147 /* It's quite necessary to add this much assembler for the sparc.
1148 The default udiv_qrnnd (in C) is more than 10 times slower! */
1149 #define udiv_qrnnd(q, r, n1, n0, d) \
1150 __asm__ ("! Inlined udiv_qrnnd
1154 addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb
1155 sub %1,%2,%1 ! this kills msb of n
1156 addx %1,%1,%1 ! so this can't give carry
1161 addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb
1163 sub %1,%2,%1 ! this kills msb of n
1168 ! Got carry from n. Subtract next step to cancel this carry.
1170 addcc %0,%0,%0 ! shift n1n0 and a 0-bit in lsb
1173 ! End of inline udiv_qrnnd" \
1174 : "=&r" ((USItype)(q)), \
1175 "=&r" ((USItype)(r)) \
1176 : "r" ((USItype)(d)), \
1177 "1" ((USItype)(n1)), \
1178 "0" ((USItype)(n0)) : "%g1" __AND_CLOBBER_CC)
1179 #define UDIV_TIME (3+7*32) /* 7 instructions/iteration. 32 iterations. */
1181 extern USItype __udiv_qrnnd __P ((USItype *, USItype, USItype, USItype));
1183 #define UDIV_TIME 140
1184 #endif /* UDIV_TIME */
1185 #endif /* udiv_qrnnd */
1186 #endif /* __sparc__ */
1188 #if (defined (__sparc_v9__) || (defined (__sparc__) && defined (__arch64__)) \
1189 || defined (__sparcv9)) && W_TYPE_SIZE == 64
1190 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1191 __asm__ ("addcc %4,%5,%1
1196 : "=r" ((UDItype)(sh)), \
1197 "=&r" ((UDItype)(sl)) \
1198 : "r" ((UDItype)(ah)), \
1199 "r" ((UDItype)(bh)), \
1200 "r" ((UDItype)(al)), \
1201 "r" ((UDItype)(bl)) \
1204 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1205 __asm__ ("subcc %4,%5,%1
1210 : "=r" ((UDItype)(sh)), \
1211 "=&r" ((UDItype)(sl)) \
1212 : "r" ((UDItype)(ah)), \
1213 "r" ((UDItype)(bh)), \
1214 "r" ((UDItype)(al)), \
1215 "r" ((UDItype)(bl)) \
1218 #define umul_ppmm(wh, wl, u, v) \
1220 UDItype tmp1, tmp2, tmp3, tmp4; \
1221 __asm__ __volatile__ ( \
1234 sethi %%hi(0x80000000),%2
1243 : "=r" ((UDItype)(wh)), \
1244 "=&r" ((UDItype)(wl)), \
1245 "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4) \
1246 : "r" ((UDItype)(u)), \
1247 "r" ((UDItype)(v)) \
1250 #define UMUL_TIME 96
1251 #define UDIV_TIME 230
1252 #endif /* __sparc_v9__ */
1254 #if defined (__vax__) && W_TYPE_SIZE == 32
1255 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1256 __asm__ ("addl2 %5,%1
1258 : "=g" ((USItype)(sh)), \
1259 "=&g" ((USItype)(sl)) \
1260 : "%0" ((USItype)(ah)), \
1261 "g" ((USItype)(bh)), \
1262 "%1" ((USItype)(al)), \
1263 "g" ((USItype)(bl)))
1264 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1265 __asm__ ("subl2 %5,%1
1267 : "=g" ((USItype)(sh)), \
1268 "=&g" ((USItype)(sl)) \
1269 : "0" ((USItype)(ah)), \
1270 "g" ((USItype)(bh)), \
1271 "1" ((USItype)(al)), \
1272 "g" ((USItype)(bl)))
1273 #define umul_ppmm(xh, xl, m0, m1) \
1275 union {UDItype __ll; \
1276 struct {USItype __l, __h;} __i; \
1278 USItype __m0 = (m0), __m1 = (m1); \
1279 __asm__ ("emul %1,%2,$0,%0" \
1280 : "=g" (__xx.__ll) \
1283 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
1284 (xh) += ((((SItype) __m0 >> 31) & __m1) \
1285 + (((SItype) __m1 >> 31) & __m0)); \
1287 #define sdiv_qrnnd(q, r, n1, n0, d) \
1289 union {DItype __ll; \
1290 struct {SItype __l, __h;} __i; \
1292 __xx.__i.__h = n1; __xx.__i.__l = n0; \
1293 __asm__ ("ediv %3,%2,%0,%1" \
1294 : "=g" (q), "=g" (r) \
1295 : "g" (__xx.ll), "g" (d)); \
1297 #endif /* __vax__ */
1299 #if defined (__z8000__) && W_TYPE_SIZE == 16
1300 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1301 __asm__ ("add %H1,%H5\n\tadc %H0,%H3" \
1302 : "=r" ((unsigned int)(sh)), \
1303 "=&r" ((unsigned int)(sl)) \
1304 : "%0" ((unsigned int)(ah)), \
1305 "r" ((unsigned int)(bh)), \
1306 "%1" ((unsigned int)(al)), \
1307 "rQR" ((unsigned int)(bl)))
1308 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1309 __asm__ ("sub %H1,%H5\n\tsbc %H0,%H3" \
1310 : "=r" ((unsigned int)(sh)), \
1311 "=&r" ((unsigned int)(sl)) \
1312 : "0" ((unsigned int)(ah)), \
1313 "r" ((unsigned int)(bh)), \
1314 "1" ((unsigned int)(al)), \
1315 "rQR" ((unsigned int)(bl)))
1316 #define umul_ppmm(xh, xl, m0, m1) \
1318 union {long int __ll; \
1319 struct {unsigned int __h, __l;} __i; \
1321 unsigned int __m0 = (m0), __m1 = (m1); \
1322 __asm__ ("mult %S0,%H3" \
1323 : "=r" (__xx.__i.__h), \
1324 "=r" (__xx.__i.__l) \
1327 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
1328 (xh) += ((((signed int) __m0 >> 15) & __m1) \
1329 + (((signed int) __m1 >> 15) & __m0)); \
1331 #endif /* __z8000__ */
1333 #endif /* __GNUC__ */
1336 #if !defined (umul_ppmm) && defined (__umulsidi3)
1337 #define umul_ppmm(ph, pl, m0, m1) \
1339 UDWtype __ll = __umulsidi3 (m0, m1); \
1340 ph = (UWtype) (__ll >> W_TYPE_SIZE); \
1341 pl = (UWtype) __ll; \
1345 #if !defined (__umulsidi3)
1346 #define __umulsidi3(u, v) \
1347 ({UWtype __hi, __lo; \
1348 umul_ppmm (__hi, __lo, u, v); \
1349 ((UDWtype) __hi << W_TYPE_SIZE) | __lo; })
1352 /* If this machine has no inline assembler, use C macros. */
1354 #if !defined (add_ssaaaa)
1355 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1358 __x = (al) + (bl); \
1359 (sh) = (ah) + (bh) + (__x < (al)); \
1364 #if !defined (sub_ddmmss)
1365 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1368 __x = (al) - (bl); \
1369 (sh) = (ah) - (bh) - (__x > (al)); \
1374 #if !defined (umul_ppmm)
1375 #define umul_ppmm(w1, w0, u, v) \
1377 UWtype __x0, __x1, __x2, __x3; \
1378 UHWtype __ul, __vl, __uh, __vh; \
1379 UWtype __u = (u), __v = (v); \
1381 __ul = __ll_lowpart (__u); \
1382 __uh = __ll_highpart (__u); \
1383 __vl = __ll_lowpart (__v); \
1384 __vh = __ll_highpart (__v); \
1386 __x0 = (UWtype) __ul * __vl; \
1387 __x1 = (UWtype) __ul * __vh; \
1388 __x2 = (UWtype) __uh * __vl; \
1389 __x3 = (UWtype) __uh * __vh; \
1391 __x1 += __ll_highpart (__x0);/* this can't give carry */ \
1392 __x1 += __x2; /* but this indeed can */ \
1393 if (__x1 < __x2) /* did we get it? */ \
1394 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
1396 (w1) = __x3 + __ll_highpart (__x1); \
1397 (w0) = (__ll_lowpart (__x1) << W_TYPE_SIZE/2) + __ll_lowpart (__x0);\
1401 #if !defined (umul_ppmm)
1402 #define smul_ppmm(w1, w0, u, v) \
1405 UWtype __m0 = (u), __m1 = (v); \
1406 umul_ppmm (__w1, w0, __m0, __m1); \
1407 (w1) = __w1 - (-(__m0 >> (W_TYPE_SIZE - 1)) & __m1) \
1408 - (-(__m1 >> (W_TYPE_SIZE - 1)) & __m0); \
1412 /* Define this unconditionally, so it can be used for debugging. */
1413 #define __udiv_qrnnd_c(q, r, n1, n0, d) \
1415 UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \
1416 __d1 = __ll_highpart (d); \
1417 __d0 = __ll_lowpart (d); \
1419 __r1 = (n1) % __d1; \
1420 __q1 = (n1) / __d1; \
1421 __m = (UWtype) __q1 * __d0; \
1422 __r1 = __r1 * __ll_B | __ll_highpart (n0); \
1425 __q1--, __r1 += (d); \
1426 if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
1428 __q1--, __r1 += (d); \
1432 __r0 = __r1 % __d1; \
1433 __q0 = __r1 / __d1; \
1434 __m = (UWtype) __q0 * __d0; \
1435 __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
1438 __q0--, __r0 += (d); \
1441 __q0--, __r0 += (d); \
1445 (q) = (UWtype) __q1 * __ll_B | __q0; \
1449 /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
1450 __udiv_w_sdiv (defined in libgcc or elsewhere). */
1451 #if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
1452 #define udiv_qrnnd(q, r, nh, nl, d) \
1455 (q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d); \
1460 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
1461 #if !defined (udiv_qrnnd)
1462 #define UDIV_NEEDS_NORMALIZATION 1
1463 #define udiv_qrnnd __udiv_qrnnd_c
1466 #if !defined (count_leading_zeros)
1471 unsigned char __clz_tab[];
1472 #define count_leading_zeros(count, x) \
1474 UWtype __xr = (x); \
1477 if (W_TYPE_SIZE <= 32) \
1479 __a = __xr < ((UWtype) 1 << 2*__BITS4) \
1480 ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \
1481 : (__xr < ((UWtype) 1 << 3*__BITS4) ? 2*__BITS4 : 3*__BITS4);\
1485 for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
1486 if (((__xr >> __a) & 0xff) != 0) \
1490 (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
1492 /* This version gives a well-defined value for zero. */
1493 #define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
1496 #if !defined (count_trailing_zeros)
1497 /* Define count_trailing_zeros using count_leading_zeros. The latter might be
1498 defined in asm, but if it is not, the C version above is good enough. */
1499 #define count_trailing_zeros(count, x) \
1501 UWtype __ctz_x = (x); \
1503 count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x); \
1504 (count) = W_TYPE_SIZE - 1 - __ctz_c; \
1508 #ifndef UDIV_NEEDS_NORMALIZATION
1509 #define UDIV_NEEDS_NORMALIZATION 0