sexp: Improve argument checking of sexp parser.
[libgcrypt.git] / mpi / longlong.h
1 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
2    Note: This is the Libgcrypt version
3
4
5 Copyright (C) 1991, 1992, 1993, 1994, 1996, 1998,
6               2000, 2001, 2002, 2003, 2004, 2011 Free Software Foundation, Inc.
7
8 This file is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or (at your
11 option) any later version.
12
13 This file is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16 License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this file; see the file COPYING.LIB.  If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA. */
22
23 /* You have to define the following before including this file:
24
25    UWtype -- An unsigned type, default type for operations (typically a "word")
26    UHWtype -- An unsigned type, at least half the size of UWtype.
27    UDWtype -- An unsigned type, at least twice as large a UWtype
28    W_TYPE_SIZE -- size in bits of UWtype
29
30    SItype, USItype -- Signed and unsigned 32 bit types.
31    DItype, UDItype -- Signed and unsigned 64 bit types.
32
33    On a 32 bit machine UWtype should typically be USItype;
34    on a 64 bit machine, UWtype should typically be UDItype.
35 */
36
37 #define __BITS4 (W_TYPE_SIZE / 4)
38 #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
39 #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
40 #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
41
42 /* This is used to make sure no undesirable sharing between different libraries
43    that use this file takes place.  */
44 #ifndef __MPN
45 # define __MPN(x) __##x
46 #endif
47
48 /* Define auxiliary asm macros.
49
50    1) umul_ppmm(high_prod, low_prod, multipler, multiplicand) multiplies two
51    UWtype integers MULTIPLER and MULTIPLICAND, and generates a two UWtype
52    word product in HIGH_PROD and LOW_PROD.
53
54    2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a
55    UDWtype product.  This is just a variant of umul_ppmm.
56
57    3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
58    denominator) divides a UDWtype, composed by the UWtype integers
59    HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
60    in QUOTIENT and the remainder in REMAINDER.  HIGH_NUMERATOR must be less
61    than DENOMINATOR for correct operation.  If, in addition, the most
62    significant bit of DENOMINATOR must be 1, then the pre-processor symbol
63    UDIV_NEEDS_NORMALIZATION is defined to 1.
64
65    4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
66    denominator).  Like udiv_qrnnd but the numbers are signed.  The quotient
67    is rounded towards 0.
68
69    5) count_leading_zeros(count, x) counts the number of zero-bits from the
70    msb to the first non-zero bit in the UWtype X.  This is the number of
71    steps X needs to be shifted left to set the msb.  Undefined for X == 0,
72    unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.
73
74    6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
75    from the least significant end.
76
77    7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
78    high_addend_2, low_addend_2) adds two UWtype integers, composed by
79    HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2
80    respectively.  The result is placed in HIGH_SUM and LOW_SUM.  Overflow
81    (i.e. carry out) is not stored anywhere, and is lost.
82
83    8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend,
84    high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers,
85    composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and
86    LOW_SUBTRAHEND_2 respectively.  The result is placed in HIGH_DIFFERENCE
87    and LOW_DIFFERENCE.  Overflow (i.e. carry out) is not stored anywhere,
88    and is lost.
89
90    If any of these macros are left undefined for a particular CPU,
91    C macros are used.  */
92
93 /* The CPUs come in alphabetical order below.
94
95    Please add support for more CPUs here, or improve the current support
96    for the CPUs below!  */
97
98 #ifdef __riscos__
99 #pragma continue_after_hash_error
100 #else /* !__riscos__ */
101 #if defined (__GNUC__) && !defined (NO_ASM)
102
103 /* We sometimes need to clobber "cc" with gcc2, but that would not be
104    understood by gcc1.  Use cpp to avoid major code duplication.  */
105 #if __GNUC__ < 2
106 # define __CLOBBER_CC
107 # define __AND_CLOBBER_CC
108 #else /* __GNUC__ >= 2 */
109 # define __CLOBBER_CC : "cc"
110 # define __AND_CLOBBER_CC , "cc"
111 #endif /* __GNUC__ < 2 */
112
113 /***************************************
114  ****  Begin CPU Specific Versions  ****
115  ***************************************/
116
117 /***************************************
118  **************  A29K  *****************
119  ***************************************/
120 #if (defined (__a29k__) || defined (_AM29K)) && W_TYPE_SIZE == 32
121 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
122   __asm__ ("add %1,%4,%5\n"   \
123            "addc %0,%2,%3"                                              \
124            : "=r" ((USItype)(sh)),                                      \
125             "=&r" ((USItype)(sl))                                       \
126            : "%r" ((USItype)(ah)),                                      \
127              "rI" ((USItype)(bh)),                                      \
128              "%r" ((USItype)(al)),                                      \
129              "rI" ((USItype)(bl)))
130 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
131   __asm__ ("sub %1,%4,%5\n"                                             \
132            "subc %0,%2,%3"                                              \
133            : "=r" ((USItype)(sh)),                                      \
134              "=&r" ((USItype)(sl))                                      \
135            : "r" ((USItype)(ah)),                                       \
136              "rI" ((USItype)(bh)),                                      \
137              "r" ((USItype)(al)),                                       \
138              "rI" ((USItype)(bl)))
139 # define umul_ppmm(xh, xl, m0, m1) \
140   do {                                                                  \
141     USItype __m0 = (m0), __m1 = (m1);                                   \
142     __asm__ ("multiplu %0,%1,%2"                                        \
143              : "=r" ((USItype)(xl))                                     \
144              : "r" (__m0),                                              \
145                "r" (__m1));                                             \
146     __asm__ ("multmu %0,%1,%2"                                          \
147              : "=r" ((USItype)(xh))                                     \
148              : "r" (__m0),                                              \
149                "r" (__m1));                                             \
150   } while (0)
151 # define udiv_qrnnd(q, r, n1, n0, d) \
152   __asm__ ("dividu %0,%3,%4"                                            \
153            : "=r" ((USItype)(q)),                                       \
154              "=q" ((USItype)(r))                                        \
155            : "1" ((USItype)(n1)),                                       \
156              "r" ((USItype)(n0)),                                       \
157              "r" ((USItype)(d)))
158 # define count_leading_zeros(count, x) \
159     __asm__ ("clz %0,%1"                                                \
160              : "=r" ((USItype)(count))                                  \
161              : "r" ((USItype)(x)))
162 # define COUNT_LEADING_ZEROS_0 32
163 #endif /* __a29k__ */
164
165
166 #if defined (__alpha) && W_TYPE_SIZE == 64
167 # define umul_ppmm(ph, pl, m0, m1) \
168   do {                                                                  \
169     UDItype __m0 = (m0), __m1 = (m1);                                   \
170     __asm__ ("umulh %r1,%2,%0"                                          \
171              : "=r" ((UDItype) ph)                                      \
172              : "%rJ" (__m0),                                            \
173                "rI" (__m1));                                            \
174     (pl) = __m0 * __m1;                                                 \
175   } while (0)
176 # define UMUL_TIME 46
177 # ifndef LONGLONG_STANDALONE
178 #  define udiv_qrnnd(q, r, n1, n0, d) \
179   do { UDItype __r;                                                     \
180     (q) = __udiv_qrnnd (&__r, (n1), (n0), (d));                         \
181     (r) = __r;                                                          \
182   } while (0)
183 extern UDItype __udiv_qrnnd ();
184 #  define UDIV_TIME 220
185 # endif /* !LONGLONG_STANDALONE */
186 #endif /* __alpha */
187
188 /***************************************
189  **************  ARM  ******************
190  ***************************************/
191 #if defined (__arm__) && W_TYPE_SIZE == 32 && \
192     (!defined (__thumb__) || defined (__thumb2__))
193 /* The __ARM_ARCH define is provided by gcc 4.8.  Construct it otherwise.  */
194 # ifndef __ARM_ARCH
195 #  ifdef __ARM_ARCH_2__
196 #   define __ARM_ARCH 2
197 #  elif defined (__ARM_ARCH_3__) || defined (__ARM_ARCH_3M__)
198 #   define __ARM_ARCH 3
199 #  elif defined (__ARM_ARCH_4__) || defined (__ARM_ARCH_4T__)
200 #   define __ARM_ARCH 4
201 #  elif defined (__ARM_ARCH_5__) || defined (__ARM_ARCH_5E__) \
202         || defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_5TE__) \
203         || defined(__ARM_ARCH_5TEJ__)
204 #   define __ARM_ARCH 5
205 #  elif defined (__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
206         || defined (__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) \
207         || defined (__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__)
208 #   define __ARM_ARCH 6
209 #  elif defined (__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
210         || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
211         || defined(__ARM_ARCH_7EM__)
212 #   define __ARM_ARCH 7
213 #  else
214    /* could not detect? */
215 #  endif
216 # endif /* !__ARM_ARCH */
217
218 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
219   __asm__ ("adds %1, %4, %5\n"                                          \
220            "adc  %0, %2, %3"                                            \
221            : "=r" ((sh)),                                               \
222              "=&r" ((sl))                                               \
223            : "%r" ((USItype)(ah)),                                      \
224              "rI" ((USItype)(bh)),                                      \
225              "%r" ((USItype)(al)),                                      \
226              "rI" ((USItype)(bl)) __CLOBBER_CC)
227 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
228   __asm__ ("subs %1, %4, %5\n"                                          \
229            "sbc  %0, %2, %3"                                            \
230            : "=r" ((sh)),                                               \
231              "=&r" ((sl))                                               \
232            : "r" ((USItype)(ah)),                                       \
233              "rI" ((USItype)(bh)),                                      \
234              "r" ((USItype)(al)),                                       \
235              "rI" ((USItype)(bl)) __CLOBBER_CC)
236 # if (defined __ARM_ARCH && __ARM_ARCH <= 3)
237 #  define umul_ppmm(xh, xl, a, b) \
238   __asm__ ("@ Inlined umul_ppmm\n"                                      \
239         "mov    %|r0, %2, lsr #16               @ AAAA\n"               \
240         "mov    %|r2, %3, lsr #16               @ BBBB\n"               \
241         "bic    %|r1, %2, %|r0, lsl #16         @ aaaa\n"               \
242         "bic    %0, %3, %|r2, lsl #16           @ bbbb\n"               \
243         "mul    %1, %|r1, %|r2                  @ aaaa * BBBB\n"        \
244         "mul    %|r2, %|r0, %|r2                @ AAAA * BBBB\n"        \
245         "mul    %|r1, %0, %|r1                  @ aaaa * bbbb\n"        \
246         "mul    %0, %|r0, %0                    @ AAAA * bbbb\n"        \
247         "adds   %|r0, %1, %0                    @ central sum\n"        \
248         "addcs  %|r2, %|r2, #65536\n"                                   \
249         "adds   %1, %|r1, %|r0, lsl #16\n"                              \
250         "adc    %0, %|r2, %|r0, lsr #16"                                \
251            : "=&r" ((xh)),                                              \
252              "=r" ((xl))                                                \
253            : "r" ((USItype)(a)),                                        \
254              "r" ((USItype)(b))                                         \
255            : "r0", "r1", "r2" __AND_CLOBBER_CC)
256 # else /* __ARM_ARCH >= 4 */
257 #  define umul_ppmm(xh, xl, a, b)                                         \
258   __asm__ ("@ Inlined umul_ppmm\n"                                      \
259            "umull %1, %0, %2, %3"                                       \
260                    : "=&r" ((xh)),                                      \
261                      "=r" ((xl))                                        \
262                    : "r" ((USItype)(a)),                                \
263                      "r" ((USItype)(b)))
264 # endif /* __ARM_ARCH >= 4 */
265 # define UMUL_TIME 20
266 # define UDIV_TIME 100
267 # if (defined __ARM_ARCH && __ARM_ARCH >= 5)
268 #  define count_leading_zeros(count, x) \
269   __asm__ ("clz %0, %1"                                                 \
270                    : "=r" ((count))                                     \
271                    : "r" ((USItype)(x)))
272 # endif /* __ARM_ARCH >= 5 */
273 #endif /* __arm__ */
274
275 /***************************************
276  **********  ARM64 / Aarch64  **********
277  ***************************************/
278 #if defined(__aarch64__) && W_TYPE_SIZE == 64
279 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
280   __asm__ ("adds %1, %4, %5\n"                                          \
281            "adc  %0, %2, %3\n"                                          \
282            : "=r" ((sh)),                                               \
283              "=&r" ((sl))                                               \
284            : "r" ((UDItype)(ah)),                                       \
285              "r" ((UDItype)(bh)),                                       \
286              "r" ((UDItype)(al)),                                       \
287              "r" ((UDItype)(bl)) __CLOBBER_CC)
288 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
289   __asm__ ("subs %1, %4, %5\n"                                          \
290            "sbc  %0, %2, %3\n"                                          \
291            : "=r" ((sh)),                                               \
292              "=&r" ((sl))                                               \
293            : "r" ((UDItype)(ah)),                                       \
294              "r" ((UDItype)(bh)),                                       \
295              "r" ((UDItype)(al)),                                       \
296              "r" ((UDItype)(bl)) __CLOBBER_CC)
297 # define umul_ppmm(ph, pl, m0, m1) \
298   do {                                                                  \
299     UDItype __m0 = (m0), __m1 = (m1), __ph;                             \
300     (pl) = __m0 * __m1;                                                 \
301     __asm__ ("umulh %0,%1,%2"                                           \
302              : "=r" (__ph)                                              \
303              : "r" (__m0),                                              \
304                "r" (__m1));                                             \
305     (ph) = __ph; \
306   } while (0)
307 # define count_leading_zeros(count, x) \
308   __asm__ ("clz %0, %1\n"                                               \
309            : "=r" ((count))                                             \
310            : "r" ((UDItype)(x)))
311 #endif /* __aarch64__ */
312
313 /***************************************
314  **************  CLIPPER  **************
315  ***************************************/
316 #if defined (__clipper__) && W_TYPE_SIZE == 32
317 # define umul_ppmm(w1, w0, u, v) \
318   ({union {UDItype __ll;                                                \
319            struct {USItype __l, __h;} __i;                              \
320           } __xx;                                                       \
321   __asm__ ("mulwux %2,%0"                                               \
322            : "=r" (__xx.__ll)                                           \
323            : "%0" ((USItype)(u)),                                       \
324              "r" ((USItype)(v)));                                       \
325   (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
326 # define smul_ppmm(w1, w0, u, v) \
327   ({union {DItype __ll;                                                 \
328            struct {SItype __l, __h;} __i;                               \
329           } __xx;                                                       \
330   __asm__ ("mulwx %2,%0"                                                \
331            : "=r" (__xx.__ll)                                           \
332            : "%0" ((SItype)(u)),                                        \
333              "r" ((SItype)(v)));                                        \
334   (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
335 # define __umulsidi3(u, v) \
336   ({UDItype __w;                                                        \
337     __asm__ ("mulwux %2,%0"                                             \
338              : "=r" (__w)                                               \
339              : "%0" ((USItype)(u)),                                     \
340                "r" ((USItype)(v)));                                     \
341     __w; })
342 #endif /* __clipper__ */
343
344
345 /***************************************
346  **************  GMICRO  ***************
347  ***************************************/
348 #if defined (__gmicro__) && W_TYPE_SIZE == 32
349 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
350   __asm__ ("add.w %5,%1\n"                                              \
351            "addx %3,%0"                                                 \
352            : "=g" ((USItype)(sh)),                                      \
353              "=&g" ((USItype)(sl))                                      \
354            : "%0" ((USItype)(ah)),                                      \
355              "g" ((USItype)(bh)),                                       \
356              "%1" ((USItype)(al)),                                      \
357              "g" ((USItype)(bl)))
358 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
359   __asm__ ("sub.w %5,%1\n"                                              \
360            "subx %3,%0"                                                 \
361            : "=g" ((USItype)(sh)),                                      \
362              "=&g" ((USItype)(sl))                                      \
363            : "0" ((USItype)(ah)),                                       \
364              "g" ((USItype)(bh)),                                       \
365              "1" ((USItype)(al)),                                       \
366              "g" ((USItype)(bl)))
367 # define umul_ppmm(ph, pl, m0, m1) \
368   __asm__ ("mulx %3,%0,%1"                                              \
369            : "=g" ((USItype)(ph)),                                      \
370              "=r" ((USItype)(pl))                                       \
371            : "%0" ((USItype)(m0)),                                      \
372              "g" ((USItype)(m1)))
373 # define udiv_qrnnd(q, r, nh, nl, d) \
374   __asm__ ("divx %4,%0,%1"                                              \
375            : "=g" ((USItype)(q)),                                       \
376              "=r" ((USItype)(r))                                        \
377            : "1" ((USItype)(nh)),                                       \
378              "0" ((USItype)(nl)),                                       \
379              "g" ((USItype)(d)))
380 # define count_leading_zeros(count, x) \
381   __asm__ ("bsch/1 %1,%0"                                               \
382            : "=g" (count)                                               \
383            : "g" ((USItype)(x)),                                        \
384              "0" ((USItype)0))
385 #endif
386
387
388 /***************************************
389  **************  HPPA  *****************
390  ***************************************/
391 #if defined (__hppa) && W_TYPE_SIZE == 32
392 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
393   __asm__ ("    add %4,%5,%1\n"                                             \
394            "    addc %2,%3,%0"                                              \
395            : "=r" ((USItype)(sh)),                                      \
396              "=&r" ((USItype)(sl))                                      \
397            : "%rM" ((USItype)(ah)),                                     \
398              "rM" ((USItype)(bh)),                                      \
399              "%rM" ((USItype)(al)),                                     \
400              "rM" ((USItype)(bl)))
401 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
402   __asm__ ("    sub %4,%5,%1\n"                                             \
403            "    subb %2,%3,%0"                                              \
404            : "=r" ((USItype)(sh)),                                      \
405              "=&r" ((USItype)(sl))                                      \
406            : "rM" ((USItype)(ah)),                                      \
407              "rM" ((USItype)(bh)),                                      \
408              "rM" ((USItype)(al)),                                      \
409              "rM" ((USItype)(bl)))
410 # if defined (_PA_RISC1_1)
411 #  define umul_ppmm(wh, wl, u, v) \
412   do {                                                                  \
413     union {UDItype __ll;                                                \
414            struct {USItype __h, __l;} __i;                              \
415           } __xx;                                                       \
416     __asm__ ("  xmpyu %1,%2,%0"                                           \
417              : "=*f" (__xx.__ll)                                        \
418              : "*f" ((USItype)(u)),                                     \
419                "*f" ((USItype)(v)));                                    \
420     (wh) = __xx.__i.__h;                                                \
421     (wl) = __xx.__i.__l;                                                \
422   } while (0)
423 #  define UMUL_TIME 8
424 #  define UDIV_TIME 60
425 # else
426 #  define UMUL_TIME 40
427 #  define UDIV_TIME 80
428 # endif
429 # ifndef LONGLONG_STANDALONE
430 #  define udiv_qrnnd(q, r, n1, n0, d) \
431   do { USItype __r;                                                     \
432     (q) = __udiv_qrnnd (&__r, (n1), (n0), (d));                         \
433     (r) = __r;                                                          \
434   } while (0)
435 extern USItype __udiv_qrnnd ();
436 # endif /* !LONGLONG_STANDALONE */
437 # define count_leading_zeros(count, x) \
438   do {                                                                 \
439     USItype __tmp;                                                     \
440     __asm__ (                                                          \
441        "        ldi             1,%0                                       \n" \
442        "        extru,=         %1,15,16,%%r0  ; Bits 31..16 zero?         \n" \
443        "        extru,tr        %1,15,16,%1    ; No.  Shift down, skip add.\n" \
444        "        ldo             16(%0),%0      ; Yes.   Perform add.       \n" \
445        "        extru,=         %1,23,8,%%r0   ; Bits 15..8 zero?          \n" \
446        "        extru,tr        %1,23,8,%1     ; No.  Shift down, skip add.\n" \
447        "        ldo             8(%0),%0       ; Yes.   Perform add.       \n" \
448        "        extru,=         %1,27,4,%%r0   ; Bits 7..4 zero?           \n" \
449        "        extru,tr        %1,27,4,%1     ; No.  Shift down, skip add.\n" \
450        "        ldo             4(%0),%0       ; Yes.   Perform add.       \n" \
451        "        extru,=         %1,29,2,%%r0   ; Bits 3..2 zero?           \n" \
452        "        extru,tr        %1,29,2,%1     ; No.  Shift down, skip add.\n" \
453        "        ldo             2(%0),%0       ; Yes.   Perform add.       \n" \
454        "        extru           %1,30,1,%1     ; Extract bit 1.            \n" \
455        "        sub             %0,%1,%0       ; Subtract it.              "   \
456        : "=r" (count), "=r" (__tmp) : "1" (x));                        \
457   } while (0)
458 #endif /* hppa */
459
460
461 /***************************************
462  **************  I370  *****************
463  ***************************************/
464 #if (defined (__i370__) || defined (__mvs__)) && W_TYPE_SIZE == 32
465 # define umul_ppmm(xh, xl, m0, m1) \
466   do {                                                                  \
467     union {UDItype __ll;                                                \
468            struct {USItype __h, __l;} __i;                              \
469           } __xx;                                                       \
470     USItype __m0 = (m0), __m1 = (m1);                                   \
471     __asm__ ("mr %0,%3"                                                 \
472              : "=r" (__xx.__i.__h),                                     \
473                "=r" (__xx.__i.__l)                                      \
474              : "%1" (__m0),                                             \
475                "r" (__m1));                                             \
476     (xh) = __xx.__i.__h; (xl) = __xx.__i.__l;                           \
477     (xh) += ((((SItype) __m0 >> 31) & __m1)                             \
478              + (((SItype) __m1 >> 31) & __m0));                         \
479   } while (0)
480 # define smul_ppmm(xh, xl, m0, m1) \
481   do {                                                                  \
482     union {DItype __ll;                                                 \
483            struct {USItype __h, __l;} __i;                              \
484           } __xx;                                                       \
485     __asm__ ("mr %0,%3"                                                 \
486              : "=r" (__xx.__i.__h),                                     \
487                "=r" (__xx.__i.__l)                                      \
488              : "%1" (m0),                                               \
489                "r" (m1));                                               \
490     (xh) = __xx.__i.__h; (xl) = __xx.__i.__l;                           \
491   } while (0)
492 # define sdiv_qrnnd(q, r, n1, n0, d) \
493   do {                                                                  \
494     union {DItype __ll;                                                 \
495            struct {USItype __h, __l;} __i;                              \
496           } __xx;                                                       \
497     __xx.__i.__h = n1; __xx.__i.__l = n0;                               \
498     __asm__ ("dr %0,%2"                                                 \
499              : "=r" (__xx.__ll)                                         \
500              : "0" (__xx.__ll), "r" (d));                               \
501     (q) = __xx.__i.__l; (r) = __xx.__i.__h;                             \
502   } while (0)
503 #endif
504
505
506 /***************************************
507  **************  I386  *****************
508  ***************************************/
509 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
510 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
511   __asm__ ("addl %5,%1\n"                                               \
512            "adcl %3,%0"                                                 \
513            : "=r" ((sh)),                                               \
514              "=&r" ((sl))                                               \
515            : "%0" ((USItype)(ah)),                                      \
516              "g" ((USItype)(bh)),                                       \
517              "%1" ((USItype)(al)),                                      \
518              "g" ((USItype)(bl))                                        \
519            __CLOBBER_CC)
520 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
521   __asm__ ("subl %5,%1\n"                                               \
522            "sbbl %3,%0"                                                 \
523            : "=r" ((sh)),                                               \
524              "=&r" ((sl))                                               \
525            : "0" ((USItype)(ah)),                                       \
526              "g" ((USItype)(bh)),                                       \
527              "1" ((USItype)(al)),                                       \
528              "g" ((USItype)(bl))                                        \
529            __CLOBBER_CC)
530 # define umul_ppmm(w1, w0, u, v) \
531   __asm__ ("mull %3"                                                    \
532            : "=a" ((w0)),                                               \
533              "=d" ((w1))                                                \
534            : "%0" ((USItype)(u)),                                       \
535              "rm" ((USItype)(v))                                        \
536            __CLOBBER_CC)
537 # define udiv_qrnnd(q, r, n1, n0, d) \
538   __asm__ ("divl %4"                                                    \
539            : "=a" ((q)),                                                \
540              "=d" ((r))                                                 \
541            : "0" ((USItype)(n0)),                                       \
542              "1" ((USItype)(n1)),                                       \
543              "rm" ((USItype)(d))                                        \
544            __CLOBBER_CC)
545 # define count_leading_zeros(count, x) \
546   do {                                                                  \
547     USItype __cbtmp;                                                    \
548     __asm__ ("bsrl %1,%0"                                               \
549              : "=r" (__cbtmp) : "rm" ((USItype)(x))                     \
550              __CLOBBER_CC);                                             \
551     (count) = __cbtmp ^ 31;                                             \
552   } while (0)
553 # define count_trailing_zeros(count, x) \
554   __asm__ ("bsfl %1,%0" : "=r" (count) : "rm" ((USItype)(x)) __CLOBBER_CC)
555 # ifndef UMUL_TIME
556 #  define UMUL_TIME 40
557 # endif
558 # ifndef UDIV_TIME
559 #  define UDIV_TIME 40
560 # endif
561 #endif /* 80x86 */
562
563 /***************************************
564  *********** AMD64 / x86-64 ************
565  ***************************************/
566 #if defined(__x86_64) && W_TYPE_SIZE == 64
567 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
568   __asm__ ("addq %5,%1\n"                                               \
569            "adcq %3,%0"                                                 \
570            : "=r" ((sh)),                                               \
571              "=&r" ((sl))                                               \
572            : "0" ((UDItype)(ah)),                                       \
573              "g"  ((UDItype)(bh)),                                      \
574              "1" ((UDItype)(al)),                                       \
575              "g"  ((UDItype)(bl))                                       \
576            __CLOBBER_CC)
577 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
578   __asm__ ("subq %5,%1\n"                                               \
579            "sbbq %3,%0"                                                 \
580            : "=r" ((sh)),                                               \
581              "=&r" ((sl))                                               \
582            : "0" ((UDItype)(ah)),                                       \
583              "g" ((UDItype)(bh)),                                       \
584              "1" ((UDItype)(al)),                                       \
585              "g" ((UDItype)(bl))                                        \
586            __CLOBBER_CC)
587 # define umul_ppmm(w1, w0, u, v) \
588   __asm__ ("mulq %3"                                                    \
589            : "=a" ((w0)),                                               \
590              "=d" ((w1))                                                \
591            : "0" ((UDItype)(u)),                                        \
592              "rm" ((UDItype)(v))                                        \
593            __CLOBBER_CC)
594 # define udiv_qrnnd(q, r, n1, n0, d) \
595   __asm__ ("divq %4"                                                    \
596            : "=a" ((q)),                                                \
597              "=d" ((r))                                                 \
598            : "0" ((UDItype)(n0)),                                       \
599              "1" ((UDItype)(n1)),                                       \
600              "rm" ((UDItype)(d))                                        \
601            __CLOBBER_CC)
602 # define count_leading_zeros(count, x) \
603   do {                                                                  \
604     UDItype __cbtmp;                                                    \
605     __asm__ ("bsrq %1,%0"                                               \
606              : "=r" (__cbtmp) : "rm" ((UDItype)(x))                     \
607              __CLOBBER_CC);                                             \
608     (count) = __cbtmp ^ 63;                                             \
609   } while (0)
610 # define count_trailing_zeros(count, x) \
611   do {                                                                  \
612     UDItype __cbtmp;                                                    \
613     __asm__ ("bsfq %1,%0"                                               \
614              : "=r" (__cbtmp) : "rm" ((UDItype)(x))                     \
615              __CLOBBER_CC);                                             \
616     (count) = __cbtmp;                                                  \
617   } while (0)
618 # ifndef UMUL_TIME
619 #  define UMUL_TIME 40
620 # endif
621 # ifndef UDIV_TIME
622 #  define UDIV_TIME 40
623 # endif
624 #endif /* __x86_64 */
625
626
627 /***************************************
628  **************  I860  *****************
629  ***************************************/
630 #if defined (__i860__) && W_TYPE_SIZE == 32
631 # define rshift_rhlc(r,h,l,c) \
632   __asm__ ("shr %3,r0,r0\n"  \
633            "shrd %1,%2,%0"   \
634            "=r" (r) : "r" (h), "r" (l), "rn" (c))
635 #endif /* i860 */
636
637 /***************************************
638  **************  I960  *****************
639  ***************************************/
640 #if defined (__i960__) && W_TYPE_SIZE == 32
641 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
642   __asm__ ("cmpo 1,0\n"      \
643            "addc %5,%4,%1\n" \
644            "addc %3,%2,%0"   \
645            : "=r" ((USItype)(sh)),                                      \
646              "=&r" ((USItype)(sl))                                      \
647            : "%dI" ((USItype)(ah)),                                     \
648              "dI" ((USItype)(bh)),                                      \
649              "%dI" ((USItype)(al)),                                     \
650              "dI" ((USItype)(bl)))
651 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
652   __asm__ ("cmpo 0,0\n"      \
653            "subc %5,%4,%1\n" \
654            "subc %3,%2,%0"   \
655            : "=r" ((USItype)(sh)),                                      \
656              "=&r" ((USItype)(sl))                                      \
657            : "dI" ((USItype)(ah)),                                      \
658              "dI" ((USItype)(bh)),                                      \
659              "dI" ((USItype)(al)),                                      \
660              "dI" ((USItype)(bl)))
661 # define umul_ppmm(w1, w0, u, v) \
662   ({union {UDItype __ll;                                                \
663            struct {USItype __l, __h;} __i;                              \
664           } __xx;                                                       \
665   __asm__ ("emul        %2,%1,%0"                                       \
666            : "=d" (__xx.__ll)                                           \
667            : "%dI" ((USItype)(u)),                                      \
668              "dI" ((USItype)(v)));                                      \
669   (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
670 # define __umulsidi3(u, v) \
671   ({UDItype __w;                                                        \
672     __asm__ ("emul      %2,%1,%0"                                       \
673              : "=d" (__w)                                               \
674              : "%dI" ((USItype)(u)),                                    \
675                "dI" ((USItype)(v)));                                    \
676     __w; })
677 # define udiv_qrnnd(q, r, nh, nl, d) \
678   do {                                                                  \
679     union {UDItype __ll;                                                \
680            struct {USItype __l, __h;} __i;                              \
681           } __nn;                                                       \
682     __nn.__i.__h = (nh); __nn.__i.__l = (nl);                           \
683     __asm__ ("ediv %d,%n,%0"                                            \
684            : "=d" (__rq.__ll)                                           \
685            : "dI" (__nn.__ll),                                          \
686              "dI" ((USItype)(d)));                                      \
687     (r) = __rq.__i.__l; (q) = __rq.__i.__h;                             \
688   } while (0)
689 # define count_leading_zeros(count, x) \
690   do {                                                                  \
691     USItype __cbtmp;                                                    \
692     __asm__ ("scanbit %1,%0"                                            \
693              : "=r" (__cbtmp)                                           \
694              : "r" ((USItype)(x)));                                     \
695     (count) = __cbtmp ^ 31;                                             \
696   } while (0)
697 # define COUNT_LEADING_ZEROS_0 (-32) /* sic */
698 # if defined (__i960mx)  /* what is the proper symbol to test??? */
699 #  define rshift_rhlc(r,h,l,c) \
700   do {                                                                  \
701     union {UDItype __ll;                                                \
702            struct {USItype __l, __h;} __i;                              \
703           } __nn;                                                       \
704     __nn.__i.__h = (h); __nn.__i.__l = (l);                             \
705     __asm__ ("shre %2,%1,%0"                                            \
706              : "=d" (r) : "dI" (__nn.__ll), "dI" (c));                  \
707   }
708 # endif /* i960mx */
709 #endif /* i960 */
710
711
712 /***************************************
713  **************  68000  ****************
714  ***************************************/
715 #if (defined (__mc68000__) || defined (__mc68020__)                     \
716      || defined (__NeXT__) || defined(mc68020)) && W_TYPE_SIZE == 32
717 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
718   __asm__ ("add%.l %5,%1\n"                                             \
719            "addx%.l %3,%0"                                              \
720            : "=d" ((USItype)(sh)),                                      \
721              "=&d" ((USItype)(sl))                                      \
722            : "%0" ((USItype)(ah)),                                      \
723              "d" ((USItype)(bh)),                                       \
724              "%1" ((USItype)(al)),                                      \
725              "g" ((USItype)(bl)))
726 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
727   __asm__ ("sub%.l %5,%1\n"                                             \
728            "subx%.l %3,%0"                                              \
729            : "=d" ((USItype)(sh)),                                      \
730              "=&d" ((USItype)(sl))                                      \
731            : "0" ((USItype)(ah)),                                       \
732              "d" ((USItype)(bh)),                                       \
733              "1" ((USItype)(al)),                                       \
734              "g" ((USItype)(bl)))
735 # if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
736 #  define umul_ppmm(w1, w0, u, v) \
737   __asm__ ("mulu%.l %3,%1:%0"                                           \
738            : "=d" ((USItype)(w0)),                                      \
739              "=d" ((USItype)(w1))                                       \
740            : "%0" ((USItype)(u)),                                       \
741              "dmi" ((USItype)(v)))
742 #  define UMUL_TIME 45
743 #  define udiv_qrnnd(q, r, n1, n0, d) \
744   __asm__ ("divu%.l %4,%1:%0"                                           \
745            : "=d" ((USItype)(q)),                                       \
746              "=d" ((USItype)(r))                                        \
747            : "0" ((USItype)(n0)),                                       \
748              "1" ((USItype)(n1)),                                       \
749              "dmi" ((USItype)(d)))
750 #  define UDIV_TIME 90
751 #  define sdiv_qrnnd(q, r, n1, n0, d) \
752   __asm__ ("divs%.l %4,%1:%0"                                           \
753            : "=d" ((USItype)(q)),                                       \
754              "=d" ((USItype)(r))                                        \
755            : "0" ((USItype)(n0)),                                       \
756              "1" ((USItype)(n1)),                                       \
757              "dmi" ((USItype)(d)))
758 #  define count_leading_zeros(count, x) \
759   __asm__ ("bfffo %1{%b2:%b2},%0"                                       \
760            : "=d" ((USItype)(count))                                    \
761            : "od" ((USItype)(x)), "n" (0))
762 #  define COUNT_LEADING_ZEROS_0 32
763 # else /* not mc68020 */
764 #  define umul_ppmm(xh, xl, a, b) \
765   do { USItype __umul_tmp1, __umul_tmp2;                          \
766         __asm__ ("| Inlined umul_ppmm                         \n" \
767  "        move%.l %5,%3                                       \n" \
768  "        move%.l %2,%0                                       \n" \
769  "        move%.w %3,%1                                       \n" \
770  "        swap  %3                                            \n" \
771  "        swap  %0                                            \n" \
772  "        mulu  %2,%1                                         \n" \
773  "        mulu  %3,%0                                         \n" \
774  "        mulu  %2,%3                                         \n" \
775  "        swap  %2                                            \n" \
776  "        mulu  %5,%2                                         \n" \
777  "        add%.l        %3,%2                                 \n" \
778  "        jcc   1f                                            \n" \
779  "        add%.l        %#0x10000,%0                          \n" \
780  "1:    move%.l %2,%3                                         \n" \
781  "        clr%.w        %2                                    \n" \
782  "        swap  %2                                            \n" \
783  "        swap  %3                                            \n" \
784  "        clr%.w        %3                                    \n" \
785  "        add%.l        %3,%1                                 \n" \
786  "        addx%.l %2,%0                                       \n" \
787  "        | End inlined umul_ppmm"                                \
788               : "=&d" ((USItype)(xh)), "=&d" ((USItype)(xl)),     \
789                 "=d" (__umul_tmp1), "=&d" (__umul_tmp2)           \
790               : "%2" ((USItype)(a)), "d" ((USItype)(b)));         \
791   } while (0)
792 #  define UMUL_TIME 100
793 #  define UDIV_TIME 400
794 # endif /* not mc68020 */
795 #endif /* mc68000 */
796
797
798 /***************************************
799  **************  88000  ****************
800  ***************************************/
801 #if defined (__m88000__) && W_TYPE_SIZE == 32
802 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
803   __asm__ ("addu.co %1,%r4,%r5\n"                                       \
804            "addu.ci %0,%r2,%r3"                                         \
805            : "=r" ((USItype)(sh)),                                      \
806              "=&r" ((USItype)(sl))                                      \
807            : "%rJ" ((USItype)(ah)),                                     \
808              "rJ" ((USItype)(bh)),                                      \
809              "%rJ" ((USItype)(al)),                                     \
810              "rJ" ((USItype)(bl)))
811 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
812   __asm__ ("subu.co %1,%r4,%r5\n"                                       \
813            "subu.ci %0,%r2,%r3"                                         \
814            : "=r" ((USItype)(sh)),                                      \
815              "=&r" ((USItype)(sl))                                      \
816            : "rJ" ((USItype)(ah)),                                      \
817              "rJ" ((USItype)(bh)),                                      \
818              "rJ" ((USItype)(al)),                                      \
819              "rJ" ((USItype)(bl)))
820 # define count_leading_zeros(count, x) \
821   do {                                                                  \
822     USItype __cbtmp;                                                    \
823     __asm__ ("ff1 %0,%1"                                                \
824              : "=r" (__cbtmp)                                           \
825              : "r" ((USItype)(x)));                                     \
826     (count) = __cbtmp ^ 31;                                             \
827   } while (0)
828 # define COUNT_LEADING_ZEROS_0 63 /* sic */
829 # if defined (__m88110__)
830 #  define umul_ppmm(wh, wl, u, v) \
831   do {                                                                  \
832     union {UDItype __ll;                                                \
833            struct {USItype __h, __l;} __i;                              \
834           } __x;                                                        \
835     __asm__ ("mulu.d %0,%1,%2" : "=r" (__x.__ll) : "r" (u), "r" (v));   \
836     (wh) = __x.__i.__h;                                                 \
837     (wl) = __x.__i.__l;                                                 \
838   } while (0)
839 #  define udiv_qrnnd(q, r, n1, n0, d) \
840   ({union {UDItype __ll;                                                \
841            struct {USItype __h, __l;} __i;                              \
842           } __x, __q;                                                   \
843   __x.__i.__h = (n1); __x.__i.__l = (n0);                               \
844   __asm__ ("divu.d %0,%1,%2"                                            \
845            : "=r" (__q.__ll) : "r" (__x.__ll), "r" (d));                \
846   (r) = (n0) - __q.__l * (d); (q) = __q.__l; })
847 #  define UMUL_TIME 5
848 #  define UDIV_TIME 25
849 # else
850 #  define UMUL_TIME 17
851 #  define UDIV_TIME 150
852 # endif /* __m88110__ */
853 #endif /* __m88000__ */
854
855 /***************************************
856  **************  MIPS  *****************
857  ***************************************/
858 #if defined (__mips__) && W_TYPE_SIZE == 32
859 # if defined (__clang__) || (__GNUC__ >= 5) || (__GNUC__ == 4 && \
860                                                __GNUC_MINOR__ >= 4)
861 #  define umul_ppmm(w1, w0, u, v) \
862   do {                                                                  \
863     UDItype _r;                                                         \
864     _r = (UDItype) u * v;                                               \
865     (w1) = _r >> 32;                                                    \
866     (w0) = (USItype) _r;                                                \
867   } while (0)
868 # elif __GNUC__ > 2 || __GNUC_MINOR__ >= 7
869 #  define umul_ppmm(w1, w0, u, v) \
870   __asm__ ("multu %2,%3"                                                \
871            : "=l" ((USItype)(w0)),                                      \
872              "=h" ((USItype)(w1))                                       \
873            : "d" ((USItype)(u)),                                        \
874              "d" ((USItype)(v)))
875 # else
876 #  define umul_ppmm(w1, w0, u, v) \
877   __asm__ ("multu %2,%3 \n" \
878            "mflo %0 \n"     \
879            "mfhi %1"                                                        \
880            : "=d" ((USItype)(w0)),                                      \
881              "=d" ((USItype)(w1))                                       \
882            : "d" ((USItype)(u)),                                        \
883              "d" ((USItype)(v)))
884 # endif
885 # define UMUL_TIME 10
886 # define UDIV_TIME 100
887 #endif /* __mips__ */
888
889 /***************************************
890  **************  MIPS/64  **************
891  ***************************************/
892 #if (defined (__mips) && __mips >= 3) && W_TYPE_SIZE == 64
893 # if defined (__clang__) || (__GNUC__ >= 5) || (__GNUC__ == 4 && \
894                                                __GNUC_MINOR__ >= 4)
895 typedef unsigned int UTItype __attribute__ ((mode (TI)));
896 #  define umul_ppmm(w1, w0, u, v) \
897   do {                                                                 \
898     UTItype _r;                                                        \
899     _r = (UTItype) u * v;                                              \
900     (w1) = _r >> 64;                                                   \
901     (w0) = (UDItype) _r;                                               \
902   } while (0)
903 # elif __GNUC__ > 2 || __GNUC_MINOR__ >= 7
904 #  define umul_ppmm(w1, w0, u, v) \
905   __asm__ ("dmultu %2,%3"                                               \
906            : "=l" ((UDItype)(w0)),                                      \
907              "=h" ((UDItype)(w1))                                       \
908            : "d" ((UDItype)(u)),                                        \
909              "d" ((UDItype)(v)))
910 # else
911 #  define umul_ppmm(w1, w0, u, v) \
912   __asm__ ("dmultu %2,%3 \n"    \
913            "mflo %0 \n"         \
914            "mfhi %1"                                                        \
915            : "=d" ((UDItype)(w0)),                                      \
916              "=d" ((UDItype)(w1))                                       \
917            : "d" ((UDItype)(u)),                                        \
918              "d" ((UDItype)(v)))
919 # endif
920 # define UMUL_TIME 20
921 # define UDIV_TIME 140
922 #endif /* __mips__ */
923
924
925 /***************************************
926  **************  32000  ****************
927  ***************************************/
928 #if defined (__ns32000__) && W_TYPE_SIZE == 32
929 # define umul_ppmm(w1, w0, u, v) \
930   ({union {UDItype __ll;                                                \
931            struct {USItype __l, __h;} __i;                              \
932           } __xx;                                                       \
933   __asm__ ("meid %2,%0"                                                 \
934            : "=g" (__xx.__ll)                                           \
935            : "%0" ((USItype)(u)),                                       \
936              "g" ((USItype)(v)));                                       \
937   (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
938 # define __umulsidi3(u, v) \
939   ({UDItype __w;                                                        \
940     __asm__ ("meid %2,%0"                                               \
941              : "=g" (__w)                                               \
942              : "%0" ((USItype)(u)),                                     \
943                "g" ((USItype)(v)));                                     \
944     __w; })
945 # define udiv_qrnnd(q, r, n1, n0, d) \
946   ({union {UDItype __ll;                                                \
947            struct {USItype __l, __h;} __i;                              \
948           } __xx;                                                       \
949   __xx.__i.__h = (n1); __xx.__i.__l = (n0);                             \
950   __asm__ ("deid %2,%0"                                                 \
951            : "=g" (__xx.__ll)                                           \
952            : "0" (__xx.__ll),                                           \
953              "g" ((USItype)(d)));                                       \
954   (r) = __xx.__i.__l; (q) = __xx.__i.__h; })
955 # define count_trailing_zeros(count,x) \
956   do {
957     __asm__ ("ffsd      %2,%0"                                          \
958              : "=r" ((USItype) (count))                                 \
959              : "0" ((USItype) 0),                                       \
960                "r" ((USItype) (x)));                                    \
961   } while (0)
962 #endif /* __ns32000__ */
963
964
965 /***************************************
966  **************  PPC  ******************
967  ***************************************/
968 #if (defined (_ARCH_PPC) || defined (_IBMR2)) && W_TYPE_SIZE == 32
969 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
970   do {                                                                  \
971     if (__builtin_constant_p (bh) && (bh) == 0)                         \
972       __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2"           \
973              : "=r" ((sh)),                                             \
974                "=&r" ((sl))                                             \
975              : "%r" ((USItype)(ah)),                                    \
976                "%r" ((USItype)(al)),                                    \
977                "rI" ((USItype)(bl)));                                   \
978     else if (__builtin_constant_p (bh) && (bh) ==~(USItype) 0)          \
979       __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2"           \
980              : "=r" ((sh)),                                             \
981                "=&r" ((sl))                                             \
982              : "%r" ((USItype)(ah)),                                    \
983                "%r" ((USItype)(al)),                                    \
984                "rI" ((USItype)(bl)));                                   \
985     else                                                                \
986       __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3"          \
987              : "=r" ((sh)),                                             \
988                "=&r" ((sl))                                             \
989              : "%r" ((USItype)(ah)),                                    \
990                "r" ((USItype)(bh)),                                     \
991                "%r" ((USItype)(al)),                                    \
992                "rI" ((USItype)(bl)));                                   \
993   } while (0)
994 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
995   do {                                                                  \
996     if (__builtin_constant_p (ah) && (ah) == 0)                         \
997       __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2"       \
998                : "=r" ((sh)),                                           \
999                  "=&r" ((sl))                                           \
1000                : "r" ((USItype)(bh)),                                   \
1001                  "rI" ((USItype)(al)),                                  \
1002                  "r" ((USItype)(bl)));                                  \
1003     else if (__builtin_constant_p (ah) && (ah) ==~(USItype) 0)          \
1004       __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2"       \
1005                : "=r" ((sh)),                                  \
1006                  "=&r" ((sl))                                  \
1007                : "r" ((USItype)(bh)),                                   \
1008                  "rI" ((USItype)(al)),                                  \
1009                  "r" ((USItype)(bl)));                                  \
1010     else if (__builtin_constant_p (bh) && (bh) == 0)                    \
1011       __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2"         \
1012                : "=r" ((sh)),                                           \
1013                  "=&r" ((sl))                                           \
1014                : "r" ((USItype)(ah)),                                   \
1015                  "rI" ((USItype)(al)),                                  \
1016                  "r" ((USItype)(bl)));                                  \
1017     else if (__builtin_constant_p (bh) && (bh) ==~(USItype) 0)          \
1018       __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2"         \
1019                : "=r" ((sh)),                                           \
1020                  "=&r" ((sl))                                           \
1021                : "r" ((USItype)(ah)),                                   \
1022                  "rI" ((USItype)(al)),                                  \
1023                  "r" ((USItype)(bl)));                                  \
1024     else                                                                \
1025       __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2"      \
1026                : "=r" ((sh)),                                           \
1027                  "=&r" ((sl))                                           \
1028                : "r" ((USItype)(ah)),                                   \
1029                  "r" ((USItype)(bh)),                                   \
1030                  "rI" ((USItype)(al)),                                  \
1031                  "r" ((USItype)(bl)));                                  \
1032   } while (0)
1033 # define count_leading_zeros(count, x) \
1034   __asm__ ("{cntlz|cntlzw} %0,%1"                                       \
1035            : "=r" ((count))                                             \
1036            : "r" ((USItype)(x)))
1037 # define COUNT_LEADING_ZEROS_0 32
1038 # if defined (_ARCH_PPC)
1039 #  define umul_ppmm(ph, pl, m0, m1) \
1040   do {                                                                  \
1041     USItype __m0 = (m0), __m1 = (m1);                                   \
1042     __asm__ ("mulhwu %0,%1,%2"                                          \
1043              : "=r" (ph)                                                \
1044              : "%r" (__m0),                                             \
1045                "r" (__m1));                                             \
1046     (pl) = __m0 * __m1;                                                 \
1047   } while (0)
1048 #  define UMUL_TIME 15
1049 #  define smul_ppmm(ph, pl, m0, m1) \
1050   do {                                                                  \
1051     SItype __m0 = (m0), __m1 = (m1);                                    \
1052     __asm__ ("mulhw %0,%1,%2"                                           \
1053              : "=r" ((SItype) ph)                                       \
1054              : "%r" (__m0),                                             \
1055                "r" (__m1));                                             \
1056     (pl) = __m0 * __m1;                                                 \
1057   } while (0)
1058 #  define SMUL_TIME 14
1059 #  define UDIV_TIME 120
1060 # else
1061 #  define umul_ppmm(xh, xl, m0, m1) \
1062   do {                                                                  \
1063     USItype __m0 = (m0), __m1 = (m1);                                   \
1064     __asm__ ("mul %0,%2,%3"                                             \
1065              : "=r" ((xh)),                                             \
1066                "=q" ((xl))                                              \
1067              : "r" (__m0),                                              \
1068                "r" (__m1));                                             \
1069     (xh) += ((((SItype) __m0 >> 31) & __m1)                             \
1070              + (((SItype) __m1 >> 31) & __m0));                         \
1071   } while (0)
1072 #  define UMUL_TIME 8
1073 #  define smul_ppmm(xh, xl, m0, m1) \
1074   __asm__ ("mul %0,%2,%3"                                               \
1075            : "=r" ((SItype)(xh)),                                       \
1076              "=q" ((SItype)(xl))                                        \
1077            : "r" (m0),                                                  \
1078              "r" (m1))
1079 #  define SMUL_TIME 4
1080 #  define sdiv_qrnnd(q, r, nh, nl, d) \
1081   __asm__ ("div %0,%2,%4"                                               \
1082            : "=r" ((SItype)(q)), "=q" ((SItype)(r))                     \
1083            : "r" ((SItype)(nh)), "1" ((SItype)(nl)), "r" ((SItype)(d)))
1084 #  define UDIV_TIME 100
1085 # endif
1086 #endif /* Power architecture variants.  */
1087
1088 /* Powerpc 64 bit support taken from gmp-4.1.2. */
1089 /* We should test _IBMR2 here when we add assembly support for the system
1090    vendor compilers.  */
1091 #if (defined (_ARCH_PPC) || defined (__powerpc__)) && W_TYPE_SIZE == 64
1092 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1093   do {                                                                  \
1094     if (__builtin_constant_p (bh) && (bh) == 0)                         \
1095       __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2"           \
1096              : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
1097     else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0)         \
1098       __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2"           \
1099              : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
1100     else                                                                \
1101       __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3"          \
1102              : "=r" (sh), "=&r" (sl)                                    \
1103              : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl));              \
1104   } while (0)
1105 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1106   do {                                                                  \
1107     if (__builtin_constant_p (ah) && (ah) == 0)                         \
1108       __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2"       \
1109                : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
1110     else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0)         \
1111       __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2"       \
1112                : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
1113     else if (__builtin_constant_p (bh) && (bh) == 0)                    \
1114       __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2"         \
1115                : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
1116     else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0)         \
1117       __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2"         \
1118                : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
1119     else                                                                \
1120       __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2"      \
1121                : "=r" (sh), "=&r" (sl)                                  \
1122                : "r" (ah), "r" (bh), "rI" (al), "r" (bl));              \
1123   } while (0)
1124 #define count_leading_zeros(count, x) \
1125   __asm__ ("cntlzd %0,%1" : "=r" (count) : "r" (x))
1126 #define COUNT_LEADING_ZEROS_0 64
1127 #define umul_ppmm(ph, pl, m0, m1) \
1128   do {                                                                  \
1129     UDItype __m0 = (m0), __m1 = (m1);                                   \
1130     __asm__ ("mulhdu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));      \
1131     (pl) = __m0 * __m1;                                                 \
1132   } while (0)
1133 #define UMUL_TIME 15
1134 #define smul_ppmm(ph, pl, m0, m1) \
1135   do {                                                                  \
1136     DItype __m0 = (m0), __m1 = (m1);                                    \
1137     __asm__ ("mulhd %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));       \
1138     (pl) = __m0 * __m1;                                                 \
1139   } while (0)
1140 #define SMUL_TIME 14  /* ??? */
1141 #define UDIV_TIME 120 /* ??? */
1142 #endif /* 64-bit PowerPC.  */
1143
1144 /***************************************
1145  **************  PYR  ******************
1146  ***************************************/
1147 #if defined (__pyr__) && W_TYPE_SIZE == 32
1148 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1149   __asm__ ("addw        %5,%1 \n" \
1150            "addwc       %3,%0"                                          \
1151            : "=r" ((USItype)(sh)),                                      \
1152              "=&r" ((USItype)(sl))                                      \
1153            : "%0" ((USItype)(ah)),                                      \
1154              "g" ((USItype)(bh)),                                       \
1155              "%1" ((USItype)(al)),                                      \
1156              "g" ((USItype)(bl)))
1157 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1158   __asm__ ("subw        %5,%1 \n" \
1159            "subwb       %3,%0"                                          \
1160            : "=r" ((USItype)(sh)),                                      \
1161              "=&r" ((USItype)(sl))                                      \
1162            : "0" ((USItype)(ah)),                                       \
1163              "g" ((USItype)(bh)),                                       \
1164              "1" ((USItype)(al)),                                       \
1165              "g" ((USItype)(bl)))
1166 /* This insn works on Pyramids with AP, XP, or MI CPUs, but not with SP.  */
1167 # define umul_ppmm(w1, w0, u, v) \
1168   ({union {UDItype __ll;                                                \
1169            struct {USItype __h, __l;} __i;                              \
1170           } __xx;                                                       \
1171   __asm__ ("movw %1,%R0 \n" \
1172            "uemul %2,%0"                                                \
1173            : "=&r" (__xx.__ll)                                          \
1174            : "g" ((USItype) (u)),                                       \
1175              "g" ((USItype)(v)));                                       \
1176   (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
1177 #endif /* __pyr__ */
1178
1179
1180 /***************************************
1181  **************  RT/ROMP  **************
1182  ***************************************/
1183 #if defined (__ibm032__) /* RT/ROMP */  && W_TYPE_SIZE == 32
1184 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1185   __asm__ ("a %1,%5 \n" \
1186            "ae %0,%3"                                                   \
1187            : "=r" ((USItype)(sh)),                                      \
1188              "=&r" ((USItype)(sl))                                      \
1189            : "%0" ((USItype)(ah)),                                      \
1190              "r" ((USItype)(bh)),                                       \
1191              "%1" ((USItype)(al)),                                      \
1192              "r" ((USItype)(bl)))
1193 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1194   __asm__ ("s %1,%5\n" \
1195            "se %0,%3"                                                   \
1196            : "=r" ((USItype)(sh)),                                      \
1197              "=&r" ((USItype)(sl))                                      \
1198            : "0" ((USItype)(ah)),                                       \
1199              "r" ((USItype)(bh)),                                       \
1200              "1" ((USItype)(al)),                                       \
1201              "r" ((USItype)(bl)))
1202 # define umul_ppmm(ph, pl, m0, m1) \
1203   do {                                                                  \
1204     USItype __m0 = (m0), __m1 = (m1);                                   \
1205     __asm__ (                                                           \
1206        "s       r2,r2    \n" \
1207        "mts     r10,%2   \n" \
1208        "m       r2,%3    \n" \
1209        "m       r2,%3    \n" \
1210        "m       r2,%3    \n" \
1211        "m       r2,%3    \n" \
1212        "m       r2,%3    \n" \
1213        "m       r2,%3    \n" \
1214        "m       r2,%3    \n" \
1215        "m       r2,%3    \n" \
1216        "m       r2,%3    \n" \
1217        "m       r2,%3    \n" \
1218        "m       r2,%3    \n" \
1219        "m       r2,%3    \n" \
1220        "m       r2,%3    \n" \
1221        "m       r2,%3    \n" \
1222        "m       r2,%3    \n" \
1223        "m       r2,%3    \n" \
1224        "cas     %0,r2,r0 \n" \
1225        "mfs     r10,%1"                                                 \
1226              : "=r" ((USItype)(ph)),                                    \
1227                "=r" ((USItype)(pl))                                     \
1228              : "%r" (__m0),                                             \
1229                 "r" (__m1)                                              \
1230              : "r2");                                                   \
1231     (ph) += ((((SItype) __m0 >> 31) & __m1)                             \
1232              + (((SItype) __m1 >> 31) & __m0));                         \
1233   } while (0)
1234 # define UMUL_TIME 20
1235 # define UDIV_TIME 200
1236 # define count_leading_zeros(count, x) \
1237   do {                                                                  \
1238     if ((x) >= 0x10000)                                                 \
1239       __asm__ ("clz     %0,%1"                                          \
1240                : "=r" ((USItype)(count))                                \
1241                : "r" ((USItype)(x) >> 16));                             \
1242     else                                                                \
1243       {                                                                 \
1244         __asm__ ("clz   %0,%1"                                          \
1245                  : "=r" ((USItype)(count))                              \
1246                  : "r" ((USItype)(x)));                                 \
1247         (count) += 16;                                                  \
1248       }                                                                 \
1249   } while (0)
1250 #endif /* RT/ROMP */
1251
1252
1253 /***************************************
1254  **************  SH2  ******************
1255  ***************************************/
1256 #if (defined (__sh2__) || defined(__sh3__) || defined(__SH4__) ) \
1257     && W_TYPE_SIZE == 32
1258 # define umul_ppmm(w1, w0, u, v) \
1259   __asm__ (                                                             \
1260         "dmulu.l %2,%3\n"  \
1261         "sts    macl,%1\n" \
1262         "sts    mach,%0"                                                \
1263            : "=r" ((USItype)(w1)),                                      \
1264              "=r" ((USItype)(w0))                                       \
1265            : "r" ((USItype)(u)),                                        \
1266              "r" ((USItype)(v))                                         \
1267            : "macl", "mach")
1268 # define UMUL_TIME 5
1269 #endif
1270
1271 /***************************************
1272  **************  SPARC  ****************
1273  ***************************************/
1274 #if defined (__sparc__) && W_TYPE_SIZE == 32
1275 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1276   __asm__ ("addcc %r4,%5,%1\n" \
1277            "addx %r2,%3,%0"                                             \
1278            : "=r" ((USItype)(sh)),                                      \
1279              "=&r" ((USItype)(sl))                                      \
1280            : "%rJ" ((USItype)(ah)),                                     \
1281              "rI" ((USItype)(bh)),                                      \
1282              "%rJ" ((USItype)(al)),                                     \
1283              "rI" ((USItype)(bl))                                       \
1284            __CLOBBER_CC)
1285 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1286   __asm__ ("subcc %r4,%5,%1\n" \
1287            "subx %r2,%3,%0"                                             \
1288            : "=r" ((USItype)(sh)),                                      \
1289              "=&r" ((USItype)(sl))                                      \
1290            : "rJ" ((USItype)(ah)),                                      \
1291              "rI" ((USItype)(bh)),                                      \
1292              "rJ" ((USItype)(al)),                                      \
1293              "rI" ((USItype)(bl))                                       \
1294            __CLOBBER_CC)
1295 # if defined (__sparc_v8__) || defined(__sparcv8)
1296 /* Don't match immediate range because, 1) it is not often useful,
1297    2) the 'I' flag thinks of the range as a 13 bit signed interval,
1298    while we want to match a 13 bit interval, sign extended to 32 bits,
1299    but INTERPRETED AS UNSIGNED.  */
1300 #  define umul_ppmm(w1, w0, u, v) \
1301   __asm__ ("umul %2,%3,%1;rd %%y,%0"                                    \
1302            : "=r" ((USItype)(w1)),                                      \
1303              "=r" ((USItype)(w0))                                       \
1304            : "r" ((USItype)(u)),                                        \
1305              "r" ((USItype)(v)))
1306 #  define UMUL_TIME 5
1307 #  ifndef SUPERSPARC    /* SuperSPARC's udiv only handles 53 bit dividends */
1308 #   define udiv_qrnnd(q, r, n1, n0, d) \
1309   do {                                                                  \
1310     USItype __q;                                                        \
1311     __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0"                     \
1312              : "=r" ((USItype)(__q))                                    \
1313              : "r" ((USItype)(n1)),                                     \
1314                "r" ((USItype)(n0)),                                     \
1315                "r" ((USItype)(d)));                                     \
1316     (r) = (n0) - __q * (d);                                             \
1317     (q) = __q;                                                          \
1318   } while (0)
1319 #   define UDIV_TIME 25
1320 #  endif /*!SUPERSPARC */
1321 # else /* ! __sparc_v8__ */
1322 #  if defined (__sparclite__)
1323 /* This has hardware multiply but not divide.  It also has two additional
1324    instructions scan (ffs from high bit) and divscc.  */
1325 #   define umul_ppmm(w1, w0, u, v) \
1326   __asm__ ("umul %2,%3,%1;rd %%y,%0"                                    \
1327            : "=r" ((USItype)(w1)),                                      \
1328              "=r" ((USItype)(w0))                                       \
1329            : "r" ((USItype)(u)),                                        \
1330              "r" ((USItype)(v)))
1331 #   define UMUL_TIME 5
1332 #   define udiv_qrnnd(q, r, n1, n0, d) \
1333   __asm__ ("! Inlined udiv_qrnnd                                     \n" \
1334  "        wr    %%g0,%2,%%y     ! Not a delayed write for sparclite  \n" \
1335  "        tst   %%g0                                                 \n" \
1336  "        divscc        %3,%4,%%g1                                   \n" \
1337  "        divscc        %%g1,%4,%%g1                                 \n" \
1338  "        divscc        %%g1,%4,%%g1                                 \n" \
1339  "        divscc        %%g1,%4,%%g1                                 \n" \
1340  "        divscc        %%g1,%4,%%g1                                 \n" \
1341  "        divscc        %%g1,%4,%%g1                                 \n" \
1342  "        divscc        %%g1,%4,%%g1                                 \n" \
1343  "        divscc        %%g1,%4,%%g1                                 \n" \
1344  "        divscc        %%g1,%4,%%g1                                 \n" \
1345  "        divscc        %%g1,%4,%%g1                                 \n" \
1346  "        divscc        %%g1,%4,%%g1                                 \n" \
1347  "        divscc        %%g1,%4,%%g1                                 \n" \
1348  "        divscc        %%g1,%4,%%g1                                 \n" \
1349  "        divscc        %%g1,%4,%%g1                                 \n" \
1350  "        divscc        %%g1,%4,%%g1                                 \n" \
1351  "        divscc        %%g1,%4,%%g1                                 \n" \
1352  "        divscc        %%g1,%4,%%g1                                 \n" \
1353  "        divscc        %%g1,%4,%%g1                                 \n" \
1354  "        divscc        %%g1,%4,%%g1                                 \n" \
1355  "        divscc        %%g1,%4,%%g1                                 \n" \
1356  "        divscc        %%g1,%4,%%g1                                 \n" \
1357  "        divscc        %%g1,%4,%%g1                                 \n" \
1358  "        divscc        %%g1,%4,%%g1                                 \n" \
1359  "        divscc        %%g1,%4,%%g1                                 \n" \
1360  "        divscc        %%g1,%4,%%g1                                 \n" \
1361  "        divscc        %%g1,%4,%%g1                                 \n" \
1362  "        divscc        %%g1,%4,%%g1                                 \n" \
1363  "        divscc        %%g1,%4,%%g1                                 \n" \
1364  "        divscc        %%g1,%4,%%g1                                 \n" \
1365  "        divscc        %%g1,%4,%%g1                                 \n" \
1366  "        divscc        %%g1,%4,%%g1                                 \n" \
1367  "        divscc        %%g1,%4,%0                                   \n" \
1368  "        rd    %%y,%1                                               \n" \
1369  "        bl,a 1f                                                    \n" \
1370  "        add   %1,%4,%1                                             \n" \
1371  "1:    ! End of inline udiv_qrnnd"                                     \
1372            : "=r" ((USItype)(q)),                                       \
1373              "=r" ((USItype)(r))                                        \
1374            : "r" ((USItype)(n1)),                                       \
1375              "r" ((USItype)(n0)),                                       \
1376              "rI" ((USItype)(d))                                        \
1377            : "%g1" __AND_CLOBBER_CC)
1378 #   define UDIV_TIME 37
1379 #   define count_leading_zeros(count, x) \
1380   __asm__ ("scan %1,0,%0"                                               \
1381            : "=r" ((USItype)(x))                                        \
1382            : "r" ((USItype)(count)))
1383 /* Early sparclites return 63 for an argument of 0, but they warn that future
1384    implementations might change this.  Therefore, leave COUNT_LEADING_ZEROS_0
1385    undefined.  */
1386 #  endif /* !__sparclite__ */
1387 # endif /* !__sparc_v8__ */
1388 /* Default to sparc v7 versions of umul_ppmm and udiv_qrnnd.  */
1389 # ifndef umul_ppmm
1390 #  define umul_ppmm(w1, w0, u, v) \
1391   __asm__ ("! Inlined umul_ppmm                                        \n" \
1392  "        wr    %%g0,%2,%%y     ! SPARC has 0-3 delay insn after a wr  \n" \
1393  "        sra   %3,31,%%g2      ! Don't move this insn                 \n" \
1394  "        and   %2,%%g2,%%g2    ! Don't move this insn                 \n" \
1395  "        andcc %%g0,0,%%g1     ! Don't move this insn                 \n" \
1396  "        mulscc        %%g1,%3,%%g1                                   \n" \
1397  "        mulscc        %%g1,%3,%%g1                                   \n" \
1398  "        mulscc        %%g1,%3,%%g1                                   \n" \
1399  "        mulscc        %%g1,%3,%%g1                                   \n" \
1400  "        mulscc        %%g1,%3,%%g1                                   \n" \
1401  "        mulscc        %%g1,%3,%%g1                                   \n" \
1402  "        mulscc        %%g1,%3,%%g1                                   \n" \
1403  "        mulscc        %%g1,%3,%%g1                                   \n" \
1404  "        mulscc        %%g1,%3,%%g1                                   \n" \
1405  "        mulscc        %%g1,%3,%%g1                                   \n" \
1406  "        mulscc        %%g1,%3,%%g1                                   \n" \
1407  "        mulscc        %%g1,%3,%%g1                                   \n" \
1408  "        mulscc        %%g1,%3,%%g1                                   \n" \
1409  "        mulscc        %%g1,%3,%%g1                                   \n" \
1410  "        mulscc        %%g1,%3,%%g1                                   \n" \
1411  "        mulscc        %%g1,%3,%%g1                                   \n" \
1412  "        mulscc        %%g1,%3,%%g1                                   \n" \
1413  "        mulscc        %%g1,%3,%%g1                                   \n" \
1414  "        mulscc        %%g1,%3,%%g1                                   \n" \
1415  "        mulscc        %%g1,%3,%%g1                                   \n" \
1416  "        mulscc        %%g1,%3,%%g1                                   \n" \
1417  "        mulscc        %%g1,%3,%%g1                                   \n" \
1418  "        mulscc        %%g1,%3,%%g1                                   \n" \
1419  "        mulscc        %%g1,%3,%%g1                                   \n" \
1420  "        mulscc        %%g1,%3,%%g1                                   \n" \
1421  "        mulscc        %%g1,%3,%%g1                                   \n" \
1422  "        mulscc        %%g1,%3,%%g1                                   \n" \
1423  "        mulscc        %%g1,%3,%%g1                                   \n" \
1424  "        mulscc        %%g1,%3,%%g1                                   \n" \
1425  "        mulscc        %%g1,%3,%%g1                                   \n" \
1426  "        mulscc        %%g1,%3,%%g1                                   \n" \
1427  "        mulscc        %%g1,%3,%%g1                                   \n" \
1428  "        mulscc        %%g1,0,%%g1                                    \n" \
1429  "        add   %%g1,%%g2,%0                                           \n" \
1430  "        rd    %%y,%1"                                                 \
1431            : "=r" ((USItype)(w1)),                                      \
1432              "=r" ((USItype)(w0))                                       \
1433            : "%rI" ((USItype)(u)),                                      \
1434              "r" ((USItype)(v))                                         \
1435            : "%g1", "%g2" __AND_CLOBBER_CC)
1436 #  define UMUL_TIME 39          /* 39 instructions */
1437 # endif /* umul_ppmm */
1438 # ifndef udiv_qrnnd
1439 #  ifndef LONGLONG_STANDALONE
1440 #   define udiv_qrnnd(q, r, n1, n0, d) \
1441   do { USItype __r;                                                     \
1442     (q) = __udiv_qrnnd (&__r, (n1), (n0), (d));                         \
1443     (r) = __r;                                                          \
1444   } while (0)
1445 extern USItype __udiv_qrnnd ();
1446 #   define UDIV_TIME 140
1447 #  endif /* LONGLONG_STANDALONE */
1448 # endif /* udiv_qrnnd */
1449 #endif /* __sparc__ */
1450
1451
1452 /***************************************
1453  **************  VAX  ******************
1454  ***************************************/
1455 #if defined (__vax__) && W_TYPE_SIZE == 32
1456 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1457   __asm__ ("addl2 %5,%1\n" \
1458            "adwc %3,%0"                                                 \
1459            : "=g" ((USItype)(sh)),                                      \
1460              "=&g" ((USItype)(sl))                                      \
1461            : "%0" ((USItype)(ah)),                                      \
1462              "g" ((USItype)(bh)),                                       \
1463              "%1" ((USItype)(al)),                                      \
1464              "g" ((USItype)(bl)))
1465 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1466   __asm__ ("subl2 %5,%1\n" \
1467            "sbwc %3,%0"                                                 \
1468            : "=g" ((USItype)(sh)),                                      \
1469              "=&g" ((USItype)(sl))                                      \
1470            : "0" ((USItype)(ah)),                                       \
1471              "g" ((USItype)(bh)),                                       \
1472              "1" ((USItype)(al)),                                       \
1473              "g" ((USItype)(bl)))
1474 # define umul_ppmm(xh, xl, m0, m1) \
1475   do {                                                                  \
1476     union {UDItype __ll;                                                \
1477            struct {USItype __l, __h;} __i;                              \
1478           } __xx;                                                       \
1479     USItype __m0 = (m0), __m1 = (m1);                                   \
1480     __asm__ ("emul %1,%2,$0,%0"                                         \
1481              : "=g" (__xx.__ll)                                         \
1482              : "g" (__m0),                                              \
1483                "g" (__m1));                                             \
1484     (xh) = __xx.__i.__h; (xl) = __xx.__i.__l;                           \
1485     (xh) += ((((SItype) __m0 >> 31) & __m1)                             \
1486              + (((SItype) __m1 >> 31) & __m0));                         \
1487   } while (0)
1488 # define sdiv_qrnnd(q, r, n1, n0, d) \
1489   do {                                                                  \
1490     union {DItype __ll;                                                 \
1491            struct {SItype __l, __h;} __i;                               \
1492           } __xx;                                                       \
1493     __xx.__i.__h = n1; __xx.__i.__l = n0;                               \
1494     __asm__ ("ediv %3,%2,%0,%1"                                         \
1495              : "=g" (q), "=g" (r)                                       \
1496              : "g" (__xx.__ll), "g" (d));                               \
1497   } while (0)
1498 #endif /* __vax__ */
1499
1500
1501 /***************************************
1502  **************  Z8000  ****************
1503  ***************************************/
1504 #if defined (__z8000__) && W_TYPE_SIZE == 16
1505 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1506   __asm__ ("add %H1,%H5\n\tadc  %H0,%H3"                                \
1507            : "=r" ((unsigned int)(sh)),                                 \
1508              "=&r" ((unsigned int)(sl))                                 \
1509            : "%0" ((unsigned int)(ah)),                                 \
1510              "r" ((unsigned int)(bh)),                                  \
1511              "%1" ((unsigned int)(al)),                                 \
1512              "rQR" ((unsigned int)(bl)))
1513 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1514   __asm__ ("sub %H1,%H5\n\tsbc  %H0,%H3"                                \
1515            : "=r" ((unsigned int)(sh)),                                 \
1516              "=&r" ((unsigned int)(sl))                                 \
1517            : "0" ((unsigned int)(ah)),                                  \
1518              "r" ((unsigned int)(bh)),                                  \
1519              "1" ((unsigned int)(al)),                                  \
1520              "rQR" ((unsigned int)(bl)))
1521 # define umul_ppmm(xh, xl, m0, m1) \
1522   do {                                                                  \
1523     union {long int __ll;                                               \
1524            struct {unsigned int __h, __l;} __i;                         \
1525           } __xx;                                                       \
1526     unsigned int __m0 = (m0), __m1 = (m1);                              \
1527     __asm__ ("mult      %S0,%H3"                                        \
1528              : "=r" (__xx.__i.__h),                                     \
1529                "=r" (__xx.__i.__l)                                      \
1530              : "%1" (__m0),                                             \
1531                "rQR" (__m1));                                           \
1532     (xh) = __xx.__i.__h; (xl) = __xx.__i.__l;                           \
1533     (xh) += ((((signed int) __m0 >> 15) & __m1)                         \
1534              + (((signed int) __m1 >> 15) & __m0));                     \
1535   } while (0)
1536 #endif /* __z8000__ */
1537
1538
1539 /***************************************
1540  *****  End CPU Specific Versions  *****
1541  ***************************************/
1542
1543 #endif /* __GNUC__ */
1544 #endif /* !__riscos__ */
1545
1546
1547 /***************************************
1548  ***********  Generic Versions  ********
1549  ***************************************/
1550 #if !defined (umul_ppmm) && defined (__umulsidi3)
1551 #  define umul_ppmm(ph, pl, m0, m1) \
1552   {                                                                     \
1553     UDWtype __ll = __umulsidi3 (m0, m1);                                \
1554     ph = (UWtype) (__ll >> W_TYPE_SIZE);                                \
1555     pl = (UWtype) __ll;                                                 \
1556   }
1557 #endif
1558
1559 #if !defined (__umulsidi3)
1560 #  define __umulsidi3(u, v) \
1561   ({UWtype __hi, __lo;                                                  \
1562     umul_ppmm (__hi, __lo, u, v);                                       \
1563     ((UDWtype) __hi << W_TYPE_SIZE) | __lo; })
1564 #endif
1565
1566 /* If this machine has no inline assembler, use C macros.  */
1567
1568 #if !defined (add_ssaaaa)
1569 #  define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1570   do {                                                                  \
1571     UWtype __x;                                                         \
1572     __x = (al) + (bl);                                                  \
1573     (sh) = (ah) + (bh) + (__x < (al));                                  \
1574     (sl) = __x;                                                         \
1575   } while (0)
1576 #endif
1577
1578 #if !defined (sub_ddmmss)
1579 #  define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1580   do {                                                                  \
1581     UWtype __x;                                                         \
1582     __x = (al) - (bl);                                                  \
1583     (sh) = (ah) - (bh) - (__x > (al));                                  \
1584     (sl) = __x;                                                         \
1585   } while (0)
1586 #endif
1587
1588 #if !defined (umul_ppmm)
1589 #  define umul_ppmm(w1, w0, u, v)                                       \
1590   do {                                                                  \
1591     UWtype __x0, __x1, __x2, __x3;                                      \
1592     UHWtype __ul, __vl, __uh, __vh;                                     \
1593     UWtype __u = (u), __v = (v);                                        \
1594                                                                         \
1595     __ul = __ll_lowpart (__u);                                          \
1596     __uh = __ll_highpart (__u);                                         \
1597     __vl = __ll_lowpart (__v);                                          \
1598     __vh = __ll_highpart (__v);                                         \
1599                                                                         \
1600     __x0 = (UWtype) __ul * __vl;                                        \
1601     __x1 = (UWtype) __ul * __vh;                                        \
1602     __x2 = (UWtype) __uh * __vl;                                        \
1603     __x3 = (UWtype) __uh * __vh;                                        \
1604                                                                         \
1605     __x1 += __ll_highpart (__x0);/* this can't give carry */            \
1606     __x1 += __x2;               /* but this indeed can */               \
1607     if (__x1 < __x2)            /* did we get it? */                    \
1608       __x3 += __ll_B;           /* yes, add it in the proper pos. */    \
1609                                                                         \
1610     (w1) = __x3 + __ll_highpart (__x1);                                 \
1611     (w0) = (__ll_lowpart (__x1) << W_TYPE_SIZE/2) + __ll_lowpart (__x0);\
1612   } while (0)
1613 #endif
1614
1615 #if !defined (umul_ppmm)
1616 #  define smul_ppmm(w1, w0, u, v)                                       \
1617   do {                                                                  \
1618     UWtype __w1;                                                        \
1619     UWtype __m0 = (u), __m1 = (v);                                      \
1620     umul_ppmm (__w1, w0, __m0, __m1);                                   \
1621     (w1) = __w1 - (-(__m0 >> (W_TYPE_SIZE - 1)) & __m1)                 \
1622                 - (-(__m1 >> (W_TYPE_SIZE - 1)) & __m0);                \
1623   } while (0)
1624 #endif
1625
1626 /* Define this unconditionally, so it can be used for debugging.  */
1627 #define __udiv_qrnnd_c(q, r, n1, n0, d) \
1628   do {                                                                  \
1629     UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m;                     \
1630     __d1 = __ll_highpart (d);                                           \
1631     __d0 = __ll_lowpart (d);                                            \
1632                                                                         \
1633     __r1 = (n1) % __d1;                                                 \
1634     __q1 = (n1) / __d1;                                                 \
1635     __m = (UWtype) __q1 * __d0;                                         \
1636     __r1 = __r1 * __ll_B | __ll_highpart (n0);                          \
1637     if (__r1 < __m)                                                     \
1638       {                                                                 \
1639         __q1--, __r1 += (d);                                            \
1640         if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
1641           if (__r1 < __m)                                               \
1642             __q1--, __r1 += (d);                                        \
1643       }                                                                 \
1644     __r1 -= __m;                                                        \
1645                                                                         \
1646     __r0 = __r1 % __d1;                                                 \
1647     __q0 = __r1 / __d1;                                                 \
1648     __m = (UWtype) __q0 * __d0;                                         \
1649     __r0 = __r0 * __ll_B | __ll_lowpart (n0);                           \
1650     if (__r0 < __m)                                                     \
1651       {                                                                 \
1652         __q0--, __r0 += (d);                                            \
1653         if (__r0 >= (d))                                                \
1654           if (__r0 < __m)                                               \
1655             __q0--, __r0 += (d);                                        \
1656       }                                                                 \
1657     __r0 -= __m;                                                        \
1658                                                                         \
1659     (q) = (UWtype) __q1 * __ll_B | __q0;                                \
1660     (r) = __r0;                                                         \
1661   } while (0)
1662
1663 /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
1664    __udiv_w_sdiv (defined in libgcc or elsewhere).  */
1665 #if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
1666 #  define udiv_qrnnd(q, r, nh, nl, d) \
1667   do {                                                                  \
1668     UWtype __r;                                                         \
1669     (q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d);                         \
1670     (r) = __r;                                                          \
1671   } while (0)
1672 #endif
1673
1674 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  */
1675 #if !defined (udiv_qrnnd)
1676 #  define UDIV_NEEDS_NORMALIZATION 1
1677 #  define udiv_qrnnd __udiv_qrnnd_c
1678 #endif
1679
1680 #if !defined (count_leading_zeros)
1681 extern
1682 #  ifdef __STDC__
1683 const
1684 #  endif
1685 unsigned char _gcry_clz_tab[];
1686 #  define MPI_INTERNAL_NEED_CLZ_TAB 1
1687 #  define count_leading_zeros(count, x) \
1688   do {                                                                  \
1689     UWtype __xr = (x);                                                  \
1690     UWtype __a;                                                         \
1691                                                                         \
1692     if (W_TYPE_SIZE <= 32)                                              \
1693       {                                                                 \
1694         __a = __xr < ((UWtype) 1 << 2*__BITS4)                          \
1695           ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4)              \
1696           : (__xr < ((UWtype) 1 << 3*__BITS4) ?  2*__BITS4 : 3*__BITS4);\
1697       }                                                                 \
1698     else                                                                \
1699       {                                                                 \
1700         for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8)                  \
1701           if (((__xr >> __a) & 0xff) != 0)                              \
1702             break;                                                      \
1703       }                                                                 \
1704                                                                         \
1705     (count) = W_TYPE_SIZE - (_gcry_clz_tab[__xr >> __a] + __a);         \
1706   } while (0)
1707 /* This version gives a well-defined value for zero. */
1708 #  define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
1709 #endif /* !count_leading_zeros */
1710
1711 #if !defined (count_trailing_zeros)
1712 /* Define count_trailing_zeros using count_leading_zeros.  The latter might be
1713    defined in asm, but if it is not, the C version above is good enough.  */
1714 #  define count_trailing_zeros(count, x) \
1715   do {                                                                  \
1716     UWtype __ctz_x = (x);                                               \
1717     UWtype __ctz_c;                                                     \
1718     count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x);                  \
1719     (count) = W_TYPE_SIZE - 1 - __ctz_c;                                \
1720   } while (0)
1721 #endif /* !count_trailing_zeros */
1722
1723 #ifndef UDIV_NEEDS_NORMALIZATION
1724 #  define UDIV_NEEDS_NORMALIZATION 0
1725 #endif
1726
1727 /***************************************
1728  ******  longlong.h ends here  *********
1729  ***************************************/