4 | fpsp_unfl --- FPSP handler for underflow exception
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
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.
21 | Copyright (C) Motorola, Inc. 1990
24 | For details on the license for this file, please see the
25 | file, README, in this same directory.
27 X_UNFL: |idnt 2,1 | Motorola 040 Floating Point Software Package
48 moveml %d0-%d1/%a0-%a1,USER_DA(%a6)
49 fmovemx %fp0-%fp3,USER_FP0(%a6)
50 fmoveml %fpcr/%fpsr/%fpiar,USER_FPCR(%a6)
53 bsrl unf_res |denormalize, round & store interm op
55 | If underflow exceptions are not enabled, check for inexact
58 btstb #unfl_bit,FPCR_ENABLE(%a6)
64 | Clear dirty bit on dest resister in the frame before branching
67 bfextu CMDREG3B(%a6){#6:#3},%d0 |get dest reg no
68 bclrb %d0,FPR_DIRTY_BITS(%a6) |clr dest dirty bit
69 bsrl b1238_fix |test for bug1238 case
70 movel USER_FPSR(%a6),FPSR_SHADOW(%a6)
71 orl #sx_mask,E_BYTE(%a6)
73 moveml USER_DA(%a6),%d0-%d1/%a0-%a1
74 fmovemx USER_FP0(%a6),%fp0-%fp3
75 fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
80 | It is possible to have either inex2 or inex1 exceptions with the
81 | unfl. If the inex enable bit is set in the FPCR, and either
82 | inex2 or inex1 occurred, we must clean up and branch to the
86 moveb FPCR_ENABLE(%a6),%d0
87 andb FPSR_EXCEPT(%a6),%d0
92 | Inexact enabled and reported, and we must take an inexact exception
98 | Clear dirty bit on dest resister in the frame before branching
101 bfextu CMDREG3B(%a6){#6:#3},%d0 |get dest reg no
102 bclrb %d0,FPR_DIRTY_BITS(%a6) |clr dest dirty bit
103 bsrl b1238_fix |test for bug1238 case
104 movel USER_FPSR(%a6),FPSR_SHADOW(%a6)
105 orl #sx_mask,E_BYTE(%a6)
107 moveb #INEX_VEC,EXC_VEC+1(%a6)
108 moveml USER_DA(%a6),%d0-%d1/%a0-%a1
109 fmovemx USER_FP0(%a6),%fp0-%fp3
110 fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
116 bclrb #E3,E_BYTE(%a6)
117 beqs e1_set |if set then branch
119 | Clear dirty bit on dest resister in the frame before branching
122 bfextu CMDREG3B(%a6){#6:#3},%d0 |get dest reg no
123 bclrb %d0,FPR_DIRTY_BITS(%a6) |clr dest dirty bit
124 bsrl b1238_fix |test for bug1238 case
125 movel USER_FPSR(%a6),FPSR_SHADOW(%a6)
126 orl #sx_mask,E_BYTE(%a6)
127 moveml USER_DA(%a6),%d0-%d1/%a0-%a1
128 fmovemx USER_FP0(%a6),%fp0-%fp3
129 fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
134 moveml USER_DA(%a6),%d0-%d1/%a0-%a1
135 fmovemx USER_FP0(%a6),%fp0-%fp3
136 fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
140 | unf_res --- underflow result calculation
143 bsrl g_rndpr |returns RND_PREC in d0 0=ext,
145 | ;we need the RND_PREC in the
146 | ;upper word for round
148 movew %d0,-(%a7) |copy RND_PREC to stack
151 | If the exception bit set is E3, the exceptional operand from the
152 | fpu is in WBTEMP; else it is in FPTEMP.
154 btstb #E3,E_BYTE(%a6)
157 lea WBTEMP(%a6),%a0 |a0 now points to operand
159 | Test for fsgldiv and fsglmul. If the inst was one of these, then
160 | force the precision to extended for the denorm routine. Use
161 | the user's precision for the round routine.
163 movew CMDREG3B(%a6),%d1 |check for fsgldiv or fsglmul
165 cmpiw #0x30,%d1 |check for sgldiv
167 cmpiw #0x33,%d1 |check for sglmul
168 bnes unf_cont |if not, use fpcr prec in round
171 movew #0x1,(%a7) |override g_rndpr precision
175 lea FPTEMP(%a6),%a0 |a0 now points to operand
177 bclrb #sign_bit,LOCAL_EX(%a0) |clear sign bit
178 sne LOCAL_SGN(%a0) |store sign
180 bsrl denorm |returns denorm, a0 points to it
183 | ;d0 has guard,round sticky bit
184 | ;make sure that it is not corrupted
185 | ;before it reaches the round subroutine
186 | ;also ensure that a0 isn't corrupted
189 | Set up d1 for round subroutine d1 contains the PREC/MODE
190 | information respectively on upper/lower register halves.
192 bfextu FPCR_MODE(%a6){#2:#2},%d1 |get mode from FPCR
194 addl (%a7)+,%d1 |merge PREC/MODE
196 | WARNING: a0 and d0 are assumed to be intact between the denorm and
197 | round subroutines. All code between these two subroutines
198 | must not corrupt a0 and d0.
202 | Input: a0 points to input operand
203 | d0{31:29} has guard, round, sticky
204 | d1{01:00} has rounding mode
205 | d1{17:16} has rounding precision
206 | Output: a0 points to rounded operand
209 bsrl round |returns rounded denorm at (a0)
211 | Differentiate between store to memory vs. store to register
214 bsrl g_opcls |returns opclass in d0{2:0}
218 | At this point, a store to memory is pending
223 beqs ext_opc011 |If extended, do not subtract
224 | ;If destination format is sgl/dbl,
225 tstb LOCAL_HI(%a0) |If rounded result is normal,don't
228 subqw #1,LOCAL_EX(%a0) |account for denorm bias vs.
230 | ; normalized denormalized
235 bsrl store |stores to memory
236 bras unf_done |finish up
239 | At this point, a store to a float register is pending
242 bsrl store |stores to float register
243 | ;a0 is not corrupted on a store to a
246 | Set the condition codes according to result
248 tstl LOCAL_HI(%a0) |check upper mantissa
250 tstl LOCAL_LO(%a0) |check lower mantissa
252 bsetb #z_bit,FPSR_CC(%a6) |set condition codes if zero
254 btstb #sign_bit,LOCAL_EX(%a0) |check the sign bit
256 bsetb #neg_bit,FPSR_CC(%a6)
262 btstb #inex2_bit,FPSR_EXCEPT(%a6)
264 bsetb #aunfl_bit,FPSR_AEXCEPT(%a6)