73a80f73af4c0dffce9bfae7c2e823e87287d6d4
1 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
2 Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
4 This definition file is free software; you can redistribute it
5 and/or modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2, or (at your option) any later version.
9 This definition file is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied
11 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 See the GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19 #define SI_TYPE_SIZE 32
22 #define __BITS4 (SI_TYPE_SIZE / 4)
23 #define __ll_B (1L << (SI_TYPE_SIZE / 2))
24 #define __ll_lowpart(t) ((USItype) (t) % __ll_B)
25 #define __ll_highpart(t) ((USItype) (t) / __ll_B)
27 /* Define auxiliary asm macros.
29 1) umul_ppmm(high_prod, low_prod, multipler, multiplicand)
30 multiplies two USItype integers MULTIPLER and MULTIPLICAND,
31 and generates a two-part USItype product in HIGH_PROD and
34 2) __umulsidi3(a,b) multiplies two USItype integers A and B,
35 and returns a UDItype product. This is just a variant of umul_ppmm.
37 3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
38 denominator) divides a two-word unsigned integer, composed by the
39 integers HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and
40 places the quotient in QUOTIENT and the remainder in REMAINDER.
41 HIGH_NUMERATOR must be less than DENOMINATOR for correct operation.
42 If, in addition, the most significant bit of DENOMINATOR must be 1,
43 then the pre-processor symbol UDIV_NEEDS_NORMALIZATION is defined to 1.
45 4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
46 denominator). Like udiv_qrnnd but the numbers are signed. The
47 quotient is rounded towards 0.
49 5) count_leading_zeros(count, x) counts the number of zero-bits from
50 the msb to the first non-zero bit. This is the number of steps X
51 needs to be shifted left to set the msb. Undefined for X == 0.
53 6) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
54 high_addend_2, low_addend_2) adds two two-word unsigned integers,
55 composed by HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and
56 LOW_ADDEND_2 respectively. The result is placed in HIGH_SUM and
57 LOW_SUM. Overflow (i.e. carry out) is not stored anywhere, and is
60 7) sub_ddmmss(high_difference, low_difference, high_minuend,
61 low_minuend, high_subtrahend, low_subtrahend) subtracts two
62 two-word unsigned integers, composed by HIGH_MINUEND_1 and
63 LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and LOW_SUBTRAHEND_2
64 respectively. The result is placed in HIGH_DIFFERENCE and
65 LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere,
68 If any of these macros are left undefined for a particular CPU,
71 /* The CPUs come in alphabetical order below.
73 Please add support for more CPUs here, or improve the current support
75 (E.g. WE32100, IBM360.) */
77 #if defined (__GNUC__) && !defined (NO_ASM)
79 /* We sometimes need to clobber "cc" with gcc2, but that would not be
80 understood by gcc1. Use cpp to avoid major code duplication. */
83 #define __AND_CLOBBER_CC
84 #else /* __GNUC__ >= 2 */
85 #define __CLOBBER_CC : "cc"
86 #define __AND_CLOBBER_CC , "cc"
87 #endif /* __GNUC__ < 2 */
89 #if defined (__a29k__) || defined (_AM29K)
90 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
91 __asm__ ("add %1,%4,%5
93 : "=r" ((USItype)(sh)), \
94 "=&r" ((USItype)(sl)) \
95 : "%r" ((USItype)(ah)), \
96 "rI" ((USItype)(bh)), \
97 "%r" ((USItype)(al)), \
99 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
100 __asm__ ("sub %1,%4,%5
102 : "=r" ((USItype)(sh)), \
103 "=&r" ((USItype)(sl)) \
104 : "r" ((USItype)(ah)), \
105 "rI" ((USItype)(bh)), \
106 "r" ((USItype)(al)), \
107 "rI" ((USItype)(bl)))
108 #define umul_ppmm(xh, xl, m0, m1) \
110 USItype __m0 = (m0), __m1 = (m1); \
111 __asm__ ("multiplu %0,%1,%2" \
112 : "=r" ((USItype)(xl)) \
115 __asm__ ("multmu %0,%1,%2" \
116 : "=r" ((USItype)(xh)) \
120 #define udiv_qrnnd(q, r, n1, n0, d) \
121 __asm__ ("dividu %0,%3,%4" \
122 : "=r" ((USItype)(q)), \
123 "=q" ((USItype)(r)) \
124 : "1" ((USItype)(n1)), \
125 "r" ((USItype)(n0)), \
127 #define count_leading_zeros(count, x) \
128 __asm__ ("clz %0,%1" \
129 : "=r" ((USItype)(count)) \
130 : "r" ((USItype)(x)))
131 #endif /* __a29k__ */
133 #if defined (__arm__)
134 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
135 __asm__ ("adds %1, %4, %5
137 : "=r" ((USItype)(sh)), \
138 "=&r" ((USItype)(sl)) \
139 : "%r" ((USItype)(ah)), \
140 "rI" ((USItype)(bh)), \
141 "%r" ((USItype)(al)), \
142 "rI" ((USItype)(bl)))
143 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
144 __asm__ ("subs %1, %4, %5
146 : "=r" ((USItype)(sh)), \
147 "=&r" ((USItype)(sl)) \
148 : "r" ((USItype)(ah)), \
149 "rI" ((USItype)(bh)), \
150 "r" ((USItype)(al)), \
151 "rI" ((USItype)(bl)))
152 #define umul_ppmm(xh, xl, a, b) \
153 {register USItype __t0, __t1, __t2; \
154 __asm__ ("%@ Inlined umul_ppmm
157 bic %3, %5, %2, lsl #16
158 bic %4, %6, %0, lsl #16
165 adds %1, %1, %3, lsl #16
166 adc %0, %0, %3, lsr #16" \
167 : "=&r" ((USItype)(xh)), \
168 "=r" ((USItype)(xl)), \
169 "=&r" (__t0), "=&r" (__t1), "=r" (__t2) \
170 : "r" ((USItype)(a)), \
171 "r" ((USItype)(b)));}
173 #define UDIV_TIME 100
176 #if defined (__clipper__)
177 #define umul_ppmm(w1, w0, u, v) \
178 ({union {UDItype __ll; \
179 struct {USItype __l, __h;} __i; \
181 __asm__ ("mulwux %2,%0" \
183 : "%0" ((USItype)(u)), \
184 "r" ((USItype)(v))); \
185 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
186 #define smul_ppmm(w1, w0, u, v) \
187 ({union {DItype __ll; \
188 struct {SItype __l, __h;} __i; \
190 __asm__ ("mulwx %2,%0" \
192 : "%0" ((SItype)(u)), \
193 "r" ((SItype)(v))); \
194 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
195 #define __umulsidi3(u, v) \
197 __asm__ ("mulwux %2,%0" \
199 : "%0" ((USItype)(u)), \
200 "r" ((USItype)(v))); \
202 #endif /* __clipper__ */
204 #if defined (__gmicro__)
205 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
206 __asm__ ("add.w %5,%1
208 : "=g" ((USItype)(sh)), \
209 "=&g" ((USItype)(sl)) \
210 : "%0" ((USItype)(ah)), \
211 "g" ((USItype)(bh)), \
212 "%1" ((USItype)(al)), \
214 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
215 __asm__ ("sub.w %5,%1
217 : "=g" ((USItype)(sh)), \
218 "=&g" ((USItype)(sl)) \
219 : "0" ((USItype)(ah)), \
220 "g" ((USItype)(bh)), \
221 "1" ((USItype)(al)), \
223 #define umul_ppmm(ph, pl, m0, m1) \
224 __asm__ ("mulx %3,%0,%1" \
225 : "=g" ((USItype)(ph)), \
226 "=r" ((USItype)(pl)) \
227 : "%0" ((USItype)(m0)), \
229 #define udiv_qrnnd(q, r, nh, nl, d) \
230 __asm__ ("divx %4,%0,%1" \
231 : "=g" ((USItype)(q)), \
232 "=r" ((USItype)(r)) \
233 : "1" ((USItype)(nh)), \
234 "0" ((USItype)(nl)), \
236 #define count_leading_zeros(count, x) \
237 __asm__ ("bsch/1 %1,%0" \
239 : "g" ((USItype)(x)), \
244 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
245 __asm__ ("add %4,%5,%1
247 : "=r" ((USItype)(sh)), \
248 "=&r" ((USItype)(sl)) \
249 : "%rM" ((USItype)(ah)), \
250 "rM" ((USItype)(bh)), \
251 "%rM" ((USItype)(al)), \
252 "rM" ((USItype)(bl)))
253 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
254 __asm__ ("sub %4,%5,%1
256 : "=r" ((USItype)(sh)), \
257 "=&r" ((USItype)(sl)) \
258 : "rM" ((USItype)(ah)), \
259 "rM" ((USItype)(bh)), \
260 "rM" ((USItype)(al)), \
261 "rM" ((USItype)(bl)))
262 #if defined (_PA_RISC1_1)
263 #define umul_ppmm(w1, w0, u, v) \
268 struct {USItype __w1, __w0;} __w1w0; \
270 __asm__ ("xmpyu %1,%2,%0" \
272 : "x" ((USItype)(u)), \
273 "x" ((USItype)(v))); \
274 (w1) = __t.__w1w0.__w1; \
275 (w0) = __t.__w1w0.__w0; \
282 #define count_leading_zeros(count, x) \
287 extru,= %1,15,16,%%r0 ; Bits 31..16 zero?
288 extru,tr %1,15,16,%1 ; No. Shift down, skip add.
289 ldo 16(%0),%0 ; Yes. Perform add.
290 extru,= %1,23,8,%%r0 ; Bits 15..8 zero?
291 extru,tr %1,23,8,%1 ; No. Shift down, skip add.
292 ldo 8(%0),%0 ; Yes. Perform add.
293 extru,= %1,27,4,%%r0 ; Bits 7..4 zero?
294 extru,tr %1,27,4,%1 ; No. Shift down, skip add.
295 ldo 4(%0),%0 ; Yes. Perform add.
296 extru,= %1,29,2,%%r0 ; Bits 3..2 zero?
297 extru,tr %1,29,2,%1 ; No. Shift down, skip add.
298 ldo 2(%0),%0 ; Yes. Perform add.
299 extru %1,30,1,%1 ; Extract bit 1.
300 sub %0,%1,%0 ; Subtract it.
301 " : "=r" (count), "=r" (__tmp) : "1" (x)); \
305 #if defined (__i386__) || defined (__i486__)
306 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
309 : "=r" ((USItype)(sh)), \
310 "=&r" ((USItype)(sl)) \
311 : "%0" ((USItype)(ah)), \
312 "g" ((USItype)(bh)), \
313 "%1" ((USItype)(al)), \
315 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
318 : "=r" ((USItype)(sh)), \
319 "=&r" ((USItype)(sl)) \
320 : "0" ((USItype)(ah)), \
321 "g" ((USItype)(bh)), \
322 "1" ((USItype)(al)), \
324 #define umul_ppmm(w1, w0, u, v) \
326 : "=a" ((USItype)(w0)), \
327 "=d" ((USItype)(w1)) \
328 : "%0" ((USItype)(u)), \
330 #define udiv_qrnnd(q, r, n1, n0, d) \
332 : "=a" ((USItype)(q)), \
333 "=d" ((USItype)(r)) \
334 : "0" ((USItype)(n0)), \
335 "1" ((USItype)(n1)), \
337 #define count_leading_zeros(count, x) \
340 __asm__ ("bsrl %1,%0" \
341 : "=r" (__cbtmp) : "rm" ((USItype)(x))); \
342 (count) = __cbtmp ^ 31; \
348 #if defined (__i860__)
350 /* Make sure these patterns really improve the code before
351 switching them on. */
352 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
357 struct {USItype __l, __h;} __i; \
359 __a.__i.__l = (al); \
360 __a.__i.__h = (ah); \
361 __b.__i.__l = (bl); \
362 __b.__i.__h = (bh); \
363 __asm__ ("fiadd.dd %1,%2,%0" \
365 : "%f" (__a.__ll), "f" (__b.__ll)); \
366 (sh) = __s.__i.__h; \
367 (sl) = __s.__i.__l; \
369 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
374 struct {USItype __l, __h;} __i; \
376 __a.__i.__l = (al); \
377 __a.__i.__h = (ah); \
378 __b.__i.__l = (bl); \
379 __b.__i.__h = (bh); \
380 __asm__ ("fisub.dd %1,%2,%0" \
382 : "%f" (__a.__ll), "f" (__b.__ll)); \
383 (sh) = __s.__i.__h; \
384 (sl) = __s.__i.__l; \
387 #endif /* __i860__ */
389 #if defined (__i960__)
390 #define umul_ppmm(w1, w0, u, v) \
391 ({union {UDItype __ll; \
392 struct {USItype __l, __h;} __i; \
394 __asm__ ("emul %2,%1,%0" \
396 : "%dI" ((USItype)(u)), \
397 "dI" ((USItype)(v))); \
398 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
399 #define __umulsidi3(u, v) \
401 __asm__ ("emul %2,%1,%0" \
403 : "%dI" ((USItype)(u)), \
404 "dI" ((USItype)(v))); \
406 #endif /* __i960__ */
408 #if defined (__mc68000__)
409 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
410 __asm__ ("add%.l %5,%1
412 : "=d" ((USItype)(sh)), \
413 "=&d" ((USItype)(sl)) \
414 : "%0" ((USItype)(ah)), \
415 "d" ((USItype)(bh)), \
416 "%1" ((USItype)(al)), \
418 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
419 __asm__ ("sub%.l %5,%1
421 : "=d" ((USItype)(sh)), \
422 "=&d" ((USItype)(sl)) \
423 : "0" ((USItype)(ah)), \
424 "d" ((USItype)(bh)), \
425 "1" ((USItype)(al)), \
427 #if defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)
428 #define umul_ppmm(w1, w0, u, v) \
429 __asm__ ("mulu%.l %3,%1:%0" \
430 : "=d" ((USItype)(w0)), \
431 "=d" ((USItype)(w1)) \
432 : "%0" ((USItype)(u)), \
433 "dmi" ((USItype)(v)))
435 #define udiv_qrnnd(q, r, n1, n0, d) \
436 __asm__ ("divu%.l %4,%1:%0" \
437 : "=d" ((USItype)(q)), \
438 "=d" ((USItype)(r)) \
439 : "0" ((USItype)(n0)), \
440 "1" ((USItype)(n1)), \
441 "dmi" ((USItype)(d)))
443 #define sdiv_qrnnd(q, r, n1, n0, d) \
444 __asm__ ("divs%.l %4,%1:%0" \
445 : "=d" ((USItype)(q)), \
446 "=d" ((USItype)(r)) \
447 : "0" ((USItype)(n0)), \
448 "1" ((USItype)(n1)), \
449 "dmi" ((USItype)(d)))
450 #define count_leading_zeros(count, x) \
451 __asm__ ("bfffo %1{%b2:%b2},%0" \
452 : "=d" ((USItype)(count)) \
453 : "od" ((USItype)(x)), "n" (0))
454 #else /* not mc68020 */
455 /* %/ inserts REGISTER_PREFIX, %# inserts IMMEDIATE_PREFIX. */
456 #define umul_ppmm(xh, xl, a, b) \
457 __asm__ ("| Inlined umul_ppmm
483 : "=g" ((USItype)(xh)), \
484 "=g" ((USItype)(xl)) \
485 : "g" ((USItype)(a)), \
487 : "d0", "d1", "d2", "d3", "d4")
488 #define UMUL_TIME 100
489 #define UDIV_TIME 400
490 #endif /* not mc68020 */
493 #if defined (__m88000__)
494 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
495 __asm__ ("addu.co %1,%r4,%r5
496 addu.ci %0,%r2,%r3" \
497 : "=r" ((USItype)(sh)), \
498 "=&r" ((USItype)(sl)) \
499 : "%rJ" ((USItype)(ah)), \
500 "rJ" ((USItype)(bh)), \
501 "%rJ" ((USItype)(al)), \
502 "rJ" ((USItype)(bl)))
503 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
504 __asm__ ("subu.co %1,%r4,%r5
505 subu.ci %0,%r2,%r3" \
506 : "=r" ((USItype)(sh)), \
507 "=&r" ((USItype)(sl)) \
508 : "rJ" ((USItype)(ah)), \
509 "rJ" ((USItype)(bh)), \
510 "rJ" ((USItype)(al)), \
511 "rJ" ((USItype)(bl)))
512 #define count_leading_zeros(count, x) \
515 __asm__ ("ff1 %0,%1" \
517 : "r" ((USItype)(x))); \
518 (count) = __cbtmp ^ 31; \
520 #if defined (__mc88110__)
521 #define umul_ppmm(wh, wl, u, v) \
523 union {UDItype __ll; \
524 struct {USItype __h, __l;} __i; \
526 __asm__ ("mulu.d %0,%1,%2" \
528 : "r" ((USItype)(u)), \
529 "r" ((USItype)(v))); \
530 (wh) = __xx.__i.__h; \
531 (wl) = __xx.__i.__l; \
533 #define udiv_qrnnd(q, r, n1, n0, d) \
534 ({union {UDItype __ll; \
535 struct {USItype __h, __l;} __i; \
538 __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
539 __asm__ ("divu.d %0,%1,%2" \
542 "r" ((USItype)(d))); \
543 (r) = (n0) - __q * (d); (q) = __q; })
548 #define UDIV_TIME 150
549 #endif /* __mc88110__ */
550 #endif /* __m88000__ */
552 #if defined (__mips__)
553 #define umul_ppmm(w1, w0, u, v) \
554 __asm__ ("multu %2,%3
557 : "=d" ((USItype)(w0)), \
558 "=d" ((USItype)(w1)) \
559 : "d" ((USItype)(u)), \
562 #define UDIV_TIME 100
563 #endif /* __mips__ */
565 #if defined (__ns32000__)
566 #define umul_ppmm(w1, w0, u, v) \
567 ({union {UDItype __ll; \
568 struct {USItype __l, __h;} __i; \
570 __asm__ ("meid %2,%0" \
572 : "%0" ((USItype)(u)), \
573 "g" ((USItype)(v))); \
574 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
575 #define __umulsidi3(u, v) \
577 __asm__ ("meid %2,%0" \
579 : "%0" ((USItype)(u)), \
580 "g" ((USItype)(v))); \
582 #define udiv_qrnnd(q, r, n1, n0, d) \
583 ({union {UDItype __ll; \
584 struct {USItype __l, __h;} __i; \
586 __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
587 __asm__ ("deid %2,%0" \
590 "g" ((USItype)(d))); \
591 (r) = __xx.__i.__l; (q) = __xx.__i.__h; })
592 #endif /* __ns32000__ */
594 #if (defined (_ARCH_PPC) || defined (_IBMR2)) && W_TYPE_SIZE == 32
595 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
597 if (__builtin_constant_p (bh) && (bh) == 0) \
598 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
599 : "=r" ((USItype)(sh)), \
600 "=&r" ((USItype)(sl)) \
601 : "%r" ((USItype)(ah)), \
602 "%r" ((USItype)(al)), \
603 "rI" ((USItype)(bl))); \
604 else if (__builtin_constant_p (bh) && (bh) ==~(USItype) 0) \
605 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
606 : "=r" ((USItype)(sh)), \
607 "=&r" ((USItype)(sl)) \
608 : "%r" ((USItype)(ah)), \
609 "%r" ((USItype)(al)), \
610 "rI" ((USItype)(bl))); \
612 __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
613 : "=r" ((USItype)(sh)), \
614 "=&r" ((USItype)(sl)) \
615 : "%r" ((USItype)(ah)), \
616 "r" ((USItype)(bh)), \
617 "%r" ((USItype)(al)), \
618 "rI" ((USItype)(bl))); \
620 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
622 if (__builtin_constant_p (ah) && (ah) == 0) \
623 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
624 : "=r" ((USItype)(sh)), \
625 "=&r" ((USItype)(sl)) \
626 : "r" ((USItype)(bh)), \
627 "rI" ((USItype)(al)), \
628 "r" ((USItype)(bl))); \
629 else if (__builtin_constant_p (ah) && (ah) ==~(USItype) 0) \
630 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
631 : "=r" ((USItype)(sh)), \
632 "=&r" ((USItype)(sl)) \
633 : "r" ((USItype)(bh)), \
634 "rI" ((USItype)(al)), \
635 "r" ((USItype)(bl))); \
636 else if (__builtin_constant_p (bh) && (bh) == 0) \
637 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
638 : "=r" ((USItype)(sh)), \
639 "=&r" ((USItype)(sl)) \
640 : "r" ((USItype)(ah)), \
641 "rI" ((USItype)(al)), \
642 "r" ((USItype)(bl))); \
643 else if (__builtin_constant_p (bh) && (bh) ==~(USItype) 0) \
644 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
645 : "=r" ((USItype)(sh)), \
646 "=&r" ((USItype)(sl)) \
647 : "r" ((USItype)(ah)), \
648 "rI" ((USItype)(al)), \
649 "r" ((USItype)(bl))); \
651 __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
652 : "=r" ((USItype)(sh)), \
653 "=&r" ((USItype)(sl)) \
654 : "r" ((USItype)(ah)), \
655 "r" ((USItype)(bh)), \
656 "rI" ((USItype)(al)), \
657 "r" ((USItype)(bl))); \
659 #define count_leading_zeros(count, x) \
660 __asm__ ("{cntlz|cntlzw} %0,%1" \
661 : "=r" ((USItype)(count)) \
662 : "r" ((USItype)(x)))
663 #if defined (_ARCH_PPC)
664 #define umul_ppmm(ph, pl, m0, m1) \
666 USItype __m0 = (m0), __m1 = (m1); \
667 __asm__ ("mulhwu %0,%1,%2" \
668 : "=r" ((USItype) ph) \
671 (pl) = __m0 * __m1; \
674 #define smul_ppmm(ph, pl, m0, m1) \
676 SItype __m0 = (m0), __m1 = (m1); \
677 __asm__ ("mulhw %0,%1,%2" \
678 : "=r" ((SItype) ph) \
681 (pl) = __m0 * __m1; \
684 #define UDIV_TIME 120
686 #define umul_ppmm(xh, xl, m0, m1) \
688 USItype __m0 = (m0), __m1 = (m1); \
689 __asm__ ("mul %0,%2,%3" \
690 : "=r" ((USItype)(xh)), \
691 "=q" ((USItype)(xl)) \
694 (xh) += ((((SItype) __m0 >> 31) & __m1) \
695 + (((SItype) __m1 >> 31) & __m0)); \
698 #define smul_ppmm(xh, xl, m0, m1) \
699 __asm__ ("mul %0,%2,%3" \
700 : "=r" ((SItype)(xh)), \
701 "=q" ((SItype)(xl)) \
705 #define sdiv_qrnnd(q, r, nh, nl, d) \
706 __asm__ ("div %0,%2,%4" \
707 : "=r" ((SItype)(q)), "=q" ((SItype)(r)) \
708 : "r" ((SItype)(nh)), "1" ((SItype)(nl)), "r" ((SItype)(d)))
709 #define UDIV_TIME 100
711 #endif /* Power architecture variants. */
713 #if defined (__pyr__)
714 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
717 : "=r" ((USItype)(sh)), \
718 "=&r" ((USItype)(sl)) \
719 : "%0" ((USItype)(ah)), \
720 "g" ((USItype)(bh)), \
721 "%1" ((USItype)(al)), \
723 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
726 : "=r" ((USItype)(sh)), \
727 "=&r" ((USItype)(sl)) \
728 : "0" ((USItype)(ah)), \
729 "g" ((USItype)(bh)), \
730 "1" ((USItype)(al)), \
732 /* This insn doesn't work on ancient pyramids. */
733 #define umul_ppmm(w1, w0, u, v) \
736 struct {USItype __h, __l;} __i; \
739 __asm__ ("uemul %3,%0" \
740 : "=r" (__xx.__i.__h), \
741 "=r" (__xx.__i.__l) \
742 : "1" (__xx.__i.__l), \
743 "g" ((USItype)(v))); \
744 (w1) = __xx.__i.__h; \
745 (w0) = __xx.__i.__l;})
748 #if defined (__ibm032__) /* RT/ROMP */
749 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
752 : "=r" ((USItype)(sh)), \
753 "=&r" ((USItype)(sl)) \
754 : "%0" ((USItype)(ah)), \
755 "r" ((USItype)(bh)), \
756 "%1" ((USItype)(al)), \
758 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
761 : "=r" ((USItype)(sh)), \
762 "=&r" ((USItype)(sl)) \
763 : "0" ((USItype)(ah)), \
764 "r" ((USItype)(bh)), \
765 "1" ((USItype)(al)), \
767 #define umul_ppmm(ph, pl, m0, m1) \
769 USItype __m0 = (m0), __m1 = (m1); \
791 : "=r" ((USItype)(ph)), \
792 "=r" ((USItype)(pl)) \
796 (ph) += ((((SItype) __m0 >> 31) & __m1) \
797 + (((SItype) __m1 >> 31) & __m0)); \
800 #define UDIV_TIME 200
801 #define count_leading_zeros(count, x) \
803 if ((x) >= 0x10000) \
804 __asm__ ("clz %0,%1" \
805 : "=r" ((USItype)(count)) \
806 : "r" ((USItype)(x) >> 16)); \
809 __asm__ ("clz %0,%1" \
810 : "=r" ((USItype)(count)) \
811 : "r" ((USItype)(x))); \
817 #if defined (__sparc__)
818 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
819 __asm__ ("addcc %r4,%5,%1
821 : "=r" ((USItype)(sh)), \
822 "=&r" ((USItype)(sl)) \
823 : "%rJ" ((USItype)(ah)), \
824 "rI" ((USItype)(bh)), \
825 "%rJ" ((USItype)(al)), \
826 "rI" ((USItype)(bl)) \
828 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
829 __asm__ ("subcc %r4,%5,%1
831 : "=r" ((USItype)(sh)), \
832 "=&r" ((USItype)(sl)) \
833 : "rJ" ((USItype)(ah)), \
834 "rI" ((USItype)(bh)), \
835 "rJ" ((USItype)(al)), \
836 "rI" ((USItype)(bl)) \
838 #if defined (__sparc_v8__)
839 #define umul_ppmm(w1, w0, u, v) \
840 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
841 : "=r" ((USItype)(w1)), \
842 "=r" ((USItype)(w0)) \
843 : "r" ((USItype)(u)), \
845 #define udiv_qrnnd(q, r, n1, n0, d) \
846 __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
847 : "=&r" ((USItype)(q)), \
848 "=&r" ((USItype)(r)) \
849 : "r" ((USItype)(n1)), \
850 "r" ((USItype)(n0)), \
853 #if defined (__sparclite__)
854 /* This has hardware multiply but not divide. It also has two additional
855 instructions scan (ffs from high bit) and divscc. */
856 #define umul_ppmm(w1, w0, u, v) \
857 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
858 : "=r" ((USItype)(w1)), \
859 "=r" ((USItype)(w0)) \
860 : "r" ((USItype)(u)), \
862 #define udiv_qrnnd(q, r, n1, n0, d) \
863 __asm__ ("! Inlined udiv_qrnnd
864 wr %%g0,%2,%%y ! Not a delayed write for sparclite
901 1: ! End of inline udiv_qrnnd" \
902 : "=r" ((USItype)(q)), \
903 "=r" ((USItype)(r)) \
904 : "r" ((USItype)(n1)), \
905 "r" ((USItype)(n0)), \
906 "rI" ((USItype)(d)) \
907 : "%g1" __AND_CLOBBER_CC)
909 #define count_leading_zeros(count, x) \
910 __asm__ ("scan %1,0,%0" \
911 : "=r" ((USItype)(x)) \
912 : "r" ((USItype)(count)))
914 /* SPARC without integer multiplication and divide instructions.
915 (i.e. at least Sun4/20,40,60,65,75,110,260,280,330,360,380,470,490) */
916 #define umul_ppmm(w1, w0, u, v) \
917 __asm__ ("! Inlined umul_ppmm
918 wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr
919 sra %3,31,%%g2 ! Don't move this insn
920 and %2,%%g2,%%g2 ! Don't move this insn
921 andcc %%g0,0,%%g1 ! Don't move this insn
957 : "=r" ((USItype)(w1)), \
958 "=r" ((USItype)(w0)) \
959 : "%rI" ((USItype)(u)), \
961 : "%g1", "%g2" __AND_CLOBBER_CC)
962 #define UMUL_TIME 39 /* 39 instructions */
963 /* It's quite necessary to add this much assembler for the sparc.
964 The default udiv_qrnnd (in C) is more than 10 times slower! */
965 #define udiv_qrnnd(q, r, n1, n0, d) \
966 __asm__ ("! Inlined udiv_qrnnd
970 addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb
971 sub %1,%2,%1 ! this kills msb of n
972 addx %1,%1,%1 ! so this can't give carry
977 addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb
979 sub %1,%2,%1 ! this kills msb of n
984 ! Got carry from n. Subtract next step to cancel this carry.
986 addcc %0,%0,%0 ! shift n1n0 and a 0-bit in lsb
989 ! End of inline udiv_qrnnd" \
990 : "=&r" ((USItype)(q)), \
991 "=&r" ((USItype)(r)) \
992 : "r" ((USItype)(d)), \
993 "1" ((USItype)(n1)), \
994 "0" ((USItype)(n0)) : "%g1" __AND_CLOBBER_CC)
995 #define UDIV_TIME (3+7*32) /* 7 instructions/iteration. 32 iterations. */
996 #endif /* __sparclite__ */
997 #endif /* __sparc_v8__ */
998 #endif /* __sparc__ */
1000 #if defined (__vax__)
1001 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1002 __asm__ ("addl2 %5,%1
1004 : "=g" ((USItype)(sh)), \
1005 "=&g" ((USItype)(sl)) \
1006 : "%0" ((USItype)(ah)), \
1007 "g" ((USItype)(bh)), \
1008 "%1" ((USItype)(al)), \
1009 "g" ((USItype)(bl)))
1010 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1011 __asm__ ("subl2 %5,%1
1013 : "=g" ((USItype)(sh)), \
1014 "=&g" ((USItype)(sl)) \
1015 : "0" ((USItype)(ah)), \
1016 "g" ((USItype)(bh)), \
1017 "1" ((USItype)(al)), \
1018 "g" ((USItype)(bl)))
1019 #define umul_ppmm(xh, xl, m0, m1) \
1023 struct {USItype __l, __h;} __i; \
1025 USItype __m0 = (m0), __m1 = (m1); \
1026 __asm__ ("emul %1,%2,$0,%0" \
1027 : "=r" (__xx.__ll) \
1030 (xh) = __xx.__i.__h; \
1031 (xl) = __xx.__i.__l; \
1032 (xh) += ((((SItype) __m0 >> 31) & __m1) \
1033 + (((SItype) __m1 >> 31) & __m0)); \
1035 #define sdiv_qrnnd(q, r, n1, n0, d) \
1037 union {DItype __ll; \
1038 struct {SItype __l, __h;} __i; \
1040 __xx.__i.__h = n1; __xx.__i.__l = n0; \
1041 __asm__ ("ediv %3,%2,%0,%1" \
1042 : "=g" (q), "=g" (r) \
1043 : "g" (__xx.__ll), "g" (d)); \
1045 #endif /* __vax__ */
1047 #endif /* __GNUC__ */
1049 /* If this machine has no inline assembler, use C macros. */
1051 #if !defined (add_ssaaaa)
1052 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1055 __x = (al) + (bl); \
1056 (sh) = (ah) + (bh) + (__x < (al)); \
1061 #if !defined (sub_ddmmss)
1062 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1065 __x = (al) - (bl); \
1066 (sh) = (ah) - (bh) - (__x > (al)); \
1071 #if !defined (umul_ppmm)
1072 #define umul_ppmm(w1, w0, u, v) \
1074 USItype __x0, __x1, __x2, __x3; \
1075 USItype __ul, __vl, __uh, __vh; \
1077 __ul = __ll_lowpart (u); \
1078 __uh = __ll_highpart (u); \
1079 __vl = __ll_lowpart (v); \
1080 __vh = __ll_highpart (v); \
1082 __x0 = (USItype) __ul * __vl; \
1083 __x1 = (USItype) __ul * __vh; \
1084 __x2 = (USItype) __uh * __vl; \
1085 __x3 = (USItype) __uh * __vh; \
1087 __x1 += __ll_highpart (__x0);/* this can't give carry */ \
1088 __x1 += __x2; /* but this indeed can */ \
1089 if (__x1 < __x2) /* did we get it? */ \
1090 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
1092 (w1) = __x3 + __ll_highpart (__x1); \
1093 (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
1097 #if !defined (__umulsidi3)
1098 #define __umulsidi3(u, v) \
1100 umul_ppmm (__w.s.high, __w.s.low, u, v); \
1104 /* Define this unconditionally, so it can be used for debugging. */
1105 #define __udiv_qrnnd_c(q, r, n1, n0, d) \
1107 USItype __d1, __d0, __q1, __q0; \
1108 USItype __r1, __r0, __m; \
1109 __d1 = __ll_highpart (d); \
1110 __d0 = __ll_lowpart (d); \
1112 __r1 = (n1) % __d1; \
1113 __q1 = (n1) / __d1; \
1114 __m = (USItype) __q1 * __d0; \
1115 __r1 = __r1 * __ll_B | __ll_highpart (n0); \
1118 __q1--, __r1 += (d); \
1119 if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
1121 __q1--, __r1 += (d); \
1125 __r0 = __r1 % __d1; \
1126 __q0 = __r1 / __d1; \
1127 __m = (USItype) __q0 * __d0; \
1128 __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
1131 __q0--, __r0 += (d); \
1134 __q0--, __r0 += (d); \
1138 (q) = (USItype) __q1 * __ll_B | __q0; \
1142 /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
1143 __udiv_w_sdiv (defined in libgcc or elsewhere). */
1144 #if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
1145 #define udiv_qrnnd(q, r, nh, nl, d) \
1148 (q) = __udiv_w_sdiv (&__r, nh, nl, d); \
1153 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
1154 #if !defined (udiv_qrnnd)
1155 #define UDIV_NEEDS_NORMALIZATION 1
1156 #define udiv_qrnnd __udiv_qrnnd_c
1159 #if !defined (count_leading_zeros)
1160 extern const UQItype __clz_tab
[];
1161 #define count_leading_zeros(count, x) \
1163 USItype __xr = (x); \
1166 if (SI_TYPE_SIZE <= 32) \
1168 __a = __xr < (1<<2*__BITS4) \
1169 ? (__xr < (1<<__BITS4) ? 0 : __BITS4) \
1170 : (__xr < (1<<3*__BITS4) ? 2*__BITS4 : 3*__BITS4); \
1174 for (__a = SI_TYPE_SIZE - 8; __a > 0; __a -= 8) \
1175 if (((__xr >> __a) & 0xff) != 0) \
1179 (count) = SI_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
1183 #ifndef UDIV_NEEDS_NORMALIZATION
1184 #define UDIV_NEEDS_NORMALIZATION 0