longlong.h 40 KB

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