x_unfl.S 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. |
  2. | x_unfl.sa 3.4 7/1/91
  3. |
  4. | fpsp_unfl --- FPSP handler for underflow exception
  5. |
  6. | Trap disabled results
  7. | For 881/2 compatibility, sw must denormalize the intermediate
  8. | result, then store the result. Denormalization is accomplished
  9. | by taking the intermediate result (which is always normalized) and
  10. | shifting the mantissa right while incrementing the exponent until
  11. | it is equal to the denormalized exponent for the destination
  12. | format. After denormalization, the result is rounded to the
  13. | destination format.
  14. |
  15. | Trap enabled results
  16. | All trap disabled code applies. In addition the exceptional
  17. | operand needs to made available to the user with a bias of $6000
  18. | added to the exponent.
  19. |
  20. | Copyright (C) Motorola, Inc. 1990
  21. | All Rights Reserved
  22. |
  23. | For details on the license for this file, please see the
  24. | file, README, in this same directory.
  25. X_UNFL: |idnt 2,1 | Motorola 040 Floating Point Software Package
  26. |section 8
  27. #include "fpsp.h"
  28. |xref denorm
  29. |xref round
  30. |xref store
  31. |xref g_rndpr
  32. |xref g_opcls
  33. |xref g_dfmtou
  34. |xref real_unfl
  35. |xref real_inex
  36. |xref fpsp_done
  37. |xref b1238_fix
  38. .global fpsp_unfl
  39. fpsp_unfl:
  40. link %a6,#-LOCAL_SIZE
  41. fsave -(%a7)
  42. moveml %d0-%d1/%a0-%a1,USER_DA(%a6)
  43. fmovemx %fp0-%fp3,USER_FP0(%a6)
  44. fmoveml %fpcr/%fpsr/%fpiar,USER_FPCR(%a6)
  45. |
  46. bsrl unf_res |denormalize, round & store interm op
  47. |
  48. | If underflow exceptions are not enabled, check for inexact
  49. | exception
  50. |
  51. btstb #unfl_bit,FPCR_ENABLE(%a6)
  52. beqs ck_inex
  53. btstb #E3,E_BYTE(%a6)
  54. beqs no_e3_1
  55. |
  56. | Clear dirty bit on dest resister in the frame before branching
  57. | to b1238_fix.
  58. |
  59. bfextu CMDREG3B(%a6){#6:#3},%d0 |get dest reg no
  60. bclrb %d0,FPR_DIRTY_BITS(%a6) |clr dest dirty bit
  61. bsrl b1238_fix |test for bug1238 case
  62. movel USER_FPSR(%a6),FPSR_SHADOW(%a6)
  63. orl #sx_mask,E_BYTE(%a6)
  64. no_e3_1:
  65. moveml USER_DA(%a6),%d0-%d1/%a0-%a1
  66. fmovemx USER_FP0(%a6),%fp0-%fp3
  67. fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
  68. frestore (%a7)+
  69. unlk %a6
  70. bral real_unfl
  71. |
  72. | It is possible to have either inex2 or inex1 exceptions with the
  73. | unfl. If the inex enable bit is set in the FPCR, and either
  74. | inex2 or inex1 occurred, we must clean up and branch to the
  75. | real inex handler.
  76. |
  77. ck_inex:
  78. moveb FPCR_ENABLE(%a6),%d0
  79. andb FPSR_EXCEPT(%a6),%d0
  80. andib #0x3,%d0
  81. beqs unfl_done
  82. |
  83. | Inexact enabled and reported, and we must take an inexact exception
  84. |
  85. take_inex:
  86. btstb #E3,E_BYTE(%a6)
  87. beqs no_e3_2
  88. |
  89. | Clear dirty bit on dest resister in the frame before branching
  90. | to b1238_fix.
  91. |
  92. bfextu CMDREG3B(%a6){#6:#3},%d0 |get dest reg no
  93. bclrb %d0,FPR_DIRTY_BITS(%a6) |clr dest dirty bit
  94. bsrl b1238_fix |test for bug1238 case
  95. movel USER_FPSR(%a6),FPSR_SHADOW(%a6)
  96. orl #sx_mask,E_BYTE(%a6)
  97. no_e3_2:
  98. moveb #INEX_VEC,EXC_VEC+1(%a6)
  99. moveml USER_DA(%a6),%d0-%d1/%a0-%a1
  100. fmovemx USER_FP0(%a6),%fp0-%fp3
  101. fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
  102. frestore (%a7)+
  103. unlk %a6
  104. bral real_inex
  105. unfl_done:
  106. bclrb #E3,E_BYTE(%a6)
  107. beqs e1_set |if set then branch
  108. |
  109. | Clear dirty bit on dest resister in the frame before branching
  110. | to b1238_fix.
  111. |
  112. bfextu CMDREG3B(%a6){#6:#3},%d0 |get dest reg no
  113. bclrb %d0,FPR_DIRTY_BITS(%a6) |clr dest dirty bit
  114. bsrl b1238_fix |test for bug1238 case
  115. movel USER_FPSR(%a6),FPSR_SHADOW(%a6)
  116. orl #sx_mask,E_BYTE(%a6)
  117. moveml USER_DA(%a6),%d0-%d1/%a0-%a1
  118. fmovemx USER_FP0(%a6),%fp0-%fp3
  119. fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
  120. frestore (%a7)+
  121. unlk %a6
  122. bral fpsp_done
  123. e1_set:
  124. moveml USER_DA(%a6),%d0-%d1/%a0-%a1
  125. fmovemx USER_FP0(%a6),%fp0-%fp3
  126. fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
  127. unlk %a6
  128. bral fpsp_done
  129. |
  130. | unf_res --- underflow result calculation
  131. |
  132. unf_res:
  133. bsrl g_rndpr |returns RND_PREC in d0 0=ext,
  134. | ;1=sgl, 2=dbl
  135. | ;we need the RND_PREC in the
  136. | ;upper word for round
  137. movew #0,-(%a7)
  138. movew %d0,-(%a7) |copy RND_PREC to stack
  139. |
  140. |
  141. | If the exception bit set is E3, the exceptional operand from the
  142. | fpu is in WBTEMP; else it is in FPTEMP.
  143. |
  144. btstb #E3,E_BYTE(%a6)
  145. beqs unf_E1
  146. unf_E3:
  147. lea WBTEMP(%a6),%a0 |a0 now points to operand
  148. |
  149. | Test for fsgldiv and fsglmul. If the inst was one of these, then
  150. | force the precision to extended for the denorm routine. Use
  151. | the user's precision for the round routine.
  152. |
  153. movew CMDREG3B(%a6),%d1 |check for fsgldiv or fsglmul
  154. andiw #0x7f,%d1
  155. cmpiw #0x30,%d1 |check for sgldiv
  156. beqs unf_sgl
  157. cmpiw #0x33,%d1 |check for sglmul
  158. bnes unf_cont |if not, use fpcr prec in round
  159. unf_sgl:
  160. clrl %d0
  161. movew #0x1,(%a7) |override g_rndpr precision
  162. | ;force single
  163. bras unf_cont
  164. unf_E1:
  165. lea FPTEMP(%a6),%a0 |a0 now points to operand
  166. unf_cont:
  167. bclrb #sign_bit,LOCAL_EX(%a0) |clear sign bit
  168. sne LOCAL_SGN(%a0) |store sign
  169. bsrl denorm |returns denorm, a0 points to it
  170. |
  171. | WARNING:
  172. | ;d0 has guard,round sticky bit
  173. | ;make sure that it is not corrupted
  174. | ;before it reaches the round subroutine
  175. | ;also ensure that a0 isn't corrupted
  176. |
  177. | Set up d1 for round subroutine d1 contains the PREC/MODE
  178. | information respectively on upper/lower register halves.
  179. |
  180. bfextu FPCR_MODE(%a6){#2:#2},%d1 |get mode from FPCR
  181. | ;mode in lower d1
  182. addl (%a7)+,%d1 |merge PREC/MODE
  183. |
  184. | WARNING: a0 and d0 are assumed to be intact between the denorm and
  185. | round subroutines. All code between these two subroutines
  186. | must not corrupt a0 and d0.
  187. |
  188. |
  189. | Perform Round
  190. | Input: a0 points to input operand
  191. | d0{31:29} has guard, round, sticky
  192. | d1{01:00} has rounding mode
  193. | d1{17:16} has rounding precision
  194. | Output: a0 points to rounded operand
  195. |
  196. bsrl round |returns rounded denorm at (a0)
  197. |
  198. | Differentiate between store to memory vs. store to register
  199. |
  200. unf_store:
  201. bsrl g_opcls |returns opclass in d0{2:0}
  202. cmpib #0x3,%d0
  203. bnes not_opc011
  204. |
  205. | At this point, a store to memory is pending
  206. |
  207. opc011:
  208. bsrl g_dfmtou
  209. tstb %d0
  210. beqs ext_opc011 |If extended, do not subtract
  211. | ;If destination format is sgl/dbl,
  212. tstb LOCAL_HI(%a0) |If rounded result is normal,don't
  213. | ;subtract
  214. bmis ext_opc011
  215. subqw #1,LOCAL_EX(%a0) |account for denorm bias vs.
  216. | ;normalized bias
  217. | ; normalized denormalized
  218. | ;single $7f $7e
  219. | ;double $3ff $3fe
  220. |
  221. ext_opc011:
  222. bsrl store |stores to memory
  223. bras unf_done |finish up
  224. |
  225. | At this point, a store to a float register is pending
  226. |
  227. not_opc011:
  228. bsrl store |stores to float register
  229. | ;a0 is not corrupted on a store to a
  230. | ;float register.
  231. |
  232. | Set the condition codes according to result
  233. |
  234. tstl LOCAL_HI(%a0) |check upper mantissa
  235. bnes ck_sgn
  236. tstl LOCAL_LO(%a0) |check lower mantissa
  237. bnes ck_sgn
  238. bsetb #z_bit,FPSR_CC(%a6) |set condition codes if zero
  239. ck_sgn:
  240. btstb #sign_bit,LOCAL_EX(%a0) |check the sign bit
  241. beqs unf_done
  242. bsetb #neg_bit,FPSR_CC(%a6)
  243. |
  244. | Finish.
  245. |
  246. unf_done:
  247. btstb #inex2_bit,FPSR_EXCEPT(%a6)
  248. beqs no_aunfl
  249. bsetb #aunfl_bit,FPSR_AEXCEPT(%a6)
  250. no_aunfl:
  251. rts
  252. |end