longlong.h 48 KB

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