2 | do_func.sa 3.4 2/18/91
4 | Do_func performs the unimplemented operation. The operation
5 | to be performed is determined from the lower 7 bits of the
6 | extension word (except in the case of fmovecr and fsincos).
7 | The opcode and tag bits form an index into a jump table in
8 | tbldo.sa. Cases of zero, infinity and NaN are handled in
9 | do_func by forcing the default result. Normalized and
10 | denormalized (there are no unnormalized numbers at this
11 | point) are passed onto the emulation code.
13 | CMDREG1B and STAG are extracted from the fsave frame
14 | and combined to form the table index. The function called
15 | will start with a0 pointing to the ETEMP operand. Dyadic
16 | functions can find FPTEMP at -12(a0).
18 | Called functions return their result in fp0. Sincos returns
19 | sin(x) in fp0 and cos(x) in fp1.
22 | Copyright (C) Motorola, Inc. 1990
25 | For details on the license for this file, please see the
26 | file, README, in this same directory.
28 DO_FUNC: |idnt 2,1 | Motorola 040 Floating Point Software Package
44 |xref slognp1,slogn,slog10,slog2
45 |xref slognd,slog10d,slog2d
50 PONE: .long 0x3fff0000,0x80000000,0x00000000 |+1
51 MONE: .long 0xbfff0000,0x80000000,0x00000000 |-1
52 PZERO: .long 0x00000000,0x00000000,0x00000000 |+0
53 MZERO: .long 0x80000000,0x00000000,0x00000000 |-0
54 PINF: .long 0x7fff0000,0x00000000,0x00000000 |+inf
55 MINF: .long 0xffff0000,0x00000000,0x00000000 |-inf
56 QNAN: .long 0x7fff0000,0xffffffff,0xffffffff |non-signaling nan
57 PPIBY2: .long 0x3FFF0000,0xC90FDAA2,0x2168C235 |+PI/2
58 MPIBY2: .long 0xbFFF0000,0xC90FDAA2,0x2168C235 |-PI/2
64 | Check for fmovecr. It does not follow the format of fp gen
65 | unimplemented instructions. The test is on the upper 6 bits;
66 | if they are $17, the inst is fmovecr. Call entry smovcr
69 bfextu CMDREG1B(%a6){#0:#6},%d0 |get opclass and src fields
70 cmpil #0x17,%d0 |if op class and size fields are $17,
71 | ;it is FMOVECR; if not, continue
73 jmp smovcr |fmovecr; jmp directly to emulation
76 movew CMDREG1B(%a6),%d0
78 cmpil #0x38,%d0 |if the extension is >= $38,
79 bge serror |it is illegal
80 bfextu STAG(%a6){#0:#3},%d1
81 lsll #3,%d0 |make room for STAG
82 addl %d1,%d0 |combine for final index into table
83 leal tblpre,%a1 |start of monster jump table
84 movel (%a1,%d0.w*4),%a1 |real target address
85 leal ETEMP(%a6),%a0 |a0 is pointer to src op
86 movel USER_FPCR(%a6),%d1
87 andl #0xFF,%d1 | discard all but rounding mode/prec
98 | These routines load forced values into fp0. They are called
99 | by index into tbldo.
101 | Load a signed zero to fp0 and set inex2/ainex
105 btstb #sign_bit,LOCAL_EX(%a0) |get sign of source operand
106 bnes ld_mzinx |if negative, branch
107 bsr ld_pzero |bsr so we can return and set inx
108 bra t_inx2 |now, set the inx for the next inst
110 bsr ld_mzero |if neg, load neg zero, return here
111 bra t_inx2 |now, set the inx for the next inst
113 | Load a signed zero to fp0; do not set inex2/ainex
117 btstb #sign_bit,LOCAL_EX(%a0) |get sign of source operand
118 bne ld_mzero |if neg, load neg zero
119 bra ld_pzero |load positive zero
121 | Load a signed infinity to fp0; do not set inex2/ainex
125 btstb #sign_bit,LOCAL_EX(%a0) |get sign of source operand
126 bne ld_minf |if negative branch
129 | Load a signed one to fp0; do not set inex2/ainex
133 btstb #sign_bit,LOCAL_EX(%a0) |check sign of source
137 | Load a signed pi/2 to fp0; do not set inex2/ainex
141 btstb #sign_bit,LOCAL_EX(%a0) |check sign of source
145 | Load either a +0 or +inf for plus/minus operand
149 btstb #sign_bit,LOCAL_EX(%a0) |check sign of source
153 | Result is either an operr or +inf for plus/minus operand
154 | [Used by slogn, slognp1, slog10, and slog2]
158 btstb #sign_bit,LOCAL_EX(%a0) |check sign of source
166 fmovemx (%a0),%fp0-%fp0
169 fbeq t_dz2 |if = -1, divide by zero exception
170 fmovel #0,%FPSR |clr N flag
171 bra t_operr |take care of operands < -1
177 btstb #sign_bit,LOCAL_EX(%a0) |check sign of source
183 | Test for 1.0 as an input argument, returning +zero. Also check
184 | the sign and return operr if negative.
188 btstb #sign_bit,LOCAL_EX(%a0)
189 bne t_operr |take care of operands < 0
190 cmpiw #0x3fff,LOCAL_EX(%a0) |test for 1.0 input
192 cmpil #0x80000000,LOCAL_HI(%a0)
201 btstb #sign_bit,LOCAL_EX(%a0)
203 bra t_operr |take care of operands < 0
210 btstb #sign_bit,LOCAL_EX(%a0)
211 bne t_operr |take care of operands < 0
212 cmpiw #0x3fff,LOCAL_EX(%a0) |test for 1.0 input
214 cmpil #0x80000000,LOCAL_HI(%a0)
223 btstb #sign_bit,LOCAL_EX(%a0)
225 bra t_operr |take care of operands < 0
232 btstb #sign_bit,LOCAL_EX(%a0)
233 bne t_operr |take care of operands < 0
234 cmpiw #0x3fff,LOCAL_EX(%a0) |test for 1.0 input
236 cmpil #0x80000000,LOCAL_HI(%a0)
245 btstb #sign_bit,LOCAL_EX(%a0)
247 bra t_operr |take care of operands < 0
255 .long smod | 00,00 norm,norm = normal
256 .long smod_oper | 00,01 norm,zero = nan with operr
257 .long smod_fpn | 00,10 norm,inf = fpn
258 .long smod_snan | 00,11 norm,nan = nan
259 .long smod_zro | 01,00 zero,norm = +-zero
260 .long smod_oper | 01,01 zero,zero = nan with operr
261 .long smod_zro | 01,10 zero,inf = +-zero
262 .long smod_snan | 01,11 zero,nan = nan
263 .long smod_oper | 10,00 inf,norm = nan with operr
264 .long smod_oper | 10,01 inf,zero = nan with operr
265 .long smod_oper | 10,10 inf,inf = nan with operr
266 .long smod_snan | 10,11 inf,nan = nan
267 .long smod_dnan | 11,00 nan,norm = nan
268 .long smod_dnan | 11,01 nan,zero = nan
269 .long smod_dnan | 11,10 nan,inf = nan
270 .long smod_dnan | 11,11 nan,nan = nan
274 clrb FPSR_QBYTE(%a6) | clear quotient field
275 bfextu STAG(%a6){#0:#3},%d0 |stag = d0
276 bfextu DTAG(%a6){#0:#3},%d1 |dtag = d1
279 | Alias extended denorms to norms for the jump table.
285 orb %d0,%d1 |d1{3:2} = dtag, d1{1:0} = stag
287 | ;00 = norm or denorm
292 movel (%a1,%d1.w*4),%a1
302 moveb ETEMP(%a6),%d1 |get sign of src op
303 moveb FPTEMP(%a6),%d0 |get sign of dst op
304 eorb %d0,%d1 |get exor of sign bits
305 btstl #7,%d1 |test for sign
306 beqs smod_zsn |if clr, do not set sign big
307 bsetb #q_sn_bit,FPSR_QBYTE(%a6) |set q-byte sign bit
309 btstl #7,%d0 |test if + or -
310 beq ld_pzero |if pos then load +0
311 bra ld_mzero |else neg load -0
314 moveb ETEMP(%a6),%d1 |get sign of src op
315 moveb FPTEMP(%a6),%d0 |get sign of dst op
316 eorb %d0,%d1 |get exor of sign bits
317 btstl #7,%d1 |test for sign
318 beqs smod_fsn |if clr, do not set sign big
319 bsetb #q_sn_bit,FPSR_QBYTE(%a6) |set q-byte sign bit
321 tstb DTAG(%a6) |filter out denormal destination case
323 leal FPTEMP(%a6),%a0 |a0<- addr(FPTEMP)
324 bra t_resdnrm |force UNFL(but exact) result
326 fmovel USER_FPCR(%a6),%fpcr |use user's rmode and precision
327 fmovex FPTEMP(%a6),%fp0 |return dest to fp0
336 .long srem | 00,00 norm,norm = normal
337 .long srem_oper | 00,01 norm,zero = nan with operr
338 .long srem_fpn | 00,10 norm,inf = fpn
339 .long srem_snan | 00,11 norm,nan = nan
340 .long srem_zro | 01,00 zero,norm = +-zero
341 .long srem_oper | 01,01 zero,zero = nan with operr
342 .long srem_zro | 01,10 zero,inf = +-zero
343 .long srem_snan | 01,11 zero,nan = nan
344 .long srem_oper | 10,00 inf,norm = nan with operr
345 .long srem_oper | 10,01 inf,zero = nan with operr
346 .long srem_oper | 10,10 inf,inf = nan with operr
347 .long srem_snan | 10,11 inf,nan = nan
348 .long srem_dnan | 11,00 nan,norm = nan
349 .long srem_dnan | 11,01 nan,zero = nan
350 .long srem_dnan | 11,10 nan,inf = nan
351 .long srem_dnan | 11,11 nan,nan = nan
355 clrb FPSR_QBYTE(%a6) |clear quotient field
356 bfextu STAG(%a6){#0:#3},%d0 |stag = d0
357 bfextu DTAG(%a6){#0:#3},%d1 |dtag = d1
359 | Alias extended denorms to norms for the jump table.
365 orb %d0,%d1 |d1{3:2} = dtag, d1{1:0} = stag
367 | ;00 = norm or denorm
372 movel (%a1,%d1.w*4),%a1
382 moveb ETEMP(%a6),%d1 |get sign of src op
383 moveb FPTEMP(%a6),%d0 |get sign of dst op
384 eorb %d0,%d1 |get exor of sign bits
385 btstl #7,%d1 |test for sign
386 beqs srem_zsn |if clr, do not set sign big
387 bsetb #q_sn_bit,FPSR_QBYTE(%a6) |set q-byte sign bit
389 btstl #7,%d0 |test if + or -
390 beq ld_pzero |if pos then load +0
391 bra ld_mzero |else neg load -0
394 moveb ETEMP(%a6),%d1 |get sign of src op
395 moveb FPTEMP(%a6),%d0 |get sign of dst op
396 eorb %d0,%d1 |get exor of sign bits
397 btstl #7,%d1 |test for sign
398 beqs srem_fsn |if clr, do not set sign big
399 bsetb #q_sn_bit,FPSR_QBYTE(%a6) |set q-byte sign bit
401 tstb DTAG(%a6) |filter out denormal destination case
403 leal FPTEMP(%a6),%a0 |a0<- addr(FPTEMP)
404 bra t_resdnrm |force UNFL(but exact) result
406 fmovel USER_FPCR(%a6),%fpcr |use user's rmode and precision
407 fmovex FPTEMP(%a6),%fp0 |return dest to fp0
415 .long sscale | 00,00 norm,norm = result
416 .long sscale | 00,01 norm,zero = fpn
417 .long scl_opr | 00,10 norm,inf = nan with operr
418 .long scl_snan | 00,11 norm,nan = nan
419 .long scl_zro | 01,00 zero,norm = +-zero
420 .long scl_zro | 01,01 zero,zero = +-zero
421 .long scl_opr | 01,10 zero,inf = nan with operr
422 .long scl_snan | 01,11 zero,nan = nan
423 .long scl_inf | 10,00 inf,norm = +-inf
424 .long scl_inf | 10,01 inf,zero = +-inf
425 .long scl_opr | 10,10 inf,inf = nan with operr
426 .long scl_snan | 10,11 inf,nan = nan
427 .long scl_dnan | 11,00 nan,norm = nan
428 .long scl_dnan | 11,01 nan,zero = nan
429 .long scl_dnan | 11,10 nan,inf = nan
430 .long scl_dnan | 11,11 nan,nan = nan
434 bfextu STAG(%a6){#0:#3},%d0 |stag in d0
435 bfextu DTAG(%a6){#0:#3},%d1 |dtag in d1
436 bclrl #2,%d0 |alias denorm into norm
437 bclrl #2,%d1 |alias denorm into norm
439 orb %d0,%d1 |d1{4:2} = dtag, d1{1:0} = stag
440 | ;dtag values stag values:
441 | ;000 = norm 00 = norm
442 | ;001 = zero 01 = zero
443 | ;010 = inf 10 = inf
444 | ;011 = nan 11 = nan
448 leal pscalet,%a1 |load start of jump table
449 movel (%a1,%d1.w*4),%a1 |load a1 with label depending on tag
450 jmp (%a1) |go to the routine
459 btstb #sign_bit,FPTEMP_EX(%a6) |test if + or -
460 beq ld_pzero |if pos then load +0
461 bra ld_mzero |if neg then load -0
463 btstb #sign_bit,FPTEMP_EX(%a6) |test if + or -
464 beq ld_pinf |if pos then load +inf
465 bra ld_minf |else neg load -inf
473 btstb #sign_bit,ETEMP(%a6) |get sign
480 fmovemx PONE,%fp1-%fp1 |do not allow FPSR to be affected
481 bra sto_cos |store cosine result
485 fmovex QNAN,%fp1 |load NAN
486 bsr sto_cos |store cosine result
487 fmovex QNAN,%fp0 |load NAN
492 movel ETEMP_EX(%a6),FP_SCR1(%a6)
493 movel ETEMP_HI(%a6),FP_SCR1+4(%a6)
494 movel ETEMP_LO(%a6),FP_SCR1+8(%a6)
495 bsetb #signan_bit,FP_SCR1+4(%a6)
496 fmovemx FP_SCR1(%a6),%fp1-%fp1
500 | This code forces default values for the zero, inf, and nan cases
501 | in the transcendentals code. The CC bits must be set in the
502 | stacked FPSR to be correctly reported.
507 fmovex PPIBY2,%fp0 |load +pi/2
508 bra t_inx2 |set inex2 exc
513 fmovex MPIBY2,%fp0 |load -pi/2
514 orl #neg_mask,USER_FPSR(%a6) |set N bit
515 bra t_inx2 |set inex2 exc
520 fmovex PINF,%fp0 |load +inf
521 orl #inf_mask,USER_FPSR(%a6) |set I bit
527 fmovex MINF,%fp0 |load -inf
528 orl #neg_mask+inf_mask,USER_FPSR(%a6) |set N and I bits
534 fmovex PONE,%fp0 |load +1
540 fmovex MONE,%fp0 |load -1
541 orl #neg_mask,USER_FPSR(%a6) |set N bit
547 fmovex PZERO,%fp0 |load +0
548 orl #z_mask,USER_FPSR(%a6) |set Z bit
554 fmovex MZERO,%fp0 |load -0
555 orl #neg_mask+z_mask,USER_FPSR(%a6) |set N and Z bits