4 | This file contains routines used by other programs.
6 | ovf_res: used by overflow to force the correct
7 | result. ovf_r_k, ovf_r_x2, ovf_r_x3 are
8 | derivatives of this routine.
9 | get_fline: get user's opcode word
10 | g_dfmtou: returns the destination format.
11 | g_opcls: returns the opclass of the float instruction.
12 | g_rndpr: returns the rounding precision.
13 | reg_dest: write byte, word, or long data to Dn
16 | Copyright (C) Motorola, Inc. 1990
19 | For details on the license for this file, please see the
20 | file, README, in this same directory.
22 |UTIL idnt 2,1 | Motorola 040 Floating Point Software Package
37 | Final result table for ovf_res. Note that the negative counterparts
38 | are unnecessary as ovf_res always returns the sign separately from
41 EXT_PINF: .long 0x7fff0000,0x00000000,0x00000000,0x00000000
43 EXT_PLRG: .long 0x7ffe0000,0xffffffff,0xffffffff,0x00000000
44 | ;largest magnitude +sgl in ext
45 SGL_PLRG: .long 0x407e0000,0xffffff00,0x00000000,0x00000000
46 | ;largest magnitude +dbl in ext
47 DBL_PLRG: .long 0x43fe0000,0xffffffff,0xfffff800,0x00000000
70 | ovf_r_k --- overflow result calculation
72 | This entry point is used by kernel_ex.
74 | This forces the destination precision to be extended
76 | Input: operand in ETEMP
77 | Output: a result is in ETEMP (internal extended format)
81 lea ETEMP(%a6),%a0 |a0 points to source operand
82 bclrb #sign_bit,ETEMP_EX(%a6)
83 sne ETEMP_SGN(%a6) |convert to internal IEEE format
86 | ovf_r_x2 --- overflow result calculation
88 | This entry point used by x_ovfl. (opclass 0 and 2)
90 | Input a0 points to an operand in the internal extended format
91 | Output a0 points to the result in the internal extended format
93 | This sets the round precision according to the user's FPCR unless the
94 | instruction is fsgldiv or fsglmul or fsadd, fdadd, fsub, fdsub, fsmul,
95 | fdmul, fsdiv, fddiv, fssqrt, fsmove, fdmove, fsabs, fdabs, fsneg, fdneg.
96 | If the instruction is fsgldiv of fsglmul, the rounding precision must be
97 | extended. If the instruction is not fsgldiv or fsglmul but a force-
98 | precision instruction, the rounding precision is then set to the force
103 btstb #E3,E_BYTE(%a6) |check for nu exception
104 beql ovf_e1_exc |it is cu exception
106 movew CMDREG3B(%a6),%d0 |get the command word
107 andiw #0x00000060,%d0 |clear all bits except 6 and 5
108 cmpil #0x00000040,%d0
109 beql ovff_sgl |force precision is single
110 cmpil #0x00000060,%d0
111 beql ovff_dbl |force precision is double
112 movew CMDREG3B(%a6),%d0 |get the command word again
113 andil #0x7f,%d0 |clear all except operation
115 beql ovf_fsgl |fsglmul or fsgldiv
118 bra ovf_fpcr |instruction is none of the above
121 movew CMDREG1B(%a6),%d0 |get command word
122 andil #0x00000044,%d0 |clear all bits except 6 and 2
123 cmpil #0x00000040,%d0
124 beql ovff_sgl |the instruction is force single
125 cmpil #0x00000044,%d0
126 beql ovff_dbl |the instruction is force double
127 movew CMDREG1B(%a6),%d0 |again get the command word
128 andil #0x0000007f,%d0 |clear all except the op code
129 cmpil #0x00000027,%d0
130 beql ovf_fsgl |fsglmul
131 cmpil #0x00000024,%d0
132 beql ovf_fsgl |fsgldiv
133 bra ovf_fpcr |none of the above, use FPCR
136 | Inst is either fsgldiv or fsglmul. Force extended precision.
143 movel #0x00000001,%d0 |set single
146 movel #0x00000002,%d0 |set double
149 | The precision is in the fpcr.
152 bfextu FPCR_MODE(%a6){#0:#2},%d0 |set round precision
157 | ovf_r_x3 --- overflow result calculation
159 | This entry point used by x_ovfl. (opclass 3 only)
161 | Input a0 points to an operand in the internal extended format
162 | Output a0 points to the result in the internal extended format
164 | This sets the round precision according to the destination size.
168 bsr g_dfmtou |get dest fmt in d0{1:0}
169 | ;for fmovout, the destination format
170 | ;is the rounding precision
173 | ovf_res --- overflow result calculation
176 | a0 points to operand in internal extended format
178 | a0 points to result in internal extended format
182 lsll #2,%d0 |move round precision to d0{3:2}
183 bfextu FPCR_MODE(%a6){#2:#2},%d1 |set round mode
184 orl %d1,%d0 |index is fmt:mode in d0{3:0}
185 leal tblovfl,%a1 |load a1 with table address
186 movel %a1@(%d0:l:4),%a1 |use d0 as index to the table
187 jmp (%a1) |go to the correct routine
192 leal EXT_PINF,%a1 |answer is +/- infinity
193 bsetb #inf_bit,FPSR_CC(%a6)
194 bra set_sign |now go set the sign
196 leal EXT_PLRG,%a1 |answer is +/- large number
197 bra set_sign |now go set the sign
199 tstb LOCAL_SGN(%a0) |if negative overflow
202 leal EXT_PINF,%a1 |answer is negative infinity
203 orl #neginf_mask,USER_FPSR(%a6)
206 leal EXT_PLRG,%a1 |answer is large positive number
209 tstb LOCAL_SGN(%a0) |if negative overflow
212 leal EXT_PLRG,%a1 |answer is large negative number
213 bsetb #neg_bit,FPSR_CC(%a6)
216 leal EXT_PINF,%a1 |answer is positive infinity
217 bsetb #inf_bit,FPSR_CC(%a6)
223 leal EXT_PINF,%a1 |answer is +/- infinity
224 bsetb #inf_bit,FPSR_CC(%a6)
227 leal DBL_PLRG,%a1 |answer is +/- large number
228 bra set_sign |now go set the sign
230 tstb LOCAL_SGN(%a0) |if negative overflow
233 leal EXT_PINF,%a1 |answer is negative infinity
234 orl #neginf_mask,USER_FPSR(%a6)
235 bra end_ovfr |inf is same for all precisions (ext,dbl,sgl)
237 leal DBL_PLRG,%a1 |answer is large positive number
240 tstb LOCAL_SGN(%a0) |if negative overflow
243 leal DBL_PLRG,%a1 |answer is large negative number
244 bsetb #neg_bit,FPSR_CC(%a6)
247 leal EXT_PINF,%a1 |answer is positive infinity
248 bsetb #inf_bit,FPSR_CC(%a6)
254 leal EXT_PINF,%a1 |answer is +/- infinity
255 bsetb #inf_bit,FPSR_CC(%a6)
258 leal SGL_PLRG,%a1 |answer is +/- large number
261 tstb LOCAL_SGN(%a0) |if negative overflow
264 leal EXT_PINF,%a1 |answer is negative infinity
265 orl #neginf_mask,USER_FPSR(%a6)
268 leal SGL_PLRG,%a1 |answer is large positive number
271 tstb LOCAL_SGN(%a0) |if negative overflow
274 leal SGL_PLRG,%a1 |answer is large negative number
275 bsetb #neg_bit,FPSR_CC(%a6)
278 leal EXT_PINF,%a1 |answer is positive infinity
279 bsetb #inf_bit,FPSR_CC(%a6)
283 tstb LOCAL_SGN(%a0) |if negative overflow
286 bsetb #neg_bit,FPSR_CC(%a6)
289 movew LOCAL_EX(%a1),LOCAL_EX(%a0) |do not overwrite sign
290 movel LOCAL_HI(%a1),LOCAL_HI(%a0)
291 movel LOCAL_LO(%a1),LOCAL_LO(%a0)
301 | get_fline --- get f-line opcode of interrupted instruction
303 | Returns opcode in the low word of d0.
306 movel USER_FPIAR(%a6),%a0 |opcode address
307 movel #0,-(%a7) |reserve a word on the stack
308 leal 2(%a7),%a1 |point to low word of temporary
314 | g_rndpr --- put rounding precision in d0{1:0}
316 | valid return codes are:
322 | get rounding precision (cmdreg3b{6:5})
324 | case opclass = 011 (move out)
325 | get destination format - this is the also the rounding precision
329 | *case RndPr(from cmdreg3b{6:5} = 11 then RND_PREC = DBL
330 | *case RndPr(from cmdreg3b{6:5} = 10 then RND_PREC = SGL
331 | case RndPr(from cmdreg3b{6:5} = 00 | 01
332 | use precision from FPCR{7:6}
333 | case 00 then RND_PREC = EXT
334 | case 01 then RND_PREC = SGL
335 | case 10 then RND_PREC = DBL
337 | use precision in FPCR{7:6}
338 | case 00 then RND_PREC = EXT
339 | case 01 then RND_PREC = SGL
340 | case 10 then RND_PREC = DBL
344 bsr g_opcls |get opclass in d0{2:0}
345 cmpw #0x0003,%d0 |check for opclass 011
349 | For move out instructions (opclass 011) the destination format
350 | is the same as the rounding precision. Pass results from g_dfmtou.
355 btstb #E3,E_BYTE(%a6)
356 beql unf_e1_exc |branch to e1 underflow
358 movel CMDREG3B(%a6),%d0 |rounding precision in d0{10:9}
359 bfextu %d0{#9:#2},%d0 |move the rounding prec bits to d0{1:0}
361 beql unff_sgl |force precision is single
362 cmpil #0x3,%d0 |force precision is double
364 movew CMDREG3B(%a6),%d0 |get the command word again
365 andil #0x7f,%d0 |clear all except operation
367 beql unf_fsgl |fsglmul or fsgldiv
369 beql unf_fsgl |fsgldiv or fsglmul
372 movel CMDREG1B(%a6),%d0 |get 32 bits off the stack, 1st 16 bits
373 | ;are the command word
374 andil #0x00440000,%d0 |clear all bits except bits 6 and 2
375 cmpil #0x00400000,%d0
376 beql unff_sgl |force single
377 cmpil #0x00440000,%d0 |force double
379 movel CMDREG1B(%a6),%d0 |get the command word again
380 andil #0x007f0000,%d0 |clear all bits except the operation
381 cmpil #0x00270000,%d0
382 beql unf_fsgl |fsglmul
383 cmpil #0x00240000,%d0
384 beql unf_fsgl |fsgldiv
388 | Convert to return format. The values from cmdreg3b and the return
390 | cmdreg3b return precision
391 | -------- ------ ---------
398 movel #1,%d0 |return 1
404 movel #2,%d0 |return 2
413 | Get rounding precision set in FPCR{7:6}.
416 movel USER_FPCR(%a6),%d0 |rounding precision bits in d0{7:6}
417 bfextu %d0{#24:#2},%d0 |move the rounding prec bits to d0{1:0}
420 | g_opcls --- put opclass in d0{2:0}
423 btstb #E3,E_BYTE(%a6)
424 beqs opc_1b |if set, go to cmdreg1b
426 clrl %d0 |if E3, only opclass 0x0 is possible
429 movel CMDREG1B(%a6),%d0
430 bfextu %d0{#0:#3},%d0 |shift opclass bits d0{31:29} to d0{2:0}
433 | g_dfmtou --- put destination format in d0{1:0}
435 | If E1, the format is from cmdreg1b{12:10}
436 | If E3, the format is extended.
444 btstb #E3,E_BYTE(%a6)
446 clrl %d0 |if E1, size is always ext
449 movel CMDREG1B(%a6),%d0
450 bfextu %d0{#3:#3},%d0 |dest fmt from cmdreg1b{12:10}
451 cmpb #1,%d0 |check for single
456 cmpb #5,%d0 |check for double
461 clrl %d0 |must be extended
466 | Final result table for unf_sub. Note that the negative counterparts
467 | are unnecessary as unf_sub always returns the sign separately from
470 EXT_PZRO: .long 0x00000000,0x00000000,0x00000000,0x00000000
472 SGL_PZRO: .long 0x3f810000,0x00000000,0x00000000,0x00000000
474 DBL_PZRO: .long 0x3c010000,0x00000000,0x00000000,0x00000000
475 | ;smallest +ext denorm
476 EXT_PSML: .long 0x00000000,0x00000000,0x00000001,0x00000000
477 | ;smallest +sgl denorm
478 SGL_PSML: .long 0x3f810000,0x00000100,0x00000000,0x00000000
479 | ;smallest +dbl denorm
480 DBL_PSML: .long 0x3c010000,0x00000000,0x00000800,0x00000000
482 | UNF_SUB --- underflow result calculation
485 | d0 contains round precision
486 | a0 points to input operand in the internal extended format
489 | a0 points to correct internal extended precision result.
512 lsll #2,%d0 |move round precision to d0{3:2}
513 bfextu FPCR_MODE(%a6){#2:#2},%d1 |set round mode
514 orl %d1,%d0 |index is fmt:mode in d0{3:0}
515 leal tblunf,%a1 |load a1 with table address
516 movel %a1@(%d0:l:4),%a1 |use d0 as index to the table
517 jmp (%a1) |go to the correct routine
522 leal EXT_PZRO,%a1 |answer is +/- zero
523 bsetb #z_bit,FPSR_CC(%a6)
524 bra uset_sign |now go set the sign
526 leal EXT_PZRO,%a1 |answer is +/- zero
527 bsetb #z_bit,FPSR_CC(%a6)
528 bra uset_sign |now go set the sign
530 tstb LOCAL_SGN(%a0) |if negative underflow
533 leal EXT_PSML,%a1 |answer is negative smallest denorm
534 bsetb #neg_bit,FPSR_CC(%a6)
537 leal EXT_PZRO,%a1 |answer is positive zero
538 bsetb #z_bit,FPSR_CC(%a6)
541 tstb LOCAL_SGN(%a0) |if negative underflow
544 leal EXT_PZRO,%a1 |answer is negative zero
545 oril #negz_mask,USER_FPSR(%a6)
548 leal EXT_PSML,%a1 |answer is positive smallest denorm
554 leal DBL_PZRO,%a1 |answer is +/- zero
555 bsetb #z_bit,FPSR_CC(%a6)
558 leal DBL_PZRO,%a1 |answer is +/- zero
559 bsetb #z_bit,FPSR_CC(%a6)
560 bra uset_sign |now go set the sign
562 tstb LOCAL_SGN(%a0) |if negative overflow
565 leal DBL_PSML,%a1 |answer is smallest denormalized negative
566 bsetb #neg_bit,FPSR_CC(%a6)
569 leal DBL_PZRO,%a1 |answer is positive zero
570 bsetb #z_bit,FPSR_CC(%a6)
573 tstb LOCAL_SGN(%a0) |if negative overflow
576 leal DBL_PZRO,%a1 |answer is negative zero
577 oril #negz_mask,USER_FPSR(%a6)
580 leal DBL_PSML,%a1 |answer is smallest denormalized negative
586 leal SGL_PZRO,%a1 |answer is +/- zero
587 bsetb #z_bit,FPSR_CC(%a6)
590 leal SGL_PZRO,%a1 |answer is +/- zero
591 bsetb #z_bit,FPSR_CC(%a6)
594 tstb LOCAL_SGN(%a0) |if negative overflow
597 leal SGL_PSML,%a1 |answer is smallest denormalized negative
598 bsetb #neg_bit,FPSR_CC(%a6)
601 leal SGL_PZRO,%a1 |answer is positive zero
602 bsetb #z_bit,FPSR_CC(%a6)
605 tstb LOCAL_SGN(%a0) |if negative overflow
608 leal SGL_PZRO,%a1 |answer is negative zero
609 oril #negz_mask,USER_FPSR(%a6)
612 leal SGL_PSML,%a1 |answer is smallest denormalized positive
616 tstb LOCAL_SGN(%a0) |if negative overflow
619 bsetb #neg_bit,FPSR_CC(%a6)
622 movew LOCAL_EX(%a1),LOCAL_EX(%a0) |be careful not to overwrite sign
623 movel LOCAL_HI(%a1),LOCAL_HI(%a0)
624 movel LOCAL_LO(%a1),LOCAL_LO(%a0)
627 | reg_dest --- write byte, word, or long data to Dn
632 | d1: data size and dest register number formatted as:
635 | -----------------------------------------------
636 | | 0 | Size | Dest Reg # |
637 | -----------------------------------------------
672 movel %a0@(%d1:l:4),%a0
676 moveb L_SCR1(%a6),USER_D0+3(%a6)
679 moveb L_SCR1(%a6),USER_D1+3(%a6)
682 moveb L_SCR1(%a6),%d2
685 moveb L_SCR1(%a6),%d3
688 moveb L_SCR1(%a6),%d4
691 moveb L_SCR1(%a6),%d5
694 moveb L_SCR1(%a6),%d6
697 moveb L_SCR1(%a6),%d7
700 movew L_SCR1(%a6),USER_D0+2(%a6)
703 movew L_SCR1(%a6),USER_D1+2(%a6)
706 movew L_SCR1(%a6),%d2
709 movew L_SCR1(%a6),%d3
712 movew L_SCR1(%a6),%d4
715 movew L_SCR1(%a6),%d5
718 movew L_SCR1(%a6),%d6
721 movew L_SCR1(%a6),%d7
724 movel L_SCR1(%a6),USER_D0(%a6)
727 movel L_SCR1(%a6),USER_D1(%a6)
730 movel L_SCR1(%a6),%d2
733 movel L_SCR1(%a6),%d3
736 movel L_SCR1(%a6),%d4
739 movel L_SCR1(%a6),%d5
742 movel L_SCR1(%a6),%d6
745 movel L_SCR1(%a6),%d7