x_snan.S 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. |
  2. | x_snan.sa 3.3 7/1/91
  3. |
  4. | fpsp_snan --- FPSP handler for signalling NAN exception
  5. |
  6. | SNAN for float -> integer conversions (integer conversion of
  7. | an SNAN) is a non-maskable run-time exception.
  8. |
  9. | For trap disabled the 040 does the following:
  10. | If the dest data format is s, d, or x, then the SNAN bit in the NAN
  11. | is set to one and the resulting non-signaling NAN (truncated if
  12. | necessary) is transferred to the dest. If the dest format is b, w,
  13. | or l, then garbage is written to the dest (actually the upper 32 bits
  14. | of the mantissa are sent to the integer unit).
  15. |
  16. | For trap enabled the 040 does the following:
  17. | If the inst is move_out, then the results are the same as for trap
  18. | disabled with the exception posted. If the instruction is not move_
  19. | out, the dest. is not modified, and the exception is posted.
  20. |
  21. | Copyright (C) Motorola, Inc. 1990
  22. | All Rights Reserved
  23. |
  24. | For details on the license for this file, please see the
  25. | file, README, in this same directory.
  26. X_SNAN: |idnt 2,1 | Motorola 040 Floating Point Software Package
  27. |section 8
  28. #include "fpsp.h"
  29. |xref get_fline
  30. |xref mem_write
  31. |xref real_snan
  32. |xref real_inex
  33. |xref fpsp_done
  34. |xref reg_dest
  35. .global fpsp_snan
  36. fpsp_snan:
  37. link %a6,#-LOCAL_SIZE
  38. fsave -(%a7)
  39. moveml %d0-%d1/%a0-%a1,USER_DA(%a6)
  40. fmovemx %fp0-%fp3,USER_FP0(%a6)
  41. fmoveml %fpcr/%fpsr/%fpiar,USER_FPCR(%a6)
  42. |
  43. | Check if trap enabled
  44. |
  45. btstb #snan_bit,FPCR_ENABLE(%a6)
  46. bnes ena |If enabled, then branch
  47. bsrl move_out |else SNAN disabled
  48. |
  49. | It is possible to have an inex1 exception with the
  50. | snan. If the inex enable bit is set in the FPCR, and either
  51. | inex2 or inex1 occurred, we must clean up and branch to the
  52. | real inex handler.
  53. |
  54. ck_inex:
  55. moveb FPCR_ENABLE(%a6),%d0
  56. andb FPSR_EXCEPT(%a6),%d0
  57. andib #0x3,%d0
  58. beq end_snan
  59. |
  60. | Inexact enabled and reported, and we must take an inexact exception.
  61. |
  62. take_inex:
  63. moveb #INEX_VEC,EXC_VEC+1(%a6)
  64. moveml USER_DA(%a6),%d0-%d1/%a0-%a1
  65. fmovemx USER_FP0(%a6),%fp0-%fp3
  66. fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
  67. frestore (%a7)+
  68. unlk %a6
  69. bral real_inex
  70. |
  71. | SNAN is enabled. Check if inst is move_out.
  72. | Make any corrections to the 040 output as necessary.
  73. |
  74. ena:
  75. btstb #5,CMDREG1B(%a6) |if set, inst is move out
  76. beq not_out
  77. bsrl move_out
  78. report_snan:
  79. moveb (%a7),VER_TMP(%a6)
  80. cmpib #VER_40,(%a7) |test for orig unimp frame
  81. bnes ck_rev
  82. moveql #13,%d0 |need to zero 14 lwords
  83. bras rep_con
  84. ck_rev:
  85. moveql #11,%d0 |need to zero 12 lwords
  86. rep_con:
  87. clrl (%a7)
  88. loop1:
  89. clrl -(%a7) |clear and dec a7
  90. dbra %d0,loop1
  91. moveb VER_TMP(%a6),(%a7) |format a busy frame
  92. moveb #BUSY_SIZE-4,1(%a7)
  93. movel USER_FPSR(%a6),FPSR_SHADOW(%a6)
  94. orl #sx_mask,E_BYTE(%a6)
  95. moveml USER_DA(%a6),%d0-%d1/%a0-%a1
  96. fmovemx USER_FP0(%a6),%fp0-%fp3
  97. fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
  98. frestore (%a7)+
  99. unlk %a6
  100. bral real_snan
  101. |
  102. | Exit snan handler by expanding the unimp frame into a busy frame
  103. |
  104. end_snan:
  105. bclrb #E1,E_BYTE(%a6)
  106. moveb (%a7),VER_TMP(%a6)
  107. cmpib #VER_40,(%a7) |test for orig unimp frame
  108. bnes ck_rev2
  109. moveql #13,%d0 |need to zero 14 lwords
  110. bras rep_con2
  111. ck_rev2:
  112. moveql #11,%d0 |need to zero 12 lwords
  113. rep_con2:
  114. clrl (%a7)
  115. loop2:
  116. clrl -(%a7) |clear and dec a7
  117. dbra %d0,loop2
  118. moveb VER_TMP(%a6),(%a7) |format a busy frame
  119. moveb #BUSY_SIZE-4,1(%a7) |write busy size
  120. movel USER_FPSR(%a6),FPSR_SHADOW(%a6)
  121. orl #sx_mask,E_BYTE(%a6)
  122. moveml USER_DA(%a6),%d0-%d1/%a0-%a1
  123. fmovemx USER_FP0(%a6),%fp0-%fp3
  124. fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
  125. frestore (%a7)+
  126. unlk %a6
  127. bral fpsp_done
  128. |
  129. | Move_out
  130. |
  131. move_out:
  132. movel EXC_EA(%a6),%a0 |get <ea> from exc frame
  133. bfextu CMDREG1B(%a6){#3:#3},%d0 |move rx field to d0{2:0}
  134. cmpil #0,%d0 |check for long
  135. beqs sto_long |branch if move_out long
  136. cmpil #4,%d0 |check for word
  137. beqs sto_word |branch if move_out word
  138. cmpil #6,%d0 |check for byte
  139. beqs sto_byte |branch if move_out byte
  140. |
  141. | Not byte, word or long
  142. |
  143. rts
  144. |
  145. | Get the 32 most significant bits of etemp mantissa
  146. |
  147. sto_long:
  148. movel ETEMP_HI(%a6),%d1
  149. movel #4,%d0 |load byte count
  150. |
  151. | Set signalling nan bit
  152. |
  153. bsetl #30,%d1
  154. |
  155. | Store to the users destination address
  156. |
  157. tstl %a0 |check if <ea> is 0
  158. beqs wrt_dn |destination is a data register
  159. movel %d1,-(%a7) |move the snan onto the stack
  160. movel %a0,%a1 |load dest addr into a1
  161. movel %a7,%a0 |load src addr of snan into a0
  162. bsrl mem_write |write snan to user memory
  163. movel (%a7)+,%d1 |clear off stack
  164. rts
  165. |
  166. | Get the 16 most significant bits of etemp mantissa
  167. |
  168. sto_word:
  169. movel ETEMP_HI(%a6),%d1
  170. movel #2,%d0 |load byte count
  171. |
  172. | Set signalling nan bit
  173. |
  174. bsetl #30,%d1
  175. |
  176. | Store to the users destination address
  177. |
  178. tstl %a0 |check if <ea> is 0
  179. beqs wrt_dn |destination is a data register
  180. movel %d1,-(%a7) |move the snan onto the stack
  181. movel %a0,%a1 |load dest addr into a1
  182. movel %a7,%a0 |point to low word
  183. bsrl mem_write |write snan to user memory
  184. movel (%a7)+,%d1 |clear off stack
  185. rts
  186. |
  187. | Get the 8 most significant bits of etemp mantissa
  188. |
  189. sto_byte:
  190. movel ETEMP_HI(%a6),%d1
  191. movel #1,%d0 |load byte count
  192. |
  193. | Set signalling nan bit
  194. |
  195. bsetl #30,%d1
  196. |
  197. | Store to the users destination address
  198. |
  199. tstl %a0 |check if <ea> is 0
  200. beqs wrt_dn |destination is a data register
  201. movel %d1,-(%a7) |move the snan onto the stack
  202. movel %a0,%a1 |load dest addr into a1
  203. movel %a7,%a0 |point to source byte
  204. bsrl mem_write |write snan to user memory
  205. movel (%a7)+,%d1 |clear off stack
  206. rts
  207. |
  208. | wrt_dn --- write to a data register
  209. |
  210. | We get here with D1 containing the data to write and D0 the
  211. | number of bytes to write: 1=byte,2=word,4=long.
  212. |
  213. wrt_dn:
  214. movel %d1,L_SCR1(%a6) |data
  215. movel %d0,-(%a7) |size
  216. bsrl get_fline |returns fline word in d0
  217. movel %d0,%d1
  218. andil #0x7,%d1 |d1 now holds register number
  219. movel (%sp)+,%d0 |get original size
  220. cmpil #4,%d0
  221. beqs wrt_long
  222. cmpil #2,%d0
  223. bnes wrt_byte
  224. wrt_word:
  225. orl #0x8,%d1
  226. bral reg_dest
  227. wrt_long:
  228. orl #0x10,%d1
  229. bral reg_dest
  230. wrt_byte:
  231. bral reg_dest
  232. |
  233. | Check if it is a src nan or dst nan
  234. |
  235. not_out:
  236. movel DTAG(%a6),%d0
  237. bfextu %d0{#0:#3},%d0 |isolate dtag in lsbs
  238. cmpib #3,%d0 |check for nan in destination
  239. bnes issrc |destination nan has priority
  240. dst_nan:
  241. btstb #6,FPTEMP_HI(%a6) |check if dest nan is an snan
  242. bnes issrc |no, so check source for snan
  243. movew FPTEMP_EX(%a6),%d0
  244. bras cont
  245. issrc:
  246. movew ETEMP_EX(%a6),%d0
  247. cont:
  248. btstl #15,%d0 |test for sign of snan
  249. beqs clr_neg
  250. bsetb #neg_bit,FPSR_CC(%a6)
  251. bra report_snan
  252. clr_neg:
  253. bclrb #neg_bit,FPSR_CC(%a6)
  254. bra report_snan
  255. |end