div_const.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /* 32 and 64-bit millicode, original author Hewlett-Packard
  2. adapted for gcc by Paul Bame <bame@debian.org>
  3. and Alan Modra <alan@linuxcare.com.au>.
  4. Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
  5. This file is part of GCC and is released under the terms of
  6. of the GNU General Public License as published by the Free Software
  7. Foundation; either version 2, or (at your option) any later version.
  8. See the file COPYING in the top-level GCC source directory for a copy
  9. of the license. */
  10. #include "milli.h"
  11. #ifdef L_div_const
  12. /* ROUTINE: $$divI_2
  13. . $$divI_3 $$divU_3
  14. . $$divI_4
  15. . $$divI_5 $$divU_5
  16. . $$divI_6 $$divU_6
  17. . $$divI_7 $$divU_7
  18. . $$divI_8
  19. . $$divI_9 $$divU_9
  20. . $$divI_10 $$divU_10
  21. .
  22. . $$divI_12 $$divU_12
  23. .
  24. . $$divI_14 $$divU_14
  25. . $$divI_15 $$divU_15
  26. . $$divI_16
  27. . $$divI_17 $$divU_17
  28. .
  29. . Divide by selected constants for single precision binary integers.
  30. INPUT REGISTERS:
  31. . arg0 == dividend
  32. . mrp == return pc
  33. . sr0 == return space when called externally
  34. OUTPUT REGISTERS:
  35. . arg0 = undefined
  36. . arg1 = undefined
  37. . ret1 = quotient
  38. OTHER REGISTERS AFFECTED:
  39. . r1 = undefined
  40. SIDE EFFECTS:
  41. . Causes a trap under the following conditions: NONE
  42. . Changes memory at the following places: NONE
  43. PERMISSIBLE CONTEXT:
  44. . Unwindable.
  45. . Does not create a stack frame.
  46. . Suitable for internal or external millicode.
  47. . Assumes the special millicode register conventions.
  48. DISCUSSION:
  49. . Calls other millicode routines using mrp: NONE
  50. . Calls other millicode routines: NONE */
  51. /* TRUNCATED DIVISION BY SMALL INTEGERS
  52. We are interested in q(x) = floor(x/y), where x >= 0 and y > 0
  53. (with y fixed).
  54. Let a = floor(z/y), for some choice of z. Note that z will be
  55. chosen so that division by z is cheap.
  56. Let r be the remainder(z/y). In other words, r = z - ay.
  57. Now, our method is to choose a value for b such that
  58. q'(x) = floor((ax+b)/z)
  59. is equal to q(x) over as large a range of x as possible. If the
  60. two are equal over a sufficiently large range, and if it is easy to
  61. form the product (ax), and it is easy to divide by z, then we can
  62. perform the division much faster than the general division algorithm.
  63. So, we want the following to be true:
  64. . For x in the following range:
  65. .
  66. . ky <= x < (k+1)y
  67. .
  68. . implies that
  69. .
  70. . k <= (ax+b)/z < (k+1)
  71. We want to determine b such that this is true for all k in the
  72. range {0..K} for some maximum K.
  73. Since (ax+b) is an increasing function of x, we can take each
  74. bound separately to determine the "best" value for b.
  75. (ax+b)/z < (k+1) implies
  76. (a((k+1)y-1)+b < (k+1)z implies
  77. b < a + (k+1)(z-ay) implies
  78. b < a + (k+1)r
  79. This needs to be true for all k in the range {0..K}. In
  80. particular, it is true for k = 0 and this leads to a maximum
  81. acceptable value for b.
  82. b < a+r or b <= a+r-1
  83. Taking the other bound, we have
  84. k <= (ax+b)/z implies
  85. k <= (aky+b)/z implies
  86. k(z-ay) <= b implies
  87. kr <= b
  88. Clearly, the largest range for k will be achieved by maximizing b,
  89. when r is not zero. When r is zero, then the simplest choice for b
  90. is 0. When r is not 0, set
  91. . b = a+r-1
  92. Now, by construction, q'(x) = floor((ax+b)/z) = q(x) = floor(x/y)
  93. for all x in the range:
  94. . 0 <= x < (K+1)y
  95. We need to determine what K is. Of our two bounds,
  96. . b < a+(k+1)r is satisfied for all k >= 0, by construction.
  97. The other bound is
  98. . kr <= b
  99. This is always true if r = 0. If r is not 0 (the usual case), then
  100. K = floor((a+r-1)/r), is the maximum value for k.
  101. Therefore, the formula q'(x) = floor((ax+b)/z) yields the correct
  102. answer for q(x) = floor(x/y) when x is in the range
  103. (0,(K+1)y-1) K = floor((a+r-1)/r)
  104. To be most useful, we want (K+1)y-1 = (max x) >= 2**32-1 so that
  105. the formula for q'(x) yields the correct value of q(x) for all x
  106. representable by a single word in HPPA.
  107. We are also constrained in that computing the product (ax), adding
  108. b, and dividing by z must all be done quickly, otherwise we will be
  109. better off going through the general algorithm using the DS
  110. instruction, which uses approximately 70 cycles.
  111. For each y, there is a choice of z which satisfies the constraints
  112. for (K+1)y >= 2**32. We may not, however, be able to satisfy the
  113. timing constraints for arbitrary y. It seems that z being equal to
  114. a power of 2 or a power of 2 minus 1 is as good as we can do, since
  115. it minimizes the time to do division by z. We want the choice of z
  116. to also result in a value for (a) that minimizes the computation of
  117. the product (ax). This is best achieved if (a) has a regular bit
  118. pattern (so the multiplication can be done with shifts and adds).
  119. The value of (a) also needs to be less than 2**32 so the product is
  120. always guaranteed to fit in 2 words.
  121. In actual practice, the following should be done:
  122. 1) For negative x, you should take the absolute value and remember
  123. . the fact so that the result can be negated. This obviously does
  124. . not apply in the unsigned case.
  125. 2) For even y, you should factor out the power of 2 that divides y
  126. . and divide x by it. You can then proceed by dividing by the
  127. . odd factor of y.
  128. Here is a table of some odd values of y, and corresponding choices
  129. for z which are "good".
  130. y z r a (hex) max x (hex)
  131. 3 2**32 1 55555555 100000001
  132. 5 2**32 1 33333333 100000003
  133. 7 2**24-1 0 249249 (infinite)
  134. 9 2**24-1 0 1c71c7 (infinite)
  135. 11 2**20-1 0 1745d (infinite)
  136. 13 2**24-1 0 13b13b (infinite)
  137. 15 2**32 1 11111111 10000000d
  138. 17 2**32 1 f0f0f0f 10000000f
  139. If r is 1, then b = a+r-1 = a. This simplifies the computation
  140. of (ax+b), since you can compute (x+1)(a) instead. If r is 0,
  141. then b = 0 is ok to use which simplifies (ax+b).
  142. The bit patterns for 55555555, 33333333, and 11111111 are obviously
  143. very regular. The bit patterns for the other values of a above are:
  144. y (hex) (binary)
  145. 7 249249 001001001001001001001001 << regular >>
  146. 9 1c71c7 000111000111000111000111 << regular >>
  147. 11 1745d 000000010111010001011101 << irregular >>
  148. 13 13b13b 000100111011000100111011 << irregular >>
  149. The bit patterns for (a) corresponding to (y) of 11 and 13 may be
  150. too irregular to warrant using this method.
  151. When z is a power of 2 minus 1, then the division by z is slightly
  152. more complicated, involving an iterative solution.
  153. The code presented here solves division by 1 through 17, except for
  154. 11 and 13. There are algorithms for both signed and unsigned
  155. quantities given.
  156. TIMINGS (cycles)
  157. divisor positive negative unsigned
  158. . 1 2 2 2
  159. . 2 4 4 2
  160. . 3 19 21 19
  161. . 4 4 4 2
  162. . 5 18 22 19
  163. . 6 19 22 19
  164. . 8 4 4 2
  165. . 10 18 19 17
  166. . 12 18 20 18
  167. . 15 16 18 16
  168. . 16 4 4 2
  169. . 17 16 18 16
  170. Now, the algorithm for 7, 9, and 14 is an iterative one. That is,
  171. a loop body is executed until the tentative quotient is 0. The
  172. number of times the loop body is executed varies depending on the
  173. dividend, but is never more than two times. If the dividend is
  174. less than the divisor, then the loop body is not executed at all.
  175. Each iteration adds 4 cycles to the timings.
  176. divisor positive negative unsigned
  177. . 7 19+4n 20+4n 20+4n n = number of iterations
  178. . 9 21+4n 22+4n 21+4n
  179. . 14 21+4n 22+4n 20+4n
  180. To give an idea of how the number of iterations varies, here is a
  181. table of dividend versus number of iterations when dividing by 7.
  182. smallest largest required
  183. dividend dividend iterations
  184. . 0 6 0
  185. . 7 0x6ffffff 1
  186. 0x1000006 0xffffffff 2
  187. There is some overlap in the range of numbers requiring 1 and 2
  188. iterations. */
  189. RDEFINE(t2,r1)
  190. RDEFINE(x2,arg0) /* r26 */
  191. RDEFINE(t1,arg1) /* r25 */
  192. RDEFINE(x1,ret1) /* r29 */
  193. SUBSPA_MILLI_DIV
  194. ATTR_MILLI
  195. .proc
  196. .callinfo millicode
  197. .entry
  198. /* NONE of these routines require a stack frame
  199. ALL of these routines are unwindable from millicode */
  200. GSYM($$divide_by_constant)
  201. .export $$divide_by_constant,millicode
  202. /* Provides a "nice" label for the code covered by the unwind descriptor
  203. for things like gprof. */
  204. /* DIVISION BY 2 (shift by 1) */
  205. GSYM($$divI_2)
  206. .export $$divI_2,millicode
  207. comclr,>= arg0,0,0
  208. addi 1,arg0,arg0
  209. MILLIRET
  210. extrs arg0,30,31,ret1
  211. /* DIVISION BY 4 (shift by 2) */
  212. GSYM($$divI_4)
  213. .export $$divI_4,millicode
  214. comclr,>= arg0,0,0
  215. addi 3,arg0,arg0
  216. MILLIRET
  217. extrs arg0,29,30,ret1
  218. /* DIVISION BY 8 (shift by 3) */
  219. GSYM($$divI_8)
  220. .export $$divI_8,millicode
  221. comclr,>= arg0,0,0
  222. addi 7,arg0,arg0
  223. MILLIRET
  224. extrs arg0,28,29,ret1
  225. /* DIVISION BY 16 (shift by 4) */
  226. GSYM($$divI_16)
  227. .export $$divI_16,millicode
  228. comclr,>= arg0,0,0
  229. addi 15,arg0,arg0
  230. MILLIRET
  231. extrs arg0,27,28,ret1
  232. /****************************************************************************
  233. *
  234. * DIVISION BY DIVISORS OF FFFFFFFF, and powers of 2 times these
  235. *
  236. * includes 3,5,15,17 and also 6,10,12
  237. *
  238. ****************************************************************************/
  239. /* DIVISION BY 3 (use z = 2**32; a = 55555555) */
  240. GSYM($$divI_3)
  241. .export $$divI_3,millicode
  242. comb,<,N x2,0,LREF(neg3)
  243. addi 1,x2,x2 /* this cannot overflow */
  244. extru x2,1,2,x1 /* multiply by 5 to get started */
  245. sh2add x2,x2,x2
  246. b LREF(pos)
  247. addc x1,0,x1
  248. LSYM(neg3)
  249. subi 1,x2,x2 /* this cannot overflow */
  250. extru x2,1,2,x1 /* multiply by 5 to get started */
  251. sh2add x2,x2,x2
  252. b LREF(neg)
  253. addc x1,0,x1
  254. GSYM($$divU_3)
  255. .export $$divU_3,millicode
  256. addi 1,x2,x2 /* this CAN overflow */
  257. addc 0,0,x1
  258. shd x1,x2,30,t1 /* multiply by 5 to get started */
  259. sh2add x2,x2,x2
  260. b LREF(pos)
  261. addc x1,t1,x1
  262. /* DIVISION BY 5 (use z = 2**32; a = 33333333) */
  263. GSYM($$divI_5)
  264. .export $$divI_5,millicode
  265. comb,<,N x2,0,LREF(neg5)
  266. addi 3,x2,t1 /* this cannot overflow */
  267. sh1add x2,t1,x2 /* multiply by 3 to get started */
  268. b LREF(pos)
  269. addc 0,0,x1
  270. LSYM(neg5)
  271. sub 0,x2,x2 /* negate x2 */
  272. addi 1,x2,x2 /* this cannot overflow */
  273. shd 0,x2,31,x1 /* get top bit (can be 1) */
  274. sh1add x2,x2,x2 /* multiply by 3 to get started */
  275. b LREF(neg)
  276. addc x1,0,x1
  277. GSYM($$divU_5)
  278. .export $$divU_5,millicode
  279. addi 1,x2,x2 /* this CAN overflow */
  280. addc 0,0,x1
  281. shd x1,x2,31,t1 /* multiply by 3 to get started */
  282. sh1add x2,x2,x2
  283. b LREF(pos)
  284. addc t1,x1,x1
  285. /* DIVISION BY 6 (shift to divide by 2 then divide by 3) */
  286. GSYM($$divI_6)
  287. .export $$divI_6,millicode
  288. comb,<,N x2,0,LREF(neg6)
  289. extru x2,30,31,x2 /* divide by 2 */
  290. addi 5,x2,t1 /* compute 5*(x2+1) = 5*x2+5 */
  291. sh2add x2,t1,x2 /* multiply by 5 to get started */
  292. b LREF(pos)
  293. addc 0,0,x1
  294. LSYM(neg6)
  295. subi 2,x2,x2 /* negate, divide by 2, and add 1 */
  296. /* negation and adding 1 are done */
  297. /* at the same time by the SUBI */
  298. extru x2,30,31,x2
  299. shd 0,x2,30,x1
  300. sh2add x2,x2,x2 /* multiply by 5 to get started */
  301. b LREF(neg)
  302. addc x1,0,x1
  303. GSYM($$divU_6)
  304. .export $$divU_6,millicode
  305. extru x2,30,31,x2 /* divide by 2 */
  306. addi 1,x2,x2 /* cannot carry */
  307. shd 0,x2,30,x1 /* multiply by 5 to get started */
  308. sh2add x2,x2,x2
  309. b LREF(pos)
  310. addc x1,0,x1
  311. /* DIVISION BY 10 (shift to divide by 2 then divide by 5) */
  312. GSYM($$divU_10)
  313. .export $$divU_10,millicode
  314. extru x2,30,31,x2 /* divide by 2 */
  315. addi 3,x2,t1 /* compute 3*(x2+1) = (3*x2)+3 */
  316. sh1add x2,t1,x2 /* multiply by 3 to get started */
  317. addc 0,0,x1
  318. LSYM(pos)
  319. shd x1,x2,28,t1 /* multiply by 0x11 */
  320. shd x2,0,28,t2
  321. add x2,t2,x2
  322. addc x1,t1,x1
  323. LSYM(pos_for_17)
  324. shd x1,x2,24,t1 /* multiply by 0x101 */
  325. shd x2,0,24,t2
  326. add x2,t2,x2
  327. addc x1,t1,x1
  328. shd x1,x2,16,t1 /* multiply by 0x10001 */
  329. shd x2,0,16,t2
  330. add x2,t2,x2
  331. MILLIRET
  332. addc x1,t1,x1
  333. GSYM($$divI_10)
  334. .export $$divI_10,millicode
  335. comb,< x2,0,LREF(neg10)
  336. copy 0,x1
  337. extru x2,30,31,x2 /* divide by 2 */
  338. addib,TR 1,x2,LREF(pos) /* add 1 (cannot overflow) */
  339. sh1add x2,x2,x2 /* multiply by 3 to get started */
  340. LSYM(neg10)
  341. subi 2,x2,x2 /* negate, divide by 2, and add 1 */
  342. /* negation and adding 1 are done */
  343. /* at the same time by the SUBI */
  344. extru x2,30,31,x2
  345. sh1add x2,x2,x2 /* multiply by 3 to get started */
  346. LSYM(neg)
  347. shd x1,x2,28,t1 /* multiply by 0x11 */
  348. shd x2,0,28,t2
  349. add x2,t2,x2
  350. addc x1,t1,x1
  351. LSYM(neg_for_17)
  352. shd x1,x2,24,t1 /* multiply by 0x101 */
  353. shd x2,0,24,t2
  354. add x2,t2,x2
  355. addc x1,t1,x1
  356. shd x1,x2,16,t1 /* multiply by 0x10001 */
  357. shd x2,0,16,t2
  358. add x2,t2,x2
  359. addc x1,t1,x1
  360. MILLIRET
  361. sub 0,x1,x1
  362. /* DIVISION BY 12 (shift to divide by 4 then divide by 3) */
  363. GSYM($$divI_12)
  364. .export $$divI_12,millicode
  365. comb,< x2,0,LREF(neg12)
  366. copy 0,x1
  367. extru x2,29,30,x2 /* divide by 4 */
  368. addib,tr 1,x2,LREF(pos) /* compute 5*(x2+1) = 5*x2+5 */
  369. sh2add x2,x2,x2 /* multiply by 5 to get started */
  370. LSYM(neg12)
  371. subi 4,x2,x2 /* negate, divide by 4, and add 1 */
  372. /* negation and adding 1 are done */
  373. /* at the same time by the SUBI */
  374. extru x2,29,30,x2
  375. b LREF(neg)
  376. sh2add x2,x2,x2 /* multiply by 5 to get started */
  377. GSYM($$divU_12)
  378. .export $$divU_12,millicode
  379. extru x2,29,30,x2 /* divide by 4 */
  380. addi 5,x2,t1 /* cannot carry */
  381. sh2add x2,t1,x2 /* multiply by 5 to get started */
  382. b LREF(pos)
  383. addc 0,0,x1
  384. /* DIVISION BY 15 (use z = 2**32; a = 11111111) */
  385. GSYM($$divI_15)
  386. .export $$divI_15,millicode
  387. comb,< x2,0,LREF(neg15)
  388. copy 0,x1
  389. addib,tr 1,x2,LREF(pos)+4
  390. shd x1,x2,28,t1
  391. LSYM(neg15)
  392. b LREF(neg)
  393. subi 1,x2,x2
  394. GSYM($$divU_15)
  395. .export $$divU_15,millicode
  396. addi 1,x2,x2 /* this CAN overflow */
  397. b LREF(pos)
  398. addc 0,0,x1
  399. /* DIVISION BY 17 (use z = 2**32; a = f0f0f0f) */
  400. GSYM($$divI_17)
  401. .export $$divI_17,millicode
  402. comb,<,n x2,0,LREF(neg17)
  403. addi 1,x2,x2 /* this cannot overflow */
  404. shd 0,x2,28,t1 /* multiply by 0xf to get started */
  405. shd x2,0,28,t2
  406. sub t2,x2,x2
  407. b LREF(pos_for_17)
  408. subb t1,0,x1
  409. LSYM(neg17)
  410. subi 1,x2,x2 /* this cannot overflow */
  411. shd 0,x2,28,t1 /* multiply by 0xf to get started */
  412. shd x2,0,28,t2
  413. sub t2,x2,x2
  414. b LREF(neg_for_17)
  415. subb t1,0,x1
  416. GSYM($$divU_17)
  417. .export $$divU_17,millicode
  418. addi 1,x2,x2 /* this CAN overflow */
  419. addc 0,0,x1
  420. shd x1,x2,28,t1 /* multiply by 0xf to get started */
  421. LSYM(u17)
  422. shd x2,0,28,t2
  423. sub t2,x2,x2
  424. b LREF(pos_for_17)
  425. subb t1,x1,x1
  426. /* DIVISION BY DIVISORS OF FFFFFF, and powers of 2 times these
  427. includes 7,9 and also 14
  428. z = 2**24-1
  429. r = z mod x = 0
  430. so choose b = 0
  431. Also, in order to divide by z = 2**24-1, we approximate by dividing
  432. by (z+1) = 2**24 (which is easy), and then correcting.
  433. (ax) = (z+1)q' + r
  434. . = zq' + (q'+r)
  435. So to compute (ax)/z, compute q' = (ax)/(z+1) and r = (ax) mod (z+1)
  436. Then the true remainder of (ax)/z is (q'+r). Repeat the process
  437. with this new remainder, adding the tentative quotients together,
  438. until a tentative quotient is 0 (and then we are done). There is
  439. one last correction to be done. It is possible that (q'+r) = z.
  440. If so, then (q'+r)/(z+1) = 0 and it looks like we are done. But,
  441. in fact, we need to add 1 more to the quotient. Now, it turns
  442. out that this happens if and only if the original value x is
  443. an exact multiple of y. So, to avoid a three instruction test at
  444. the end, instead use 1 instruction to add 1 to x at the beginning. */
  445. /* DIVISION BY 7 (use z = 2**24-1; a = 249249) */
  446. GSYM($$divI_7)
  447. .export $$divI_7,millicode
  448. comb,<,n x2,0,LREF(neg7)
  449. LSYM(7)
  450. addi 1,x2,x2 /* cannot overflow */
  451. shd 0,x2,29,x1
  452. sh3add x2,x2,x2
  453. addc x1,0,x1
  454. LSYM(pos7)
  455. shd x1,x2,26,t1
  456. shd x2,0,26,t2
  457. add x2,t2,x2
  458. addc x1,t1,x1
  459. shd x1,x2,20,t1
  460. shd x2,0,20,t2
  461. add x2,t2,x2
  462. addc x1,t1,t1
  463. /* computed <t1,x2>. Now divide it by (2**24 - 1) */
  464. copy 0,x1
  465. shd,= t1,x2,24,t1 /* tentative quotient */
  466. LSYM(1)
  467. addb,tr t1,x1,LREF(2) /* add to previous quotient */
  468. extru x2,31,24,x2 /* new remainder (unadjusted) */
  469. MILLIRETN
  470. LSYM(2)
  471. addb,tr t1,x2,LREF(1) /* adjust remainder */
  472. extru,= x2,7,8,t1 /* new quotient */
  473. LSYM(neg7)
  474. subi 1,x2,x2 /* negate x2 and add 1 */
  475. LSYM(8)
  476. shd 0,x2,29,x1
  477. sh3add x2,x2,x2
  478. addc x1,0,x1
  479. LSYM(neg7_shift)
  480. shd x1,x2,26,t1
  481. shd x2,0,26,t2
  482. add x2,t2,x2
  483. addc x1,t1,x1
  484. shd x1,x2,20,t1
  485. shd x2,0,20,t2
  486. add x2,t2,x2
  487. addc x1,t1,t1
  488. /* computed <t1,x2>. Now divide it by (2**24 - 1) */
  489. copy 0,x1
  490. shd,= t1,x2,24,t1 /* tentative quotient */
  491. LSYM(3)
  492. addb,tr t1,x1,LREF(4) /* add to previous quotient */
  493. extru x2,31,24,x2 /* new remainder (unadjusted) */
  494. MILLIRET
  495. sub 0,x1,x1 /* negate result */
  496. LSYM(4)
  497. addb,tr t1,x2,LREF(3) /* adjust remainder */
  498. extru,= x2,7,8,t1 /* new quotient */
  499. GSYM($$divU_7)
  500. .export $$divU_7,millicode
  501. addi 1,x2,x2 /* can carry */
  502. addc 0,0,x1
  503. shd x1,x2,29,t1
  504. sh3add x2,x2,x2
  505. b LREF(pos7)
  506. addc t1,x1,x1
  507. /* DIVISION BY 9 (use z = 2**24-1; a = 1c71c7) */
  508. GSYM($$divI_9)
  509. .export $$divI_9,millicode
  510. comb,<,n x2,0,LREF(neg9)
  511. addi 1,x2,x2 /* cannot overflow */
  512. shd 0,x2,29,t1
  513. shd x2,0,29,t2
  514. sub t2,x2,x2
  515. b LREF(pos7)
  516. subb t1,0,x1
  517. LSYM(neg9)
  518. subi 1,x2,x2 /* negate and add 1 */
  519. shd 0,x2,29,t1
  520. shd x2,0,29,t2
  521. sub t2,x2,x2
  522. b LREF(neg7_shift)
  523. subb t1,0,x1
  524. GSYM($$divU_9)
  525. .export $$divU_9,millicode
  526. addi 1,x2,x2 /* can carry */
  527. addc 0,0,x1
  528. shd x1,x2,29,t1
  529. shd x2,0,29,t2
  530. sub t2,x2,x2
  531. b LREF(pos7)
  532. subb t1,x1,x1
  533. /* DIVISION BY 14 (shift to divide by 2 then divide by 7) */
  534. GSYM($$divI_14)
  535. .export $$divI_14,millicode
  536. comb,<,n x2,0,LREF(neg14)
  537. GSYM($$divU_14)
  538. .export $$divU_14,millicode
  539. b LREF(7) /* go to 7 case */
  540. extru x2,30,31,x2 /* divide by 2 */
  541. LSYM(neg14)
  542. subi 2,x2,x2 /* negate (and add 2) */
  543. b LREF(8)
  544. extru x2,30,31,x2 /* divide by 2 */
  545. .exit
  546. .procend
  547. .end
  548. #endif