longlong.h 42 KB

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