home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / superopt-2.5-src.tgz / tar.out / fsf / superopt / longlong.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  41KB  |  1,312 lines

  1. /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
  2.  
  3. Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
  4.  
  5. This file is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU Library General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or (at your
  8. option) any later version.
  9.  
  10. This file is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
  13. License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public License
  16. along with this file; see the file COPYING.LIB.  If not, write to
  17. the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  18.  
  19. /* You have to define the following before including this file:
  20.  
  21.    UWtype -- An unsigned type, default type for operations (typically a "word")
  22.    UHWtype -- An unsigned type, at least half the size of UWtype.
  23.    UDWtype -- An unsigned type, at least twice as large a UWtype
  24.    W_TYPE_SIZE -- size in bits of UWtype
  25.  
  26.    SItype, USItype -- Signed and unsigned 32 bit types.
  27.    DItype, UDItype -- Signed and unsigned 64 bit types.
  28.  
  29.    On a 32 bit machine UWtype should typically be USItype;
  30.    on a 64 bit machine, UWtype should typically be UDItype.
  31. */
  32.  
  33. #define __BITS4 (W_TYPE_SIZE / 4)
  34. #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
  35. #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
  36. #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
  37.  
  38. /* Define auxiliary asm macros.
  39.  
  40.    1) umul_ppmm(high_prod, low_prod, multipler, multiplicand) multiplies two
  41.    UWtype integers MULTIPLER and MULTIPLICAND, and generates a two UWtype
  42.    word product in HIGH_PROD and LOW_PROD.
  43.  
  44.    2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a
  45.    UDWtype product.  This is just a variant of umul_ppmm.
  46.  
  47.    3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
  48.    denominator) divides a UDWtype, composed by the UWtype integers
  49.    HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
  50.    in QUOTIENT and the remainder in REMAINDER.  HIGH_NUMERATOR must be less
  51.    than DENOMINATOR for correct operation.  If, in addition, the most
  52.    significant bit of DENOMINATOR must be 1, then the pre-processor symbol
  53.    UDIV_NEEDS_NORMALIZATION is defined to 1.
  54.  
  55.    4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
  56.    denominator).  Like udiv_qrnnd but the numbers are signed.  The quotient
  57.    is rounded towards 0.
  58.  
  59.    5) count_leading_zeros(count, x) counts the number of zero-bits from the
  60.    msb to the first non-zero bit in the UWtype X.  This is the number of
  61.    steps X needs to be shifted left to set the msb.  Undefined for X == 0,
  62.    unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.
  63.  
  64.    6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
  65.    from the least significant end.
  66.  
  67.    7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
  68.    high_addend_2, low_addend_2) adds two UWtype integers, composed by
  69.    HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2
  70.    respectively.  The result is placed in HIGH_SUM and LOW_SUM.  Overflow
  71.    (i.e. carry out) is not stored anywhere, and is lost.
  72.  
  73.    8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend,
  74.    high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers,
  75.    composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and
  76.    LOW_SUBTRAHEND_2 respectively.  The result is placed in HIGH_DIFFERENCE
  77.    and LOW_DIFFERENCE.  Overflow (i.e. carry out) is not stored anywhere,
  78.    and is lost.
  79.  
  80.    If any of these macros are left undefined for a particular CPU,
  81.    C macros are used.  */
  82.  
  83. /* The CPUs come in alphabetical order below.
  84.  
  85.    Please add support for more CPUs here, or improve the current support
  86.    for the CPUs below!  */
  87.  
  88. #if defined (__GNUC__) && !defined (NO_ASM)
  89.  
  90. /* We sometimes need to clobber "cc" with gcc2, but that would not be
  91.    understood by gcc1.  Use cpp to avoid major code duplication.  */
  92. #if __GNUC__ < 2
  93. #define __CLOBBER_CC
  94. #define __AND_CLOBBER_CC
  95. #else /* __GNUC__ >= 2 */
  96. #define __CLOBBER_CC : "cc"
  97. #define __AND_CLOBBER_CC , "cc"
  98. #endif /* __GNUC__ < 2 */
  99.  
  100. #if (defined (__a29k__) || defined (_AM29K)) && W_TYPE_SIZE == 32
  101. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  102.   __asm__ ("add %1,%4,%5
  103.     addc %0,%2,%3"                            \
  104.        : "=r" ((USItype)(sh)),                    \
  105.         "=&r" ((USItype)(sl))                    \
  106.        : "%r" ((USItype)(ah)),                    \
  107.          "rI" ((USItype)(bh)),                    \
  108.          "%r" ((USItype)(al)),                    \
  109.          "rI" ((USItype)(bl)))
  110. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  111.   __asm__ ("sub %1,%4,%5
  112.     subc %0,%2,%3"                            \
  113.        : "=r" ((USItype)(sh)),                    \
  114.          "=&r" ((USItype)(sl))                    \
  115.        : "r" ((USItype)(ah)),                    \
  116.          "rI" ((USItype)(bh)),                    \
  117.          "r" ((USItype)(al)),                    \
  118.          "rI" ((USItype)(bl)))
  119. #define umul_ppmm(xh, xl, m0, m1) \
  120.   do {                                    \
  121.     USItype __m0 = (m0), __m1 = (m1);                    \
  122.     __asm__ ("multiplu %0,%1,%2"                    \
  123.          : "=r" ((USItype)(xl))                    \
  124.          : "r" (__m0),                        \
  125.            "r" (__m1));                        \
  126.     __asm__ ("multmu %0,%1,%2"                        \
  127.          : "=r" ((USItype)(xh))                    \
  128.          : "r" (__m0),                        \
  129.            "r" (__m1));                        \
  130.   } while (0)
  131. #define udiv_qrnnd(q, r, n1, n0, d) \
  132.   __asm__ ("dividu %0,%3,%4"                        \
  133.        : "=r" ((USItype)(q)),                    \
  134.          "=q" ((USItype)(r))                    \
  135.        : "1" ((USItype)(n1)),                    \
  136.          "r" ((USItype)(n0)),                    \
  137.          "r" ((USItype)(d)))
  138. #define count_leading_zeros(count, x) \
  139.     __asm__ ("clz %0,%1"                        \
  140.          : "=r" ((USItype)(count))                    \
  141.          : "r" ((USItype)(x)))
  142. #endif /* __a29k__ */
  143.  
  144. #if defined (__alpha__) && W_TYPE_SIZE == 64
  145. #define umul_ppmm(ph, pl, m0, m1) \
  146.   do {                                    \
  147.     UDItype __m0 = (m0), __m1 = (m1);                    \
  148.     __asm__ ("umulh %r1,%2,%0"                        \
  149.          : "=r" ((UDItype) ph)                    \
  150.          : "%rJ" (__m0),                        \
  151.            "rI" (__m1));                        \
  152.     (pl) = __m0 * __m1;                            \
  153.   } while (0)
  154. #define UMUL_TIME 46
  155. #ifndef LONGLONG_STANDALONE
  156. #define udiv_qrnnd(q, r, n1, n0, d) \
  157.   do { UDItype __r;                            \
  158.     (q) = __udiv_qrnnd (&__r, (n1), (n0), (d));                \
  159.     (r) = __r;                                \
  160.   } while (0)
  161. extern UDItype __udiv_qrnnd ();
  162. #define UDIV_TIME 220
  163. #endif /* LONGLONG_STANDALONE */
  164. #endif /* __alpha__ */
  165.  
  166. #if defined (__arm__) && W_TYPE_SIZE == 32
  167. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  168.   __asm__ ("adds    %1, %4, %5
  169.     adc    %0, %2, %3"                        \
  170.        : "=r" ((USItype)(sh)),                    \
  171.          "=&r" ((USItype)(sl))                    \
  172.        : "%r" ((USItype)(ah)),                    \
  173.          "rI" ((USItype)(bh)),                    \
  174.          "%r" ((USItype)(al)),                    \
  175.          "rI" ((USItype)(bl)))
  176. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  177.   __asm__ ("subs    %1, %4, %5
  178.     sbc    %0, %2, %3"                        \
  179.        : "=r" ((USItype)(sh)),                    \
  180.          "=&r" ((USItype)(sl))                    \
  181.        : "r" ((USItype)(ah)),                    \
  182.          "rI" ((USItype)(bh)),                    \
  183.          "r" ((USItype)(al)),                    \
  184.          "rI" ((USItype)(bl)))
  185. #define umul_ppmm(xh, xl, a, b) \
  186.   __asm__ ("%@ Inlined umul_ppmm
  187.     mov    %|r0, %2, lsr #16
  188.     mov    %|r2, %3, lsr #16
  189.     bic    %|r1, %2, %|r0, lsl #16
  190.     bic    %|r2, %3, %|r2, lsl #16
  191.     mul    %1, %|r1, %|r2
  192.     mul    %|r2, %|r0, %|r2
  193.     mul    %|r1, %0, %|r1
  194.     mul    %0, %|r0, %0
  195.     adds    %|r1, %|r2, %|r1
  196.     addcs    %0, %0, #65536
  197.     adds    %1, %1, %|r1, lsl #16
  198.     adc    %0, %0, %|r1, lsr #16"                    \
  199.        : "=&r" ((USItype)(xh)),                    \
  200.          "=r" ((USItype)(xl))                    \
  201.        : "r" ((USItype)(a)),                    \
  202.          "r" ((USItype)(b))                        \
  203.        : "r0", "r1", "r2")
  204. #define UMUL_TIME 20
  205. #define UDIV_TIME 100
  206. #endif /* __arm__ */
  207.  
  208. #if defined (__clipper__) && W_TYPE_SIZE == 32
  209. #define umul_ppmm(w1, w0, u, v) \
  210.   ({union {UDItype __ll;                        \
  211.        struct {USItype __l, __h;} __i;                \
  212.       } __xx;                            \
  213.   __asm__ ("mulwux %2,%0"                        \
  214.        : "=r" (__xx.__ll)                        \
  215.        : "%0" ((USItype)(u)),                    \
  216.          "r" ((USItype)(v)));                    \
  217.   (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
  218. #define smul_ppmm(w1, w0, u, v) \
  219.   ({union {DItype __ll;                            \
  220.        struct {SItype __l, __h;} __i;                \
  221.       } __xx;                            \
  222.   __asm__ ("mulwx %2,%0"                        \
  223.        : "=r" (__xx.__ll)                        \
  224.        : "%0" ((SItype)(u)),                    \
  225.          "r" ((SItype)(v)));                    \
  226.   (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
  227. #define __umulsidi3(u, v) \
  228.   ({UDItype __w;                            \
  229.     __asm__ ("mulwux %2,%0"                        \
  230.          : "=r" (__w)                        \
  231.          : "%0" ((USItype)(u)),                    \
  232.            "r" ((USItype)(v)));                    \
  233.     __w; })
  234. #endif /* __clipper__ */
  235.  
  236. #if defined (__gmicro__) && W_TYPE_SIZE == 32
  237. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  238.   __asm__ ("add.w %5,%1
  239.     addx %3,%0"                            \
  240.        : "=g" ((USItype)(sh)),                    \
  241.          "=&g" ((USItype)(sl))                    \
  242.        : "%0" ((USItype)(ah)),                    \
  243.          "g" ((USItype)(bh)),                    \
  244.          "%1" ((USItype)(al)),                    \
  245.          "g" ((USItype)(bl)))
  246. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  247.   __asm__ ("sub.w %5,%1
  248.     subx %3,%0"                            \
  249.        : "=g" ((USItype)(sh)),                    \
  250.          "=&g" ((USItype)(sl))                    \
  251.        : "0" ((USItype)(ah)),                    \
  252.          "g" ((USItype)(bh)),                    \
  253.          "1" ((USItype)(al)),                    \
  254.          "g" ((USItype)(bl)))
  255. #define umul_ppmm(ph, pl, m0, m1) \
  256.   __asm__ ("mulx %3,%0,%1"                        \
  257.        : "=g" ((USItype)(ph)),                    \
  258.          "=r" ((USItype)(pl))                    \
  259.        : "%0" ((USItype)(m0)),                    \
  260.          "g" ((USItype)(m1)))
  261. #define udiv_qrnnd(q, r, nh, nl, d) \
  262.   __asm__ ("divx %4,%0,%1"                        \
  263.        : "=g" ((USItype)(q)),                    \
  264.          "=r" ((USItype)(r))                    \
  265.        : "1" ((USItype)(nh)),                    \
  266.          "0" ((USItype)(nl)),                    \
  267.          "g" ((USItype)(d)))
  268. #define count_leading_zeros(count, x) \
  269.   __asm__ ("bsch/1 %1,%0"                        \
  270.        : "=g" (count)                        \
  271.        : "g" ((USItype)(x)),                    \
  272.          "0" ((USItype)0))
  273. #endif
  274.  
  275. #if defined (__hppa) && W_TYPE_SIZE == 32
  276. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  277.   __asm__ ("add %4,%5,%1
  278.     addc %2,%3,%0"                            \
  279.        : "=r" ((USItype)(sh)),                    \
  280.          "=&r" ((USItype)(sl))                    \
  281.        : "%rM" ((USItype)(ah)),                    \
  282.          "rM" ((USItype)(bh)),                    \
  283.          "%rM" ((USItype)(al)),                    \
  284.          "rM" ((USItype)(bl)))
  285. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  286.   __asm__ ("sub %4,%5,%1
  287.     subb %2,%3,%0"                            \
  288.        : "=r" ((USItype)(sh)),                    \
  289.          "=&r" ((USItype)(sl))                    \
  290.        : "rM" ((USItype)(ah)),                    \
  291.          "rM" ((USItype)(bh)),                    \
  292.          "rM" ((USItype)(al)),                    \
  293.          "rM" ((USItype)(bl)))
  294. #if defined (_PA_RISC1_1)
  295. #define umul_ppmm(wh, wl, u, v) \
  296.   do {                                    \
  297.     union {UDItype __ll;                        \
  298.        struct {USItype __h, __l;} __i;                \
  299.       } __xx;                            \
  300.     __asm__ ("xmpyu %1,%2,%0"                        \
  301.          : "=fx" (__xx.__ll)                    \
  302.          : "fx" ((USItype)(u)),                    \
  303.            "fx" ((USItype)(v)));                    \
  304.     (wh) = __xx.__i.__h;                        \
  305.     (wl) = __xx.__i.__l;                        \
  306.   } while (0)
  307. #define UMUL_TIME 8
  308. #define UDIV_TIME 60
  309. #else
  310. #define UMUL_TIME 40
  311. #define UDIV_TIME 80
  312. #endif
  313. #ifndef LONGLONG_STANDALONE
  314. #define udiv_qrnnd(q, r, n1, n0, d) \
  315.   do { USItype __r;                            \
  316.     (q) = __udiv_qrnnd (&__r, (n1), (n0), (d));                \
  317.     (r) = __r;                                \
  318.   } while (0)
  319. extern USItype __udiv_qrnnd ();
  320. #endif /* LONGLONG_STANDALONE */
  321. #define count_leading_zeros(count, x) \
  322.   do {                                    \
  323.     USItype __tmp;                            \
  324.     __asm__ (                                \
  325.        "ldi        1,%0
  326.     extru,=        %1,15,16,%%r0        ; Bits 31..16 zero?
  327.     extru,tr    %1,15,16,%1        ; No.  Shift down, skip add.
  328.     ldo        16(%0),%0        ; Yes.  Perform add.
  329.     extru,=        %1,23,8,%%r0        ; Bits 15..8 zero?
  330.     extru,tr    %1,23,8,%1        ; No.  Shift down, skip add.
  331.     ldo        8(%0),%0        ; Yes.  Perform add.
  332.     extru,=        %1,27,4,%%r0        ; Bits 7..4 zero?
  333.     extru,tr    %1,27,4,%1        ; No.  Shift down, skip add.
  334.     ldo        4(%0),%0        ; Yes.  Perform add.
  335.     extru,=        %1,29,2,%%r0        ; Bits 3..2 zero?
  336.     extru,tr    %1,29,2,%1        ; No.  Shift down, skip add.
  337.     ldo        2(%0),%0        ; Yes.  Perform add.
  338.     extru        %1,30,1,%1        ; Extract bit 1.
  339.     sub        %0,%1,%0        ; Subtract it.
  340.     " : "=r" (count), "=r" (__tmp) : "1" (x));            \
  341.   } while (0)
  342. #endif
  343.  
  344. #if (defined (__i370__) || defined (__mvs__)) && W_TYPE_SIZE == 32
  345. #define umul_ppmm(xh, xl, m0, m1) \
  346.   do {                                    \
  347.     union {UDItype __ll;                        \
  348.        struct {USItype __h, __l;} __i;                \
  349.       } __xx;                            \
  350.     USItype __m0 = (m0), __m1 = (m1);                    \
  351.     __asm__ ("mr %0,%3"                            \
  352.          : "=r" (__xx.__i.__h),                    \
  353.            "=r" (__xx.__i.__l)                    \
  354.          : "%1" (__m0),                        \
  355.            "r" (__m1));                        \
  356.     (xh) = __xx.__i.__h; (xl) = __xx.__i.__l;                \
  357.     (xh) += ((((SItype) __m0 >> 31) & __m1)                \
  358.          + (((SItype) __m1 >> 31) & __m0));                \
  359.   } while (0)
  360. #define smul_ppmm(xh, xl, m0, m1) \
  361.   do {                                    \
  362.     union {DItype __ll;                            \
  363.        struct {USItype __h, __l;} __i;                \
  364.       } __xx;                            \
  365.     __asm__ ("mr %0,%3"                            \
  366.          : "=r" (__xx.__i.__h),                    \
  367.            "=r" (__xx.__i.__l)                    \
  368.          : "%1" (m0),                        \
  369.            "r" (m1));                        \
  370.     (xh) = __xx.__i.__h; (xl) = __xx.__i.__l;                \
  371.   } while (0)
  372. #define sdiv_qrnnd(q, r, n1, n0, d) \
  373.   do {                                    \
  374.     union {DItype __ll;                            \
  375.        struct {USItype __h, __l;} __i;                \
  376.       } __xx;                            \
  377.     __xx.__i.__h = n1; __xx.__i.__l = n0;                \
  378.     __asm__ ("dr %0,%2"                            \
  379.          : "=r" (__xx.__ll)                        \
  380.          : "0" (__xx.__ll), "r" (d));                \
  381.     (q) = __xx.__i.__l; (r) = __xx.__i.__h;                \
  382.   } while (0)
  383. #endif
  384.  
  385. #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
  386. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  387.   __asm__ ("addl %5,%1
  388.     adcl %3,%0"                            \
  389.        : "=r" ((USItype)(sh)),                    \
  390.          "=&r" ((USItype)(sl))                    \
  391.        : "%0" ((USItype)(ah)),                    \
  392.          "g" ((USItype)(bh)),                    \
  393.          "%1" ((USItype)(al)),                    \
  394.          "g" ((USItype)(bl)))
  395. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  396.   __asm__ ("subl %5,%1
  397.     sbbl %3,%0"                            \
  398.        : "=r" ((USItype)(sh)),                    \
  399.          "=&r" ((USItype)(sl))                    \
  400.        : "0" ((USItype)(ah)),                    \
  401.          "g" ((USItype)(bh)),                    \
  402.          "1" ((USItype)(al)),                    \
  403.          "g" ((USItype)(bl)))
  404. #define umul_ppmm(w1, w0, u, v) \
  405.   __asm__ ("mull %3"                            \
  406.        : "=a" ((USItype)(w0)),                    \
  407.          "=d" ((USItype)(w1))                    \
  408.        : "%0" ((USItype)(u)),                    \
  409.          "rm" ((USItype)(v)))
  410. #define udiv_qrnnd(q, r, n1, n0, d) \
  411.   __asm__ ("divl %4"                            \
  412.        : "=a" ((USItype)(q)),                    \
  413.          "=d" ((USItype)(r))                    \
  414.        : "0" ((USItype)(n0)),                    \
  415.          "1" ((USItype)(n1)),                    \
  416.          "rm" ((USItype)(d)))
  417. #define count_leading_zeros(count, x) \
  418.   do {                                    \
  419.     USItype __cbtmp;                            \
  420.     __asm__ ("bsrl %1,%0"                        \
  421.          : "=r" (__cbtmp) : "rm" ((USItype)(x)));            \
  422.     (count) = __cbtmp ^ 31;                        \
  423.   } while (0)
  424. #define count_trailing_zeros(count, x) \
  425.   __asm__ ("bsfl %1,%0" : "=r" (count) : "rm" ((USItype)(x)))
  426. #define UMUL_TIME 40
  427. #define UDIV_TIME 40
  428. #endif /* 80x86 */
  429.  
  430. #if defined (__i960__) && W_TYPE_SIZE == 32
  431. #define umul_ppmm(w1, w0, u, v) \
  432.   ({union {UDItype __ll;                        \
  433.        struct {USItype __l, __h;} __i;                \
  434.       } __xx;                            \
  435.   __asm__ ("emul    %2,%1,%0"                    \
  436.        : "=d" (__xx.__ll)                        \
  437.        : "%dI" ((USItype)(u)),                    \
  438.          "dI" ((USItype)(v)));                    \
  439.   (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
  440. #define __umulsidi3(u, v) \
  441.   ({UDItype __w;                            \
  442.     __asm__ ("emul    %2,%1,%0"                    \
  443.          : "=d" (__w)                        \
  444.          : "%dI" ((USItype)(u)),                    \
  445.            "dI" ((USItype)(v)));                    \
  446.     __w; })  
  447. #endif /* __i960__ */
  448.  
  449. #if (defined (__mc68000__) || defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) && W_TYPE_SIZE == 32
  450. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  451.   __asm__ ("add%.l %5,%1
  452.     addx%.l %3,%0"                            \
  453.        : "=d" ((USItype)(sh)),                    \
  454.          "=&d" ((USItype)(sl))                    \
  455.        : "%0" ((USItype)(ah)),                    \
  456.          "d" ((USItype)(bh)),                    \
  457.          "%1" ((USItype)(al)),                    \
  458.          "g" ((USItype)(bl)))
  459. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  460.   __asm__ ("sub%.l %5,%1
  461.     subx%.l %3,%0"                            \
  462.        : "=d" ((USItype)(sh)),                    \
  463.          "=&d" ((USItype)(sl))                    \
  464.        : "0" ((USItype)(ah)),                    \
  465.          "d" ((USItype)(bh)),                    \
  466.          "1" ((USItype)(al)),                    \
  467.          "g" ((USItype)(bl)))
  468. #if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) && W_TYPE_SIZE == 32
  469. #define umul_ppmm(w1, w0, u, v) \
  470.   __asm__ ("mulu%.l %3,%1:%0"                        \
  471.        : "=d" ((USItype)(w0)),                    \
  472.          "=d" ((USItype)(w1))                    \
  473.        : "%0" ((USItype)(u)),                    \
  474.          "dmi" ((USItype)(v)))
  475. #define UMUL_TIME 45
  476. #define udiv_qrnnd(q, r, n1, n0, d) \
  477.   __asm__ ("divu%.l %4,%1:%0"                        \
  478.        : "=d" ((USItype)(q)),                    \
  479.          "=d" ((USItype)(r))                    \
  480.        : "0" ((USItype)(n0)),                    \
  481.          "1" ((USItype)(n1)),                    \
  482.          "dmi" ((USItype)(d)))
  483. #define UDIV_TIME 90
  484. #define sdiv_qrnnd(q, r, n1, n0, d) \
  485.   __asm__ ("divs%.l %4,%1:%0"                        \
  486.        : "=d" ((USItype)(q)),                    \
  487.          "=d" ((USItype)(r))                    \
  488.        : "0" ((USItype)(n0)),                    \
  489.          "1" ((USItype)(n1)),                    \
  490.          "dmi" ((USItype)(d)))
  491. #define count_leading_zeros(count, x) \
  492.   __asm__ ("bfffo %1{%b2:%b2},%0"                    \
  493.        : "=d" ((USItype)(count))                    \
  494.        : "od" ((USItype)(x)), "n" (0))
  495. #else /* not mc68020 */
  496. #define umul_ppmmxx(xh, xl, a, b) \
  497.   do { USItype __umul_tmp1, __umul_tmp2;                \
  498.     __asm__ ("| Inlined umul_ppmm
  499.     move%.l    %5,%3
  500.     move%.l    %2,%0
  501.     move%.w    %3,%1
  502.     swap    %3
  503.     swap    %0
  504.     mulu    %2,%1
  505.     mulu    %3,%0
  506.     mulu    %2,%3
  507.     swap    %2
  508.     mulu    %5,%2
  509.     add%.l    %3,%2
  510.     jcc    1f
  511.     add%.l    #0x10000,%0
  512. 1:    move%.l    %2,%3
  513.     clr%.w    %2
  514.     swap    %2
  515.     swap    %3
  516.     clr%.w    %3
  517.     add%.l    %3,%1
  518.     addx%.l    %2,%0
  519.     | End inlined umul_ppmm"                    \
  520.           : "=&d" ((USItype)(xh)), "=&d" ((USItype)(xl)),        \
  521.             "=d" (__umul_tmp1), "=&d" (__umul_tmp2)            \
  522.           : "%2" ((USItype)(a)), "d" ((USItype)(b)));        \
  523.   } while (0)
  524. #define UMUL_TIME 100
  525. #define UDIV_TIME 400
  526. #endif /* not mc68020 */
  527. #endif /* mc68000 */
  528.  
  529. #if defined (__m88000__) && W_TYPE_SIZE == 32
  530. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  531.   __asm__ ("addu.co %1,%r4,%r5
  532.     addu.ci %0,%r2,%r3"                        \
  533.        : "=r" ((USItype)(sh)),                    \
  534.          "=&r" ((USItype)(sl))                    \
  535.        : "%rJ" ((USItype)(ah)),                    \
  536.          "rJ" ((USItype)(bh)),                    \
  537.          "%rJ" ((USItype)(al)),                    \
  538.          "rJ" ((USItype)(bl)))
  539. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  540.   __asm__ ("subu.co %1,%r4,%r5
  541.     subu.ci %0,%r2,%r3"                        \
  542.        : "=r" ((USItype)(sh)),                    \
  543.          "=&r" ((USItype)(sl))                    \
  544.        : "rJ" ((USItype)(ah)),                    \
  545.          "rJ" ((USItype)(bh)),                    \
  546.          "rJ" ((USItype)(al)),                    \
  547.          "rJ" ((USItype)(bl)))
  548. #define count_leading_zeros(count, x) \
  549.   do {                                    \
  550.     USItype __cbtmp;                            \
  551.     __asm__ ("ff1 %0,%1"                        \
  552.          : "=r" (__cbtmp)                        \
  553.          : "r" ((USItype)(x)));                    \
  554.     (count) = __cbtmp ^ 31;                        \
  555.   } while (0)
  556. #if defined (__mc88110__)
  557. #define umul_ppmm(wh, wl, u, v) \
  558.   do {                                    \
  559.     union {UDItype __ll;                        \
  560.        struct {USItype __h, __l;} __i;                \
  561.       } __xx;                            \
  562.     __asm__ ("mulu.d    %0,%1,%2"                    \
  563.          : "=r" (__xx.__ll)                        \
  564.          : "r" ((USItype)(u)),                    \
  565.            "r" ((USItype)(v)));                    \
  566.     (wh) = __xx.__i.__h;                        \
  567.     (wl) = __xx.__i.__l;                        \
  568.   } while (0)
  569. #define udiv_qrnnd(q, r, n1, n0, d) \
  570.   ({union {UDItype __ll;                        \
  571.        struct {USItype __h, __l;} __i;                \
  572.       } __xx;                            \
  573.   USItype __q;                                \
  574.   __xx.__i.__h = (n1); __xx.__i.__l = (n0);                \
  575.   __asm__ ("divu.d %0,%1,%2"                        \
  576.        : "=r" (__q)                            \
  577.        : "r" (__xx.__ll),                        \
  578.          "r" ((USItype)(d)));                    \
  579.   (r) = (n0) - __q * (d); (q) = __q; })
  580. #define UMUL_TIME 5
  581. #define UDIV_TIME 25
  582. #else
  583. #define UMUL_TIME 17
  584. #define UDIV_TIME 150
  585. #endif /* __mc88110__ */
  586. #endif /* __m88000__ */
  587.  
  588. #if defined (__mips__) && W_TYPE_SIZE == 32
  589. #define umul_ppmm(w1, w0, u, v) \
  590.   __asm__ ("multu %2,%3
  591.     mflo %0
  592.     mfhi %1"                            \
  593.        : "=d" ((USItype)(w0)),                    \
  594.          "=d" ((USItype)(w1))                    \
  595.        : "d" ((USItype)(u)),                    \
  596.          "d" ((USItype)(v)))
  597. #define UMUL_TIME 10
  598. #define UDIV_TIME 100
  599. #endif /* __mips__ */
  600.  
  601. #if (defined (__mips) && __mips >= 3) && W_TYPE_SIZE == 64
  602. #define umul_ppmm(w1, w0, u, v) \
  603.   __asm__ ("dmultu %2,%3
  604.     mflo %0
  605.     mfhi %1"                            \
  606.        : "=d" ((UDItype)(w0)),                    \
  607.          "=d" ((UDItype)(w1))                    \
  608.        : "d" ((UDItype)(u)),                    \
  609.          "d" ((UDItype)(v)))
  610. #define UMUL_TIME 10
  611. #define UDIV_TIME 100
  612. #endif /* __mips__ */
  613.  
  614. #if defined (__ns32000__) && W_TYPE_SIZE == 32
  615. #define umul_ppmm(w1, w0, u, v) \
  616.   ({union {UDItype __ll;                        \
  617.        struct {USItype __l, __h;} __i;                \
  618.       } __xx;                            \
  619.   __asm__ ("meid %2,%0"                            \
  620.        : "=g" (__xx.__ll)                        \
  621.        : "%0" ((USItype)(u)),                    \
  622.          "g" ((USItype)(v)));                    \
  623.   (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
  624. #define __umulsidi3(u, v) \
  625.   ({UDItype __w;                            \
  626.     __asm__ ("meid %2,%0"                        \
  627.          : "=g" (__w)                        \
  628.          : "%0" ((USItype)(u)),                    \
  629.            "g" ((USItype)(v)));                    \
  630.     __w; })
  631. #define udiv_qrnnd(q, r, n1, n0, d) \
  632.   ({union {UDItype __ll;                        \
  633.        struct {USItype __l, __h;} __i;                \
  634.       } __xx;                            \
  635.   __xx.__i.__h = (n1); __xx.__i.__l = (n0);                \
  636.   __asm__ ("deid %2,%0"                            \
  637.        : "=g" (__xx.__ll)                        \
  638.        : "0" (__xx.__ll),                        \
  639.          "g" ((USItype)(d)));                    \
  640.   (r) = __xx.__i.__l; (q) = __xx.__i.__h; })
  641. #define count_trailing_zeros(count,x) \
  642.   do {
  643.     __asm__ ("ffsd    %2,%0"                        \
  644.          : "=r" ((USItype) (count))                    \
  645.          : "0" ((USItype) 0),                    \
  646.            "r" ((USItype) (x)));                    \
  647.   } while (0)
  648. #endif /* __ns32000__ */
  649.  
  650. #if (defined (_ARCH_PPC) || defined (_IBMR2)) && W_TYPE_SIZE == 32
  651. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  652.   do {                                    \
  653.     if (__builtin_constant_p (bh) && (bh) == 0)                \
  654.       __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2"        \
  655.          : "=r" ((USItype)(sh)),                    \
  656.            "=&r" ((USItype)(sl))                    \
  657.          : "%r" ((USItype)(ah)),                    \
  658.            "%r" ((USItype)(al)),                    \
  659.            "rI" ((USItype)(bl)));                    \
  660.     else if (__builtin_constant_p (bh) && (bh) ==~(USItype) 0)        \
  661.       __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2"        \
  662.          : "=r" ((USItype)(sh)),                    \
  663.            "=&r" ((USItype)(sl))                    \
  664.          : "%r" ((USItype)(ah)),                    \
  665.            "%r" ((USItype)(al)),                    \
  666.            "rI" ((USItype)(bl)));                    \
  667.     else                                \
  668.       __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3"        \
  669.          : "=r" ((USItype)(sh)),                    \
  670.            "=&r" ((USItype)(sl))                    \
  671.          : "%r" ((USItype)(ah)),                    \
  672.            "r" ((USItype)(bh)),                    \
  673.            "%r" ((USItype)(al)),                    \
  674.            "rI" ((USItype)(bl)));                    \
  675.   } while (0)
  676. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  677.   do {                                    \
  678.     if (__builtin_constant_p (ah) && (ah) == 0)                \
  679.       __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2"    \
  680.            : "=r" ((USItype)(sh)),                    \
  681.          "=&r" ((USItype)(sl))                    \
  682.            : "r" ((USItype)(bh)),                    \
  683.          "rI" ((USItype)(al)),                    \
  684.          "r" ((USItype)(bl)));                    \
  685.     else if (__builtin_constant_p (ah) && (ah) ==~(USItype) 0)        \
  686.       __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2"    \
  687.            : "=r" ((USItype)(sh)),                    \
  688.          "=&r" ((USItype)(sl))                    \
  689.            : "r" ((USItype)(bh)),                    \
  690.          "rI" ((USItype)(al)),                    \
  691.          "r" ((USItype)(bl)));                    \
  692.     else if (__builtin_constant_p (bh) && (bh) == 0)            \
  693.       __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2"        \
  694.            : "=r" ((USItype)(sh)),                    \
  695.          "=&r" ((USItype)(sl))                    \
  696.            : "r" ((USItype)(ah)),                    \
  697.          "rI" ((USItype)(al)),                    \
  698.          "r" ((USItype)(bl)));                    \
  699.     else if (__builtin_constant_p (bh) && (bh) ==~(USItype) 0)        \
  700.       __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2"        \
  701.            : "=r" ((USItype)(sh)),                    \
  702.          "=&r" ((USItype)(sl))                    \
  703.            : "r" ((USItype)(ah)),                    \
  704.          "rI" ((USItype)(al)),                    \
  705.          "r" ((USItype)(bl)));                    \
  706.     else                                \
  707.       __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2"    \
  708.            : "=r" ((USItype)(sh)),                    \
  709.          "=&r" ((USItype)(sl))                    \
  710.            : "r" ((USItype)(ah)),                    \
  711.          "r" ((USItype)(bh)),                    \
  712.          "rI" ((USItype)(al)),                    \
  713.          "r" ((USItype)(bl)));                    \
  714.   } while (0)
  715. #define count_leading_zeros(count, x) \
  716.   __asm__ ("{cntlz|cntlzw} %0,%1"                    \
  717.        : "=r" ((USItype)(count))                    \
  718.        : "r" ((USItype)(x)))
  719. #if defined (_ARCH_PPC)
  720. #define umul_ppmm(ph, pl, m0, m1) \
  721.   do {                                    \
  722.     USItype __m0 = (m0), __m1 = (m1);                    \
  723.     __asm__ ("mulhwu %0,%1,%2"                        \
  724.          : "=r" ((USItype) ph)                    \
  725.          : "%r" (__m0),                        \
  726.            "r" (__m1));                        \
  727.     (pl) = __m0 * __m1;                            \
  728.   } while (0)
  729. #define UMUL_TIME 15
  730. #define smul_ppmm(ph, pl, m0, m1) \
  731.   do {                                    \
  732.     SItype __m0 = (m0), __m1 = (m1);                    \
  733.     __asm__ ("mulhw %0,%1,%2"                        \
  734.          : "=r" ((SItype) ph)                    \
  735.          : "%r" (__m0),                        \
  736.            "r" (__m1));                        \
  737.     (pl) = __m0 * __m1;                            \
  738.   } while (0)
  739. #define SMUL_TIME 14
  740. #define UDIV_TIME 120
  741. #else
  742. #define umul_ppmm(xh, xl, m0, m1) \
  743.   do {                                    \
  744.     USItype __m0 = (m0), __m1 = (m1);                    \
  745.     __asm__ ("mul %0,%2,%3"                        \
  746.          : "=r" ((USItype)(xh)),                    \
  747.            "=q" ((USItype)(xl))                    \
  748.          : "r" (__m0),                        \
  749.            "r" (__m1));                        \
  750.     (xh) += ((((SItype) __m0 >> 31) & __m1)                \
  751.          + (((SItype) __m1 >> 31) & __m0));                \
  752.   } while (0)
  753. #define UMUL_TIME 8
  754. #define smul_ppmm(xh, xl, m0, m1) \
  755.   __asm__ ("mul %0,%2,%3"                        \
  756.        : "=r" ((SItype)(xh)),                    \
  757.          "=q" ((SItype)(xl))                    \
  758.        : "r" (m0),                            \
  759.          "r" (m1))
  760. #define SMUL_TIME 4
  761. #define sdiv_qrnnd(q, r, nh, nl, d) \
  762.   __asm__ ("div %0,%2,%4"                        \
  763.        : "=r" ((SItype)(q)), "=q" ((SItype)(r))            \
  764.        : "r" ((SItype)(nh)), "1" ((SItype)(nl)), "r" ((SItype)(d)))
  765. #define UDIV_TIME 100
  766. #endif
  767. #endif /* Power architecture variants.  */
  768.  
  769. #if defined (__pyr__) && W_TYPE_SIZE == 32
  770. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  771.   __asm__ ("addw    %5,%1
  772.     addwc    %3,%0"                            \
  773.        : "=r" ((USItype)(sh)),                    \
  774.          "=&r" ((USItype)(sl))                    \
  775.        : "%0" ((USItype)(ah)),                    \
  776.          "g" ((USItype)(bh)),                    \
  777.          "%1" ((USItype)(al)),                    \
  778.          "g" ((USItype)(bl)))
  779. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  780.   __asm__ ("subw    %5,%1
  781.     subwb    %3,%0"                            \
  782.        : "=r" ((USItype)(sh)),                    \
  783.          "=&r" ((USItype)(sl))                    \
  784.        : "0" ((USItype)(ah)),                    \
  785.          "g" ((USItype)(bh)),                    \
  786.          "1" ((USItype)(al)),                    \
  787.          "g" ((USItype)(bl)))
  788. /* This insn doesn't work on ancient pyramids.  */
  789. #define umul_ppmm(w1, w0, u, v) \
  790.   ({union {UDItype __ll;                        \
  791.        struct {USItype __h, __l;} __i;                \
  792.       } __xx;                            \
  793.   __xx.__i.__l = u;                            \
  794.   __asm__ ("uemul %3,%0"                        \
  795.        : "=r" (__xx.__i.__h),                    \
  796.          "=r" (__xx.__i.__l)                    \
  797.        : "1" (__xx.__i.__l),                    \
  798.          "g" ((USItype)(v)));                    \
  799.   (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
  800. #endif /* __pyr__ */
  801.  
  802. #if defined (__ibm032__) /* RT/ROMP */  && W_TYPE_SIZE == 32
  803. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  804.   __asm__ ("a %1,%5
  805.     ae %0,%3"                            \
  806.        : "=r" ((USItype)(sh)),                    \
  807.          "=&r" ((USItype)(sl))                    \
  808.        : "%0" ((USItype)(ah)),                    \
  809.          "r" ((USItype)(bh)),                    \
  810.          "%1" ((USItype)(al)),                    \
  811.          "r" ((USItype)(bl)))
  812. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  813.   __asm__ ("s %1,%5
  814.     se %0,%3"                            \
  815.        : "=r" ((USItype)(sh)),                    \
  816.          "=&r" ((USItype)(sl))                    \
  817.        : "0" ((USItype)(ah)),                    \
  818.          "r" ((USItype)(bh)),                    \
  819.          "1" ((USItype)(al)),                    \
  820.          "r" ((USItype)(bl)))
  821. #define umul_ppmm(ph, pl, m0, m1) \
  822.   do {                                    \
  823.     USItype __m0 = (m0), __m1 = (m1);                    \
  824.     __asm__ (                                \
  825.        "s    r2,r2
  826.     mts    r10,%2
  827.     m    r2,%3
  828.     m    r2,%3
  829.     m    r2,%3
  830.     m    r2,%3
  831.     m    r2,%3
  832.     m    r2,%3
  833.     m    r2,%3
  834.     m    r2,%3
  835.     m    r2,%3
  836.     m    r2,%3
  837.     m    r2,%3
  838.     m    r2,%3
  839.     m    r2,%3
  840.     m    r2,%3
  841.     m    r2,%3
  842.     m    r2,%3
  843.     cas    %0,r2,r0
  844.     mfs    r10,%1"                            \
  845.          : "=r" ((USItype)(ph)),                    \
  846.            "=r" ((USItype)(pl))                    \
  847.          : "%r" (__m0),                        \
  848.         "r" (__m1)                        \
  849.          : "r2");                            \
  850.     (ph) += ((((SItype) __m0 >> 31) & __m1)                \
  851.          + (((SItype) __m1 >> 31) & __m0));                \
  852.   } while (0)
  853. #define UMUL_TIME 20
  854. #define UDIV_TIME 200
  855. #define count_leading_zeros(count, x) \
  856.   do {                                    \
  857.     if ((x) >= 0x10000)                            \
  858.       __asm__ ("clz    %0,%1"                        \
  859.            : "=r" ((USItype)(count))                \
  860.            : "r" ((USItype)(x) >> 16));                \
  861.     else                                \
  862.       {                                    \
  863.     __asm__ ("clz    %0,%1"                        \
  864.          : "=r" ((USItype)(count))                \
  865.          : "r" ((USItype)(x)));                    \
  866.     (count) += 16;                            \
  867.       }                                    \
  868.   } while (0)
  869. #endif
  870.  
  871. #if defined (__sparc__) && W_TYPE_SIZE == 32
  872. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  873.   __asm__ ("addcc %r4,%5,%1
  874.     addx %r2,%3,%0"                            \
  875.        : "=r" ((USItype)(sh)),                    \
  876.          "=&r" ((USItype)(sl))                    \
  877.        : "%rJ" ((USItype)(ah)),                    \
  878.          "rI" ((USItype)(bh)),                    \
  879.          "%rJ" ((USItype)(al)),                    \
  880.          "rI" ((USItype)(bl))                    \
  881.        __CLOBBER_CC)
  882. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  883.   __asm__ ("subcc %r4,%5,%1
  884.     subx %r2,%3,%0"                            \
  885.        : "=r" ((USItype)(sh)),                    \
  886.          "=&r" ((USItype)(sl))                    \
  887.        : "rJ" ((USItype)(ah)),                    \
  888.          "rI" ((USItype)(bh)),                    \
  889.          "rJ" ((USItype)(al)),                    \
  890.          "rI" ((USItype)(bl))                    \
  891.        __CLOBBER_CC)
  892. #if defined (__sparc_v8__)
  893. /* Don't match immediate range because, 1) it is not often useful,
  894.    2) the 'I' flag thinks of the range as a 13 bit signed interval,
  895.    while we want to match a 13 bit interval, sign extended to 32 bits,
  896.    but INTERPRETED AS UNSIGNED.  */
  897. #define umul_ppmm(w1, w0, u, v) \
  898.   __asm__ ("umul %2,%3,%1;rd %%y,%0"                    \
  899.        : "=r" ((USItype)(w1)),                    \
  900.          "=r" ((USItype)(w0))                    \
  901.        : "r" ((USItype)(u)),                    \
  902.          "r" ((USItype)(v)))
  903. #define UMUL_TIME 5
  904. #ifndef SUPERSPARC
  905. #define udiv_qrnnd(q, r, n1, n0, d) \
  906.   __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
  907.        : "=&r" ((USItype)(q)),                    \
  908.          "=&r" ((USItype)(r))                    \
  909.        : "r" ((USItype)(n1)),                    \
  910.          "r" ((USItype)(n0)),                    \
  911.          "r" ((USItype)(d)))
  912. #define UDIV_TIME 25
  913. #endif /* SUPERSPARC */
  914. #else /* ! __sparc_v8__ */
  915. #if defined (__sparclite__)
  916. /* This has hardware multiply but not divide.  It also has two additional
  917.    instructions scan (ffs from high bit) and divscc.  */
  918. #define umul_ppmm(w1, w0, u, v) \
  919.   __asm__ ("umul %2,%3,%1;rd %%y,%0"                    \
  920.        : "=r" ((USItype)(w1)),                    \
  921.          "=r" ((USItype)(w0))                    \
  922.        : "r" ((USItype)(u)),                    \
  923.          "r" ((USItype)(v)))
  924. #define UMUL_TIME 5
  925. #define udiv_qrnnd(q, r, n1, n0, d) \
  926.   __asm__ ("! Inlined udiv_qrnnd
  927.     wr    %%g0,%2,%%y    ! Not a delayed write for sparclite
  928.     tst    %%g0
  929.     divscc    %3,%4,%%g1
  930.     divscc    %%g1,%4,%%g1
  931.     divscc    %%g1,%4,%%g1
  932.     divscc    %%g1,%4,%%g1
  933.     divscc    %%g1,%4,%%g1
  934.     divscc    %%g1,%4,%%g1
  935.     divscc    %%g1,%4,%%g1
  936.     divscc    %%g1,%4,%%g1
  937.     divscc    %%g1,%4,%%g1
  938.     divscc    %%g1,%4,%%g1
  939.     divscc    %%g1,%4,%%g1
  940.     divscc    %%g1,%4,%%g1
  941.     divscc    %%g1,%4,%%g1
  942.     divscc    %%g1,%4,%%g1
  943.     divscc    %%g1,%4,%%g1
  944.     divscc    %%g1,%4,%%g1
  945.     divscc    %%g1,%4,%%g1
  946.     divscc    %%g1,%4,%%g1
  947.     divscc    %%g1,%4,%%g1
  948.     divscc    %%g1,%4,%%g1
  949.     divscc    %%g1,%4,%%g1
  950.     divscc    %%g1,%4,%%g1
  951.     divscc    %%g1,%4,%%g1
  952.     divscc    %%g1,%4,%%g1
  953.     divscc    %%g1,%4,%%g1
  954.     divscc    %%g1,%4,%%g1
  955.     divscc    %%g1,%4,%%g1
  956.     divscc    %%g1,%4,%%g1
  957.     divscc    %%g1,%4,%%g1
  958.     divscc    %%g1,%4,%%g1
  959.     divscc    %%g1,%4,%%g1
  960.     divscc    %%g1,%4,%0
  961.     rd    %%y,%1
  962.     bl,a 1f
  963.     add    %1,%4,%1
  964. 1:    ! End of inline udiv_qrnnd"                    \
  965.        : "=r" ((USItype)(q)),                    \
  966.          "=r" ((USItype)(r))                    \
  967.        : "r" ((USItype)(n1)),                    \
  968.          "r" ((USItype)(n0)),                    \
  969.          "rI" ((USItype)(d))                    \
  970.        : "%g1" __AND_CLOBBER_CC)
  971. #define UDIV_TIME 37
  972. #define count_leading_zeros(count, x) \
  973.   __asm__ ("scan %1,0,%0"                        \
  974.        : "=r" ((USItype)(x))                    \
  975.        : "r" ((USItype)(count)))
  976. #endif /* __sparclite__ */
  977. #endif /* __sparc_v8__ */
  978. /* Default to sparc v7 versions of umul_ppmm and udiv_qrnnd.  */
  979. #ifndef umul_ppmm
  980. #define umul_ppmm(w1, w0, u, v) \
  981.   __asm__ ("! Inlined umul_ppmm
  982.     wr    %%g0,%2,%%y    ! SPARC has 0-3 delay insn after a wr
  983.     sra    %3,31,%%g2    ! Don't move this insn
  984.     and    %2,%%g2,%%g2    ! Don't move this insn
  985.     andcc    %%g0,0,%%g1    ! Don't move this insn
  986.     mulscc    %%g1,%3,%%g1
  987.     mulscc    %%g1,%3,%%g1
  988.     mulscc    %%g1,%3,%%g1
  989.     mulscc    %%g1,%3,%%g1
  990.     mulscc    %%g1,%3,%%g1
  991.     mulscc    %%g1,%3,%%g1
  992.     mulscc    %%g1,%3,%%g1
  993.     mulscc    %%g1,%3,%%g1
  994.     mulscc    %%g1,%3,%%g1
  995.     mulscc    %%g1,%3,%%g1
  996.     mulscc    %%g1,%3,%%g1
  997.     mulscc    %%g1,%3,%%g1
  998.     mulscc    %%g1,%3,%%g1
  999.     mulscc    %%g1,%3,%%g1
  1000.     mulscc    %%g1,%3,%%g1
  1001.     mulscc    %%g1,%3,%%g1
  1002.     mulscc    %%g1,%3,%%g1
  1003.     mulscc    %%g1,%3,%%g1
  1004.     mulscc    %%g1,%3,%%g1
  1005.     mulscc    %%g1,%3,%%g1
  1006.     mulscc    %%g1,%3,%%g1
  1007.     mulscc    %%g1,%3,%%g1
  1008.     mulscc    %%g1,%3,%%g1
  1009.     mulscc    %%g1,%3,%%g1
  1010.     mulscc    %%g1,%3,%%g1
  1011.     mulscc    %%g1,%3,%%g1
  1012.     mulscc    %%g1,%3,%%g1
  1013.     mulscc    %%g1,%3,%%g1
  1014.     mulscc    %%g1,%3,%%g1
  1015.     mulscc    %%g1,%3,%%g1
  1016.     mulscc    %%g1,%3,%%g1
  1017.     mulscc    %%g1,%3,%%g1
  1018.     mulscc    %%g1,0,%%g1
  1019.     add    %%g1,%%g2,%0
  1020.     rd    %%y,%1"                            \
  1021.        : "=r" ((USItype)(w1)),                    \
  1022.          "=r" ((USItype)(w0))                    \
  1023.        : "%rI" ((USItype)(u)),                    \
  1024.          "r" ((USItype)(v))                        \
  1025.        : "%g1", "%g2" __AND_CLOBBER_CC)
  1026. #define UMUL_TIME 39        /* 39 instructions */
  1027. #endif
  1028. #ifndef udiv_qrnnd
  1029. #ifndef LONGLONG_STANDALONE
  1030. #define udiv_qrnnd(q, r, n1, n0, d) \
  1031.   do { USItype __r;                            \
  1032.     (q) = __udiv_qrnnd (&__r, (n1), (n0), (d));                \
  1033.     (r) = __r;                                \
  1034.   } while (0)
  1035. extern USItype __udiv_qrnnd ();
  1036. #define UDIV_TIME 140
  1037. #endif /* LONGLONG_STANDALONE */
  1038. #endif /* udiv_qrnnd */
  1039. #endif /* __sparc__ */
  1040.  
  1041. #if defined (__vax__) && W_TYPE_SIZE == 32
  1042. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  1043.   __asm__ ("addl2 %5,%1
  1044.     adwc %3,%0"                            \
  1045.        : "=g" ((USItype)(sh)),                    \
  1046.          "=&g" ((USItype)(sl))                    \
  1047.        : "%0" ((USItype)(ah)),                    \
  1048.          "g" ((USItype)(bh)),                    \
  1049.          "%1" ((USItype)(al)),                    \
  1050.          "g" ((USItype)(bl)))
  1051. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  1052.   __asm__ ("subl2 %5,%1
  1053.     sbwc %3,%0"                            \
  1054.        : "=g" ((USItype)(sh)),                    \
  1055.          "=&g" ((USItype)(sl))                    \
  1056.        : "0" ((USItype)(ah)),                    \
  1057.          "g" ((USItype)(bh)),                    \
  1058.          "1" ((USItype)(al)),                    \
  1059.          "g" ((USItype)(bl)))
  1060. #define umul_ppmm(xh, xl, m0, m1) \
  1061.   do {                                    \
  1062.     union {UDItype __ll;                        \
  1063.        struct {USItype __l, __h;} __i;                \
  1064.       } __xx;                            \
  1065.     USItype __m0 = (m0), __m1 = (m1);                    \
  1066.     __asm__ ("emul %1,%2,$0,%0"                        \
  1067.          : "=g" (__xx.__ll)                        \
  1068.          : "g" (__m0),                        \
  1069.            "g" (__m1));                        \
  1070.     (xh) = __xx.__i.__h; (xl) = __xx.__i.__l;                \
  1071.     (xh) += ((((SItype) __m0 >> 31) & __m1)                \
  1072.          + (((SItype) __m1 >> 31) & __m0));                \
  1073.   } while (0)
  1074. #define sdiv_qrnnd(q, r, n1, n0, d) \
  1075.   do {                                    \
  1076.     union {DItype __ll;                            \
  1077.        struct {SItype __l, __h;} __i;                \
  1078.       } __xx;                            \
  1079.     __xx.__i.__h = n1; __xx.__i.__l = n0;                \
  1080.     __asm__ ("ediv %3,%2,%0,%1"                        \
  1081.          : "=g" (q), "=g" (r)                    \
  1082.          : "g" (__xx.ll), "g" (d));                    \
  1083.   } while (0)
  1084. #endif /* __vax__ */
  1085.  
  1086. #if defined (__z8000__) && W_TYPE_SIZE == 16
  1087. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  1088.   __asm__ ("add    %H1,%H5\n\tadc    %H0,%H3"                \
  1089.        : "=r" ((unsigned int)(sh)),                    \
  1090.          "=&r" ((unsigned int)(sl))                    \
  1091.        : "%0" ((unsigned int)(ah)),                    \
  1092.          "r" ((unsigned int)(bh)),                    \
  1093.          "%1" ((unsigned int)(al)),                    \
  1094.          "rQR" ((unsigned int)(bl)))
  1095. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  1096.   __asm__ ("sub    %H1,%H5\n\tsbc    %H0,%H3"                \
  1097.        : "=r" ((unsigned int)(sh)),                    \
  1098.          "=&r" ((unsigned int)(sl))                    \
  1099.        : "0" ((unsigned int)(ah)),                    \
  1100.          "r" ((unsigned int)(bh)),                    \
  1101.          "1" ((unsigned int)(al)),                    \
  1102.          "rQR" ((unsigned int)(bl)))
  1103. #define umul_ppmm(xh, xl, m0, m1) \
  1104.   do {                                    \
  1105.     union {long int __ll;                        \
  1106.        struct {unsigned int __h, __l;} __i;                \
  1107.       } __xx;                            \
  1108.     unsigned int __m0 = (m0), __m1 = (m1);                \
  1109.     __asm__ ("mult    %S0,%H3"                    \
  1110.          : "=r" (__xx.__i.__h),                    \
  1111.            "=r" (__xx.__i.__l)                    \
  1112.          : "%1" (__m0),                        \
  1113.            "rQR" (__m1));                        \
  1114.     (xh) = __xx.__i.__h; (xl) = __xx.__i.__l;                \
  1115.     (xh) += ((((signed int) __m0 >> 15) & __m1)                \
  1116.          + (((signed int) __m1 >> 15) & __m0));            \
  1117.   } while (0)
  1118. #define umul_ppmm_off(xh, xl, m0, m1) \
  1119.   do {                                    \
  1120.     union {long int __ll;                        \
  1121.        struct {unsigned int __h, __l;} __i;                \
  1122.       } __xx;                            \
  1123.     __asm__ ("mult    %S0,%H3"                    \
  1124.          : "=r" (__xx.__i.__h),                    \
  1125.            "=r" (__xx.__i.__l)                    \
  1126.          : "%1" (m0),                        \
  1127.            "rQR" (m1));                        \
  1128.     (xh) = __xx.__i.__h + ((((signed int) m0 >> 15) & m1)        \
  1129.                + (((signed int) m1 >> 15) & m0));        \
  1130.     (xl) = __xx.__i.__l;                        \
  1131.   } while (0)
  1132. #endif /* __z8000__ */
  1133.  
  1134. #endif /* __GNUC__ */
  1135.  
  1136.  
  1137. #if !defined (umul_ppmm) && defined (__umulsidi3)
  1138. #define umul_ppmm(ph, pl, m0, m1) \
  1139.   {                                    \
  1140.     UDWtype __ll = __umulsidi3 (m0, m1);                \
  1141.     ph = (UWtype) (__ll >> W_TYPE_SIZE);                \
  1142.     pl = (UWtype) __ll;                            \
  1143.   }
  1144. #endif
  1145.  
  1146. #if !defined (__umulsidi3)
  1147. #define __umulsidi3(u, v) \
  1148.   ({UWtype __hi, __lo;                            \
  1149.     umul_ppmm (__hi, __lo, u, v);                    \
  1150.     ((UDWtype) __hi << W_TYPE_SIZE) | __lo; })
  1151. #endif
  1152.  
  1153. /* If this machine has no inline assembler, use C macros.  */
  1154.  
  1155. #if !defined (add_ssaaaa)
  1156. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  1157.   do {                                    \
  1158.     UWtype __x;                                \
  1159.     __x = (al) + (bl);                            \
  1160.     (sh) = (ah) + (bh) + (__x < (al));                    \
  1161.     (sl) = __x;                                \
  1162.   } while (0)
  1163. #endif
  1164.  
  1165. #if !defined (sub_ddmmss)
  1166. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  1167.   do {                                    \
  1168.     UWtype __x;                                \
  1169.     __x = (al) - (bl);                            \
  1170.     (sh) = (ah) - (bh) - (__x > (al));                    \
  1171.     (sl) = __x;                                \
  1172.   } while (0)
  1173. #endif
  1174.  
  1175. #if !defined (umul_ppmm)
  1176. #define umul_ppmm(w1, w0, u, v)                        \
  1177.   do {                                    \
  1178.     UWtype __x0, __x1, __x2, __x3;                    \
  1179.     UHWtype __ul, __vl, __uh, __vh;                    \
  1180.     UWtype __u = (u), __v = (v);                    \
  1181.                                     \
  1182.     __ul = __ll_lowpart (__u);                        \
  1183.     __uh = __ll_highpart (__u);                        \
  1184.     __vl = __ll_lowpart (__v);                        \
  1185.     __vh = __ll_highpart (__v);                        \
  1186.                                     \
  1187.     __x0 = (UWtype) __ul * __vl;                    \
  1188.     __x1 = (UWtype) __ul * __vh;                    \
  1189.     __x2 = (UWtype) __uh * __vl;                    \
  1190.     __x3 = (UWtype) __uh * __vh;                    \
  1191.                                     \
  1192.     __x1 += __ll_highpart (__x0);/* this can't give carry */        \
  1193.     __x1 += __x2;        /* but this indeed can */        \
  1194.     if (__x1 < __x2)        /* did we get it? */            \
  1195.       __x3 += __ll_B;        /* yes, add it in the proper pos. */    \
  1196.                                     \
  1197.     (w1) = __x3 + __ll_highpart (__x1);                    \
  1198.     (w0) = (__ll_lowpart (__x1) << W_TYPE_SIZE/2) + __ll_lowpart (__x0);\
  1199.   } while (0)
  1200. #endif
  1201.  
  1202. #if !defined (umul_ppmm)
  1203. #define smul_ppmm(w1, w0, u, v)                        \
  1204.   do {                                    \
  1205.     UWtype __w1;                            \
  1206.     USItype __m0 = (u), __m1 = (v);                    \
  1207.     umul_ppmm (__w1, w0, __m0, __m1);                    \
  1208.     (w1) = __w1 - (-(__m0 >> (W_TYPE_SIZE - 1)) & __m1)            \
  1209.         - (-(__m1 >> (W_TYPE_SIZE - 1)) & __m0);        \
  1210.   } while (0)
  1211. #endif
  1212.  
  1213. /* Define this unconditionally, so it can be used for debugging.  */
  1214. #define __udiv_qrnnd_c(q, r, n1, n0, d) \
  1215.   do {                                    \
  1216.     UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m;            \
  1217.     __d1 = __ll_highpart (d);                        \
  1218.     __d0 = __ll_lowpart (d);                        \
  1219.                                     \
  1220.     __r1 = (n1) % __d1;                            \
  1221.     __q1 = (n1) / __d1;                            \
  1222.     __m = (UWtype) __q1 * __d0;                        \
  1223.     __r1 = __r1 * __ll_B | __ll_highpart (n0);                \
  1224.     if (__r1 < __m)                            \
  1225.       {                                    \
  1226.     __q1--, __r1 += (d);                        \
  1227.     if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
  1228.       if (__r1 < __m)                        \
  1229.         __q1--, __r1 += (d);                    \
  1230.       }                                    \
  1231.     __r1 -= __m;                            \
  1232.                                     \
  1233.     __r0 = __r1 % __d1;                            \
  1234.     __q0 = __r1 / __d1;                            \
  1235.     __m = (UWtype) __q0 * __d0;                        \
  1236.     __r0 = __r0 * __ll_B | __ll_lowpart (n0);                \
  1237.     if (__r0 < __m)                            \
  1238.       {                                    \
  1239.     __q0--, __r0 += (d);                        \
  1240.     if (__r0 >= (d))                        \
  1241.       if (__r0 < __m)                        \
  1242.         __q0--, __r0 += (d);                    \
  1243.       }                                    \
  1244.     __r0 -= __m;                            \
  1245.                                     \
  1246.     (q) = (UWtype) __q1 * __ll_B | __q0;                \
  1247.     (r) = __r0;                                \
  1248.   } while (0)
  1249.  
  1250. /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
  1251.    __udiv_w_sdiv (defined in libgcc or elsewhere).  */
  1252. #if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
  1253. #define udiv_qrnnd(q, r, nh, nl, d) \
  1254.   do {                                    \
  1255.     UWtype __r;                                \
  1256.     (q) = __udiv_w_sdiv (&__r, nh, nl, d);                \
  1257.     (r) = __r;                                \
  1258.   } while (0)
  1259. #endif
  1260.  
  1261. /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  */
  1262. #if !defined (udiv_qrnnd)
  1263. #define UDIV_NEEDS_NORMALIZATION 1
  1264. #define udiv_qrnnd __udiv_qrnnd_c
  1265. #endif
  1266.  
  1267. #if !defined (count_leading_zeros)
  1268. extern
  1269. #ifdef __STDC__
  1270. const
  1271. #endif
  1272. unsigned char __clz_tab[];
  1273. #define count_leading_zeros(count, x) \
  1274.   do {                                    \
  1275.     UWtype __xr = (x);                            \
  1276.     UWtype __a;                                \
  1277.                                     \
  1278.     if (W_TYPE_SIZE <= 32)                        \
  1279.       {                                    \
  1280.     __a = __xr < ((UWtype) 1 << 2*__BITS4)                \
  1281.       ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4)        \
  1282.       : (__xr < ((UWtype) 1 << 3*__BITS4) ?  2*__BITS4 : 3*__BITS4);\
  1283.       }                                    \
  1284.     else                                \
  1285.       {                                    \
  1286.     for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8)            \
  1287.       if (((__xr >> __a) & 0xff) != 0)                \
  1288.         break;                            \
  1289.       }                                    \
  1290.                                     \
  1291.     (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a);        \
  1292.   } while (0)
  1293. /* This version gives a well-defined value for zero. */
  1294. #define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
  1295. #endif
  1296.  
  1297. #if !defined (count_trailing_zeros)
  1298. /* Define count_trailing_zeros using count_leading_zeros.  The latter might be
  1299.    defined in asm, but if it is not, the C version above is good enough.  */
  1300. #define count_trailing_zeros(count, x) \
  1301.   do {                                    \
  1302.     UWtype __ctz_x = (x);                        \
  1303.     UWtype __ctz_c;                            \
  1304.     count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x);            \
  1305.     (count) = W_TYPE_SIZE - 1 - __ctz_c;                \
  1306.   } while (0)
  1307. #endif
  1308.  
  1309. #ifndef UDIV_NEEDS_NORMALIZATION
  1310. #define UDIV_NEEDS_NORMALIZATION 0
  1311. #endif
  1312.