include/sys/reboot.h: add constants RB_SW_SUSPEND and RB_KEXEC
[uclibc-ng.git] / libc / sysdeps / linux / sparc / soft-fp / longlong.h
blobbd0d9be01772fd3e86f0ba9deffe42ebd1f012c2
1 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
2 Copyright (C) 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
21 /* You have to define the following before including this file:
23 UWtype -- An unsigned type, default type for operations (typically a "word")
24 UHWtype -- An unsigned type, at least half the size of UWtype.
25 UDWtype -- An unsigned type, at least twice as large a UWtype
26 W_TYPE_SIZE -- size in bits of UWtype
28 UQItype -- Unsigned 8 bit type.
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. */
35 #define __BITS4 (W_TYPE_SIZE / 4)
36 #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
37 #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
38 #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
40 #ifndef W_TYPE_SIZE
41 #define W_TYPE_SIZE 32
42 #define UWtype USItype
43 #define UHWtype USItype
44 #define UDWtype UDItype
45 #endif
47 extern const UQItype __clz_tab[256] attribute_hidden;
49 /* Define auxiliary asm macros.
51 1) umul_ppmm(high_prod, low_prod, multiplier, multiplicand) multiplies two
52 UWtype integers MULTIPLIER and MULTIPLICAND, and generates a two UWtype
53 word product in HIGH_PROD and LOW_PROD.
55 2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a
56 UDWtype product. This is just a variant of umul_ppmm.
58 3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
59 denominator) divides a UDWtype, composed by the UWtype integers
60 HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
61 in QUOTIENT and the remainder in REMAINDER. HIGH_NUMERATOR must be less
62 than DENOMINATOR for correct operation. If, in addition, the most
63 significant bit of DENOMINATOR must be 1, then the pre-processor symbol
64 UDIV_NEEDS_NORMALIZATION is defined to 1.
66 4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
67 denominator). Like udiv_qrnnd but the numbers are signed. The quotient
68 is rounded towards 0.
70 5) count_leading_zeros(count, x) counts the number of zero-bits from the
71 msb to the first nonzero bit in the UWtype X. This is the number of
72 steps X needs to be shifted left to set the msb. Undefined for X == 0,
73 unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.
75 6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
76 from the least significant end.
78 7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
79 high_addend_2, low_addend_2) adds two UWtype integers, composed by
80 HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2
81 respectively. The result is placed in HIGH_SUM and LOW_SUM. Overflow
82 (i.e. carry out) is not stored anywhere, and is lost.
84 8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend,
85 high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers,
86 composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and
87 LOW_SUBTRAHEND_2 respectively. The result is placed in HIGH_DIFFERENCE
88 and LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere,
89 and is lost.
91 If any of these macros are left undefined for a particular CPU,
92 C macros are used. */
94 /* The CPUs come in alphabetical order below.
96 Please add support for more CPUs here, or improve the current support
97 for the CPUs below!
98 (E.g. WE32100, IBM360.) */
100 #if defined (__GNUC__) && !defined (NO_ASM)
102 /* We sometimes need to clobber "cc" with gcc2, but that would not be
103 understood by gcc1. Use cpp to avoid major code duplication. */
104 #if __GNUC__ < 2
105 #define __CLOBBER_CC
106 #define __AND_CLOBBER_CC
107 #else /* __GNUC__ >= 2 */
108 #define __CLOBBER_CC : "cc"
109 #define __AND_CLOBBER_CC , "cc"
110 #endif /* __GNUC__ < 2 */
112 #if defined (__alpha) && W_TYPE_SIZE == 64
113 #define umul_ppmm(ph, pl, m0, m1) \
114 do { \
115 UDItype __m0 = (m0), __m1 = (m1); \
116 (ph) = __builtin_alpha_umulh (__m0, __m1); \
117 (pl) = __m0 * __m1; \
118 } while (0)
119 #define UMUL_TIME 46
120 #ifndef LONGLONG_STANDALONE
121 #define udiv_qrnnd(q, r, n1, n0, d) \
122 do { UDItype __r; \
123 (q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \
124 (r) = __r; \
125 } while (0)
126 extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
127 #define UDIV_TIME 220
128 #endif /* LONGLONG_STANDALONE */
129 #ifdef __alpha_cix__
130 #define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clzl (X))
131 #define count_trailing_zeros(COUNT,X) ((COUNT) = __builtin_ctzl (X))
132 #define COUNT_LEADING_ZEROS_0 64
133 #else
134 #define count_leading_zeros(COUNT,X) \
135 do { \
136 UDItype __xr = (X), __t, __a; \
137 __t = __builtin_alpha_cmpbge (0, __xr); \
138 __a = __clz_tab[__t ^ 0xff] - 1; \
139 __t = __builtin_alpha_extbl (__xr, __a); \
140 (COUNT) = 64 - (__clz_tab[__t] + __a*8); \
141 } while (0)
142 #define count_trailing_zeros(COUNT,X) \
143 do { \
144 UDItype __xr = (X), __t, __a; \
145 __t = __builtin_alpha_cmpbge (0, __xr); \
146 __t = ~__t & -~__t; \
147 __a = ((__t & 0xCC) != 0) * 2; \
148 __a += ((__t & 0xF0) != 0) * 4; \
149 __a += ((__t & 0xAA) != 0); \
150 __t = __builtin_alpha_extbl (__xr, __a); \
151 __a <<= 3; \
152 __t &= -__t; \
153 __a += ((__t & 0xCC) != 0) * 2; \
154 __a += ((__t & 0xF0) != 0) * 4; \
155 __a += ((__t & 0xAA) != 0); \
156 (COUNT) = __a; \
157 } while (0)
158 #endif /* __alpha_cix__ */
159 #endif /* __alpha */
161 #if defined (__arc__) && W_TYPE_SIZE == 32
162 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
163 __asm__ ("add.f %1, %4, %5\n\tadc %0, %2, %3" \
164 : "=r" ((USItype) (sh)), \
165 "=&r" ((USItype) (sl)) \
166 : "%r" ((USItype) (ah)), \
167 "rIJ" ((USItype) (bh)), \
168 "%r" ((USItype) (al)), \
169 "rIJ" ((USItype) (bl)))
170 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
171 __asm__ ("sub.f %1, %4, %5\n\tsbc %0, %2, %3" \
172 : "=r" ((USItype) (sh)), \
173 "=&r" ((USItype) (sl)) \
174 : "r" ((USItype) (ah)), \
175 "rIJ" ((USItype) (bh)), \
176 "r" ((USItype) (al)), \
177 "rIJ" ((USItype) (bl)))
178 /* Call libgcc routine. */
179 #define umul_ppmm(w1, w0, u, v) \
180 do { \
181 DWunion __w; \
182 __w.ll = __umulsidi3 (u, v); \
183 w1 = __w.s.high; \
184 w0 = __w.s.low; \
185 } while (0)
186 #define __umulsidi3 __umulsidi3
187 UDItype __umulsidi3 (USItype, USItype);
188 #endif
190 #if defined (__arm__) && !defined (__thumb__) && W_TYPE_SIZE == 32
191 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
192 __asm__ ("adds %1, %4, %5\n\tadc %0, %2, %3" \
193 : "=r" ((USItype) (sh)), \
194 "=&r" ((USItype) (sl)) \
195 : "%r" ((USItype) (ah)), \
196 "rI" ((USItype) (bh)), \
197 "%r" ((USItype) (al)), \
198 "rI" ((USItype) (bl)) __CLOBBER_CC)
199 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
200 __asm__ ("subs %1, %4, %5\n\tsbc %0, %2, %3" \
201 : "=r" ((USItype) (sh)), \
202 "=&r" ((USItype) (sl)) \
203 : "r" ((USItype) (ah)), \
204 "rI" ((USItype) (bh)), \
205 "r" ((USItype) (al)), \
206 "rI" ((USItype) (bl)) __CLOBBER_CC)
207 #define umul_ppmm(xh, xl, a, b) \
208 {register USItype __t0, __t1, __t2; \
209 __asm__ ("%@ Inlined umul_ppmm\n" \
210 " mov %2, %5, lsr #16\n" \
211 " mov %0, %6, lsr #16\n" \
212 " bic %3, %5, %2, lsl #16\n" \
213 " bic %4, %6, %0, lsl #16\n" \
214 " mul %1, %3, %4\n" \
215 " mul %4, %2, %4\n" \
216 " mul %3, %0, %3\n" \
217 " mul %0, %2, %0\n" \
218 " adds %3, %4, %3\n" \
219 " addcs %0, %0, #65536\n" \
220 " adds %1, %1, %3, lsl #16\n" \
221 " adc %0, %0, %3, lsr #16" \
222 : "=&r" ((USItype) (xh)), \
223 "=r" ((USItype) (xl)), \
224 "=&r" (__t0), "=&r" (__t1), "=r" (__t2) \
225 : "r" ((USItype) (a)), \
226 "r" ((USItype) (b)) __CLOBBER_CC );}
227 #define UMUL_TIME 20
228 #define UDIV_TIME 100
229 #endif /* __arm__ */
231 #if defined(__arm__)
232 /* Let gcc decide how best to implement count_leading_zeros. */
233 #define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clz (X))
234 #define COUNT_LEADING_ZEROS_0 32
235 #endif
237 #if defined (__CRIS__) && __CRIS_arch_version >= 3
238 #define count_leading_zeros(COUNT, X) ((COUNT) = __builtin_clz (X))
239 #if __CRIS_arch_version >= 8
240 #define count_trailing_zeros(COUNT, X) ((COUNT) = __builtin_ctz (X))
241 #endif
242 #endif /* __CRIS__ */
244 #if defined (__hppa) && W_TYPE_SIZE == 32
245 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
246 __asm__ ("add %4,%5,%1\n\taddc %2,%3,%0" \
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\n\tsubb %2,%3,%0" \
255 : "=r" ((USItype) (sh)), \
256 "=&r" ((USItype) (sl)) \
257 : "rM" ((USItype) (ah)), \
258 "rM" ((USItype) (bh)), \
259 "rM" ((USItype) (al)), \
260 "rM" ((USItype) (bl)))
261 #if defined (_PA_RISC1_1)
262 #define umul_ppmm(w1, w0, u, v) \
263 do { \
264 union \
266 UDItype __f; \
267 struct {USItype __w1, __w0;} __w1w0; \
268 } __t; \
269 __asm__ ("xmpyu %1,%2,%0" \
270 : "=x" (__t.__f) \
271 : "x" ((USItype) (u)), \
272 "x" ((USItype) (v))); \
273 (w1) = __t.__w1w0.__w1; \
274 (w0) = __t.__w1w0.__w0; \
275 } while (0)
276 #define UMUL_TIME 8
277 #else
278 #define UMUL_TIME 30
279 #endif
280 #define UDIV_TIME 40
281 #define count_leading_zeros(count, x) \
282 do { \
283 USItype __tmp; \
284 __asm__ ( \
285 "ldi 1,%0\n" \
286 " extru,= %1,15,16,%%r0 ; Bits 31..16 zero?\n" \
287 " extru,tr %1,15,16,%1 ; No. Shift down, skip add.\n"\
288 " ldo 16(%0),%0 ; Yes. Perform add.\n" \
289 " extru,= %1,23,8,%%r0 ; Bits 15..8 zero?\n" \
290 " extru,tr %1,23,8,%1 ; No. Shift down, skip add.\n"\
291 " ldo 8(%0),%0 ; Yes. Perform add.\n" \
292 " extru,= %1,27,4,%%r0 ; Bits 7..4 zero?\n" \
293 " extru,tr %1,27,4,%1 ; No. Shift down, skip add.\n"\
294 " ldo 4(%0),%0 ; Yes. Perform add.\n" \
295 " extru,= %1,29,2,%%r0 ; Bits 3..2 zero?\n" \
296 " extru,tr %1,29,2,%1 ; No. Shift down, skip add.\n"\
297 " ldo 2(%0),%0 ; Yes. Perform add.\n" \
298 " extru %1,30,1,%1 ; Extract bit 1.\n" \
299 " sub %0,%1,%0 ; Subtract it.\n" \
300 : "=r" (count), "=r" (__tmp) : "1" (x)); \
301 } while (0)
302 #endif
304 #if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_TYPE_SIZE == 32
305 #define smul_ppmm(xh, xl, m0, m1) \
306 do { \
307 union {DItype __ll; \
308 struct {USItype __h, __l;} __i; \
309 } __x; \
310 __asm__ ("lr %N0,%1\n\tmr %0,%2" \
311 : "=&r" (__x.__ll) \
312 : "r" (m0), "r" (m1)); \
313 (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
314 } while (0)
315 #define sdiv_qrnnd(q, r, n1, n0, d) \
316 do { \
317 union {DItype __ll; \
318 struct {USItype __h, __l;} __i; \
319 } __x; \
320 __x.__i.__h = n1; __x.__i.__l = n0; \
321 __asm__ ("dr %0,%2" \
322 : "=r" (__x.__ll) \
323 : "0" (__x.__ll), "r" (d)); \
324 (q) = __x.__i.__l; (r) = __x.__i.__h; \
325 } while (0)
326 #endif
328 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
329 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
330 __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}" \
331 : "=r" ((USItype) (sh)), \
332 "=&r" ((USItype) (sl)) \
333 : "%0" ((USItype) (ah)), \
334 "g" ((USItype) (bh)), \
335 "%1" ((USItype) (al)), \
336 "g" ((USItype) (bl)))
337 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
338 __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}" \
339 : "=r" ((USItype) (sh)), \
340 "=&r" ((USItype) (sl)) \
341 : "0" ((USItype) (ah)), \
342 "g" ((USItype) (bh)), \
343 "1" ((USItype) (al)), \
344 "g" ((USItype) (bl)))
345 #define umul_ppmm(w1, w0, u, v) \
346 __asm__ ("mul{l} %3" \
347 : "=a" ((USItype) (w0)), \
348 "=d" ((USItype) (w1)) \
349 : "%0" ((USItype) (u)), \
350 "rm" ((USItype) (v)))
351 #define udiv_qrnnd(q, r, n1, n0, dv) \
352 __asm__ ("div{l} %4" \
353 : "=a" ((USItype) (q)), \
354 "=d" ((USItype) (r)) \
355 : "0" ((USItype) (n0)), \
356 "1" ((USItype) (n1)), \
357 "rm" ((USItype) (dv)))
358 #define count_leading_zeros(count, x) ((count) = __builtin_clz (x))
359 #define count_trailing_zeros(count, x) ((count) = __builtin_ctz (x))
360 #define UMUL_TIME 40
361 #define UDIV_TIME 40
362 #endif /* 80x86 */
364 #if (defined (__x86_64__) || defined (__i386__)) && W_TYPE_SIZE == 64
365 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
366 __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}" \
367 : "=r" ((UDItype) (sh)), \
368 "=&r" ((UDItype) (sl)) \
369 : "%0" ((UDItype) (ah)), \
370 "rme" ((UDItype) (bh)), \
371 "%1" ((UDItype) (al)), \
372 "rme" ((UDItype) (bl)))
373 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
374 __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}" \
375 : "=r" ((UDItype) (sh)), \
376 "=&r" ((UDItype) (sl)) \
377 : "0" ((UDItype) (ah)), \
378 "rme" ((UDItype) (bh)), \
379 "1" ((UDItype) (al)), \
380 "rme" ((UDItype) (bl)))
381 #define umul_ppmm(w1, w0, u, v) \
382 __asm__ ("mul{q} %3" \
383 : "=a" ((UDItype) (w0)), \
384 "=d" ((UDItype) (w1)) \
385 : "%0" ((UDItype) (u)), \
386 "rm" ((UDItype) (v)))
387 #define udiv_qrnnd(q, r, n1, n0, dv) \
388 __asm__ ("div{q} %4" \
389 : "=a" ((UDItype) (q)), \
390 "=d" ((UDItype) (r)) \
391 : "0" ((UDItype) (n0)), \
392 "1" ((UDItype) (n1)), \
393 "rm" ((UDItype) (dv)))
394 #define count_leading_zeros(count, x) ((count) = __builtin_clzl (x))
395 #define count_trailing_zeros(count, x) ((count) = __builtin_ctzl (x))
396 #define UMUL_TIME 40
397 #define UDIV_TIME 40
398 #endif /* x86_64 */
400 #if defined (__M32R__) && W_TYPE_SIZE == 32
401 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
402 /* The cmp clears the condition bit. */ \
403 __asm__ ("cmp %0,%0\n\taddx %1,%5\n\taddx %0,%3" \
404 : "=r" ((USItype) (sh)), \
405 "=&r" ((USItype) (sl)) \
406 : "0" ((USItype) (ah)), \
407 "r" ((USItype) (bh)), \
408 "1" ((USItype) (al)), \
409 "r" ((USItype) (bl)) \
410 : "cbit")
411 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
412 /* The cmp clears the condition bit. */ \
413 __asm__ ("cmp %0,%0\n\tsubx %1,%5\n\tsubx %0,%3" \
414 : "=r" ((USItype) (sh)), \
415 "=&r" ((USItype) (sl)) \
416 : "0" ((USItype) (ah)), \
417 "r" ((USItype) (bh)), \
418 "1" ((USItype) (al)), \
419 "r" ((USItype) (bl)) \
420 : "cbit")
421 #endif /* __M32R__ */
423 #if defined (__mc68000__) && W_TYPE_SIZE == 32
424 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
425 __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0" \
426 : "=d" ((USItype) (sh)), \
427 "=&d" ((USItype) (sl)) \
428 : "%0" ((USItype) (ah)), \
429 "d" ((USItype) (bh)), \
430 "%1" ((USItype) (al)), \
431 "g" ((USItype) (bl)))
432 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
433 __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0" \
434 : "=d" ((USItype) (sh)), \
435 "=&d" ((USItype) (sl)) \
436 : "0" ((USItype) (ah)), \
437 "d" ((USItype) (bh)), \
438 "1" ((USItype) (al)), \
439 "g" ((USItype) (bl)))
441 /* The '020, '030, '040, '060 and CPU32 have 32x32->64 and 64/32->32q-32r. */
442 #if (defined (__mc68020__) && !defined (__mc68060__))
443 #define umul_ppmm(w1, w0, u, v) \
444 __asm__ ("mulu%.l %3,%1:%0" \
445 : "=d" ((USItype) (w0)), \
446 "=d" ((USItype) (w1)) \
447 : "%0" ((USItype) (u)), \
448 "dmi" ((USItype) (v)))
449 #define UMUL_TIME 45
450 #define udiv_qrnnd(q, r, n1, n0, d) \
451 __asm__ ("divu%.l %4,%1:%0" \
452 : "=d" ((USItype) (q)), \
453 "=d" ((USItype) (r)) \
454 : "0" ((USItype) (n0)), \
455 "1" ((USItype) (n1)), \
456 "dmi" ((USItype) (d)))
457 #define UDIV_TIME 90
458 #define sdiv_qrnnd(q, r, n1, n0, d) \
459 __asm__ ("divs%.l %4,%1:%0" \
460 : "=d" ((USItype) (q)), \
461 "=d" ((USItype) (r)) \
462 : "0" ((USItype) (n0)), \
463 "1" ((USItype) (n1)), \
464 "dmi" ((USItype) (d)))
466 #elif defined (__mcoldfire__) /* not mc68020 */
468 #define umul_ppmm(xh, xl, a, b) \
469 __asm__ ("| Inlined umul_ppmm\n" \
470 " move%.l %2,%/d0\n" \
471 " move%.l %3,%/d1\n" \
472 " move%.l %/d0,%/d2\n" \
473 " swap %/d0\n" \
474 " move%.l %/d1,%/d3\n" \
475 " swap %/d1\n" \
476 " move%.w %/d2,%/d4\n" \
477 " mulu %/d3,%/d4\n" \
478 " mulu %/d1,%/d2\n" \
479 " mulu %/d0,%/d3\n" \
480 " mulu %/d0,%/d1\n" \
481 " move%.l %/d4,%/d0\n" \
482 " clr%.w %/d0\n" \
483 " swap %/d0\n" \
484 " add%.l %/d0,%/d2\n" \
485 " add%.l %/d3,%/d2\n" \
486 " jcc 1f\n" \
487 " add%.l %#65536,%/d1\n" \
488 "1: swap %/d2\n" \
489 " moveq %#0,%/d0\n" \
490 " move%.w %/d2,%/d0\n" \
491 " move%.w %/d4,%/d2\n" \
492 " move%.l %/d2,%1\n" \
493 " add%.l %/d1,%/d0\n" \
494 " move%.l %/d0,%0" \
495 : "=g" ((USItype) (xh)), \
496 "=g" ((USItype) (xl)) \
497 : "g" ((USItype) (a)), \
498 "g" ((USItype) (b)) \
499 : "d0", "d1", "d2", "d3", "d4")
500 #define UMUL_TIME 100
501 #define UDIV_TIME 400
502 #else /* not ColdFire */
503 /* %/ inserts REGISTER_PREFIX, %# inserts IMMEDIATE_PREFIX. */
504 #define umul_ppmm(xh, xl, a, b) \
505 __asm__ ("| Inlined umul_ppmm\n" \
506 " move%.l %2,%/d0\n" \
507 " move%.l %3,%/d1\n" \
508 " move%.l %/d0,%/d2\n" \
509 " swap %/d0\n" \
510 " move%.l %/d1,%/d3\n" \
511 " swap %/d1\n" \
512 " move%.w %/d2,%/d4\n" \
513 " mulu %/d3,%/d4\n" \
514 " mulu %/d1,%/d2\n" \
515 " mulu %/d0,%/d3\n" \
516 " mulu %/d0,%/d1\n" \
517 " move%.l %/d4,%/d0\n" \
518 " eor%.w %/d0,%/d0\n" \
519 " swap %/d0\n" \
520 " add%.l %/d0,%/d2\n" \
521 " add%.l %/d3,%/d2\n" \
522 " jcc 1f\n" \
523 " add%.l %#65536,%/d1\n" \
524 "1: swap %/d2\n" \
525 " moveq %#0,%/d0\n" \
526 " move%.w %/d2,%/d0\n" \
527 " move%.w %/d4,%/d2\n" \
528 " move%.l %/d2,%1\n" \
529 " add%.l %/d1,%/d0\n" \
530 " move%.l %/d0,%0" \
531 : "=g" ((USItype) (xh)), \
532 "=g" ((USItype) (xl)) \
533 : "g" ((USItype) (a)), \
534 "g" ((USItype) (b)) \
535 : "d0", "d1", "d2", "d3", "d4")
536 #define UMUL_TIME 100
537 #define UDIV_TIME 400
539 #endif /* not mc68020 */
541 /* The '020, '030, '040 and '060 have bitfield insns.
542 cpu32 disguises as a 68020, but lacks them. */
543 #if defined (__mc68020__) && !defined (__mcpu32__)
544 #define count_leading_zeros(count, x) \
545 __asm__ ("bfffo %1{%b2:%b2},%0" \
546 : "=d" ((USItype) (count)) \
547 : "od" ((USItype) (x)), "n" (0))
548 /* Some ColdFire architectures have a ff1 instruction supported via
549 __builtin_clz. */
550 #elif defined (__mcfisaaplus__) || defined (__mcfisac__)
551 #define count_leading_zeros(count,x) ((count) = __builtin_clz (x))
552 #define COUNT_LEADING_ZEROS_0 32
553 #endif
554 #endif /* mc68000 */
556 #if defined (__m88000__) && W_TYPE_SIZE == 32
557 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
558 __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3" \
559 : "=r" ((USItype) (sh)), \
560 "=&r" ((USItype) (sl)) \
561 : "%rJ" ((USItype) (ah)), \
562 "rJ" ((USItype) (bh)), \
563 "%rJ" ((USItype) (al)), \
564 "rJ" ((USItype) (bl)))
565 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
566 __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3" \
567 : "=r" ((USItype) (sh)), \
568 "=&r" ((USItype) (sl)) \
569 : "rJ" ((USItype) (ah)), \
570 "rJ" ((USItype) (bh)), \
571 "rJ" ((USItype) (al)), \
572 "rJ" ((USItype) (bl)))
573 #define count_leading_zeros(count, x) \
574 do { \
575 USItype __cbtmp; \
576 __asm__ ("ff1 %0,%1" \
577 : "=r" (__cbtmp) \
578 : "r" ((USItype) (x))); \
579 (count) = __cbtmp ^ 31; \
580 } while (0)
581 #define COUNT_LEADING_ZEROS_0 63 /* sic */
582 #if defined (__mc88110__)
583 #define umul_ppmm(wh, wl, u, v) \
584 do { \
585 union {UDItype __ll; \
586 struct {USItype __h, __l;} __i; \
587 } __xx; \
588 __asm__ ("mulu.d %0,%1,%2" \
589 : "=r" (__xx.__ll) \
590 : "r" ((USItype) (u)), \
591 "r" ((USItype) (v))); \
592 (wh) = __xx.__i.__h; \
593 (wl) = __xx.__i.__l; \
594 } while (0)
595 #define udiv_qrnnd(q, r, n1, n0, d) \
596 ({union {UDItype __ll; \
597 struct {USItype __h, __l;} __i; \
598 } __xx; \
599 USItype __q; \
600 __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
601 __asm__ ("divu.d %0,%1,%2" \
602 : "=r" (__q) \
603 : "r" (__xx.__ll), \
604 "r" ((USItype) (d))); \
605 (r) = (n0) - __q * (d); (q) = __q; })
606 #define UMUL_TIME 5
607 #define UDIV_TIME 25
608 #else
609 #define UMUL_TIME 17
610 #define UDIV_TIME 150
611 #endif /* __mc88110__ */
612 #endif /* __m88000__ */
614 #if defined (__mips__) && W_TYPE_SIZE == 32
615 #define umul_ppmm(w1, w0, u, v) \
616 do { \
617 UDItype __x = (UDItype) (USItype) (u) * (USItype) (v); \
618 (w1) = (USItype) (__x >> 32); \
619 (w0) = (USItype) (__x); \
620 } while (0)
621 #define UMUL_TIME 10
622 #define UDIV_TIME 100
624 #if (__mips == 32 || __mips == 64) && ! __mips16
625 #define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clz (X))
626 #define COUNT_LEADING_ZEROS_0 32
627 #endif
628 #endif /* __mips__ */
630 #if defined (__ns32000__) && W_TYPE_SIZE == 32
631 #define umul_ppmm(w1, w0, u, v) \
632 ({union {UDItype __ll; \
633 struct {USItype __l, __h;} __i; \
634 } __xx; \
635 __asm__ ("meid %2,%0" \
636 : "=g" (__xx.__ll) \
637 : "%0" ((USItype) (u)), \
638 "g" ((USItype) (v))); \
639 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
640 #define __umulsidi3(u, v) \
641 ({UDItype __w; \
642 __asm__ ("meid %2,%0" \
643 : "=g" (__w) \
644 : "%0" ((USItype) (u)), \
645 "g" ((USItype) (v))); \
646 __w; })
647 #define udiv_qrnnd(q, r, n1, n0, d) \
648 ({union {UDItype __ll; \
649 struct {USItype __l, __h;} __i; \
650 } __xx; \
651 __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
652 __asm__ ("deid %2,%0" \
653 : "=g" (__xx.__ll) \
654 : "0" (__xx.__ll), \
655 "g" ((USItype) (d))); \
656 (r) = __xx.__i.__l; (q) = __xx.__i.__h; })
657 #define count_trailing_zeros(count,x) \
658 do { \
659 __asm__ ("ffsd %2,%0" \
660 : "=r" ((USItype) (count)) \
661 : "0" ((USItype) 0), \
662 "r" ((USItype) (x))); \
663 } while (0)
664 #endif /* __ns32000__ */
666 /* FIXME: We should test _IBMR2 here when we add assembly support for the
667 system vendor compilers.
668 FIXME: What's needed for gcc PowerPC VxWorks? __vxworks__ is not good
669 enough, since that hits ARM and m68k too. */
670 #if (defined (_ARCH_PPC) /* AIX */ \
671 || defined (_ARCH_PWR) /* AIX */ \
672 || defined (_ARCH_COM) /* AIX */ \
673 || defined (__powerpc__) /* gcc */ \
674 || defined (__POWERPC__) /* BEOS */ \
675 || defined (__ppc__) /* Darwin */ \
676 || (defined (PPC) && ! defined (CPU_FAMILY)) /* gcc 2.7.x GNU&SysV */ \
677 || (defined (PPC) && defined (CPU_FAMILY) /* VxWorks */ \
678 && CPU_FAMILY == PPC) \
679 ) && W_TYPE_SIZE == 32
680 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
681 do { \
682 if (__builtin_constant_p (bh) && (bh) == 0) \
683 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
684 : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
685 else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \
686 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
687 : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
688 else \
689 __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
690 : "=r" (sh), "=&r" (sl) \
691 : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \
692 } while (0)
693 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
694 do { \
695 if (__builtin_constant_p (ah) && (ah) == 0) \
696 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
697 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
698 else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0) \
699 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
700 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
701 else if (__builtin_constant_p (bh) && (bh) == 0) \
702 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
703 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
704 else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \
705 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
706 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
707 else \
708 __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
709 : "=r" (sh), "=&r" (sl) \
710 : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \
711 } while (0)
712 #define count_leading_zeros(count, x) \
713 __asm__ ("{cntlz|cntlzw} %0,%1" : "=r" (count) : "r" (x))
714 #define COUNT_LEADING_ZEROS_0 32
715 #if defined (_ARCH_PPC) || defined (__powerpc__) || defined (__POWERPC__) \
716 || defined (__ppc__) \
717 || (defined (PPC) && ! defined (CPU_FAMILY)) /* gcc 2.7.x GNU&SysV */ \
718 || (defined (PPC) && defined (CPU_FAMILY) /* VxWorks */ \
719 && CPU_FAMILY == PPC)
720 #define umul_ppmm(ph, pl, m0, m1) \
721 do { \
722 USItype __m0 = (m0), __m1 = (m1); \
723 __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
724 (pl) = __m0 * __m1; \
725 } while (0)
726 #define UMUL_TIME 15
727 #define smul_ppmm(ph, pl, m0, m1) \
728 do { \
729 SItype __m0 = (m0), __m1 = (m1); \
730 __asm__ ("mulhw %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
731 (pl) = __m0 * __m1; \
732 } while (0)
733 #define SMUL_TIME 14
734 #define UDIV_TIME 120
735 #elif defined (_ARCH_PWR)
736 #define UMUL_TIME 8
737 #define smul_ppmm(xh, xl, m0, m1) \
738 __asm__ ("mul %0,%2,%3" : "=r" (xh), "=q" (xl) : "r" (m0), "r" (m1))
739 #define SMUL_TIME 4
740 #define sdiv_qrnnd(q, r, nh, nl, d) \
741 __asm__ ("div %0,%2,%4" : "=r" (q), "=q" (r) : "r" (nh), "1" (nl), "r" (d))
742 #define UDIV_TIME 100
743 #endif
744 #endif /* 32-bit POWER architecture variants. */
746 /* We should test _IBMR2 here when we add assembly support for the system
747 vendor compilers. */
748 #if (defined (_ARCH_PPC64) || defined (__powerpc64__)) && W_TYPE_SIZE == 64
749 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
750 do { \
751 if (__builtin_constant_p (bh) && (bh) == 0) \
752 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
753 : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
754 else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \
755 __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
756 : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
757 else \
758 __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
759 : "=r" (sh), "=&r" (sl) \
760 : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \
761 } while (0)
762 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
763 do { \
764 if (__builtin_constant_p (ah) && (ah) == 0) \
765 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
766 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
767 else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0) \
768 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
769 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
770 else if (__builtin_constant_p (bh) && (bh) == 0) \
771 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
772 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
773 else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \
774 __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
775 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
776 else \
777 __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
778 : "=r" (sh), "=&r" (sl) \
779 : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \
780 } while (0)
781 #define count_leading_zeros(count, x) \
782 __asm__ ("cntlzd %0,%1" : "=r" (count) : "r" (x))
783 #define COUNT_LEADING_ZEROS_0 64
784 #define umul_ppmm(ph, pl, m0, m1) \
785 do { \
786 UDItype __m0 = (m0), __m1 = (m1); \
787 __asm__ ("mulhdu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
788 (pl) = __m0 * __m1; \
789 } while (0)
790 #define UMUL_TIME 15
791 #define smul_ppmm(ph, pl, m0, m1) \
792 do { \
793 DItype __m0 = (m0), __m1 = (m1); \
794 __asm__ ("mulhd %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
795 (pl) = __m0 * __m1; \
796 } while (0)
797 #define SMUL_TIME 14 /* ??? */
798 #define UDIV_TIME 120 /* ??? */
799 #endif /* 64-bit PowerPC. */
801 #if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
802 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
803 __asm__ ("a %1,%5\n\tae %0,%3" \
804 : "=r" ((USItype) (sh)), \
805 "=&r" ((USItype) (sl)) \
806 : "%0" ((USItype) (ah)), \
807 "r" ((USItype) (bh)), \
808 "%1" ((USItype) (al)), \
809 "r" ((USItype) (bl)))
810 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
811 __asm__ ("s %1,%5\n\tse %0,%3" \
812 : "=r" ((USItype) (sh)), \
813 "=&r" ((USItype) (sl)) \
814 : "0" ((USItype) (ah)), \
815 "r" ((USItype) (bh)), \
816 "1" ((USItype) (al)), \
817 "r" ((USItype) (bl)))
818 #define umul_ppmm(ph, pl, m0, m1) \
819 do { \
820 USItype __m0 = (m0), __m1 = (m1); \
821 __asm__ ( \
822 "s r2,r2\n" \
823 " mts r10,%2\n" \
824 " m r2,%3\n" \
825 " m r2,%3\n" \
826 " m r2,%3\n" \
827 " m r2,%3\n" \
828 " m r2,%3\n" \
829 " m r2,%3\n" \
830 " m r2,%3\n" \
831 " m r2,%3\n" \
832 " m r2,%3\n" \
833 " m r2,%3\n" \
834 " m r2,%3\n" \
835 " m r2,%3\n" \
836 " m r2,%3\n" \
837 " m r2,%3\n" \
838 " m r2,%3\n" \
839 " m r2,%3\n" \
840 " cas %0,r2,r0\n" \
841 " mfs r10,%1" \
842 : "=r" ((USItype) (ph)), \
843 "=r" ((USItype) (pl)) \
844 : "%r" (__m0), \
845 "r" (__m1) \
846 : "r2"); \
847 (ph) += ((((SItype) __m0 >> 31) & __m1) \
848 + (((SItype) __m1 >> 31) & __m0)); \
849 } while (0)
850 #define UMUL_TIME 20
851 #define UDIV_TIME 200
852 #define count_leading_zeros(count, x) \
853 do { \
854 if ((x) >= 0x10000) \
855 __asm__ ("clz %0,%1" \
856 : "=r" ((USItype) (count)) \
857 : "r" ((USItype) (x) >> 16)); \
858 else \
860 __asm__ ("clz %0,%1" \
861 : "=r" ((USItype) (count)) \
862 : "r" ((USItype) (x))); \
863 (count) += 16; \
865 } while (0)
866 #endif
868 #if defined(__sh__) && !__SHMEDIA__ && W_TYPE_SIZE == 32
869 #ifndef __sh1__
870 #define umul_ppmm(w1, w0, u, v) \
871 __asm__ ( \
872 "dmulu.l %2,%3\n\tsts%M1 macl,%1\n\tsts%M0 mach,%0" \
873 : "=r<" ((USItype)(w1)), \
874 "=r<" ((USItype)(w0)) \
875 : "r" ((USItype)(u)), \
876 "r" ((USItype)(v)) \
877 : "macl", "mach")
878 #define UMUL_TIME 5
879 #endif
881 /* This is the same algorithm as __udiv_qrnnd_c. */
882 #define UDIV_NEEDS_NORMALIZATION 1
884 #define udiv_qrnnd(q, r, n1, n0, d) \
885 do { \
886 extern UWtype __udiv_qrnnd_16 (UWtype, UWtype) \
887 __attribute__ ((visibility ("hidden"))); \
888 /* r0: rn r1: qn */ /* r0: n1 r4: n0 r5: d r6: d1 */ /* r2: __m */ \
889 __asm__ ( \
890 "mov%M4 %4,r5\n" \
891 " swap.w %3,r4\n" \
892 " swap.w r5,r6\n" \
893 " jsr @%5\n" \
894 " shll16 r6\n" \
895 " swap.w r4,r4\n" \
896 " jsr @%5\n" \
897 " swap.w r1,%0\n" \
898 " or r1,%0" \
899 : "=r" (q), "=&z" (r) \
900 : "1" (n1), "r" (n0), "rm" (d), "r" (&__udiv_qrnnd_16) \
901 : "r1", "r2", "r4", "r5", "r6", "pr"); \
902 } while (0)
904 #define UDIV_TIME 80
906 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
907 __asm__ ("clrt;subc %5,%1; subc %4,%0" \
908 : "=r" (sh), "=r" (sl) \
909 : "0" (ah), "1" (al), "r" (bh), "r" (bl))
911 #endif /* __sh__ */
913 #if defined (__SH5__) && __SHMEDIA__ && W_TYPE_SIZE == 32
914 #define __umulsidi3(u,v) ((UDItype)(USItype)u*(USItype)v)
915 #define count_leading_zeros(count, x) \
916 do \
918 UDItype x_ = (USItype)(x); \
919 SItype c_; \
921 __asm__ ("nsb %1, %0" : "=r" (c_) : "r" (x_)); \
922 (count) = c_ - 31; \
924 while (0)
925 #define COUNT_LEADING_ZEROS_0 32
926 #endif
928 #if defined (__sparc__) && !defined (__arch64__) && !defined (__sparcv9) \
929 && W_TYPE_SIZE == 32
930 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
931 __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0" \
932 : "=r" ((USItype) (sh)), \
933 "=&r" ((USItype) (sl)) \
934 : "%rJ" ((USItype) (ah)), \
935 "rI" ((USItype) (bh)), \
936 "%rJ" ((USItype) (al)), \
937 "rI" ((USItype) (bl)) \
938 __CLOBBER_CC)
939 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
940 __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0" \
941 : "=r" ((USItype) (sh)), \
942 "=&r" ((USItype) (sl)) \
943 : "rJ" ((USItype) (ah)), \
944 "rI" ((USItype) (bh)), \
945 "rJ" ((USItype) (al)), \
946 "rI" ((USItype) (bl)) \
947 __CLOBBER_CC)
948 #if defined (__sparc_v8__)
949 #define umul_ppmm(w1, w0, u, v) \
950 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
951 : "=r" ((USItype) (w1)), \
952 "=r" ((USItype) (w0)) \
953 : "r" ((USItype) (u)), \
954 "r" ((USItype) (v)))
955 #define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
956 __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
957 : "=&r" ((USItype) (__q)), \
958 "=&r" ((USItype) (__r)) \
959 : "r" ((USItype) (__n1)), \
960 "r" ((USItype) (__n0)), \
961 "r" ((USItype) (__d)))
962 #else
963 #if defined (__sparclite__)
964 /* This has hardware multiply but not divide. It also has two additional
965 instructions scan (ffs from high bit) and divscc. */
966 #define umul_ppmm(w1, w0, u, v) \
967 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
968 : "=r" ((USItype) (w1)), \
969 "=r" ((USItype) (w0)) \
970 : "r" ((USItype) (u)), \
971 "r" ((USItype) (v)))
972 #define udiv_qrnnd(q, r, n1, n0, d) \
973 __asm__ ("! Inlined udiv_qrnnd\n" \
974 " wr %%g0,%2,%%y ! Not a delayed write for sparclite\n" \
975 " tst %%g0\n" \
976 " divscc %3,%4,%%g1\n" \
977 " divscc %%g1,%4,%%g1\n" \
978 " divscc %%g1,%4,%%g1\n" \
979 " divscc %%g1,%4,%%g1\n" \
980 " divscc %%g1,%4,%%g1\n" \
981 " divscc %%g1,%4,%%g1\n" \
982 " divscc %%g1,%4,%%g1\n" \
983 " divscc %%g1,%4,%%g1\n" \
984 " divscc %%g1,%4,%%g1\n" \
985 " divscc %%g1,%4,%%g1\n" \
986 " divscc %%g1,%4,%%g1\n" \
987 " divscc %%g1,%4,%%g1\n" \
988 " divscc %%g1,%4,%%g1\n" \
989 " divscc %%g1,%4,%%g1\n" \
990 " divscc %%g1,%4,%%g1\n" \
991 " divscc %%g1,%4,%%g1\n" \
992 " divscc %%g1,%4,%%g1\n" \
993 " divscc %%g1,%4,%%g1\n" \
994 " divscc %%g1,%4,%%g1\n" \
995 " divscc %%g1,%4,%%g1\n" \
996 " divscc %%g1,%4,%%g1\n" \
997 " divscc %%g1,%4,%%g1\n" \
998 " divscc %%g1,%4,%%g1\n" \
999 " divscc %%g1,%4,%%g1\n" \
1000 " divscc %%g1,%4,%%g1\n" \
1001 " divscc %%g1,%4,%%g1\n" \
1002 " divscc %%g1,%4,%%g1\n" \
1003 " divscc %%g1,%4,%%g1\n" \
1004 " divscc %%g1,%4,%%g1\n" \
1005 " divscc %%g1,%4,%%g1\n" \
1006 " divscc %%g1,%4,%%g1\n" \
1007 " divscc %%g1,%4,%0\n" \
1008 " rd %%y,%1\n" \
1009 " bl,a 1f\n" \
1010 " add %1,%4,%1\n" \
1011 "1: ! End of inline udiv_qrnnd" \
1012 : "=r" ((USItype) (q)), \
1013 "=r" ((USItype) (r)) \
1014 : "r" ((USItype) (n1)), \
1015 "r" ((USItype) (n0)), \
1016 "rI" ((USItype) (d)) \
1017 : "g1" __AND_CLOBBER_CC)
1018 #define UDIV_TIME 37
1019 #define count_leading_zeros(count, x) \
1020 do { \
1021 __asm__ ("scan %1,1,%0" \
1022 : "=r" ((USItype) (count)) \
1023 : "r" ((USItype) (x))); \
1024 } while (0)
1025 /* Early sparclites return 63 for an argument of 0, but they warn that future
1026 implementations might change this. Therefore, leave COUNT_LEADING_ZEROS_0
1027 undefined. */
1028 #else
1029 /* SPARC without integer multiplication and divide instructions.
1030 (i.e. at least Sun4/20,40,60,65,75,110,260,280,330,360,380,470,490) */
1031 #define umul_ppmm(w1, w0, u, v) \
1032 __asm__ ("! Inlined umul_ppmm\n" \
1033 " wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr\n"\
1034 " sra %3,31,%%o5 ! Don't move this insn\n" \
1035 " and %2,%%o5,%%o5 ! Don't move this insn\n" \
1036 " andcc %%g0,0,%%g1 ! Don't move this insn\n" \
1037 " mulscc %%g1,%3,%%g1\n" \
1038 " mulscc %%g1,%3,%%g1\n" \
1039 " mulscc %%g1,%3,%%g1\n" \
1040 " mulscc %%g1,%3,%%g1\n" \
1041 " mulscc %%g1,%3,%%g1\n" \
1042 " mulscc %%g1,%3,%%g1\n" \
1043 " mulscc %%g1,%3,%%g1\n" \
1044 " mulscc %%g1,%3,%%g1\n" \
1045 " mulscc %%g1,%3,%%g1\n" \
1046 " mulscc %%g1,%3,%%g1\n" \
1047 " mulscc %%g1,%3,%%g1\n" \
1048 " mulscc %%g1,%3,%%g1\n" \
1049 " mulscc %%g1,%3,%%g1\n" \
1050 " mulscc %%g1,%3,%%g1\n" \
1051 " mulscc %%g1,%3,%%g1\n" \
1052 " mulscc %%g1,%3,%%g1\n" \
1053 " mulscc %%g1,%3,%%g1\n" \
1054 " mulscc %%g1,%3,%%g1\n" \
1055 " mulscc %%g1,%3,%%g1\n" \
1056 " mulscc %%g1,%3,%%g1\n" \
1057 " mulscc %%g1,%3,%%g1\n" \
1058 " mulscc %%g1,%3,%%g1\n" \
1059 " mulscc %%g1,%3,%%g1\n" \
1060 " mulscc %%g1,%3,%%g1\n" \
1061 " mulscc %%g1,%3,%%g1\n" \
1062 " mulscc %%g1,%3,%%g1\n" \
1063 " mulscc %%g1,%3,%%g1\n" \
1064 " mulscc %%g1,%3,%%g1\n" \
1065 " mulscc %%g1,%3,%%g1\n" \
1066 " mulscc %%g1,%3,%%g1\n" \
1067 " mulscc %%g1,%3,%%g1\n" \
1068 " mulscc %%g1,%3,%%g1\n" \
1069 " mulscc %%g1,0,%%g1\n" \
1070 " add %%g1,%%o5,%0\n" \
1071 " rd %%y,%1" \
1072 : "=r" ((USItype) (w1)), \
1073 "=r" ((USItype) (w0)) \
1074 : "%rI" ((USItype) (u)), \
1075 "r" ((USItype) (v)) \
1076 : "g1", "o5" __AND_CLOBBER_CC)
1077 #define UMUL_TIME 39 /* 39 instructions */
1078 /* It's quite necessary to add this much assembler for the sparc.
1079 The default udiv_qrnnd (in C) is more than 10 times slower! */
1080 #define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
1081 __asm__ ("! Inlined udiv_qrnnd\n" \
1082 " mov 32,%%g1\n" \
1083 " subcc %1,%2,%%g0\n" \
1084 "1: bcs 5f\n" \
1085 " addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n" \
1086 " sub %1,%2,%1 ! this kills msb of n\n" \
1087 " addx %1,%1,%1 ! so this can't give carry\n" \
1088 " subcc %%g1,1,%%g1\n" \
1089 "2: bne 1b\n" \
1090 " subcc %1,%2,%%g0\n" \
1091 " bcs 3f\n" \
1092 " addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n" \
1093 " b 3f\n" \
1094 " sub %1,%2,%1 ! this kills msb of n\n" \
1095 "4: sub %1,%2,%1\n" \
1096 "5: addxcc %1,%1,%1\n" \
1097 " bcc 2b\n" \
1098 " subcc %%g1,1,%%g1\n" \
1099 "! Got carry from n. Subtract next step to cancel this carry.\n" \
1100 " bne 4b\n" \
1101 " addcc %0,%0,%0 ! shift n1n0 and a 0-bit in lsb\n" \
1102 " sub %1,%2,%1\n" \
1103 "3: xnor %0,0,%0\n" \
1104 " ! End of inline udiv_qrnnd" \
1105 : "=&r" ((USItype) (__q)), \
1106 "=&r" ((USItype) (__r)) \
1107 : "r" ((USItype) (__d)), \
1108 "1" ((USItype) (__n1)), \
1109 "0" ((USItype) (__n0)) : "g1" __AND_CLOBBER_CC)
1110 #define UDIV_TIME (3+7*32) /* 7 instructions/iteration. 32 iterations. */
1111 #endif /* __sparclite__ */
1112 #endif /* __sparc_v8__ */
1113 #endif /* sparc32 */
1115 #if ((defined (__sparc__) && defined (__arch64__)) || defined (__sparcv9)) \
1116 && W_TYPE_SIZE == 64
1117 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1118 __asm__ ("addcc %r4,%5,%1\n\t" \
1119 "add %r2,%3,%0\n\t" \
1120 "bcs,a,pn %%xcc, 1f\n\t" \
1121 "add %0, 1, %0\n" \
1122 "1:" \
1123 : "=r" ((UDItype)(sh)), \
1124 "=&r" ((UDItype)(sl)) \
1125 : "%rJ" ((UDItype)(ah)), \
1126 "rI" ((UDItype)(bh)), \
1127 "%rJ" ((UDItype)(al)), \
1128 "rI" ((UDItype)(bl)) \
1129 __CLOBBER_CC)
1131 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1132 __asm__ ("subcc %r4,%5,%1\n\t" \
1133 "sub %r2,%3,%0\n\t" \
1134 "bcs,a,pn %%xcc, 1f\n\t" \
1135 "sub %0, 1, %0\n\t" \
1136 "1:" \
1137 : "=r" ((UDItype)(sh)), \
1138 "=&r" ((UDItype)(sl)) \
1139 : "rJ" ((UDItype)(ah)), \
1140 "rI" ((UDItype)(bh)), \
1141 "rJ" ((UDItype)(al)), \
1142 "rI" ((UDItype)(bl)) \
1143 __CLOBBER_CC)
1145 #define umul_ppmm(wh, wl, u, v) \
1146 do { \
1147 UDItype tmp1, tmp2, tmp3, tmp4; \
1148 __asm__ __volatile__ ( \
1149 "srl %7,0,%3\n\t" \
1150 "mulx %3,%6,%1\n\t" \
1151 "srlx %6,32,%2\n\t" \
1152 "mulx %2,%3,%4\n\t" \
1153 "sllx %4,32,%5\n\t" \
1154 "srl %6,0,%3\n\t" \
1155 "sub %1,%5,%5\n\t" \
1156 "srlx %5,32,%5\n\t" \
1157 "addcc %4,%5,%4\n\t" \
1158 "srlx %7,32,%5\n\t" \
1159 "mulx %3,%5,%3\n\t" \
1160 "mulx %2,%5,%5\n\t" \
1161 "sethi %%hi(0x80000000),%2\n\t" \
1162 "addcc %4,%3,%4\n\t" \
1163 "srlx %4,32,%4\n\t" \
1164 "add %2,%2,%2\n\t" \
1165 "movcc %%xcc,%%g0,%2\n\t" \
1166 "addcc %5,%4,%5\n\t" \
1167 "sllx %3,32,%3\n\t" \
1168 "add %1,%3,%1\n\t" \
1169 "add %5,%2,%0" \
1170 : "=r" ((UDItype)(wh)), \
1171 "=&r" ((UDItype)(wl)), \
1172 "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4) \
1173 : "r" ((UDItype)(u)), \
1174 "r" ((UDItype)(v)) \
1175 __CLOBBER_CC); \
1176 } while (0)
1177 #define UMUL_TIME 96
1178 #define UDIV_TIME 230
1179 #endif /* sparc64 */
1181 #if defined (__xtensa__) && W_TYPE_SIZE == 32
1182 /* This code is not Xtensa-configuration-specific, so rely on the compiler
1183 to expand builtin functions depending on what configuration features
1184 are available. This avoids library calls when the operation can be
1185 performed in-line. */
1186 #define umul_ppmm(w1, w0, u, v) \
1187 do { \
1188 DWunion __w; \
1189 __w.ll = __builtin_umulsidi3 (u, v); \
1190 w1 = __w.s.high; \
1191 w0 = __w.s.low; \
1192 } while (0)
1193 #define __umulsidi3(u, v) __builtin_umulsidi3 (u, v)
1194 #define count_leading_zeros(COUNT, X) ((COUNT) = __builtin_clz (X))
1195 #define count_trailing_zeros(COUNT, X) ((COUNT) = __builtin_ctz (X))
1196 #endif /* __xtensa__ */
1198 #if defined (__z8000__) && W_TYPE_SIZE == 16
1199 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1200 __asm__ ("add %H1,%H5\n\tadc %H0,%H3" \
1201 : "=r" ((unsigned int)(sh)), \
1202 "=&r" ((unsigned int)(sl)) \
1203 : "%0" ((unsigned int)(ah)), \
1204 "r" ((unsigned int)(bh)), \
1205 "%1" ((unsigned int)(al)), \
1206 "rQR" ((unsigned int)(bl)))
1207 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1208 __asm__ ("sub %H1,%H5\n\tsbc %H0,%H3" \
1209 : "=r" ((unsigned int)(sh)), \
1210 "=&r" ((unsigned int)(sl)) \
1211 : "0" ((unsigned int)(ah)), \
1212 "r" ((unsigned int)(bh)), \
1213 "1" ((unsigned int)(al)), \
1214 "rQR" ((unsigned int)(bl)))
1215 #define umul_ppmm(xh, xl, m0, m1) \
1216 do { \
1217 union {long int __ll; \
1218 struct {unsigned int __h, __l;} __i; \
1219 } __xx; \
1220 unsigned int __m0 = (m0), __m1 = (m1); \
1221 __asm__ ("mult %S0,%H3" \
1222 : "=r" (__xx.__i.__h), \
1223 "=r" (__xx.__i.__l) \
1224 : "%1" (__m0), \
1225 "rQR" (__m1)); \
1226 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
1227 (xh) += ((((signed int) __m0 >> 15) & __m1) \
1228 + (((signed int) __m1 >> 15) & __m0)); \
1229 } while (0)
1230 #endif /* __z8000__ */
1232 #endif /* __GNUC__ */
1234 /* If this machine has no inline assembler, use C macros. */
1236 #if !defined (add_ssaaaa)
1237 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1238 do { \
1239 UWtype __x; \
1240 __x = (al) + (bl); \
1241 (sh) = (ah) + (bh) + (__x < (al)); \
1242 (sl) = __x; \
1243 } while (0)
1244 #endif
1246 #if !defined (sub_ddmmss)
1247 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1248 do { \
1249 UWtype __x; \
1250 __x = (al) - (bl); \
1251 (sh) = (ah) - (bh) - (__x > (al)); \
1252 (sl) = __x; \
1253 } while (0)
1254 #endif
1256 /* If we lack umul_ppmm but have smul_ppmm, define umul_ppmm in terms of
1257 smul_ppmm. */
1258 #if !defined (umul_ppmm) && defined (smul_ppmm)
1259 #define umul_ppmm(w1, w0, u, v) \
1260 do { \
1261 UWtype __w1; \
1262 UWtype __xm0 = (u), __xm1 = (v); \
1263 smul_ppmm (__w1, w0, __xm0, __xm1); \
1264 (w1) = __w1 + (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1) \
1265 + (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0); \
1266 } while (0)
1267 #endif
1269 /* If we still don't have umul_ppmm, define it using plain C. */
1270 #if !defined (umul_ppmm)
1271 #define umul_ppmm(w1, w0, u, v) \
1272 do { \
1273 UWtype __x0, __x1, __x2, __x3; \
1274 UHWtype __ul, __vl, __uh, __vh; \
1276 __ul = __ll_lowpart (u); \
1277 __uh = __ll_highpart (u); \
1278 __vl = __ll_lowpart (v); \
1279 __vh = __ll_highpart (v); \
1281 __x0 = (UWtype) __ul * __vl; \
1282 __x1 = (UWtype) __ul * __vh; \
1283 __x2 = (UWtype) __uh * __vl; \
1284 __x3 = (UWtype) __uh * __vh; \
1286 __x1 += __ll_highpart (__x0);/* this can't give carry */ \
1287 __x1 += __x2; /* but this indeed can */ \
1288 if (__x1 < __x2) /* did we get it? */ \
1289 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
1291 (w1) = __x3 + __ll_highpart (__x1); \
1292 (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
1293 } while (0)
1294 #endif
1296 #if !defined (__umulsidi3)
1297 #define __umulsidi3(u, v) \
1298 ({DWunion __w; \
1299 umul_ppmm (__w.s.high, __w.s.low, u, v); \
1300 __w.ll; })
1301 #endif
1303 /* Define this unconditionally, so it can be used for debugging. */
1304 #define __udiv_qrnnd_c(q, r, n1, n0, d) \
1305 do { \
1306 UWtype __d1, __d0, __q1, __q0; \
1307 UWtype __r1, __r0, __m; \
1308 __d1 = __ll_highpart (d); \
1309 __d0 = __ll_lowpart (d); \
1311 __r1 = (n1) % __d1; \
1312 __q1 = (n1) / __d1; \
1313 __m = (UWtype) __q1 * __d0; \
1314 __r1 = __r1 * __ll_B | __ll_highpart (n0); \
1315 if (__r1 < __m) \
1317 __q1--, __r1 += (d); \
1318 if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
1319 if (__r1 < __m) \
1320 __q1--, __r1 += (d); \
1322 __r1 -= __m; \
1324 __r0 = __r1 % __d1; \
1325 __q0 = __r1 / __d1; \
1326 __m = (UWtype) __q0 * __d0; \
1327 __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
1328 if (__r0 < __m) \
1330 __q0--, __r0 += (d); \
1331 if (__r0 >= (d)) \
1332 if (__r0 < __m) \
1333 __q0--, __r0 += (d); \
1335 __r0 -= __m; \
1337 (q) = (UWtype) __q1 * __ll_B | __q0; \
1338 (r) = __r0; \
1339 } while (0)
1341 /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
1342 __udiv_w_sdiv (defined in libgcc or elsewhere). */
1343 #if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
1344 #define udiv_qrnnd(q, r, nh, nl, d) \
1345 do { \
1346 USItype __r; \
1347 (q) = __udiv_w_sdiv (&__r, nh, nl, d); \
1348 (r) = __r; \
1349 } while (0)
1350 #endif
1352 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
1353 #if !defined (udiv_qrnnd)
1354 #define UDIV_NEEDS_NORMALIZATION 1
1355 #define udiv_qrnnd __udiv_qrnnd_c
1356 #endif
1358 #if !defined (count_leading_zeros)
1359 #define count_leading_zeros(count, x) \
1360 do { \
1361 UWtype __xr = (x); \
1362 UWtype __a; \
1364 if (W_TYPE_SIZE <= 32) \
1366 __a = __xr < ((UWtype)1<<2*__BITS4) \
1367 ? (__xr < ((UWtype)1<<__BITS4) ? 0 : __BITS4) \
1368 : (__xr < ((UWtype)1<<3*__BITS4) ? 2*__BITS4 : 3*__BITS4); \
1370 else \
1372 for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
1373 if (((__xr >> __a) & 0xff) != 0) \
1374 break; \
1377 (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
1378 } while (0)
1379 #define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
1380 #endif
1382 #if !defined (count_trailing_zeros)
1383 /* Define count_trailing_zeros using count_leading_zeros. The latter might be
1384 defined in asm, but if it is not, the C version above is good enough. */
1385 #define count_trailing_zeros(count, x) \
1386 do { \
1387 UWtype __ctz_x = (x); \
1388 UWtype __ctz_c; \
1389 count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x); \
1390 (count) = W_TYPE_SIZE - 1 - __ctz_c; \
1391 } while (0)
1392 #endif
1394 #ifndef UDIV_NEEDS_NORMALIZATION
1395 #define UDIV_NEEDS_NORMALIZATION 0
1396 #endif