longlong.h 43 KB

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