longlong.h 39 KB

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