kernel_ex.sa revision 1.1 1 1.1 mycroft * MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
2 1.1 mycroft * M68000 Hi-Performance Microprocessor Division
3 1.1 mycroft * M68040 Software Package
4 1.1 mycroft *
5 1.1 mycroft * M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
6 1.1 mycroft * All rights reserved.
7 1.1 mycroft *
8 1.1 mycroft * THE SOFTWARE is provided on an "AS IS" basis and without warranty.
9 1.1 mycroft * To the maximum extent permitted by applicable law,
10 1.1 mycroft * MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
11 1.1 mycroft * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
12 1.1 mycroft * PARTICULAR PURPOSE and any warranty against infringement with
13 1.1 mycroft * regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
14 1.1 mycroft * and any accompanying written materials.
15 1.1 mycroft *
16 1.1 mycroft * To the maximum extent permitted by applicable law,
17 1.1 mycroft * IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
18 1.1 mycroft * (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
19 1.1 mycroft * PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
20 1.1 mycroft * OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
21 1.1 mycroft * SOFTWARE. Motorola assumes no responsibility for the maintenance
22 1.1 mycroft * and support of the SOFTWARE.
23 1.1 mycroft *
24 1.1 mycroft * You are hereby granted a copyright license to use, modify, and
25 1.1 mycroft * distribute the SOFTWARE so long as this entire notice is retained
26 1.1 mycroft * without alteration in any modified and/or redistributed versions,
27 1.1 mycroft * and that such modified versions are clearly identified as such.
28 1.1 mycroft * No licenses are granted by implication, estoppel or otherwise
29 1.1 mycroft * under any patents or trademarks of Motorola, Inc.
30 1.1 mycroft
31 1.1 mycroft *
32 1.1 mycroft * kernel_ex.sa 3.3 12/19/90
33 1.1 mycroft *
34 1.1 mycroft * This file contains routines to force exception status in the
35 1.1 mycroft * fpu for exceptional cases detected or reported within the
36 1.1 mycroft * transcendental functions. Typically, the t_xx routine will
37 1.1 mycroft * set the appropriate bits in the USER_FPSR word on the stack.
38 1.1 mycroft * The bits are tested in gen_except.sa to determine if an exceptional
39 1.1 mycroft * situation needs to be created on return from the FPSP.
40 1.1 mycroft *
41 1.1 mycroft
42 1.1 mycroft KERNEL_EX IDNT 2,1 Motorola 040 Floating Point Software Package
43 1.1 mycroft
44 1.1 mycroft section 8
45 1.1 mycroft
46 1.1 mycroft include fpsp.h
47 1.1 mycroft
48 1.1 mycroft mns_inf dc.l $ffff0000,$00000000,$00000000
49 1.1 mycroft pls_inf dc.l $7fff0000,$00000000,$00000000
50 1.1 mycroft nan dc.l $7fff0000,$ffffffff,$ffffffff
51 1.1 mycroft huge dc.l $7ffe0000,$ffffffff,$ffffffff
52 1.1 mycroft
53 1.1 mycroft xref ovf_r_k
54 1.1 mycroft xref unf_sub
55 1.1 mycroft xref nrm_set
56 1.1 mycroft
57 1.1 mycroft xdef t_dz
58 1.1 mycroft xdef t_dz2
59 1.1 mycroft xdef t_operr
60 1.1 mycroft xdef t_unfl
61 1.1 mycroft xdef t_ovfl
62 1.1 mycroft xdef t_ovfl2
63 1.1 mycroft xdef t_inx2
64 1.1 mycroft xdef t_frcinx
65 1.1 mycroft xdef t_extdnrm
66 1.1 mycroft xdef t_resdnrm
67 1.1 mycroft xdef dst_nan
68 1.1 mycroft xdef src_nan
69 1.1 mycroft *
70 1.1 mycroft * DZ exception
71 1.1 mycroft *
72 1.1 mycroft *
73 1.1 mycroft * if dz trap disabled
74 1.1 mycroft * store properly signed inf (use sign of etemp) into fp0
75 1.1 mycroft * set FPSR exception status dz bit, condition code
76 1.1 mycroft * inf bit, and accrued dz bit
77 1.1 mycroft * return
78 1.1 mycroft * frestore the frame into the machine (done by unimp_hd)
79 1.1 mycroft *
80 1.1 mycroft * else dz trap enabled
81 1.1 mycroft * set exception status bit & accrued bits in FPSR
82 1.1 mycroft * set flag to disable sto_res from corrupting fp register
83 1.1 mycroft * return
84 1.1 mycroft * frestore the frame into the machine (done by unimp_hd)
85 1.1 mycroft *
86 1.1 mycroft * t_dz2 is used by monadic functions such as flogn (from do_func).
87 1.1 mycroft * t_dz is used by monadic functions such as satanh (from the
88 1.1 mycroft * transcendental function).
89 1.1 mycroft *
90 1.1 mycroft t_dz2:
91 1.1 mycroft bset.b #neg_bit,FPSR_CC(a6) ;set neg bit in FPSR
92 1.1 mycroft fmove.l #0,FPSR ;clr status bits (Z set)
93 1.1 mycroft btst.b #dz_bit,FPCR_ENABLE(a6) ;test FPCR for dz exc enabled
94 1.1 mycroft bne.b dz_ena_end
95 1.1 mycroft bra.b m_inf ;flogx always returns -inf
96 1.1 mycroft t_dz:
97 1.1 mycroft fmove.l #0,FPSR ;clr status bits (Z set)
98 1.1 mycroft btst.b #dz_bit,FPCR_ENABLE(a6) ;test FPCR for dz exc enabled
99 1.1 mycroft bne.b dz_ena
100 1.1 mycroft *
101 1.1 mycroft * dz disabled
102 1.1 mycroft *
103 1.1 mycroft btst.b #sign_bit,ETEMP_EX(a6) ;check sign for neg or pos
104 1.1 mycroft beq.b p_inf ;branch if pos sign
105 1.1 mycroft
106 1.1 mycroft m_inf:
107 1.1 mycroft fmovem.x mns_inf,fp0 ;load -inf
108 1.1 mycroft bset.b #neg_bit,FPSR_CC(a6) ;set neg bit in FPSR
109 1.1 mycroft bra.b set_fpsr
110 1.1 mycroft p_inf:
111 1.1 mycroft fmovem.x pls_inf,fp0 ;load +inf
112 1.1 mycroft set_fpsr:
113 1.1 mycroft or.l #dzinf_mask,USER_FPSR(a6) ;set I,DZ,ADZ
114 1.1 mycroft rts
115 1.1 mycroft *
116 1.1 mycroft * dz enabled
117 1.1 mycroft *
118 1.1 mycroft dz_ena:
119 1.1 mycroft btst.b #sign_bit,ETEMP_EX(a6) ;check sign for neg or pos
120 1.1 mycroft beq.b dz_ena_end
121 1.1 mycroft bset.b #neg_bit,FPSR_CC(a6) ;set neg bit in FPSR
122 1.1 mycroft dz_ena_end:
123 1.1 mycroft or.l #dzinf_mask,USER_FPSR(a6) ;set I,DZ,ADZ
124 1.1 mycroft st.b STORE_FLG(a6)
125 1.1 mycroft rts
126 1.1 mycroft *
127 1.1 mycroft * OPERR exception
128 1.1 mycroft *
129 1.1 mycroft * if (operr trap disabled)
130 1.1 mycroft * set FPSR exception status operr bit, condition code
131 1.1 mycroft * nan bit; Store default NAN into fp0
132 1.1 mycroft * frestore the frame into the machine (done by unimp_hd)
133 1.1 mycroft *
134 1.1 mycroft * else (operr trap enabled)
135 1.1 mycroft * set FPSR exception status operr bit, accrued operr bit
136 1.1 mycroft * set flag to disable sto_res from corrupting fp register
137 1.1 mycroft * frestore the frame into the machine (done by unimp_hd)
138 1.1 mycroft *
139 1.1 mycroft t_operr:
140 1.1 mycroft or.l #opnan_mask,USER_FPSR(a6) ;set NaN, OPERR, AIOP
141 1.1 mycroft
142 1.1 mycroft btst.b #operr_bit,FPCR_ENABLE(a6) ;test FPCR for operr enabled
143 1.1 mycroft bne.b op_ena
144 1.1 mycroft
145 1.1 mycroft fmovem.x nan,fp0 ;load default nan
146 1.1 mycroft rts
147 1.1 mycroft op_ena:
148 1.1 mycroft st.b STORE_FLG(a6) ;do not corrupt destination
149 1.1 mycroft rts
150 1.1 mycroft
151 1.1 mycroft *
152 1.1 mycroft * t_unfl --- UNFL exception
153 1.1 mycroft *
154 1.1 mycroft * This entry point is used by all routines requiring unfl, inex2,
155 1.1 mycroft * aunfl, and ainex to be set on exit.
156 1.1 mycroft *
157 1.1 mycroft * On entry, a0 points to the exceptional operand. The final exceptional
158 1.1 mycroft * operand is built in FP_SCR1 and only the sign from the original operand
159 1.1 mycroft * is used.
160 1.1 mycroft *
161 1.1 mycroft t_unfl:
162 1.1 mycroft clr.l FP_SCR1(a6) ;set exceptional operand to zero
163 1.1 mycroft clr.l FP_SCR1+4(a6)
164 1.1 mycroft clr.l FP_SCR1+8(a6)
165 1.1 mycroft tst.b (a0) ;extract sign from caller's exop
166 1.1 mycroft bpl.b unfl_signok
167 1.1 mycroft bset #sign_bit,FP_SCR1(a6)
168 1.1 mycroft unfl_signok:
169 1.1 mycroft lea.l FP_SCR1(a6),a0
170 1.1 mycroft or.l #unfinx_mask,USER_FPSR(a6)
171 1.1 mycroft * ;set UNFL, INEX2, AUNFL, AINEX
172 1.1 mycroft unfl_con:
173 1.1 mycroft btst.b #unfl_bit,FPCR_ENABLE(a6)
174 1.1 mycroft beq.b unfl_dis
175 1.1 mycroft
176 1.1 mycroft unfl_ena:
177 1.1 mycroft bfclr STAG(a6){5:3} ;clear wbtm66,wbtm1,wbtm0
178 1.1 mycroft bset.b #wbtemp15_bit,WB_BYTE(a6) ;set wbtemp15
179 1.1 mycroft bset.b #sticky_bit,STICKY(a6) ;set sticky bit
180 1.1 mycroft
181 1.1 mycroft bclr.b #E1,E_BYTE(a6)
182 1.1 mycroft
183 1.1 mycroft unfl_dis:
184 1.1 mycroft bfextu FPCR_MODE(a6){0:2},d0 ;get round precision
185 1.1 mycroft
186 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0)
187 1.1 mycroft sne LOCAL_SGN(a0) ;convert to internal ext format
188 1.1 mycroft
189 1.1 mycroft bsr unf_sub ;returns IEEE result at a0
190 1.1 mycroft * ;and sets FPSR_CC accordingly
191 1.1 mycroft
192 1.1 mycroft bfclr LOCAL_SGN(a0){0:8} ;convert back to IEEE ext format
193 1.1 mycroft beq.b unfl_fin
194 1.1 mycroft
195 1.1 mycroft bset.b #sign_bit,LOCAL_EX(a0)
196 1.1 mycroft bset.b #sign_bit,FP_SCR1(a6) ;set sign bit of exc operand
197 1.1 mycroft
198 1.1 mycroft unfl_fin:
199 1.1 mycroft fmovem.x (a0),fp0 ;store result in fp0
200 1.1 mycroft rts
201 1.1 mycroft
202 1.1 mycroft
203 1.1 mycroft *
204 1.1 mycroft * t_ovfl2 --- OVFL exception (without inex2 returned)
205 1.1 mycroft *
206 1.1 mycroft * This entry is used by scale to force catastrophic overflow. The
207 1.1 mycroft * ovfl, aovfl, and ainex bits are set, but not the inex2 bit.
208 1.1 mycroft *
209 1.1 mycroft t_ovfl2:
210 1.1 mycroft or.l #ovfl_inx_mask,USER_FPSR(a6)
211 1.1 mycroft move.l ETEMP(a6),FP_SCR1(a6)
212 1.1 mycroft move.l ETEMP_HI(a6),FP_SCR1+4(a6)
213 1.1 mycroft move.l ETEMP_LO(a6),FP_SCR1+8(a6)
214 1.1 mycroft *
215 1.1 mycroft * Check for single or double round precision. If single, check if
216 1.1 mycroft * the lower 40 bits of ETEMP are zero; if not, set inex2. If double,
217 1.1 mycroft * check if the lower 21 bits are zero; if not, set inex2.
218 1.1 mycroft *
219 1.1 mycroft move.b FPCR_MODE(a6),d0
220 1.1 mycroft andi.b #$c0,d0
221 1.1 mycroft beq.w t_work ;if extended, finish ovfl processing
222 1.1 mycroft cmpi.b #$40,d0 ;test for single
223 1.1 mycroft bne.b t_dbl
224 1.1 mycroft t_sgl:
225 1.1 mycroft tst.b ETEMP_LO(a6)
226 1.1 mycroft bne.b t_setinx2
227 1.1 mycroft move.l ETEMP_HI(a6),d0
228 1.1 mycroft andi.l #$ff,d0 ;look at only lower 8 bits
229 1.1 mycroft bne.b t_setinx2
230 1.1 mycroft bra.w t_work
231 1.1 mycroft t_dbl:
232 1.1 mycroft move.l ETEMP_LO(a6),d0
233 1.1 mycroft andi.l #$7ff,d0 ;look at only lower 11 bits
234 1.1 mycroft beq.w t_work
235 1.1 mycroft t_setinx2:
236 1.1 mycroft or.l #inex2_mask,USER_FPSR(a6)
237 1.1 mycroft bra.b t_work
238 1.1 mycroft *
239 1.1 mycroft * t_ovfl --- OVFL exception
240 1.1 mycroft *
241 1.1 mycroft *** Note: the exc operand is returned in ETEMP.
242 1.1 mycroft *
243 1.1 mycroft t_ovfl:
244 1.1 mycroft or.l #ovfinx_mask,USER_FPSR(a6)
245 1.1 mycroft t_work:
246 1.1 mycroft btst.b #ovfl_bit,FPCR_ENABLE(a6) ;test FPCR for ovfl enabled
247 1.1 mycroft beq.b ovf_dis
248 1.1 mycroft
249 1.1 mycroft ovf_ena:
250 1.1 mycroft clr.l FP_SCR1(a6) ;set exceptional operand
251 1.1 mycroft clr.l FP_SCR1+4(a6)
252 1.1 mycroft clr.l FP_SCR1+8(a6)
253 1.1 mycroft
254 1.1 mycroft bfclr STAG(a6){5:3} ;clear wbtm66,wbtm1,wbtm0
255 1.1 mycroft bclr.b #wbtemp15_bit,WB_BYTE(a6) ;clear wbtemp15
256 1.1 mycroft bset.b #sticky_bit,STICKY(a6) ;set sticky bit
257 1.1 mycroft
258 1.1 mycroft bclr.b #E1,E_BYTE(a6)
259 1.1 mycroft * ;fall through to disabled case
260 1.1 mycroft
261 1.1 mycroft * For disabled overflow call 'ovf_r_k'. This routine loads the
262 1.1 mycroft * correct result based on the rounding precision, destination
263 1.1 mycroft * format, rounding mode and sign.
264 1.1 mycroft *
265 1.1 mycroft ovf_dis:
266 1.1 mycroft bsr ovf_r_k ;returns unsigned ETEMP_EX
267 1.1 mycroft * ;and sets FPSR_CC accordingly.
268 1.1 mycroft bfclr ETEMP_SGN(a6){0:8} ;fix sign
269 1.1 mycroft beq.b ovf_pos
270 1.1 mycroft bset.b #sign_bit,ETEMP_EX(a6)
271 1.1 mycroft bset.b #sign_bit,FP_SCR1(a6) ;set exceptional operand sign
272 1.1 mycroft ovf_pos:
273 1.1 mycroft fmovem.x ETEMP(a6),fp0 ;move the result to fp0
274 1.1 mycroft rts
275 1.1 mycroft
276 1.1 mycroft
277 1.1 mycroft *
278 1.1 mycroft * INEX2 exception
279 1.1 mycroft *
280 1.1 mycroft * The inex2 and ainex bits are set.
281 1.1 mycroft *
282 1.1 mycroft t_inx2:
283 1.1 mycroft or.l #inx2a_mask,USER_FPSR(a6) ;set INEX2, AINEX
284 1.1 mycroft rts
285 1.1 mycroft
286 1.1 mycroft *
287 1.1 mycroft * Force Inex2
288 1.1 mycroft *
289 1.1 mycroft * This routine is called by the transcendental routines to force
290 1.1 mycroft * the inex2 exception bits set in the FPSR. If the underflow bit
291 1.1 mycroft * is set, but the underflow trap was not taken, the aunfl bit in
292 1.1 mycroft * the FPSR must be set.
293 1.1 mycroft *
294 1.1 mycroft t_frcinx:
295 1.1 mycroft or.l #inx2a_mask,USER_FPSR(a6) ;set INEX2, AINEX
296 1.1 mycroft btst.b #unfl_bit,FPSR_EXCEPT(a6) ;test for unfl bit set
297 1.1 mycroft beq.b no_uacc1 ;if clear, do not set aunfl
298 1.1 mycroft bset.b #aunfl_bit,FPSR_AEXCEPT(a6)
299 1.1 mycroft no_uacc1:
300 1.1 mycroft rts
301 1.1 mycroft
302 1.1 mycroft *
303 1.1 mycroft * DST_NAN
304 1.1 mycroft *
305 1.1 mycroft * Determine if the destination nan is signalling or non-signalling,
306 1.1 mycroft * and set the FPSR bits accordingly. See the MC68040 User's Manual
307 1.1 mycroft * section 3.2.2.5 NOT-A-NUMBERS.
308 1.1 mycroft *
309 1.1 mycroft dst_nan:
310 1.1 mycroft btst.b #sign_bit,FPTEMP_EX(a6) ;test sign of nan
311 1.1 mycroft beq.b dst_pos ;if clr, it was positive
312 1.1 mycroft bset.b #neg_bit,FPSR_CC(a6) ;set N bit
313 1.1 mycroft dst_pos:
314 1.1 mycroft btst.b #signan_bit,FPTEMP_HI(a6) ;check if signalling
315 1.1 mycroft beq.b dst_snan ;branch if signalling
316 1.1 mycroft
317 1.1 mycroft fmove.l d1,fpcr ;restore user's rmode/prec
318 1.1 mycroft fmove.x FPTEMP(a6),fp0 ;return the non-signalling nan
319 1.1 mycroft *
320 1.1 mycroft * Check the source nan. If it is signalling, snan will be reported.
321 1.1 mycroft *
322 1.1 mycroft move.b STAG(a6),d0
323 1.1 mycroft andi.b #$e0,d0
324 1.1 mycroft cmpi.b #$60,d0
325 1.1 mycroft bne.b no_snan
326 1.1 mycroft btst.b #signan_bit,ETEMP_HI(a6) ;check if signalling
327 1.1 mycroft bne.b no_snan
328 1.1 mycroft or.l #snaniop_mask,USER_FPSR(a6) ;set NAN, SNAN, AIOP
329 1.1 mycroft no_snan:
330 1.1 mycroft rts
331 1.1 mycroft
332 1.1 mycroft dst_snan:
333 1.1 mycroft btst.b #snan_bit,FPCR_ENABLE(a6) ;check if trap enabled
334 1.1 mycroft beq.b dst_dis ;branch if disabled
335 1.1 mycroft
336 1.1 mycroft or.b #nan_tag,DTAG(a6) ;set up dtag for nan
337 1.1 mycroft st.b STORE_FLG(a6) ;do not store a result
338 1.1 mycroft or.l #snaniop_mask,USER_FPSR(a6) ;set NAN, SNAN, AIOP
339 1.1 mycroft rts
340 1.1 mycroft
341 1.1 mycroft dst_dis:
342 1.1 mycroft bset.b #signan_bit,FPTEMP_HI(a6) ;set SNAN bit in sop
343 1.1 mycroft fmove.l d1,fpcr ;restore user's rmode/prec
344 1.1 mycroft fmove.x FPTEMP(a6),fp0 ;load non-sign. nan
345 1.1 mycroft or.l #snaniop_mask,USER_FPSR(a6) ;set NAN, SNAN, AIOP
346 1.1 mycroft rts
347 1.1 mycroft
348 1.1 mycroft *
349 1.1 mycroft * SRC_NAN
350 1.1 mycroft *
351 1.1 mycroft * Determine if the source nan is signalling or non-signalling,
352 1.1 mycroft * and set the FPSR bits accordingly. See the MC68040 User's Manual
353 1.1 mycroft * section 3.2.2.5 NOT-A-NUMBERS.
354 1.1 mycroft *
355 1.1 mycroft src_nan:
356 1.1 mycroft btst.b #sign_bit,ETEMP_EX(a6) ;test sign of nan
357 1.1 mycroft beq.b src_pos ;if clr, it was positive
358 1.1 mycroft bset.b #neg_bit,FPSR_CC(a6) ;set N bit
359 1.1 mycroft src_pos:
360 1.1 mycroft btst.b #signan_bit,ETEMP_HI(a6) ;check if signalling
361 1.1 mycroft beq.b src_snan ;branch if signalling
362 1.1 mycroft fmove.l d1,fpcr ;restore user's rmode/prec
363 1.1 mycroft fmove.x ETEMP(a6),fp0 ;return the non-signalling nan
364 1.1 mycroft rts
365 1.1 mycroft
366 1.1 mycroft src_snan:
367 1.1 mycroft btst.b #snan_bit,FPCR_ENABLE(a6) ;check if trap enabled
368 1.1 mycroft beq.b src_dis ;branch if disabled
369 1.1 mycroft bset.b #signan_bit,ETEMP_HI(a6) ;set SNAN bit in sop
370 1.1 mycroft or.b #norm_tag,DTAG(a6) ;set up dtag for norm
371 1.1 mycroft or.b #nan_tag,STAG(a6) ;set up stag for nan
372 1.1 mycroft st.b STORE_FLG(a6) ;do not store a result
373 1.1 mycroft or.l #snaniop_mask,USER_FPSR(a6) ;set NAN, SNAN, AIOP
374 1.1 mycroft rts
375 1.1 mycroft
376 1.1 mycroft src_dis:
377 1.1 mycroft bset.b #signan_bit,ETEMP_HI(a6) ;set SNAN bit in sop
378 1.1 mycroft fmove.l d1,fpcr ;restore user's rmode/prec
379 1.1 mycroft fmove.x ETEMP(a6),fp0 ;load non-sign. nan
380 1.1 mycroft or.l #snaniop_mask,USER_FPSR(a6) ;set NAN, SNAN, AIOP
381 1.1 mycroft rts
382 1.1 mycroft
383 1.1 mycroft *
384 1.1 mycroft * For all functions that have a denormalized input and that f(x)=x,
385 1.1 mycroft * this is the entry point
386 1.1 mycroft *
387 1.1 mycroft t_extdnrm:
388 1.1 mycroft or.l #unfinx_mask,USER_FPSR(a6)
389 1.1 mycroft * ;set UNFL, INEX2, AUNFL, AINEX
390 1.1 mycroft bra.b xdnrm_con
391 1.1 mycroft *
392 1.1 mycroft * Entry point for scale with extended denorm. The function does
393 1.1 mycroft * not set inex2, aunfl, or ainex.
394 1.1 mycroft *
395 1.1 mycroft t_resdnrm:
396 1.1 mycroft or.l #unfl_mask,USER_FPSR(a6)
397 1.1 mycroft
398 1.1 mycroft xdnrm_con:
399 1.1 mycroft btst.b #unfl_bit,FPCR_ENABLE(a6)
400 1.1 mycroft beq.b xdnrm_dis
401 1.1 mycroft
402 1.1 mycroft *
403 1.1 mycroft * If exceptions are enabled, the additional task of setting up WBTEMP
404 1.1 mycroft * is needed so that when the underflow exception handler is entered,
405 1.1 mycroft * the user perceives no difference between what the 040 provides vs.
406 1.1 mycroft * what the FPSP provides.
407 1.1 mycroft *
408 1.1 mycroft xdnrm_ena:
409 1.1 mycroft move.l a0,-(a7)
410 1.1 mycroft
411 1.1 mycroft move.l LOCAL_EX(a0),FP_SCR1(a6)
412 1.1 mycroft move.l LOCAL_HI(a0),FP_SCR1+4(a6)
413 1.1 mycroft move.l LOCAL_LO(a0),FP_SCR1+8(a6)
414 1.1 mycroft
415 1.1 mycroft lea FP_SCR1(a6),a0
416 1.1 mycroft
417 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0)
418 1.1 mycroft sne LOCAL_SGN(a0) ;convert to internal ext format
419 1.1 mycroft tst.w LOCAL_EX(a0) ;check if input is denorm
420 1.1 mycroft beq.b xdnrm_dn ;if so, skip nrm_set
421 1.1 mycroft bsr nrm_set ;normalize the result (exponent
422 1.1 mycroft * ;will be negative
423 1.1 mycroft xdnrm_dn:
424 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0) ;take off false sign
425 1.1 mycroft bfclr LOCAL_SGN(a0){0:8} ;change back to IEEE ext format
426 1.1 mycroft beq.b xdep
427 1.1 mycroft bset.b #sign_bit,LOCAL_EX(a0)
428 1.1 mycroft xdep:
429 1.1 mycroft bfclr STAG(a6){5:3} ;clear wbtm66,wbtm1,wbtm0
430 1.1 mycroft bset.b #wbtemp15_bit,WB_BYTE(a6) ;set wbtemp15
431 1.1 mycroft bclr.b #sticky_bit,STICKY(a6) ;clear sticky bit
432 1.1 mycroft bclr.b #E1,E_BYTE(a6)
433 1.1 mycroft move.l (a7)+,a0
434 1.1 mycroft xdnrm_dis:
435 1.1 mycroft bfextu FPCR_MODE(a6){0:2},d0 ;get round precision
436 1.1 mycroft bne.b not_ext ;if not round extended, store
437 1.1 mycroft * ;IEEE defaults
438 1.1 mycroft is_ext:
439 1.1 mycroft btst.b #sign_bit,LOCAL_EX(a0)
440 1.1 mycroft beq.b xdnrm_store
441 1.1 mycroft
442 1.1 mycroft bset.b #neg_bit,FPSR_CC(a6) ;set N bit in FPSR_CC
443 1.1 mycroft
444 1.1 mycroft bra.b xdnrm_store
445 1.1 mycroft
446 1.1 mycroft not_ext:
447 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0)
448 1.1 mycroft sne LOCAL_SGN(a0) ;convert to internal ext format
449 1.1 mycroft bsr unf_sub ;returns IEEE result pointed by
450 1.1 mycroft * ;a0; sets FPSR_CC accordingly
451 1.1 mycroft bfclr LOCAL_SGN(a0){0:8} ;convert back to IEEE ext format
452 1.1 mycroft beq.b xdnrm_store
453 1.1 mycroft bset.b #sign_bit,LOCAL_EX(a0)
454 1.1 mycroft xdnrm_store:
455 1.1 mycroft fmovem.x (a0),fp0 ;store result in fp0
456 1.1 mycroft rts
457 1.1 mycroft
458 1.1 mycroft *
459 1.1 mycroft * This subroutine is used for dyadic operations that use an extended
460 1.1 mycroft * denorm within the kernel. The approach used is to capture the frame,
461 1.1 mycroft * fix/restore.
462 1.1 mycroft *
463 1.1 mycroft xdef t_avoid_unsupp
464 1.1 mycroft t_avoid_unsupp:
465 1.1 mycroft link a2,#-LOCAL_SIZE ;so that a2 fpsp.h negative
466 1.1 mycroft * ;offsets may be used
467 1.1 mycroft fsave -(a7)
468 1.1 mycroft tst.b 1(a7) ;check if idle, exit if so
469 1.1 mycroft beq.w idle_end
470 1.1 mycroft btst.b #E1,E_BYTE(a2) ;check for an E1 exception if
471 1.1 mycroft * ;enabled, there is an unsupp
472 1.1 mycroft beq.w end_avun ;else, exit
473 1.1 mycroft btst.b #7,DTAG(a2) ;check for denorm destination
474 1.1 mycroft beq.b src_den ;else, must be a source denorm
475 1.1 mycroft *
476 1.1 mycroft * handle destination denorm
477 1.1 mycroft *
478 1.1 mycroft lea FPTEMP(a2),a0
479 1.1 mycroft btst.b #sign_bit,LOCAL_EX(a0)
480 1.1 mycroft sne LOCAL_SGN(a0) ;convert to internal ext format
481 1.1 mycroft bclr.b #7,DTAG(a2) ;set DTAG to norm
482 1.1 mycroft bsr nrm_set ;normalize result, exponent
483 1.1 mycroft * ;will become negative
484 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0) ;get rid of fake sign
485 1.1 mycroft bfclr LOCAL_SGN(a0){0:8} ;convert back to IEEE ext format
486 1.1 mycroft beq.b ck_src_den ;check if source is also denorm
487 1.1 mycroft bset.b #sign_bit,LOCAL_EX(a0)
488 1.1 mycroft ck_src_den:
489 1.1 mycroft btst.b #7,STAG(a2)
490 1.1 mycroft beq.b end_avun
491 1.1 mycroft src_den:
492 1.1 mycroft lea ETEMP(a2),a0
493 1.1 mycroft btst.b #sign_bit,LOCAL_EX(a0)
494 1.1 mycroft sne LOCAL_SGN(a0) ;convert to internal ext format
495 1.1 mycroft bclr.b #7,STAG(a2) ;set STAG to norm
496 1.1 mycroft bsr nrm_set ;normalize result, exponent
497 1.1 mycroft * ;will become negative
498 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0) ;get rid of fake sign
499 1.1 mycroft bfclr LOCAL_SGN(a0){0:8} ;convert back to IEEE ext format
500 1.1 mycroft beq.b den_com
501 1.1 mycroft bset.b #sign_bit,LOCAL_EX(a0)
502 1.1 mycroft den_com:
503 1.1 mycroft move.b #$fe,CU_SAVEPC(a2) ;set continue frame
504 1.1 mycroft clr.w NMNEXC(a2) ;clear NMNEXC
505 1.1 mycroft bclr.b #E1,E_BYTE(a2)
506 1.1 mycroft * fmove.l FPSR,FPSR_SHADOW(a2)
507 1.1 mycroft * bset.b #SFLAG,E_BYTE(a2)
508 1.1 mycroft * bset.b #XFLAG,T_BYTE(a2)
509 1.1 mycroft end_avun:
510 1.1 mycroft frestore (a7)+
511 1.1 mycroft unlk a2
512 1.1 mycroft rts
513 1.1 mycroft idle_end:
514 1.1 mycroft add.l #4,a7
515 1.1 mycroft unlk a2
516 1.1 mycroft rts
517 1.1 mycroft end
518