ae4447b36ea4a88a0ab09dbc1d94ae0b81ee9365
1 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
2 Copyright (C) 1991 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. */
18 #ifndef LONG_TYPE_SIZE
19 #define LONG_TYPE_SIZE 32
22 #define __BITS4 (LONG_TYPE_SIZE / 4)
23 #define __ll_B (1L << (LONG_TYPE_SIZE / 2))
24 #define __ll_lowpart(t) ((unsigned long int) (t) % __ll_B)
25 #define __ll_highpart(t) ((unsigned long int) (t) / __ll_B)
27 /* Define auxiliary asm macros.
29 1) umul_ppmm(high_prod, low_prod, multipler, multiplicand)
30 multiplies two unsigned long integers MULTIPLER and MULTIPLICAND,
31 and generates a two unsigned word product in HIGH_PROD and
34 2) __umulsidi3(a,b) multiplies two unsigned long integers A and B,
35 and returns a long long 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) count_leading_zeros(count, x) counts the number of zero-bits from
46 the msb to the first non-zero bit. This is the number of steps X
47 needs to be shifted left to set the msb. Undefined for X == 0.
49 5) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
50 high_addend_2, low_addend_2) adds two two-word unsigned integers,
51 composed by HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and
52 LOW_ADDEND_2 respectively. The result is placed in HIGH_SUM and
53 LOW_SUM. Overflow (i.e. carry out) is not stored anywhere, and is
56 6) sub_ddmmss(high_difference, low_difference, high_minuend,
57 low_minuend, high_subtrahend, low_subtrahend) subtracts two
58 two-word unsigned integers, composed by HIGH_MINUEND_1 and
59 LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and LOW_SUBTRAHEND_2
60 respectively. The result is placed in HIGH_DIFFERENCE and
61 LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere,
64 If any of these macros are left undefined for a particular CPU,
67 /* The CPUs come in alphabetical order below.
69 Please add support for more CPUs here, or improve the current support
71 (E.g. WE32100, HP-PA (xmpyu?), i960, IBM360, TRON.) */
73 #if defined (__GNUC__) && !defined (NO_ASM)
75 #if defined (__a29k__) || defined (___AM29K__)
76 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
77 __asm__ ("add %1,%4,%5
79 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl)) \
80 : "%r" ((unsigned long int)(ah)), "rI" ((unsigned long int)(bh)), \
81 "%r" ((unsigned long int)(al)), "rI" ((unsigned long int)(bl)))
82 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
83 __asm__ ("sub %1,%4,%5
85 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl)) \
86 : "r" ((unsigned long int)(ah)), "rI" ((unsigned long int)(bh)), \
87 "r" ((unsigned long int)(al)), "rI" ((unsigned long int)(bl)))
88 #define umul_ppmm(xh, xl, m0, m1) \
90 unsigned long int __m0 = (m0), __m1 = (m1); \
91 __asm__ ("multiplu %0,%1,%2" : "=r" ((unsigned long int)(xl)) \
92 : "r" (__m0), "r" (__m1)); \
93 __asm__ ("multmu %0,%1,%2" : "=r" ((unsigned long int)(xh)) \
94 : "r" (__m0), "r" (__m1)); \
96 #define udiv_qrnnd(q, r, n1, n0, d) \
97 __asm__ ("dividu %0,%3,%4" \
98 : "=r" ((unsigned long int)(q)), "=q" ((unsigned long int)(r)) \
99 : "1" ((unsigned long int)(n1)), "r" ((unsigned long int)(n0)), \
100 "r" ((unsigned long int)(d)))
101 #define count_leading_zeros(count, x) \
102 __asm__ ("clz %0,%1" : "=r" ((unsigned long int)(count)) \
103 : "r" ((unsigned long int)(x)))
104 #endif /* __a29k__ */
106 #if defined (__arm__)
107 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
108 __asm__ ("adds %1,%4,%5
110 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl)) \
111 : "%r" ((unsigned long int)(ah)), "rI" ((unsigned long int)(bh)), \
112 "%r" ((unsigned long int)(al)), "rI" ((unsigned long int)(bl)))
113 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
114 __asm__ ("subs %1,%4,%5
116 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl)) \
117 : "r" ((unsigned long int)(ah)), "rI" ((unsigned long int)(bh)), \
118 "r" ((unsigned long int)(al)), "rI" ((unsigned long int)(bl)))
121 #if defined (__gmicro__)
122 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
123 __asm__ ("add.w %5,%1
125 : "=g" ((unsigned long int)(sh)), "=&g" ((unsigned long int)(sl))\
126 : "%0" ((unsigned long int)(ah)), "g" ((unsigned long int)(bh)), \
127 "%1" ((unsigned long int)(al)), "g" ((unsigned long int)(bl)))
128 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
129 __asm__ ("sub.w %5,%1
131 : "=g" ((unsigned long int)(sh)), "=&g" ((unsigned long int)(sl))\
132 : "0" ((unsigned long int)(ah)), "g" ((unsigned long int)(bh)), \
133 "1" ((unsigned long int)(al)), "g" ((unsigned long int)(bl)))
134 #define umul_ppmm(ph, pl, m0, m1) \
135 __asm__ ("mulx %3,%0,%1" \
136 : "=g" ((unsigned long int)(ph)), "=r" ((unsigned long int)(pl))\
137 : "%0" ((unsigned long int)(m0)), "g" ((unsigned long int)(m1)))
138 #define udiv_qrnnd(q, r, nh, nl, d) \
139 __asm__ ("divx %4,%0,%1" \
140 : "=g" ((unsigned long int)(q)), "=r" ((unsigned long int)(r)) \
141 : "1" ((unsigned long int)(nh)), "0" ((unsigned long int)(nl)), \
142 "g" ((unsigned long int)(d)))
143 #define count_leading_zeros(count, x) \
144 __asm__ ("bsch/1 %1,%0" \
146 : "g" ((unsigned long int)(x)), "0" (0UL))
150 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
151 __asm__ ("add %4,%5,%1
153 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
154 : "%r" ((unsigned long int)(ah)), "r" ((unsigned long int)(bh)),\
155 "%r" ((unsigned long int)(al)), "r" ((unsigned long int)(bl)))
156 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
157 __asm__ ("sub %5,%4,%1
159 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
160 : "r" ((unsigned long int)(ah)), "r" ((unsigned long int)(bh)), \
161 "r" ((unsigned long int)(al)), "r" ((unsigned long int)(bl)))
164 #if defined (__i386__) || defined (__i486__)
165 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
168 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
169 : "%0" ((unsigned long int)(ah)), "g" ((unsigned long int)(bh)), \
170 "%1" ((unsigned long int)(al)), "g" ((unsigned long int)(bl)))
171 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
174 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
175 : "0" ((unsigned long int)(ah)), "g" ((unsigned long int)(bh)), \
176 "1" ((unsigned long int)(al)), "g" ((unsigned long int)(bl)))
177 #define umul_ppmm(w1, w0, u, v) \
179 : "=a" ((unsigned long int)(w0)), "=d" ((unsigned long int)(w1))\
180 : "%0" ((unsigned long int)(u)), "rm" ((unsigned long int)(v)))
181 #define udiv_qrnnd(q, r, n1, n0, d) \
183 : "=a" ((unsigned long int)(q)), "=d" ((unsigned long int)(r)) \
184 : "0" ((unsigned long int)(n0)), "1" ((unsigned long int)(n1)), \
185 "rm" ((unsigned long int)(d)))
186 #define count_leading_zeros(count, x) \
188 unsigned long int __cbtmp; \
189 __asm__ ("bsrl %1,%0" \
190 : "=r" (__cbtmp) : "rm" ((unsigned long int)(x))); \
191 (count) = __cbtmp ^ 31; \
195 #if defined (__i860__)
197 /* Make sure these patterns really improve the code before
198 switching them on. */
199 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
204 struct {unsigned long int l, h;} i; \
206 __a.i.l = (al); __a.i.h = (ah); \
207 __b.i.l = (bl); __b.i.h = (bh); \
208 __asm__ ("fiadd.dd %1,%2,%0" \
210 : "%f" (__a.ll), "f" (__b.ll)); \
211 (sh) = __s.i.h; (sl) = __s.i.l; \
213 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
218 struct {unsigned long int l, h;} i; \
220 __a.i.l = (al); __a.i.h = (ah); \
221 __b.i.l = (bl); __b.i.h = (bh); \
222 __asm__ ("fisub.dd %1,%2,%0" \
224 : "%f" (__a.ll), "f" (__b.ll)); \
225 (sh) = __s.i.h; (sl) = __s.i.l; \
228 #endif /* __i860__ */
230 #if defined (___IBMR2__) /* IBM RS6000 */
231 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
234 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
235 : "%r" ((unsigned long int)(ah)), "r" ((unsigned long int)(bh)),\
236 "%r" ((unsigned long int)(al)), "r" ((unsigned long int)(bl)))
237 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
238 __asm__ ("sf %1,%5,%4
240 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
241 : "r" ((unsigned long int)(ah)), "r" ((unsigned long int)(bh)), \
242 "r" ((unsigned long int)(al)), "r" ((unsigned long int)(bl)))
243 #define umul_ppmm(xh, xl, m0, m1) \
245 unsigned long int __m0 = (m0), __m1 = (m1); \
246 __asm__ ("mul %0,%2,%3" \
247 : "=r" ((unsigned long int)(xh)), "=q" ((unsigned long int)(xl))\
248 : "r" (__m0), "r" (__m1)); \
249 (xh) += ((((signed long int) __m0 >> 31) & __m1) \
250 + (((signed long int) __m1 >> 31) & __m0)); \
253 #if 0 /* Overflow for nh>=FFFFFFFE, d==FFFFFFFF. Find a good fix later. */
254 #define udiv_qrnnd(q, r, nh, nl, d) \
255 do { /* Use the signed "div" insn, and adjust the result. */ \
256 unsigned long int __q, __r, __nh, __nl, __d, __xh, __xl; \
258 __nl = (((unsigned long int)(nh)) << 30) | ((unsigned long int)(nl) >> 2);\
259 __nh = (unsigned long int)(nh) >> 2; \
260 __d = ((unsigned long int)(d) >> 1); \
261 __asm__ ("div %0,%2,%4" \
262 : "=r" (__q), "=q" (__r) \
263 : "r" (__nh), "1" (__nl), "r" (__d)); \
265 __asm__ ("mul %0,%2,%3" \
266 : "=r" (__xh), "=q" (__xl) \
267 : "r" (__q), "r" ((unsigned long int)(d))); \
268 __xh += (((signed long int) __q >> 31) & (d)) + __q; \
269 if ((nh) < __xh || ((nh) == __xh && (nl) < __xl)) \
273 sub_ddmmss (__xh, __xl, __xh, __xl, 0, (d)); \
276 while ((nh) < __xh || ((nh) == __xh && (nl) < __xl)); \
277 __xl = (nl) - __xl; \
281 sub_ddmmss (__xh, __xl, (nh), (nl), __xh, __xl); \
286 sub_ddmmss (__xh, __xl, __xh, __xl, 0, (d)); \
301 #define UDIV_NEEDS_NORMALIZATION 1
303 #define count_leading_zeros(count, x) \
304 __asm__ ("cntlz %0,%1" \
305 : "=r" ((unsigned long int)(count)) : "r" ((unsigned long int)(x)))
306 #endif /* ___IBMR2__ */
308 #if defined (__mc68000__)
309 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
310 __asm__ ("add%.l %5,%1
312 : "=d" ((unsigned long int)(sh)), "=&d" ((unsigned long int)(sl))\
313 : "%0" ((unsigned long int)(ah)), "d" ((unsigned long int)(bh)), \
314 "%1" ((unsigned long int)(al)), "g" ((unsigned long int)(bl)))
315 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
316 __asm__ ("sub%.l %5,%1
318 : "=d" ((unsigned long int)(sh)), "=&d" ((unsigned long int)(sl))\
319 : "0" ((unsigned long int)(ah)), "d" ((unsigned long int)(bh)), \
320 "1" ((unsigned long int)(al)), "g" ((unsigned long int)(bl)))
321 #if defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)
322 #define umul_ppmm(w1, w0, u, v) \
323 __asm__ ("mulu%.l %3,%1:%0" \
324 : "=d" ((unsigned long int)(w0)), "=d" ((unsigned long int)(w1))\
325 : "%0" ((unsigned long int)(u)), "dmi" ((unsigned long int)(v)))
326 #define udiv_qrnnd(q, r, n1, n0, d) \
327 __asm__ ("divu%.l %4,%1:%0" \
328 : "=d" ((unsigned long int)(q)), "=d" ((unsigned long int)(r)) \
329 : "0" ((unsigned long int)(n0)), "1" ((unsigned long int)(n1)), \
330 "dmi" ((unsigned long int)(d)))
331 #define count_leading_zeros(count, x) \
332 __asm__ ("bfffo %1{%b2:%b2},%0" \
333 : "=d" ((unsigned long int)(count)) \
334 : "od" ((unsigned long int)(x)), "n" (0))
335 #else /* not mc68020 */
336 #define umul_ppmm(xh, xl, a, b) \
337 __asm__ ("| Inlined umul_ppmm
363 : "=g" ((unsigned long int)(xh)), "=g" ((unsigned long int)(xl)) \
364 :"g" ((unsigned long int)(a)), "g" ((unsigned long int)(b)) \
365 : "d0", "d1", "d2", "d3", "d4")
366 #endif /* not mc68020 */
369 #if defined (__m88000__)
370 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
371 __asm__ ("addu.co %1,%r4,%r5
372 addu.ci %0,%r2,%r3" \
373 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
374 : "%rJ" ((unsigned long int)(ah)), "rJ" ((unsigned long int)(bh)),\
375 "%rJ" ((unsigned long int)(al)), "rJ" ((unsigned long int)(bl)))
376 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
377 __asm__ ("subu.co %1,%r4,%r5
378 subu.ci %0,%r2,%r3" \
379 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
380 : "rJ" ((unsigned long int)(ah)), "rJ" ((unsigned long int)(bh)),\
381 "rJ" ((unsigned long int)(al)), "rJ" ((unsigned long int)(bl)))
383 #define UDIV_TIME 150
384 #define count_leading_zeros(count, x) \
386 unsigned long int __cbtmp; \
387 __asm__ ("ff1 %0,%1" \
388 : "=r" (__cbtmp) : "r" ((unsigned long int)(x))); \
389 (count) = __cbtmp ^ 31; \
391 #endif /* __m88000__ */
393 #if defined (__mips__)
394 #define umul_ppmm(w1, w0, u, v) \
395 __asm__ ("multu %2,%3
398 : "=r" ((unsigned long int)(w0)), "=r" ((unsigned long int)(w1))\
399 : "r" ((unsigned long int)(u)), "r" ((unsigned long int)(v)))
401 #define UDIV_TIME 100
402 #endif /* __mips__ */
404 #if defined (__ns32000__)
405 #define __umulsidi3(u, v) \
406 ({long long int __w; \
407 __asm__ ("meid %2,%0" : "=g" (__w) \
408 : "%0" ((unsigned long int)(u)), "g" ((unsigned long int)(v))); \
410 #define div_qrnnd(q, r, n1, n0, d) \
416 : "=g" ((unsigned long int)(q)), "=g" ((unsigned long int)(r)) \
417 : "g" ((unsigned long int)(n0)), "g" ((unsigned long int)(n1)), \
418 "g" ((unsigned long int)(d)) : "r0", "r1")
419 #endif /* __ns32000__ */
421 #if defined (__pyr__)
422 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
425 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
426 : "%0" ((unsigned long int)(ah)), "g" ((unsigned long int)(bh)),\
427 "%1" ((unsigned long int)(al)), "g" ((unsigned long int)(bl)))
428 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
431 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
432 : "0" ((unsigned long int)(ah)), "g" ((unsigned long int)(bh)), \
433 "1" ((unsigned long int)(al)), "g" ((unsigned long int)(bl)))
434 /* This insn doesn't work on ancient pyramids. */
435 #define umul_ppmm(w1, w0, u, v) \
436 __asm__ ("movw %2,tr11
440 : "=r" ((unsigned long int)(w1)), "=r" ((unsigned long int)(w0))\
441 : "r" ((unsigned long int)(u)), "r" ((unsigned long int)(v)) \
445 #if defined (__ibm032__) /* RT/ROMP */
446 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
449 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
450 : "%0" ((unsigned long int)(ah)), "r" ((unsigned long int)(bh)),\
451 "%1" ((unsigned long int)(al)), "r" ((unsigned long int)(bl)))
452 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
455 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
456 : "0" ((unsigned long int)(ah)), "r" ((unsigned long int)(bh)), \
457 "1" ((unsigned long int)(al)), "r" ((unsigned long int)(bl)))
458 #define umul_ppmm(ph, pl, m0, m1) \
460 unsigned long int __m0 = (m0), __m1 = (m1); \
482 : "=r" ((unsigned long int)(ph)), "=r" ((unsigned long int)(pl)) \
483 : "%r" (__m0), "r" (__m1) \
485 (ph) += ((((signed long int) __m0 >> 31) & __m1) \
486 + (((signed long int) __m1 >> 31) & __m0)); \
488 #define count_leading_zeros(count, x) \
490 if ((x) >= 0x10000) \
491 __asm__ ("clz %0,%1" \
492 : "=r" ((unsigned long int)(count)) \
493 : "r" ((unsigned long int)(x) >> 16)); \
496 __asm__ ("clz %0,%1" \
497 : "=r" ((unsigned long int)(count)) \
498 : "r" ((unsigned long int)(x))); \
504 #if defined (__sparc__)
505 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
506 __asm__ ("addcc %4,%5,%1
508 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
509 : "%r" ((unsigned long int)(ah)), "rI" ((unsigned long int)(bh)),\
510 "%r" ((unsigned long int)(al)), "rI" ((unsigned long int)(bl)))
511 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
512 __asm__ ("subcc %4,%5,%1
514 : "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
515 : "r" ((unsigned long int)(ah)), "rI" ((unsigned long int)(bh)),\
516 "r" ((unsigned long int)(al)), "rI" ((unsigned long int)(bl)))
517 #if defined (__sparc8__) /* How do we recog. version 8 SPARC? */
518 #define umul_ppmm(w1, w0, u, v) \
519 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
520 : "=r" ((unsigned long int)(w1)), "=r" ((unsigned long int)(w0))\
521 : "r" ((unsigned long int)(u)), "r" ((unsigned long int)(v)))
522 #define udiv_qrnnd(q, r, n1, n0, d) \
523 __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
524 : "=&r" ((unsigned long int)(q)), "=&r" ((unsigned long int)(r))\
525 : "r" ((unsigned long int)(n1)), "r" ((unsigned long int)(n0)), \
526 "r" ((unsigned long int)(d)))
528 /* SPARC without integer multiplication and divide instructions.
529 (i.e. at least Sun4/20,40,60,65,75,110,260,280,330,360,380,470,490) */
530 #define umul_ppmm(w1, w0, u, v) \
531 __asm__ ("! Inlined umul_ppmm
532 wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr
533 sra %3,31,%%g2 ! Don't move this insn
534 and %2,%%g2,%%g2 ! Don't move this insn
535 andcc %%g0,0,%%g1 ! Don't move this insn
571 : "=r" ((unsigned long int)(w1)), "=r" ((unsigned long int)(w0))\
572 : "%rI" ((unsigned long int)(u)), "r" ((unsigned long int)(v)) \
574 #define UMUL_TIME 39 /* 39 instructions */
575 /* It's quite necessary to add this much assembler for the sparc.
576 The default udiv_qrnnd (in C) is more than 10 times slower! */
577 #define udiv_qrnnd(q, r, n1, n0, d) \
578 __asm__ ("! Inlined udiv_qrnnd
582 addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb
583 sub %1,%2,%1 ! this kills msb of n
584 addx %1,%1,%1 ! so this can't give carry
589 addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb
591 sub %1,%2,%1 ! this kills msb of n
596 ! Got carry from n. Subtract next step to cancel this carry.
598 addcc %0,%0,%0 ! shift n1n0 and a 0-bit in lsb
601 ! End of inline udiv_qrnnd" \
602 : "=r&" ((unsigned long int)(q)), "=r&" ((unsigned long int)(r))\
603 : "r" ((unsigned long int)(d)), "1" ((unsigned long int)(n1)), \
604 "0" ((unsigned long int)(n0)) : "%g1")
605 #define UDIV_TIME (3+7*32) /* 7 instructions/iteration. 32 iterations. */
607 #endif /* __sparc8__ */
609 #if defined (__vax__)
610 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
611 __asm__ ("addl2 %5,%1
613 : "=g" ((unsigned long int)(sh)), "=&g" ((unsigned long int)(sl))\
614 : "%0" ((unsigned long int)(ah)), "g" ((unsigned long int)(bh)),\
615 "%1" ((unsigned long int)(al)), "g" ((unsigned long int)(bl)))
616 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
617 __asm__ ("subl2 %5,%1
619 : "=g" ((unsigned long int)(sh)), "=&g" ((unsigned long int)(sl))\
620 : "0" ((unsigned long int)(ah)), "g" ((unsigned long int)(bh)), \
621 "1" ((unsigned long int)(al)), "g" ((unsigned long int)(bl)))
622 #define umul_ppmm(xh, xl, m0, m1) \
624 union {long long int ll;struct {unsigned long int l, h;} i;} __xx; \
625 unsigned long int __m0 = (m0), __m1 = (m1); \
626 __asm__ ("emul %1,%2,$0,%0" \
627 : "=r" (__xx.ll) : "g" (__m0), "g" (__m1)); \
628 (xh) = __xx.i.h; (xl) = __xx.i.l; \
629 (xh) += ((((signed long int) __m0 >> 31) & __m1) \
630 + (((signed long int) __m1 >> 31) & __m0)); \
634 #endif /* __GNUC__ */
636 /* If this machine has no inline assembler, use C macros. */
638 #if !defined (add_ssaaaa)
639 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
641 unsigned long int __x; \
643 (sh) = (ah) + (bh) + (__x < (al)); \
648 #if !defined (sub_ddmmss)
649 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
651 unsigned long int __x; \
653 (sh) = (ah) - (bh) - (__x > (al)); \
658 #if !defined (umul_ppmm)
659 #define umul_ppmm(w1, w0, u, v) \
661 unsigned long int __x0, __x1, __x2, __x3; \
662 unsigned int __ul, __vl, __uh, __vh; \
664 __ul = __ll_lowpart (u); \
665 __uh = __ll_highpart (u); \
666 __vl = __ll_lowpart (v); \
667 __vh = __ll_highpart (v); \
669 __x0 = (unsigned long int) __ul * __vl; \
670 __x1 = (unsigned long int) __ul * __vh; \
671 __x2 = (unsigned long int) __uh * __vl; \
672 __x3 = (unsigned long int) __uh * __vh; \
674 __x1 += __ll_highpart (__x0);/* this can't give carry */ \
675 __x1 += __x2; /* but this indeed can */ \
676 if (__x1 < __x2) /* did we get it? */ \
677 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
679 (w1) = __x3 + __ll_highpart (__x1); \
680 (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
684 #if !defined (__umulsidi3)
685 #define __umulsidi3(u, v) \
687 umul_ppmm (__w.s.high, __w.s.low, u, v); \
691 #if !defined (udiv_qrnnd) || defined (__LLDEBUG__)
692 #define UDIV_NEEDS_NORMALIZATION 1
694 #define udiv_qrnnd udiv_qrnnd_c
696 #define udiv_qrnnd_c(q, r, n1, n0, d) \
698 unsigned int __d1, __d0, __q1, __q0; \
699 unsigned long int __r1, __r0, __m; \
700 __d1 = __ll_highpart (d); \
701 __d0 = __ll_lowpart (d); \
703 __r1 = (n1) % __d1; \
704 __q1 = (n1) / __d1; \
705 __m = (unsigned long int) __q1 * __d0; \
706 __r1 = __r1 * __ll_B | __ll_highpart (n0); \
709 __q1--, __r1 += (d); \
710 if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
712 __q1--, __r1 += (d); \
716 __r0 = __r1 % __d1; \
717 __q0 = __r1 / __d1; \
718 __m = (unsigned long int) __q0 * __d0; \
719 __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
722 __q0--, __r0 += (d); \
725 __q0--, __r0 += (d); \
729 (q) = (unsigned long int) __q1 * __ll_B | __q0; \
734 #if !defined (count_leading_zeros)
735 extern const unsigned char __clz_tab
[];
737 #define count_leading_zeros(count, x) \
739 unsigned long int xr = (x); \
742 a = xr < (1<<2*__BITS4) \
743 ? (xr < (1<<__BITS4) ? 0 : __BITS4) \
744 : (xr < (1<<3*__BITS4) ? 2*__BITS4 : 3*__BITS4); \
746 (count) = 4*__BITS4 - (__clz_tab[xr >> a] + a); \
750 #ifndef UDIV_NEEDS_NORMALIZATION
751 #define UDIV_NEEDS_NORMALIZATION 0