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 | THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA
20 | The copyright notice above does not evidence any
21 | actual or intended publication of such source code.
23 |UTIL idnt 2,1 | Motorola 040 Floating Point Software Package
38 | Final result table for ovf_res. Note that the negative counterparts
39 | are unnecessary as ovf_res always returns the sign separately from
42 EXT_PINF: .long 0x7fff0000,0x00000000,0x00000000,0x00000000
44 EXT_PLRG: .long 0x7ffe0000,0xffffffff,0xffffffff,0x00000000
45 | ;largest magnitude +sgl in ext
46 SGL_PLRG: .long 0x407e0000,0xffffff00,0x00000000,0x00000000
47 | ;largest magnitude +dbl in ext
48 DBL_PLRG: .long 0x43fe0000,0xffffffff,0xfffff800,0x00000000
71 | ovf_r_k --- overflow result calculation
73 | This entry point is used by kernel_ex.
75 | This forces the destination precision to be extended
77 | Input: operand in ETEMP
78 | Output: a result is in ETEMP (internal extended format)
82 lea ETEMP(%a6),%a0 |a0 points to source operand
83 bclrb #sign_bit,ETEMP_EX(%a6)
84 sne ETEMP_SGN(%a6) |convert to internal IEEE format
87 | ovf_r_x2 --- overflow result calculation
89 | This entry point used by x_ovfl. (opclass 0 and 2)
91 | Input a0 points to an operand in the internal extended format
92 | Output a0 points to the result in the internal extended format
94 | This sets the round precision according to the user's FPCR unless the
95 | instruction is fsgldiv or fsglmul or fsadd, fdadd, fsub, fdsub, fsmul,
96 | fdmul, fsdiv, fddiv, fssqrt, fsmove, fdmove, fsabs, fdabs, fsneg, fdneg.
97 | If the instruction is fsgldiv of fsglmul, the rounding precision must be
98 | extended. If the instruction is not fsgldiv or fsglmul but a force-
99 | precision instruction, the rounding precision is then set to the force
104 btstb #E3,E_BYTE(%a6) |check for nu exception
105 beql ovf_e1_exc |it is cu exception
107 movew CMDREG3B(%a6),%d0 |get the command word
108 andiw #0x00000060,%d0 |clear all bits except 6 and 5
109 cmpil #0x00000040,%d0
110 beql ovff_sgl |force precision is single
111 cmpil #0x00000060,%d0
112 beql ovff_dbl |force precision is double
113 movew CMDREG3B(%a6),%d0 |get the command word again
114 andil #0x7f,%d0 |clear all except operation
116 beql ovf_fsgl |fsglmul or fsgldiv
119 bra ovf_fpcr |instruction is none of the above
122 movew CMDREG1B(%a6),%d0 |get command word
123 andil #0x00000044,%d0 |clear all bits except 6 and 2
124 cmpil #0x00000040,%d0
125 beql ovff_sgl |the instruction is force single
126 cmpil #0x00000044,%d0
127 beql ovff_dbl |the instruction is force double
128 movew CMDREG1B(%a6),%d0 |again get the command word
129 andil #0x0000007f,%d0 |clear all except the op code
130 cmpil #0x00000027,%d0
131 beql ovf_fsgl |fsglmul
132 cmpil #0x00000024,%d0
133 beql ovf_fsgl |fsgldiv
134 bra ovf_fpcr |none of the above, use FPCR
137 | Inst is either fsgldiv or fsglmul. Force extended precision.
144 movel #0x00000001,%d0 |set single
147 movel #0x00000002,%d0 |set double
150 | The precision is in the fpcr.
153 bfextu FPCR_MODE(%a6){#0:#2},%d0 |set round precision
158 | ovf_r_x3 --- overflow result calculation
160 | This entry point used by x_ovfl. (opclass 3 only)
162 | Input a0 points to an operand in the internal extended format
163 | Output a0 points to the result in the internal extended format
165 | This sets the round precision according to the destination size.
169 bsr g_dfmtou |get dest fmt in d0{1:0}
170 | ;for fmovout, the destination format
171 | ;is the rounding precision
174 | ovf_res --- overflow result calculation
177 | a0 points to operand in internal extended format
179 | a0 points to result in internal extended format
183 lsll #2,%d0 |move round precision to d0{3:2}
184 bfextu FPCR_MODE(%a6){#2:#2},%d1 |set round mode
185 orl %d1,%d0 |index is fmt:mode in d0{3:0}
186 leal tblovfl,%a1 |load a1 with table address
187 movel %a1@(%d0:l:4),%a1 |use d0 as index to the table
188 jmp (%a1) |go to the correct routine
193 leal EXT_PINF,%a1 |answer is +/- infinity
194 bsetb #inf_bit,FPSR_CC(%a6)
195 bra set_sign |now go set the sign
197 leal EXT_PLRG,%a1 |answer is +/- large number
198 bra set_sign |now go set the sign
200 tstb LOCAL_SGN(%a0) |if negative overflow
203 leal EXT_PINF,%a1 |answer is negative infinity
204 orl #neginf_mask,USER_FPSR(%a6)
207 leal EXT_PLRG,%a1 |answer is large positive number
210 tstb LOCAL_SGN(%a0) |if negative overflow
213 leal EXT_PLRG,%a1 |answer is large negative number
214 bsetb #neg_bit,FPSR_CC(%a6)
217 leal EXT_PINF,%a1 |answer is positive infinity
218 bsetb #inf_bit,FPSR_CC(%a6)
224 leal EXT_PINF,%a1 |answer is +/- infinity
225 bsetb #inf_bit,FPSR_CC(%a6)
228 leal DBL_PLRG,%a1 |answer is +/- large number
229 bra set_sign |now go set the sign
231 tstb LOCAL_SGN(%a0) |if negative overflow
234 leal EXT_PINF,%a1 |answer is negative infinity
235 orl #neginf_mask,USER_FPSR(%a6)
236 bra end_ovfr |inf is same for all precisions (ext,dbl,sgl)
238 leal DBL_PLRG,%a1 |answer is large positive number
241 tstb LOCAL_SGN(%a0) |if negative overflow
244 leal DBL_PLRG,%a1 |answer is large negative number
245 bsetb #neg_bit,FPSR_CC(%a6)
248 leal EXT_PINF,%a1 |answer is positive infinity
249 bsetb #inf_bit,FPSR_CC(%a6)
255 leal EXT_PINF,%a1 |answer is +/- infinity
256 bsetb #inf_bit,FPSR_CC(%a6)
259 leal SGL_PLRG,%a1 |answer is +/- large number
262 tstb LOCAL_SGN(%a0) |if negative overflow
265 leal EXT_PINF,%a1 |answer is negative infinity
266 orl #neginf_mask,USER_FPSR(%a6)
269 leal SGL_PLRG,%a1 |answer is large positive number
272 tstb LOCAL_SGN(%a0) |if negative overflow
275 leal SGL_PLRG,%a1 |answer is large negative number
276 bsetb #neg_bit,FPSR_CC(%a6)
279 leal EXT_PINF,%a1 |answer is positive infinity
280 bsetb #inf_bit,FPSR_CC(%a6)
284 tstb LOCAL_SGN(%a0) |if negative overflow
287 bsetb #neg_bit,FPSR_CC(%a6)
290 movew LOCAL_EX(%a1),LOCAL_EX(%a0) |do not overwrite sign
291 movel LOCAL_HI(%a1),LOCAL_HI(%a0)
292 movel LOCAL_LO(%a1),LOCAL_LO(%a0)
302 | get_fline --- get f-line opcode of interrupted instruction
304 | Returns opcode in the low word of d0.
307 movel USER_FPIAR(%a6),%a0 |opcode address
308 movel #0,-(%a7) |reserve a word on the stack
309 leal 2(%a7),%a1 |point to low word of temporary
315 | g_rndpr --- put rounding precision in d0{1:0}
317 | valid return codes are:
323 | get rounding precision (cmdreg3b{6:5})
325 | case opclass = 011 (move out)
326 | get destination format - this is the also the rounding precision
330 | *case RndPr(from cmdreg3b{6:5} = 11 then RND_PREC = DBL
331 | *case RndPr(from cmdreg3b{6:5} = 10 then RND_PREC = SGL
332 | case RndPr(from cmdreg3b{6:5} = 00 | 01
333 | use precision from FPCR{7:6}
334 | case 00 then RND_PREC = EXT
335 | case 01 then RND_PREC = SGL
336 | case 10 then RND_PREC = DBL
338 | use precision in FPCR{7:6}
339 | case 00 then RND_PREC = EXT
340 | case 01 then RND_PREC = SGL
341 | case 10 then RND_PREC = DBL
345 bsr g_opcls |get opclass in d0{2:0}
346 cmpw #0x0003,%d0 |check for opclass 011
350 | For move out instructions (opclass 011) the destination format
351 | is the same as the rounding precision. Pass results from g_dfmtou.
356 btstb #E3,E_BYTE(%a6)
357 beql unf_e1_exc |branch to e1 underflow
359 movel CMDREG3B(%a6),%d0 |rounding precision in d0{10:9}
360 bfextu %d0{#9:#2},%d0 |move the rounding prec bits to d0{1:0}
362 beql unff_sgl |force precision is single
363 cmpil #0x3,%d0 |force precision is double
365 movew CMDREG3B(%a6),%d0 |get the command word again
366 andil #0x7f,%d0 |clear all except operation
368 beql unf_fsgl |fsglmul or fsgldiv
370 beql unf_fsgl |fsgldiv or fsglmul
373 movel CMDREG1B(%a6),%d0 |get 32 bits off the stack, 1st 16 bits
374 | ;are the command word
375 andil #0x00440000,%d0 |clear all bits except bits 6 and 2
376 cmpil #0x00400000,%d0
377 beql unff_sgl |force single
378 cmpil #0x00440000,%d0 |force double
380 movel CMDREG1B(%a6),%d0 |get the command word again
381 andil #0x007f0000,%d0 |clear all bits except the operation
382 cmpil #0x00270000,%d0
383 beql unf_fsgl |fsglmul
384 cmpil #0x00240000,%d0
385 beql unf_fsgl |fsgldiv
389 | Convert to return format. The values from cmdreg3b and the return
391 | cmdreg3b return precision
392 | -------- ------ ---------
399 movel #1,%d0 |return 1
405 movel #2,%d0 |return 2
414 | Get rounding precision set in FPCR{7:6}.
417 movel USER_FPCR(%a6),%d0 |rounding precision bits in d0{7:6}
418 bfextu %d0{#24:#2},%d0 |move the rounding prec bits to d0{1:0}
421 | g_opcls --- put opclass in d0{2:0}
424 btstb #E3,E_BYTE(%a6)
425 beqs opc_1b |if set, go to cmdreg1b
427 clrl %d0 |if E3, only opclass 0x0 is possible
430 movel CMDREG1B(%a6),%d0
431 bfextu %d0{#0:#3},%d0 |shift opclass bits d0{31:29} to d0{2:0}
434 | g_dfmtou --- put destination format in d0{1:0}
436 | If E1, the format is from cmdreg1b{12:10}
437 | If E3, the format is extended.
445 btstb #E3,E_BYTE(%a6)
447 clrl %d0 |if E1, size is always ext
450 movel CMDREG1B(%a6),%d0
451 bfextu %d0{#3:#3},%d0 |dest fmt from cmdreg1b{12:10}
452 cmpb #1,%d0 |check for single
457 cmpb #5,%d0 |check for double
462 clrl %d0 |must be extended
467 | Final result table for unf_sub. Note that the negative counterparts
468 | are unnecessary as unf_sub always returns the sign separately from
471 EXT_PZRO: .long 0x00000000,0x00000000,0x00000000,0x00000000
473 SGL_PZRO: .long 0x3f810000,0x00000000,0x00000000,0x00000000
475 DBL_PZRO: .long 0x3c010000,0x00000000,0x00000000,0x00000000
476 | ;smallest +ext denorm
477 EXT_PSML: .long 0x00000000,0x00000000,0x00000001,0x00000000
478 | ;smallest +sgl denorm
479 SGL_PSML: .long 0x3f810000,0x00000100,0x00000000,0x00000000
480 | ;smallest +dbl denorm
481 DBL_PSML: .long 0x3c010000,0x00000000,0x00000800,0x00000000
483 | UNF_SUB --- underflow result calculation
486 | d0 contains round precision
487 | a0 points to input operand in the internal extended format
490 | a0 points to correct internal extended precision result.
513 lsll #2,%d0 |move round precision to d0{3:2}
514 bfextu FPCR_MODE(%a6){#2:#2},%d1 |set round mode
515 orl %d1,%d0 |index is fmt:mode in d0{3:0}
516 leal tblunf,%a1 |load a1 with table address
517 movel %a1@(%d0:l:4),%a1 |use d0 as index to the table
518 jmp (%a1) |go to the correct routine
523 leal EXT_PZRO,%a1 |answer is +/- zero
524 bsetb #z_bit,FPSR_CC(%a6)
525 bra uset_sign |now go set the sign
527 leal EXT_PZRO,%a1 |answer is +/- zero
528 bsetb #z_bit,FPSR_CC(%a6)
529 bra uset_sign |now go set the sign
531 tstb LOCAL_SGN(%a0) |if negative underflow
534 leal EXT_PSML,%a1 |answer is negative smallest denorm
535 bsetb #neg_bit,FPSR_CC(%a6)
538 leal EXT_PZRO,%a1 |answer is positive zero
539 bsetb #z_bit,FPSR_CC(%a6)
542 tstb LOCAL_SGN(%a0) |if negative underflow
545 leal EXT_PZRO,%a1 |answer is negative zero
546 oril #negz_mask,USER_FPSR(%a6)
549 leal EXT_PSML,%a1 |answer is positive smallest denorm
555 leal DBL_PZRO,%a1 |answer is +/- zero
556 bsetb #z_bit,FPSR_CC(%a6)
559 leal DBL_PZRO,%a1 |answer is +/- zero
560 bsetb #z_bit,FPSR_CC(%a6)
561 bra uset_sign |now go set the sign
563 tstb LOCAL_SGN(%a0) |if negative overflow
566 leal DBL_PSML,%a1 |answer is smallest denormalized negative
567 bsetb #neg_bit,FPSR_CC(%a6)
570 leal DBL_PZRO,%a1 |answer is positive zero
571 bsetb #z_bit,FPSR_CC(%a6)
574 tstb LOCAL_SGN(%a0) |if negative overflow
577 leal DBL_PZRO,%a1 |answer is negative zero
578 oril #negz_mask,USER_FPSR(%a6)
581 leal DBL_PSML,%a1 |answer is smallest denormalized negative
587 leal SGL_PZRO,%a1 |answer is +/- zero
588 bsetb #z_bit,FPSR_CC(%a6)
591 leal SGL_PZRO,%a1 |answer is +/- zero
592 bsetb #z_bit,FPSR_CC(%a6)
595 tstb LOCAL_SGN(%a0) |if negative overflow
598 leal SGL_PSML,%a1 |answer is smallest denormalized negative
599 bsetb #neg_bit,FPSR_CC(%a6)
602 leal SGL_PZRO,%a1 |answer is positive zero
603 bsetb #z_bit,FPSR_CC(%a6)
606 tstb LOCAL_SGN(%a0) |if negative overflow
609 leal SGL_PZRO,%a1 |answer is negative zero
610 oril #negz_mask,USER_FPSR(%a6)
613 leal SGL_PSML,%a1 |answer is smallest denormalized positive
617 tstb LOCAL_SGN(%a0) |if negative overflow
620 bsetb #neg_bit,FPSR_CC(%a6)
623 movew LOCAL_EX(%a1),LOCAL_EX(%a0) |be careful not to overwrite sign
624 movel LOCAL_HI(%a1),LOCAL_HI(%a0)
625 movel LOCAL_LO(%a1),LOCAL_LO(%a0)
628 | reg_dest --- write byte, word, or long data to Dn
633 | d1: data size and dest register number formatted as:
636 | -----------------------------------------------
637 | | 0 | Size | Dest Reg # |
638 | -----------------------------------------------
673 movel %a0@(%d1:l:4),%a0
677 moveb L_SCR1(%a6),USER_D0+3(%a6)
680 moveb L_SCR1(%a6),USER_D1+3(%a6)
683 moveb L_SCR1(%a6),%d2
686 moveb L_SCR1(%a6),%d3
689 moveb L_SCR1(%a6),%d4
692 moveb L_SCR1(%a6),%d5
695 moveb L_SCR1(%a6),%d6
698 moveb L_SCR1(%a6),%d7
701 movew L_SCR1(%a6),USER_D0+2(%a6)
704 movew L_SCR1(%a6),USER_D1+2(%a6)
707 movew L_SCR1(%a6),%d2
710 movew L_SCR1(%a6),%d3
713 movew L_SCR1(%a6),%d4
716 movew L_SCR1(%a6),%d5
719 movew L_SCR1(%a6),%d6
722 movew L_SCR1(%a6),%d7
725 movel L_SCR1(%a6),USER_D0(%a6)
728 movel L_SCR1(%a6),USER_D1(%a6)
731 movel L_SCR1(%a6),%d2
734 movel L_SCR1(%a6),%d3
737 movel L_SCR1(%a6),%d4
740 movel L_SCR1(%a6),%d5
743 movel L_SCR1(%a6),%d6
746 movel L_SCR1(%a6),%d7