longlong.h 40 KB

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