1 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
2 * Note: I added some stuff for use with gnupg
4 * Copyright (C) 1991, 1992, 1993, 1994, 1996, 1998,
5 * 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Library General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * This file is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15 * License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this file; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 * MA 02111-1307, USA. */
22 /* You have to define the following before including this file:
24 * UWtype -- An unsigned type, default type for operations (typically a "word")
25 * UHWtype -- An unsigned type, at least half the size of UWtype.
26 * UDWtype -- An unsigned type, at least twice as large a UWtype
27 * W_TYPE_SIZE -- size in bits of UWtype
29 * SItype, USItype -- Signed and unsigned 32 bit types.
30 * DItype, UDItype -- Signed and unsigned 64 bit types.
32 * On a 32 bit machine UWtype should typically be USItype;
33 * on a 64 bit machine, UWtype should typically be UDItype.
36 #define __BITS4 (W_TYPE_SIZE / 4)
37 #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
38 #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
39 #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
41 /* This is used to make sure no undesirable sharing between different libraries
42 that use this file takes place. */
44 #define __MPN(x) __##x
47 /* Define auxiliary asm macros.
49 * 1) umul_ppmm(high_prod, low_prod, multipler, multiplicand) multiplies two
50 * UWtype integers MULTIPLER and MULTIPLICAND, and generates a two UWtype
51 * word product in HIGH_PROD and LOW_PROD.
53 * 2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a
54 * UDWtype product. This is just a variant of umul_ppmm.
56 * 3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
57 * denominator) divides a UDWtype, composed by the UWtype integers
58 * HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
59 * in QUOTIENT and the remainder in REMAINDER. HIGH_NUMERATOR must be less
60 * than DENOMINATOR for correct operation. If, in addition, the most
61 * significant bit of DENOMINATOR must be 1, then the pre-processor symbol
62 * UDIV_NEEDS_NORMALIZATION is defined to 1.
63 * 4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
64 * denominator). Like udiv_qrnnd but the numbers are signed. The quotient
65 * is rounded towards 0.
67 * 5) count_leading_zeros(count, x) counts the number of zero-bits from the
68 * msb to the first non-zero bit in the UWtype X. This is the number of
69 * steps X needs to be shifted left to set the msb. Undefined for X == 0,
70 * unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.
72 * 6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
73 * from the least significant end.
75 * 7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
76 * high_addend_2, low_addend_2) adds two UWtype integers, composed by
77 * HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2
78 * respectively. The result is placed in HIGH_SUM and LOW_SUM. Overflow
79 * (i.e. carry out) is not stored anywhere, and is lost.
81 * 8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend,
82 * high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers,
83 * composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and
84 * LOW_SUBTRAHEND_2 respectively. The result is placed in HIGH_DIFFERENCE
85 * and LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere,
88 * If any of these macros are left undefined for a particular CPU,
89 * C macros are used. */
91 /* The CPUs come in alphabetical order below.
93 * Please add support for more CPUs here, or improve the current support
94 * for the CPUs below! */
96 #if defined(__GNUC__) && !defined(NO_ASM)
98 /* We sometimes need to clobber "cc" with gcc2, but that would not be
99 understood by gcc1. Use cpp to avoid major code duplication. */
102 #define __AND_CLOBBER_CC
103 #else /* __GNUC__ >= 2 */
104 #define __CLOBBER_CC : "cc"
105 #define __AND_CLOBBER_CC , "cc"
106 #endif /* __GNUC__ < 2 */
108 /***************************************
109 ************** A29K *****************
110 ***************************************/
111 #if (defined(__a29k__) || defined(_AM29K)) && W_TYPE_SIZE == 32
112 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
113 __asm__ ("add %1,%4,%5\n" \
115 : "=r" ((USItype)(sh)), \
116 "=&r" ((USItype)(sl)) \
117 : "%r" ((USItype)(ah)), \
118 "rI" ((USItype)(bh)), \
119 "%r" ((USItype)(al)), \
120 "rI" ((USItype)(bl)))
121 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
122 __asm__ ("sub %1,%4,%5\n" \
124 : "=r" ((USItype)(sh)), \
125 "=&r" ((USItype)(sl)) \
126 : "r" ((USItype)(ah)), \
127 "rI" ((USItype)(bh)), \
128 "r" ((USItype)(al)), \
129 "rI" ((USItype)(bl)))
130 #define umul_ppmm(xh, xl, m0, m1) \
132 USItype __m0 = (m0), __m1 = (m1); \
133 __asm__ ("multiplu %0,%1,%2" \
134 : "=r" ((USItype)(xl)) \
137 __asm__ ("multmu %0,%1,%2" \
138 : "=r" ((USItype)(xh)) \
142 #define udiv_qrnnd(q, r, n1, n0, d) \
143 __asm__ ("dividu %0,%3,%4" \
144 : "=r" ((USItype)(q)), \
145 "=q" ((USItype)(r)) \
146 : "1" ((USItype)(n1)), \
147 "r" ((USItype)(n0)), \
150 #define count_leading_zeros(count, x) \
151 __asm__ ("clz %0,%1" \
152 : "=r" ((USItype)(count)) \
153 : "r" ((USItype)(x)))
154 #define COUNT_LEADING_ZEROS_0 32
155 #endif /* __a29k__ */
157 #if defined(__alpha) && W_TYPE_SIZE == 64
158 #define umul_ppmm(ph, pl, m0, m1) \
160 UDItype __m0 = (m0), __m1 = (m1); \
161 __asm__ ("umulh %r1,%2,%0" \
162 : "=r" ((UDItype) ph) \
165 (pl) = __m0 * __m1; \
168 #ifndef LONGLONG_STANDALONE
169 #define udiv_qrnnd(q, r, n1, n0, d) \
171 (q) = __udiv_qrnnd(&__r, (n1), (n0), (d)); \
174 extern UDItype
__udiv_qrnnd();
175 #define UDIV_TIME 220
176 #endif /* LONGLONG_STANDALONE */
179 /***************************************
180 ************** ARM ******************
181 ***************************************/
182 #if defined(__arm__) && W_TYPE_SIZE == 32
183 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
184 __asm__ ("adds %1, %4, %5\n" \
186 : "=r" ((USItype)(sh)), \
187 "=&r" ((USItype)(sl)) \
188 : "%r" ((USItype)(ah)), \
189 "rI" ((USItype)(bh)), \
190 "%r" ((USItype)(al)), \
191 "rI" ((USItype)(bl)))
192 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
193 __asm__ ("subs %1, %4, %5\n" \
195 : "=r" ((USItype)(sh)), \
196 "=&r" ((USItype)(sl)) \
197 : "r" ((USItype)(ah)), \
198 "rI" ((USItype)(bh)), \
199 "r" ((USItype)(al)), \
200 "rI" ((USItype)(bl)))
201 #if defined __ARM_ARCH_2__ || defined __ARM_ARCH_3__
202 #define umul_ppmm(xh, xl, a, b) \
203 __asm__ ("%@ Inlined umul_ppmm\n" \
204 "mov %|r0, %2, lsr #16 @ AAAA\n" \
205 "mov %|r2, %3, lsr #16 @ BBBB\n" \
206 "bic %|r1, %2, %|r0, lsl #16 @ aaaa\n" \
207 "bic %0, %3, %|r2, lsl #16 @ bbbb\n" \
208 "mul %1, %|r1, %|r2 @ aaaa * BBBB\n" \
209 "mul %|r2, %|r0, %|r2 @ AAAA * BBBB\n" \
210 "mul %|r1, %0, %|r1 @ aaaa * bbbb\n" \
211 "mul %0, %|r0, %0 @ AAAA * bbbb\n" \
212 "adds %|r0, %1, %0 @ central sum\n" \
213 "addcs %|r2, %|r2, #65536\n" \
214 "adds %1, %|r1, %|r0, lsl #16\n" \
215 "adc %0, %|r2, %|r0, lsr #16" \
216 : "=&r" ((USItype)(xh)), \
217 "=r" ((USItype)(xl)) \
218 : "r" ((USItype)(a)), \
222 #define umul_ppmm(xh, xl, a, b) \
223 __asm__ ("%@ Inlined umul_ppmm\n" \
224 "umull %r1, %r0, %r2, %r3" \
225 : "=&r" ((USItype)(xh)), \
226 "=r" ((USItype)(xl)) \
227 : "r" ((USItype)(a)), \
232 #define UDIV_TIME 100
235 /***************************************
236 ************** CLIPPER **************
237 ***************************************/
238 #if defined(__clipper__) && W_TYPE_SIZE == 32
239 #define umul_ppmm(w1, w0, u, v) \
240 ({union {UDItype __ll; \
241 struct {USItype __l, __h; } __i; \
243 __asm__ ("mulwux %2,%0" \
245 : "%0" ((USItype)(u)), \
246 "r" ((USItype)(v))); \
247 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l; })
248 #define smul_ppmm(w1, w0, u, v) \
249 ({union {DItype __ll; \
250 struct {SItype __l, __h; } __i; \
252 __asm__ ("mulwx %2,%0" \
254 : "%0" ((SItype)(u)), \
255 "r" ((SItype)(v))); \
256 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l; })
257 #define __umulsidi3(u, v) \
259 __asm__ ("mulwux %2,%0" \
261 : "%0" ((USItype)(u)), \
262 "r" ((USItype)(v))); \
264 #endif /* __clipper__ */
266 /***************************************
267 ************** GMICRO ***************
268 ***************************************/
269 #if defined(__gmicro__) && W_TYPE_SIZE == 32
270 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
271 __asm__ ("add.w %5,%1\n" \
273 : "=g" ((USItype)(sh)), \
274 "=&g" ((USItype)(sl)) \
275 : "%0" ((USItype)(ah)), \
276 "g" ((USItype)(bh)), \
277 "%1" ((USItype)(al)), \
279 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
280 __asm__ ("sub.w %5,%1\n" \
282 : "=g" ((USItype)(sh)), \
283 "=&g" ((USItype)(sl)) \
284 : "0" ((USItype)(ah)), \
285 "g" ((USItype)(bh)), \
286 "1" ((USItype)(al)), \
288 #define umul_ppmm(ph, pl, m0, m1) \
289 __asm__ ("mulx %3,%0,%1" \
290 : "=g" ((USItype)(ph)), \
291 "=r" ((USItype)(pl)) \
292 : "%0" ((USItype)(m0)), \
294 #define udiv_qrnnd(q, r, nh, nl, d) \
295 __asm__ ("divx %4,%0,%1" \
296 : "=g" ((USItype)(q)), \
297 "=r" ((USItype)(r)) \
298 : "1" ((USItype)(nh)), \
299 "0" ((USItype)(nl)), \
301 #define count_leading_zeros(count, x) \
302 __asm__ ("bsch/1 %1,%0" \
304 : "g" ((USItype)(x)), \
308 /***************************************
309 ************** HPPA *****************
310 ***************************************/
311 #if defined(__hppa) && W_TYPE_SIZE == 32
312 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
313 __asm__ ("add %4,%5,%1\n" \
315 : "=r" ((USItype)(sh)), \
316 "=&r" ((USItype)(sl)) \
317 : "%rM" ((USItype)(ah)), \
318 "rM" ((USItype)(bh)), \
319 "%rM" ((USItype)(al)), \
320 "rM" ((USItype)(bl)))
321 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
322 __asm__ ("sub %4,%5,%1\n" \
324 : "=r" ((USItype)(sh)), \
325 "=&r" ((USItype)(sl)) \
326 : "rM" ((USItype)(ah)), \
327 "rM" ((USItype)(bh)), \
328 "rM" ((USItype)(al)), \
329 "rM" ((USItype)(bl)))
330 #if defined(_PA_RISC1_1)
331 #define umul_ppmm(wh, wl, u, v) \
333 union {UDItype __ll; \
334 struct {USItype __h, __l; } __i; \
336 __asm__ ("xmpyu %1,%2,%0" \
337 : "=*f" (__xx.__ll) \
338 : "*f" ((USItype)(u)), \
339 "*f" ((USItype)(v))); \
340 (wh) = __xx.__i.__h; \
341 (wl) = __xx.__i.__l; \
349 #ifndef LONGLONG_STANDALONE
350 #define udiv_qrnnd(q, r, n1, n0, d) \
352 (q) = __udiv_qrnnd(&__r, (n1), (n0), (d)); \
355 extern USItype
__udiv_qrnnd();
356 #endif /* LONGLONG_STANDALONE */
357 #define count_leading_zeros(count, x) \
362 "extru,= %1,15,16,%%r0 ; Bits 31..16 zero?\n" \
363 "extru,tr %1,15,16,%1 ; No. Shift down, skip add.\n" \
364 "ldo 16(%0),%0 ; Yes. Perform add.\n" \
365 "extru,= %1,23,8,%%r0 ; Bits 15..8 zero?\n" \
366 "extru,tr %1,23,8,%1 ; No. Shift down, skip add.\n" \
367 "ldo 8(%0),%0 ; Yes. Perform add.\n" \
368 "extru,= %1,27,4,%%r0 ; Bits 7..4 zero?\n" \
369 "extru,tr %1,27,4,%1 ; No. Shift down, skip add.\n" \
370 "ldo 4(%0),%0 ; Yes. Perform add.\n" \
371 "extru,= %1,29,2,%%r0 ; Bits 3..2 zero?\n" \
372 "extru,tr %1,29,2,%1 ; No. Shift down, skip add.\n" \
373 "ldo 2(%0),%0 ; Yes. Perform add.\n" \
374 "extru %1,30,1,%1 ; Extract bit 1.\n" \
375 "sub %0,%1,%0 ; Subtract it. " \
376 : "=r" (count), "=r" (__tmp) : "1" (x)); \
380 /***************************************
381 ************** I370 *****************
382 ***************************************/
383 #if (defined(__i370__) || defined(__mvs__)) && W_TYPE_SIZE == 32
384 #define umul_ppmm(xh, xl, m0, m1) \
386 union {UDItype __ll; \
387 struct {USItype __h, __l; } __i; \
389 USItype __m0 = (m0), __m1 = (m1); \
390 __asm__ ("mr %0,%3" \
391 : "=r" (__xx.__i.__h), \
392 "=r" (__xx.__i.__l) \
395 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
396 (xh) += ((((SItype) __m0 >> 31) & __m1) \
397 + (((SItype) __m1 >> 31) & __m0)); \
399 #define smul_ppmm(xh, xl, m0, m1) \
401 union {DItype __ll; \
402 struct {USItype __h, __l; } __i; \
404 __asm__ ("mr %0,%3" \
405 : "=r" (__xx.__i.__h), \
406 "=r" (__xx.__i.__l) \
409 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
411 #define sdiv_qrnnd(q, r, n1, n0, d) \
413 union {DItype __ll; \
414 struct {USItype __h, __l; } __i; \
416 __xx.__i.__h = n1; __xx.__i.__l = n0; \
417 __asm__ ("dr %0,%2" \
419 : "0" (__xx.__ll), "r" (d)); \
420 (q) = __xx.__i.__l; (r) = __xx.__i.__h; \
424 /***************************************
425 ************** I386 *****************
426 ***************************************/
428 #if (defined(__i386__) || defined(__i486__)) && W_TYPE_SIZE == 32
429 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
430 __asm__ ("addl %5,%1\n" \
432 : "=r" ((USItype)(sh)), \
433 "=&r" ((USItype)(sl)) \
434 : "%0" ((USItype)(ah)), \
435 "g" ((USItype)(bh)), \
436 "%1" ((USItype)(al)), \
438 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
439 __asm__ ("subl %5,%1\n" \
441 : "=r" ((USItype)(sh)), \
442 "=&r" ((USItype)(sl)) \
443 : "0" ((USItype)(ah)), \
444 "g" ((USItype)(bh)), \
445 "1" ((USItype)(al)), \
447 #define umul_ppmm(w1, w0, u, v) \
449 : "=a" ((USItype)(w0)), \
450 "=d" ((USItype)(w1)) \
451 : "%0" ((USItype)(u)), \
453 #define udiv_qrnnd(q, r, n1, n0, d) \
455 : "=a" ((USItype)(q)), \
456 "=d" ((USItype)(r)) \
457 : "0" ((USItype)(n0)), \
458 "1" ((USItype)(n1)), \
460 #define count_leading_zeros(count, x) \
463 __asm__ ("bsrl %1,%0" \
464 : "=r" (__cbtmp) : "rm" ((USItype)(x))); \
465 (count) = __cbtmp ^ 31; \
467 #define count_trailing_zeros(count, x) \
468 __asm__ ("bsfl %1,%0" : "=r" (count) : "rm" ((USItype)(x)))
477 /***************************************
478 ************** I860 *****************
479 ***************************************/
480 #if defined(__i860__) && W_TYPE_SIZE == 32
481 #define rshift_rhlc(r, h, l, c) \
482 __asm__ ("shr %3,r0,r0\n" \
484 "=r" (r) : "r" (h), "r" (l), "rn" (c))
487 /***************************************
488 ************** I960 *****************
489 ***************************************/
490 #if defined(__i960__) && W_TYPE_SIZE == 32
491 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
492 __asm__ ("cmpo 1,0\n" \
495 : "=r" ((USItype)(sh)), \
496 "=&r" ((USItype)(sl)) \
497 : "%dI" ((USItype)(ah)), \
498 "dI" ((USItype)(bh)), \
499 "%dI" ((USItype)(al)), \
500 "dI" ((USItype)(bl)))
501 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
502 __asm__ ("cmpo 0,0\n" \
505 : "=r" ((USItype)(sh)), \
506 "=&r" ((USItype)(sl)) \
507 : "dI" ((USItype)(ah)), \
508 "dI" ((USItype)(bh)), \
509 "dI" ((USItype)(al)), \
510 "dI" ((USItype)(bl)))
511 #define umul_ppmm(w1, w0, u, v) \
512 ({union {UDItype __ll; \
513 struct {USItype __l, __h; } __i; \
515 __asm__ ("emul %2,%1,%0" \
517 : "%dI" ((USItype)(u)), \
518 "dI" ((USItype)(v))); \
519 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l; })
520 #define __umulsidi3(u, v) \
522 __asm__ ("emul %2,%1,%0" \
524 : "%dI" ((USItype)(u)), \
525 "dI" ((USItype)(v))); \
527 #define udiv_qrnnd(q, r, nh, nl, d) \
529 union {UDItype __ll; \
530 struct {USItype __l, __h; } __i; \
532 __nn.__i.__h = (nh); __nn.__i.__l = (nl); \
533 __asm__ ("ediv %d,%n,%0" \
535 : "dI" (__nn.__ll), \
536 "dI" ((USItype)(d))); \
537 (r) = __rq.__i.__l; (q) = __rq.__i.__h; \
539 #define count_leading_zeros(count, x) \
542 __asm__ ("scanbit %1,%0" \
544 : "r" ((USItype)(x))); \
545 (count) = __cbtmp ^ 31; \
547 #define COUNT_LEADING_ZEROS_0 (-32) /* sic */
548 #if defined(__i960mx) /* what is the proper symbol to test??? */
549 #define rshift_rhlc(r, h, l, c) \
551 union {UDItype __ll; \
552 struct {USItype __l, __h; } __i; \
554 __nn.__i.__h = (h); __nn.__i.__l = (l); \
555 __asm__ ("shre %2,%1,%0" \
556 : "=d" (r) : "dI" (__nn.__ll), "dI" (c)); \
561 /***************************************
562 ************** 68000 ****************
563 ***************************************/
564 #if (defined(__mc68000__) || defined(__mc68020__) || defined(__NeXT__) || defined(mc68020)) && W_TYPE_SIZE == 32
565 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
566 __asm__ ("add%.l %5,%1\n" \
568 : "=d" ((USItype)(sh)), \
569 "=&d" ((USItype)(sl)) \
570 : "%0" ((USItype)(ah)), \
571 "d" ((USItype)(bh)), \
572 "%1" ((USItype)(al)), \
574 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
575 __asm__ ("sub%.l %5,%1\n" \
577 : "=d" ((USItype)(sh)), \
578 "=&d" ((USItype)(sl)) \
579 : "0" ((USItype)(ah)), \
580 "d" ((USItype)(bh)), \
581 "1" ((USItype)(al)), \
583 #if (defined(__mc68020__) || defined(__NeXT__) || defined(mc68020))
584 #define umul_ppmm(w1, w0, u, v) \
585 __asm__ ("mulu%.l %3,%1:%0" \
586 : "=d" ((USItype)(w0)), \
587 "=d" ((USItype)(w1)) \
588 : "%0" ((USItype)(u)), \
589 "dmi" ((USItype)(v)))
591 #define udiv_qrnnd(q, r, n1, n0, d) \
592 __asm__ ("divu%.l %4,%1:%0" \
593 : "=d" ((USItype)(q)), \
594 "=d" ((USItype)(r)) \
595 : "0" ((USItype)(n0)), \
596 "1" ((USItype)(n1)), \
597 "dmi" ((USItype)(d)))
599 #define sdiv_qrnnd(q, r, n1, n0, d) \
600 __asm__ ("divs%.l %4,%1:%0" \
601 : "=d" ((USItype)(q)), \
602 "=d" ((USItype)(r)) \
603 : "0" ((USItype)(n0)), \
604 "1" ((USItype)(n1)), \
605 "dmi" ((USItype)(d)))
606 #define count_leading_zeros(count, x) \
607 __asm__ ("bfffo %1{%b2:%b2},%0" \
608 : "=d" ((USItype)(count)) \
609 : "od" ((USItype)(x)), "n" (0))
610 #define COUNT_LEADING_ZEROS_0 32
611 #else /* not mc68020 */
612 #define umul_ppmm(xh, xl, a, b) \
613 do { USItype __umul_tmp1, __umul_tmp2; \
614 __asm__ ("| Inlined umul_ppmm\n" \
627 "add%.l %#0x10000,%0\n" \
628 "1: move%.l %2,%3\n" \
635 "| End inlined umul_ppmm" \
636 : "=&d" ((USItype)(xh)), "=&d" ((USItype)(xl)), \
637 "=d" (__umul_tmp1), "=&d" (__umul_tmp2) \
638 : "%2" ((USItype)(a)), "d" ((USItype)(b))); \
640 #define UMUL_TIME 100
641 #define UDIV_TIME 400
642 #endif /* not mc68020 */
645 /***************************************
646 ************** 88000 ****************
647 ***************************************/
648 #if defined(__m88000__) && W_TYPE_SIZE == 32
649 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
650 __asm__ ("addu.co %1,%r4,%r5\n" \
651 "addu.ci %0,%r2,%r3" \
652 : "=r" ((USItype)(sh)), \
653 "=&r" ((USItype)(sl)) \
654 : "%rJ" ((USItype)(ah)), \
655 "rJ" ((USItype)(bh)), \
656 "%rJ" ((USItype)(al)), \
657 "rJ" ((USItype)(bl)))
658 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
659 __asm__ ("subu.co %1,%r4,%r5\n" \
660 "subu.ci %0,%r2,%r3" \
661 : "=r" ((USItype)(sh)), \
662 "=&r" ((USItype)(sl)) \
663 : "rJ" ((USItype)(ah)), \
664 "rJ" ((USItype)(bh)), \
665 "rJ" ((USItype)(al)), \
666 "rJ" ((USItype)(bl)))
667 #define count_leading_zeros(count, x) \
670 __asm__ ("ff1 %0,%1" \
672 : "r" ((USItype)(x))); \
673 (count) = __cbtmp ^ 31; \
675 #define COUNT_LEADING_ZEROS_0 63 /* sic */
676 #if defined(__m88110__)
677 #define umul_ppmm(wh, wl, u, v) \
679 union {UDItype __ll; \
680 struct {USItype __h, __l; } __i; \
682 __asm__ ("mulu.d %0,%1,%2" : "=r" (__x.__ll) : "r" (u), "r" (v)); \
683 (wh) = __x.__i.__h; \
684 (wl) = __x.__i.__l; \
686 #define udiv_qrnnd(q, r, n1, n0, d) \
687 ({union {UDItype __ll; \
688 struct {USItype __h, __l; } __i; \
690 __x.__i.__h = (n1); __x.__i.__l = (n0); \
691 __asm__ ("divu.d %0,%1,%2" \
692 : "=r" (__q.__ll) : "r" (__x.__ll), "r" (d)); \
693 (r) = (n0) - __q.__l * (d); (q) = __q.__l; })
698 #define UDIV_TIME 150
699 #endif /* __m88110__ */
700 #endif /* __m88000__ */
702 /***************************************
703 ************** MIPS *****************
704 ***************************************/
705 #if defined(__mips__) && W_TYPE_SIZE == 32
706 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 7
707 #define umul_ppmm(w1, w0, u, v) \
708 __asm__ ("multu %2,%3" \
709 : "=l" ((USItype)(w0)), \
710 "=h" ((USItype)(w1)) \
711 : "d" ((USItype)(u)), \
714 #define umul_ppmm(w1, w0, u, v) \
715 __asm__ ("multu %2,%3\n" \
718 : "=d" ((USItype)(w0)), \
719 "=d" ((USItype)(w1)) \
720 : "d" ((USItype)(u)), \
724 #define UDIV_TIME 100
725 #endif /* __mips__ */
727 /***************************************
728 ************** MIPS/64 **************
729 ***************************************/
730 #if (defined(__mips) && __mips >= 3) && W_TYPE_SIZE == 64
731 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 7
732 #define umul_ppmm(w1, w0, u, v) \
733 __asm__ ("dmultu %2,%3" \
734 : "=l" ((UDItype)(w0)), \
735 "=h" ((UDItype)(w1)) \
736 : "d" ((UDItype)(u)), \
739 #define umul_ppmm(w1, w0, u, v) \
740 __asm__ ("dmultu %2,%3\n" \
743 : "=d" ((UDItype)(w0)), \
744 "=d" ((UDItype)(w1)) \
745 : "d" ((UDItype)(u)), \
749 #define UDIV_TIME 140
750 #endif /* __mips__ */
752 /***************************************
753 ************** 32000 ****************
754 ***************************************/
755 #if defined(__ns32000__) && W_TYPE_SIZE == 32
756 #define umul_ppmm(w1, w0, u, v) \
757 ({union {UDItype __ll; \
758 struct {USItype __l, __h; } __i; \
760 __asm__ ("meid %2,%0" \
762 : "%0" ((USItype)(u)), \
763 "g" ((USItype)(v))); \
764 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l; })
765 #define __umulsidi3(u, v) \
767 __asm__ ("meid %2,%0" \
769 : "%0" ((USItype)(u)), \
770 "g" ((USItype)(v))); \
772 #define udiv_qrnnd(q, r, n1, n0, d) \
773 ({union {UDItype __ll; \
774 struct {USItype __l, __h; } __i; \
776 __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
777 __asm__ ("deid %2,%0" \
780 "g" ((USItype)(d))); \
781 (r) = __xx.__i.__l; (q) = __xx.__i.__h; })
782 #define count_trailing_zeros(count, x) \
784 __asm__("ffsd %2,%0" \
785 : "=r"((USItype) (count)) \
786 : "0"((USItype) 0), "r"((USItype) (x))); \
788 #endif /* __ns32000__ */
790 /***************************************
791 ************** PPC ******************
792 ***************************************/
793 #if (defined(_ARCH_PPC) || defined(_IBMR2)) && W_TYPE_SIZE == 32
794 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
796 if (__builtin_constant_p(bh) && (bh) == 0) \
797 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
798 : "=r" ((USItype)(sh)), \
799 "=&r" ((USItype)(sl)) \
800 : "%r" ((USItype)(ah)), \
801 "%r" ((USItype)(al)), \
802 "rI" ((USItype)(bl))); \
803 else if (__builtin_constant_p(bh) && (bh) == ~(USItype) 0) \
804 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
805 : "=r" ((USItype)(sh)), \
806 "=&r" ((USItype)(sl)) \
807 : "%r" ((USItype)(ah)), \
808 "%r" ((USItype)(al)), \
809 "rI" ((USItype)(bl))); \
811 __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
812 : "=r" ((USItype)(sh)), \
813 "=&r" ((USItype)(sl)) \
814 : "%r" ((USItype)(ah)), \
815 "r" ((USItype)(bh)), \
816 "%r" ((USItype)(al)), \
817 "rI" ((USItype)(bl))); \
819 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
821 if (__builtin_constant_p(ah) && (ah) == 0) \
822 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
823 : "=r" ((USItype)(sh)), \
824 "=&r" ((USItype)(sl)) \
825 : "r" ((USItype)(bh)), \
826 "rI" ((USItype)(al)), \
827 "r" ((USItype)(bl))); \
828 else if (__builtin_constant_p(ah) && (ah) == ~(USItype) 0) \
829 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
830 : "=r" ((USItype)(sh)), \
831 "=&r" ((USItype)(sl)) \
832 : "r" ((USItype)(bh)), \
833 "rI" ((USItype)(al)), \
834 "r" ((USItype)(bl))); \
835 else if (__builtin_constant_p(bh) && (bh) == 0) \
836 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
837 : "=r" ((USItype)(sh)), \
838 "=&r" ((USItype)(sl)) \
839 : "r" ((USItype)(ah)), \
840 "rI" ((USItype)(al)), \
841 "r" ((USItype)(bl))); \
842 else if (__builtin_constant_p(bh) && (bh) == ~(USItype) 0) \
843 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
844 : "=r" ((USItype)(sh)), \
845 "=&r" ((USItype)(sl)) \
846 : "r" ((USItype)(ah)), \
847 "rI" ((USItype)(al)), \
848 "r" ((USItype)(bl))); \
850 __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
851 : "=r" ((USItype)(sh)), \
852 "=&r" ((USItype)(sl)) \
853 : "r" ((USItype)(ah)), \
854 "r" ((USItype)(bh)), \
855 "rI" ((USItype)(al)), \
856 "r" ((USItype)(bl))); \
858 #define count_leading_zeros(count, x) \
859 __asm__ ("{cntlz|cntlzw} %0,%1" \
860 : "=r" ((USItype)(count)) \
861 : "r" ((USItype)(x)))
862 #define COUNT_LEADING_ZEROS_0 32
863 #if defined(_ARCH_PPC)
864 #define umul_ppmm(ph, pl, m0, m1) \
866 USItype __m0 = (m0), __m1 = (m1); \
867 __asm__ ("mulhwu %0,%1,%2" \
868 : "=r" ((USItype) ph) \
871 (pl) = __m0 * __m1; \
874 #define smul_ppmm(ph, pl, m0, m1) \
876 SItype __m0 = (m0), __m1 = (m1); \
877 __asm__ ("mulhw %0,%1,%2" \
878 : "=r" ((SItype) ph) \
881 (pl) = __m0 * __m1; \
884 #define UDIV_TIME 120
886 #define umul_ppmm(xh, xl, m0, m1) \
888 USItype __m0 = (m0), __m1 = (m1); \
889 __asm__ ("mul %0,%2,%3" \
890 : "=r" ((USItype)(xh)), \
891 "=q" ((USItype)(xl)) \
894 (xh) += ((((SItype) __m0 >> 31) & __m1) \
895 + (((SItype) __m1 >> 31) & __m0)); \
898 #define smul_ppmm(xh, xl, m0, m1) \
899 __asm__ ("mul %0,%2,%3" \
900 : "=r" ((SItype)(xh)), \
901 "=q" ((SItype)(xl)) \
905 #define sdiv_qrnnd(q, r, nh, nl, d) \
906 __asm__ ("div %0,%2,%4" \
907 : "=r" ((SItype)(q)), "=q" ((SItype)(r)) \
908 : "r" ((SItype)(nh)), "1" ((SItype)(nl)), "r" ((SItype)(d)))
909 #define UDIV_TIME 100
911 #endif /* Power architecture variants. */
913 /***************************************
914 ************** PYR ******************
915 ***************************************/
916 #if defined(__pyr__) && W_TYPE_SIZE == 32
917 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
918 __asm__ ("addw %5,%1\n" \
920 : "=r" ((USItype)(sh)), \
921 "=&r" ((USItype)(sl)) \
922 : "%0" ((USItype)(ah)), \
923 "g" ((USItype)(bh)), \
924 "%1" ((USItype)(al)), \
926 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
927 __asm__ ("subw %5,%1\n" \
929 : "=r" ((USItype)(sh)), \
930 "=&r" ((USItype)(sl)) \
931 : "0" ((USItype)(ah)), \
932 "g" ((USItype)(bh)), \
933 "1" ((USItype)(al)), \
935 /* This insn works on Pyramids with AP, XP, or MI CPUs, but not with SP. */
936 #define umul_ppmm(w1, w0, u, v) \
937 ({union {UDItype __ll; \
938 struct {USItype __h, __l; } __i; \
940 __asm__ ("movw %1,%R0\n" \
942 : "=&r" (__xx.__ll) \
943 : "g" ((USItype) (u)), \
944 "g" ((USItype)(v))); \
945 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l; })
948 /***************************************
949 ************** RT/ROMP **************
950 ***************************************/
951 #if defined(__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
952 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
953 __asm__ ("a %1,%5\n" \
955 : "=r" ((USItype)(sh)), \
956 "=&r" ((USItype)(sl)) \
957 : "%0" ((USItype)(ah)), \
958 "r" ((USItype)(bh)), \
959 "%1" ((USItype)(al)), \
961 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
962 __asm__ ("s %1,%5\n" \
964 : "=r" ((USItype)(sh)), \
965 "=&r" ((USItype)(sl)) \
966 : "0" ((USItype)(ah)), \
967 "r" ((USItype)(bh)), \
968 "1" ((USItype)(al)), \
970 #define umul_ppmm(ph, pl, m0, m1) \
972 USItype __m0 = (m0), __m1 = (m1); \
994 : "=r" ((USItype)(ph)), \
995 "=r" ((USItype)(pl)) \
999 (ph) += ((((SItype) __m0 >> 31) & __m1) \
1000 + (((SItype) __m1 >> 31) & __m0)); \
1002 #define UMUL_TIME 20
1003 #define UDIV_TIME 200
1004 #define count_leading_zeros(count, x) \
1006 if ((x) >= 0x10000) \
1007 __asm__ ("clz %0,%1" \
1008 : "=r" ((USItype)(count)) \
1009 : "r" ((USItype)(x) >> 16)); \
1011 __asm__ ("clz %0,%1" \
1012 : "=r" ((USItype)(count)) \
1013 : "r" ((USItype)(x))); \
1017 #endif /* RT/ROMP */
1019 /***************************************
1020 ************** SH2 ******************
1021 ***************************************/
1022 #if (defined(__sh2__) || defined(__sh3__) || defined(__SH4__)) \
1023 && W_TYPE_SIZE == 32
1024 #define umul_ppmm(w1, w0, u, v) \
1029 : "=r" ((USItype)(w1)), \
1030 "=r" ((USItype)(w0)) \
1031 : "r" ((USItype)(u)), \
1032 "r" ((USItype)(v)) \
1037 /***************************************
1038 ************** SPARC ****************
1039 ***************************************/
1040 #if defined(__sparc__) && W_TYPE_SIZE == 32
1041 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1042 __asm__ ("addcc %r4,%5,%1\n" \
1044 : "=r" ((USItype)(sh)), \
1045 "=&r" ((USItype)(sl)) \
1046 : "%rJ" ((USItype)(ah)), \
1047 "rI" ((USItype)(bh)), \
1048 "%rJ" ((USItype)(al)), \
1049 "rI" ((USItype)(bl)) \
1051 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1052 __asm__ ("subcc %r4,%5,%1\n" \
1054 : "=r" ((USItype)(sh)), \
1055 "=&r" ((USItype)(sl)) \
1056 : "rJ" ((USItype)(ah)), \
1057 "rI" ((USItype)(bh)), \
1058 "rJ" ((USItype)(al)), \
1059 "rI" ((USItype)(bl)) \
1061 #if defined(__sparc_v8__)
1062 /* Don't match immediate range because, 1) it is not often useful,
1063 2) the 'I' flag thinks of the range as a 13 bit signed interval,
1064 while we want to match a 13 bit interval, sign extended to 32 bits,
1065 but INTERPRETED AS UNSIGNED. */
1066 #define umul_ppmm(w1, w0, u, v) \
1067 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
1068 : "=r" ((USItype)(w1)), \
1069 "=r" ((USItype)(w0)) \
1070 : "r" ((USItype)(u)), \
1073 #ifndef SUPERSPARC /* SuperSPARC's udiv only handles 53 bit dividends */
1074 #define udiv_qrnnd(q, r, n1, n0, d) \
1077 __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0" \
1078 : "=r" ((USItype)(__q)) \
1079 : "r" ((USItype)(n1)), \
1080 "r" ((USItype)(n0)), \
1081 "r" ((USItype)(d))); \
1082 (r) = (n0) - __q * (d); \
1085 #define UDIV_TIME 25
1086 #endif /* SUPERSPARC */
1087 #else /* ! __sparc_v8__ */
1088 #if defined(__sparclite__)
1089 /* This has hardware multiply but not divide. It also has two additional
1090 instructions scan (ffs from high bit) and divscc. */
1091 #define umul_ppmm(w1, w0, u, v) \
1092 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
1093 : "=r" ((USItype)(w1)), \
1094 "=r" ((USItype)(w0)) \
1095 : "r" ((USItype)(u)), \
1098 #define udiv_qrnnd(q, r, n1, n0, d) \
1099 __asm__ ("! Inlined udiv_qrnnd\n" \
1100 "wr %%g0,%2,%%y ! Not a delayed write for sparclite\n" \
1102 "divscc %3,%4,%%g1\n" \
1103 "divscc %%g1,%4,%%g1\n" \
1104 "divscc %%g1,%4,%%g1\n" \
1105 "divscc %%g1,%4,%%g1\n" \
1106 "divscc %%g1,%4,%%g1\n" \
1107 "divscc %%g1,%4,%%g1\n" \
1108 "divscc %%g1,%4,%%g1\n" \
1109 "divscc %%g1,%4,%%g1\n" \
1110 "divscc %%g1,%4,%%g1\n" \
1111 "divscc %%g1,%4,%%g1\n" \
1112 "divscc %%g1,%4,%%g1\n" \
1113 "divscc %%g1,%4,%%g1\n" \
1114 "divscc %%g1,%4,%%g1\n" \
1115 "divscc %%g1,%4,%%g1\n" \
1116 "divscc %%g1,%4,%%g1\n" \
1117 "divscc %%g1,%4,%%g1\n" \
1118 "divscc %%g1,%4,%%g1\n" \
1119 "divscc %%g1,%4,%%g1\n" \
1120 "divscc %%g1,%4,%%g1\n" \
1121 "divscc %%g1,%4,%%g1\n" \
1122 "divscc %%g1,%4,%%g1\n" \
1123 "divscc %%g1,%4,%%g1\n" \
1124 "divscc %%g1,%4,%%g1\n" \
1125 "divscc %%g1,%4,%%g1\n" \
1126 "divscc %%g1,%4,%%g1\n" \
1127 "divscc %%g1,%4,%%g1\n" \
1128 "divscc %%g1,%4,%%g1\n" \
1129 "divscc %%g1,%4,%%g1\n" \
1130 "divscc %%g1,%4,%%g1\n" \
1131 "divscc %%g1,%4,%%g1\n" \
1132 "divscc %%g1,%4,%%g1\n" \
1133 "divscc %%g1,%4,%0\n" \
1137 "1: ! End of inline udiv_qrnnd" \
1138 : "=r" ((USItype)(q)), \
1139 "=r" ((USItype)(r)) \
1140 : "r" ((USItype)(n1)), \
1141 "r" ((USItype)(n0)), \
1142 "rI" ((USItype)(d)) \
1143 : "%g1" __AND_CLOBBER_CC)
1144 #define UDIV_TIME 37
1145 #define count_leading_zeros(count, x) \
1146 __asm__ ("scan %1,0,%0" \
1147 : "=r" ((USItype)(x)) \
1148 : "r" ((USItype)(count)))
1149 /* Early sparclites return 63 for an argument of 0, but they warn that future
1150 implementations might change this. Therefore, leave COUNT_LEADING_ZEROS_0
1152 #endif /* __sparclite__ */
1153 #endif /* __sparc_v8__ */
1154 /* Default to sparc v7 versions of umul_ppmm and udiv_qrnnd. */
1156 #define umul_ppmm(w1, w0, u, v) \
1157 __asm__ ("! Inlined umul_ppmm\n" \
1158 "wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr\n" \
1159 "sra %3,31,%%g2 ! Don't move this insn\n" \
1160 "and %2,%%g2,%%g2 ! Don't move this insn\n" \
1161 "andcc %%g0,0,%%g1 ! Don't move this insn\n" \
1162 "mulscc %%g1,%3,%%g1\n" \
1163 "mulscc %%g1,%3,%%g1\n" \
1164 "mulscc %%g1,%3,%%g1\n" \
1165 "mulscc %%g1,%3,%%g1\n" \
1166 "mulscc %%g1,%3,%%g1\n" \
1167 "mulscc %%g1,%3,%%g1\n" \
1168 "mulscc %%g1,%3,%%g1\n" \
1169 "mulscc %%g1,%3,%%g1\n" \
1170 "mulscc %%g1,%3,%%g1\n" \
1171 "mulscc %%g1,%3,%%g1\n" \
1172 "mulscc %%g1,%3,%%g1\n" \
1173 "mulscc %%g1,%3,%%g1\n" \
1174 "mulscc %%g1,%3,%%g1\n" \
1175 "mulscc %%g1,%3,%%g1\n" \
1176 "mulscc %%g1,%3,%%g1\n" \
1177 "mulscc %%g1,%3,%%g1\n" \
1178 "mulscc %%g1,%3,%%g1\n" \
1179 "mulscc %%g1,%3,%%g1\n" \
1180 "mulscc %%g1,%3,%%g1\n" \
1181 "mulscc %%g1,%3,%%g1\n" \
1182 "mulscc %%g1,%3,%%g1\n" \
1183 "mulscc %%g1,%3,%%g1\n" \
1184 "mulscc %%g1,%3,%%g1\n" \
1185 "mulscc %%g1,%3,%%g1\n" \
1186 "mulscc %%g1,%3,%%g1\n" \
1187 "mulscc %%g1,%3,%%g1\n" \
1188 "mulscc %%g1,%3,%%g1\n" \
1189 "mulscc %%g1,%3,%%g1\n" \
1190 "mulscc %%g1,%3,%%g1\n" \
1191 "mulscc %%g1,%3,%%g1\n" \
1192 "mulscc %%g1,%3,%%g1\n" \
1193 "mulscc %%g1,%3,%%g1\n" \
1194 "mulscc %%g1,0,%%g1\n" \
1195 "add %%g1,%%g2,%0\n" \
1197 : "=r" ((USItype)(w1)), \
1198 "=r" ((USItype)(w0)) \
1199 : "%rI" ((USItype)(u)), \
1200 "r" ((USItype)(v)) \
1201 : "%g1", "%g2" __AND_CLOBBER_CC)
1202 #define UMUL_TIME 39 /* 39 instructions */
1203 /* It's quite necessary to add this much assembler for the sparc.
1204 The default udiv_qrnnd (in C) is more than 10 times slower! */
1205 #define udiv_qrnnd(q, r, n1, n0, d) \
1206 __asm__ ("! Inlined udiv_qrnnd\n\t" \
1208 "subcc %1,%2,%%g0\n\t" \
1210 "addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n\t" \
1211 "sub %1,%2,%1 ! this kills msb of n\n\t" \
1212 "addx %1,%1,%1 ! so this can't give carry\n\t" \
1213 "subcc %%g1,1,%%g1\n\t" \
1215 "subcc %1,%2,%%g0\n\t" \
1217 "addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n\t" \
1219 "sub %1,%2,%1 ! this kills msb of n\n\t" \
1220 "4: sub %1,%2,%1\n\t" \
1221 "5: addxcc %1,%1,%1\n\t" \
1223 "subcc %%g1,1,%%g1\n\t" \
1224 "! Got carry from n. Subtract next step to cancel this carry.\n\t" \
1226 "addcc %0,%0,%0 ! shift n1n0 and a 0-bit in lsb\n\t" \
1227 "sub %1,%2,%1\n\t" \
1228 "3: xnor %0,0,%0\n\t" \
1229 "! End of inline udiv_qrnnd\n" \
1230 : "=&r" ((USItype)(q)), \
1231 "=&r" ((USItype)(r)) \
1232 : "r" ((USItype)(d)), \
1233 "1" ((USItype)(n1)), \
1234 "0" ((USItype)(n0)) : "%g1", "cc")
1235 #define UDIV_TIME (3+7*32) /* 7 instructions/iteration. 32 iterations. */
1237 #endif /* __sparc__ */
1239 /***************************************
1240 ************** VAX ******************
1241 ***************************************/
1242 #if defined(__vax__) && W_TYPE_SIZE == 32
1243 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1244 __asm__ ("addl2 %5,%1\n" \
1246 : "=g" ((USItype)(sh)), \
1247 "=&g" ((USItype)(sl)) \
1248 : "%0" ((USItype)(ah)), \
1249 "g" ((USItype)(bh)), \
1250 "%1" ((USItype)(al)), \
1251 "g" ((USItype)(bl)))
1252 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1253 __asm__ ("subl2 %5,%1\n" \
1255 : "=g" ((USItype)(sh)), \
1256 "=&g" ((USItype)(sl)) \
1257 : "0" ((USItype)(ah)), \
1258 "g" ((USItype)(bh)), \
1259 "1" ((USItype)(al)), \
1260 "g" ((USItype)(bl)))
1261 #define umul_ppmm(xh, xl, m0, m1) \
1263 union {UDItype __ll; \
1264 struct {USItype __l, __h; } __i; \
1266 USItype __m0 = (m0), __m1 = (m1); \
1267 __asm__ ("emul %1,%2,$0,%0" \
1268 : "=g" (__xx.__ll) \
1271 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
1272 (xh) += ((((SItype) __m0 >> 31) & __m1) \
1273 + (((SItype) __m1 >> 31) & __m0)); \
1275 #define sdiv_qrnnd(q, r, n1, n0, d) \
1277 union {DItype __ll; \
1278 struct {SItype __l, __h; } __i; \
1280 __xx.__i.__h = n1; __xx.__i.__l = n0; \
1281 __asm__ ("ediv %3,%2,%0,%1" \
1282 : "=g" (q), "=g" (r) \
1283 : "g" (__xx.__ll), "g" (d)); \
1285 #endif /* __vax__ */
1287 /***************************************
1288 ************** Z8000 ****************
1289 ***************************************/
1290 #if defined(__z8000__) && W_TYPE_SIZE == 16
1291 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1292 __asm__ ("add %H1,%H5\n\tadc %H0,%H3" \
1293 : "=r" ((unsigned int)(sh)), \
1294 "=&r" ((unsigned int)(sl)) \
1295 : "%0" ((unsigned int)(ah)), \
1296 "r" ((unsigned int)(bh)), \
1297 "%1" ((unsigned int)(al)), \
1298 "rQR" ((unsigned int)(bl)))
1299 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1300 __asm__ ("sub %H1,%H5\n\tsbc %H0,%H3" \
1301 : "=r" ((unsigned int)(sh)), \
1302 "=&r" ((unsigned int)(sl)) \
1303 : "0" ((unsigned int)(ah)), \
1304 "r" ((unsigned int)(bh)), \
1305 "1" ((unsigned int)(al)), \
1306 "rQR" ((unsigned int)(bl)))
1307 #define umul_ppmm(xh, xl, m0, m1) \
1309 union {long int __ll; \
1310 struct {unsigned int __h, __l; } __i; \
1312 unsigned int __m0 = (m0), __m1 = (m1); \
1313 __asm__ ("mult %S0,%H3" \
1314 : "=r" (__xx.__i.__h), \
1315 "=r" (__xx.__i.__l) \
1318 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
1319 (xh) += ((((signed int) __m0 >> 15) & __m1) \
1320 + (((signed int) __m1 >> 15) & __m0)); \
1322 #endif /* __z8000__ */
1324 #endif /* __GNUC__ */
1326 /***************************************
1327 *********** Generic Versions ********
1328 ***************************************/
1329 #if !defined(umul_ppmm) && defined(__umulsidi3)
1330 #define umul_ppmm(ph, pl, m0, m1) \
1332 UDWtype __ll = __umulsidi3(m0, m1); \
1333 ph = (UWtype) (__ll >> W_TYPE_SIZE); \
1334 pl = (UWtype) __ll; \
1338 #if !defined(__umulsidi3)
1339 #define __umulsidi3(u, v) \
1340 ({UWtype __hi, __lo; \
1341 umul_ppmm(__hi, __lo, u, v); \
1342 ((UDWtype) __hi << W_TYPE_SIZE) | __lo; })
1345 /* If this machine has no inline assembler, use C macros. */
1347 #if !defined(add_ssaaaa)
1348 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1351 __x = (al) + (bl); \
1352 (sh) = (ah) + (bh) + (__x < (al)); \
1357 #if !defined(sub_ddmmss)
1358 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1361 __x = (al) - (bl); \
1362 (sh) = (ah) - (bh) - (__x > (al)); \
1367 #if !defined(umul_ppmm)
1368 #define umul_ppmm(w1, w0, u, v) \
1370 UWtype __x0, __x1, __x2, __x3; \
1371 UHWtype __ul, __vl, __uh, __vh; \
1372 UWtype __u = (u), __v = (v); \
1374 __ul = __ll_lowpart(__u); \
1375 __uh = __ll_highpart(__u); \
1376 __vl = __ll_lowpart(__v); \
1377 __vh = __ll_highpart(__v); \
1379 __x0 = (UWtype) __ul * __vl; \
1380 __x1 = (UWtype) __ul * __vh; \
1381 __x2 = (UWtype) __uh * __vl; \
1382 __x3 = (UWtype) __uh * __vh; \
1384 __x1 += __ll_highpart(__x0);/* this can't give carry */ \
1385 __x1 += __x2; /* but this indeed can */ \
1386 if (__x1 < __x2) /* did we get it? */ \
1387 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
1389 (w1) = __x3 + __ll_highpart(__x1); \
1390 (w0) = (__ll_lowpart(__x1) << W_TYPE_SIZE/2) + __ll_lowpart(__x0); \
1394 #if !defined(umul_ppmm)
1395 #define smul_ppmm(w1, w0, u, v) \
1398 UWtype __m0 = (u), __m1 = (v); \
1399 umul_ppmm(__w1, w0, __m0, __m1); \
1400 (w1) = __w1 - (-(__m0 >> (W_TYPE_SIZE - 1)) & __m1) \
1401 - (-(__m1 >> (W_TYPE_SIZE - 1)) & __m0); \
1405 /* Define this unconditionally, so it can be used for debugging. */
1406 #define __udiv_qrnnd_c(q, r, n1, n0, d) \
1408 UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \
1409 __d1 = __ll_highpart(d); \
1410 __d0 = __ll_lowpart(d); \
1412 __r1 = (n1) % __d1; \
1413 __q1 = (n1) / __d1; \
1414 __m = (UWtype) __q1 * __d0; \
1415 __r1 = __r1 * __ll_B | __ll_highpart(n0); \
1417 __q1--, __r1 += (d); \
1418 if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */ \
1420 __q1--, __r1 += (d); \
1424 __r0 = __r1 % __d1; \
1425 __q0 = __r1 / __d1; \
1426 __m = (UWtype) __q0 * __d0; \
1427 __r0 = __r0 * __ll_B | __ll_lowpart(n0); \
1429 __q0--, __r0 += (d); \
1432 __q0--, __r0 += (d); \
1436 (q) = (UWtype) __q1 * __ll_B | __q0; \
1440 /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
1441 __udiv_w_sdiv (defined in libgcc or elsewhere). */
1442 #if !defined(udiv_qrnnd) && defined(sdiv_qrnnd)
1443 #define udiv_qrnnd(q, r, nh, nl, d) \
1446 (q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d); \
1451 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
1452 #if !defined(udiv_qrnnd)
1453 #define UDIV_NEEDS_NORMALIZATION 1
1454 #define udiv_qrnnd __udiv_qrnnd_c
1457 #undef count_leading_zeros
1458 #if !defined(count_leading_zeros)
1463 unsigned char __clz_tab
[];
1464 #define count_leading_zeros(count, x) \
1466 UWtype __xr = (x); \
1469 if (W_TYPE_SIZE <= 32) { \
1470 __a = __xr < ((UWtype) 1 << 2*__BITS4) \
1471 ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \
1472 : (__xr < ((UWtype) 1 << 3*__BITS4) ? 2*__BITS4 : 3*__BITS4); \
1475 for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
1476 if (((__xr >> __a) & 0xff) != 0) \
1480 (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
1482 /* This version gives a well-defined value for zero. */
1483 #define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
1486 #if !defined(count_trailing_zeros)
1487 /* Define count_trailing_zeros using count_leading_zeros. The latter might be
1488 defined in asm, but if it is not, the C version above is good enough. */
1489 #define count_trailing_zeros(count, x) \
1491 UWtype __ctz_x = (x); \
1493 count_leading_zeros(__ctz_c, __ctz_x & -__ctz_x); \
1494 (count) = W_TYPE_SIZE - 1 - __ctz_c; \
1498 #ifndef UDIV_NEEDS_NORMALIZATION
1499 #define UDIV_NEEDS_NORMALIZATION 0