longlong.h 50 KB

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