round.S 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. |
  2. | round.sa 3.4 7/29/91
  3. |
  4. | handle rounding and normalization tasks
  5. |
  6. |
  7. |
  8. | Copyright (C) Motorola, Inc. 1990
  9. | All Rights Reserved
  10. |
  11. | For details on the license for this file, please see the
  12. | file, README, in this same directory.
  13. |ROUND idnt 2,1 | Motorola 040 Floating Point Software Package
  14. |section 8
  15. #include "fpsp.h"
  16. |
  17. | round --- round result according to precision/mode
  18. |
  19. | a0 points to the input operand in the internal extended format
  20. | d1(high word) contains rounding precision:
  21. | ext = $0000xxxx
  22. | sgl = $0001xxxx
  23. | dbl = $0002xxxx
  24. | d1(low word) contains rounding mode:
  25. | RN = $xxxx0000
  26. | RZ = $xxxx0001
  27. | RM = $xxxx0010
  28. | RP = $xxxx0011
  29. | d0{31:29} contains the g,r,s bits (extended)
  30. |
  31. | On return the value pointed to by a0 is correctly rounded,
  32. | a0 is preserved and the g-r-s bits in d0 are cleared.
  33. | The result is not typed - the tag field is invalid. The
  34. | result is still in the internal extended format.
  35. |
  36. | The INEX bit of USER_FPSR will be set if the rounded result was
  37. | inexact (i.e. if any of the g-r-s bits were set).
  38. |
  39. .global round
  40. round:
  41. | If g=r=s=0 then result is exact and round is done, else set
  42. | the inex flag in status reg and continue.
  43. |
  44. bsrs ext_grs |this subroutine looks at the
  45. | :rounding precision and sets
  46. | ;the appropriate g-r-s bits.
  47. tstl %d0 |if grs are zero, go force
  48. bne rnd_cont |lower bits to zero for size
  49. swap %d1 |set up d1.w for round prec.
  50. bra truncate
  51. rnd_cont:
  52. |
  53. | Use rounding mode as an index into a jump table for these modes.
  54. |
  55. orl #inx2a_mask,USER_FPSR(%a6) |set inex2/ainex
  56. lea mode_tab,%a1
  57. movel (%a1,%d1.w*4),%a1
  58. jmp (%a1)
  59. |
  60. | Jump table indexed by rounding mode in d1.w. All following assumes
  61. | grs != 0.
  62. |
  63. mode_tab:
  64. .long rnd_near
  65. .long rnd_zero
  66. .long rnd_mnus
  67. .long rnd_plus
  68. |
  69. | ROUND PLUS INFINITY
  70. |
  71. | If sign of fp number = 0 (positive), then add 1 to l.
  72. |
  73. rnd_plus:
  74. swap %d1 |set up d1 for round prec.
  75. tstb LOCAL_SGN(%a0) |check for sign
  76. bmi truncate |if positive then truncate
  77. movel #0xffffffff,%d0 |force g,r,s to be all f's
  78. lea add_to_l,%a1
  79. movel (%a1,%d1.w*4),%a1
  80. jmp (%a1)
  81. |
  82. | ROUND MINUS INFINITY
  83. |
  84. | If sign of fp number = 1 (negative), then add 1 to l.
  85. |
  86. rnd_mnus:
  87. swap %d1 |set up d1 for round prec.
  88. tstb LOCAL_SGN(%a0) |check for sign
  89. bpl truncate |if negative then truncate
  90. movel #0xffffffff,%d0 |force g,r,s to be all f's
  91. lea add_to_l,%a1
  92. movel (%a1,%d1.w*4),%a1
  93. jmp (%a1)
  94. |
  95. | ROUND ZERO
  96. |
  97. | Always truncate.
  98. rnd_zero:
  99. swap %d1 |set up d1 for round prec.
  100. bra truncate
  101. |
  102. |
  103. | ROUND NEAREST
  104. |
  105. | If (g=1), then add 1 to l and if (r=s=0), then clear l
  106. | Note that this will round to even in case of a tie.
  107. |
  108. rnd_near:
  109. swap %d1 |set up d1 for round prec.
  110. asll #1,%d0 |shift g-bit to c-bit
  111. bcc truncate |if (g=1) then
  112. lea add_to_l,%a1
  113. movel (%a1,%d1.w*4),%a1
  114. jmp (%a1)
  115. |
  116. | ext_grs --- extract guard, round and sticky bits
  117. |
  118. | Input: d1 = PREC:ROUND
  119. | Output: d0{31:29}= guard, round, sticky
  120. |
  121. | The ext_grs extract the guard/round/sticky bits according to the
  122. | selected rounding precision. It is called by the round subroutine
  123. | only. All registers except d0 are kept intact. d0 becomes an
  124. | updated guard,round,sticky in d0{31:29}
  125. |
  126. | Notes: the ext_grs uses the round PREC, and therefore has to swap d1
  127. | prior to usage, and needs to restore d1 to original.
  128. |
  129. ext_grs:
  130. swap %d1 |have d1.w point to round precision
  131. cmpiw #0,%d1
  132. bnes sgl_or_dbl
  133. bras end_ext_grs
  134. sgl_or_dbl:
  135. moveml %d2/%d3,-(%a7) |make some temp registers
  136. cmpiw #1,%d1
  137. bnes grs_dbl
  138. grs_sgl:
  139. bfextu LOCAL_HI(%a0){#24:#2},%d3 |sgl prec. g-r are 2 bits right
  140. movel #30,%d2 |of the sgl prec. limits
  141. lsll %d2,%d3 |shift g-r bits to MSB of d3
  142. movel LOCAL_HI(%a0),%d2 |get word 2 for s-bit test
  143. andil #0x0000003f,%d2 |s bit is the or of all other
  144. bnes st_stky |bits to the right of g-r
  145. tstl LOCAL_LO(%a0) |test lower mantissa
  146. bnes st_stky |if any are set, set sticky
  147. tstl %d0 |test original g,r,s
  148. bnes st_stky |if any are set, set sticky
  149. bras end_sd |if words 3 and 4 are clr, exit
  150. grs_dbl:
  151. bfextu LOCAL_LO(%a0){#21:#2},%d3 |dbl-prec. g-r are 2 bits right
  152. movel #30,%d2 |of the dbl prec. limits
  153. lsll %d2,%d3 |shift g-r bits to the MSB of d3
  154. movel LOCAL_LO(%a0),%d2 |get lower mantissa for s-bit test
  155. andil #0x000001ff,%d2 |s bit is the or-ing of all
  156. bnes st_stky |other bits to the right of g-r
  157. tstl %d0 |test word original g,r,s
  158. bnes st_stky |if any are set, set sticky
  159. bras end_sd |if clear, exit
  160. st_stky:
  161. bset #rnd_stky_bit,%d3
  162. end_sd:
  163. movel %d3,%d0 |return grs to d0
  164. moveml (%a7)+,%d2/%d3 |restore scratch registers
  165. end_ext_grs:
  166. swap %d1 |restore d1 to original
  167. rts
  168. |******************* Local Equates
  169. .set ad_1_sgl,0x00000100 | constant to add 1 to l-bit in sgl prec
  170. .set ad_1_dbl,0x00000800 | constant to add 1 to l-bit in dbl prec
  171. |Jump table for adding 1 to the l-bit indexed by rnd prec
  172. add_to_l:
  173. .long add_ext
  174. .long add_sgl
  175. .long add_dbl
  176. .long add_dbl
  177. |
  178. | ADD SINGLE
  179. |
  180. add_sgl:
  181. addl #ad_1_sgl,LOCAL_HI(%a0)
  182. bccs scc_clr |no mantissa overflow
  183. roxrw LOCAL_HI(%a0) |shift v-bit back in
  184. roxrw LOCAL_HI+2(%a0) |shift v-bit back in
  185. addw #0x1,LOCAL_EX(%a0) |and incr exponent
  186. scc_clr:
  187. tstl %d0 |test for rs = 0
  188. bnes sgl_done
  189. andiw #0xfe00,LOCAL_HI+2(%a0) |clear the l-bit
  190. sgl_done:
  191. andil #0xffffff00,LOCAL_HI(%a0) |truncate bits beyond sgl limit
  192. clrl LOCAL_LO(%a0) |clear d2
  193. rts
  194. |
  195. | ADD EXTENDED
  196. |
  197. add_ext:
  198. addql #1,LOCAL_LO(%a0) |add 1 to l-bit
  199. bccs xcc_clr |test for carry out
  200. addql #1,LOCAL_HI(%a0) |propagate carry
  201. bccs xcc_clr
  202. roxrw LOCAL_HI(%a0) |mant is 0 so restore v-bit
  203. roxrw LOCAL_HI+2(%a0) |mant is 0 so restore v-bit
  204. roxrw LOCAL_LO(%a0)
  205. roxrw LOCAL_LO+2(%a0)
  206. addw #0x1,LOCAL_EX(%a0) |and inc exp
  207. xcc_clr:
  208. tstl %d0 |test rs = 0
  209. bnes add_ext_done
  210. andib #0xfe,LOCAL_LO+3(%a0) |clear the l bit
  211. add_ext_done:
  212. rts
  213. |
  214. | ADD DOUBLE
  215. |
  216. add_dbl:
  217. addl #ad_1_dbl,LOCAL_LO(%a0)
  218. bccs dcc_clr
  219. addql #1,LOCAL_HI(%a0) |propagate carry
  220. bccs dcc_clr
  221. roxrw LOCAL_HI(%a0) |mant is 0 so restore v-bit
  222. roxrw LOCAL_HI+2(%a0) |mant is 0 so restore v-bit
  223. roxrw LOCAL_LO(%a0)
  224. roxrw LOCAL_LO+2(%a0)
  225. addw #0x1,LOCAL_EX(%a0) |incr exponent
  226. dcc_clr:
  227. tstl %d0 |test for rs = 0
  228. bnes dbl_done
  229. andiw #0xf000,LOCAL_LO+2(%a0) |clear the l-bit
  230. dbl_done:
  231. andil #0xfffff800,LOCAL_LO(%a0) |truncate bits beyond dbl limit
  232. rts
  233. error:
  234. rts
  235. |
  236. | Truncate all other bits
  237. |
  238. trunct:
  239. .long end_rnd
  240. .long sgl_done
  241. .long dbl_done
  242. .long dbl_done
  243. truncate:
  244. lea trunct,%a1
  245. movel (%a1,%d1.w*4),%a1
  246. jmp (%a1)
  247. end_rnd:
  248. rts
  249. |
  250. | NORMALIZE
  251. |
  252. | These routines (nrm_zero & nrm_set) normalize the unnorm. This
  253. | is done by shifting the mantissa left while decrementing the
  254. | exponent.
  255. |
  256. | NRM_SET shifts and decrements until there is a 1 set in the integer
  257. | bit of the mantissa (msb in d1).
  258. |
  259. | NRM_ZERO shifts and decrements until there is a 1 set in the integer
  260. | bit of the mantissa (msb in d1) unless this would mean the exponent
  261. | would go less than 0. In that case the number becomes a denorm - the
  262. | exponent (d0) is set to 0 and the mantissa (d1 & d2) is not
  263. | normalized.
  264. |
  265. | Note that both routines have been optimized (for the worst case) and
  266. | therefore do not have the easy to follow decrement/shift loop.
  267. |
  268. | NRM_ZERO
  269. |
  270. | Distance to first 1 bit in mantissa = X
  271. | Distance to 0 from exponent = Y
  272. | If X < Y
  273. | Then
  274. | nrm_set
  275. | Else
  276. | shift mantissa by Y
  277. | set exponent = 0
  278. |
  279. |input:
  280. | FP_SCR1 = exponent, ms mantissa part, ls mantissa part
  281. |output:
  282. | L_SCR1{4} = fpte15 or ete15 bit
  283. |
  284. .global nrm_zero
  285. nrm_zero:
  286. movew LOCAL_EX(%a0),%d0
  287. cmpw #64,%d0 |see if exp > 64
  288. bmis d0_less
  289. bsr nrm_set |exp > 64 so exp won't exceed 0
  290. rts
  291. d0_less:
  292. moveml %d2/%d3/%d5/%d6,-(%a7)
  293. movel LOCAL_HI(%a0),%d1
  294. movel LOCAL_LO(%a0),%d2
  295. bfffo %d1{#0:#32},%d3 |get the distance to the first 1
  296. | ;in ms mant
  297. beqs ms_clr |branch if no bits were set
  298. cmpw %d3,%d0 |of X>Y
  299. bmis greater |then exp will go past 0 (neg) if
  300. | ;it is just shifted
  301. bsr nrm_set |else exp won't go past 0
  302. moveml (%a7)+,%d2/%d3/%d5/%d6
  303. rts
  304. greater:
  305. movel %d2,%d6 |save ls mant in d6
  306. lsll %d0,%d2 |shift ls mant by count
  307. lsll %d0,%d1 |shift ms mant by count
  308. movel #32,%d5
  309. subl %d0,%d5 |make op a denorm by shifting bits
  310. lsrl %d5,%d6 |by the number in the exp, then
  311. | ;set exp = 0.
  312. orl %d6,%d1 |shift the ls mant bits into the ms mant
  313. movel #0,%d0 |same as if decremented exp to 0
  314. | ;while shifting
  315. movew %d0,LOCAL_EX(%a0)
  316. movel %d1,LOCAL_HI(%a0)
  317. movel %d2,LOCAL_LO(%a0)
  318. moveml (%a7)+,%d2/%d3/%d5/%d6
  319. rts
  320. ms_clr:
  321. bfffo %d2{#0:#32},%d3 |check if any bits set in ls mant
  322. beqs all_clr |branch if none set
  323. addw #32,%d3
  324. cmpw %d3,%d0 |if X>Y
  325. bmis greater |then branch
  326. bsr nrm_set |else exp won't go past 0
  327. moveml (%a7)+,%d2/%d3/%d5/%d6
  328. rts
  329. all_clr:
  330. movew #0,LOCAL_EX(%a0) |no mantissa bits set. Set exp = 0.
  331. moveml (%a7)+,%d2/%d3/%d5/%d6
  332. rts
  333. |
  334. | NRM_SET
  335. |
  336. .global nrm_set
  337. nrm_set:
  338. movel %d7,-(%a7)
  339. bfffo LOCAL_HI(%a0){#0:#32},%d7 |find first 1 in ms mant to d7)
  340. beqs lower |branch if ms mant is all 0's
  341. movel %d6,-(%a7)
  342. subw %d7,LOCAL_EX(%a0) |sub exponent by count
  343. movel LOCAL_HI(%a0),%d0 |d0 has ms mant
  344. movel LOCAL_LO(%a0),%d1 |d1 has ls mant
  345. lsll %d7,%d0 |shift first 1 to j bit position
  346. movel %d1,%d6 |copy ls mant into d6
  347. lsll %d7,%d6 |shift ls mant by count
  348. movel %d6,LOCAL_LO(%a0) |store ls mant into memory
  349. moveql #32,%d6
  350. subl %d7,%d6 |continue shift
  351. lsrl %d6,%d1 |shift off all bits but those that will
  352. | ;be shifted into ms mant
  353. orl %d1,%d0 |shift the ls mant bits into the ms mant
  354. movel %d0,LOCAL_HI(%a0) |store ms mant into memory
  355. moveml (%a7)+,%d7/%d6 |restore registers
  356. rts
  357. |
  358. | We get here if ms mant was = 0, and we assume ls mant has bits
  359. | set (otherwise this would have been tagged a zero not a denorm).
  360. |
  361. lower:
  362. movew LOCAL_EX(%a0),%d0 |d0 has exponent
  363. movel LOCAL_LO(%a0),%d1 |d1 has ls mant
  364. subw #32,%d0 |account for ms mant being all zeros
  365. bfffo %d1{#0:#32},%d7 |find first 1 in ls mant to d7)
  366. subw %d7,%d0 |subtract shift count from exp
  367. lsll %d7,%d1 |shift first 1 to integer bit in ms mant
  368. movew %d0,LOCAL_EX(%a0) |store ms mant
  369. movel %d1,LOCAL_HI(%a0) |store exp
  370. clrl LOCAL_LO(%a0) |clear ls mant
  371. movel (%a7)+,%d7
  372. rts
  373. |
  374. | denorm --- denormalize an intermediate result
  375. |
  376. | Used by underflow.
  377. |
  378. | Input:
  379. | a0 points to the operand to be denormalized
  380. | (in the internal extended format)
  381. |
  382. | d0: rounding precision
  383. | Output:
  384. | a0 points to the denormalized result
  385. | (in the internal extended format)
  386. |
  387. | d0 is guard,round,sticky
  388. |
  389. | d0 comes into this routine with the rounding precision. It
  390. | is then loaded with the denormalized exponent threshold for the
  391. | rounding precision.
  392. |
  393. .global denorm
  394. denorm:
  395. btstb #6,LOCAL_EX(%a0) |check for exponents between $7fff-$4000
  396. beqs no_sgn_ext
  397. bsetb #7,LOCAL_EX(%a0) |sign extend if it is so
  398. no_sgn_ext:
  399. cmpib #0,%d0 |if 0 then extended precision
  400. bnes not_ext |else branch
  401. clrl %d1 |load d1 with ext threshold
  402. clrl %d0 |clear the sticky flag
  403. bsr dnrm_lp |denormalize the number
  404. tstb %d1 |check for inex
  405. beq no_inex |if clr, no inex
  406. bras dnrm_inex |if set, set inex
  407. not_ext:
  408. cmpil #1,%d0 |if 1 then single precision
  409. beqs load_sgl |else must be 2, double prec
  410. load_dbl:
  411. movew #dbl_thresh,%d1 |put copy of threshold in d1
  412. movel %d1,%d0 |copy d1 into d0
  413. subw LOCAL_EX(%a0),%d0 |diff = threshold - exp
  414. cmpw #67,%d0 |if diff > 67 (mant + grs bits)
  415. bpls chk_stky |then branch (all bits would be
  416. | ; shifted off in denorm routine)
  417. clrl %d0 |else clear the sticky flag
  418. bsr dnrm_lp |denormalize the number
  419. tstb %d1 |check flag
  420. beqs no_inex |if clr, no inex
  421. bras dnrm_inex |if set, set inex
  422. load_sgl:
  423. movew #sgl_thresh,%d1 |put copy of threshold in d1
  424. movel %d1,%d0 |copy d1 into d0
  425. subw LOCAL_EX(%a0),%d0 |diff = threshold - exp
  426. cmpw #67,%d0 |if diff > 67 (mant + grs bits)
  427. bpls chk_stky |then branch (all bits would be
  428. | ; shifted off in denorm routine)
  429. clrl %d0 |else clear the sticky flag
  430. bsr dnrm_lp |denormalize the number
  431. tstb %d1 |check flag
  432. beqs no_inex |if clr, no inex
  433. bras dnrm_inex |if set, set inex
  434. chk_stky:
  435. tstl LOCAL_HI(%a0) |check for any bits set
  436. bnes set_stky
  437. tstl LOCAL_LO(%a0) |check for any bits set
  438. bnes set_stky
  439. bras clr_mant
  440. set_stky:
  441. orl #inx2a_mask,USER_FPSR(%a6) |set inex2/ainex
  442. movel #0x20000000,%d0 |set sticky bit in return value
  443. clr_mant:
  444. movew %d1,LOCAL_EX(%a0) |load exp with threshold
  445. movel #0,LOCAL_HI(%a0) |set d1 = 0 (ms mantissa)
  446. movel #0,LOCAL_LO(%a0) |set d2 = 0 (ms mantissa)
  447. rts
  448. dnrm_inex:
  449. orl #inx2a_mask,USER_FPSR(%a6) |set inex2/ainex
  450. no_inex:
  451. rts
  452. |
  453. | dnrm_lp --- normalize exponent/mantissa to specified threshold
  454. |
  455. | Input:
  456. | a0 points to the operand to be denormalized
  457. | d0{31:29} initial guard,round,sticky
  458. | d1{15:0} denormalization threshold
  459. | Output:
  460. | a0 points to the denormalized operand
  461. | d0{31:29} final guard,round,sticky
  462. | d1.b inexact flag: all ones means inexact result
  463. |
  464. | The LOCAL_LO and LOCAL_GRS parts of the value are copied to FP_SCR2
  465. | so that bfext can be used to extract the new low part of the mantissa.
  466. | Dnrm_lp can be called with a0 pointing to ETEMP or WBTEMP and there
  467. | is no LOCAL_GRS scratch word following it on the fsave frame.
  468. |
  469. .global dnrm_lp
  470. dnrm_lp:
  471. movel %d2,-(%sp) |save d2 for temp use
  472. btstb #E3,E_BYTE(%a6) |test for type E3 exception
  473. beqs not_E3 |not type E3 exception
  474. bfextu WBTEMP_GRS(%a6){#6:#3},%d2 |extract guard,round, sticky bit
  475. movel #29,%d0
  476. lsll %d0,%d2 |shift g,r,s to their positions
  477. movel %d2,%d0
  478. not_E3:
  479. movel (%sp)+,%d2 |restore d2
  480. movel LOCAL_LO(%a0),FP_SCR2+LOCAL_LO(%a6)
  481. movel %d0,FP_SCR2+LOCAL_GRS(%a6)
  482. movel %d1,%d0 |copy the denorm threshold
  483. subw LOCAL_EX(%a0),%d1 |d1 = threshold - uns exponent
  484. bles no_lp |d1 <= 0
  485. cmpw #32,%d1
  486. blts case_1 |0 = d1 < 32
  487. cmpw #64,%d1
  488. blts case_2 |32 <= d1 < 64
  489. bra case_3 |d1 >= 64
  490. |
  491. | No normalization necessary
  492. |
  493. no_lp:
  494. clrb %d1 |set no inex2 reported
  495. movel FP_SCR2+LOCAL_GRS(%a6),%d0 |restore original g,r,s
  496. rts
  497. |
  498. | case (0<d1<32)
  499. |
  500. case_1:
  501. movel %d2,-(%sp)
  502. movew %d0,LOCAL_EX(%a0) |exponent = denorm threshold
  503. movel #32,%d0
  504. subw %d1,%d0 |d0 = 32 - d1
  505. bfextu LOCAL_EX(%a0){%d0:#32},%d2
  506. bfextu %d2{%d1:%d0},%d2 |d2 = new LOCAL_HI
  507. bfextu LOCAL_HI(%a0){%d0:#32},%d1 |d1 = new LOCAL_LO
  508. bfextu FP_SCR2+LOCAL_LO(%a6){%d0:#32},%d0 |d0 = new G,R,S
  509. movel %d2,LOCAL_HI(%a0) |store new LOCAL_HI
  510. movel %d1,LOCAL_LO(%a0) |store new LOCAL_LO
  511. clrb %d1
  512. bftst %d0{#2:#30}
  513. beqs c1nstky
  514. bsetl #rnd_stky_bit,%d0
  515. st %d1
  516. c1nstky:
  517. movel FP_SCR2+LOCAL_GRS(%a6),%d2 |restore original g,r,s
  518. andil #0xe0000000,%d2 |clear all but G,R,S
  519. tstl %d2 |test if original G,R,S are clear
  520. beqs grs_clear
  521. orl #0x20000000,%d0 |set sticky bit in d0
  522. grs_clear:
  523. andil #0xe0000000,%d0 |clear all but G,R,S
  524. movel (%sp)+,%d2
  525. rts
  526. |
  527. | case (32<=d1<64)
  528. |
  529. case_2:
  530. movel %d2,-(%sp)
  531. movew %d0,LOCAL_EX(%a0) |unsigned exponent = threshold
  532. subw #32,%d1 |d1 now between 0 and 32
  533. movel #32,%d0
  534. subw %d1,%d0 |d0 = 32 - d1
  535. bfextu LOCAL_EX(%a0){%d0:#32},%d2
  536. bfextu %d2{%d1:%d0},%d2 |d2 = new LOCAL_LO
  537. bfextu LOCAL_HI(%a0){%d0:#32},%d1 |d1 = new G,R,S
  538. bftst %d1{#2:#30}
  539. bnes c2_sstky |bra if sticky bit to be set
  540. bftst FP_SCR2+LOCAL_LO(%a6){%d0:#32}
  541. bnes c2_sstky |bra if sticky bit to be set
  542. movel %d1,%d0
  543. clrb %d1
  544. bras end_c2
  545. c2_sstky:
  546. movel %d1,%d0
  547. bsetl #rnd_stky_bit,%d0
  548. st %d1
  549. end_c2:
  550. clrl LOCAL_HI(%a0) |store LOCAL_HI = 0
  551. movel %d2,LOCAL_LO(%a0) |store LOCAL_LO
  552. movel FP_SCR2+LOCAL_GRS(%a6),%d2 |restore original g,r,s
  553. andil #0xe0000000,%d2 |clear all but G,R,S
  554. tstl %d2 |test if original G,R,S are clear
  555. beqs clear_grs
  556. orl #0x20000000,%d0 |set sticky bit in d0
  557. clear_grs:
  558. andil #0xe0000000,%d0 |get rid of all but G,R,S
  559. movel (%sp)+,%d2
  560. rts
  561. |
  562. | d1 >= 64 Force the exponent to be the denorm threshold with the
  563. | correct sign.
  564. |
  565. case_3:
  566. movew %d0,LOCAL_EX(%a0)
  567. tstw LOCAL_SGN(%a0)
  568. bges c3con
  569. c3neg:
  570. orl #0x80000000,LOCAL_EX(%a0)
  571. c3con:
  572. cmpw #64,%d1
  573. beqs sixty_four
  574. cmpw #65,%d1
  575. beqs sixty_five
  576. |
  577. | Shift value is out of range. Set d1 for inex2 flag and
  578. | return a zero with the given threshold.
  579. |
  580. clrl LOCAL_HI(%a0)
  581. clrl LOCAL_LO(%a0)
  582. movel #0x20000000,%d0
  583. st %d1
  584. rts
  585. sixty_four:
  586. movel LOCAL_HI(%a0),%d0
  587. bfextu %d0{#2:#30},%d1
  588. andil #0xc0000000,%d0
  589. bras c3com
  590. sixty_five:
  591. movel LOCAL_HI(%a0),%d0
  592. bfextu %d0{#1:#31},%d1
  593. andil #0x80000000,%d0
  594. lsrl #1,%d0 |shift high bit into R bit
  595. c3com:
  596. tstl %d1
  597. bnes c3ssticky
  598. tstl LOCAL_LO(%a0)
  599. bnes c3ssticky
  600. tstb FP_SCR2+LOCAL_GRS(%a6)
  601. bnes c3ssticky
  602. clrb %d1
  603. bras c3end
  604. c3ssticky:
  605. bsetl #rnd_stky_bit,%d0
  606. st %d1
  607. c3end:
  608. clrl LOCAL_HI(%a0)
  609. clrl LOCAL_LO(%a0)
  610. rts
  611. |end