1 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
2 Copyright (C) 1991,92,94,95,96,97,98,99,2000,2001 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., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 /* You have to define the following before including this file:
21 UWtype -- An unsigned type, default type for operations (typically a "word")
22 UHWtype -- An unsigned type, at least half the size of UWtype.
23 UDWtype -- An unsigned type, at least twice as large a UWtype
24 W_TYPE_SIZE -- size in bits of UWtype
26 UQItype -- Unsigned 8 bit type.
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))
40 #define W_TYPE_SIZE 32
41 #define UWtype USItype
42 #define UHWtype USItype
43 #define UDWtype UDItype
46 /* Define auxiliary asm macros.
48 1) umul_ppmm(high_prod, low_prod, multipler, multiplicand) multiplies two
49 UWtype integers MULTIPLER and MULTIPLICAND, and generates a two UWtype
50 word product in HIGH_PROD and LOW_PROD.
52 2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a
53 UDWtype product. This is just a variant of umul_ppmm.
55 3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
56 denominator) divides a UDWtype, composed by the UWtype integers
57 HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
58 in QUOTIENT and the remainder in REMAINDER. HIGH_NUMERATOR must be less
59 than DENOMINATOR for correct operation. If, in addition, the most
60 significant bit of DENOMINATOR must be 1, then the pre-processor symbol
61 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
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,
91 /* The CPUs come in alphabetical order below.
93 Please add support for more CPUs here, or improve the current support
95 (E.g. WE32100, IBM360.) */
97 #if defined (__GNUC__) && !defined (NO_ASM)
99 /* We sometimes need to clobber "cc" with gcc2, but that would not be
100 understood by gcc1. Use cpp to avoid major code duplication. */
103 #define __AND_CLOBBER_CC
104 #else /* __GNUC__ >= 2 */
105 #define __CLOBBER_CC : "cc"
106 #define __AND_CLOBBER_CC , "cc"
107 #endif /* __GNUC__ < 2 */
109 #if (defined (__a29k__) || defined (_AM29K)) && W_TYPE_SIZE == 32
110 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
111 __asm__ ("add %1,%4,%5\n" \
113 : "=r" ((USItype) (sh)), \
114 "=&r" ((USItype) (sl)) \
115 : "%r" ((USItype) (ah)), \
116 "rI" ((USItype) (bh)), \
117 "%r" ((USItype) (al)), \
118 "rI" ((USItype) (bl)))
119 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
120 __asm__ ("sub %1,%4,%5\n" \
122 : "=r" ((USItype) (sh)), \
123 "=&r" ((USItype) (sl)) \
124 : "r" ((USItype) (ah)), \
125 "rI" ((USItype) (bh)), \
126 "r" ((USItype) (al)), \
127 "rI" ((USItype) (bl)))
128 #define umul_ppmm(xh, xl, m0, m1) \
130 USItype __m0 = (m0), __m1 = (m1); \
131 __asm__ ("multiplu %0,%1,%2" \
132 : "=r" ((USItype) (xl)) \
135 __asm__ ("multmu %0,%1,%2" \
136 : "=r" ((USItype) (xh)) \
140 #define udiv_qrnnd(q, r, n1, n0, d) \
141 __asm__ ("dividu %0,%3,%4" \
142 : "=r" ((USItype) (q)), \
143 "=q" ((USItype) (r)) \
144 : "1" ((USItype) (n1)), \
145 "r" ((USItype) (n0)), \
147 #define count_leading_zeros(count, x) \
148 __asm__ ("clz %0,%1" \
149 : "=r" ((USItype) (count)) \
150 : "r" ((USItype) (x)))
151 #define COUNT_LEADING_ZEROS_0 32
152 #endif /* __a29k__ */
154 #if defined (__alpha) && W_TYPE_SIZE == 64
155 #define umul_ppmm(ph, pl, m0, m1) \
157 UDItype __m0 = (m0), __m1 = (m1); \
158 __asm__ ("umulh %r1,%2,%0" \
159 : "=r" ((UDItype) ph) \
162 (pl) = __m0 * __m1; \
165 #ifndef LONGLONG_STANDALONE
166 #define udiv_qrnnd(q, r, n1, n0, d) \
168 (q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \
171 extern UDItype
__udiv_qrnnd (UDItype
*, UDItype
, UDItype
, UDItype
);
172 #define UDIV_TIME 220
173 #endif /* LONGLONG_STANDALONE */
176 #if defined (__arc__) && W_TYPE_SIZE == 32
177 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
178 __asm__ ("add.f %1, %4, %5\n" \
180 : "=r" ((USItype) (sh)), \
181 "=&r" ((USItype) (sl)) \
182 : "%r" ((USItype) (ah)), \
183 "rIJ" ((USItype) (bh)), \
184 "%r" ((USItype) (al)), \
185 "rIJ" ((USItype) (bl)))
186 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
187 __asm__ ("sub.f %1, %4, %5\n" \
189 : "=r" ((USItype) (sh)), \
190 "=&r" ((USItype) (sl)) \
191 : "r" ((USItype) (ah)), \
192 "rIJ" ((USItype) (bh)), \
193 "r" ((USItype) (al)), \
194 "rIJ" ((USItype) (bl)))
195 /* Call libgcc1 routine. */
196 #define umul_ppmm(w1, w0, u, v) \
199 __w.ll = __umulsidi3 (u, v); \
203 #define __umulsidi3 __umulsidi3
204 UDItype
__umulsidi3 (USItype
, USItype
);
207 #if defined (__arm__) && W_TYPE_SIZE == 32
208 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
209 __asm__ ("adds %1, %4, %5\n" \
211 : "=r" ((USItype) (sh)), \
212 "=&r" ((USItype) (sl)) \
213 : "%r" ((USItype) (ah)), \
214 "rI" ((USItype) (bh)), \
215 "%r" ((USItype) (al)), \
216 "rI" ((USItype) (bl)))
217 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
218 __asm__ ("subs %1, %4, %5\n" \
220 : "=r" ((USItype) (sh)), \
221 "=&r" ((USItype) (sl)) \
222 : "r" ((USItype) (ah)), \
223 "rI" ((USItype) (bh)), \
224 "r" ((USItype) (al)), \
225 "rI" ((USItype) (bl)))
226 #define umul_ppmm(xh, xl, a, b) \
227 {register USItype __t0, __t1, __t2; \
228 __asm__ ("%@ Inlined umul_ppmm\n" \
229 "mov %2, %5, lsr #16\n" \
230 "mov %0, %6, lsr #16\n" \
231 "bic %3, %5, %2, lsl #16\n" \
232 "bic %4, %6, %0, lsl #16\n" \
237 "adds %3, %4, %3\n" \
238 "addcs %0, %0, #65536\n" \
239 "adds %1, %1, %3, lsl #16\n" \
240 "adc %0, %0, %3, lsr #16" \
241 : "=&r" ((USItype) (xh)), \
242 "=r" ((USItype) (xl)), \
243 "=&r" (__t0), "=&r" (__t1), "=r" (__t2) \
244 : "r" ((USItype) (a)), \
245 "r" ((USItype) (b)));}
247 #define UDIV_TIME 100
250 #if defined (__clipper__) && W_TYPE_SIZE == 32
251 #define umul_ppmm(w1, w0, u, v) \
252 ({union {UDItype __ll; \
253 struct {USItype __l, __h;} __i; \
255 __asm__ ("mulwux %2,%0" \
257 : "%0" ((USItype) (u)), \
258 "r" ((USItype) (v))); \
259 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
260 #define smul_ppmm(w1, w0, u, v) \
261 ({union {DItype __ll; \
262 struct {SItype __l, __h;} __i; \
264 __asm__ ("mulwx %2,%0" \
266 : "%0" ((SItype) (u)), \
267 "r" ((SItype) (v))); \
268 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
269 #define __umulsidi3(u, v) \
271 __asm__ ("mulwux %2,%0" \
273 : "%0" ((USItype) (u)), \
274 "r" ((USItype) (v))); \
276 #endif /* __clipper__ */
278 #if defined (__gmicro__) && W_TYPE_SIZE == 32
279 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
280 __asm__ ("add.w %5,%1\n" \
282 : "=g" ((USItype) (sh)), \
283 "=&g" ((USItype) (sl)) \
284 : "%0" ((USItype) (ah)), \
285 "g" ((USItype) (bh)), \
286 "%1" ((USItype) (al)), \
287 "g" ((USItype) (bl)))
288 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
289 __asm__ ("sub.w %5,%1\n" \
291 : "=g" ((USItype) (sh)), \
292 "=&g" ((USItype) (sl)) \
293 : "0" ((USItype) (ah)), \
294 "g" ((USItype) (bh)), \
295 "1" ((USItype) (al)), \
296 "g" ((USItype) (bl)))
297 #define umul_ppmm(ph, pl, m0, m1) \
298 __asm__ ("mulx %3,%0,%1" \
299 : "=g" ((USItype) (ph)), \
300 "=r" ((USItype) (pl)) \
301 : "%0" ((USItype) (m0)), \
302 "g" ((USItype) (m1)))
303 #define udiv_qrnnd(q, r, nh, nl, d) \
304 __asm__ ("divx %4,%0,%1" \
305 : "=g" ((USItype) (q)), \
306 "=r" ((USItype) (r)) \
307 : "1" ((USItype) (nh)), \
308 "0" ((USItype) (nl)), \
310 #define count_leading_zeros(count, x) \
311 __asm__ ("bsch/1 %1,%0" \
313 : "g" ((USItype) (x)), \
317 #if defined (__hppa) && W_TYPE_SIZE == 32
318 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
319 __asm__ ("add %4,%5,%1\n" \
321 : "=r" ((USItype) (sh)), \
322 "=&r" ((USItype) (sl)) \
323 : "%rM" ((USItype) (ah)), \
324 "rM" ((USItype) (bh)), \
325 "%rM" ((USItype) (al)), \
326 "rM" ((USItype) (bl)))
327 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
328 __asm__ ("sub %4,%5,%1\n" \
330 : "=r" ((USItype) (sh)), \
331 "=&r" ((USItype) (sl)) \
332 : "rM" ((USItype) (ah)), \
333 "rM" ((USItype) (bh)), \
334 "rM" ((USItype) (al)), \
335 "rM" ((USItype) (bl)))
336 #if defined (_PA_RISC1_1)
337 #define umul_ppmm(w1, w0, u, v) \
342 struct {USItype __w1, __w0;} __w1w0; \
344 __asm__ ("xmpyu %1,%2,%0" \
346 : "x" ((USItype) (u)), \
347 "x" ((USItype) (v))); \
348 (w1) = __t.__w1w0.__w1; \
349 (w0) = __t.__w1w0.__w0; \
356 #define count_leading_zeros(count, x) \
361 "extru,= %1,15,16,%%r0 ; Bits 31..16 zero?\n" \
362 "extru,tr %1,15,16,%1 ; No. Shift down, skip add.\n" \
363 "ldo 16(%0),%0 ; Yes. Perform add.\n" \
364 "extru,= %1,23,8,%%r0 ; Bits 15..8 zero?\n" \
365 "extru,tr %1,23,8,%1 ; No. Shift down, skip add.\n" \
366 "ldo 8(%0),%0 ; Yes. Perform add.\n" \
367 "extru,= %1,27,4,%%r0 ; Bits 7..4 zero?\n" \
368 "extru,tr %1,27,4,%1 ; No. Shift down, skip add.\n" \
369 "ldo 4(%0),%0 ; Yes. Perform add.\n" \
370 "extru,= %1,29,2,%%r0 ; Bits 3..2 zero?\n" \
371 "extru,tr %1,29,2,%1 ; No. Shift down, skip add.\n" \
372 "ldo 2(%0),%0 ; Yes. Perform add.\n" \
373 "extru %1,30,1,%1 ; Extract bit 1.\n" \
374 "sub %0,%1,%0 ; Subtract it." \
375 : "=r" (count), "=r" (__tmp) : "1" (x)); \
379 #if (defined (__i370__) || defined (__mvs__)) && W_TYPE_SIZE == 32
380 #define umul_ppmm(xh, xl, m0, m1) \
382 union {UDItype __ll; \
383 struct {USItype __h, __l;} __i; \
385 USItype __m0 = (m0), __m1 = (m1); \
386 __asm__ ("mr %0,%3" \
387 : "=r" (__xx.__i.__h), \
388 "=r" (__xx.__i.__l) \
391 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
392 (xh) += ((((SItype) __m0 >> 31) & __m1) \
393 + (((SItype) __m1 >> 31) & __m0)); \
395 #define smul_ppmm(xh, xl, m0, m1) \
397 union {DItype __ll; \
398 struct {USItype __h, __l;} __i; \
400 __asm__ ("mr %0,%3" \
401 : "=r" (__xx.__i.__h), \
402 "=r" (__xx.__i.__l) \
405 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
407 #define sdiv_qrnnd(q, r, n1, n0, d) \
409 union {DItype __ll; \
410 struct {USItype __h, __l;} __i; \
412 __xx.__i.__h = n1; __xx.__i.__l = n0; \
413 __asm__ ("dr %0,%2" \
415 : "0" (__xx.__ll), "r" (d)); \
416 (q) = __xx.__i.__l; (r) = __xx.__i.__h; \
420 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
421 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
422 __asm__ ("addl %5,%1\n" \
424 : "=r" ((USItype) (sh)), \
425 "=&r" ((USItype) (sl)) \
426 : "%0" ((USItype) (ah)), \
427 "g" ((USItype) (bh)), \
428 "%1" ((USItype) (al)), \
429 "g" ((USItype) (bl)))
430 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
431 __asm__ ("subl %5,%1\n" \
433 : "=r" ((USItype) (sh)), \
434 "=&r" ((USItype) (sl)) \
435 : "0" ((USItype) (ah)), \
436 "g" ((USItype) (bh)), \
437 "1" ((USItype) (al)), \
438 "g" ((USItype) (bl)))
439 #define umul_ppmm(w1, w0, u, v) \
441 : "=a" ((USItype) (w0)), \
442 "=d" ((USItype) (w1)) \
443 : "%0" ((USItype) (u)), \
444 "rm" ((USItype) (v)))
445 #define udiv_qrnnd(q, r, n1, n0, d) \
447 : "=a" ((USItype) (q)), \
448 "=d" ((USItype) (r)) \
449 : "0" ((USItype) (n0)), \
450 "1" ((USItype) (n1)), \
451 "rm" ((USItype) (d)))
452 #define count_leading_zeros(count, x) \
455 __asm__ ("bsrl %1,%0" \
456 : "=r" (__cbtmp) : "rm" ((USItype) (x))); \
457 (count) = __cbtmp ^ 31; \
459 #define count_trailing_zeros(count, x) \
460 __asm__ ("bsfl %1,%0" : "=r" (count) : "rm" ((USItype)(x)))
465 #if defined (__i860__) && W_TYPE_SIZE == 32
467 /* Make sure these patterns really improve the code before
468 switching them on. */
469 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
474 struct {USItype __l, __h;} __i; \
476 __a.__i.__l = (al); \
477 __a.__i.__h = (ah); \
478 __b.__i.__l = (bl); \
479 __b.__i.__h = (bh); \
480 __asm__ ("fiadd.dd %1,%2,%0" \
482 : "%f" (__a.__ll), "f" (__b.__ll)); \
483 (sh) = __s.__i.__h; \
484 (sl) = __s.__i.__l; \
486 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
491 struct {USItype __l, __h;} __i; \
493 __a.__i.__l = (al); \
494 __a.__i.__h = (ah); \
495 __b.__i.__l = (bl); \
496 __b.__i.__h = (bh); \
497 __asm__ ("fisub.dd %1,%2,%0" \
499 : "%f" (__a.__ll), "f" (__b.__ll)); \
500 (sh) = __s.__i.__h; \
501 (sl) = __s.__i.__l; \
504 #endif /* __i860__ */
506 #if defined (__i960__) && W_TYPE_SIZE == 32
507 #define umul_ppmm(w1, w0, u, v) \
508 ({union {UDItype __ll; \
509 struct {USItype __l, __h;} __i; \
511 __asm__ ("emul %2,%1,%0" \
513 : "%dI" ((USItype) (u)), \
514 "dI" ((USItype) (v))); \
515 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
516 #define __umulsidi3(u, v) \
518 __asm__ ("emul %2,%1,%0" \
520 : "%dI" ((USItype) (u)), \
521 "dI" ((USItype) (v))); \
523 #endif /* __i960__ */
525 #if defined (__M32R__) && W_TYPE_SIZE == 32
526 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
527 /* The cmp clears the condition bit. */ \
528 __asm__ ("cmp %0,%0\n" \
531 : "=r" ((USItype) (sh)), \
532 "=&r" ((USItype) (sl)) \
533 : "%0" ((USItype) (ah)), \
534 "r" ((USItype) (bh)), \
535 "%1" ((USItype) (al)), \
536 "r" ((USItype) (bl)) \
538 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
539 /* The cmp clears the condition bit. */ \
540 __asm__ ("cmp %0,%0\n" \
543 : "=r" ((USItype) (sh)), \
544 "=&r" ((USItype) (sl)) \
545 : "0" ((USItype) (ah)), \
546 "r" ((USItype) (bh)), \
547 "1" ((USItype) (al)), \
548 "r" ((USItype) (bl)) \
550 #endif /* __M32R__ */
552 #if defined (__mc68000__) && W_TYPE_SIZE == 32
553 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
554 __asm__ ("add%.l %5,%1\n" \
556 : "=d" ((USItype) (sh)), \
557 "=&d" ((USItype) (sl)) \
558 : "%0" ((USItype) (ah)), \
559 "d" ((USItype) (bh)), \
560 "%1" ((USItype) (al)), \
561 "g" ((USItype) (bl)))
562 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
563 __asm__ ("sub%.l %5,%1\n" \
565 : "=d" ((USItype) (sh)), \
566 "=&d" ((USItype) (sl)) \
567 : "0" ((USItype) (ah)), \
568 "d" ((USItype) (bh)), \
569 "1" ((USItype) (al)), \
570 "g" ((USItype) (bl)))
572 /* The '020, '030, '040 and CPU32 have 32x32->64 and 64/32->32q-32r. */
573 #if defined (__mc68020__) || defined(mc68020) \
574 || defined(__mc68030__) || defined(mc68030) \
575 || defined(__mc68040__) || defined(mc68040) \
576 || defined(__mcpu32__) || defined(mcpu32) \
578 #define umul_ppmm(w1, w0, u, v) \
579 __asm__ ("mulu%.l %3,%1:%0" \
580 : "=d" ((USItype) (w0)), \
581 "=d" ((USItype) (w1)) \
582 : "%0" ((USItype) (u)), \
583 "dmi" ((USItype) (v)))
585 #define udiv_qrnnd(q, r, n1, n0, d) \
586 __asm__ ("divu%.l %4,%1:%0" \
587 : "=d" ((USItype) (q)), \
588 "=d" ((USItype) (r)) \
589 : "0" ((USItype) (n0)), \
590 "1" ((USItype) (n1)), \
591 "dmi" ((USItype) (d)))
593 #define sdiv_qrnnd(q, r, n1, n0, d) \
594 __asm__ ("divs%.l %4,%1:%0" \
595 : "=d" ((USItype) (q)), \
596 "=d" ((USItype) (r)) \
597 : "0" ((USItype) (n0)), \
598 "1" ((USItype) (n1)), \
599 "dmi" ((USItype) (d)))
601 #else /* not mc68020 */
602 #if !defined(__mcf5200__)
603 /* %/ inserts REGISTER_PREFIX, %# inserts IMMEDIATE_PREFIX. */
604 #define umul_ppmm(xh, xl, a, b) \
605 __asm__ ("| Inlined umul_ppmm\n" \
606 " move%.l %2,%/d0\n" \
607 " move%.l %3,%/d1\n" \
608 " move%.l %/d0,%/d2\n" \
610 " move%.l %/d1,%/d3\n" \
612 " move%.w %/d2,%/d4\n" \
613 " mulu %/d3,%/d4\n" \
614 " mulu %/d1,%/d2\n" \
615 " mulu %/d0,%/d3\n" \
616 " mulu %/d0,%/d1\n" \
617 " move%.l %/d4,%/d0\n" \
618 " eor%.w %/d0,%/d0\n" \
620 " add%.l %/d0,%/d2\n" \
621 " add%.l %/d3,%/d2\n" \
623 " add%.l %#65536,%/d1\n" \
625 " moveq %#0,%/d0\n" \
626 " move%.w %/d2,%/d0\n" \
627 " move%.w %/d4,%/d2\n" \
628 " move%.l %/d2,%1\n" \
629 " add%.l %/d1,%/d0\n" \
631 : "=g" ((USItype) (xh)), \
632 "=g" ((USItype) (xl)) \
633 : "g" ((USItype) (a)), \
634 "g" ((USItype) (b)) \
635 : "d0", "d1", "d2", "d3", "d4")
636 #define UMUL_TIME 100
637 #define UDIV_TIME 400
638 #endif /* not mcf5200 */
639 #endif /* not mc68020 */
641 /* The '020, '030, '040 and '060 have bitfield insns. */
642 #if defined (__mc68020__) || defined(mc68020) \
643 || defined(__mc68030__) || defined(mc68030) \
644 || defined(__mc68040__) || defined(mc68040) \
645 || defined(__mc68060__) || defined(mc68060) \
647 #define count_leading_zeros(count, x) \
648 __asm__ ("bfffo %1{%b2:%b2},%0" \
649 : "=d" ((USItype) (count)) \
650 : "od" ((USItype) (x)), "n" (0))
654 #if defined (__m88000__) && W_TYPE_SIZE == 32
655 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
656 __asm__ ("addu.co %1,%r4,%r5\n" \
657 "addu.ci %0,%r2,%r3" \
658 : "=r" ((USItype) (sh)), \
659 "=&r" ((USItype) (sl)) \
660 : "%rJ" ((USItype) (ah)), \
661 "rJ" ((USItype) (bh)), \
662 "%rJ" ((USItype) (al)), \
663 "rJ" ((USItype) (bl)))
664 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
665 __asm__ ("subu.co %1,%r4,%r5\n" \
666 "subu.ci %0,%r2,%r3" \
667 : "=r" ((USItype) (sh)), \
668 "=&r" ((USItype) (sl)) \
669 : "rJ" ((USItype) (ah)), \
670 "rJ" ((USItype) (bh)), \
671 "rJ" ((USItype) (al)), \
672 "rJ" ((USItype) (bl)))
673 #define count_leading_zeros(count, x) \
676 __asm__ ("ff1 %0,%1" \
678 : "r" ((USItype) (x))); \
679 (count) = __cbtmp ^ 31; \
681 #define COUNT_LEADING_ZEROS_0 63 /* sic */
682 #if defined (__mc88110__)
683 #define umul_ppmm(wh, wl, u, v) \
685 union {UDItype __ll; \
686 struct {USItype __h, __l;} __i; \
688 __asm__ ("mulu.d %0,%1,%2" \
690 : "r" ((USItype) (u)), \
691 "r" ((USItype) (v))); \
692 (wh) = __xx.__i.__h; \
693 (wl) = __xx.__i.__l; \
695 #define udiv_qrnnd(q, r, n1, n0, d) \
696 ({union {UDItype __ll; \
697 struct {USItype __h, __l;} __i; \
700 __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
701 __asm__ ("divu.d %0,%1,%2" \
704 "r" ((USItype) (d))); \
705 (r) = (n0) - __q * (d); (q) = __q; })
710 #define UDIV_TIME 150
711 #endif /* __mc88110__ */
712 #endif /* __m88000__ */
714 #if defined (__mips__) && W_TYPE_SIZE == 32
715 #define umul_ppmm(w1, w0, u, v) \
716 __asm__ ("multu %2,%3" \
717 : "=l" ((USItype) (w0)), \
718 "=h" ((USItype) (w1)) \
719 : "d" ((USItype) (u)), \
722 #define UDIV_TIME 100
723 #endif /* __mips__ */
725 #if defined (__ns32000__) && W_TYPE_SIZE == 32
726 #define umul_ppmm(w1, w0, u, v) \
727 ({union {UDItype __ll; \
728 struct {USItype __l, __h;} __i; \
730 __asm__ ("meid %2,%0" \
732 : "%0" ((USItype) (u)), \
733 "g" ((USItype) (v))); \
734 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
735 #define __umulsidi3(u, v) \
737 __asm__ ("meid %2,%0" \
739 : "%0" ((USItype) (u)), \
740 "g" ((USItype) (v))); \
742 #define udiv_qrnnd(q, r, n1, n0, d) \
743 ({union {UDItype __ll; \
744 struct {USItype __l, __h;} __i; \
746 __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
747 __asm__ ("deid %2,%0" \
750 "g" ((USItype) (d))); \
751 (r) = __xx.__i.__l; (q) = __xx.__i.__h; })
752 #define count_trailing_zeros(count,x) \
754 __asm__ ("ffsd %2,%0" \
755 : "=r" ((USItype
) (count
)) \
756 : "0" ((USItype
) 0), \
757 "r" ((USItype
) (x
))); \
759 #endif /* __ns32000__ */
761 #if (defined (_ARCH_PPC) || defined (_IBMR2)) && W_TYPE_SIZE == 32
762 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
764 if (__builtin_constant_p (bh) && (bh) == 0) \
765 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
766 : "=r" ((USItype) (sh)), \
767 "=&r" ((USItype) (sl)) \
768 : "%r" ((USItype) (ah)), \
769 "%r" ((USItype) (al)), \
770 "rI" ((USItype) (bl))); \
771 else if (__builtin_constant_p (bh) && (bh) ==~(USItype) 0) \
772 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
773 : "=r" ((USItype) (sh)), \
774 "=&r" ((USItype) (sl)) \
775 : "%r" ((USItype) (ah)), \
776 "%r" ((USItype) (al)), \
777 "rI" ((USItype) (bl))); \
779 __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
780 : "=r" ((USItype) (sh)), \
781 "=&r" ((USItype) (sl)) \
782 : "%r" ((USItype) (ah)), \
783 "r" ((USItype) (bh)), \
784 "%r" ((USItype) (al)), \
785 "rI" ((USItype) (bl))); \
787 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
789 if (__builtin_constant_p (ah) && (ah) == 0) \
790 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
791 : "=r" ((USItype) (sh)), \
792 "=&r" ((USItype) (sl)) \
793 : "r" ((USItype) (bh)), \
794 "rI" ((USItype) (al)), \
795 "r" ((USItype) (bl))); \
796 else if (__builtin_constant_p (ah) && (ah) ==~(USItype) 0) \
797 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
798 : "=r" ((USItype) (sh)), \
799 "=&r" ((USItype) (sl)) \
800 : "r" ((USItype) (bh)), \
801 "rI" ((USItype) (al)), \
802 "r" ((USItype) (bl))); \
803 else if (__builtin_constant_p (bh) && (bh) == 0) \
804 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
805 : "=r" ((USItype) (sh)), \
806 "=&r" ((USItype) (sl)) \
807 : "r" ((USItype) (ah)), \
808 "rI" ((USItype) (al)), \
809 "r" ((USItype) (bl))); \
810 else if (__builtin_constant_p (bh) && (bh) ==~(USItype) 0) \
811 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
812 : "=r" ((USItype) (sh)), \
813 "=&r" ((USItype) (sl)) \
814 : "r" ((USItype) (ah)), \
815 "rI" ((USItype) (al)), \
816 "r" ((USItype) (bl))); \
818 __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
819 : "=r" ((USItype) (sh)), \
820 "=&r" ((USItype) (sl)) \
821 : "r" ((USItype) (ah)), \
822 "r" ((USItype) (bh)), \
823 "rI" ((USItype) (al)), \
824 "r" ((USItype) (bl))); \
826 #define count_leading_zeros(count, x) \
827 __asm__ ("{cntlz|cntlzw} %0,%1" \
828 : "=r" ((USItype) (count)) \
829 : "r" ((USItype) (x)))
830 #define COUNT_LEADING_ZEROS_0 32
831 #if defined (_ARCH_PPC)
832 #define umul_ppmm(ph, pl, m0, m1) \
834 USItype __m0 = (m0), __m1 = (m1); \
835 __asm__ ("mulhwu %0,%1,%2" \
836 : "=r" ((USItype) ph) \
839 (pl) = __m0 * __m1; \
842 #define smul_ppmm(ph, pl, m0, m1) \
844 SItype __m0 = (m0), __m1 = (m1); \
845 __asm__ ("mulhw %0,%1,%2" \
846 : "=r" ((SItype) ph) \
849 (pl) = __m0 * __m1; \
852 #define UDIV_TIME 120
854 #define umul_ppmm(xh, xl, m0, m1) \
856 USItype __m0 = (m0), __m1 = (m1); \
857 __asm__ ("mul %0,%2,%3" \
858 : "=r" ((USItype) (xh)), \
859 "=q" ((USItype) (xl)) \
862 (xh) += ((((SItype) __m0 >> 31) & __m1) \
863 + (((SItype) __m1 >> 31) & __m0)); \
866 #define smul_ppmm(xh, xl, m0, m1) \
867 __asm__ ("mul %0,%2,%3" \
868 : "=r" ((SItype) (xh)), \
869 "=q" ((SItype) (xl)) \
873 #define sdiv_qrnnd(q, r, nh, nl, d) \
874 __asm__ ("div %0,%2,%4" \
875 : "=r" ((SItype) (q)), "=q" ((SItype) (r)) \
876 : "r" ((SItype) (nh)), "1" ((SItype) (nl)), "r" ((SItype) (d)))
877 #define UDIV_TIME 100
879 #endif /* Power architecture variants. */
881 #if defined (__pyr__) && W_TYPE_SIZE == 32
882 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
883 __asm__ ("addw %5,%1\n" \
885 : "=r" ((USItype) (sh)), \
886 "=&r" ((USItype) (sl)) \
887 : "%0" ((USItype) (ah)), \
888 "g" ((USItype) (bh)), \
889 "%1" ((USItype) (al)), \
890 "g" ((USItype) (bl)))
891 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
892 __asm__ ("subw %5,%1\n" \
894 : "=r" ((USItype) (sh)), \
895 "=&r" ((USItype) (sl)) \
896 : "0" ((USItype) (ah)), \
897 "g" ((USItype) (bh)), \
898 "1" ((USItype) (al)), \
899 "g" ((USItype) (bl)))
900 /* This insn works on Pyramids with AP, XP, or MI CPUs, but not with SP. */
901 #define umul_ppmm(w1, w0, u, v) \
902 ({union {UDItype __ll; \
903 struct {USItype __h, __l;} __i; \
905 __asm__ ("movw %1,%R0\n" \
907 : "=&r" (__xx.__ll) \
908 : "g" ((USItype) (u)), \
909 "g" ((USItype) (v))); \
910 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
913 #if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
914 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
915 __asm__ ("a %1,%5\n" \
917 : "=r" ((USItype) (sh)), \
918 "=&r" ((USItype) (sl)) \
919 : "%0" ((USItype) (ah)), \
920 "r" ((USItype) (bh)), \
921 "%1" ((USItype) (al)), \
922 "r" ((USItype) (bl)))
923 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
924 __asm__ ("s %1,%5\n" \
926 : "=r" ((USItype) (sh)), \
927 "=&r" ((USItype) (sl)) \
928 : "0" ((USItype) (ah)), \
929 "r" ((USItype) (bh)), \
930 "1" ((USItype) (al)), \
931 "r" ((USItype) (bl)))
932 #define umul_ppmm(ph, pl, m0, m1) \
934 USItype __m0 = (m0), __m1 = (m1); \
956 : "=r" ((USItype) (ph)), \
957 "=r" ((USItype) (pl)) \
961 (ph) += ((((SItype) __m0 >> 31) & __m1) \
962 + (((SItype) __m1 >> 31) & __m0)); \
965 #define UDIV_TIME 200
966 #define count_leading_zeros(count, x) \
968 if ((x) >= 0x10000) \
969 __asm__ ("clz %0,%1" \
970 : "=r" ((USItype) (count)) \
971 : "r" ((USItype) (x) >> 16)); \
974 __asm__ ("clz %0,%1" \
975 : "=r" ((USItype) (count)) \
976 : "r" ((USItype) (x))); \
982 #if defined (__sh2__) && W_TYPE_SIZE == 32
983 #define umul_ppmm(w1, w0, u, v) \
988 : "=r" ((USItype)(w1)), \
989 "=r" ((USItype)(w0)) \
990 : "r" ((USItype)(u)), \
996 #if defined (__sparc__) && !defined(__arch64__) \
997 && !defined(__sparcv9) && W_TYPE_SIZE == 32
998 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
999 __asm__ ("addcc %r4,%5,%1\n" \
1001 : "=r" ((USItype) (sh)), \
1002 "=&r" ((USItype) (sl)) \
1003 : "%rJ" ((USItype) (ah)), \
1004 "rI" ((USItype) (bh)), \
1005 "%rJ" ((USItype) (al)), \
1006 "rI" ((USItype) (bl)) \
1008 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1009 __asm__ ("subcc %r4,%5,%1\n" \
1011 : "=r" ((USItype) (sh)), \
1012 "=&r" ((USItype) (sl)) \
1013 : "rJ" ((USItype) (ah)), \
1014 "rI" ((USItype) (bh)), \
1015 "rJ" ((USItype) (al)), \
1016 "rI" ((USItype) (bl)) \
1018 #if defined (__sparc_v8__)
1019 #define umul_ppmm(w1, w0, u, v) \
1020 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
1021 : "=r" ((USItype) (w1)), \
1022 "=r" ((USItype) (w0)) \
1023 : "r" ((USItype) (u)), \
1024 "r" ((USItype) (v)))
1025 #define udiv_qrnnd(q, r, n1, n0, d) \
1026 __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
1027 : "=&r" ((USItype) (q)), \
1028 "=&r" ((USItype) (r)) \
1029 : "r" ((USItype) (n1)), \
1030 "r" ((USItype) (n0)), \
1031 "r" ((USItype) (d)))
1033 #if defined (__sparclite__)
1034 /* This has hardware multiply but not divide. It also has two additional
1035 instructions scan (ffs from high bit) and divscc. */
1036 #define umul_ppmm(w1, w0, u, v) \
1037 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
1038 : "=r" ((USItype) (w1)), \
1039 "=r" ((USItype) (w0)) \
1040 : "r" ((USItype) (u)), \
1041 "r" ((USItype) (v)))
1042 #define udiv_qrnnd(q, r, n1, n0, d) \
1043 __asm__ ("! Inlined udiv_qrnnd\n" \
1044 " wr %%g0,%2,%%y ! Not a delayed write for sparclite\n" \
1046 " divscc %3,%4,%%g1\n" \
1047 " divscc %%g1,%4,%%g1\n" \
1048 " divscc %%g1,%4,%%g1\n" \
1049 " divscc %%g1,%4,%%g1\n" \
1050 " divscc %%g1,%4,%%g1\n" \
1051 " divscc %%g1,%4,%%g1\n" \
1052 " divscc %%g1,%4,%%g1\n" \
1053 " divscc %%g1,%4,%%g1\n" \
1054 " divscc %%g1,%4,%%g1\n" \
1055 " divscc %%g1,%4,%%g1\n" \
1056 " divscc %%g1,%4,%%g1\n" \
1057 " divscc %%g1,%4,%%g1\n" \
1058 " divscc %%g1,%4,%%g1\n" \
1059 " divscc %%g1,%4,%%g1\n" \
1060 " divscc %%g1,%4,%%g1\n" \
1061 " divscc %%g1,%4,%%g1\n" \
1062 " divscc %%g1,%4,%%g1\n" \
1063 " divscc %%g1,%4,%%g1\n" \
1064 " divscc %%g1,%4,%%g1\n" \
1065 " divscc %%g1,%4,%%g1\n" \
1066 " divscc %%g1,%4,%%g1\n" \
1067 " divscc %%g1,%4,%%g1\n" \
1068 " divscc %%g1,%4,%%g1\n" \
1069 " divscc %%g1,%4,%%g1\n" \
1070 " divscc %%g1,%4,%%g1\n" \
1071 " divscc %%g1,%4,%%g1\n" \
1072 " divscc %%g1,%4,%%g1\n" \
1073 " divscc %%g1,%4,%%g1\n" \
1074 " divscc %%g1,%4,%%g1\n" \
1075 " divscc %%g1,%4,%%g1\n" \
1076 " divscc %%g1,%4,%%g1\n" \
1077 " divscc %%g1,%4,%0\n" \
1081 "1: ! End of inline udiv_qrnnd" \
1082 : "=r" ((USItype) (q)), \
1083 "=r" ((USItype) (r)) \
1084 : "r" ((USItype) (n1)), \
1085 "r" ((USItype) (n0)), \
1086 "rI" ((USItype) (d)) \
1087 : "g1" __AND_CLOBBER_CC)
1088 #define UDIV_TIME 37
1089 #define count_leading_zeros(count, x) \
1091 __asm__ ("scan %1,1,%0" \
1092 : "=r" ((USItype) (count)) \
1093 : "r" ((USItype) (x))); \
1095 /* Early sparclites return 63 for an argument of 0, but they warn that future
1096 implementations might change this. Therefore, leave COUNT_LEADING_ZEROS_0
1099 /* SPARC without integer multiplication and divide instructions.
1100 (i.e. at least Sun4/20,40,60,65,75,110,260,280,330,360,380,470,490) */
1101 #define umul_ppmm(w1, w0, u, v) \
1102 __asm__ ("! Inlined umul_ppmm\n" \
1103 " wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr\n"\
1104 " sra %3,31,%%o5 ! Don't move this insn\n" \
1105 " and %2,%%o5,%%o5 ! Don't move this insn\n" \
1106 " andcc %%g0,0,%%g1 ! Don't move this insn\n" \
1107 " mulscc %%g1,%3,%%g1\n" \
1108 " mulscc %%g1,%3,%%g1\n" \
1109 " mulscc %%g1,%3,%%g1\n" \
1110 " mulscc %%g1,%3,%%g1\n" \
1111 " mulscc %%g1,%3,%%g1\n" \
1112 " mulscc %%g1,%3,%%g1\n" \
1113 " mulscc %%g1,%3,%%g1\n" \
1114 " mulscc %%g1,%3,%%g1\n" \
1115 " mulscc %%g1,%3,%%g1\n" \
1116 " mulscc %%g1,%3,%%g1\n" \
1117 " mulscc %%g1,%3,%%g1\n" \
1118 " mulscc %%g1,%3,%%g1\n" \
1119 " mulscc %%g1,%3,%%g1\n" \
1120 " mulscc %%g1,%3,%%g1\n" \
1121 " mulscc %%g1,%3,%%g1\n" \
1122 " mulscc %%g1,%3,%%g1\n" \
1123 " mulscc %%g1,%3,%%g1\n" \
1124 " mulscc %%g1,%3,%%g1\n" \
1125 " mulscc %%g1,%3,%%g1\n" \
1126 " mulscc %%g1,%3,%%g1\n" \
1127 " mulscc %%g1,%3,%%g1\n" \
1128 " mulscc %%g1,%3,%%g1\n" \
1129 " mulscc %%g1,%3,%%g1\n" \
1130 " mulscc %%g1,%3,%%g1\n" \
1131 " mulscc %%g1,%3,%%g1\n" \
1132 " mulscc %%g1,%3,%%g1\n" \
1133 " mulscc %%g1,%3,%%g1\n" \
1134 " mulscc %%g1,%3,%%g1\n" \
1135 " mulscc %%g1,%3,%%g1\n" \
1136 " mulscc %%g1,%3,%%g1\n" \
1137 " mulscc %%g1,%3,%%g1\n" \
1138 " mulscc %%g1,%3,%%g1\n" \
1139 " mulscc %%g1,0,%%g1\n" \
1140 " add %%g1,%%o5,%0\n" \
1142 : "=r" ((USItype) (w1)), \
1143 "=r" ((USItype) (w0)) \
1144 : "%rI" ((USItype) (u)), \
1145 "r" ((USItype) (v)) \
1146 : "g1", "o5" __AND_CLOBBER_CC)
1147 #define UMUL_TIME 39 /* 39 instructions */
1148 /* It's quite necessary to add this much assembler for the sparc.
1149 The default udiv_qrnnd (in C) is more than 10 times slower! */
1150 #define udiv_qrnnd(q, r, n1, n0, d) \
1151 __asm__ ("! Inlined udiv_qrnnd\n" \
1153 " subcc %1,%2,%%g0\n" \
1155 " addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n" \
1156 " sub %1,%2,%1 ! this kills msb of n\n" \
1157 " addx %1,%1,%1 ! so this can't give carry\n" \
1158 " subcc %%g1,1,%%g1\n" \
1160 " subcc %1,%2,%%g0\n" \
1162 " addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n" \
1164 " sub %1,%2,%1 ! this kills msb of n\n" \
1165 "4: sub %1,%2,%1\n" \
1166 "5: addxcc %1,%1,%1\n" \
1168 " subcc %%g1,1,%%g1\n" \
1169 "! Got carry from n. Subtract next step to cancel this carry.\n" \
1171 " addcc %0,%0,%0 ! shift n1n0 and a 0-bit in lsb\n" \
1173 "3: xnor %0,0,%0\n" \
1174 " ! End of inline udiv_qrnnd" \
1175 : "=&r" ((USItype) (q)), \
1176 "=&r" ((USItype) (r)) \
1177 : "r" ((USItype) (d)), \
1178 "1" ((USItype) (n1)), \
1179 "0" ((USItype) (n0)) : "g1" __AND_CLOBBER_CC)
1180 #define UDIV_TIME (3+7*32) /* 7 instructions/iteration. 32 iterations. */
1181 #endif /* __sparclite__ */
1182 #endif /* __sparc_v8__ */
1183 #endif /* __sparc__ */
1185 #if ((defined (__sparc__) && defined (__arch64__)) \
1186 || defined (__sparcv9)) && W_TYPE_SIZE == 64
1187 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1188 __asm__ ("addcc %r4,%5,%1\n" \
1190 "bcs,a,pn %%xcc, 1f\n" \
1193 : "=r" ((UDItype)(sh)), \
1194 "=&r" ((UDItype)(sl)) \
1195 : "%rJ" ((UDItype)(ah)), \
1196 "rI" ((UDItype)(bh)), \
1197 "%rJ" ((UDItype)(al)), \
1198 "rI" ((UDItype)(bl)) \
1201 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1202 __asm__ ("subcc %r4,%5,%1\n" \
1204 "bcs,a,pn %%xcc, 1f\n" \
1207 : "=r" ((UDItype)(sh)), \
1208 "=&r" ((UDItype)(sl)) \
1209 : "rJ" ((UDItype)(ah)), \
1210 "rI" ((UDItype)(bh)), \
1211 "rJ" ((UDItype)(al)), \
1212 "rI" ((UDItype)(bl)) \
1215 #define umul_ppmm(wh, wl, u, v) \
1217 UDItype tmp1, tmp2, tmp3, tmp4; \
1218 __asm__ __volatile__ ( \
1227 "addcc %4,%5,%4\n" \
1231 "sethi %%hi(0x80000000),%2\n" \
1232 "addcc %4,%3,%4\n" \
1235 "movcc %%xcc,%%g0,%2\n" \
1236 "addcc %5,%4,%5\n" \
1240 : "=r" ((UDItype)(wh)), \
1241 "=&r" ((UDItype)(wl)), \
1242 "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4) \
1243 : "r" ((UDItype)(u)), \
1244 "r" ((UDItype)(v)) \
1247 #define UMUL_TIME 96
1248 #define UDIV_TIME 230
1249 #endif /* sparc64 */
1251 #if defined (__vax__) && W_TYPE_SIZE == 32
1252 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1253 __asm__ ("addl2 %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 sub_ddmmss(sh, sl, ah, al, bh, bl) \
1262 __asm__ ("subl2 %5,%1\n" \
1264 : "=g" ((USItype) (sh)), \
1265 "=&g" ((USItype) (sl)) \
1266 : "0" ((USItype) (ah)), \
1267 "g" ((USItype) (bh)), \
1268 "1" ((USItype) (al)), \
1269 "g" ((USItype) (bl)))
1270 #define umul_ppmm(xh, xl, m0, m1) \
1274 struct {USItype __l, __h;} __i; \
1276 USItype __m0 = (m0), __m1 = (m1); \
1277 __asm__ ("emul %1,%2,$0,%0" \
1278 : "=r" (__xx.__ll) \
1281 (xh) = __xx.__i.__h; \
1282 (xl) = __xx.__i.__l; \
1283 (xh) += ((((SItype) __m0 >> 31) & __m1) \
1284 + (((SItype) __m1 >> 31) & __m0)); \
1286 #define sdiv_qrnnd(q, r, n1, n0, d) \
1288 union {DItype __ll; \
1289 struct {SItype __l, __h;} __i; \
1291 __xx.__i.__h = n1; __xx.__i.__l = n0; \
1292 __asm__ ("ediv %3,%2,%0,%1" \
1293 : "=g" (q), "=g" (r) \
1294 : "g" (__xx.__ll), "g" (d)); \
1296 #endif /* __vax__ */
1298 #if defined (__z8000__) && W_TYPE_SIZE == 16
1299 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1300 __asm__ ("add %H1,%H5\n\tadc %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 sub_ddmmss(sh, sl, ah, al, bh, bl) \
1308 __asm__ ("sub %H1,%H5\n\tsbc %H0,%H3" \
1309 : "=r" ((unsigned int)(sh)), \
1310 "=&r" ((unsigned int)(sl)) \
1311 : "0" ((unsigned int)(ah)), \
1312 "r" ((unsigned int)(bh)), \
1313 "1" ((unsigned int)(al)), \
1314 "rQR" ((unsigned int)(bl)))
1315 #define umul_ppmm(xh, xl, m0, m1) \
1317 union {long int __ll; \
1318 struct {unsigned int __h, __l;} __i; \
1320 unsigned int __m0 = (m0), __m1 = (m1); \
1321 __asm__ ("mult %S0,%H3" \
1322 : "=r" (__xx.__i.__h), \
1323 "=r" (__xx.__i.__l) \
1326 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
1327 (xh) += ((((signed int) __m0 >> 15) & __m1) \
1328 + (((signed int) __m1 >> 15) & __m0)); \
1330 #endif /* __z8000__ */
1332 #endif /* __GNUC__ */
1334 /* If this machine has no inline assembler, use C macros. */
1336 #if !defined (add_ssaaaa)
1337 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1340 __x = (al) + (bl); \
1341 (sh) = (ah) + (bh) + (__x < (al)); \
1346 #if !defined (sub_ddmmss)
1347 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1350 __x = (al) - (bl); \
1351 (sh) = (ah) - (bh) - (__x > (al)); \
1356 #if !defined (umul_ppmm)
1357 #define umul_ppmm(w1, w0, u, v) \
1359 UWtype __x0, __x1, __x2, __x3; \
1360 UHWtype __ul, __vl, __uh, __vh; \
1362 __ul = __ll_lowpart (u); \
1363 __uh = __ll_highpart (u); \
1364 __vl = __ll_lowpart (v); \
1365 __vh = __ll_highpart (v); \
1367 __x0 = (UWtype) __ul * __vl; \
1368 __x1 = (UWtype) __ul * __vh; \
1369 __x2 = (UWtype) __uh * __vl; \
1370 __x3 = (UWtype) __uh * __vh; \
1372 __x1 += __ll_highpart (__x0);/* this can't give carry */ \
1373 __x1 += __x2; /* but this indeed can */ \
1374 if (__x1 < __x2) /* did we get it? */ \
1375 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
1377 (w1) = __x3 + __ll_highpart (__x1); \
1378 (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
1382 #if !defined (__umulsidi3)
1383 #define __umulsidi3(u, v) \
1385 umul_ppmm (__w.s.high, __w.s.low, u, v); \
1389 /* Define this unconditionally, so it can be used for debugging. */
1390 #define __udiv_qrnnd_c(q, r, n1, n0, d) \
1392 UWtype __d1, __d0, __q1, __q0; \
1393 UWtype __r1, __r0, __m; \
1394 __d1 = __ll_highpart (d); \
1395 __d0 = __ll_lowpart (d); \
1397 __r1 = (n1) % __d1; \
1398 __q1 = (n1) / __d1; \
1399 __m = (UWtype) __q1 * __d0; \
1400 __r1 = __r1 * __ll_B | __ll_highpart (n0); \
1403 __q1--, __r1 += (d); \
1404 if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
1406 __q1--, __r1 += (d); \
1410 __r0 = __r1 % __d1; \
1411 __q0 = __r1 / __d1; \
1412 __m = (UWtype) __q0 * __d0; \
1413 __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
1416 __q0--, __r0 += (d); \
1419 __q0--, __r0 += (d); \
1423 (q) = (UWtype) __q1 * __ll_B | __q0; \
1427 /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
1428 __udiv_w_sdiv (defined in libgcc or elsewhere). */
1429 #if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
1430 #define udiv_qrnnd(q, r, nh, nl, d) \
1433 (q) = __udiv_w_sdiv (&__r, nh, nl, d); \
1438 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
1439 #if !defined (udiv_qrnnd)
1440 #define UDIV_NEEDS_NORMALIZATION 1
1441 #define udiv_qrnnd __udiv_qrnnd_c
1444 #if !defined (count_leading_zeros)
1445 extern const UQItype __clz_tab
[];
1446 #define count_leading_zeros(count, x) \
1448 UWtype __xr = (x); \
1451 if (W_TYPE_SIZE <= 32) \
1453 __a = __xr < ((UWtype)1<<2*__BITS4) \
1454 ? (__xr < ((UWtype)1<<__BITS4) ? 0 : __BITS4) \
1455 : (__xr < ((UWtype)1<<3*__BITS4) ? 2*__BITS4 : 3*__BITS4); \
1459 for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
1460 if (((__xr >> __a) & 0xff) != 0) \
1464 (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
1466 #define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
1469 #if !defined (count_trailing_zeros)
1470 /* Define count_trailing_zeros using count_leading_zeros. The latter might be
1471 defined in asm, but if it is not, the C version above is good enough. */
1472 #define count_trailing_zeros(count, x) \
1474 UWtype __ctz_x = (x); \
1476 count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x); \
1477 (count) = W_TYPE_SIZE - 1 - __ctz_c; \
1481 #ifndef UDIV_NEEDS_NORMALIZATION
1482 #define UDIV_NEEDS_NORMALIZATION 0