longlong.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500
  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__ > 2 || __GNUC_MINOR__ >= 7
  685. #define umul_ppmm(w1, w0, u, v) \
  686. __asm__ ("multu %2,%3" \
  687. : "=l" ((USItype)(w0)), \
  688. "=h" ((USItype)(w1)) \
  689. : "d" ((USItype)(u)), \
  690. "d" ((USItype)(v)))
  691. #else
  692. #define umul_ppmm(w1, w0, u, v) \
  693. __asm__ ("multu %2,%3\n" \
  694. "mflo %0\n" \
  695. "mfhi %1" \
  696. : "=d" ((USItype)(w0)), \
  697. "=d" ((USItype)(w1)) \
  698. : "d" ((USItype)(u)), \
  699. "d" ((USItype)(v)))
  700. #endif
  701. #define UMUL_TIME 10
  702. #define UDIV_TIME 100
  703. #endif /* __mips__ */
  704. /***************************************
  705. ************** MIPS/64 **************
  706. ***************************************/
  707. #if (defined(__mips) && __mips >= 3) && W_TYPE_SIZE == 64
  708. #if __GNUC__ > 2 || __GNUC_MINOR__ >= 7
  709. #define umul_ppmm(w1, w0, u, v) \
  710. __asm__ ("dmultu %2,%3" \
  711. : "=l" ((UDItype)(w0)), \
  712. "=h" ((UDItype)(w1)) \
  713. : "d" ((UDItype)(u)), \
  714. "d" ((UDItype)(v)))
  715. #else
  716. #define umul_ppmm(w1, w0, u, v) \
  717. __asm__ ("dmultu %2,%3\n" \
  718. "mflo %0\n" \
  719. "mfhi %1" \
  720. : "=d" ((UDItype)(w0)), \
  721. "=d" ((UDItype)(w1)) \
  722. : "d" ((UDItype)(u)), \
  723. "d" ((UDItype)(v)))
  724. #endif
  725. #define UMUL_TIME 20
  726. #define UDIV_TIME 140
  727. #endif /* __mips__ */
  728. /***************************************
  729. ************** 32000 ****************
  730. ***************************************/
  731. #if defined(__ns32000__) && W_TYPE_SIZE == 32
  732. #define umul_ppmm(w1, w0, u, v) \
  733. ({union {UDItype __ll; \
  734. struct {USItype __l, __h; } __i; \
  735. } __xx; \
  736. __asm__ ("meid %2,%0" \
  737. : "=g" (__xx.__ll) \
  738. : "%0" ((USItype)(u)), \
  739. "g" ((USItype)(v))); \
  740. (w1) = __xx.__i.__h; (w0) = __xx.__i.__l; })
  741. #define __umulsidi3(u, v) \
  742. ({UDItype __w; \
  743. __asm__ ("meid %2,%0" \
  744. : "=g" (__w) \
  745. : "%0" ((USItype)(u)), \
  746. "g" ((USItype)(v))); \
  747. __w; })
  748. #define udiv_qrnnd(q, r, n1, n0, d) \
  749. ({union {UDItype __ll; \
  750. struct {USItype __l, __h; } __i; \
  751. } __xx; \
  752. __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
  753. __asm__ ("deid %2,%0" \
  754. : "=g" (__xx.__ll) \
  755. : "0" (__xx.__ll), \
  756. "g" ((USItype)(d))); \
  757. (r) = __xx.__i.__l; (q) = __xx.__i.__h; })
  758. #define count_trailing_zeros(count, x) \
  759. do { \
  760. __asm__("ffsd %2,%0" \
  761. : "=r"((USItype) (count)) \
  762. : "0"((USItype) 0), "r"((USItype) (x))); \
  763. } while (0)
  764. #endif /* __ns32000__ */
  765. /***************************************
  766. ************** PPC ******************
  767. ***************************************/
  768. #if (defined(_ARCH_PPC) || defined(_IBMR2)) && W_TYPE_SIZE == 32
  769. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  770. do { \
  771. if (__builtin_constant_p(bh) && (bh) == 0) \
  772. __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
  773. : "=r" ((USItype)(sh)), \
  774. "=&r" ((USItype)(sl)) \
  775. : "%r" ((USItype)(ah)), \
  776. "%r" ((USItype)(al)), \
  777. "rI" ((USItype)(bl))); \
  778. else if (__builtin_constant_p(bh) && (bh) == ~(USItype) 0) \
  779. __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
  780. : "=r" ((USItype)(sh)), \
  781. "=&r" ((USItype)(sl)) \
  782. : "%r" ((USItype)(ah)), \
  783. "%r" ((USItype)(al)), \
  784. "rI" ((USItype)(bl))); \
  785. else \
  786. __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
  787. : "=r" ((USItype)(sh)), \
  788. "=&r" ((USItype)(sl)) \
  789. : "%r" ((USItype)(ah)), \
  790. "r" ((USItype)(bh)), \
  791. "%r" ((USItype)(al)), \
  792. "rI" ((USItype)(bl))); \
  793. } while (0)
  794. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  795. do { \
  796. if (__builtin_constant_p(ah) && (ah) == 0) \
  797. __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
  798. : "=r" ((USItype)(sh)), \
  799. "=&r" ((USItype)(sl)) \
  800. : "r" ((USItype)(bh)), \
  801. "rI" ((USItype)(al)), \
  802. "r" ((USItype)(bl))); \
  803. else if (__builtin_constant_p(ah) && (ah) == ~(USItype) 0) \
  804. __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
  805. : "=r" ((USItype)(sh)), \
  806. "=&r" ((USItype)(sl)) \
  807. : "r" ((USItype)(bh)), \
  808. "rI" ((USItype)(al)), \
  809. "r" ((USItype)(bl))); \
  810. else if (__builtin_constant_p(bh) && (bh) == 0) \
  811. __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
  812. : "=r" ((USItype)(sh)), \
  813. "=&r" ((USItype)(sl)) \
  814. : "r" ((USItype)(ah)), \
  815. "rI" ((USItype)(al)), \
  816. "r" ((USItype)(bl))); \
  817. else if (__builtin_constant_p(bh) && (bh) == ~(USItype) 0) \
  818. __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
  819. : "=r" ((USItype)(sh)), \
  820. "=&r" ((USItype)(sl)) \
  821. : "r" ((USItype)(ah)), \
  822. "rI" ((USItype)(al)), \
  823. "r" ((USItype)(bl))); \
  824. else \
  825. __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
  826. : "=r" ((USItype)(sh)), \
  827. "=&r" ((USItype)(sl)) \
  828. : "r" ((USItype)(ah)), \
  829. "r" ((USItype)(bh)), \
  830. "rI" ((USItype)(al)), \
  831. "r" ((USItype)(bl))); \
  832. } while (0)
  833. #define count_leading_zeros(count, x) \
  834. __asm__ ("{cntlz|cntlzw} %0,%1" \
  835. : "=r" ((USItype)(count)) \
  836. : "r" ((USItype)(x)))
  837. #define COUNT_LEADING_ZEROS_0 32
  838. #if defined(_ARCH_PPC)
  839. #define umul_ppmm(ph, pl, m0, m1) \
  840. do { \
  841. USItype __m0 = (m0), __m1 = (m1); \
  842. __asm__ ("mulhwu %0,%1,%2" \
  843. : "=r" ((USItype) ph) \
  844. : "%r" (__m0), \
  845. "r" (__m1)); \
  846. (pl) = __m0 * __m1; \
  847. } while (0)
  848. #define UMUL_TIME 15
  849. #define smul_ppmm(ph, pl, m0, m1) \
  850. do { \
  851. SItype __m0 = (m0), __m1 = (m1); \
  852. __asm__ ("mulhw %0,%1,%2" \
  853. : "=r" ((SItype) ph) \
  854. : "%r" (__m0), \
  855. "r" (__m1)); \
  856. (pl) = __m0 * __m1; \
  857. } while (0)
  858. #define SMUL_TIME 14
  859. #define UDIV_TIME 120
  860. #else
  861. #define umul_ppmm(xh, xl, m0, m1) \
  862. do { \
  863. USItype __m0 = (m0), __m1 = (m1); \
  864. __asm__ ("mul %0,%2,%3" \
  865. : "=r" ((USItype)(xh)), \
  866. "=q" ((USItype)(xl)) \
  867. : "r" (__m0), \
  868. "r" (__m1)); \
  869. (xh) += ((((SItype) __m0 >> 31) & __m1) \
  870. + (((SItype) __m1 >> 31) & __m0)); \
  871. } while (0)
  872. #define UMUL_TIME 8
  873. #define smul_ppmm(xh, xl, m0, m1) \
  874. __asm__ ("mul %0,%2,%3" \
  875. : "=r" ((SItype)(xh)), \
  876. "=q" ((SItype)(xl)) \
  877. : "r" (m0), \
  878. "r" (m1))
  879. #define SMUL_TIME 4
  880. #define sdiv_qrnnd(q, r, nh, nl, d) \
  881. __asm__ ("div %0,%2,%4" \
  882. : "=r" ((SItype)(q)), "=q" ((SItype)(r)) \
  883. : "r" ((SItype)(nh)), "1" ((SItype)(nl)), "r" ((SItype)(d)))
  884. #define UDIV_TIME 100
  885. #endif
  886. #endif /* Power architecture variants. */
  887. /***************************************
  888. ************** PYR ******************
  889. ***************************************/
  890. #if defined(__pyr__) && W_TYPE_SIZE == 32
  891. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  892. __asm__ ("addw %5,%1\n" \
  893. "addwc %3,%0" \
  894. : "=r" ((USItype)(sh)), \
  895. "=&r" ((USItype)(sl)) \
  896. : "%0" ((USItype)(ah)), \
  897. "g" ((USItype)(bh)), \
  898. "%1" ((USItype)(al)), \
  899. "g" ((USItype)(bl)))
  900. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  901. __asm__ ("subw %5,%1\n" \
  902. "subwb %3,%0" \
  903. : "=r" ((USItype)(sh)), \
  904. "=&r" ((USItype)(sl)) \
  905. : "0" ((USItype)(ah)), \
  906. "g" ((USItype)(bh)), \
  907. "1" ((USItype)(al)), \
  908. "g" ((USItype)(bl)))
  909. /* This insn works on Pyramids with AP, XP, or MI CPUs, but not with SP. */
  910. #define umul_ppmm(w1, w0, u, v) \
  911. ({union {UDItype __ll; \
  912. struct {USItype __h, __l; } __i; \
  913. } __xx; \
  914. __asm__ ("movw %1,%R0\n" \
  915. "uemul %2,%0" \
  916. : "=&r" (__xx.__ll) \
  917. : "g" ((USItype) (u)), \
  918. "g" ((USItype)(v))); \
  919. (w1) = __xx.__i.__h; (w0) = __xx.__i.__l; })
  920. #endif /* __pyr__ */
  921. /***************************************
  922. ************** RT/ROMP **************
  923. ***************************************/
  924. #if defined(__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
  925. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  926. __asm__ ("a %1,%5\n" \
  927. "ae %0,%3" \
  928. : "=r" ((USItype)(sh)), \
  929. "=&r" ((USItype)(sl)) \
  930. : "%0" ((USItype)(ah)), \
  931. "r" ((USItype)(bh)), \
  932. "%1" ((USItype)(al)), \
  933. "r" ((USItype)(bl)))
  934. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  935. __asm__ ("s %1,%5\n" \
  936. "se %0,%3" \
  937. : "=r" ((USItype)(sh)), \
  938. "=&r" ((USItype)(sl)) \
  939. : "0" ((USItype)(ah)), \
  940. "r" ((USItype)(bh)), \
  941. "1" ((USItype)(al)), \
  942. "r" ((USItype)(bl)))
  943. #define umul_ppmm(ph, pl, m0, m1) \
  944. do { \
  945. USItype __m0 = (m0), __m1 = (m1); \
  946. __asm__ ( \
  947. "s r2,r2\n" \
  948. "mts r10,%2\n" \
  949. "m r2,%3\n" \
  950. "m r2,%3\n" \
  951. "m r2,%3\n" \
  952. "m r2,%3\n" \
  953. "m r2,%3\n" \
  954. "m r2,%3\n" \
  955. "m r2,%3\n" \
  956. "m r2,%3\n" \
  957. "m r2,%3\n" \
  958. "m r2,%3\n" \
  959. "m r2,%3\n" \
  960. "m r2,%3\n" \
  961. "m r2,%3\n" \
  962. "m r2,%3\n" \
  963. "m r2,%3\n" \
  964. "m r2,%3\n" \
  965. "cas %0,r2,r0\n" \
  966. "mfs r10,%1" \
  967. : "=r" ((USItype)(ph)), \
  968. "=r" ((USItype)(pl)) \
  969. : "%r" (__m0), \
  970. "r" (__m1) \
  971. : "r2"); \
  972. (ph) += ((((SItype) __m0 >> 31) & __m1) \
  973. + (((SItype) __m1 >> 31) & __m0)); \
  974. } while (0)
  975. #define UMUL_TIME 20
  976. #define UDIV_TIME 200
  977. #define count_leading_zeros(count, x) \
  978. do { \
  979. if ((x) >= 0x10000) \
  980. __asm__ ("clz %0,%1" \
  981. : "=r" ((USItype)(count)) \
  982. : "r" ((USItype)(x) >> 16)); \
  983. else { \
  984. __asm__ ("clz %0,%1" \
  985. : "=r" ((USItype)(count)) \
  986. : "r" ((USItype)(x))); \
  987. (count) += 16; \
  988. } \
  989. } while (0)
  990. #endif /* RT/ROMP */
  991. /***************************************
  992. ************** SH2 ******************
  993. ***************************************/
  994. #if (defined(__sh2__) || defined(__sh3__) || defined(__SH4__)) \
  995. && W_TYPE_SIZE == 32
  996. #define umul_ppmm(w1, w0, u, v) \
  997. __asm__ ( \
  998. "dmulu.l %2,%3\n" \
  999. "sts macl,%1\n" \
  1000. "sts mach,%0" \
  1001. : "=r" ((USItype)(w1)), \
  1002. "=r" ((USItype)(w0)) \
  1003. : "r" ((USItype)(u)), \
  1004. "r" ((USItype)(v)) \
  1005. : "macl", "mach")
  1006. #define UMUL_TIME 5
  1007. #endif
  1008. /***************************************
  1009. ************** SPARC ****************
  1010. ***************************************/
  1011. #if defined(__sparc__) && W_TYPE_SIZE == 32
  1012. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  1013. __asm__ ("addcc %r4,%5,%1\n" \
  1014. "addx %r2,%3,%0" \
  1015. : "=r" ((USItype)(sh)), \
  1016. "=&r" ((USItype)(sl)) \
  1017. : "%rJ" ((USItype)(ah)), \
  1018. "rI" ((USItype)(bh)), \
  1019. "%rJ" ((USItype)(al)), \
  1020. "rI" ((USItype)(bl)) \
  1021. __CLOBBER_CC)
  1022. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  1023. __asm__ ("subcc %r4,%5,%1\n" \
  1024. "subx %r2,%3,%0" \
  1025. : "=r" ((USItype)(sh)), \
  1026. "=&r" ((USItype)(sl)) \
  1027. : "rJ" ((USItype)(ah)), \
  1028. "rI" ((USItype)(bh)), \
  1029. "rJ" ((USItype)(al)), \
  1030. "rI" ((USItype)(bl)) \
  1031. __CLOBBER_CC)
  1032. #if defined(__sparc_v8__)
  1033. /* Don't match immediate range because, 1) it is not often useful,
  1034. 2) the 'I' flag thinks of the range as a 13 bit signed interval,
  1035. while we want to match a 13 bit interval, sign extended to 32 bits,
  1036. but INTERPRETED AS UNSIGNED. */
  1037. #define umul_ppmm(w1, w0, u, v) \
  1038. __asm__ ("umul %2,%3,%1;rd %%y,%0" \
  1039. : "=r" ((USItype)(w1)), \
  1040. "=r" ((USItype)(w0)) \
  1041. : "r" ((USItype)(u)), \
  1042. "r" ((USItype)(v)))
  1043. #define UMUL_TIME 5
  1044. #ifndef SUPERSPARC /* SuperSPARC's udiv only handles 53 bit dividends */
  1045. #define udiv_qrnnd(q, r, n1, n0, d) \
  1046. do { \
  1047. USItype __q; \
  1048. __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0" \
  1049. : "=r" ((USItype)(__q)) \
  1050. : "r" ((USItype)(n1)), \
  1051. "r" ((USItype)(n0)), \
  1052. "r" ((USItype)(d))); \
  1053. (r) = (n0) - __q * (d); \
  1054. (q) = __q; \
  1055. } while (0)
  1056. #define UDIV_TIME 25
  1057. #endif /* SUPERSPARC */
  1058. #else /* ! __sparc_v8__ */
  1059. #if defined(__sparclite__)
  1060. /* This has hardware multiply but not divide. It also has two additional
  1061. instructions scan (ffs from high bit) and divscc. */
  1062. #define umul_ppmm(w1, w0, u, v) \
  1063. __asm__ ("umul %2,%3,%1;rd %%y,%0" \
  1064. : "=r" ((USItype)(w1)), \
  1065. "=r" ((USItype)(w0)) \
  1066. : "r" ((USItype)(u)), \
  1067. "r" ((USItype)(v)))
  1068. #define UMUL_TIME 5
  1069. #define udiv_qrnnd(q, r, n1, n0, d) \
  1070. __asm__ ("! Inlined udiv_qrnnd\n" \
  1071. "wr %%g0,%2,%%y ! Not a delayed write for sparclite\n" \
  1072. "tst %%g0\n" \
  1073. "divscc %3,%4,%%g1\n" \
  1074. "divscc %%g1,%4,%%g1\n" \
  1075. "divscc %%g1,%4,%%g1\n" \
  1076. "divscc %%g1,%4,%%g1\n" \
  1077. "divscc %%g1,%4,%%g1\n" \
  1078. "divscc %%g1,%4,%%g1\n" \
  1079. "divscc %%g1,%4,%%g1\n" \
  1080. "divscc %%g1,%4,%%g1\n" \
  1081. "divscc %%g1,%4,%%g1\n" \
  1082. "divscc %%g1,%4,%%g1\n" \
  1083. "divscc %%g1,%4,%%g1\n" \
  1084. "divscc %%g1,%4,%%g1\n" \
  1085. "divscc %%g1,%4,%%g1\n" \
  1086. "divscc %%g1,%4,%%g1\n" \
  1087. "divscc %%g1,%4,%%g1\n" \
  1088. "divscc %%g1,%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,%0\n" \
  1105. "rd %%y,%1\n" \
  1106. "bl,a 1f\n" \
  1107. "add %1,%4,%1\n" \
  1108. "1: ! End of inline udiv_qrnnd" \
  1109. : "=r" ((USItype)(q)), \
  1110. "=r" ((USItype)(r)) \
  1111. : "r" ((USItype)(n1)), \
  1112. "r" ((USItype)(n0)), \
  1113. "rI" ((USItype)(d)) \
  1114. : "%g1" __AND_CLOBBER_CC)
  1115. #define UDIV_TIME 37
  1116. #define count_leading_zeros(count, x) \
  1117. __asm__ ("scan %1,0,%0" \
  1118. : "=r" ((USItype)(x)) \
  1119. : "r" ((USItype)(count)))
  1120. /* Early sparclites return 63 for an argument of 0, but they warn that future
  1121. implementations might change this. Therefore, leave COUNT_LEADING_ZEROS_0
  1122. undefined. */
  1123. #endif /* __sparclite__ */
  1124. #endif /* __sparc_v8__ */
  1125. /* Default to sparc v7 versions of umul_ppmm and udiv_qrnnd. */
  1126. #ifndef umul_ppmm
  1127. #define umul_ppmm(w1, w0, u, v) \
  1128. __asm__ ("! Inlined umul_ppmm\n" \
  1129. "wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr\n" \
  1130. "sra %3,31,%%g2 ! Don't move this insn\n" \
  1131. "and %2,%%g2,%%g2 ! Don't move this insn\n" \
  1132. "andcc %%g0,0,%%g1 ! Don't move this insn\n" \
  1133. "mulscc %%g1,%3,%%g1\n" \
  1134. "mulscc %%g1,%3,%%g1\n" \
  1135. "mulscc %%g1,%3,%%g1\n" \
  1136. "mulscc %%g1,%3,%%g1\n" \
  1137. "mulscc %%g1,%3,%%g1\n" \
  1138. "mulscc %%g1,%3,%%g1\n" \
  1139. "mulscc %%g1,%3,%%g1\n" \
  1140. "mulscc %%g1,%3,%%g1\n" \
  1141. "mulscc %%g1,%3,%%g1\n" \
  1142. "mulscc %%g1,%3,%%g1\n" \
  1143. "mulscc %%g1,%3,%%g1\n" \
  1144. "mulscc %%g1,%3,%%g1\n" \
  1145. "mulscc %%g1,%3,%%g1\n" \
  1146. "mulscc %%g1,%3,%%g1\n" \
  1147. "mulscc %%g1,%3,%%g1\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,0,%%g1\n" \
  1166. "add %%g1,%%g2,%0\n" \
  1167. "rd %%y,%1" \
  1168. : "=r" ((USItype)(w1)), \
  1169. "=r" ((USItype)(w0)) \
  1170. : "%rI" ((USItype)(u)), \
  1171. "r" ((USItype)(v)) \
  1172. : "%g1", "%g2" __AND_CLOBBER_CC)
  1173. #define UMUL_TIME 39 /* 39 instructions */
  1174. /* It's quite necessary to add this much assembler for the sparc.
  1175. The default udiv_qrnnd (in C) is more than 10 times slower! */
  1176. #define udiv_qrnnd(q, r, n1, n0, d) \
  1177. __asm__ ("! Inlined udiv_qrnnd\n\t" \
  1178. "mov 32,%%g1\n\t" \
  1179. "subcc %1,%2,%%g0\n\t" \
  1180. "1: bcs 5f\n\t" \
  1181. "addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n\t" \
  1182. "sub %1,%2,%1 ! this kills msb of n\n\t" \
  1183. "addx %1,%1,%1 ! so this can't give carry\n\t" \
  1184. "subcc %%g1,1,%%g1\n\t" \
  1185. "2: bne 1b\n\t" \
  1186. "subcc %1,%2,%%g0\n\t" \
  1187. "bcs 3f\n\t" \
  1188. "addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n\t" \
  1189. "b 3f\n\t" \
  1190. "sub %1,%2,%1 ! this kills msb of n\n\t" \
  1191. "4: sub %1,%2,%1\n\t" \
  1192. "5: addxcc %1,%1,%1\n\t" \
  1193. "bcc 2b\n\t" \
  1194. "subcc %%g1,1,%%g1\n\t" \
  1195. "! Got carry from n. Subtract next step to cancel this carry.\n\t" \
  1196. "bne 4b\n\t" \
  1197. "addcc %0,%0,%0 ! shift n1n0 and a 0-bit in lsb\n\t" \
  1198. "sub %1,%2,%1\n\t" \
  1199. "3: xnor %0,0,%0\n\t" \
  1200. "! End of inline udiv_qrnnd\n" \
  1201. : "=&r" ((USItype)(q)), \
  1202. "=&r" ((USItype)(r)) \
  1203. : "r" ((USItype)(d)), \
  1204. "1" ((USItype)(n1)), \
  1205. "0" ((USItype)(n0)) : "%g1", "cc")
  1206. #define UDIV_TIME (3+7*32) /* 7 instructions/iteration. 32 iterations. */
  1207. #endif
  1208. #endif /* __sparc__ */
  1209. /***************************************
  1210. ************** VAX ******************
  1211. ***************************************/
  1212. #if defined(__vax__) && W_TYPE_SIZE == 32
  1213. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  1214. __asm__ ("addl2 %5,%1\n" \
  1215. "adwc %3,%0" \
  1216. : "=g" ((USItype)(sh)), \
  1217. "=&g" ((USItype)(sl)) \
  1218. : "%0" ((USItype)(ah)), \
  1219. "g" ((USItype)(bh)), \
  1220. "%1" ((USItype)(al)), \
  1221. "g" ((USItype)(bl)))
  1222. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  1223. __asm__ ("subl2 %5,%1\n" \
  1224. "sbwc %3,%0" \
  1225. : "=g" ((USItype)(sh)), \
  1226. "=&g" ((USItype)(sl)) \
  1227. : "0" ((USItype)(ah)), \
  1228. "g" ((USItype)(bh)), \
  1229. "1" ((USItype)(al)), \
  1230. "g" ((USItype)(bl)))
  1231. #define umul_ppmm(xh, xl, m0, m1) \
  1232. do { \
  1233. union {UDItype __ll; \
  1234. struct {USItype __l, __h; } __i; \
  1235. } __xx; \
  1236. USItype __m0 = (m0), __m1 = (m1); \
  1237. __asm__ ("emul %1,%2,$0,%0" \
  1238. : "=g" (__xx.__ll) \
  1239. : "g" (__m0), \
  1240. "g" (__m1)); \
  1241. (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
  1242. (xh) += ((((SItype) __m0 >> 31) & __m1) \
  1243. + (((SItype) __m1 >> 31) & __m0)); \
  1244. } while (0)
  1245. #define sdiv_qrnnd(q, r, n1, n0, d) \
  1246. do { \
  1247. union {DItype __ll; \
  1248. struct {SItype __l, __h; } __i; \
  1249. } __xx; \
  1250. __xx.__i.__h = n1; __xx.__i.__l = n0; \
  1251. __asm__ ("ediv %3,%2,%0,%1" \
  1252. : "=g" (q), "=g" (r) \
  1253. : "g" (__xx.__ll), "g" (d)); \
  1254. } while (0)
  1255. #endif /* __vax__ */
  1256. /***************************************
  1257. ************** Z8000 ****************
  1258. ***************************************/
  1259. #if defined(__z8000__) && W_TYPE_SIZE == 16
  1260. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  1261. __asm__ ("add %H1,%H5\n\tadc %H0,%H3" \
  1262. : "=r" ((unsigned int)(sh)), \
  1263. "=&r" ((unsigned int)(sl)) \
  1264. : "%0" ((unsigned int)(ah)), \
  1265. "r" ((unsigned int)(bh)), \
  1266. "%1" ((unsigned int)(al)), \
  1267. "rQR" ((unsigned int)(bl)))
  1268. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  1269. __asm__ ("sub %H1,%H5\n\tsbc %H0,%H3" \
  1270. : "=r" ((unsigned int)(sh)), \
  1271. "=&r" ((unsigned int)(sl)) \
  1272. : "0" ((unsigned int)(ah)), \
  1273. "r" ((unsigned int)(bh)), \
  1274. "1" ((unsigned int)(al)), \
  1275. "rQR" ((unsigned int)(bl)))
  1276. #define umul_ppmm(xh, xl, m0, m1) \
  1277. do { \
  1278. union {long int __ll; \
  1279. struct {unsigned int __h, __l; } __i; \
  1280. } __xx; \
  1281. unsigned int __m0 = (m0), __m1 = (m1); \
  1282. __asm__ ("mult %S0,%H3" \
  1283. : "=r" (__xx.__i.__h), \
  1284. "=r" (__xx.__i.__l) \
  1285. : "%1" (__m0), \
  1286. "rQR" (__m1)); \
  1287. (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
  1288. (xh) += ((((signed int) __m0 >> 15) & __m1) \
  1289. + (((signed int) __m1 >> 15) & __m0)); \
  1290. } while (0)
  1291. #endif /* __z8000__ */
  1292. #endif /* __GNUC__ */
  1293. /***************************************
  1294. *********** Generic Versions ********
  1295. ***************************************/
  1296. #if !defined(umul_ppmm) && defined(__umulsidi3)
  1297. #define umul_ppmm(ph, pl, m0, m1) \
  1298. { \
  1299. UDWtype __ll = __umulsidi3(m0, m1); \
  1300. ph = (UWtype) (__ll >> W_TYPE_SIZE); \
  1301. pl = (UWtype) __ll; \
  1302. }
  1303. #endif
  1304. #if !defined(__umulsidi3)
  1305. #define __umulsidi3(u, v) \
  1306. ({UWtype __hi, __lo; \
  1307. umul_ppmm(__hi, __lo, u, v); \
  1308. ((UDWtype) __hi << W_TYPE_SIZE) | __lo; })
  1309. #endif
  1310. /* If this machine has no inline assembler, use C macros. */
  1311. #if !defined(add_ssaaaa)
  1312. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  1313. do { \
  1314. UWtype __x; \
  1315. __x = (al) + (bl); \
  1316. (sh) = (ah) + (bh) + (__x < (al)); \
  1317. (sl) = __x; \
  1318. } while (0)
  1319. #endif
  1320. #if !defined(sub_ddmmss)
  1321. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  1322. do { \
  1323. UWtype __x; \
  1324. __x = (al) - (bl); \
  1325. (sh) = (ah) - (bh) - (__x > (al)); \
  1326. (sl) = __x; \
  1327. } while (0)
  1328. #endif
  1329. #if !defined(umul_ppmm)
  1330. #define umul_ppmm(w1, w0, u, v) \
  1331. do { \
  1332. UWtype __x0, __x1, __x2, __x3; \
  1333. UHWtype __ul, __vl, __uh, __vh; \
  1334. UWtype __u = (u), __v = (v); \
  1335. \
  1336. __ul = __ll_lowpart(__u); \
  1337. __uh = __ll_highpart(__u); \
  1338. __vl = __ll_lowpart(__v); \
  1339. __vh = __ll_highpart(__v); \
  1340. \
  1341. __x0 = (UWtype) __ul * __vl; \
  1342. __x1 = (UWtype) __ul * __vh; \
  1343. __x2 = (UWtype) __uh * __vl; \
  1344. __x3 = (UWtype) __uh * __vh; \
  1345. \
  1346. __x1 += __ll_highpart(__x0);/* this can't give carry */ \
  1347. __x1 += __x2; /* but this indeed can */ \
  1348. if (__x1 < __x2) /* did we get it? */ \
  1349. __x3 += __ll_B; /* yes, add it in the proper pos. */ \
  1350. \
  1351. (w1) = __x3 + __ll_highpart(__x1); \
  1352. (w0) = (__ll_lowpart(__x1) << W_TYPE_SIZE/2) + __ll_lowpart(__x0); \
  1353. } while (0)
  1354. #endif
  1355. #if !defined(umul_ppmm)
  1356. #define smul_ppmm(w1, w0, u, v) \
  1357. do { \
  1358. UWtype __w1; \
  1359. UWtype __m0 = (u), __m1 = (v); \
  1360. umul_ppmm(__w1, w0, __m0, __m1); \
  1361. (w1) = __w1 - (-(__m0 >> (W_TYPE_SIZE - 1)) & __m1) \
  1362. - (-(__m1 >> (W_TYPE_SIZE - 1)) & __m0); \
  1363. } while (0)
  1364. #endif
  1365. /* Define this unconditionally, so it can be used for debugging. */
  1366. #define __udiv_qrnnd_c(q, r, n1, n0, d) \
  1367. do { \
  1368. UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \
  1369. __d1 = __ll_highpart(d); \
  1370. __d0 = __ll_lowpart(d); \
  1371. \
  1372. __r1 = (n1) % __d1; \
  1373. __q1 = (n1) / __d1; \
  1374. __m = (UWtype) __q1 * __d0; \
  1375. __r1 = __r1 * __ll_B | __ll_highpart(n0); \
  1376. if (__r1 < __m) { \
  1377. __q1--, __r1 += (d); \
  1378. if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */ \
  1379. if (__r1 < __m) \
  1380. __q1--, __r1 += (d); \
  1381. } \
  1382. __r1 -= __m; \
  1383. \
  1384. __r0 = __r1 % __d1; \
  1385. __q0 = __r1 / __d1; \
  1386. __m = (UWtype) __q0 * __d0; \
  1387. __r0 = __r0 * __ll_B | __ll_lowpart(n0); \
  1388. if (__r0 < __m) { \
  1389. __q0--, __r0 += (d); \
  1390. if (__r0 >= (d)) \
  1391. if (__r0 < __m) \
  1392. __q0--, __r0 += (d); \
  1393. } \
  1394. __r0 -= __m; \
  1395. \
  1396. (q) = (UWtype) __q1 * __ll_B | __q0; \
  1397. (r) = __r0; \
  1398. } while (0)
  1399. /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
  1400. __udiv_w_sdiv (defined in libgcc or elsewhere). */
  1401. #if !defined(udiv_qrnnd) && defined(sdiv_qrnnd)
  1402. #define udiv_qrnnd(q, r, nh, nl, d) \
  1403. do { \
  1404. UWtype __r; \
  1405. (q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d); \
  1406. (r) = __r; \
  1407. } while (0)
  1408. #endif
  1409. /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
  1410. #if !defined(udiv_qrnnd)
  1411. #define UDIV_NEEDS_NORMALIZATION 1
  1412. #define udiv_qrnnd __udiv_qrnnd_c
  1413. #endif
  1414. #undef count_leading_zeros
  1415. #if !defined(count_leading_zeros)
  1416. extern
  1417. #ifdef __STDC__
  1418. const
  1419. #endif
  1420. unsigned char __clz_tab[];
  1421. #define count_leading_zeros(count, x) \
  1422. do { \
  1423. UWtype __xr = (x); \
  1424. UWtype __a; \
  1425. \
  1426. if (W_TYPE_SIZE <= 32) { \
  1427. __a = __xr < ((UWtype) 1 << 2*__BITS4) \
  1428. ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \
  1429. : (__xr < ((UWtype) 1 << 3*__BITS4) ? 2*__BITS4 : 3*__BITS4); \
  1430. } \
  1431. else { \
  1432. for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
  1433. if (((__xr >> __a) & 0xff) != 0) \
  1434. break; \
  1435. } \
  1436. \
  1437. (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
  1438. } while (0)
  1439. /* This version gives a well-defined value for zero. */
  1440. #define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
  1441. #endif
  1442. #if !defined(count_trailing_zeros)
  1443. /* Define count_trailing_zeros using count_leading_zeros. The latter might be
  1444. defined in asm, but if it is not, the C version above is good enough. */
  1445. #define count_trailing_zeros(count, x) \
  1446. do { \
  1447. UWtype __ctz_x = (x); \
  1448. UWtype __ctz_c; \
  1449. count_leading_zeros(__ctz_c, __ctz_x & -__ctz_x); \
  1450. (count) = W_TYPE_SIZE - 1 - __ctz_c; \
  1451. } while (0)
  1452. #endif
  1453. #ifndef UDIV_NEEDS_NORMALIZATION
  1454. #define UDIV_NEEDS_NORMALIZATION 0
  1455. #endif