longlong.h 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  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 <linux/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 defined(__mips_isa_rev) && __mips_isa_rev >= 6
  652. /*
  653. * GCC ends up emitting a __multi3 intrinsic call for MIPS64r6 with the plain C
  654. * code below, so we special case MIPS64r6 until the compiler can do better.
  655. */
  656. #define umul_ppmm(w1, w0, u, v) \
  657. do { \
  658. __asm__ ("dmulu %0,%1,%2" \
  659. : "=d" ((UDItype)(w0)) \
  660. : "d" ((UDItype)(u)), \
  661. "d" ((UDItype)(v))); \
  662. __asm__ ("dmuhu %0,%1,%2" \
  663. : "=d" ((UDItype)(w1)) \
  664. : "d" ((UDItype)(u)), \
  665. "d" ((UDItype)(v))); \
  666. } while (0)
  667. #elif (__GNUC__ >= 5) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 4)
  668. #define umul_ppmm(w1, w0, u, v) \
  669. do { \
  670. typedef unsigned int __ll_UTItype __attribute__((mode(TI))); \
  671. __ll_UTItype __ll = (__ll_UTItype)(u) * (v); \
  672. w1 = __ll >> 64; \
  673. w0 = __ll; \
  674. } while (0)
  675. #elif __GNUC__ > 2 || __GNUC_MINOR__ >= 7
  676. #define umul_ppmm(w1, w0, u, v) \
  677. __asm__ ("dmultu %2,%3" \
  678. : "=l" ((UDItype)(w0)), \
  679. "=h" ((UDItype)(w1)) \
  680. : "d" ((UDItype)(u)), \
  681. "d" ((UDItype)(v)))
  682. #else
  683. #define umul_ppmm(w1, w0, u, v) \
  684. __asm__ ("dmultu %2,%3\n" \
  685. "mflo %0\n" \
  686. "mfhi %1" \
  687. : "=d" ((UDItype)(w0)), \
  688. "=d" ((UDItype)(w1)) \
  689. : "d" ((UDItype)(u)), \
  690. "d" ((UDItype)(v)))
  691. #endif
  692. #define UMUL_TIME 20
  693. #define UDIV_TIME 140
  694. #endif /* __mips__ */
  695. /***************************************
  696. ************** 32000 ****************
  697. ***************************************/
  698. #if defined(__ns32000__) && W_TYPE_SIZE == 32
  699. #define umul_ppmm(w1, w0, u, v) \
  700. ({union {UDItype __ll; \
  701. struct {USItype __l, __h; } __i; \
  702. } __xx; \
  703. __asm__ ("meid %2,%0" \
  704. : "=g" (__xx.__ll) \
  705. : "%0" ((USItype)(u)), \
  706. "g" ((USItype)(v))); \
  707. (w1) = __xx.__i.__h; (w0) = __xx.__i.__l; })
  708. #define __umulsidi3(u, v) \
  709. ({UDItype __w; \
  710. __asm__ ("meid %2,%0" \
  711. : "=g" (__w) \
  712. : "%0" ((USItype)(u)), \
  713. "g" ((USItype)(v))); \
  714. __w; })
  715. #define udiv_qrnnd(q, r, n1, n0, d) \
  716. ({union {UDItype __ll; \
  717. struct {USItype __l, __h; } __i; \
  718. } __xx; \
  719. __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
  720. __asm__ ("deid %2,%0" \
  721. : "=g" (__xx.__ll) \
  722. : "0" (__xx.__ll), \
  723. "g" ((USItype)(d))); \
  724. (r) = __xx.__i.__l; (q) = __xx.__i.__h; })
  725. #endif /* __ns32000__ */
  726. /***************************************
  727. ************** PPC ******************
  728. ***************************************/
  729. #if (defined(_ARCH_PPC) || defined(_IBMR2)) && W_TYPE_SIZE == 32
  730. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  731. do { \
  732. if (__builtin_constant_p(bh) && (bh) == 0) \
  733. __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
  734. : "=r" ((USItype)(sh)), \
  735. "=&r" ((USItype)(sl)) \
  736. : "%r" ((USItype)(ah)), \
  737. "%r" ((USItype)(al)), \
  738. "rI" ((USItype)(bl))); \
  739. else if (__builtin_constant_p(bh) && (bh) == ~(USItype) 0) \
  740. __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
  741. : "=r" ((USItype)(sh)), \
  742. "=&r" ((USItype)(sl)) \
  743. : "%r" ((USItype)(ah)), \
  744. "%r" ((USItype)(al)), \
  745. "rI" ((USItype)(bl))); \
  746. else \
  747. __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
  748. : "=r" ((USItype)(sh)), \
  749. "=&r" ((USItype)(sl)) \
  750. : "%r" ((USItype)(ah)), \
  751. "r" ((USItype)(bh)), \
  752. "%r" ((USItype)(al)), \
  753. "rI" ((USItype)(bl))); \
  754. } while (0)
  755. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  756. do { \
  757. if (__builtin_constant_p(ah) && (ah) == 0) \
  758. __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
  759. : "=r" ((USItype)(sh)), \
  760. "=&r" ((USItype)(sl)) \
  761. : "r" ((USItype)(bh)), \
  762. "rI" ((USItype)(al)), \
  763. "r" ((USItype)(bl))); \
  764. else if (__builtin_constant_p(ah) && (ah) == ~(USItype) 0) \
  765. __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
  766. : "=r" ((USItype)(sh)), \
  767. "=&r" ((USItype)(sl)) \
  768. : "r" ((USItype)(bh)), \
  769. "rI" ((USItype)(al)), \
  770. "r" ((USItype)(bl))); \
  771. else if (__builtin_constant_p(bh) && (bh) == 0) \
  772. __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
  773. : "=r" ((USItype)(sh)), \
  774. "=&r" ((USItype)(sl)) \
  775. : "r" ((USItype)(ah)), \
  776. "rI" ((USItype)(al)), \
  777. "r" ((USItype)(bl))); \
  778. else if (__builtin_constant_p(bh) && (bh) == ~(USItype) 0) \
  779. __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
  780. : "=r" ((USItype)(sh)), \
  781. "=&r" ((USItype)(sl)) \
  782. : "r" ((USItype)(ah)), \
  783. "rI" ((USItype)(al)), \
  784. "r" ((USItype)(bl))); \
  785. else \
  786. __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
  787. : "=r" ((USItype)(sh)), \
  788. "=&r" ((USItype)(sl)) \
  789. : "r" ((USItype)(ah)), \
  790. "r" ((USItype)(bh)), \
  791. "rI" ((USItype)(al)), \
  792. "r" ((USItype)(bl))); \
  793. } while (0)
  794. #if defined(_ARCH_PPC)
  795. #define umul_ppmm(ph, pl, m0, m1) \
  796. do { \
  797. USItype __m0 = (m0), __m1 = (m1); \
  798. __asm__ ("mulhwu %0,%1,%2" \
  799. : "=r" ((USItype) ph) \
  800. : "%r" (__m0), \
  801. "r" (__m1)); \
  802. (pl) = __m0 * __m1; \
  803. } while (0)
  804. #define UMUL_TIME 15
  805. #define smul_ppmm(ph, pl, m0, m1) \
  806. do { \
  807. SItype __m0 = (m0), __m1 = (m1); \
  808. __asm__ ("mulhw %0,%1,%2" \
  809. : "=r" ((SItype) ph) \
  810. : "%r" (__m0), \
  811. "r" (__m1)); \
  812. (pl) = __m0 * __m1; \
  813. } while (0)
  814. #define SMUL_TIME 14
  815. #define UDIV_TIME 120
  816. #else
  817. #define umul_ppmm(xh, xl, m0, m1) \
  818. do { \
  819. USItype __m0 = (m0), __m1 = (m1); \
  820. __asm__ ("mul %0,%2,%3" \
  821. : "=r" ((USItype)(xh)), \
  822. "=q" ((USItype)(xl)) \
  823. : "r" (__m0), \
  824. "r" (__m1)); \
  825. (xh) += ((((SItype) __m0 >> 31) & __m1) \
  826. + (((SItype) __m1 >> 31) & __m0)); \
  827. } while (0)
  828. #define UMUL_TIME 8
  829. #define smul_ppmm(xh, xl, m0, m1) \
  830. __asm__ ("mul %0,%2,%3" \
  831. : "=r" ((SItype)(xh)), \
  832. "=q" ((SItype)(xl)) \
  833. : "r" (m0), \
  834. "r" (m1))
  835. #define SMUL_TIME 4
  836. #define sdiv_qrnnd(q, r, nh, nl, d) \
  837. __asm__ ("div %0,%2,%4" \
  838. : "=r" ((SItype)(q)), "=q" ((SItype)(r)) \
  839. : "r" ((SItype)(nh)), "1" ((SItype)(nl)), "r" ((SItype)(d)))
  840. #define UDIV_TIME 100
  841. #endif
  842. #endif /* Power architecture variants. */
  843. /***************************************
  844. ************** PYR ******************
  845. ***************************************/
  846. #if defined(__pyr__) && W_TYPE_SIZE == 32
  847. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  848. __asm__ ("addw %5,%1\n" \
  849. "addwc %3,%0" \
  850. : "=r" ((USItype)(sh)), \
  851. "=&r" ((USItype)(sl)) \
  852. : "%0" ((USItype)(ah)), \
  853. "g" ((USItype)(bh)), \
  854. "%1" ((USItype)(al)), \
  855. "g" ((USItype)(bl)))
  856. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  857. __asm__ ("subw %5,%1\n" \
  858. "subwb %3,%0" \
  859. : "=r" ((USItype)(sh)), \
  860. "=&r" ((USItype)(sl)) \
  861. : "0" ((USItype)(ah)), \
  862. "g" ((USItype)(bh)), \
  863. "1" ((USItype)(al)), \
  864. "g" ((USItype)(bl)))
  865. /* This insn works on Pyramids with AP, XP, or MI CPUs, but not with SP. */
  866. #define umul_ppmm(w1, w0, u, v) \
  867. ({union {UDItype __ll; \
  868. struct {USItype __h, __l; } __i; \
  869. } __xx; \
  870. __asm__ ("movw %1,%R0\n" \
  871. "uemul %2,%0" \
  872. : "=&r" (__xx.__ll) \
  873. : "g" ((USItype) (u)), \
  874. "g" ((USItype)(v))); \
  875. (w1) = __xx.__i.__h; (w0) = __xx.__i.__l; })
  876. #endif /* __pyr__ */
  877. /***************************************
  878. ************** RT/ROMP **************
  879. ***************************************/
  880. #if defined(__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
  881. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  882. __asm__ ("a %1,%5\n" \
  883. "ae %0,%3" \
  884. : "=r" ((USItype)(sh)), \
  885. "=&r" ((USItype)(sl)) \
  886. : "%0" ((USItype)(ah)), \
  887. "r" ((USItype)(bh)), \
  888. "%1" ((USItype)(al)), \
  889. "r" ((USItype)(bl)))
  890. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  891. __asm__ ("s %1,%5\n" \
  892. "se %0,%3" \
  893. : "=r" ((USItype)(sh)), \
  894. "=&r" ((USItype)(sl)) \
  895. : "0" ((USItype)(ah)), \
  896. "r" ((USItype)(bh)), \
  897. "1" ((USItype)(al)), \
  898. "r" ((USItype)(bl)))
  899. #define umul_ppmm(ph, pl, m0, m1) \
  900. do { \
  901. USItype __m0 = (m0), __m1 = (m1); \
  902. __asm__ ( \
  903. "s r2,r2\n" \
  904. "mts r10,%2\n" \
  905. "m r2,%3\n" \
  906. "m r2,%3\n" \
  907. "m r2,%3\n" \
  908. "m r2,%3\n" \
  909. "m r2,%3\n" \
  910. "m r2,%3\n" \
  911. "m r2,%3\n" \
  912. "m r2,%3\n" \
  913. "m r2,%3\n" \
  914. "m r2,%3\n" \
  915. "m r2,%3\n" \
  916. "m r2,%3\n" \
  917. "m r2,%3\n" \
  918. "m r2,%3\n" \
  919. "m r2,%3\n" \
  920. "m r2,%3\n" \
  921. "cas %0,r2,r0\n" \
  922. "mfs r10,%1" \
  923. : "=r" ((USItype)(ph)), \
  924. "=r" ((USItype)(pl)) \
  925. : "%r" (__m0), \
  926. "r" (__m1) \
  927. : "r2"); \
  928. (ph) += ((((SItype) __m0 >> 31) & __m1) \
  929. + (((SItype) __m1 >> 31) & __m0)); \
  930. } while (0)
  931. #define UMUL_TIME 20
  932. #define UDIV_TIME 200
  933. #endif /* RT/ROMP */
  934. /***************************************
  935. ************** SH2 ******************
  936. ***************************************/
  937. #if (defined(__sh2__) || defined(__sh3__) || defined(__SH4__)) \
  938. && W_TYPE_SIZE == 32
  939. #define umul_ppmm(w1, w0, u, v) \
  940. __asm__ ( \
  941. "dmulu.l %2,%3\n" \
  942. "sts macl,%1\n" \
  943. "sts mach,%0" \
  944. : "=r" ((USItype)(w1)), \
  945. "=r" ((USItype)(w0)) \
  946. : "r" ((USItype)(u)), \
  947. "r" ((USItype)(v)) \
  948. : "macl", "mach")
  949. #define UMUL_TIME 5
  950. #endif
  951. /***************************************
  952. ************** SPARC ****************
  953. ***************************************/
  954. #if defined(__sparc__) && W_TYPE_SIZE == 32
  955. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  956. __asm__ ("addcc %r4,%5,%1\n" \
  957. "addx %r2,%3,%0" \
  958. : "=r" ((USItype)(sh)), \
  959. "=&r" ((USItype)(sl)) \
  960. : "%rJ" ((USItype)(ah)), \
  961. "rI" ((USItype)(bh)), \
  962. "%rJ" ((USItype)(al)), \
  963. "rI" ((USItype)(bl)) \
  964. __CLOBBER_CC)
  965. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  966. __asm__ ("subcc %r4,%5,%1\n" \
  967. "subx %r2,%3,%0" \
  968. : "=r" ((USItype)(sh)), \
  969. "=&r" ((USItype)(sl)) \
  970. : "rJ" ((USItype)(ah)), \
  971. "rI" ((USItype)(bh)), \
  972. "rJ" ((USItype)(al)), \
  973. "rI" ((USItype)(bl)) \
  974. __CLOBBER_CC)
  975. #if defined(__sparc_v8__)
  976. /* Don't match immediate range because, 1) it is not often useful,
  977. 2) the 'I' flag thinks of the range as a 13 bit signed interval,
  978. while we want to match a 13 bit interval, sign extended to 32 bits,
  979. but INTERPRETED AS UNSIGNED. */
  980. #define umul_ppmm(w1, w0, u, v) \
  981. __asm__ ("umul %2,%3,%1;rd %%y,%0" \
  982. : "=r" ((USItype)(w1)), \
  983. "=r" ((USItype)(w0)) \
  984. : "r" ((USItype)(u)), \
  985. "r" ((USItype)(v)))
  986. #define UMUL_TIME 5
  987. #ifndef SUPERSPARC /* SuperSPARC's udiv only handles 53 bit dividends */
  988. #define udiv_qrnnd(q, r, n1, n0, d) \
  989. do { \
  990. USItype __q; \
  991. __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0" \
  992. : "=r" ((USItype)(__q)) \
  993. : "r" ((USItype)(n1)), \
  994. "r" ((USItype)(n0)), \
  995. "r" ((USItype)(d))); \
  996. (r) = (n0) - __q * (d); \
  997. (q) = __q; \
  998. } while (0)
  999. #define UDIV_TIME 25
  1000. #endif /* SUPERSPARC */
  1001. #else /* ! __sparc_v8__ */
  1002. #if defined(__sparclite__)
  1003. /* This has hardware multiply but not divide. It also has two additional
  1004. instructions scan (ffs from high bit) and divscc. */
  1005. #define umul_ppmm(w1, w0, u, v) \
  1006. __asm__ ("umul %2,%3,%1;rd %%y,%0" \
  1007. : "=r" ((USItype)(w1)), \
  1008. "=r" ((USItype)(w0)) \
  1009. : "r" ((USItype)(u)), \
  1010. "r" ((USItype)(v)))
  1011. #define UMUL_TIME 5
  1012. #define udiv_qrnnd(q, r, n1, n0, d) \
  1013. __asm__ ("! Inlined udiv_qrnnd\n" \
  1014. "wr %%g0,%2,%%y ! Not a delayed write for sparclite\n" \
  1015. "tst %%g0\n" \
  1016. "divscc %3,%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,%%g1\n" \
  1032. "divscc %%g1,%4,%%g1\n" \
  1033. "divscc %%g1,%4,%%g1\n" \
  1034. "divscc %%g1,%4,%%g1\n" \
  1035. "divscc %%g1,%4,%%g1\n" \
  1036. "divscc %%g1,%4,%%g1\n" \
  1037. "divscc %%g1,%4,%%g1\n" \
  1038. "divscc %%g1,%4,%%g1\n" \
  1039. "divscc %%g1,%4,%%g1\n" \
  1040. "divscc %%g1,%4,%%g1\n" \
  1041. "divscc %%g1,%4,%%g1\n" \
  1042. "divscc %%g1,%4,%%g1\n" \
  1043. "divscc %%g1,%4,%%g1\n" \
  1044. "divscc %%g1,%4,%%g1\n" \
  1045. "divscc %%g1,%4,%%g1\n" \
  1046. "divscc %%g1,%4,%%g1\n" \
  1047. "divscc %%g1,%4,%0\n" \
  1048. "rd %%y,%1\n" \
  1049. "bl,a 1f\n" \
  1050. "add %1,%4,%1\n" \
  1051. "1: ! End of inline udiv_qrnnd" \
  1052. : "=r" ((USItype)(q)), \
  1053. "=r" ((USItype)(r)) \
  1054. : "r" ((USItype)(n1)), \
  1055. "r" ((USItype)(n0)), \
  1056. "rI" ((USItype)(d)) \
  1057. : "%g1" __AND_CLOBBER_CC)
  1058. #define UDIV_TIME 37
  1059. #endif /* __sparclite__ */
  1060. #endif /* __sparc_v8__ */
  1061. /* Default to sparc v7 versions of umul_ppmm and udiv_qrnnd. */
  1062. #ifndef umul_ppmm
  1063. #define umul_ppmm(w1, w0, u, v) \
  1064. __asm__ ("! Inlined umul_ppmm\n" \
  1065. "wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr\n" \
  1066. "sra %3,31,%%g2 ! Don't move this insn\n" \
  1067. "and %2,%%g2,%%g2 ! Don't move this insn\n" \
  1068. "andcc %%g0,0,%%g1 ! Don't move this insn\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,%3,%%g1\n" \
  1086. "mulscc %%g1,%3,%%g1\n" \
  1087. "mulscc %%g1,%3,%%g1\n" \
  1088. "mulscc %%g1,%3,%%g1\n" \
  1089. "mulscc %%g1,%3,%%g1\n" \
  1090. "mulscc %%g1,%3,%%g1\n" \
  1091. "mulscc %%g1,%3,%%g1\n" \
  1092. "mulscc %%g1,%3,%%g1\n" \
  1093. "mulscc %%g1,%3,%%g1\n" \
  1094. "mulscc %%g1,%3,%%g1\n" \
  1095. "mulscc %%g1,%3,%%g1\n" \
  1096. "mulscc %%g1,%3,%%g1\n" \
  1097. "mulscc %%g1,%3,%%g1\n" \
  1098. "mulscc %%g1,%3,%%g1\n" \
  1099. "mulscc %%g1,%3,%%g1\n" \
  1100. "mulscc %%g1,%3,%%g1\n" \
  1101. "mulscc %%g1,0,%%g1\n" \
  1102. "add %%g1,%%g2,%0\n" \
  1103. "rd %%y,%1" \
  1104. : "=r" ((USItype)(w1)), \
  1105. "=r" ((USItype)(w0)) \
  1106. : "%rI" ((USItype)(u)), \
  1107. "r" ((USItype)(v)) \
  1108. : "%g1", "%g2" __AND_CLOBBER_CC)
  1109. #define UMUL_TIME 39 /* 39 instructions */
  1110. /* It's quite necessary to add this much assembler for the sparc.
  1111. The default udiv_qrnnd (in C) is more than 10 times slower! */
  1112. #define udiv_qrnnd(q, r, n1, n0, d) \
  1113. __asm__ ("! Inlined udiv_qrnnd\n\t" \
  1114. "mov 32,%%g1\n\t" \
  1115. "subcc %1,%2,%%g0\n\t" \
  1116. "1: bcs 5f\n\t" \
  1117. "addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n\t" \
  1118. "sub %1,%2,%1 ! this kills msb of n\n\t" \
  1119. "addx %1,%1,%1 ! so this can't give carry\n\t" \
  1120. "subcc %%g1,1,%%g1\n\t" \
  1121. "2: bne 1b\n\t" \
  1122. "subcc %1,%2,%%g0\n\t" \
  1123. "bcs 3f\n\t" \
  1124. "addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n\t" \
  1125. "b 3f\n\t" \
  1126. "sub %1,%2,%1 ! this kills msb of n\n\t" \
  1127. "4: sub %1,%2,%1\n\t" \
  1128. "5: addxcc %1,%1,%1\n\t" \
  1129. "bcc 2b\n\t" \
  1130. "subcc %%g1,1,%%g1\n\t" \
  1131. "! Got carry from n. Subtract next step to cancel this carry.\n\t" \
  1132. "bne 4b\n\t" \
  1133. "addcc %0,%0,%0 ! shift n1n0 and a 0-bit in lsb\n\t" \
  1134. "sub %1,%2,%1\n\t" \
  1135. "3: xnor %0,0,%0\n\t" \
  1136. "! End of inline udiv_qrnnd\n" \
  1137. : "=&r" ((USItype)(q)), \
  1138. "=&r" ((USItype)(r)) \
  1139. : "r" ((USItype)(d)), \
  1140. "1" ((USItype)(n1)), \
  1141. "0" ((USItype)(n0)) : "%g1", "cc")
  1142. #define UDIV_TIME (3+7*32) /* 7 instructions/iteration. 32 iterations. */
  1143. #endif
  1144. #endif /* __sparc__ */
  1145. /***************************************
  1146. ************** VAX ******************
  1147. ***************************************/
  1148. #if defined(__vax__) && W_TYPE_SIZE == 32
  1149. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  1150. __asm__ ("addl2 %5,%1\n" \
  1151. "adwc %3,%0" \
  1152. : "=g" ((USItype)(sh)), \
  1153. "=&g" ((USItype)(sl)) \
  1154. : "%0" ((USItype)(ah)), \
  1155. "g" ((USItype)(bh)), \
  1156. "%1" ((USItype)(al)), \
  1157. "g" ((USItype)(bl)))
  1158. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  1159. __asm__ ("subl2 %5,%1\n" \
  1160. "sbwc %3,%0" \
  1161. : "=g" ((USItype)(sh)), \
  1162. "=&g" ((USItype)(sl)) \
  1163. : "0" ((USItype)(ah)), \
  1164. "g" ((USItype)(bh)), \
  1165. "1" ((USItype)(al)), \
  1166. "g" ((USItype)(bl)))
  1167. #define umul_ppmm(xh, xl, m0, m1) \
  1168. do { \
  1169. union {UDItype __ll; \
  1170. struct {USItype __l, __h; } __i; \
  1171. } __xx; \
  1172. USItype __m0 = (m0), __m1 = (m1); \
  1173. __asm__ ("emul %1,%2,$0,%0" \
  1174. : "=g" (__xx.__ll) \
  1175. : "g" (__m0), \
  1176. "g" (__m1)); \
  1177. (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
  1178. (xh) += ((((SItype) __m0 >> 31) & __m1) \
  1179. + (((SItype) __m1 >> 31) & __m0)); \
  1180. } while (0)
  1181. #define sdiv_qrnnd(q, r, n1, n0, d) \
  1182. do { \
  1183. union {DItype __ll; \
  1184. struct {SItype __l, __h; } __i; \
  1185. } __xx; \
  1186. __xx.__i.__h = n1; __xx.__i.__l = n0; \
  1187. __asm__ ("ediv %3,%2,%0,%1" \
  1188. : "=g" (q), "=g" (r) \
  1189. : "g" (__xx.__ll), "g" (d)); \
  1190. } while (0)
  1191. #endif /* __vax__ */
  1192. /***************************************
  1193. ************** Z8000 ****************
  1194. ***************************************/
  1195. #if defined(__z8000__) && W_TYPE_SIZE == 16
  1196. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  1197. __asm__ ("add %H1,%H5\n\tadc %H0,%H3" \
  1198. : "=r" ((unsigned int)(sh)), \
  1199. "=&r" ((unsigned int)(sl)) \
  1200. : "%0" ((unsigned int)(ah)), \
  1201. "r" ((unsigned int)(bh)), \
  1202. "%1" ((unsigned int)(al)), \
  1203. "rQR" ((unsigned int)(bl)))
  1204. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  1205. __asm__ ("sub %H1,%H5\n\tsbc %H0,%H3" \
  1206. : "=r" ((unsigned int)(sh)), \
  1207. "=&r" ((unsigned int)(sl)) \
  1208. : "0" ((unsigned int)(ah)), \
  1209. "r" ((unsigned int)(bh)), \
  1210. "1" ((unsigned int)(al)), \
  1211. "rQR" ((unsigned int)(bl)))
  1212. #define umul_ppmm(xh, xl, m0, m1) \
  1213. do { \
  1214. union {long int __ll; \
  1215. struct {unsigned int __h, __l; } __i; \
  1216. } __xx; \
  1217. unsigned int __m0 = (m0), __m1 = (m1); \
  1218. __asm__ ("mult %S0,%H3" \
  1219. : "=r" (__xx.__i.__h), \
  1220. "=r" (__xx.__i.__l) \
  1221. : "%1" (__m0), \
  1222. "rQR" (__m1)); \
  1223. (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
  1224. (xh) += ((((signed int) __m0 >> 15) & __m1) \
  1225. + (((signed int) __m1 >> 15) & __m0)); \
  1226. } while (0)
  1227. #endif /* __z8000__ */
  1228. #endif /* __GNUC__ */
  1229. /***************************************
  1230. *********** Generic Versions ********
  1231. ***************************************/
  1232. #if !defined(umul_ppmm) && defined(__umulsidi3)
  1233. #define umul_ppmm(ph, pl, m0, m1) \
  1234. { \
  1235. UDWtype __ll = __umulsidi3(m0, m1); \
  1236. ph = (UWtype) (__ll >> W_TYPE_SIZE); \
  1237. pl = (UWtype) __ll; \
  1238. }
  1239. #endif
  1240. #if !defined(__umulsidi3)
  1241. #define __umulsidi3(u, v) \
  1242. ({UWtype __hi, __lo; \
  1243. umul_ppmm(__hi, __lo, u, v); \
  1244. ((UDWtype) __hi << W_TYPE_SIZE) | __lo; })
  1245. #endif
  1246. /* If this machine has no inline assembler, use C macros. */
  1247. #if !defined(add_ssaaaa)
  1248. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  1249. do { \
  1250. UWtype __x; \
  1251. __x = (al) + (bl); \
  1252. (sh) = (ah) + (bh) + (__x < (al)); \
  1253. (sl) = __x; \
  1254. } while (0)
  1255. #endif
  1256. #if !defined(sub_ddmmss)
  1257. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  1258. do { \
  1259. UWtype __x; \
  1260. __x = (al) - (bl); \
  1261. (sh) = (ah) - (bh) - (__x > (al)); \
  1262. (sl) = __x; \
  1263. } while (0)
  1264. #endif
  1265. #if !defined(umul_ppmm)
  1266. #define umul_ppmm(w1, w0, u, v) \
  1267. do { \
  1268. UWtype __x0, __x1, __x2, __x3; \
  1269. UHWtype __ul, __vl, __uh, __vh; \
  1270. UWtype __u = (u), __v = (v); \
  1271. \
  1272. __ul = __ll_lowpart(__u); \
  1273. __uh = __ll_highpart(__u); \
  1274. __vl = __ll_lowpart(__v); \
  1275. __vh = __ll_highpart(__v); \
  1276. \
  1277. __x0 = (UWtype) __ul * __vl; \
  1278. __x1 = (UWtype) __ul * __vh; \
  1279. __x2 = (UWtype) __uh * __vl; \
  1280. __x3 = (UWtype) __uh * __vh; \
  1281. \
  1282. __x1 += __ll_highpart(__x0);/* this can't give carry */ \
  1283. __x1 += __x2; /* but this indeed can */ \
  1284. if (__x1 < __x2) /* did we get it? */ \
  1285. __x3 += __ll_B; /* yes, add it in the proper pos. */ \
  1286. \
  1287. (w1) = __x3 + __ll_highpart(__x1); \
  1288. (w0) = (__ll_lowpart(__x1) << W_TYPE_SIZE/2) + __ll_lowpart(__x0); \
  1289. } while (0)
  1290. #endif
  1291. #if !defined(umul_ppmm)
  1292. #define smul_ppmm(w1, w0, u, v) \
  1293. do { \
  1294. UWtype __w1; \
  1295. UWtype __m0 = (u), __m1 = (v); \
  1296. umul_ppmm(__w1, w0, __m0, __m1); \
  1297. (w1) = __w1 - (-(__m0 >> (W_TYPE_SIZE - 1)) & __m1) \
  1298. - (-(__m1 >> (W_TYPE_SIZE - 1)) & __m0); \
  1299. } while (0)
  1300. #endif
  1301. /* Define this unconditionally, so it can be used for debugging. */
  1302. #define __udiv_qrnnd_c(q, r, n1, n0, d) \
  1303. do { \
  1304. UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \
  1305. __d1 = __ll_highpart(d); \
  1306. __d0 = __ll_lowpart(d); \
  1307. \
  1308. __r1 = (n1) % __d1; \
  1309. __q1 = (n1) / __d1; \
  1310. __m = (UWtype) __q1 * __d0; \
  1311. __r1 = __r1 * __ll_B | __ll_highpart(n0); \
  1312. if (__r1 < __m) { \
  1313. __q1--, __r1 += (d); \
  1314. if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */ \
  1315. if (__r1 < __m) \
  1316. __q1--, __r1 += (d); \
  1317. } \
  1318. __r1 -= __m; \
  1319. \
  1320. __r0 = __r1 % __d1; \
  1321. __q0 = __r1 / __d1; \
  1322. __m = (UWtype) __q0 * __d0; \
  1323. __r0 = __r0 * __ll_B | __ll_lowpart(n0); \
  1324. if (__r0 < __m) { \
  1325. __q0--, __r0 += (d); \
  1326. if (__r0 >= (d)) \
  1327. if (__r0 < __m) \
  1328. __q0--, __r0 += (d); \
  1329. } \
  1330. __r0 -= __m; \
  1331. \
  1332. (q) = (UWtype) __q1 * __ll_B | __q0; \
  1333. (r) = __r0; \
  1334. } while (0)
  1335. /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
  1336. __udiv_w_sdiv (defined in libgcc or elsewhere). */
  1337. #if !defined(udiv_qrnnd) && defined(sdiv_qrnnd)
  1338. #define udiv_qrnnd(q, r, nh, nl, d) \
  1339. do { \
  1340. UWtype __r; \
  1341. (q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d); \
  1342. (r) = __r; \
  1343. } while (0)
  1344. #endif
  1345. /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
  1346. #if !defined(udiv_qrnnd)
  1347. #define UDIV_NEEDS_NORMALIZATION 1
  1348. #define udiv_qrnnd __udiv_qrnnd_c
  1349. #endif
  1350. #ifndef UDIV_NEEDS_NORMALIZATION
  1351. #define UDIV_NEEDS_NORMALIZATION 0
  1352. #endif