~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
M68000 Hi-Performance Microprocessor Division
M68060 Software Package
Production Release P1.00 -- October 10, 1994
M68060 Software Package Copyright © 1993, 1994 Motorola Inc. All rights reserved.
THE SOFTWARE is provided on an "AS IS" basis and without warranty.
To the maximum extent permitted by applicable law,
MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
and any warranty against infringement with regard to the SOFTWARE
(INCLUDING ANY MODIFIED VERSIONS THEREOF) and any accompanying written materials.
To the maximum extent permitted by applicable law,
IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
(INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS)
ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.
Motorola assumes no responsibility for the maintenance and support of the SOFTWARE.
You are hereby granted a copyright license to use, modify, and distribute the SOFTWARE
so long as this entire notice is retained without alteration in any modified and/or
redistributed versions, and that such modified versions are clearly identified as such.
No licenses are granted by implication, estoppel or otherwise under any patents
or trademarks of Motorola, Inc.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
set _off_bsun, 0x00
set _off_snan, 0x04
set _off_operr, 0x08
set _off_ovfl, 0x0c
set _off_unfl, 0x10
set _off_dz, 0x14
set _off_inex, 0x18
set _off_fline, 0x1c
set _off_fpu_dis, 0x20
set _off_trap, 0x24
set _off_trace, 0x28
set _off_access, 0x2c
set _off_done, 0x30
set _off_imr, 0x40
set _off_dmr, 0x44
set _off_dmw, 0x48
set _off_irw, 0x4c
set _off_irl, 0x50
set _off_drb, 0x54
set _off_drw, 0x58
set _off_drl, 0x5c
set _off_dwb, 0x60
set _off_dww, 0x64
set _off_dwl, 0x68
_060FPSP_TABLE:
###############################################################
bra.l _fpsp_snan
short 0x0000
bra.l _fpsp_operr
short 0x0000
bra.l _fpsp_ovfl
short 0x0000
bra.l _fpsp_unfl
short 0x0000
bra.l _fpsp_dz
short 0x0000
bra.l _fpsp_inex
short 0x0000
bra.l _fpsp_fline
short 0x0000
bra.l _fpsp_unsupp
short 0x0000
bra.l _fpsp_effadd
short 0x0000
space 56
###############################################################
global _fpsp_done
_fpsp_done:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_done,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _real_ovfl
_real_ovfl:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_ovfl,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _real_unfl
_real_unfl:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_unfl,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _real_inex
_real_inex:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_inex,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _real_bsun
_real_bsun:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_bsun,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _real_operr
_real_operr:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_operr,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _real_snan
_real_snan:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_snan,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _real_dz
_real_dz:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_dz,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _real_fline
_real_fline:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_fline,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _real_fpu_disabled
_real_fpu_disabled:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_fpu_dis,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _real_trap
_real_trap:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_trap,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _real_trace
_real_trace:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_trace,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _real_access
_real_access:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_access,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
#######################################
global _imem_read
_imem_read:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_imr,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _dmem_read
_dmem_read:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_dmr,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _dmem_write
_dmem_write:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_dmw,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _imem_read_word
_imem_read_word:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_irw,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _imem_read_long
_imem_read_long:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_irl,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _dmem_read_byte
_dmem_read_byte:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_drb,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _dmem_read_word
_dmem_read_word:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_drw,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _dmem_read_long
_dmem_read_long:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_drl,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _dmem_write_byte
_dmem_write_byte:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_dwb,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _dmem_write_word
_dmem_write_word:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_dww,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
global _dmem_write_long
_dmem_write_long:
mov.l %d0,-(%sp)
mov.l (_060FPSP_TABLE-0x80+_off_dwl,%pc),%d0
pea.l (_060FPSP_TABLE-0x80,%pc,%d0)
mov.l 0x4(%sp),%d0
rtd &0x4
#
#
set LOCAL_SIZE, 192 # stack frame size(bytes)
set LV, -LOCAL_SIZE # stack offset
set EXC_SR, 0x4 # stack status register
set EXC_PC, 0x6 # stack pc
set EXC_VOFF, 0xa # stacked vector offset
set EXC_EA, 0xc # stacked <ea>
set EXC_FP, 0x0 # frame pointer
set EXC_AREGS, -68 # offset of all address regs
set EXC_DREGS, -100 # offset of all data regs
set EXC_FPREGS, -36 # offset of all fp regs
set EXC_A7, EXC_AREGS+(7*4) # offset of saved a7
set OLD_A7, EXC_AREGS+(6*4) # extra copy of saved a7
set EXC_A6, EXC_AREGS+(6*4) # offset of saved a6
set EXC_A5, EXC_AREGS+(5*4)
set EXC_A4, EXC_AREGS+(4*4)
set EXC_A3, EXC_AREGS+(3*4)
set EXC_A2, EXC_AREGS+(2*4)
set EXC_A1, EXC_AREGS+(1*4)
set EXC_A0, EXC_AREGS+(0*4)
set EXC_D7, EXC_DREGS+(7*4)
set EXC_D6, EXC_DREGS+(6*4)
set EXC_D5, EXC_DREGS+(5*4)
set EXC_D4, EXC_DREGS+(4*4)
set EXC_D3, EXC_DREGS+(3*4)
set EXC_D2, EXC_DREGS+(2*4)
set EXC_D1, EXC_DREGS+(1*4)
set EXC_D0, EXC_DREGS+(0*4)
set EXC_FP0, EXC_FPREGS+(0*12) # offset of saved fp0
set EXC_FP1, EXC_FPREGS+(1*12) # offset of saved fp1
set EXC_FP2, EXC_FPREGS+(2*12) # offset of saved fp2 (not used)
set FP_SCR1, LV+80 # fp scratch 1
set FP_SCR1_EX, FP_SCR1+0
set FP_SCR1_SGN, FP_SCR1+2
set FP_SCR1_HI, FP_SCR1+4
set FP_SCR1_LO, FP_SCR1+8
set FP_SCR0, LV+68 # fp scratch 0
set FP_SCR0_EX, FP_SCR0+0
set FP_SCR0_SGN, FP_SCR0+2
set FP_SCR0_HI, FP_SCR0+4
set FP_SCR0_LO, FP_SCR0+8
set FP_DST, LV+56 # fp destination operand
set FP_DST_EX, FP_DST+0
set FP_DST_SGN, FP_DST+2
set FP_DST_HI, FP_DST+4
set FP_DST_LO, FP_DST+8
set FP_SRC, LV+44 # fp source operand
set FP_SRC_EX, FP_SRC+0
set FP_SRC_SGN, FP_SRC+2
set FP_SRC_HI, FP_SRC+4
set FP_SRC_LO, FP_SRC+8
set USER_FPIAR, LV+40 # FP instr address register
set USER_FPSR, LV+36 # FP status register
set FPSR_CC, USER_FPSR+0 # FPSR condition codes
set FPSR_QBYTE, USER_FPSR+1 # FPSR qoutient byte
set FPSR_EXCEPT, USER_FPSR+2 # FPSR exception status byte
set FPSR_AEXCEPT, USER_FPSR+3 # FPSR accrued exception byte
set USER_FPCR, LV+32 # FP control register
set FPCR_ENABLE, USER_FPCR+2 # FPCR exception enable
set FPCR_MODE, USER_FPCR+3 # FPCR rounding mode control
set L_SCR3, LV+28 # integer scratch 3
set L_SCR2, LV+24 # integer scratch 2
set L_SCR1, LV+20 # integer scratch 1
set STORE_FLG, LV+19 # flag: operand store (ie. not fcmp/ftst)
set EXC_TEMP2, LV+24 # temporary space
set EXC_TEMP, LV+16 # temporary space
set DTAG, LV+15 # destination operand type
set STAG, LV+14 # source operand type
set SPCOND_FLG, LV+10 # flag: special case (see below)
set EXC_CC, LV+8 # saved condition codes
set EXC_EXTWPTR, LV+4 # saved current PC (active)
set EXC_EXTWORD, LV+2 # saved extension word
set EXC_CMDREG, LV+2 # saved extension word
set EXC_OPWORD, LV+0 # saved operation word
################################
set FTEMP, 0 # offsets within an
set FTEMP_EX, 0 # extended precision
set FTEMP_SGN, 2 # value saved in memory.
set FTEMP_HI, 4
set FTEMP_LO, 8
set FTEMP_GRS, 12
set LOCAL, 0 # offsets within an
set LOCAL_EX, 0 # extended precision
set LOCAL_SGN, 2 # value saved in memory.
set LOCAL_HI, 4
set LOCAL_LO, 8
set LOCAL_GRS, 12
set DST, 0 # offsets within an
set DST_EX, 0 # extended precision
set DST_HI, 4 # value saved in memory.
set DST_LO, 8
set SRC, 0 # offsets within an
set SRC_EX, 0 # extended precision
set SRC_HI, 4 # value saved in memory.
set SRC_LO, 8
set SGL_LO, 0x3f81 # min sgl prec exponent
set SGL_HI, 0x407e # max sgl prec exponent
set DBL_LO, 0x3c01 # min dbl prec exponent
set DBL_HI, 0x43fe # max dbl prec exponent
set EXT_LO, 0x0 # min ext prec exponent
set EXT_HI, 0x7ffe # max ext prec exponent
set EXT_BIAS, 0x3fff # extended precision bias
set SGL_BIAS, 0x007f # single precision bias
set DBL_BIAS, 0x03ff # double precision bias
set NORM, 0x00 # operand type for STAG/DTAG
set ZERO, 0x01 # operand type for STAG/DTAG
set INF, 0x02 # operand type for STAG/DTAG
set QNAN, 0x03 # operand type for STAG/DTAG
set DENORM, 0x04 # operand type for STAG/DTAG
set SNAN, 0x05 # operand type for STAG/DTAG
set UNNORM, 0x06 # operand type for STAG/DTAG
##################
##################
set neg_bit, 0x3 # negative result
set z_bit, 0x2 # zero result
set inf_bit, 0x1 # infinite result
set nan_bit, 0x0 # NAN result
set q_sn_bit, 0x7 # sign bit of quotient byte
set bsun_bit, 7 # branch on unordered
set snan_bit, 6 # signalling NAN
set operr_bit, 5 # operand error
set ovfl_bit, 4 # overflow
set unfl_bit, 3 # underflow
set dz_bit, 2 # divide by zero
set inex2_bit, 1 # inexact result 2
set inex1_bit, 0 # inexact result 1
set aiop_bit, 7 # accrued inexact operation bit
set aovfl_bit, 6 # accrued overflow bit
set aunfl_bit, 5 # accrued underflow bit
set adz_bit, 4 # accrued dz bit
set ainex_bit, 3 # accrued inexact bit
#############################
#############################
set neg_mask, 0x08000000 # negative bit mask (lw)
set inf_mask, 0x02000000 # infinity bit mask (lw)
set z_mask, 0x04000000 # zero bit mask (lw)
set nan_mask, 0x01000000 # nan bit mask (lw)
set neg_bmask, 0x08 # negative bit mask (byte)
set inf_bmask, 0x02 # infinity bit mask (byte)
set z_bmask, 0x04 # zero bit mask (byte)
set nan_bmask, 0x01 # nan bit mask (byte)
set bsun_mask, 0x00008000 # bsun exception mask
set snan_mask, 0x00004000 # snan exception mask
set operr_mask, 0x00002000 # operr exception mask
set ovfl_mask, 0x00001000 # overflow exception mask
set unfl_mask, 0x00000800 # underflow exception mask
set dz_mask, 0x00000400 # dz exception mask
set inex2_mask, 0x00000200 # inex2 exception mask
set inex1_mask, 0x00000100 # inex1 exception mask
set aiop_mask, 0x00000080 # accrued illegal operation
set aovfl_mask, 0x00000040 # accrued overflow
set aunfl_mask, 0x00000020 # accrued underflow
set adz_mask, 0x00000010 # accrued divide by zero
set ainex_mask, 0x00000008 # accrued inexact
######################################
######################################
set dzinf_mask, inf_mask+dz_mask+adz_mask
set opnan_mask, nan_mask+operr_mask+aiop_mask
set nzi_mask, 0x01ffffff #clears N, Z, and I
set unfinx_mask, unfl_mask+inex2_mask+aunfl_mask+ainex_mask
set unf2inx_mask, unfl_mask+inex2_mask+ainex_mask
set ovfinx_mask, ovfl_mask+inex2_mask+aovfl_mask+ainex_mask
set inx1a_mask, inex1_mask+ainex_mask
set inx2a_mask, inex2_mask+ainex_mask
set snaniop_mask, nan_mask+snan_mask+aiop_mask
set snaniop2_mask, snan_mask+aiop_mask
set naniop_mask, nan_mask+aiop_mask
set neginf_mask, neg_mask+inf_mask
set infaiop_mask, inf_mask+aiop_mask
set negz_mask, neg_mask+z_mask
set opaop_mask, operr_mask+aiop_mask
set unfl_inx_mask, unfl_mask+aunfl_mask+ainex_mask
set ovfl_inx_mask, ovfl_mask+aovfl_mask+ainex_mask
#########
#########
set rnd_stky_bit, 29 # stky bit pos in longword
set sign_bit, 0x7 # sign bit
set signan_bit, 0x6 # signalling nan bit
set sgl_thresh, 0x3f81 # minimum sgl exponent
set dbl_thresh, 0x3c01 # minimum dbl exponent
set x_mode, 0x0 # extended precision
set s_mode, 0x4 # single precision
set d_mode, 0x8 # double precision
set rn_mode, 0x0 # round-to-nearest
set rz_mode, 0x1 # round-to-zero
set rm_mode, 0x2 # round-tp-minus-infinity
set rp_mode, 0x3 # round-to-plus-infinity
set mantissalen, 64 # length of mantissa in bits
set BYTE, 1 # len(byte) == 1 byte
set WORD, 2 # len(word) == 2 bytes
set LONG, 4 # len(longword) == 2 bytes
set BSUN_VEC, 0xc0 # bsun vector offset
set INEX_VEC, 0xc4 # inexact vector offset
set DZ_VEC, 0xc8 # dz vector offset
set UNFL_VEC, 0xcc # unfl vector offset
set OPERR_VEC, 0xd0 # operr vector offset
set OVFL_VEC, 0xd4 # ovfl vector offset
set SNAN_VEC, 0xd8 # snan vector offset
###########################
###########################
set ftrapcc_flg, 0x01 # flag bit: ftrapcc exception
set fbsun_flg, 0x02 # flag bit: bsun exception
set mia7_flg, 0x04 # flag bit: (a7)+ <ea>
set mda7_flg, 0x08 # flag bit: -(a7) <ea>
set fmovm_flg, 0x40 # flag bit: fmovm instruction
set immed_flg, 0x80 # flag bit: &<data> <ea>
set ftrapcc_bit, 0x0
set fbsun_bit, 0x1
set mia7_bit, 0x2
set mda7_bit, 0x3
set immed_bit, 0x7
##################################
##################################
set FMUL_OP, 0x0 # fmul instr performed last
set FDIV_OP, 0x1 # fdiv performed last
set FADD_OP, 0x2 # fadd performed last
set FMOV_OP, 0x3 # fmov performed last
#############
#############
T1: long 0x40C62D38,0xD3D64634 # 16381 LOG2 LEAD
T2: long 0x3D6F90AE,0xB1E75CC7 # 16381 LOG2 TRAIL
PI: long 0x40000000,0xC90FDAA2,0x2168C235,0x00000000
PIBY2: long 0x3FFF0000,0xC90FDAA2,0x2168C235,0x00000000
TWOBYPI:
long 0x3FE45F30,0x6DC9C883
#########################################################################
# #
# #
# #
# - The system stack contains the FP Ovfl exception stack frame #
# - The fsave frame contains the source operand #
# #
# - The system stack is unchanged #
# - The fsave frame contains the adjusted src op for opclass 0,2 #
# - The system stack is unchanged #
# - The "exception present" flag in the fsave frame is cleared #
# #
# #
#########################################################################
global _fpsp_ovfl
_fpsp_ovfl:
#$# sub.l &24,%sp # make room for src/dst
link.w %a6,&-LOCAL_SIZE # init stack frame
fsave FP_SRC(%a6) # grab the "busy" frame
movm.l &0x0303,EXC_DREGS(%a6) # save d0-d1/a0-a1
fmovm.l %fpcr,%fpsr,%fpiar,USER_FPCR(%a6) # save ctrl regs
fmovm.x &0xc0,EXC_FPREGS(%a6) # save fp0-fp1 on stack
mov.l USER_FPIAR(%a6),EXC_EXTWPTR(%a6)
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch the instruction words
mov.l %d0,EXC_OPWORD(%a6)
##############################################################################
btst &0x5,EXC_CMDREG(%a6) # is instr an fmove out?
bne.w fovfl_out
lea FP_SRC(%a6),%a0 # pass: ptr to src op
bsr.l fix_skewed_ops # fix src op
lea FP_SRC(%a6),%a0 # pass: ptr to src op
bsr.l set_tag_x # tag the operand type
mov.b %d0,STAG(%a6) # maybe NORM,DENORM
btst &0x5,1+EXC_CMDREG(%a6) # is operation monadic or dyadic?
beq.b fovfl_extract # monadic
bfextu EXC_CMDREG(%a6){&6:&3},%d0 # dyadic; load dst reg
bsr.l load_fpn2 # load dst into FP_DST
lea FP_DST(%a6),%a0 # pass: ptr to dst op
bsr.l set_tag_x # tag the operand type
cmpi.b %d0,&UNNORM # is operand an UNNORM?
bne.b fovfl_op2_done # no
bsr.l unnorm_fix # yes; convert to NORM,DENORM,or ZERO
fovfl_op2_done:
mov.b %d0,DTAG(%a6) # save dst optype tag
fovfl_extract:
#$# mov.l FP_SRC_EX(%a6),TRAP_SRCOP_EX(%a6)
#$# mov.l FP_SRC_HI(%a6),TRAP_SRCOP_HI(%a6)
#$# mov.l FP_SRC_LO(%a6),TRAP_SRCOP_LO(%a6)
#$# mov.l FP_DST_EX(%a6),TRAP_DSTOP_EX(%a6)
#$# mov.l FP_DST_HI(%a6),TRAP_DSTOP_HI(%a6)
#$# mov.l FP_DST_LO(%a6),TRAP_DSTOP_LO(%a6)
clr.l %d0
mov.b FPCR_MODE(%a6),%d0 # pass rnd prec/mode
mov.b 1+EXC_CMDREG(%a6),%d1
andi.w &0x007f,%d1 # extract extension
andi.l &0x00ff01ff,USER_FPSR(%a6) # zero all but accured field
fmov.l &0x0,%fpcr # zero current control regs
fmov.l &0x0,%fpsr
lea FP_SRC(%a6),%a0
lea FP_DST(%a6),%a1
mov.l (tbl_unsupp.l,%pc,%d1.w*4),%d1 # fetch routine addr
jsr (tbl_unsupp.l,%pc,%d1.l*1)
bfextu EXC_CMDREG(%a6){&6:&3},%d0
bsr.l store_fpreg
btst &ovfl_bit,FPCR_ENABLE(%a6)
bne.b fovfl_ovfl_on
btst &inex2_bit,FPCR_ENABLE(%a6)
bne.b fovfl_inex_on
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6
#$# add.l &24,%sp
bra.l _fpsp_done
fovfl_ovfl_on:
fmovm.x &0x40,FP_SRC(%a6) # save EXOP (fp1) to stack
mov.w &0xe005,2+FP_SRC(%a6) # save exc status
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6) # do this after fmovm,other f<op>s!
unlk %a6
bra.l _real_ovfl
fovfl_inex_on:
fmovm.x &0x40,FP_SRC(%a6) # save EXOP (fp1) to stack
mov.b &0xc4,1+EXC_VOFF(%a6) # vector offset = 0xc4
mov.w &0xe001,2+FP_SRC(%a6) # save exc status
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6) # do this after fmovm,other f<op>s!
unlk %a6
bra.l _real_inex
########################################################################
fovfl_out:
#$# mov.l FP_SRC_EX(%a6),TRAP_SRCOP_EX(%a6)
#$# mov.l FP_SRC_HI(%a6),TRAP_SRCOP_HI(%a6)
#$# mov.l FP_SRC_LO(%a6),TRAP_SRCOP_LO(%a6)
mov.b &NORM,STAG(%a6) # set src optype tag
clr.l %d0
mov.b FPCR_MODE(%a6),%d0 # pass rnd prec/mode
and.l &0xffff00ff,USER_FPSR(%a6) # zero all but accured field
fmov.l &0x0,%fpcr # zero current control regs
fmov.l &0x0,%fpsr
lea FP_SRC(%a6),%a0 # pass ptr to src operand
bsr.l fout
btst &ovfl_bit,FPCR_ENABLE(%a6)
bne.w fovfl_ovfl_on
btst &inex2_bit,FPCR_ENABLE(%a6)
bne.w fovfl_inex_on
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6
#$# add.l &24,%sp
btst &0x7,(%sp) # is trace on?
beq.l _fpsp_done # no
fmov.l %fpiar,0x8(%sp) # "Current PC" is in FPIAR
mov.w &0x2024,0x6(%sp) # stk fmt = 0x2; voff = 0x024
bra.l _real_trace
#########################################################################
# #
# #
# #
# - The system stack contains the FP Unfl exception stack frame #
# - The fsave frame contains the source operand #
# #
# - The system stack is unchanged #
# - The fsave frame contains the adjusted src op for opclass 0,2 #
# - The system stack is unchanged #
# - The "exception present" flag in the fsave frame is cleared #
# #
# #
#########################################################################
global _fpsp_unfl
_fpsp_unfl:
#$# sub.l &24,%sp # make room for src/dst
link.w %a6,&-LOCAL_SIZE # init stack frame
fsave FP_SRC(%a6) # grab the "busy" frame
movm.l &0x0303,EXC_DREGS(%a6) # save d0-d1/a0-a1
fmovm.l %fpcr,%fpsr,%fpiar,USER_FPCR(%a6) # save ctrl regs
fmovm.x &0xc0,EXC_FPREGS(%a6) # save fp0-fp1 on stack
mov.l USER_FPIAR(%a6),EXC_EXTWPTR(%a6)
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch the instruction words
mov.l %d0,EXC_OPWORD(%a6)
##############################################################################
btst &0x5,EXC_CMDREG(%a6) # is instr an fmove out?
bne.w funfl_out
lea FP_SRC(%a6),%a0 # pass: ptr to src op
bsr.l fix_skewed_ops # fix src op
lea FP_SRC(%a6),%a0 # pass: ptr to src op
bsr.l set_tag_x # tag the operand type
mov.b %d0,STAG(%a6) # maybe NORM,DENORM
btst &0x5,1+EXC_CMDREG(%a6) # is op monadic or dyadic?
beq.b funfl_extract # monadic
btst &0x4,1+EXC_CMDREG(%a6) # is op an fsincos?
bne.b funfl_extract # yes
bfextu EXC_CMDREG(%a6){&6:&3},%d0 # dyadic; load dst reg
bsr.l load_fpn2 # load dst into FP_DST
lea FP_DST(%a6),%a0 # pass: ptr to dst op
bsr.l set_tag_x # tag the operand type
cmpi.b %d0,&UNNORM # is operand an UNNORM?
bne.b funfl_op2_done # no
bsr.l unnorm_fix # yes; convert to NORM,DENORM,or ZERO
funfl_op2_done:
mov.b %d0,DTAG(%a6) # save dst optype tag
funfl_extract:
#$# mov.l FP_SRC_EX(%a6),TRAP_SRCOP_EX(%a6)
#$# mov.l FP_SRC_HI(%a6),TRAP_SRCOP_HI(%a6)
#$# mov.l FP_SRC_LO(%a6),TRAP_SRCOP_LO(%a6)
#$# mov.l FP_DST_EX(%a6),TRAP_DSTOP_EX(%a6)
#$# mov.l FP_DST_HI(%a6),TRAP_DSTOP_HI(%a6)
#$# mov.l FP_DST_LO(%a6),TRAP_DSTOP_LO(%a6)
clr.l %d0
mov.b FPCR_MODE(%a6),%d0 # pass rnd prec/mode
mov.b 1+EXC_CMDREG(%a6),%d1
andi.w &0x007f,%d1 # extract extension
andi.l &0x00ff01ff,USER_FPSR(%a6)
fmov.l &0x0,%fpcr # zero current control regs
fmov.l &0x0,%fpsr
lea FP_SRC(%a6),%a0
lea FP_DST(%a6),%a1
mov.l (tbl_unsupp.l,%pc,%d1.w*4),%d1 # fetch routine addr
jsr (tbl_unsupp.l,%pc,%d1.l*1)
bfextu EXC_CMDREG(%a6){&6:&3},%d0
bsr.l store_fpreg
# (0x00000000_80000000_00000000), then the machine will take an
# if our emulation, after re-doing the operation, decided that
btst &unfl_bit,FPCR_ENABLE(%a6)
bne.b funfl_unfl_on
funfl_chkinex:
btst &inex2_bit,FPCR_ENABLE(%a6)
bne.b funfl_inex_on
funfl_exit:
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6
#$# add.l &24,%sp
bra.l _fpsp_done
funfl_unfl_on:
# (0x00000000_80000000_00000000), then the machine will take an
# if our emulation, after re-doing the operation, decided that
btst &unfl_bit,FPSR_EXCEPT(%a6)
beq.w funfl_chkinex
funfl_unfl_on2:
fmovm.x &0x40,FP_SRC(%a6) # save EXOP (fp1) to stack
mov.w &0xe003,2+FP_SRC(%a6) # save exc status
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6) # do this after fmovm,other f<op>s!
unlk %a6
bra.l _real_unfl
funfl_inex_on:
# (0x00000000_80000000_00000000), then the machine will take an
btst &inex2_bit,FPSR_EXCEPT(%a6)
beq.w funfl_exit
funfl_inex_on2:
fmovm.x &0x40,FP_SRC(%a6) # save EXOP to stack
mov.b &0xc4,1+EXC_VOFF(%a6) # vector offset = 0xc4
mov.w &0xe001,2+FP_SRC(%a6) # save exc status
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6) # do this after fmovm,other f<op>s!
unlk %a6
bra.l _real_inex
#######################################################################
funfl_out:
#$# mov.l FP_SRC_EX(%a6),TRAP_SRCOP_EX(%a6)
#$# mov.l FP_SRC_HI(%a6),TRAP_SRCOP_HI(%a6)
#$# mov.l FP_SRC_LO(%a6),TRAP_SRCOP_LO(%a6)
mov.b &NORM,STAG(%a6) # set src optype tag
clr.l %d0
mov.b FPCR_MODE(%a6),%d0 # pass rnd prec/mode
and.l &0xffff00ff,USER_FPSR(%a6) # zero all but accured field
fmov.l &0x0,%fpcr # zero current control regs
fmov.l &0x0,%fpsr
lea FP_SRC(%a6),%a0 # pass ptr to src operand
bsr.l fout
btst &unfl_bit,FPCR_ENABLE(%a6)
bne.w funfl_unfl_on2
btst &inex2_bit,FPCR_ENABLE(%a6)
bne.w funfl_inex_on2
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6
#$# add.l &24,%sp
btst &0x7,(%sp) # is trace on?
beq.l _fpsp_done # no
fmov.l %fpiar,0x8(%sp) # "Current PC" is in FPIAR
mov.w &0x2024,0x6(%sp) # stk fmt = 0x2; voff = 0x024
bra.l _real_trace
#########################################################################
# #
# #
# #
# - The system stack contains the "Unimp Data Type" stk frame #
# - The fsave frame contains the ssrc op (for UNNORM/DENORM) #
# #
# - The system stack is changed to an Inexact exception stk frame #
# - The system stack is changed to an SNAN exception stk frame #
# - The system stack is changed to an OPERR exception stk frame #
# - The system stack is changed to an OVFL exception stk frame #
# - The system stack is changed to an UNFL exception stack frame #
# - The system stack is changed to a Trace exception stack frame #
# - Correct result has been stored as appropriate #
# #
# (a Trace stack frame must be created here, too). If an FP exception #
# #
#########################################################################
#
# (1) DENORM and UNNORM (unimplemented) data types:
#
# *****************
# * EA *
# ***************** *****************
# * 0x0 * 0x0dc * * 0x3 * 0x0dc *
# ***************** *****************
# * Next * * Next *
# * PC * * PC *
# ***************** *****************
# * SR * * SR *
# ***************** *****************
#
# (2) PACKED format (unsupported) opclasses two and three:
# *****************
# * EA *
# * *
# *****************
# * 0x2 * 0x0dc *
# *****************
# * Next *
# * PC *
# *****************
# * SR *
# *****************
#
global _fpsp_unsupp
_fpsp_unsupp:
link.w %a6,&-LOCAL_SIZE # init stack frame
fsave FP_SRC(%a6) # save fp state
movm.l &0x0303,EXC_DREGS(%a6) # save d0-d1/a0-a1
fmovm.l %fpcr,%fpsr,%fpiar,USER_FPCR(%a6) # save ctrl regs
fmovm.x &0xc0,EXC_FPREGS(%a6) # save fp0-fp1 on stack
btst &0x5,EXC_SR(%a6) # user or supervisor mode?
bne.b fu_s
fu_u:
mov.l %usp,%a0 # fetch user stack pointer
mov.l %a0,EXC_A7(%a6) # save on stack
bra.b fu_cont
# if the exception is an opclass zero or two unimplemented data type
fu_s:
lea 0x4+EXC_EA(%a6),%a0 # load old a7'
mov.l %a0,EXC_A7(%a6) # save on stack
fu_cont:
mov.l USER_FPIAR(%a6),EXC_EXTWPTR(%a6)
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch the instruction words
mov.l %d0,EXC_OPWORD(%a6) # store OPWORD and EXTWORD
############################
clr.b SPCOND_FLG(%a6) # clear special condition flag
btst &0x5,EXC_CMDREG(%a6) # is it an fmove out?
bne.w fu_out # yes
bfextu EXC_CMDREG(%a6){&0:&6},%d0
cmpi.b %d0,&0x13
beq.w fu_in_pack
andi.l &0x00ff00ff,USER_FPSR(%a6) # zero exception field
fmov.l &0x0,%fpcr # zero current control regs
fmov.l &0x0,%fpsr
lea FP_SRC(%a6),%a0 # pass ptr to input
bsr.l fix_skewed_ops
lea FP_SRC(%a6),%a0 # pass: ptr to src op
bsr.l set_tag_x # tag the operand type
cmpi.b %d0,&UNNORM # is operand an UNNORM?
bne.b fu_op2 # no
bsr.l unnorm_fix # yes; convert to NORM,DENORM,or ZERO
fu_op2:
mov.b %d0,STAG(%a6) # save src optype tag
bfextu EXC_CMDREG(%a6){&6:&3},%d0 # dyadic; load dst reg
btst &0x5,1+EXC_CMDREG(%a6) # is operation monadic or dyadic?
beq.b fu_extract # monadic
cmpi.b 1+EXC_CMDREG(%a6),&0x3a # is operation an ftst?
beq.b fu_extract # yes, so it's monadic, too
bsr.l load_fpn2 # load dst into FP_DST
lea FP_DST(%a6),%a0 # pass: ptr to dst op
bsr.l set_tag_x # tag the operand type
cmpi.b %d0,&UNNORM # is operand an UNNORM?
bne.b fu_op2_done # no
bsr.l unnorm_fix # yes; convert to NORM,DENORM,or ZERO
fu_op2_done:
mov.b %d0,DTAG(%a6) # save dst optype tag
fu_extract:
clr.l %d0
mov.b FPCR_MODE(%a6),%d0 # fetch rnd mode/prec
bfextu 1+EXC_CMDREG(%a6){&1:&7},%d1 # extract extension
lea FP_SRC(%a6),%a0
lea FP_DST(%a6),%a1
mov.l (tbl_unsupp.l,%pc,%d1.l*4),%d1 # fetch routine addr
jsr (tbl_unsupp.l,%pc,%d1.l*1)
#
#
mov.b FPCR_ENABLE(%a6),%d0 # fetch exceptions set
bne.b fu_in_ena # some are enabled
fu_in_cont:
mov.b 1+EXC_CMDREG(%a6),%d0 # fetch extension
andi.b &0x38,%d0 # extract bits 3-5
cmpi.b %d0,&0x38 # is instr fcmp or ftst?
beq.b fu_in_exit # yes
bfextu EXC_CMDREG(%a6){&6:&3},%d0 # dyadic; load dst reg
bsr.l store_fpreg # store the result
fu_in_exit:
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6
bra.l _fpsp_done
fu_in_ena:
and.b FPSR_EXCEPT(%a6),%d0 # keep only ones enabled
bfffo %d0{&24:&8},%d0 # find highest priority exception
bne.b fu_in_exc # there is at least one set
#
#
# if (OVFL && ovfl_disabled && inexact_enabled) {
# } else {
# }
#
btst &ovfl_bit,FPSR_EXCEPT(%a6) # was overflow set?
beq.b fu_in_cont # no
fu_in_ovflchk:
btst &inex2_bit,FPCR_ENABLE(%a6) # was inexact enabled?
beq.b fu_in_cont # no
bra.w fu_in_exc_ovfl # go insert overflow frame
#
#
# if (((INEX2 || INEX1) && inex_enabled && OVFL && ovfl_disabled) ||
# ((INEX2 || INEX1) && inex_enabled && UNFL && unfl_disabled)) {
#
# } else {
# }
#
fu_in_exc:
subi.l &24,%d0 # fix offset to be 0-8
cmpi.b %d0,&0x6 # is exception INEX? (6)
bne.b fu_in_exc_exit # no
btst &unfl_bit,FPSR_EXCEPT(%a6) # did disabled underflow occur?
bne.w fu_in_exc_unfl # yes
btst &ovfl_bit,FPSR_EXCEPT(%a6) # did disabled overflow occur?
bne.w fu_in_exc_ovfl # yes
fu_in_exc_exit:
mov.l %d0,-(%sp) # save d0
bsr.l funimp_skew # skew sgl or dbl inputs
mov.l (%sp)+,%d0 # restore d0
mov.w (tbl_except.b,%pc,%d0.w*2),2+FP_SRC(%a6) # create exc status
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6) # restore src op
unlk %a6
bra.l _fpsp_done
tbl_except:
short 0xe000,0xe006,0xe004,0xe005
short 0xe003,0xe002,0xe001,0xe001
fu_in_exc_unfl:
mov.w &0x4,%d0
bra.b fu_in_exc_exit
fu_in_exc_ovfl:
mov.w &0x03,%d0
bra.b fu_in_exc_exit
# "corrected" in order to have the proper equivalent extended precision
global fix_skewed_ops
fix_skewed_ops:
bfextu EXC_CMDREG(%a6){&0:&6},%d0 # extract opclass,src fmt
cmpi.b %d0,&0x11 # is class = 2 & fmt = sgl?
beq.b fso_sgl # yes
cmpi.b %d0,&0x15 # is class = 2 & fmt = dbl?
beq.b fso_dbl # yes
rts # no
fso_sgl:
mov.w LOCAL_EX(%a0),%d0 # fetch src exponent
andi.w &0x7fff,%d0 # strip sign
cmpi.w %d0,&0x3f80 # is |exp| == $3f80?
beq.b fso_sgl_dnrm_zero # yes
cmpi.w %d0,&0x407f # no; is |exp| == $407f?
beq.b fso_infnan # yes
rts # no
fso_sgl_dnrm_zero:
andi.l &0x7fffffff,LOCAL_HI(%a0) # clear j-bit
beq.b fso_zero # it's a skewed zero
fso_sgl_dnrm:
bsr.l norm # normalize mantissa
neg.w %d0 # -shft amt
addi.w &0x3f81,%d0 # adjust new exponent
andi.w &0x8000,LOCAL_EX(%a0) # clear old exponent
or.w %d0,LOCAL_EX(%a0) # insert new exponent
rts
fso_zero:
andi.w &0x8000,LOCAL_EX(%a0) # clear bogus exponent
rts
fso_infnan:
andi.b &0x7f,LOCAL_HI(%a0) # clear j-bit
ori.w &0x7fff,LOCAL_EX(%a0) # make exponent = $7fff
rts
fso_dbl:
mov.w LOCAL_EX(%a0),%d0 # fetch src exponent
andi.w &0x7fff,%d0 # strip sign
cmpi.w %d0,&0x3c00 # is |exp| == $3c00?
beq.b fso_dbl_dnrm_zero # yes
cmpi.w %d0,&0x43ff # no; is |exp| == $43ff?
beq.b fso_infnan # yes
rts # no
fso_dbl_dnrm_zero:
andi.l &0x7fffffff,LOCAL_HI(%a0) # clear j-bit
bne.b fso_dbl_dnrm # it's a skewed denorm
tst.l LOCAL_LO(%a0) # is it a zero?
beq.b fso_zero # yes
fso_dbl_dnrm:
bsr.l norm # normalize mantissa
neg.w %d0 # -shft amt
addi.w &0x3c01,%d0 # adjust new exponent
andi.w &0x8000,LOCAL_EX(%a0) # clear old exponent
or.w %d0,LOCAL_EX(%a0) # insert new exponent
rts
#################################################################
fu_out:
bfextu EXC_CMDREG(%a6){&3:&3},%d0
cmpi.b %d0,&0x3
beq.w fu_out_pack
cmpi.b %d0,&0x7
beq.w fu_out_pack
and.l &0xffff00ff,USER_FPSR(%a6) # zero exception field
fmov.l &0x0,%fpcr # zero current control regs
fmov.l &0x0,%fpsr
mov.w FP_SRC_EX(%a6),%d0 # get exponent
andi.w &0x7fff,%d0 # strip sign
beq.b fu_out_denorm # it's a DENORM
lea FP_SRC(%a6),%a0
bsr.l unnorm_fix # yes; fix it
mov.b %d0,STAG(%a6)
bra.b fu_out_cont
fu_out_denorm:
mov.b &DENORM,STAG(%a6)
fu_out_cont:
clr.l %d0
mov.b FPCR_MODE(%a6),%d0 # fetch rnd mode/prec
lea FP_SRC(%a6),%a0 # pass ptr to src operand
mov.l (%a6),EXC_A6(%a6) # in case a6 changes
bsr.l fout # call fmove out routine
mov.b FPCR_ENABLE(%a6),%d0 # fetch exceptions enabled
bne.w fu_out_ena # some are enabled
fu_out_done:
mov.l EXC_A6(%a6),(%a6) # in case a6 changed
btst &0x5,EXC_SR(%a6)
bne.b fu_out_done_s
mov.l EXC_A7(%a6),%a0 # restore a7
mov.l %a0,%usp
fu_out_done_cont:
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6
btst &0x7,(%sp) # is trace on?
bne.b fu_out_trace # yes
bra.l _fpsp_done
# ("fmov.x fpm,-(a7)") if so,
fu_out_done_s:
cmpi.b SPCOND_FLG(%a6),&mda7_flg
bne.b fu_out_done_cont
fmovm.x &0x80,FP_SRC(%a6) # put answer on stack
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
mov.l (%a6),%a6 # restore frame pointer
mov.l LOCAL_SIZE+EXC_SR(%sp),LOCAL_SIZE+EXC_SR-0xc(%sp)
mov.l LOCAL_SIZE+2+EXC_PC(%sp),LOCAL_SIZE+2+EXC_PC-0xc(%sp)
mov.l LOCAL_SIZE+FP_SRC_EX(%sp),LOCAL_SIZE+EXC_SR+0x0(%sp)
mov.l LOCAL_SIZE+FP_SRC_HI(%sp),LOCAL_SIZE+EXC_SR+0x4(%sp)
mov.l LOCAL_SIZE+FP_SRC_LO(%sp),LOCAL_SIZE+EXC_SR+0x8(%sp)
add.l &LOCAL_SIZE-0x8,%sp
btst &0x7,(%sp)
bne.b fu_out_trace
bra.l _fpsp_done
fu_out_ena:
and.b FPSR_EXCEPT(%a6),%d0 # keep only ones enabled
bfffo %d0{&24:&8},%d0 # find highest priority exception
bne.b fu_out_exc # there is at least one set
# if a disabled overflow occurred and inexact was enabled but the result
btst &ovfl_bit,FPSR_EXCEPT(%a6) # was overflow set?
beq.w fu_out_done # no
fu_out_ovflchk:
btst &inex2_bit,FPCR_ENABLE(%a6) # was inexact enabled?
beq.w fu_out_done # no
bra.w fu_inex # yes
#
#
# ***************** *****************
# * EA * * Current *
# * * * PC *
# ***************** *****************
# * 0x3 * 0x0dc * * 0x2 * 0x024 *
# ***************** *****************
# * Next * * Next *
# * PC * * PC *
# ***************** *****************
# * SR * * SR *
# ***************** *****************
#
fu_out_trace:
mov.w &0x2024,0x6(%sp)
fmov.l %fpiar,0x8(%sp)
bra.l _real_trace
fu_out_exc:
subi.l &24,%d0 # fix offset to be 0-8
mov.w (tbl_fu_out.b,%pc,%d0.w*2),%d0
jmp (tbl_fu_out.b,%pc,%d0.w*1)
swbeg &0x8
tbl_fu_out:
short tbl_fu_out - tbl_fu_out # BSUN can't happen
short tbl_fu_out - tbl_fu_out # SNAN can't happen
short fu_operr - tbl_fu_out # OPERR
short fu_ovfl - tbl_fu_out # OVFL
short fu_unfl - tbl_fu_out # UNFL
short tbl_fu_out - tbl_fu_out # DZ can't happen
short fu_inex - tbl_fu_out # INEX2
short tbl_fu_out - tbl_fu_out # INEX1 won't make it here
fu_snan:
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
mov.w &0x30d8,EXC_VOFF(%a6) # vector offset = 0xd8
mov.w &0xe006,2+FP_SRC(%a6)
frestore FP_SRC(%a6)
unlk %a6
bra.l _real_snan
fu_operr:
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
mov.w &0x30d0,EXC_VOFF(%a6) # vector offset = 0xd0
mov.w &0xe004,2+FP_SRC(%a6)
frestore FP_SRC(%a6)
unlk %a6
bra.l _real_operr
fu_ovfl:
fmovm.x &0x40,FP_SRC(%a6) # save EXOP to the stack
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
mov.w &0x30d4,EXC_VOFF(%a6) # vector offset = 0xd4
mov.w &0xe005,2+FP_SRC(%a6)
frestore FP_SRC(%a6) # restore EXOP
unlk %a6
bra.l _real_ovfl
# if the exception occurred from supervisor mode, check if
fu_unfl:
mov.l EXC_A6(%a6),(%a6) # restore a6
btst &0x5,EXC_SR(%a6)
bne.w fu_unfl_s
mov.l EXC_A7(%a6),%a0 # restore a7 whether we need
mov.l %a0,%usp # to or not...
fu_unfl_cont:
fmovm.x &0x40,FP_SRC(%a6) # save EXOP to the stack
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
mov.w &0x30cc,EXC_VOFF(%a6) # vector offset = 0xcc
mov.w &0xe003,2+FP_SRC(%a6)
frestore FP_SRC(%a6) # restore EXOP
unlk %a6
bra.l _real_unfl
fu_unfl_s:
cmpi.b SPCOND_FLG(%a6),&mda7_flg # was the <ea> mode -(sp)?
bne.b fu_unfl_cont
# (where the exc frame is currently). make sure it's not at the top of the
fmovm.x &0x80,FP_SRC(%a6) # put answer on stack
fmovm.x &0x40,FP_DST(%a6) # put EXOP on stack
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
mov.w &0x30cc,EXC_VOFF(%a6) # vector offset = 0xcc
mov.w &0xe003,2+FP_DST(%a6)
frestore FP_DST(%a6) # restore EXOP
mov.l (%a6),%a6 # restore frame pointer
mov.l LOCAL_SIZE+EXC_SR(%sp),LOCAL_SIZE+EXC_SR-0xc(%sp)
mov.l LOCAL_SIZE+2+EXC_PC(%sp),LOCAL_SIZE+2+EXC_PC-0xc(%sp)
mov.l LOCAL_SIZE+EXC_EA(%sp),LOCAL_SIZE+EXC_EA-0xc(%sp)
mov.l LOCAL_SIZE+FP_SRC_EX(%sp),LOCAL_SIZE+EXC_SR+0x0(%sp)
mov.l LOCAL_SIZE+FP_SRC_HI(%sp),LOCAL_SIZE+EXC_SR+0x4(%sp)
mov.l LOCAL_SIZE+FP_SRC_LO(%sp),LOCAL_SIZE+EXC_SR+0x8(%sp)
add.l &LOCAL_SIZE-0x8,%sp
bra.l _real_unfl
fu_inex:
fmovm.x &0x40,FP_SRC(%a6) # save EXOP to the stack
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
mov.w &0x30c4,EXC_VOFF(%a6) # vector offset = 0xc4
mov.w &0xe001,2+FP_SRC(%a6)
frestore FP_SRC(%a6) # restore EXOP
unlk %a6
bra.l _real_inex
#########################################################################
#########################################################################
fu_in_pack:
andi.l &0x0ff00ff,USER_FPSR(%a6) # zero exception field
fmov.l &0x0,%fpcr # zero current control regs
fmov.l &0x0,%fpsr
bsr.l get_packed # fetch packed src operand
lea FP_SRC(%a6),%a0 # pass ptr to src
bsr.l set_tag_x # set src optype tag
mov.b %d0,STAG(%a6) # save src optype tag
bfextu EXC_CMDREG(%a6){&6:&3},%d0 # dyadic; load dst reg
btst &0x5,1+EXC_CMDREG(%a6) # is operation monadic or dyadic?
beq.b fu_extract_p # monadic
cmpi.b 1+EXC_CMDREG(%a6),&0x3a # is operation an ftst?
beq.b fu_extract_p # yes, so it's monadic, too
bsr.l load_fpn2 # load dst into FP_DST
lea FP_DST(%a6),%a0 # pass: ptr to dst op
bsr.l set_tag_x # tag the operand type
cmpi.b %d0,&UNNORM # is operand an UNNORM?
bne.b fu_op2_done_p # no
bsr.l unnorm_fix # yes; convert to NORM,DENORM,or ZERO
fu_op2_done_p:
mov.b %d0,DTAG(%a6) # save dst optype tag
fu_extract_p:
clr.l %d0
mov.b FPCR_MODE(%a6),%d0 # fetch rnd mode/prec
bfextu 1+EXC_CMDREG(%a6){&1:&7},%d1 # extract extension
lea FP_SRC(%a6),%a0
lea FP_DST(%a6),%a1
mov.l (tbl_unsupp.l,%pc,%d1.l*4),%d1 # fetch routine addr
jsr (tbl_unsupp.l,%pc,%d1.l*1)
#
#
mov.b FPCR_ENABLE(%a6),%d0 # fetch exceptions enabled
bne.w fu_in_ena_p # some are enabled
fu_in_cont_p:
mov.b 1+EXC_CMDREG(%a6),%d0 # fetch extension
andi.b &0x38,%d0 # extract bits 3-5
cmpi.b %d0,&0x38 # is instr fcmp or ftst?
beq.b fu_in_exit_p # yes
bfextu EXC_CMDREG(%a6){&6:&3},%d0 # dyadic; load dst reg
bsr.l store_fpreg # store the result
fu_in_exit_p:
btst &0x5,EXC_SR(%a6) # user or supervisor?
bne.w fu_in_exit_s_p # supervisor
mov.l EXC_A7(%a6),%a0 # update user a7
mov.l %a0,%usp
fu_in_exit_cont_p:
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6 # unravel stack frame
btst &0x7,(%sp) # is trace on?
bne.w fu_trace_p # yes
bra.l _fpsp_done # exit to os
fu_in_exit_s_p:
btst &mia7_bit,SPCOND_FLG(%a6) # was ea mode (a7)+
beq.b fu_in_exit_cont_p # no
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6 # unravel stack frame
mov.l 0x4(%sp),0x10(%sp)
mov.l 0x0(%sp),0xc(%sp)
add.l &0xc,%sp
btst &0x7,(%sp) # is trace on?
bne.w fu_trace_p # yes
bra.l _fpsp_done # exit to os
fu_in_ena_p:
and.b FPSR_EXCEPT(%a6),%d0 # keep only ones enabled & set
bfffo %d0{&24:&8},%d0 # find highest priority exception
bne.b fu_in_exc_p # at least one was set
#
#
# if (OVFL && ovfl_disabled && inexact_enabled) {
# } else {
# }
#
btst &ovfl_bit,FPSR_EXCEPT(%a6) # was overflow set?
beq.w fu_in_cont_p # no
fu_in_ovflchk_p:
btst &inex2_bit,FPCR_ENABLE(%a6) # was inexact enabled?
beq.w fu_in_cont_p # no
bra.w fu_in_exc_ovfl_p # do _real_inex() now
#
#
# if (((INEX2 || INEX1) && inex_enabled && OVFL && ovfl_disabled) ||
# ((INEX2 || INEX1) && inex_enabled && UNFL && unfl_disabled)) {
#
# } else {
# }
#
fu_in_exc_p:
subi.l &24,%d0 # fix offset to be 0-8
cmpi.b %d0,&0x6 # is exception INEX? (6 or 7)
blt.b fu_in_exc_exit_p # no
btst &unfl_bit,FPSR_EXCEPT(%a6) # did disabled underflow occur?
bne.w fu_in_exc_unfl_p # yes
btst &ovfl_bit,FPSR_EXCEPT(%a6) # did disabled overflow occur?
bne.w fu_in_exc_ovfl_p # yes
# "non-skewed" operand for cases of sgl and dbl src INFs,NANs, and DENORMs.
fu_in_exc_exit_p:
btst &0x5,EXC_SR(%a6) # user or supervisor?
bne.w fu_in_exc_exit_s_p # supervisor
mov.l EXC_A7(%a6),%a0 # update user a7
mov.l %a0,%usp
fu_in_exc_exit_cont_p:
mov.w (tbl_except_p.b,%pc,%d0.w*2),2+FP_SRC(%a6)
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6) # restore src op
unlk %a6
btst &0x7,(%sp) # is trace enabled?
bne.w fu_trace_p # yes
bra.l _fpsp_done
tbl_except_p:
short 0xe000,0xe006,0xe004,0xe005
short 0xe003,0xe002,0xe001,0xe001
fu_in_exc_ovfl_p:
mov.w &0x3,%d0
bra.w fu_in_exc_exit_p
fu_in_exc_unfl_p:
mov.w &0x4,%d0
bra.w fu_in_exc_exit_p
fu_in_exc_exit_s_p:
btst &mia7_bit,SPCOND_FLG(%a6)
beq.b fu_in_exc_exit_cont_p
mov.w (tbl_except_p.b,%pc,%d0.w*2),2+FP_SRC(%a6)
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6) # restore src op
unlk %a6 # unravel stack frame
mov.l 0x4(%sp),0x10(%sp)
mov.l 0x0(%sp),0xc(%sp)
add.l &0xc,%sp
btst &0x7,(%sp) # is trace on?
bne.b fu_trace_p # yes
bra.l _fpsp_done # exit to os
#
#
# ***************** *****************
# * EA * * Current *
# * * * PC *
# ***************** *****************
# * 0x2 * 0x0dc * * 0x2 * 0x024 *
# ***************** *****************
# * Next * * Next *
# * PC * * PC *
# ***************** *****************
# * SR * * SR *
# ***************** *****************
fu_trace_p:
mov.w &0x2024,0x6(%sp)
fmov.l %fpiar,0x8(%sp)
bra.l _real_trace
#########################################################
#########################################################
fu_out_pack:
and.l &0xffff00ff,USER_FPSR(%a6) # zero exception field
fmov.l &0x0,%fpcr # zero current control regs
fmov.l &0x0,%fpsr
bfextu EXC_CMDREG(%a6){&6:&3},%d0
bsr.l load_fpn1
lea FP_SRC(%a6),%a0
bsr.l set_tag_x # tag the operand type
cmpi.b %d0,&UNNORM # is operand an UNNORM?
bne.b fu_op2_p # no
bsr.l unnorm_fix # yes; convert to NORM,DENORM,or ZERO
fu_op2_p:
mov.b %d0,STAG(%a6) # save src optype tag
clr.l %d0
mov.b FPCR_MODE(%a6),%d0 # fetch rnd mode/prec
lea FP_SRC(%a6),%a0 # pass ptr to src operand
mov.l (%a6),EXC_A6(%a6) # in case a6 changes
bsr.l fout # call fmove out routine
mov.b FPCR_ENABLE(%a6),%d0 # fetch exceptions enabled
bne.w fu_out_ena_p # some are enabled
fu_out_exit_p:
mov.l EXC_A6(%a6),(%a6) # restore a6
btst &0x5,EXC_SR(%a6) # user or supervisor?
bne.b fu_out_exit_s_p # supervisor
mov.l EXC_A7(%a6),%a0 # update user a7
mov.l %a0,%usp
fu_out_exit_cont_p:
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6 # unravel stack frame
btst &0x7,(%sp) # is trace on?
bne.w fu_trace_p # yes
bra.l _fpsp_done # exit to os
fu_out_exit_s_p:
btst &mda7_bit,SPCOND_FLG(%a6) # was ea mode -(a7)
beq.b fu_out_exit_cont_p # no
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
mov.l (%a6),%a6 # restore frame pointer
mov.l LOCAL_SIZE+EXC_SR(%sp),LOCAL_SIZE+EXC_SR-0xc(%sp)
mov.l LOCAL_SIZE+2+EXC_PC(%sp),LOCAL_SIZE+2+EXC_PC-0xc(%sp)
mov.l LOCAL_SIZE+FP_DST_EX(%sp),LOCAL_SIZE+EXC_SR+0x0(%sp)
mov.l LOCAL_SIZE+FP_DST_HI(%sp),LOCAL_SIZE+EXC_SR+0x4(%sp)
mov.l LOCAL_SIZE+FP_DST_LO(%sp),LOCAL_SIZE+EXC_SR+0x8(%sp)
add.l &LOCAL_SIZE-0x8,%sp
btst &0x7,(%sp)
bne.w fu_trace_p
bra.l _fpsp_done
fu_out_ena_p:
and.b FPSR_EXCEPT(%a6),%d0 # keep only ones enabled
bfffo %d0{&24:&8},%d0 # find highest priority exception
beq.w fu_out_exit_p
mov.l EXC_A6(%a6),(%a6) # restore a6
fu_out_exc_p:
cmpi.b %d0,&0x1a
bgt.w fu_inex_p2
beq.w fu_operr_p
fu_snan_p:
btst &0x5,EXC_SR(%a6)
bne.b fu_snan_s_p
mov.l EXC_A7(%a6),%a0
mov.l %a0,%usp
bra.w fu_snan
fu_snan_s_p:
cmpi.b SPCOND_FLG(%a6),&mda7_flg
bne.w fu_snan
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
mov.w &0x30d8,EXC_VOFF(%a6) # vector offset = 0xd0
mov.w &0xe006,2+FP_SRC(%a6) # set fsave status
frestore FP_SRC(%a6) # restore src operand
mov.l (%a6),%a6 # restore frame pointer
mov.l LOCAL_SIZE+EXC_SR(%sp),LOCAL_SIZE+EXC_SR-0xc(%sp)
mov.l LOCAL_SIZE+2+EXC_PC(%sp),LOCAL_SIZE+2+EXC_PC-0xc(%sp)
mov.l LOCAL_SIZE+EXC_EA(%sp),LOCAL_SIZE+EXC_EA-0xc(%sp)
mov.l LOCAL_SIZE+FP_DST_EX(%sp),LOCAL_SIZE+0x4(%sp)
mov.l LOCAL_SIZE+FP_DST_HI(%sp),LOCAL_SIZE+0x8(%sp)
mov.l LOCAL_SIZE+FP_DST_LO(%sp),LOCAL_SIZE+0xc(%sp)
add.l &LOCAL_SIZE-0x8,%sp
bra.l _real_snan
fu_operr_p:
btst &0x5,EXC_SR(%a6)
bne.w fu_operr_p_s
mov.l EXC_A7(%a6),%a0
mov.l %a0,%usp
bra.w fu_operr
fu_operr_p_s:
cmpi.b SPCOND_FLG(%a6),&mda7_flg
bne.w fu_operr
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
mov.w &0x30d0,EXC_VOFF(%a6) # vector offset = 0xd0
mov.w &0xe004,2+FP_SRC(%a6) # set fsave status
frestore FP_SRC(%a6) # restore src operand
mov.l (%a6),%a6 # restore frame pointer
mov.l LOCAL_SIZE+EXC_SR(%sp),LOCAL_SIZE+EXC_SR-0xc(%sp)
mov.l LOCAL_SIZE+2+EXC_PC(%sp),LOCAL_SIZE+2+EXC_PC-0xc(%sp)
mov.l LOCAL_SIZE+EXC_EA(%sp),LOCAL_SIZE+EXC_EA-0xc(%sp)
mov.l LOCAL_SIZE+FP_DST_EX(%sp),LOCAL_SIZE+0x4(%sp)
mov.l LOCAL_SIZE+FP_DST_HI(%sp),LOCAL_SIZE+0x8(%sp)
mov.l LOCAL_SIZE+FP_DST_LO(%sp),LOCAL_SIZE+0xc(%sp)
add.l &LOCAL_SIZE-0x8,%sp
bra.l _real_operr
fu_inex_p2:
btst &0x5,EXC_SR(%a6)
bne.w fu_inex_s_p2
mov.l EXC_A7(%a6),%a0
mov.l %a0,%usp
bra.w fu_inex
fu_inex_s_p2:
cmpi.b SPCOND_FLG(%a6),&mda7_flg
bne.w fu_inex
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0/fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
mov.w &0x30c4,EXC_VOFF(%a6) # vector offset = 0xc4
mov.w &0xe001,2+FP_SRC(%a6) # set fsave status
frestore FP_SRC(%a6) # restore src operand
mov.l (%a6),%a6 # restore frame pointer
mov.l LOCAL_SIZE+EXC_SR(%sp),LOCAL_SIZE+EXC_SR-0xc(%sp)
mov.l LOCAL_SIZE+2+EXC_PC(%sp),LOCAL_SIZE+2+EXC_PC-0xc(%sp)
mov.l LOCAL_SIZE+EXC_EA(%sp),LOCAL_SIZE+EXC_EA-0xc(%sp)
mov.l LOCAL_SIZE+FP_DST_EX(%sp),LOCAL_SIZE+0x4(%sp)
mov.l LOCAL_SIZE+FP_DST_HI(%sp),LOCAL_SIZE+0x8(%sp)
mov.l LOCAL_SIZE+FP_DST_LO(%sp),LOCAL_SIZE+0xc(%sp)
add.l &LOCAL_SIZE-0x8,%sp
bra.l _real_inex
#########################################################################
#
# if we're stuffing a source operand back into an fsave frame then we
#
global funimp_skew
funimp_skew:
bfextu EXC_EXTWORD(%a6){&3:&3},%d0 # extract src specifier
cmpi.b %d0,&0x1 # was src sgl?
beq.b funimp_skew_sgl # yes
cmpi.b %d0,&0x5 # was src dbl?
beq.b funimp_skew_dbl # yes
rts
funimp_skew_sgl:
mov.w FP_SRC_EX(%a6),%d0 # fetch DENORM exponent
andi.w &0x7fff,%d0 # strip sign
beq.b funimp_skew_sgl_not
cmpi.w %d0,&0x3f80
bgt.b funimp_skew_sgl_not
neg.w %d0 # make exponent negative
addi.w &0x3f81,%d0 # find amt to shift
mov.l FP_SRC_HI(%a6),%d1 # fetch DENORM hi(man)
lsr.l %d0,%d1 # shift it
bset &31,%d1 # set j-bit
mov.l %d1,FP_SRC_HI(%a6) # insert new hi(man)
andi.w &0x8000,FP_SRC_EX(%a6) # clear old exponent
ori.w &0x3f80,FP_SRC_EX(%a6) # insert new "skewed" exponent
funimp_skew_sgl_not:
rts
funimp_skew_dbl:
mov.w FP_SRC_EX(%a6),%d0 # fetch DENORM exponent
andi.w &0x7fff,%d0 # strip sign
beq.b funimp_skew_dbl_not
cmpi.w %d0,&0x3c00
bgt.b funimp_skew_dbl_not
tst.b FP_SRC_EX(%a6) # make "internal format"
smi.b 0x2+FP_SRC(%a6)
mov.w %d0,FP_SRC_EX(%a6) # insert exponent with cleared sign
clr.l %d0 # clear g,r,s
lea FP_SRC(%a6),%a0 # pass ptr to src op
mov.w &0x3c01,%d1 # pass denorm threshold
bsr.l dnrm_lp # denorm it
mov.w &0x3c00,%d0 # new exponent
tst.b 0x2+FP_SRC(%a6) # is sign set?
beq.b fss_dbl_denorm_done # no
bset &15,%d0 # set sign
fss_dbl_denorm_done:
bset &0x7,FP_SRC_HI(%a6) # set j-bit
mov.w %d0,FP_SRC_EX(%a6) # insert new exponent
funimp_skew_dbl_not:
rts
#########################################################################
global _mem_write2
_mem_write2:
btst &0x5,EXC_SR(%a6)
beq.l _dmem_write
mov.l 0x0(%a0),FP_DST_EX(%a6)
mov.l 0x4(%a0),FP_DST_HI(%a6)
mov.l 0x8(%a0),FP_DST_LO(%a6)
clr.l %d1
rts
#########################################################################
# #
# #
# #
# - The system stack contains the "Unimplemented <ea>" stk frame #
# #
# - The system stack is changed to an access error stack frame #
# - The system stack is changed to an FPU disabled stack frame #
# - The system stack is changed to a Trace exception stack frame #
# - None (correct result has been stored as appropriate) #
# #
# (1) FP Instructions using extended precision or packed immediate #
# (2) The "fmovm.x" instruction w/ dynamic register specification. #
# (3) The "fmovm.l" instruction w/ 2 or 3 control registers. #
# #
# #
# #
# "callout" returns a failing result indicating an access error, then #
# #
#########################################################################
global _fpsp_effadd
_fpsp_effadd:
mov.l %d0,-(%sp) # save d0
movc %pcr,%d0 # load proc cr
btst &0x1,%d0 # is FPU disabled?
bne.w iea_disabled # yes
mov.l (%sp)+,%d0 # restore d0
link %a6,&-LOCAL_SIZE # init stack frame
movm.l &0x0303,EXC_DREGS(%a6) # save d0-d1/a0-a1
fmovm.l %fpcr,%fpsr,%fpiar,USER_FPCR(%a6) # save ctrl regs
fmovm.x &0xc0,EXC_FPREGS(%a6) # save fp0-fp1 on stack
mov.l EXC_PC(%a6),EXC_EXTWPTR(%a6)
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch the instruction words
mov.l %d0,EXC_OPWORD(%a6) # store OPWORD and EXTWORD
#########################################################################
tst.w %d0 # is operation fmovem?
bmi.w iea_fmovm # yes
#
#
iea_op:
andi.l &0x00ff00ff,USER_FPSR(%a6)
btst &0xa,%d0 # is src fmt x or p?
bne.b iea_op_pack # packed
mov.l EXC_EXTWPTR(%a6),%a0 # pass: ptr to #<data>
lea FP_SRC(%a6),%a1 # pass: ptr to super addr
mov.l &0xc,%d0 # pass: 12 bytes
bsr.l _imem_read # read extended immediate
tst.l %d1 # did ifetch fail?
bne.w iea_iacc # yes
bra.b iea_op_setsrc
iea_op_pack:
mov.l EXC_EXTWPTR(%a6),%a0 # pass: ptr to #<data>
lea FP_SRC(%a6),%a1 # pass: ptr to super dst
mov.l &0xc,%d0 # pass: 12 bytes
bsr.l _imem_read # read packed operand
tst.l %d1 # did ifetch fail?
bne.w iea_iacc # yes
bfextu FP_SRC(%a6){&1:&15},%d0 # get exp
cmpi.w %d0,&0x7fff # INF or NAN?
beq.b iea_op_setsrc # operand is an INF or NAN
mov.b 3+FP_SRC(%a6),%d0 # get byte 4
andi.b &0x0f,%d0 # clear all but last nybble
bne.b iea_op_gp_not_spec # not a zero
tst.l FP_SRC_HI(%a6) # is lw 2 zero?
bne.b iea_op_gp_not_spec # not a zero
tst.l FP_SRC_LO(%a6) # is lw 3 zero?
beq.b iea_op_setsrc # operand is a ZERO
iea_op_gp_not_spec:
lea FP_SRC(%a6),%a0 # pass: ptr to packed op
bsr.l decbin # convert to extended
fmovm.x &0x80,FP_SRC(%a6) # make this the srcop
iea_op_setsrc:
addi.l &0xc,EXC_EXTWPTR(%a6) # update extension word pointer
lea FP_SRC(%a6),%a0 # pass: ptr to src op
bsr.l set_tag_x # tag the operand type
mov.b %d0,STAG(%a6) # could be ANYTHING!!!
cmpi.b %d0,&UNNORM # is operand an UNNORM?
bne.b iea_op_getdst # no
bsr.l unnorm_fix # yes; convert to NORM/DENORM/ZERO
mov.b %d0,STAG(%a6) # set new optype tag
iea_op_getdst:
clr.b STORE_FLG(%a6) # clear "store result" boolean
btst &0x5,1+EXC_CMDREG(%a6) # is operation monadic or dyadic?
beq.b iea_op_extract # monadic
btst &0x4,1+EXC_CMDREG(%a6) # is operation fsincos,ftst,fcmp?
bne.b iea_op_spec # yes
iea_op_loaddst:
bfextu EXC_CMDREG(%a6){&6:&3},%d0 # fetch dst regno
bsr.l load_fpn2 # load dst operand
lea FP_DST(%a6),%a0 # pass: ptr to dst op
bsr.l set_tag_x # tag the operand type
mov.b %d0,DTAG(%a6) # could be ANYTHING!!!
cmpi.b %d0,&UNNORM # is operand an UNNORM?
bne.b iea_op_extract # no
bsr.l unnorm_fix # yes; convert to NORM/DENORM/ZERO
mov.b %d0,DTAG(%a6) # set new optype tag
bra.b iea_op_extract
iea_op_spec:
btst &0x3,1+EXC_CMDREG(%a6) # is operation fsincos?
beq.b iea_op_extract # yes
st STORE_FLG(%a6) # don't store a final result
btst &0x1,1+EXC_CMDREG(%a6) # is operation fcmp?
beq.b iea_op_loaddst # yes
iea_op_extract:
clr.l %d0
mov.b FPCR_MODE(%a6),%d0 # pass: rnd mode,prec
mov.b 1+EXC_CMDREG(%a6),%d1
andi.w &0x007f,%d1 # extract extension
fmov.l &0x0,%fpcr
fmov.l &0x0,%fpsr
lea FP_SRC(%a6),%a0
lea FP_DST(%a6),%a1
mov.l (tbl_unsupp.l,%pc,%d1.w*4),%d1 # fetch routine addr
jsr (tbl_unsupp.l,%pc,%d1.l*1)
#
#
mov.b FPCR_ENABLE(%a6),%d0 # fetch exceptions enabled
bne.b iea_op_ena # some are enabled
iea_op_save:
tst.b STORE_FLG(%a6) # does this op store a result?
bne.b iea_op_exit1 # exit with no frestore
iea_op_store:
bfextu EXC_CMDREG(%a6){&6:&3},%d0 # fetch dst regno
bsr.l store_fpreg # store the result
iea_op_exit1:
mov.l EXC_PC(%a6),USER_FPIAR(%a6) # set FPIAR to "Current PC"
mov.l EXC_EXTWPTR(%a6),EXC_PC(%a6) # set "Next PC" in exc frame
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6 # unravel the frame
btst &0x7,(%sp) # is trace on?
bne.w iea_op_trace # yes
bra.l _fpsp_done # exit to os
iea_op_ena:
and.b FPSR_EXCEPT(%a6),%d0 # keep only ones enable and set
bfffo %d0{&24:&8},%d0 # find highest priority exception
bne.b iea_op_exc # at least one was set
btst &ovfl_bit,FPSR_EXCEPT(%a6) # did overflow occur?
beq.b iea_op_save
iea_op_ovfl:
btst &inex2_bit,FPCR_ENABLE(%a6) # is inexact enabled?
beq.b iea_op_store # no
bra.b iea_op_exc_ovfl # yes
iea_op_exc:
subi.l &24,%d0 # fix offset to be 0-8
cmpi.b %d0,&0x6 # is exception INEX?
bne.b iea_op_exc_force # no
btst &ovfl_bit,FPSR_EXCEPT(%a6) # did overflow occur?
bne.b iea_op_exc_ovfl # yes
btst &unfl_bit,FPSR_EXCEPT(%a6) # did underflow occur?
bne.b iea_op_exc_unfl # yes
iea_op_exc_force:
mov.w (tbl_iea_except.b,%pc,%d0.w*2),2+FP_SRC(%a6)
bra.b iea_op_exit2 # exit with frestore
tbl_iea_except:
short 0xe002, 0xe006, 0xe004, 0xe005
short 0xe003, 0xe002, 0xe001, 0xe001
iea_op_exc_ovfl:
mov.w &0xe005,2+FP_SRC(%a6)
bra.b iea_op_exit2
iea_op_exc_unfl:
mov.w &0xe003,2+FP_SRC(%a6)
iea_op_exit2:
mov.l EXC_PC(%a6),USER_FPIAR(%a6) # set FPIAR to "Current PC"
mov.l EXC_EXTWPTR(%a6),EXC_PC(%a6) # set "Next PC" in exc frame
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6) # restore exceptional state
unlk %a6 # unravel the frame
btst &0x7,(%sp) # is trace on?
bne.b iea_op_trace # yes
bra.l _fpsp_done # exit to os
#
#
# ***************** *****************
# * 0x0 * 0x0f0 * * Current *
# ***************** * PC *
# * Current * *****************
# * PC * * 0x2 * 0x024 *
# ***************** *****************
# * SR * * Next *
# ***************** * PC *
# *****************
# * SR *
# *****************
iea_op_trace:
mov.l (%sp),-(%sp) # shift stack frame "down"
mov.w 0x8(%sp),0x4(%sp)
mov.w &0x2024,0x6(%sp) # stk fmt = 0x2; voff = 0x024
fmov.l %fpiar,0x8(%sp) # "Current PC" is in FPIAR
bra.l _real_trace
#########################################################################
iea_fmovm:
btst &14,%d0 # ctrl or data reg
beq.w iea_fmovm_ctrl
iea_fmovm_data:
btst &0x5,EXC_SR(%a6) # user or supervisor mode
bne.b iea_fmovm_data_s
iea_fmovm_data_u:
mov.l %usp,%a0
mov.l %a0,EXC_A7(%a6) # store current a7
bsr.l fmovm_dynamic # do dynamic fmovm
mov.l EXC_A7(%a6),%a0 # load possibly new a7
mov.l %a0,%usp # update usp
bra.w iea_fmovm_exit
iea_fmovm_data_s:
clr.b SPCOND_FLG(%a6)
lea 0x2+EXC_VOFF(%a6),%a0
mov.l %a0,EXC_A7(%a6)
bsr.l fmovm_dynamic # do dynamic fmovm
cmpi.b SPCOND_FLG(%a6),&mda7_flg
beq.w iea_fmovm_data_predec
cmpi.b SPCOND_FLG(%a6),&mia7_flg
bne.w iea_fmovm_exit
iea_fmovm_data_postinc:
btst &0x7,EXC_SR(%a6)
bne.b iea_fmovm_data_pi_trace
mov.w EXC_SR(%a6),(EXC_SR,%a6,%d0)
mov.l EXC_EXTWPTR(%a6),(EXC_PC,%a6,%d0)
mov.w &0x00f0,(EXC_VOFF,%a6,%d0)
lea (EXC_SR,%a6,%d0),%a0
mov.l %a0,EXC_SR(%a6)
fmovm.x EXC_FP0(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6
mov.l (%sp)+,%sp
bra.l _fpsp_done
iea_fmovm_data_pi_trace:
mov.w EXC_SR(%a6),(EXC_SR-0x4,%a6,%d0)
mov.l EXC_EXTWPTR(%a6),(EXC_PC-0x4,%a6,%d0)
mov.w &0x2024,(EXC_VOFF-0x4,%a6,%d0)
mov.l EXC_PC(%a6),(EXC_VOFF+0x2-0x4,%a6,%d0)
lea (EXC_SR-0x4,%a6,%d0),%a0
mov.l %a0,EXC_SR(%a6)
fmovm.x EXC_FP0(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6
mov.l (%sp)+,%sp
bra.l _real_trace
iea_fmovm_data_predec:
mov.b %d1,EXC_VOFF(%a6) # store strg
mov.b %d0,0x1+EXC_VOFF(%a6) # store size
fmovm.x EXC_FP0(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
mov.l (%a6),-(%sp) # make a copy of a6
mov.l %d0,-(%sp) # save d0
mov.l %d1,-(%sp) # save d1
mov.l EXC_EXTWPTR(%a6),-(%sp) # make a copy of Next PC
clr.l %d0
mov.b 0x1+EXC_VOFF(%a6),%d0 # fetch size
neg.l %d0 # get negative of size
btst &0x7,EXC_SR(%a6) # is trace enabled?
beq.b iea_fmovm_data_p2
mov.w EXC_SR(%a6),(EXC_SR-0x4,%a6,%d0)
mov.l EXC_PC(%a6),(EXC_VOFF-0x2,%a6,%d0)
mov.l (%sp)+,(EXC_PC-0x4,%a6,%d0)
mov.w &0x2024,(EXC_VOFF-0x4,%a6,%d0)
pea (%a6,%d0) # create final sp
bra.b iea_fmovm_data_p3
iea_fmovm_data_p2:
mov.w EXC_SR(%a6),(EXC_SR,%a6,%d0)
mov.l (%sp)+,(EXC_PC,%a6,%d0)
mov.w &0x00f0,(EXC_VOFF,%a6,%d0)
pea (0x4,%a6,%d0) # create final sp
iea_fmovm_data_p3:
clr.l %d1
mov.b EXC_VOFF(%a6),%d1 # fetch strg
tst.b %d1
bpl.b fm_1
fmovm.x &0x80,(0x4+0x8,%a6,%d0)
addi.l &0xc,%d0
fm_1:
lsl.b &0x1,%d1
bpl.b fm_2
fmovm.x &0x40,(0x4+0x8,%a6,%d0)
addi.l &0xc,%d0
fm_2:
lsl.b &0x1,%d1
bpl.b fm_3
fmovm.x &0x20,(0x4+0x8,%a6,%d0)
addi.l &0xc,%d0
fm_3:
lsl.b &0x1,%d1
bpl.b fm_4
fmovm.x &0x10,(0x4+0x8,%a6,%d0)
addi.l &0xc,%d0
fm_4:
lsl.b &0x1,%d1
bpl.b fm_5
fmovm.x &0x08,(0x4+0x8,%a6,%d0)
addi.l &0xc,%d0
fm_5:
lsl.b &0x1,%d1
bpl.b fm_6
fmovm.x &0x04,(0x4+0x8,%a6,%d0)
addi.l &0xc,%d0
fm_6:
lsl.b &0x1,%d1
bpl.b fm_7
fmovm.x &0x02,(0x4+0x8,%a6,%d0)
addi.l &0xc,%d0
fm_7:
lsl.b &0x1,%d1
bpl.b fm_end
fmovm.x &0x01,(0x4+0x8,%a6,%d0)
fm_end:
mov.l 0x4(%sp),%d1
mov.l 0x8(%sp),%d0
mov.l 0xc(%sp),%a6
mov.l (%sp)+,%sp
btst &0x7,(%sp) # is trace enabled?
beq.l _fpsp_done
bra.l _real_trace
#########################################################################
iea_fmovm_ctrl:
bsr.l fmovm_ctrl # load ctrl regs
iea_fmovm_exit:
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
btst &0x7,EXC_SR(%a6) # is trace on?
bne.b iea_fmovm_trace # yes
mov.l EXC_EXTWPTR(%a6),EXC_PC(%a6) # set Next PC
unlk %a6 # unravel the frame
bra.l _fpsp_done # exit to os
#
#
# ***************** *****************
# * 0x0 * 0x0f0 * * Current *
# ***************** * PC *
# * Current * *****************
# * PC * * 0x2 * 0x024 *
# ***************** *****************
# * SR * * Next *
# ***************** * PC *
# *****************
# * SR *
# *****************
# -restore a6 (not with unlk)
# -shift stack frame down over where old a6 used to be
# -add LOCAL_SIZE to stack pointer
iea_fmovm_trace:
mov.l (%a6),%a6 # restore frame pointer
mov.w EXC_SR+LOCAL_SIZE(%sp),0x0+LOCAL_SIZE(%sp)
mov.l EXC_PC+LOCAL_SIZE(%sp),0x8+LOCAL_SIZE(%sp)
mov.l EXC_EXTWPTR+LOCAL_SIZE(%sp),0x2+LOCAL_SIZE(%sp)
mov.w &0x2024,0x6+LOCAL_SIZE(%sp) # stk fmt = 0x2; voff = 0x024
add.l &LOCAL_SIZE,%sp # clear stack frame
bra.l _real_trace
#########################################################################
iea_disabled:
mov.l (%sp)+,%d0 # restore d0
link %a6,&-LOCAL_SIZE # init stack frame
movm.l &0x0303,EXC_DREGS(%a6) # save d0-d1/a0-a1
mov.l EXC_PC(%a6),EXC_EXTWPTR(%a6)
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch the instruction words
mov.l %d0,EXC_OPWORD(%a6) # store OPWORD and EXTWORD
tst.w %d0 # is instr fmovm?
bmi.b iea_dis_fmovm # yes
iea_dis_immed:
mov.l &0x10,%d0 # 16 bytes of instruction
bra.b iea_dis_cont
iea_dis_fmovm:
btst &0xe,%d0 # is instr fmovm ctrl
bne.b iea_dis_fmovm_data # no
bfextu %d0{&19:&3},%d1
mov.l &0xc,%d0
cmpi.b %d1,&0x7 # move all regs?
bne.b iea_dis_cont
addq.l &0x4,%d0
bra.b iea_dis_cont
iea_dis_fmovm_data:
clr.l %d0
bsr.l fmovm_calc_ea
mov.l EXC_EXTWPTR(%a6),%d0
sub.l EXC_PC(%a6),%d0
iea_dis_cont:
mov.w %d0,EXC_VOFF(%a6) # store stack shift value
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6
subq.l &0x8,%sp # make room for new stack
mov.l %d0,-(%sp) # save d0
mov.w 0xc(%sp),0x4(%sp) # move SR
mov.l 0xe(%sp),0x6(%sp) # move Current PC
clr.l %d0
mov.w 0x12(%sp),%d0
mov.l 0x6(%sp),0x10(%sp) # move Current PC
add.l %d0,0x6(%sp) # make Next PC
mov.w &0x402c,0xa(%sp) # insert offset,frame format
mov.l (%sp)+,%d0 # restore d0
bra.l _real_fpu_disabled
##########
iea_iacc:
movc %pcr,%d0
btst &0x1,%d0
bne.b iea_iacc_cont
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1 on stack
iea_iacc_cont:
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6
subq.w &0x8,%sp # make stack frame bigger
mov.l 0x8(%sp),(%sp) # store SR,hi(PC)
mov.w 0xc(%sp),0x4(%sp) # store lo(PC)
mov.w &0x4008,0x6(%sp) # store voff
mov.l 0x2(%sp),0x8(%sp) # store ea
mov.l &0x09428001,0xc(%sp) # store fslw
iea_acc_done:
btst &0x5,(%sp) # user or supervisor mode?
beq.b iea_acc_done2 # user
bset &0x2,0xd(%sp) # set supervisor TM bit
iea_acc_done2:
bra.l _real_access
iea_dacc:
lea -LOCAL_SIZE(%a6),%sp
movc %pcr,%d1
btst &0x1,%d1
bne.b iea_dacc_cont
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1 on stack
fmovm.l LOCAL_SIZE+USER_FPCR(%sp),%fpcr,%fpsr,%fpiar # restore ctrl regs
iea_dacc_cont:
mov.l (%a6),%a6
mov.l 0x4+LOCAL_SIZE(%sp),-0x8+0x4+LOCAL_SIZE(%sp)
mov.w 0x8+LOCAL_SIZE(%sp),-0x8+0x8+LOCAL_SIZE(%sp)
mov.w &0x4008,-0x8+0xa+LOCAL_SIZE(%sp)
mov.l %a0,-0x8+0xc+LOCAL_SIZE(%sp)
mov.w %d0,-0x8+0x10+LOCAL_SIZE(%sp)
mov.w &0x0001,-0x8+0x12+LOCAL_SIZE(%sp)
movm.l LOCAL_SIZE+EXC_DREGS(%sp),&0x0303 # restore d0-d1/a0-a1
add.w &LOCAL_SIZE-0x4,%sp
bra.b iea_acc_done
#########################################################################
# #
# #
# #
# - The system stack contains the FP Operr exception frame #
# - The fsave frame contains the source operand #
# #
# - The system stack is unchanged #
# - The fsave frame contains the adjusted src op for opclass 0,2 #
# #
# #
#########################################################################
global _fpsp_operr
_fpsp_operr:
link.w %a6,&-LOCAL_SIZE # init stack frame
fsave FP_SRC(%a6) # grab the "busy" frame
movm.l &0x0303,EXC_DREGS(%a6) # save d0-d1/a0-a1
fmovm.l %fpcr,%fpsr,%fpiar,USER_FPCR(%a6) # save ctrl regs
fmovm.x &0xc0,EXC_FPREGS(%a6) # save fp0-fp1 on stack
mov.l USER_FPIAR(%a6),EXC_EXTWPTR(%a6)
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch the instruction words
mov.l %d0,EXC_OPWORD(%a6)
##############################################################################
btst &13,%d0 # is instr an fmove out?
bne.b foperr_out # fmove out
lea FP_SRC(%a6),%a0 # pass: ptr to src op
bsr.l fix_skewed_ops # fix src op
foperr_exit:
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6)
unlk %a6
bra.l _real_operr
########################################################################
#
#
#
#
foperr_out:
mov.w FP_SRC_EX(%a6),%d1 # fetch exponent
andi.w &0x7fff,%d1
cmpi.w %d1,&0x7fff
bne.b foperr_out_not_qnan
tst.l FP_SRC_LO(%a6)
bne.b foperr_out_qnan
mov.l FP_SRC_HI(%a6),%d1
andi.l &0x7fffffff,%d1
beq.b foperr_out_not_qnan
foperr_out_qnan:
mov.l FP_SRC_HI(%a6),L_SCR1(%a6)
bra.b foperr_out_jmp
foperr_out_not_qnan:
mov.l &0x7fffffff,%d1
tst.b FP_SRC_EX(%a6)
bpl.b foperr_out_not_qnan2
addq.l &0x1,%d1
foperr_out_not_qnan2:
mov.l %d1,L_SCR1(%a6)
foperr_out_jmp:
bfextu %d0{&19:&3},%d0 # extract dst format field
mov.b 1+EXC_OPWORD(%a6),%d1 # extract <ea> mode,reg
mov.w (tbl_operr.b,%pc,%d0.w*2),%a0
jmp (tbl_operr.b,%pc,%a0)
tbl_operr:
short foperr_out_l - tbl_operr # long word integer
short tbl_operr - tbl_operr # sgl prec shouldn't happen
short tbl_operr - tbl_operr # ext prec shouldn't happen
short foperr_exit - tbl_operr # packed won't enter here
short foperr_out_w - tbl_operr # word integer
short tbl_operr - tbl_operr # dbl prec shouldn't happen
short foperr_out_b - tbl_operr # byte integer
short tbl_operr - tbl_operr # packed won't enter here
foperr_out_b:
mov.b L_SCR1(%a6),%d0 # load positive default result
cmpi.b %d1,&0x7 # is <ea> mode a data reg?
ble.b foperr_out_b_save_dn # yes
mov.l EXC_EA(%a6),%a0 # pass: <ea> of default result
bsr.l _dmem_write_byte # write the default result
tst.l %d1 # did dstore fail?
bne.l facc_out_b # yes
bra.w foperr_exit
foperr_out_b_save_dn:
andi.w &0x0007,%d1
bsr.l store_dreg_b # store result to regfile
bra.w foperr_exit
foperr_out_w:
mov.w L_SCR1(%a6),%d0 # load positive default result
cmpi.b %d1,&0x7 # is <ea> mode a data reg?
ble.b foperr_out_w_save_dn # yes
mov.l EXC_EA(%a6),%a0 # pass: <ea> of default result
bsr.l _dmem_write_word # write the default result
tst.l %d1 # did dstore fail?
bne.l facc_out_w # yes
bra.w foperr_exit
foperr_out_w_save_dn:
andi.w &0x0007,%d1
bsr.l store_dreg_w # store result to regfile
bra.w foperr_exit
foperr_out_l:
mov.l L_SCR1(%a6),%d0 # load positive default result
cmpi.b %d1,&0x7 # is <ea> mode a data reg?
ble.b foperr_out_l_save_dn # yes
mov.l EXC_EA(%a6),%a0 # pass: <ea> of default result
bsr.l _dmem_write_long # write the default result
tst.l %d1 # did dstore fail?
bne.l facc_out_l # yes
bra.w foperr_exit
foperr_out_l_save_dn:
andi.w &0x0007,%d1
bsr.l store_dreg_l # store result to regfile
bra.w foperr_exit
#########################################################################
# #
# #
# #
# - The system stack contains the FP SNAN exception frame #
# - The fsave frame contains the source operand #
# #
# - The system stack is unchanged #
# - The fsave frame contains the adjusted src op for opclass 0,2 #
# #
# if the effective addressing mode was -() or ()+, then the address #
# #
#########################################################################
global _fpsp_snan
_fpsp_snan:
link.w %a6,&-LOCAL_SIZE # init stack frame
fsave FP_SRC(%a6) # grab the "busy" frame
movm.l &0x0303,EXC_DREGS(%a6) # save d0-d1/a0-a1
fmovm.l %fpcr,%fpsr,%fpiar,USER_FPCR(%a6) # save ctrl regs
fmovm.x &0xc0,EXC_FPREGS(%a6) # save fp0-fp1 on stack
mov.l USER_FPIAR(%a6),EXC_EXTWPTR(%a6)
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch the instruction words
mov.l %d0,EXC_OPWORD(%a6)
##############################################################################
btst &13,%d0 # is instr an fmove out?
bne.w fsnan_out # fmove out
lea FP_SRC(%a6),%a0 # pass: ptr to src op
bsr.l fix_skewed_ops # fix src op
fsnan_exit:
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6)
unlk %a6
bra.l _real_snan
########################################################################
#
#
#
fsnan_out:
bfextu %d0{&19:&3},%d0 # extract dst format field
mov.b 1+EXC_OPWORD(%a6),%d1 # extract <ea> mode,reg
mov.w (tbl_snan.b,%pc,%d0.w*2),%a0
jmp (tbl_snan.b,%pc,%a0)
tbl_snan:
short fsnan_out_l - tbl_snan # long word integer
short fsnan_out_s - tbl_snan # sgl prec shouldn't happen
short fsnan_out_x - tbl_snan # ext prec shouldn't happen
short tbl_snan - tbl_snan # packed needs no help
short fsnan_out_w - tbl_snan # word integer
short fsnan_out_d - tbl_snan # dbl prec shouldn't happen
short fsnan_out_b - tbl_snan # byte integer
short tbl_snan - tbl_snan # packed needs no help
fsnan_out_b:
mov.b FP_SRC_HI(%a6),%d0 # load upper byte of SNAN
bset &6,%d0 # set SNAN bit
cmpi.b %d1,&0x7 # is <ea> mode a data reg?
ble.b fsnan_out_b_dn # yes
mov.l EXC_EA(%a6),%a0 # pass: <ea> of default result
bsr.l _dmem_write_byte # write the default result
tst.l %d1 # did dstore fail?
bne.l facc_out_b # yes
bra.w fsnan_exit
fsnan_out_b_dn:
andi.w &0x0007,%d1
bsr.l store_dreg_b # store result to regfile
bra.w fsnan_exit
fsnan_out_w:
mov.w FP_SRC_HI(%a6),%d0 # load upper word of SNAN
bset &14,%d0 # set SNAN bit
cmpi.b %d1,&0x7 # is <ea> mode a data reg?
ble.b fsnan_out_w_dn # yes
mov.l EXC_EA(%a6),%a0 # pass: <ea> of default result
bsr.l _dmem_write_word # write the default result
tst.l %d1 # did dstore fail?
bne.l facc_out_w # yes
bra.w fsnan_exit
fsnan_out_w_dn:
andi.w &0x0007,%d1
bsr.l store_dreg_w # store result to regfile
bra.w fsnan_exit
fsnan_out_l:
mov.l FP_SRC_HI(%a6),%d0 # load upper longword of SNAN
bset &30,%d0 # set SNAN bit
cmpi.b %d1,&0x7 # is <ea> mode a data reg?
ble.b fsnan_out_l_dn # yes
mov.l EXC_EA(%a6),%a0 # pass: <ea> of default result
bsr.l _dmem_write_long # write the default result
tst.l %d1 # did dstore fail?
bne.l facc_out_l # yes
bra.w fsnan_exit
fsnan_out_l_dn:
andi.w &0x0007,%d1
bsr.l store_dreg_l # store result to regfile
bra.w fsnan_exit
fsnan_out_s:
cmpi.b %d1,&0x7 # is <ea> mode a data reg?
ble.b fsnan_out_d_dn # yes
mov.l FP_SRC_EX(%a6),%d0 # fetch SNAN sign
andi.l &0x80000000,%d0 # keep sign
ori.l &0x7fc00000,%d0 # insert new exponent,SNAN bit
mov.l FP_SRC_HI(%a6),%d1 # load mantissa
lsr.l &0x8,%d1 # shift mantissa for sgl
or.l %d1,%d0 # create sgl SNAN
mov.l EXC_EA(%a6),%a0 # pass: <ea> of default result
bsr.l _dmem_write_long # write the default result
tst.l %d1 # did dstore fail?
bne.l facc_out_l # yes
bra.w fsnan_exit
fsnan_out_d_dn:
mov.l FP_SRC_EX(%a6),%d0 # fetch SNAN sign
andi.l &0x80000000,%d0 # keep sign
ori.l &0x7fc00000,%d0 # insert new exponent,SNAN bit
mov.l %d1,-(%sp)
mov.l FP_SRC_HI(%a6),%d1 # load mantissa
lsr.l &0x8,%d1 # shift mantissa for sgl
or.l %d1,%d0 # create sgl SNAN
mov.l (%sp)+,%d1
andi.w &0x0007,%d1
bsr.l store_dreg_l # store result to regfile
bra.w fsnan_exit
fsnan_out_d:
mov.l FP_SRC_EX(%a6),%d0 # fetch SNAN sign
andi.l &0x80000000,%d0 # keep sign
ori.l &0x7ff80000,%d0 # insert new exponent,SNAN bit
mov.l FP_SRC_HI(%a6),%d1 # load hi mantissa
mov.l %d0,FP_SCR0_EX(%a6) # store to temp space
mov.l &11,%d0 # load shift amt
lsr.l %d0,%d1
or.l %d1,FP_SCR0_EX(%a6) # create dbl hi
mov.l FP_SRC_HI(%a6),%d1 # load hi mantissa
andi.l &0x000007ff,%d1
ror.l %d0,%d1
mov.l %d1,FP_SCR0_HI(%a6) # store to temp space
mov.l FP_SRC_LO(%a6),%d1 # load lo mantissa
lsr.l %d0,%d1
or.l %d1,FP_SCR0_HI(%a6) # create dbl lo
lea FP_SCR0(%a6),%a0 # pass: ptr to operand
mov.l EXC_EA(%a6),%a1 # pass: dst addr
movq.l &0x8,%d0 # pass: size of 8 bytes
bsr.l _dmem_write # write the default result
tst.l %d1 # did dstore fail?
bne.l facc_out_d # yes
bra.w fsnan_exit
fsnan_out_x:
clr.b SPCOND_FLG(%a6) # clear special case flag
mov.w FP_SRC_EX(%a6),FP_SCR0_EX(%a6)
clr.w 2+FP_SCR0(%a6)
mov.l FP_SRC_HI(%a6),%d0
bset &30,%d0
mov.l %d0,FP_SCR0_HI(%a6)
mov.l FP_SRC_LO(%a6),FP_SCR0_LO(%a6)
btst &0x5,EXC_SR(%a6) # supervisor mode exception?
bne.b fsnan_out_x_s # yes
mov.l %usp,%a0 # fetch user stack pointer
mov.l %a0,EXC_A7(%a6) # save on stack for calc_ea()
mov.l (%a6),EXC_A6(%a6)
bsr.l _calc_ea_fout # find the correct ea,update An
mov.l %a0,%a1
mov.l %a0,EXC_EA(%a6) # stack correct <ea>
mov.l EXC_A7(%a6),%a0
mov.l %a0,%usp # restore user stack pointer
mov.l EXC_A6(%a6),(%a6)
fsnan_out_x_save:
lea FP_SCR0(%a6),%a0 # pass: ptr to operand
movq.l &0xc,%d0 # pass: size of extended
bsr.l _dmem_write # write the default result
tst.l %d1 # did dstore fail?
bne.l facc_out_x # yes
bra.w fsnan_exit
fsnan_out_x_s:
mov.l (%a6),EXC_A6(%a6)
bsr.l _calc_ea_fout # find the correct ea,update An
mov.l %a0,%a1
mov.l %a0,EXC_EA(%a6) # stack correct <ea>
mov.l EXC_A6(%a6),(%a6)
cmpi.b SPCOND_FLG(%a6),&mda7_flg # is <ea> mode -(a7)?
bne.b fsnan_out_x_save # no
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6)
mov.l EXC_A6(%a6),%a6 # restore frame pointer
mov.l LOCAL_SIZE+EXC_SR(%sp),LOCAL_SIZE+EXC_SR-0xc(%sp)
mov.l LOCAL_SIZE+EXC_PC+0x2(%sp),LOCAL_SIZE+EXC_PC+0x2-0xc(%sp)
mov.l LOCAL_SIZE+EXC_EA(%sp),LOCAL_SIZE+EXC_EA-0xc(%sp)
mov.l LOCAL_SIZE+FP_SCR0_EX(%sp),LOCAL_SIZE+EXC_SR(%sp)
mov.l LOCAL_SIZE+FP_SCR0_HI(%sp),LOCAL_SIZE+EXC_PC+0x2(%sp)
mov.l LOCAL_SIZE+FP_SCR0_LO(%sp),LOCAL_SIZE+EXC_EA(%sp)
add.l &LOCAL_SIZE-0x8,%sp
bra.l _real_snan
#########################################################################
# #
# #
# #
# - The system stack contains the FP Inexact exception frame #
# - The fsave frame contains the source operand #
# #
# - The system stack is unchanged #
# - The fsave frame contains the adjusted src op for opclass 0,2 #
# #
# #
#########################################################################
global _fpsp_inex
_fpsp_inex:
link.w %a6,&-LOCAL_SIZE # init stack frame
fsave FP_SRC(%a6) # grab the "busy" frame
movm.l &0x0303,EXC_DREGS(%a6) # save d0-d1/a0-a1
fmovm.l %fpcr,%fpsr,%fpiar,USER_FPCR(%a6) # save ctrl regs
fmovm.x &0xc0,EXC_FPREGS(%a6) # save fp0-fp1 on stack
mov.l USER_FPIAR(%a6),EXC_EXTWPTR(%a6)
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch the instruction words
mov.l %d0,EXC_OPWORD(%a6)
##############################################################################
btst &13,%d0 # is instr an fmove out?
bne.w finex_out # fmove out
bfextu %d0{&19:&3},%d0 # fetch instr size
bne.b finex_cont # instr size is not long
cmpi.w FP_SRC_EX(%a6),&0x401e # is exponent 0x401e?
bne.b finex_cont # no
fmov.l &0x0,%fpcr
fmov.l FP_SRC_HI(%a6),%fp0 # load integer src
fmov.x %fp0,FP_SRC(%a6) # store integer as extended precision
mov.w &0xe001,0x2+FP_SRC(%a6)
finex_cont:
lea FP_SRC(%a6),%a0 # pass: ptr to src op
bsr.l fix_skewed_ops # fix src op
andi.l &0x00ff01ff,USER_FPSR(%a6) # zero all but accured field
fmov.l &0x0,%fpcr # zero current control regs
fmov.l &0x0,%fpsr
bfextu EXC_EXTWORD(%a6){&0:&6},%d1 # extract upper 6 of cmdreg
cmpi.b %d1,&0x17 # is op an fmovecr?
beq.w finex_fmovcr # yes
lea FP_SRC(%a6),%a0 # pass: ptr to src op
bsr.l set_tag_x # tag the operand type
mov.b %d0,STAG(%a6) # maybe NORM,DENORM
btst &0x5,1+EXC_CMDREG(%a6) # is operation monadic or dyadic?
beq.b finex_extract # monadic
btst &0x4,1+EXC_CMDREG(%a6) # is operation an fsincos?
bne.b finex_extract # yes
bfextu EXC_CMDREG(%a6){&6:&3},%d0 # dyadic; load dst reg
bsr.l load_fpn2 # load dst into FP_DST
lea FP_DST(%a6),%a0 # pass: ptr to dst op
bsr.l set_tag_x # tag the operand type
cmpi.b %d0,&UNNORM # is operand an UNNORM?
bne.b finex_op2_done # no
bsr.l unnorm_fix # yes; convert to NORM,DENORM,or ZERO
finex_op2_done:
mov.b %d0,DTAG(%a6) # save dst optype tag
finex_extract:
clr.l %d0
mov.b FPCR_MODE(%a6),%d0 # pass rnd prec/mode
mov.b 1+EXC_CMDREG(%a6),%d1
andi.w &0x007f,%d1 # extract extension
lea FP_SRC(%a6),%a0
lea FP_DST(%a6),%a1
mov.l (tbl_unsupp.l,%pc,%d1.w*4),%d1 # fetch routine addr
jsr (tbl_unsupp.l,%pc,%d1.l*1)
finex_save:
bfextu EXC_CMDREG(%a6){&6:&3},%d0
bsr.l store_fpreg
finex_exit:
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6)
unlk %a6
bra.l _real_inex
finex_fmovcr:
clr.l %d0
mov.b FPCR_MODE(%a6),%d0 # pass rnd prec,mode
mov.b 1+EXC_CMDREG(%a6),%d1
andi.l &0x0000007f,%d1 # pass rom offset
bsr.l smovcr
bra.b finex_save
########################################################################
#
#
#
finex_out:
mov.b &NORM,STAG(%a6) # src is a NORM
clr.l %d0
mov.b FPCR_MODE(%a6),%d0 # pass rnd prec,mode
andi.l &0xffff00ff,USER_FPSR(%a6) # zero exception field
lea FP_SRC(%a6),%a0 # pass ptr to src operand
bsr.l fout # store the default result
bra.b finex_exit
#########################################################################
# #
# #
# #
# - The system stack contains the FP DZ exception stack. #
# - The fsave frame contains the source operand. #
# #
# - The system stack contains the FP DZ exception stack. #
# - The fsave frame contains the adjusted source operand. #
# #
# #
#########################################################################
global _fpsp_dz
_fpsp_dz:
link.w %a6,&-LOCAL_SIZE # init stack frame
fsave FP_SRC(%a6) # grab the "busy" frame
movm.l &0x0303,EXC_DREGS(%a6) # save d0-d1/a0-a1
fmovm.l %fpcr,%fpsr,%fpiar,USER_FPCR(%a6) # save ctrl regs
fmovm.x &0xc0,EXC_FPREGS(%a6) # save fp0-fp1 on stack
mov.l USER_FPIAR(%a6),EXC_EXTWPTR(%a6)
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch the instruction words
mov.l %d0,EXC_OPWORD(%a6)
##############################################################################
lea FP_SRC(%a6),%a0 # pass: ptr to src op
bsr.l fix_skewed_ops # fix src op
fdz_exit:
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
frestore FP_SRC(%a6)
unlk %a6
bra.l _real_dz
#########################################################################
# #
# "Line F Emulator" exception in an operating system integrating #
# #
# #
# - The system stack contains a "Line F Emulator" exception #
# #
# - The system stack is unchanged. #
# #
# "FPU Unimplemented" instructions will not be emulated, the exception #
# #
#########################################################################
global _fpsp_fline
_fpsp_fline:
cmpi.w 0x6(%sp),&0x402c
beq.l _real_fpu_disabled
bra.l _real_fline
#########################################################################
# #
# #
# #
# #
# "Dummy" CALCulate Effective Address: #
# #
# 1) -(An) : The register is not updated regardless of size. #
# 2) (An)+ : The register is not updated. #
# 3) #<data> : The upper longword of the immediate operand is #
# #
#########################################################################
global _dcalc_ea
_dcalc_ea:
mov.l %d0, %a0 # move # bytes to %a0
mov.b 1+EXC_OPWORD(%a6), %d0 # fetch opcode word
mov.l %d0, %d1 # make a copy
andi.w &0x38, %d0 # extract mode field
andi.l &0x7, %d1 # extract reg field
cmpi.b %d0,&0x18 # is mode (An)+ ?
beq.b dcea_pi # yes
cmpi.b %d0,&0x20 # is mode -(An) ?
beq.b dcea_pd # yes
or.w %d1,%d0 # concat mode,reg
cmpi.b %d0,&0x3c # is mode #<data>?
beq.b dcea_imm # yes
mov.l EXC_EA(%a6),%a0 # return <ea>
rts
dcea_imm:
mov.b &immed_flg,SPCOND_FLG(%a6)
lea ([USER_FPIAR,%a6],0x4),%a0 # no; return <ea>
rts
dcea_pi:
mov.l %a0,%d0 # pass amt to inc by
bsr.l inc_areg # inc addr register
mov.l EXC_EA(%a6),%a0 # stacked <ea> is correct
rts
dcea_pd:
mov.l %a0,%d0 # pass amt to dec by
bsr.l dec_areg # dec addr register
mov.l EXC_EA(%a6),%a0 # stacked <ea> is correct
cmpi.b %d0,&0xc # is opsize ext or packed?
beq.b dcea_pd2 # yes
rts
dcea_pd2:
sub.l &0x8,%a0 # correct <ea>
mov.l %a0,EXC_EA(%a6) # put correct <ea> on stack
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global _calc_ea_fout
_calc_ea_fout:
mov.b 1+EXC_OPWORD(%a6),%d0 # fetch opcode word
mov.l %d0,%d1 # make a copy
andi.w &0x38,%d0 # extract mode field
andi.l &0x7,%d1 # extract reg field
cmpi.b %d0,&0x18 # is mode (An)+ ?
beq.b ceaf_pi # yes
cmpi.b %d0,&0x20 # is mode -(An) ?
beq.w ceaf_pd # yes
mov.l EXC_EA(%a6),%a0 # stacked <ea> is correct
rts
# (An)+ : extended and packed fmove out
# : stacked <ea> is correct
# : "An" not updated
ceaf_pi:
mov.w (tbl_ceaf_pi.b,%pc,%d1.w*2),%d1
mov.l EXC_EA(%a6),%a0
jmp (tbl_ceaf_pi.b,%pc,%d1.w*1)
swbeg &0x8
tbl_ceaf_pi:
short ceaf_pi0 - tbl_ceaf_pi
short ceaf_pi1 - tbl_ceaf_pi
short ceaf_pi2 - tbl_ceaf_pi
short ceaf_pi3 - tbl_ceaf_pi
short ceaf_pi4 - tbl_ceaf_pi
short ceaf_pi5 - tbl_ceaf_pi
short ceaf_pi6 - tbl_ceaf_pi
short ceaf_pi7 - tbl_ceaf_pi
ceaf_pi0:
addi.l &0xc,EXC_DREGS+0x8(%a6)
rts
ceaf_pi1:
addi.l &0xc,EXC_DREGS+0xc(%a6)
rts
ceaf_pi2:
add.l &0xc,%a2
rts
ceaf_pi3:
add.l &0xc,%a3
rts
ceaf_pi4:
add.l &0xc,%a4
rts
ceaf_pi5:
add.l &0xc,%a5
rts
ceaf_pi6:
addi.l &0xc,EXC_A6(%a6)
rts
ceaf_pi7:
mov.b &mia7_flg,SPCOND_FLG(%a6)
addi.l &0xc,EXC_A7(%a6)
rts
# -(An) : extended and packed fmove out
# : stacked <ea> = actual <ea> + 8
# : "An" not updated
ceaf_pd:
mov.w (tbl_ceaf_pd.b,%pc,%d1.w*2),%d1
mov.l EXC_EA(%a6),%a0
sub.l &0x8,%a0
sub.l &0x8,EXC_EA(%a6)
jmp (tbl_ceaf_pd.b,%pc,%d1.w*1)
swbeg &0x8
tbl_ceaf_pd:
short ceaf_pd0 - tbl_ceaf_pd
short ceaf_pd1 - tbl_ceaf_pd
short ceaf_pd2 - tbl_ceaf_pd
short ceaf_pd3 - tbl_ceaf_pd
short ceaf_pd4 - tbl_ceaf_pd
short ceaf_pd5 - tbl_ceaf_pd
short ceaf_pd6 - tbl_ceaf_pd
short ceaf_pd7 - tbl_ceaf_pd
ceaf_pd0:
mov.l %a0,EXC_DREGS+0x8(%a6)
rts
ceaf_pd1:
mov.l %a0,EXC_DREGS+0xc(%a6)
rts
ceaf_pd2:
mov.l %a0,%a2
rts
ceaf_pd3:
mov.l %a0,%a3
rts
ceaf_pd4:
mov.l %a0,%a4
rts
ceaf_pd5:
mov.l %a0,%a5
rts
ceaf_pd6:
mov.l %a0,EXC_A6(%a6)
rts
ceaf_pd7:
mov.l %a0,EXC_A7(%a6)
mov.b &mda7_flg,SPCOND_FLG(%a6)
rts
#
#
swbeg &109
tbl_unsupp:
long fin - tbl_unsupp # 00: fmove
long fint - tbl_unsupp # 01: fint
long tbl_unsupp - tbl_unsupp # 02: fsinh
long fintrz - tbl_unsupp # 03: fintrz
long fsqrt - tbl_unsupp # 04: fsqrt
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp # 06: flognp1
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp # 08: fetoxm1
long tbl_unsupp - tbl_unsupp # 09: ftanh
long tbl_unsupp - tbl_unsupp # 0a: fatan
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp # 0c: fasin
long tbl_unsupp - tbl_unsupp # 0d: fatanh
long tbl_unsupp - tbl_unsupp # 0e: fsin
long tbl_unsupp - tbl_unsupp # 0f: ftan
long tbl_unsupp - tbl_unsupp # 10: fetox
long tbl_unsupp - tbl_unsupp # 11: ftwotox
long tbl_unsupp - tbl_unsupp # 12: ftentox
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp # 14: flogn
long tbl_unsupp - tbl_unsupp # 15: flog10
long tbl_unsupp - tbl_unsupp # 16: flog2
long tbl_unsupp - tbl_unsupp
long fabs - tbl_unsupp # 18: fabs
long tbl_unsupp - tbl_unsupp # 19: fcosh
long fneg - tbl_unsupp # 1a: fneg
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp # 1c: facos
long tbl_unsupp - tbl_unsupp # 1d: fcos
long tbl_unsupp - tbl_unsupp # 1e: fgetexp
long tbl_unsupp - tbl_unsupp # 1f: fgetman
long fdiv - tbl_unsupp # 20: fdiv
long tbl_unsupp - tbl_unsupp # 21: fmod
long fadd - tbl_unsupp # 22: fadd
long fmul - tbl_unsupp # 23: fmul
long fsgldiv - tbl_unsupp # 24: fsgldiv
long tbl_unsupp - tbl_unsupp # 25: frem
long tbl_unsupp - tbl_unsupp # 26: fscale
long fsglmul - tbl_unsupp # 27: fsglmul
long fsub - tbl_unsupp # 28: fsub
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp # 30: fsincos
long tbl_unsupp - tbl_unsupp # 31: fsincos
long tbl_unsupp - tbl_unsupp # 32: fsincos
long tbl_unsupp - tbl_unsupp # 33: fsincos
long tbl_unsupp - tbl_unsupp # 34: fsincos
long tbl_unsupp - tbl_unsupp # 35: fsincos
long tbl_unsupp - tbl_unsupp # 36: fsincos
long tbl_unsupp - tbl_unsupp # 37: fsincos
long fcmp - tbl_unsupp # 38: fcmp
long tbl_unsupp - tbl_unsupp
long ftst - tbl_unsupp # 3a: ftst
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long fsin - tbl_unsupp # 40: fsmove
long fssqrt - tbl_unsupp # 41: fssqrt
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long fdin - tbl_unsupp # 44: fdmove
long fdsqrt - tbl_unsupp # 45: fdsqrt
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long fsabs - tbl_unsupp # 58: fsabs
long tbl_unsupp - tbl_unsupp
long fsneg - tbl_unsupp # 5a: fsneg
long tbl_unsupp - tbl_unsupp
long fdabs - tbl_unsupp # 5c: fdabs
long tbl_unsupp - tbl_unsupp
long fdneg - tbl_unsupp # 5e: fdneg
long tbl_unsupp - tbl_unsupp
long fsdiv - tbl_unsupp # 60: fsdiv
long tbl_unsupp - tbl_unsupp
long fsadd - tbl_unsupp # 62: fsadd
long fsmul - tbl_unsupp # 63: fsmul
long fddiv - tbl_unsupp # 64: fddiv
long tbl_unsupp - tbl_unsupp
long fdadd - tbl_unsupp # 66: fdadd
long fdmul - tbl_unsupp # 67: fdmul
long fssub - tbl_unsupp # 68: fssub
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long tbl_unsupp - tbl_unsupp
long fdsub - tbl_unsupp # 6c: fdsub
#################################################
# (smovcr is called from fpsp_inex.)
global smovcr
smovcr:
bra.b smovcr
#########################################################################
# #
# {i,d,}mem_read() - fetch data from memory #
# #
# #
# #
# #
# #
# <WORD 1> <WORD2> #
# 1111 0010 00 |<ea>| 11@& 1000 0$$$ 0000 #
# #
# & = (0): predecrement addressing mode #
# (1): postincrement or control addressing mode #
# @ = (0): move listed regs from memory to the FPU #
# (1): move listed regs from the FPU to memory #
# $$$ : index of data register holding reg select mask #
# #
# #
#########################################################################
global fmovm_dynamic
fmovm_dynamic:
mov.b 1+EXC_EXTWORD(%a6),%d1 # fetch extword
andi.w &0x70,%d1 # extract reg bits
lsr.b &0x4,%d1 # shift into lo bits
bsr.l fetch_dreg # fetch reg string
andi.l &0x000000ff,%d0 # keep only lo byte
mov.l %d0,-(%sp) # save strg
mov.b (tbl_fmovm_size.w,%pc,%d0),%d0
mov.l %d0,-(%sp) # save size
bsr.l fmovm_calc_ea # calculate <ea>
mov.l (%sp)+,%d0 # restore size
mov.l (%sp)+,%d1 # restore strg
# if the bit string is a zero, then the operation is a no-op
beq.w fmovm_data_done
btst &0x5,EXC_EXTWORD(%a6) # is it a move in or out?
beq.w fmovm_data_in # it's a move out
#############
#############
fmovm_data_out:
btst &0x4,EXC_EXTWORD(%a6) # control or predecrement?
bne.w fmovm_out_ctrl # control
############################
fmovm_out_predec:
mov.b (tbl_fmovm_convert.w,%pc,%d1.w*1),%d1
btst &0x5,EXC_SR(%a6) # user or supervisor mode?
beq.b fmovm_out_ctrl # user
fmovm_out_predec_s:
cmpi.b SPCOND_FLG(%a6),&mda7_flg # is <ea> mode -(a7)?
bne.b fmovm_out_ctrl
rts
############################
fmovm_out_ctrl:
mov.l %a0,%a1 # move <ea> to a1
sub.l %d0,%sp # subtract size of dump
lea (%sp),%a0
tst.b %d1 # should FP0 be moved?
bpl.b fmovm_out_ctrl_fp1 # no
mov.l 0x0+EXC_FP0(%a6),(%a0)+ # yes
mov.l 0x4+EXC_FP0(%a6),(%a0)+
mov.l 0x8+EXC_FP0(%a6),(%a0)+
fmovm_out_ctrl_fp1:
lsl.b &0x1,%d1 # should FP1 be moved?
bpl.b fmovm_out_ctrl_fp2 # no
mov.l 0x0+EXC_FP1(%a6),(%a0)+ # yes
mov.l 0x4+EXC_FP1(%a6),(%a0)+
mov.l 0x8+EXC_FP1(%a6),(%a0)+
fmovm_out_ctrl_fp2:
lsl.b &0x1,%d1 # should FP2 be moved?
bpl.b fmovm_out_ctrl_fp3 # no
fmovm.x &0x20,(%a0) # yes
add.l &0xc,%a0
fmovm_out_ctrl_fp3:
lsl.b &0x1,%d1 # should FP3 be moved?
bpl.b fmovm_out_ctrl_fp4 # no
fmovm.x &0x10,(%a0) # yes
add.l &0xc,%a0
fmovm_out_ctrl_fp4:
lsl.b &0x1,%d1 # should FP4 be moved?
bpl.b fmovm_out_ctrl_fp5 # no
fmovm.x &0x08,(%a0) # yes
add.l &0xc,%a0
fmovm_out_ctrl_fp5:
lsl.b &0x1,%d1 # should FP5 be moved?
bpl.b fmovm_out_ctrl_fp6 # no
fmovm.x &0x04,(%a0) # yes
add.l &0xc,%a0
fmovm_out_ctrl_fp6:
lsl.b &0x1,%d1 # should FP6 be moved?
bpl.b fmovm_out_ctrl_fp7 # no
fmovm.x &0x02,(%a0) # yes
add.l &0xc,%a0
fmovm_out_ctrl_fp7:
lsl.b &0x1,%d1 # should FP7 be moved?
bpl.b fmovm_out_ctrl_done # no
fmovm.x &0x01,(%a0) # yes
add.l &0xc,%a0
fmovm_out_ctrl_done:
mov.l %a1,L_SCR1(%a6)
lea (%sp),%a0 # pass: supervisor src
mov.l %d0,-(%sp) # save size
bsr.l _dmem_write # copy data to user mem
mov.l (%sp)+,%d0
add.l %d0,%sp # clear fpreg data from stack
tst.l %d1 # did dstore err?
bne.w fmovm_out_err # yes
rts
############
############
fmovm_data_in:
mov.l %a0,L_SCR1(%a6)
sub.l %d0,%sp # make room for fpregs
lea (%sp),%a1
mov.l %d1,-(%sp) # save bit string for later
mov.l %d0,-(%sp) # save # of bytes
bsr.l _dmem_read # copy data from user mem
mov.l (%sp)+,%d0 # retrieve # of bytes
tst.l %d1 # did dfetch fail?
bne.w fmovm_in_err # yes
mov.l (%sp)+,%d1 # load bit string
lea (%sp),%a0 # addr of stack
tst.b %d1 # should FP0 be moved?
bpl.b fmovm_data_in_fp1 # no
mov.l (%a0)+,0x0+EXC_FP0(%a6) # yes
mov.l (%a0)+,0x4+EXC_FP0(%a6)
mov.l (%a0)+,0x8+EXC_FP0(%a6)
fmovm_data_in_fp1:
lsl.b &0x1,%d1 # should FP1 be moved?
bpl.b fmovm_data_in_fp2 # no
mov.l (%a0)+,0x0+EXC_FP1(%a6) # yes
mov.l (%a0)+,0x4+EXC_FP1(%a6)
mov.l (%a0)+,0x8+EXC_FP1(%a6)
fmovm_data_in_fp2:
lsl.b &0x1,%d1 # should FP2 be moved?
bpl.b fmovm_data_in_fp3 # no
fmovm.x (%a0)+,&0x20 # yes
fmovm_data_in_fp3:
lsl.b &0x1,%d1 # should FP3 be moved?
bpl.b fmovm_data_in_fp4 # no
fmovm.x (%a0)+,&0x10 # yes
fmovm_data_in_fp4:
lsl.b &0x1,%d1 # should FP4 be moved?
bpl.b fmovm_data_in_fp5 # no
fmovm.x (%a0)+,&0x08 # yes
fmovm_data_in_fp5:
lsl.b &0x1,%d1 # should FP5 be moved?
bpl.b fmovm_data_in_fp6 # no
fmovm.x (%a0)+,&0x04 # yes
fmovm_data_in_fp6:
lsl.b &0x1,%d1 # should FP6 be moved?
bpl.b fmovm_data_in_fp7 # no
fmovm.x (%a0)+,&0x02 # yes
fmovm_data_in_fp7:
lsl.b &0x1,%d1 # should FP7 be moved?
bpl.b fmovm_data_in_done # no
fmovm.x (%a0)+,&0x01 # yes
fmovm_data_in_done:
add.l %d0,%sp # remove fpregs from stack
rts
#####################################
fmovm_data_done:
rts
##############################################################################
#
#
#
tbl_fmovm_size:
byte 0x00,0x0c,0x0c,0x18,0x0c,0x18,0x18,0x24
byte 0x0c,0x18,0x18,0x24,0x18,0x24,0x24,0x30
byte 0x0c,0x18,0x18,0x24,0x18,0x24,0x24,0x30
byte 0x18,0x24,0x24,0x30,0x24,0x30,0x30,0x3c
byte 0x0c,0x18,0x18,0x24,0x18,0x24,0x24,0x30
byte 0x18,0x24,0x24,0x30,0x24,0x30,0x30,0x3c
byte 0x18,0x24,0x24,0x30,0x24,0x30,0x30,0x3c
byte 0x24,0x30,0x30,0x3c,0x30,0x3c,0x3c,0x48
byte 0x0c,0x18,0x18,0x24,0x18,0x24,0x24,0x30
byte 0x18,0x24,0x24,0x30,0x24,0x30,0x30,0x3c
byte 0x18,0x24,0x24,0x30,0x24,0x30,0x30,0x3c
byte 0x24,0x30,0x30,0x3c,0x30,0x3c,0x3c,0x48
byte 0x18,0x24,0x24,0x30,0x24,0x30,0x30,0x3c
byte 0x24,0x30,0x30,0x3c,0x30,0x3c,0x3c,0x48
byte 0x24,0x30,0x30,0x3c,0x30,0x3c,0x3c,0x48
byte 0x30,0x3c,0x3c,0x48,0x3c,0x48,0x48,0x54
byte 0x0c,0x18,0x18,0x24,0x18,0x24,0x24,0x30
byte 0x18,0x24,0x24,0x30,0x24,0x30,0x30,0x3c
byte 0x18,0x24,0x24,0x30,0x24,0x30,0x30,0x3c
byte 0x24,0x30,0x30,0x3c,0x30,0x3c,0x3c,0x48
byte 0x18,0x24,0x24,0x30,0x24,0x30,0x30,0x3c
byte 0x24,0x30,0x30,0x3c,0x30,0x3c,0x3c,0x48
byte 0x24,0x30,0x30,0x3c,0x30,0x3c,0x3c,0x48
byte 0x30,0x3c,0x3c,0x48,0x3c,0x48,0x48,0x54
byte 0x18,0x24,0x24,0x30,0x24,0x30,0x30,0x3c
byte 0x24,0x30,0x30,0x3c,0x30,0x3c,0x3c,0x48
byte 0x24,0x30,0x30,0x3c,0x30,0x3c,0x3c,0x48
byte 0x30,0x3c,0x3c,0x48,0x3c,0x48,0x48,0x54
byte 0x24,0x30,0x30,0x3c,0x30,0x3c,0x3c,0x48
byte 0x30,0x3c,0x3c,0x48,0x3c,0x48,0x48,0x54
byte 0x30,0x3c,0x3c,0x48,0x3c,0x48,0x48,0x54
byte 0x3c,0x48,0x48,0x54,0x48,0x54,0x54,0x60
#
# 0x01 ==> 0x80
# 0x02 ==> 0x40
# .
# .
# 0xfd ==> 0xbf
# 0xfe ==> 0x7f
# 0xff ==> 0xff
#
tbl_fmovm_convert:
byte 0x00,0x80,0x40,0xc0,0x20,0xa0,0x60,0xe0
byte 0x10,0x90,0x50,0xd0,0x30,0xb0,0x70,0xf0
byte 0x08,0x88,0x48,0xc8,0x28,0xa8,0x68,0xe8
byte 0x18,0x98,0x58,0xd8,0x38,0xb8,0x78,0xf8
byte 0x04,0x84,0x44,0xc4,0x24,0xa4,0x64,0xe4
byte 0x14,0x94,0x54,0xd4,0x34,0xb4,0x74,0xf4
byte 0x0c,0x8c,0x4c,0xcc,0x2c,0xac,0x6c,0xec
byte 0x1c,0x9c,0x5c,0xdc,0x3c,0xbc,0x7c,0xfc
byte 0x02,0x82,0x42,0xc2,0x22,0xa2,0x62,0xe2
byte 0x12,0x92,0x52,0xd2,0x32,0xb2,0x72,0xf2
byte 0x0a,0x8a,0x4a,0xca,0x2a,0xaa,0x6a,0xea
byte 0x1a,0x9a,0x5a,0xda,0x3a,0xba,0x7a,0xfa
byte 0x06,0x86,0x46,0xc6,0x26,0xa6,0x66,0xe6
byte 0x16,0x96,0x56,0xd6,0x36,0xb6,0x76,0xf6
byte 0x0e,0x8e,0x4e,0xce,0x2e,0xae,0x6e,0xee
byte 0x1e,0x9e,0x5e,0xde,0x3e,0xbe,0x7e,0xfe
byte 0x01,0x81,0x41,0xc1,0x21,0xa1,0x61,0xe1
byte 0x11,0x91,0x51,0xd1,0x31,0xb1,0x71,0xf1
byte 0x09,0x89,0x49,0xc9,0x29,0xa9,0x69,0xe9
byte 0x19,0x99,0x59,0xd9,0x39,0xb9,0x79,0xf9
byte 0x05,0x85,0x45,0xc5,0x25,0xa5,0x65,0xe5
byte 0x15,0x95,0x55,0xd5,0x35,0xb5,0x75,0xf5
byte 0x0d,0x8d,0x4d,0xcd,0x2d,0xad,0x6d,0xed
byte 0x1d,0x9d,0x5d,0xdd,0x3d,0xbd,0x7d,0xfd
byte 0x03,0x83,0x43,0xc3,0x23,0xa3,0x63,0xe3
byte 0x13,0x93,0x53,0xd3,0x33,0xb3,0x73,0xf3
byte 0x0b,0x8b,0x4b,0xcb,0x2b,0xab,0x6b,0xeb
byte 0x1b,0x9b,0x5b,0xdb,0x3b,0xbb,0x7b,0xfb
byte 0x07,0x87,0x47,0xc7,0x27,0xa7,0x67,0xe7
byte 0x17,0x97,0x57,0xd7,0x37,0xb7,0x77,0xf7
byte 0x0f,0x8f,0x4f,0xcf,0x2f,0xaf,0x6f,0xef
byte 0x1f,0x9f,0x5f,0xdf,0x3f,0xbf,0x7f,0xff
global fmovm_calc_ea
###############################################
###############################################
fmovm_calc_ea:
mov.l %d0,%a0 # move # bytes to a0
mov.w EXC_OPWORD(%a6),%d0 # fetch opcode word
mov.w %d0,%d1 # make a copy
andi.w &0x3f,%d0 # extract mode field
andi.l &0x7,%d1 # extract reg field
mov.w (tbl_fea_mode.b,%pc,%d0.w*2),%d0 # fetch jmp distance
jmp (tbl_fea_mode.b,%pc,%d0.w*1) # jmp to correct ea mode
swbeg &64
tbl_fea_mode:
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short faddr_ind_a0 - tbl_fea_mode
short faddr_ind_a1 - tbl_fea_mode
short faddr_ind_a2 - tbl_fea_mode
short faddr_ind_a3 - tbl_fea_mode
short faddr_ind_a4 - tbl_fea_mode
short faddr_ind_a5 - tbl_fea_mode
short faddr_ind_a6 - tbl_fea_mode
short faddr_ind_a7 - tbl_fea_mode
short faddr_ind_p_a0 - tbl_fea_mode
short faddr_ind_p_a1 - tbl_fea_mode
short faddr_ind_p_a2 - tbl_fea_mode
short faddr_ind_p_a3 - tbl_fea_mode
short faddr_ind_p_a4 - tbl_fea_mode
short faddr_ind_p_a5 - tbl_fea_mode
short faddr_ind_p_a6 - tbl_fea_mode
short faddr_ind_p_a7 - tbl_fea_mode
short faddr_ind_m_a0 - tbl_fea_mode
short faddr_ind_m_a1 - tbl_fea_mode
short faddr_ind_m_a2 - tbl_fea_mode
short faddr_ind_m_a3 - tbl_fea_mode
short faddr_ind_m_a4 - tbl_fea_mode
short faddr_ind_m_a5 - tbl_fea_mode
short faddr_ind_m_a6 - tbl_fea_mode
short faddr_ind_m_a7 - tbl_fea_mode
short faddr_ind_disp_a0 - tbl_fea_mode
short faddr_ind_disp_a1 - tbl_fea_mode
short faddr_ind_disp_a2 - tbl_fea_mode
short faddr_ind_disp_a3 - tbl_fea_mode
short faddr_ind_disp_a4 - tbl_fea_mode
short faddr_ind_disp_a5 - tbl_fea_mode
short faddr_ind_disp_a6 - tbl_fea_mode
short faddr_ind_disp_a7 - tbl_fea_mode
short faddr_ind_ext - tbl_fea_mode
short faddr_ind_ext - tbl_fea_mode
short faddr_ind_ext - tbl_fea_mode
short faddr_ind_ext - tbl_fea_mode
short faddr_ind_ext - tbl_fea_mode
short faddr_ind_ext - tbl_fea_mode
short faddr_ind_ext - tbl_fea_mode
short faddr_ind_ext - tbl_fea_mode
short fabs_short - tbl_fea_mode
short fabs_long - tbl_fea_mode
short fpc_ind - tbl_fea_mode
short fpc_ind_ext - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
short tbl_fea_mode - tbl_fea_mode
###################################
###################################
faddr_ind_a0:
mov.l EXC_DREGS+0x8(%a6),%a0 # Get current a0
rts
faddr_ind_a1:
mov.l EXC_DREGS+0xc(%a6),%a0 # Get current a1
rts
faddr_ind_a2:
mov.l %a2,%a0 # Get current a2
rts
faddr_ind_a3:
mov.l %a3,%a0 # Get current a3
rts
faddr_ind_a4:
mov.l %a4,%a0 # Get current a4
rts
faddr_ind_a5:
mov.l %a5,%a0 # Get current a5
rts
faddr_ind_a6:
mov.l (%a6),%a0 # Get current a6
rts
faddr_ind_a7:
mov.l EXC_A7(%a6),%a0 # Get current a7
rts
#####################################################
#####################################################
faddr_ind_p_a0:
mov.l EXC_DREGS+0x8(%a6),%d0 # Get current a0
mov.l %d0,%d1
add.l %a0,%d1 # Increment
mov.l %d1,EXC_DREGS+0x8(%a6) # Save incr value
mov.l %d0,%a0
rts
faddr_ind_p_a1:
mov.l EXC_DREGS+0xc(%a6),%d0 # Get current a1
mov.l %d0,%d1
add.l %a0,%d1 # Increment
mov.l %d1,EXC_DREGS+0xc(%a6) # Save incr value
mov.l %d0,%a0
rts
faddr_ind_p_a2:
mov.l %a2,%d0 # Get current a2
mov.l %d0,%d1
add.l %a0,%d1 # Increment
mov.l %d1,%a2 # Save incr value
mov.l %d0,%a0
rts
faddr_ind_p_a3:
mov.l %a3,%d0 # Get current a3
mov.l %d0,%d1
add.l %a0,%d1 # Increment
mov.l %d1,%a3 # Save incr value
mov.l %d0,%a0
rts
faddr_ind_p_a4:
mov.l %a4,%d0 # Get current a4
mov.l %d0,%d1
add.l %a0,%d1 # Increment
mov.l %d1,%a4 # Save incr value
mov.l %d0,%a0
rts
faddr_ind_p_a5:
mov.l %a5,%d0 # Get current a5
mov.l %d0,%d1
add.l %a0,%d1 # Increment
mov.l %d1,%a5 # Save incr value
mov.l %d0,%a0
rts
faddr_ind_p_a6:
mov.l (%a6),%d0 # Get current a6
mov.l %d0,%d1
add.l %a0,%d1 # Increment
mov.l %d1,(%a6) # Save incr value
mov.l %d0,%a0
rts
faddr_ind_p_a7:
mov.b &mia7_flg,SPCOND_FLG(%a6) # set "special case" flag
mov.l EXC_A7(%a6),%d0 # Get current a7
mov.l %d0,%d1
add.l %a0,%d1 # Increment
mov.l %d1,EXC_A7(%a6) # Save incr value
mov.l %d0,%a0
rts
####################################################
####################################################
faddr_ind_m_a0:
mov.l EXC_DREGS+0x8(%a6),%d0 # Get current a0
sub.l %a0,%d0 # Decrement
mov.l %d0,EXC_DREGS+0x8(%a6) # Save decr value
mov.l %d0,%a0
rts
faddr_ind_m_a1:
mov.l EXC_DREGS+0xc(%a6),%d0 # Get current a1
sub.l %a0,%d0 # Decrement
mov.l %d0,EXC_DREGS+0xc(%a6) # Save decr value
mov.l %d0,%a0
rts
faddr_ind_m_a2:
mov.l %a2,%d0 # Get current a2
sub.l %a0,%d0 # Decrement
mov.l %d0,%a2 # Save decr value
mov.l %d0,%a0
rts
faddr_ind_m_a3:
mov.l %a3,%d0 # Get current a3
sub.l %a0,%d0 # Decrement
mov.l %d0,%a3 # Save decr value
mov.l %d0,%a0
rts
faddr_ind_m_a4:
mov.l %a4,%d0 # Get current a4
sub.l %a0,%d0 # Decrement
mov.l %d0,%a4 # Save decr value
mov.l %d0,%a0
rts
faddr_ind_m_a5:
mov.l %a5,%d0 # Get current a5
sub.l %a0,%d0 # Decrement
mov.l %d0,%a5 # Save decr value
mov.l %d0,%a0
rts
faddr_ind_m_a6:
mov.l (%a6),%d0 # Get current a6
sub.l %a0,%d0 # Decrement
mov.l %d0,(%a6) # Save decr value
mov.l %d0,%a0
rts
faddr_ind_m_a7:
mov.b &mda7_flg,SPCOND_FLG(%a6) # set "special case" flag
mov.l EXC_A7(%a6),%d0 # Get current a7
sub.l %a0,%d0 # Decrement
mov.l %d0,EXC_A7(%a6) # Save decr value
mov.l %d0,%a0
rts
########################################################
########################################################
faddr_ind_disp_a0:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.w %d0,%a0 # sign extend displacement
add.l EXC_DREGS+0x8(%a6),%a0 # a0 + d16
rts
faddr_ind_disp_a1:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.w %d0,%a0 # sign extend displacement
add.l EXC_DREGS+0xc(%a6),%a0 # a1 + d16
rts
faddr_ind_disp_a2:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.w %d0,%a0 # sign extend displacement
add.l %a2,%a0 # a2 + d16
rts
faddr_ind_disp_a3:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.w %d0,%a0 # sign extend displacement
add.l %a3,%a0 # a3 + d16
rts
faddr_ind_disp_a4:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.w %d0,%a0 # sign extend displacement
add.l %a4,%a0 # a4 + d16
rts
faddr_ind_disp_a5:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.w %d0,%a0 # sign extend displacement
add.l %a5,%a0 # a5 + d16
rts
faddr_ind_disp_a6:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.w %d0,%a0 # sign extend displacement
add.l (%a6),%a0 # a6 + d16
rts
faddr_ind_disp_a7:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.w %d0,%a0 # sign extend displacement
add.l EXC_A7(%a6),%a0 # a7 + d16
rts
########################################################################
# " " " w/ " (base displacement): (bd, An, Xn) #
########################################################################
faddr_ind_ext:
addq.l &0x8,%d1
bsr.l fetch_dreg # fetch base areg
mov.l %d0,-(%sp)
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word # fetch extword in d0
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.l (%sp)+,%a0
btst &0x8,%d0
bne.w fcalc_mem_ind
mov.l %d0,L_SCR1(%a6) # hold opword
mov.l %d0,%d1
rol.w &0x4,%d1
andi.w &0xf,%d1 # extract index regno
bsr.l fetch_dreg # fetch index
mov.l %d2,-(%sp) # save d2
mov.l L_SCR1(%a6),%d2 # fetch opword
btst &0xb,%d2 # is it word or long?
bne.b faii8_long
ext.l %d0 # sign extend word index
faii8_long:
mov.l %d2,%d1
rol.w &0x7,%d1
andi.l &0x3,%d1 # extract scale value
lsl.l %d1,%d0 # shift index by scale
extb.l %d2 # sign extend displacement
add.l %d2,%d0 # index + disp
add.l %d0,%a0 # An + (index + disp)
mov.l (%sp)+,%d2 # restore old d2
rts
###########################
###########################
fabs_short:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word # fetch short address
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.w %d0,%a0 # return <ea> in a0
rts
##########################
##########################
fabs_long:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch long address
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.l %d0,%a0 # return <ea> in a0
rts
#######################################################
#######################################################
fpc_ind:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word # fetch word displacement
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.w %d0,%a0 # sign extend displacement
add.l EXC_EXTWPTR(%a6),%a0 # pc + d16
subq.l &0x2,%a0 # adjust <ea>
rts
##########################################################
# " " w/ " (base displacement): (bd, PC, An) #
##########################################################
fpc_ind_ext:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word # fetch ext word
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.l EXC_EXTWPTR(%a6),%a0 # put base in a0
subq.l &0x2,%a0 # adjust base
btst &0x8,%d0 # is disp only 8 bits?
bne.w fcalc_mem_ind # calc memory indirect
mov.l %d0,L_SCR1(%a6) # store opword
mov.l %d0,%d1 # make extword copy
rol.w &0x4,%d1 # rotate reg num into place
andi.w &0xf,%d1 # extract register number
bsr.l fetch_dreg # fetch index
mov.l %d2,-(%sp) # save d2
mov.l L_SCR1(%a6),%d2 # fetch opword
btst &0xb,%d2 # is index word or long?
bne.b fpii8_long # long
ext.l %d0 # sign extend word index
fpii8_long:
mov.l %d2,%d1
rol.w &0x7,%d1 # rotate scale value into place
andi.l &0x3,%d1 # extract scale value
lsl.l %d1,%d0 # shift index by scale
extb.l %d2 # sign extend displacement
add.l %d2,%d0 # disp + index
add.l %d0,%a0 # An + (index + disp)
mov.l (%sp)+,%d2 # restore temp register
rts
fcalc_mem_ind:
btst &0x6,%d0 # is the index suppressed?
beq.b fcalc_index
movm.l &0x3c00,-(%sp) # save d2-d5
mov.l %d0,%d5 # put extword in d5
mov.l %a0,%d3 # put base in d3
clr.l %d2 # yes, so index = 0
bra.b fbase_supp_ck
fcalc_index:
mov.l %d0,L_SCR1(%a6) # save d0 (opword)
bfextu %d0{&16:&4},%d1 # fetch dreg index
bsr.l fetch_dreg
movm.l &0x3c00,-(%sp) # save d2-d5
mov.l %d0,%d2 # put index in d2
mov.l L_SCR1(%a6),%d5
mov.l %a0,%d3
btst &0xb,%d5 # is index word or long?
bne.b fno_ext
ext.l %d2
fno_ext:
bfextu %d5{&21:&2},%d0
lsl.l %d0,%d2
fbase_supp_ck:
btst &0x7,%d5 # is the bd suppressed?
beq.b fno_base_sup
clr.l %d3
fno_base_sup:
bfextu %d5{&26:&2},%d0 # get bd size
cmpi.b %d0,&0x2
blt.b fno_bd
beq.b fget_word_bd
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long
tst.l %d1 # did ifetch fail?
bne.l fcea_iacc # yes
bra.b fchk_ind
fget_word_bd:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word
tst.l %d1 # did ifetch fail?
bne.l fcea_iacc # yes
ext.l %d0 # sign extend bd
fchk_ind:
add.l %d0,%d3 # base += bd
fno_bd:
bfextu %d5{&30:&2},%d0 # is od suppressed?
beq.w faii_bd
cmpi.b %d0,&0x2
blt.b fnull_od
beq.b fword_od
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long
tst.l %d1 # did ifetch fail?
bne.l fcea_iacc # yes
bra.b fadd_them
fword_od:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x2,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_word
tst.l %d1 # did ifetch fail?
bne.l fcea_iacc # yes
ext.l %d0 # sign extend od
bra.b fadd_them
fnull_od:
clr.l %d0
fadd_them:
mov.l %d0,%d4
btst &0x2,%d5 # pre or post indexing?
beq.b fpre_indexed
mov.l %d3,%a0
bsr.l _dmem_read_long
tst.l %d1 # did dfetch fail?
bne.w fcea_err # yes
add.l %d2,%d0 # <ea> += index
add.l %d4,%d0 # <ea> += od
bra.b fdone_ea
fpre_indexed:
add.l %d2,%d3 # preindexing
mov.l %d3,%a0
bsr.l _dmem_read_long
tst.l %d1 # did dfetch fail?
bne.w fcea_err # yes
add.l %d4,%d0 # ea += od
bra.b fdone_ea
faii_bd:
add.l %d2,%d3 # ea = (base + bd) + index
mov.l %d3,%d0
fdone_ea:
mov.l %d0,%a0
movm.l (%sp)+,&0x003c # restore d2-d5
rts
#########################################################
fcea_err:
mov.l %d3,%a0
movm.l (%sp)+,&0x003c # restore d2-d5
mov.w &0x0101,%d0
bra.l iea_dacc
fcea_iacc:
movm.l (%sp)+,&0x003c # restore d2-d5
bra.l iea_iacc
fmovm_out_err:
bsr.l restore
mov.w &0x00e1,%d0
bra.b fmovm_err
fmovm_in_err:
bsr.l restore
mov.w &0x0161,%d0
fmovm_err:
mov.l L_SCR1(%a6),%a0
bra.l iea_dacc
#########################################################################
# #
# #
# #
# #
# #
# #
# #
# 1111 0010 00 111100 100$ $$00 0000 0000 #
# #
# $$$ (100): FPCR #
# (010): FPSR #
# (001): FPIAR #
# (000): FPIAR #
# #
#########################################################################
global fmovm_ctrl
fmovm_ctrl:
mov.b EXC_EXTWORD(%a6),%d0 # fetch reg select bits
cmpi.b %d0,&0x9c # fpcr & fpsr & fpiar ?
beq.w fctrl_in_7 # yes
cmpi.b %d0,&0x98 # fpcr & fpsr ?
beq.w fctrl_in_6 # yes
cmpi.b %d0,&0x94 # fpcr & fpiar ?
beq.b fctrl_in_5 # yes
fctrl_in_3:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch FPSR from mem
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.l %d0,USER_FPSR(%a6) # store new FPSR to stack
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch FPIAR from mem
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.l %d0,USER_FPIAR(%a6) # store new FPIAR to stack
rts
fctrl_in_5:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch FPCR from mem
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.l %d0,USER_FPCR(%a6) # store new FPCR to stack
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch FPIAR from mem
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.l %d0,USER_FPIAR(%a6) # store new FPIAR to stack
rts
fctrl_in_6:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch FPCR from mem
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.l %d0,USER_FPCR(%a6) # store new FPCR to mem
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch FPSR from mem
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.l %d0,USER_FPSR(%a6) # store new FPSR to mem
rts
fctrl_in_7:
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch FPCR from mem
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.l %d0,USER_FPCR(%a6) # store new FPCR to mem
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch FPSR from mem
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.l %d0,USER_FPSR(%a6) # store new FPSR to mem
mov.l EXC_EXTWPTR(%a6),%a0 # fetch instruction addr
addq.l &0x4,EXC_EXTWPTR(%a6) # incr instruction ptr
bsr.l _imem_read_long # fetch FPIAR from mem
tst.l %d1 # did ifetch fail?
bne.l iea_iacc # yes
mov.l %d0,USER_FPIAR(%a6) # store new FPIAR to mem
rts
##########################################################################
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global addsub_scaler2
addsub_scaler2:
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l DST_HI(%a1),FP_SCR1_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
mov.l DST_LO(%a1),FP_SCR1_LO(%a6)
mov.w SRC_EX(%a0),%d0
mov.w DST_EX(%a1),%d1
mov.w %d0,FP_SCR0_EX(%a6)
mov.w %d1,FP_SCR1_EX(%a6)
andi.w &0x7fff,%d0
andi.w &0x7fff,%d1
mov.w %d0,L_SCR1(%a6) # store src exponent
mov.w %d1,2+L_SCR1(%a6) # store dst exponent
cmp.w %d0, %d1 # is src exp >= dst exp?
bge.l src_exp_ge2
dst_exp_gt2:
bsr.l scale_to_zero_dst
mov.l %d0,-(%sp) # save scale factor
cmpi.b STAG(%a6),&DENORM # is dst denormalized?
bne.b cmpexp12
lea FP_SCR0(%a6),%a0
bsr.l norm # normalize the denorm; result is new exp
neg.w %d0 # new exp = -(shft val)
mov.w %d0,L_SCR1(%a6) # inset new exp
cmpexp12:
mov.w 2+L_SCR1(%a6),%d0
subi.w &mantissalen+2,%d0 # subtract mantissalen+2 from larger exp
cmp.w %d0,L_SCR1(%a6) # is difference >= len(mantissa)+2?
bge.b quick_scale12
mov.w L_SCR1(%a6),%d0
add.w 0x2(%sp),%d0 # scale src exponent by scale factor
mov.w FP_SCR0_EX(%a6),%d1
and.w &0x8000,%d1
or.w %d1,%d0 # concat {sgn,new exp}
mov.w %d0,FP_SCR0_EX(%a6) # insert new dst exponent
mov.l (%sp)+,%d0 # return SCALE factor
rts
quick_scale12:
andi.w &0x8000,FP_SCR0_EX(%a6) # zero src exponent
bset &0x0,1+FP_SCR0_EX(%a6) # set exp = 1
mov.l (%sp)+,%d0 # return SCALE factor
rts
src_exp_ge2:
bsr.l scale_to_zero_src
mov.l %d0,-(%sp) # save scale factor
cmpi.b DTAG(%a6),&DENORM # is dst denormalized?
bne.b cmpexp22
lea FP_SCR1(%a6),%a0
bsr.l norm # normalize the denorm; result is new exp
neg.w %d0 # new exp = -(shft val)
mov.w %d0,2+L_SCR1(%a6) # inset new exp
cmpexp22:
mov.w L_SCR1(%a6),%d0
subi.w &mantissalen+2,%d0 # subtract mantissalen+2 from larger exp
cmp.w %d0,2+L_SCR1(%a6) # is difference >= len(mantissa)+2?
bge.b quick_scale22
mov.w 2+L_SCR1(%a6),%d0
add.w 0x2(%sp),%d0 # scale dst exponent by scale factor
mov.w FP_SCR1_EX(%a6),%d1
andi.w &0x8000,%d1
or.w %d1,%d0 # concat {sgn,new exp}
mov.w %d0,FP_SCR1_EX(%a6) # insert new dst exponent
mov.l (%sp)+,%d0 # return SCALE factor
rts
quick_scale22:
andi.w &0x8000,FP_SCR1_EX(%a6) # zero dst exponent
bset &0x0,1+FP_SCR1_EX(%a6) # set exp = 1
mov.l (%sp)+,%d0 # return SCALE factor
rts
##########################################################################
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global scale_to_zero_src
scale_to_zero_src:
mov.w FP_SCR0_EX(%a6),%d1 # extract operand's {sgn,exp}
mov.w %d1,%d0 # make a copy
andi.l &0x7fff,%d1 # extract operand's exponent
andi.w &0x8000,%d0 # extract operand's sgn
or.w &0x3fff,%d0 # insert new operand's exponent(=0)
mov.w %d0,FP_SCR0_EX(%a6) # insert biased exponent
cmpi.b STAG(%a6),&DENORM # is operand normalized?
beq.b stzs_denorm # normalize the DENORM
stzs_norm:
mov.l &0x3fff,%d0
sub.l %d1,%d0 # scale = BIAS + (-exp)
rts
stzs_denorm:
lea FP_SCR0(%a6),%a0 # pass ptr to src op
bsr.l norm # normalize denorm
neg.l %d0 # new exponent = -(shft val)
mov.l %d0,%d1 # prepare for op_norm call
bra.b stzs_norm # finish scaling
###
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global scale_sqrt
scale_sqrt:
cmpi.b STAG(%a6),&DENORM # is operand normalized?
beq.b ss_denorm # normalize the DENORM
mov.w FP_SCR0_EX(%a6),%d1 # extract operand's {sgn,exp}
andi.l &0x7fff,%d1 # extract operand's exponent
andi.w &0x8000,FP_SCR0_EX(%a6) # extract operand's sgn
btst &0x0,%d1 # is exp even or odd?
beq.b ss_norm_even
ori.w &0x3fff,FP_SCR0_EX(%a6) # insert new operand's exponent(=0)
mov.l &0x3fff,%d0
sub.l %d1,%d0 # scale = BIAS + (-exp)
asr.l &0x1,%d0 # divide scale factor by 2
rts
ss_norm_even:
ori.w &0x3ffe,FP_SCR0_EX(%a6) # insert new operand's exponent(=0)
mov.l &0x3ffe,%d0
sub.l %d1,%d0 # scale = BIAS + (-exp)
asr.l &0x1,%d0 # divide scale factor by 2
rts
ss_denorm:
lea FP_SCR0(%a6),%a0 # pass ptr to src op
bsr.l norm # normalize denorm
btst &0x0,%d0 # is exp even or odd?
beq.b ss_denorm_even
ori.w &0x3fff,FP_SCR0_EX(%a6) # insert new operand's exponent(=0)
add.l &0x3fff,%d0
asr.l &0x1,%d0 # divide scale factor by 2
rts
ss_denorm_even:
ori.w &0x3ffe,FP_SCR0_EX(%a6) # insert new operand's exponent(=0)
add.l &0x3ffe,%d0
asr.l &0x1,%d0 # divide scale factor by 2
rts
###
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global scale_to_zero_dst
scale_to_zero_dst:
mov.w FP_SCR1_EX(%a6),%d1 # extract operand's {sgn,exp}
mov.w %d1,%d0 # make a copy
andi.l &0x7fff,%d1 # extract operand's exponent
andi.w &0x8000,%d0 # extract operand's sgn
or.w &0x3fff,%d0 # insert new operand's exponent(=0)
mov.w %d0,FP_SCR1_EX(%a6) # insert biased exponent
cmpi.b DTAG(%a6),&DENORM # is operand normalized?
beq.b stzd_denorm # normalize the DENORM
stzd_norm:
mov.l &0x3fff,%d0
sub.l %d1,%d0 # scale = BIAS + (-exp)
rts
stzd_denorm:
lea FP_SCR1(%a6),%a0 # pass ptr to dst op
bsr.l norm # normalize denorm
neg.l %d0 # new exponent = -(shft val)
mov.l %d0,%d1 # prepare for op_norm call
bra.b stzd_norm # finish scaling
##########################################################################
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global res_qnan
global res_snan
res_qnan:
res_snan:
cmp.b DTAG(%a6), &SNAN # is the dst an SNAN?
beq.b dst_snan2
cmp.b DTAG(%a6), &QNAN # is the dst a QNAN?
beq.b dst_qnan2
src_nan:
cmp.b STAG(%a6), &QNAN
beq.b src_qnan2
global res_snan_1op
res_snan_1op:
src_snan2:
bset &0x6, FP_SRC_HI(%a6) # set SNAN bit
or.l &nan_mask+aiop_mask+snan_mask, USER_FPSR(%a6)
lea FP_SRC(%a6), %a0
bra.b nan_comp
global res_qnan_1op
res_qnan_1op:
src_qnan2:
or.l &nan_mask, USER_FPSR(%a6)
lea FP_SRC(%a6), %a0
bra.b nan_comp
dst_snan2:
or.l &nan_mask+aiop_mask+snan_mask, USER_FPSR(%a6)
bset &0x6, FP_DST_HI(%a6) # set SNAN bit
lea FP_DST(%a6), %a0
bra.b nan_comp
dst_qnan2:
lea FP_DST(%a6), %a0
cmp.b STAG(%a6), &SNAN
bne nan_done
or.l &aiop_mask+snan_mask, USER_FPSR(%a6)
nan_done:
or.l &nan_mask, USER_FPSR(%a6)
nan_comp:
btst &0x7, FTEMP_EX(%a0) # is NAN neg?
beq.b nan_not_neg
or.l &neg_mask, USER_FPSR(%a6)
nan_not_neg:
fmovm.x (%a0), &0x80
rts
#########################################################################
# #
# #
# #
# #
# #
# #
#########################################################################
global res_operr
res_operr:
or.l &nan_mask+operr_mask+aiop_mask, USER_FPSR(%a6)
fmovm.x nan_return(%pc), &0x80
rts
nan_return:
long 0x7fff0000, 0xffffffff, 0xffffffff
#########################################################################
# #
# #
# (in the internal extended format) #
# #
# #
# (in the internal extended format) #
# #
# #
# (1) _denorm() is called by the underflow routines #
# (2) _denorm() does NOT affect the status register #
# #
#########################################################################
#
#
tbl_thresh:
short 0x0
short sgl_thresh
short dbl_thresh
global _denorm
_denorm:
#
#
lsr.b &0x2, %d0 # shift prec to lo bits
mov.w (tbl_thresh.b,%pc,%d0.w*2), %d1 # load prec threshold
mov.w %d1, %d0 # copy d1 into d0
sub.w FTEMP_EX(%a0), %d0 # diff = threshold - exp
cmpi.w %d0, &66 # is diff > 65? (mant + g,r bits)
bpl.b denorm_set_stky # yes; just calc sticky
clr.l %d0 # clear g,r,s
btst &inex2_bit, FPSR_EXCEPT(%a6) # yes; was INEX2 set?
beq.b denorm_call # no; don't change anything
bset &29, %d0 # yes; set sticky bit
denorm_call:
bsr.l dnrm_lp # denormalize the number
rts
#
#
denorm_set_stky:
mov.l &0x20000000, %d0 # set sticky bit in return value
mov.w %d1, FTEMP_EX(%a0) # load exp with threshold
clr.l FTEMP_HI(%a0) # set d1 = 0 (ms mantissa)
clr.l FTEMP_LO(%a0) # set d2 = 0 (ms mantissa)
rts
# #
# #
# %a0 : points to the operand to be denormalized #
# %d0{31:29} : initial guard,round,sticky #
# %d1{15:0} : denormalization threshold #
# %a0 : points to the denormalized operand #
# %d0{31:29} : final guard,round,sticky #
# #
# *** Local Equates *** #
set GRS, L_SCR2 # g,r,s temp storage
set FTEMP_LO2, L_SCR1 # FTEMP_LO copy
global dnrm_lp
dnrm_lp:
#
#
mov.l FTEMP_LO(%a0), FTEMP_LO2(%a6) # make FTEMP_LO copy
mov.l %d0, GRS(%a6) # place g,r,s after it
#
#
mov.l %d1, %d0 # copy the denorm threshold
sub.w FTEMP_EX(%a0), %d1 # d1 = threshold - uns exponent
ble.b dnrm_no_lp # d1 <= 0
cmpi.w %d1, &0x20 # is ( 0 <= d1 < 32) ?
blt.b case_1 # yes
cmpi.w %d1, &0x40 # is (32 <= d1 < 64) ?
blt.b case_2 # yes
bra.w case_3 # (d1 >= 64)
#
#
dnrm_no_lp:
mov.l GRS(%a6), %d0 # restore original g,r,s
rts
#
#
# %d0 = denorm threshold
# %d1 = "n" = amt to shift
#
# ---------------------------------------------------------
# | FTEMP_HI | FTEMP_LO |grs000.........000|
# ---------------------------------------------------------
# <-(32 - n)-><-(n)-><-(32 - n)-><-(n)-><-(32 - n)-><-(n)->
# \ \ \ \
# \ \ \ \
# \ \ \ \
# \ \ \ \
# \ \ \ \
# \ \ \ \
# \ \ \ \
# \ \ \ \
# <-(n)-><-(32 - n)-><------(32)-------><------(32)------->
# ---------------------------------------------------------
# |0.....0| NEW_HI | NEW_FTEMP_LO |grs |
# ---------------------------------------------------------
#
case_1:
mov.l %d2, -(%sp) # create temp storage
mov.w %d0, FTEMP_EX(%a0) # exponent = denorm threshold
mov.l &32, %d0
sub.w %d1, %d0 # %d0 = 32 - %d1
cmpi.w %d1, &29 # is shft amt >= 29
blt.b case1_extract # no; no fix needed
mov.b GRS(%a6), %d2
or.b %d2, 3+FTEMP_LO2(%a6)
case1_extract:
bfextu FTEMP_HI(%a0){&0:%d0}, %d2 # %d2 = new FTEMP_HI
bfextu FTEMP_HI(%a0){%d0:&32}, %d1 # %d1 = new FTEMP_LO
bfextu FTEMP_LO2(%a6){%d0:&32}, %d0 # %d0 = new G,R,S
mov.l %d2, FTEMP_HI(%a0) # store new FTEMP_HI
mov.l %d1, FTEMP_LO(%a0) # store new FTEMP_LO
bftst %d0{&2:&30} # were bits shifted off?
beq.b case1_sticky_clear # no; go finish
bset &rnd_stky_bit, %d0 # yes; set sticky bit
case1_sticky_clear:
and.l &0xe0000000, %d0 # clear all but G,R,S
mov.l (%sp)+, %d2 # restore temp register
rts
#
#
# %d0 = denorm threshold
# %d1 = "n" = amt to shift
#
# ---------------------------------------------------------
# | FTEMP_HI | FTEMP_LO |grs000.........000|
# ---------------------------------------------------------
# <-(32 - n)-><-(n)-><-(32 - n)-><-(n)-><-(32 - n)-><-(n)->
# \ \ \
# \ \ \
# \ \ -------------------
# \ -------------------- \
# ------------------- \ \
# \ \ \
# \ \ \
# \ \ \
# <-------(32)------><-(n)-><-(32 - n)-><------(32)------->
# ---------------------------------------------------------
# |0...............0|0....0| NEW_LO |grs |
# ---------------------------------------------------------
#
case_2:
mov.l %d2, -(%sp) # create temp storage
mov.w %d0, FTEMP_EX(%a0) # exponent = denorm threshold
subi.w &0x20, %d1 # %d1 now between 0 and 32
mov.l &0x20, %d0
sub.w %d1, %d0 # %d0 = 32 - %d1
mov.b GRS(%a6), %d2
or.b %d2, 3+FTEMP_LO2(%a6)
bfextu FTEMP_HI(%a0){&0:%d0}, %d2 # %d2 = new FTEMP_LO
bfextu FTEMP_HI(%a0){%d0:&32}, %d1 # %d1 = new G,R,S
bftst %d1{&2:&30} # were any bits shifted off?
bne.b case2_set_sticky # yes; set sticky bit
bftst FTEMP_LO2(%a6){%d0:&31} # were any bits shifted off?
bne.b case2_set_sticky # yes; set sticky bit
mov.l %d1, %d0 # move new G,R,S to %d0
bra.b case2_end
case2_set_sticky:
mov.l %d1, %d0 # move new G,R,S to %d0
bset &rnd_stky_bit, %d0 # set sticky bit
case2_end:
clr.l FTEMP_HI(%a0) # store FTEMP_HI = 0
mov.l %d2, FTEMP_LO(%a0) # store FTEMP_LO
and.l &0xe0000000, %d0 # clear all but G,R,S
mov.l (%sp)+,%d2 # restore temp register
rts
#
#
# %d0 = denorm threshold
# %d1 = amt to shift
#
case_3:
mov.w %d0, FTEMP_EX(%a0) # insert denorm threshold
cmpi.w %d1, &65 # is shift amt > 65?
blt.b case3_64 # no; it's == 64
beq.b case3_65 # no; it's == 65
#
#
#
clr.l FTEMP_HI(%a0) # clear hi(mantissa)
clr.l FTEMP_LO(%a0) # clear lo(mantissa)
mov.l &0x20000000, %d0 # set sticky bit
rts
#
#
# ---------------------------------------------------------
# | FTEMP_HI | FTEMP_LO |grs000.........000|
# ---------------------------------------------------------
# <-------(32)------>
# \ \
# \ \
# \ \
# \ ------------------------------
# ------------------------------- \
# \ \
# \ \
# \ \
# <-------(32)------>
# ---------------------------------------------------------
# |0...............0|0................0|grs |
# ---------------------------------------------------------
#
case3_64:
mov.l FTEMP_HI(%a0), %d0 # fetch hi(mantissa)
mov.l %d0, %d1 # make a copy
and.l &0xc0000000, %d0 # extract G,R
and.l &0x3fffffff, %d1 # extract other bits
bra.b case3_complete
#
#
# ---------------------------------------------------------
# | FTEMP_HI | FTEMP_LO |grs000.........000|
# ---------------------------------------------------------
# <-------(32)------>
# \ \
# \ \
# \ \
# \ ------------------------------
# -------------------------------- \
# \ \
# \ \
# \ \
# <-------(31)----->
# ---------------------------------------------------------
# |0...............0|0................0|0rs |
# ---------------------------------------------------------
#
case3_65:
mov.l FTEMP_HI(%a0), %d0 # fetch hi(mantissa)
and.l &0x80000000, %d0 # extract R bit
lsr.l &0x1, %d0 # shift high bit into R bit
and.l &0x7fffffff, %d1 # extract other bits
case3_complete:
bne.b case3_set_sticky # yes; go set new sticky
tst.l FTEMP_LO(%a0) # were any bits shifted off?
bne.b case3_set_sticky # yes; go set new sticky
tst.b GRS(%a6) # were any bits shifted off?
bne.b case3_set_sticky # yes; go set new sticky
#
#
clr.l FTEMP_HI(%a0) # clear hi(mantissa)
clr.l FTEMP_LO(%a0) # clear lo(mantissa)
rts
#
#
case3_set_sticky:
bset &rnd_stky_bit,%d0 # set new sticky bit
clr.l FTEMP_HI(%a0) # clear hi(mantissa)
clr.l FTEMP_LO(%a0) # clear lo(mantissa)
rts
#########################################################################
# #
# #
# #
# #
# #
# #
#########################################################################
global _round
_round:
#
#
bsr.l ext_grs # extract G,R,S
tst.l %d0 # are G,R,S zero?
beq.w truncate # yes; round is complete
or.w &inx2a_mask, 2+USER_FPSR(%a6) # set inex2/ainex
#
#
mov.w (tbl_mode.b,%pc,%d1.w*2), %a1 # load jump offset
jmp (tbl_mode.b,%pc,%a1) # jmp to rnd mode handler
tbl_mode:
short rnd_near - tbl_mode
short truncate - tbl_mode # RZ always truncates
short rnd_mnus - tbl_mode
short rnd_plus - tbl_mode
#################################################################
# #
#################################################################
rnd_plus:
tst.b FTEMP_SGN(%a0) # check for sign
bmi.w truncate # if positive then truncate
mov.l &0xffffffff, %d0 # force g,r,s to be all f's
swap %d1 # set up d1 for round prec.
cmpi.b %d1, &s_mode # is prec = sgl?
beq.w add_sgl # yes
bgt.w add_dbl # no; it's dbl
bra.w add_ext # no; it's ext
#################################################################
# #
#################################################################
rnd_mnus:
tst.b FTEMP_SGN(%a0) # check for sign
bpl.w truncate # if negative then truncate
mov.l &0xffffffff, %d0 # force g,r,s to be all f's
swap %d1 # set up d1 for round prec.
cmpi.b %d1, &s_mode # is prec = sgl?
beq.w add_sgl # yes
bgt.w add_dbl # no; it's dbl
bra.w add_ext # no; it's ext
#################################################################
# #
#################################################################
rnd_near:
asl.l &0x1, %d0 # shift g-bit to c-bit
bcc.w truncate # if (g=1) then
swap %d1 # set up d1 for round prec.
cmpi.b %d1, &s_mode # is prec = sgl?
beq.w add_sgl # yes
bgt.w add_dbl # no; it's dbl
bra.w add_ext # no; it's ext
# *** LOCAL EQUATES ***
set ad_1_sgl, 0x00000100 # constant to add 1 to l-bit in sgl prec
set ad_1_dbl, 0x00000800 # constant to add 1 to l-bit in dbl prec
#########################
#########################
add_sgl:
add.l &ad_1_sgl, FTEMP_HI(%a0)
bcc.b scc_clr # no mantissa overflow
roxr.w FTEMP_HI(%a0) # shift v-bit back in
roxr.w FTEMP_HI+2(%a0) # shift v-bit back in
add.w &0x1, FTEMP_EX(%a0) # and incr exponent
scc_clr:
tst.l %d0 # test for rs = 0
bne.b sgl_done
and.w &0xfe00, FTEMP_HI+2(%a0) # clear the l-bit
sgl_done:
and.l &0xffffff00, FTEMP_HI(%a0) # truncate bits beyond sgl limit
clr.l FTEMP_LO(%a0) # clear d2
rts
#########################
#########################
add_ext:
addq.l &1,FTEMP_LO(%a0) # add 1 to l-bit
bcc.b xcc_clr # test for carry out
addq.l &1,FTEMP_HI(%a0) # propagate carry
bcc.b xcc_clr
roxr.w FTEMP_HI(%a0) # mant is 0 so restore v-bit
roxr.w FTEMP_HI+2(%a0) # mant is 0 so restore v-bit
roxr.w FTEMP_LO(%a0)
roxr.w FTEMP_LO+2(%a0)
add.w &0x1,FTEMP_EX(%a0) # and inc exp
xcc_clr:
tst.l %d0 # test rs = 0
bne.b add_ext_done
and.b &0xfe,FTEMP_LO+3(%a0) # clear the l bit
add_ext_done:
rts
#########################
#########################
add_dbl:
add.l &ad_1_dbl, FTEMP_LO(%a0) # add 1 to lsb
bcc.b dcc_clr # no carry
addq.l &0x1, FTEMP_HI(%a0) # propagate carry
bcc.b dcc_clr # no carry
roxr.w FTEMP_HI(%a0) # mant is 0 so restore v-bit
roxr.w FTEMP_HI+2(%a0) # mant is 0 so restore v-bit
roxr.w FTEMP_LO(%a0)
roxr.w FTEMP_LO+2(%a0)
addq.w &0x1, FTEMP_EX(%a0) # incr exponent
dcc_clr:
tst.l %d0 # test for rs = 0
bne.b dbl_done
and.w &0xf000, FTEMP_LO+2(%a0) # clear the l-bit
dbl_done:
and.l &0xfffff800,FTEMP_LO(%a0) # truncate bits beyond dbl limit
rts
###########################
###########################
truncate:
swap %d1 # select rnd prec
cmpi.b %d1, &s_mode # is prec sgl?
beq.w sgl_done # yes
bgt.b dbl_done # no; it's dbl
rts # no; it's ext
#
#
#
#
#
ext_grs:
swap %d1 # have d1.w point to round precision
tst.b %d1 # is rnd prec = extended?
bne.b ext_grs_not_ext # no; go handle sgl or dbl
#
# %d0 actually already hold g,r,s since _round() had it before calling
#
ext_grs_ext:
swap %d1 # yes; return to correct positions
rts
ext_grs_not_ext:
movm.l &0x3000, -(%sp) # make some temp registers {d2/d3}
cmpi.b %d1, &s_mode # is rnd prec = sgl?
bne.b ext_grs_dbl # no; go handle dbl
#
# 96 64 40 32 0
# -----------------------------------------------------
# | EXP |XXXXXXX| |xx | |grs|
# -----------------------------------------------------
# <--(24)--->nn\ /
#
ext_grs_sgl:
bfextu FTEMP_HI(%a0){&24:&2}, %d3 # sgl prec. g-r are 2 bits right
mov.l &30, %d2 # of the sgl prec. limits
lsl.l %d2, %d3 # shift g-r bits to MSB of d3
mov.l FTEMP_HI(%a0), %d2 # get word 2 for s-bit test
and.l &0x0000003f, %d2 # s bit is the or of all other
bne.b ext_grs_st_stky # bits to the right of g-r
tst.l FTEMP_LO(%a0) # test lower mantissa
bne.b ext_grs_st_stky # if any are set, set sticky
tst.l %d0 # test original g,r,s
bne.b ext_grs_st_stky # if any are set, set sticky
bra.b ext_grs_end_sd # if words 3 and 4 are clr, exit
#
# 96 64 32 11 0
# -----------------------------------------------------
# | EXP |XXXXXXX| | |xx |grs|
# -----------------------------------------------------
#
ext_grs_dbl:
bfextu FTEMP_LO(%a0){&21:&2}, %d3 # dbl-prec. g-r are 2 bits right
mov.l &30, %d2 # of the dbl prec. limits
lsl.l %d2, %d3 # shift g-r bits to the MSB of d3
mov.l FTEMP_LO(%a0), %d2 # get lower mantissa for s-bit test
and.l &0x000001ff, %d2 # s bit is the or-ing of all
bne.b ext_grs_st_stky # other bits to the right of g-r
tst.l %d0 # test word original g,r,s
bne.b ext_grs_st_stky # if any are set, set sticky
bra.b ext_grs_end_sd # if clear, exit
ext_grs_st_stky:
bset &rnd_stky_bit, %d3 # set sticky bit
ext_grs_end_sd:
mov.l %d3, %d0 # return grs to d0
movm.l (%sp)+, &0xc # restore scratch registers {d2/d3}
swap %d1 # restore d1 to original
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global norm
norm:
mov.l %d2, -(%sp) # create some temp regs
mov.l %d3, -(%sp)
mov.l FTEMP_HI(%a0), %d0 # load hi(mantissa)
mov.l FTEMP_LO(%a0), %d1 # load lo(mantissa)
bfffo %d0{&0:&32}, %d2 # how many places to shift?
beq.b norm_lo # hi(man) is all zeroes!
norm_hi:
lsl.l %d2, %d0 # left shift hi(man)
bfextu %d1{&0:%d2}, %d3 # extract lo bits
or.l %d3, %d0 # create hi(man)
lsl.l %d2, %d1 # create lo(man)
mov.l %d0, FTEMP_HI(%a0) # store new hi(man)
mov.l %d1, FTEMP_LO(%a0) # store new lo(man)
mov.l %d2, %d0 # return shift amount
mov.l (%sp)+, %d3 # restore temp regs
mov.l (%sp)+, %d2
rts
norm_lo:
bfffo %d1{&0:&32}, %d2 # how many places to shift?
lsl.l %d2, %d1 # shift lo(man)
add.l &32, %d2 # add 32 to shft amount
mov.l %d1, FTEMP_HI(%a0) # store hi(man)
clr.l FTEMP_LO(%a0) # lo(man) is now zero
mov.l %d2, %d0 # return shift amount
mov.l (%sp)+, %d3 # restore temp regs
mov.l (%sp)+, %d2
rts
#########################################################################
# - returns corresponding optype tag #
# #
# #
# #
# #
# #
#########################################################################
global unnorm_fix
unnorm_fix:
bfffo FTEMP_HI(%a0){&0:&32}, %d0 # how many shifts are needed?
bne.b unnorm_shift # hi(man) is not all zeroes
#
#
unnorm_chk_lo:
bfffo FTEMP_LO(%a0){&0:&32}, %d0 # is operand really a zero?
beq.w unnorm_zero # yes
add.w &32, %d0 # no; fix shift distance
#
#
unnorm_shift:
clr.l %d1 # clear top word
mov.w FTEMP_EX(%a0), %d1 # extract exponent
and.w &0x7fff, %d1 # strip off sgn
cmp.w %d0, %d1 # will denorm push exp < 0?
bgt.b unnorm_nrm_zero # yes; denorm only until exp = 0
#
#
sub.w %d0, %d1 # shift exponent value
mov.w FTEMP_EX(%a0), %d0 # load old exponent
and.w &0x8000, %d0 # save old sign
or.w %d0, %d1 # {sgn,new exp}
mov.w %d1, FTEMP_EX(%a0) # insert new exponent
bsr.l norm # normalize UNNORM
mov.b &NORM, %d0 # return new optype tag
rts
#
#
unnorm_nrm_zero:
cmp.b %d1, &32 # is exp <= 32?
bgt.b unnorm_nrm_zero_lrg # no; go handle large exponent
bfextu FTEMP_HI(%a0){%d1:&32}, %d0 # extract new hi(man)
mov.l %d0, FTEMP_HI(%a0) # save new hi(man)
mov.l FTEMP_LO(%a0), %d0 # fetch old lo(man)
lsl.l %d1, %d0 # extract new lo(man)
mov.l %d0, FTEMP_LO(%a0) # save new lo(man)
and.w &0x8000, FTEMP_EX(%a0) # set exp = 0
mov.b &DENORM, %d0 # return new optype tag
rts
#
#
unnorm_nrm_zero_lrg:
sub.w &32, %d1 # adjust shft amt by 32
mov.l FTEMP_LO(%a0), %d0 # fetch old lo(man)
lsl.l %d1, %d0 # left shift lo(man)
mov.l %d0, FTEMP_HI(%a0) # store new hi(man)
clr.l FTEMP_LO(%a0) # lo(man) = 0
and.w &0x8000, FTEMP_EX(%a0) # set exp = 0
mov.b &DENORM, %d0 # return new optype tag
rts
#
#
unnorm_zero:
and.w &0x8000, FTEMP_EX(%a0) # force exponent to zero
mov.b &ZERO, %d0 # fix optype tag
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global set_tag_x
set_tag_x:
mov.w FTEMP_EX(%a0), %d0 # extract exponent
andi.w &0x7fff, %d0 # strip off sign
cmpi.w %d0, &0x7fff # is (EXP == MAX)?
beq.b inf_or_nan_x
not_inf_or_nan_x:
btst &0x7,FTEMP_HI(%a0)
beq.b not_norm_x
is_norm_x:
mov.b &NORM, %d0
rts
not_norm_x:
tst.w %d0 # is exponent = 0?
bne.b is_unnorm_x
not_unnorm_x:
tst.l FTEMP_HI(%a0)
bne.b is_denorm_x
tst.l FTEMP_LO(%a0)
bne.b is_denorm_x
is_zero_x:
mov.b &ZERO, %d0
rts
is_denorm_x:
mov.b &DENORM, %d0
rts
is_unnorm_x:
tst.l FTEMP_HI(%a0)
bne.b is_unnorm_reg_x
tst.l FTEMP_LO(%a0)
bne.b is_unnorm_reg_x
andi.w &0x8000,FTEMP_EX(%a0) # clear exponent
mov.b &ZERO, %d0
rts
is_unnorm_reg_x:
mov.b &UNNORM, %d0
rts
inf_or_nan_x:
tst.l FTEMP_LO(%a0)
bne.b is_nan_x
mov.l FTEMP_HI(%a0), %d0
and.l &0x7fffffff, %d0 # msb is a don't care!
bne.b is_nan_x
is_inf_x:
mov.b &INF, %d0
rts
is_nan_x:
btst &0x6, FTEMP_HI(%a0)
beq.b is_snan_x
mov.b &QNAN, %d0
rts
is_snan_x:
mov.b &SNAN, %d0
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global set_tag_d
set_tag_d:
mov.l FTEMP(%a0), %d0
mov.l %d0, %d1
andi.l &0x7ff00000, %d0
beq.b zero_or_denorm_d
cmpi.l %d0, &0x7ff00000
beq.b inf_or_nan_d
is_norm_d:
mov.b &NORM, %d0
rts
zero_or_denorm_d:
and.l &0x000fffff, %d1
bne is_denorm_d
tst.l 4+FTEMP(%a0)
bne is_denorm_d
is_zero_d:
mov.b &ZERO, %d0
rts
is_denorm_d:
mov.b &DENORM, %d0
rts
inf_or_nan_d:
and.l &0x000fffff, %d1
bne is_nan_d
tst.l 4+FTEMP(%a0)
bne is_nan_d
is_inf_d:
mov.b &INF, %d0
rts
is_nan_d:
btst &19, %d1
bne is_qnan_d
is_snan_d:
mov.b &SNAN, %d0
rts
is_qnan_d:
mov.b &QNAN, %d0
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global set_tag_s
set_tag_s:
mov.l FTEMP(%a0), %d0
mov.l %d0, %d1
andi.l &0x7f800000, %d0
beq.b zero_or_denorm_s
cmpi.l %d0, &0x7f800000
beq.b inf_or_nan_s
is_norm_s:
mov.b &NORM, %d0
rts
zero_or_denorm_s:
and.l &0x007fffff, %d1
bne is_denorm_s
is_zero_s:
mov.b &ZERO, %d0
rts
is_denorm_s:
mov.b &DENORM, %d0
rts
inf_or_nan_s:
and.l &0x007fffff, %d1
bne is_nan_s
is_inf_s:
mov.b &INF, %d0
rts
is_nan_s:
btst &22, %d1
bne is_qnan_s
is_snan_s:
mov.b &SNAN, %d0
rts
is_qnan_s:
mov.b &QNAN, %d0
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global unf_res
unf_res:
mov.l %d1, -(%sp) # save rnd prec,mode on stack
btst &0x7, FTEMP_EX(%a0) # make "internal" format
sne FTEMP_SGN(%a0)
mov.w FTEMP_EX(%a0), %d1 # extract exponent
and.w &0x7fff, %d1
sub.w %d0, %d1
mov.w %d1, FTEMP_EX(%a0) # insert 16 bit exponent
mov.l %a0, -(%sp) # save operand ptr during calls
mov.l 0x4(%sp),%d0 # pass rnd prec.
andi.w &0x00c0,%d0
lsr.w &0x4,%d0
bsr.l _denorm # denorm result
mov.l (%sp),%a0
mov.w 0x6(%sp),%d1 # load prec:mode into %d1
andi.w &0xc0,%d1 # extract rnd prec
lsr.w &0x4,%d1
swap %d1
mov.w 0x6(%sp),%d1
andi.w &0x30,%d1
lsr.w &0x4,%d1
bsr.l _round # round the denorm
mov.l (%sp)+, %a0
bclr &0x7, FTEMP_EX(%a0) # clear sgn first; may have residue
tst.b FTEMP_SGN(%a0) # is "internal result" sign set?
beq.b unf_res_chkifzero # no; result is positive
bset &0x7, FTEMP_EX(%a0) # set result sgn
clr.b FTEMP_SGN(%a0) # clear temp sign
unf_res_chkifzero:
clr.l %d0
tst.l FTEMP_HI(%a0) # is value now a zero?
bne.b unf_res_cont # no
tst.l FTEMP_LO(%a0)
bne.b unf_res_cont # no
bset &z_bit, %d0 # yes; set zero ccode bit
unf_res_cont:
#
#
#
btst &inex2_bit, FPSR_EXCEPT(%a6) # is INEX2 set?
beq.b unf_res_end # no
bset &aunfl_bit, FPSR_AEXCEPT(%a6) # yes; set aunfl
unf_res_end:
add.l &0x4, %sp # clear stack
rts
global unf_res4
unf_res4:
mov.l %d1,-(%sp) # save rnd prec,mode on stack
btst &0x7,FTEMP_EX(%a0) # make "internal" format
sne FTEMP_SGN(%a0)
mov.w FTEMP_EX(%a0),%d1 # extract exponent
and.w &0x7fff,%d1
sub.w %d0,%d1
mov.w %d1,FTEMP_EX(%a0) # insert 16 bit exponent
mov.l %a0,-(%sp) # save operand ptr during calls
clr.l %d0 # force rnd prec = ext
bsr.l _denorm # denorm result
mov.l (%sp),%a0
mov.w &s_mode,%d1 # force rnd prec = sgl
swap %d1
mov.w 0x6(%sp),%d1 # load rnd mode
andi.w &0x30,%d1 # extract rnd prec
lsr.w &0x4,%d1
bsr.l _round # round the denorm
mov.l (%sp)+,%a0
bclr &0x7,FTEMP_EX(%a0) # clear sgn first; may have residue
tst.b FTEMP_SGN(%a0) # is "internal result" sign set?
beq.b unf_res4_chkifzero # no; result is positive
bset &0x7,FTEMP_EX(%a0) # set result sgn
clr.b FTEMP_SGN(%a0) # clear temp sign
unf_res4_chkifzero:
clr.l %d0
tst.l FTEMP_HI(%a0) # is value now a zero?
bne.b unf_res4_cont # no
tst.l FTEMP_LO(%a0)
bne.b unf_res4_cont # no
bset &z_bit,%d0 # yes; set zero ccode bit
unf_res4_cont:
#
#
#
btst &inex2_bit,FPSR_EXCEPT(%a6) # is INEX2 set?
beq.b unf_res4_end # no
bset &aunfl_bit,FPSR_AEXCEPT(%a6) # yes; set aunfl
unf_res4_end:
add.l &0x4,%sp # clear stack
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global ovf_res
ovf_res:
andi.w &0x10,%d1 # keep result sign
lsr.b &0x4,%d0 # shift prec/mode
or.b %d0,%d1 # concat the two
mov.w %d1,%d0 # make a copy
lsl.b &0x1,%d1 # multiply d1 by 2
bra.b ovf_res_load
global ovf_res2
ovf_res2:
and.w &0x10, %d1 # keep result sign
or.b %d0, %d1 # insert rnd mode
swap %d0
or.b %d0, %d1 # insert rnd prec
mov.w %d1, %d0 # make a copy
lsl.b &0x1, %d1 # shift left by 1
#
#
ovf_res_load:
mov.b (tbl_ovfl_cc.b,%pc,%d0.w*1), %d0 # fetch result ccodes
lea (tbl_ovfl_result.b,%pc,%d1.w*8), %a0 # return result ptr
rts
tbl_ovfl_cc:
byte 0x2, 0x0, 0x0, 0x2
byte 0x2, 0x0, 0x0, 0x2
byte 0x2, 0x0, 0x0, 0x2
byte 0x0, 0x0, 0x0, 0x0
byte 0x2+0x8, 0x8, 0x2+0x8, 0x8
byte 0x2+0x8, 0x8, 0x2+0x8, 0x8
byte 0x2+0x8, 0x8, 0x2+0x8, 0x8
tbl_ovfl_result:
long 0x7fff0000,0x00000000,0x00000000,0x00000000 # +INF; RN
long 0x7ffe0000,0xffffffff,0xffffffff,0x00000000 # +EXT; RZ
long 0x7ffe0000,0xffffffff,0xffffffff,0x00000000 # +EXT; RM
long 0x7fff0000,0x00000000,0x00000000,0x00000000 # +INF; RP
long 0x7fff0000,0x00000000,0x00000000,0x00000000 # +INF; RN
long 0x407e0000,0xffffff00,0x00000000,0x00000000 # +SGL; RZ
long 0x407e0000,0xffffff00,0x00000000,0x00000000 # +SGL; RM
long 0x7fff0000,0x00000000,0x00000000,0x00000000 # +INF; RP
long 0x7fff0000,0x00000000,0x00000000,0x00000000 # +INF; RN
long 0x43fe0000,0xffffffff,0xfffff800,0x00000000 # +DBL; RZ
long 0x43fe0000,0xffffffff,0xfffff800,0x00000000 # +DBL; RM
long 0x7fff0000,0x00000000,0x00000000,0x00000000 # +INF; RP
long 0x00000000,0x00000000,0x00000000,0x00000000
long 0x00000000,0x00000000,0x00000000,0x00000000
long 0x00000000,0x00000000,0x00000000,0x00000000
long 0x00000000,0x00000000,0x00000000,0x00000000
long 0xffff0000,0x00000000,0x00000000,0x00000000 # -INF; RN
long 0xfffe0000,0xffffffff,0xffffffff,0x00000000 # -EXT; RZ
long 0xffff0000,0x00000000,0x00000000,0x00000000 # -INF; RM
long 0xfffe0000,0xffffffff,0xffffffff,0x00000000 # -EXT; RP
long 0xffff0000,0x00000000,0x00000000,0x00000000 # -INF; RN
long 0xc07e0000,0xffffff00,0x00000000,0x00000000 # -SGL; RZ
long 0xffff0000,0x00000000,0x00000000,0x00000000 # -INF; RM
long 0xc07e0000,0xffffff00,0x00000000,0x00000000 # -SGL; RP
long 0xffff0000,0x00000000,0x00000000,0x00000000 # -INF; RN
long 0xc3fe0000,0xffffffff,0xfffff800,0x00000000 # -DBL; RZ
long 0xffff0000,0x00000000,0x00000000,0x00000000 # -INF; RM
long 0xc3fe0000,0xffffffff,0xfffff800,0x00000000 # -DBL; RP
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global fout
fout:
bfextu EXC_CMDREG(%a6){&3:&3},%d1 # extract dst fmt
mov.w (tbl_fout.b,%pc,%d1.w*2),%a1 # use as index
jmp (tbl_fout.b,%pc,%a1) # jump to routine
swbeg &0x8
tbl_fout:
short fout_long - tbl_fout
short fout_sgl - tbl_fout
short fout_ext - tbl_fout
short fout_pack - tbl_fout
short fout_word - tbl_fout
short fout_dbl - tbl_fout
short fout_byte - tbl_fout
short fout_pack - tbl_fout
#################################################################
#################################################################
fout_byte:
tst.b STAG(%a6) # is operand normalized?
bne.b fout_byte_denorm # no
fmovm.x SRC(%a0),&0x80 # load value
fout_byte_norm:
fmov.l %d0,%fpcr # insert rnd prec,mode
fmov.b %fp0,%d0 # exec move out w/ correct rnd mode
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d1 # fetch FPSR
or.w %d1,2+USER_FPSR(%a6) # save new exc,accrued bits
mov.b 1+EXC_OPWORD(%a6),%d1 # extract dst mode
andi.b &0x38,%d1 # is mode == 0? (Dreg dst)
beq.b fout_byte_dn # must save to integer regfile
mov.l EXC_EA(%a6),%a0 # stacked <ea> is correct
bsr.l _dmem_write_byte # write byte
tst.l %d1 # did dstore fail?
bne.l facc_out_b # yes
rts
fout_byte_dn:
mov.b 1+EXC_OPWORD(%a6),%d1 # extract Dn
andi.w &0x7,%d1
bsr.l store_dreg_b
rts
fout_byte_denorm:
mov.l SRC_EX(%a0),%d1
andi.l &0x80000000,%d1 # keep DENORM sign
ori.l &0x00800000,%d1 # make smallest sgl
fmov.s %d1,%fp0
bra.b fout_byte_norm
#################################################################
#################################################################
fout_word:
tst.b STAG(%a6) # is operand normalized?
bne.b fout_word_denorm # no
fmovm.x SRC(%a0),&0x80 # load value
fout_word_norm:
fmov.l %d0,%fpcr # insert rnd prec:mode
fmov.w %fp0,%d0 # exec move out w/ correct rnd mode
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d1 # fetch FPSR
or.w %d1,2+USER_FPSR(%a6) # save new exc,accrued bits
mov.b 1+EXC_OPWORD(%a6),%d1 # extract dst mode
andi.b &0x38,%d1 # is mode == 0? (Dreg dst)
beq.b fout_word_dn # must save to integer regfile
mov.l EXC_EA(%a6),%a0 # stacked <ea> is correct
bsr.l _dmem_write_word # write word
tst.l %d1 # did dstore fail?
bne.l facc_out_w # yes
rts
fout_word_dn:
mov.b 1+EXC_OPWORD(%a6),%d1 # extract Dn
andi.w &0x7,%d1
bsr.l store_dreg_w
rts
fout_word_denorm:
mov.l SRC_EX(%a0),%d1
andi.l &0x80000000,%d1 # keep DENORM sign
ori.l &0x00800000,%d1 # make smallest sgl
fmov.s %d1,%fp0
bra.b fout_word_norm
#################################################################
#################################################################
fout_long:
tst.b STAG(%a6) # is operand normalized?
bne.b fout_long_denorm # no
fmovm.x SRC(%a0),&0x80 # load value
fout_long_norm:
fmov.l %d0,%fpcr # insert rnd prec:mode
fmov.l %fp0,%d0 # exec move out w/ correct rnd mode
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d1 # fetch FPSR
or.w %d1,2+USER_FPSR(%a6) # save new exc,accrued bits
fout_long_write:
mov.b 1+EXC_OPWORD(%a6),%d1 # extract dst mode
andi.b &0x38,%d1 # is mode == 0? (Dreg dst)
beq.b fout_long_dn # must save to integer regfile
mov.l EXC_EA(%a6),%a0 # stacked <ea> is correct
bsr.l _dmem_write_long # write long
tst.l %d1 # did dstore fail?
bne.l facc_out_l # yes
rts
fout_long_dn:
mov.b 1+EXC_OPWORD(%a6),%d1 # extract Dn
andi.w &0x7,%d1
bsr.l store_dreg_l
rts
fout_long_denorm:
mov.l SRC_EX(%a0),%d1
andi.l &0x80000000,%d1 # keep DENORM sign
ori.l &0x00800000,%d1 # make smallest sgl
fmov.s %d1,%fp0
bra.b fout_long_norm
#################################################################
#################################################################
fout_ext:
# 16-bit field gets zeroed. we do this since we promise not to disturb
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
clr.w 2+FP_SCR0_EX(%a6) # clear reserved field
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
fmovm.x SRC(%a0),&0x80 # return result
bsr.l _calc_ea_fout # fix stacked <ea>
mov.l %a0,%a1 # pass: dst addr
lea FP_SCR0(%a6),%a0 # pass: src addr
mov.l &0xc,%d0 # pass: opsize is 12 bytes
cmpi.b SPCOND_FLG(%a6),&mda7_flg
beq.b fout_ext_a7
bsr.l _dmem_write # write ext prec number to memory
tst.l %d1 # did dstore fail?
bne.w fout_ext_err # yes
tst.b STAG(%a6) # is operand normalized?
bne.b fout_ext_denorm # no
rts
fout_ext_denorm:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set underflow exc bit
mov.b FPCR_ENABLE(%a6),%d0
andi.b &0x0a,%d0 # is UNFL or INEX enabled?
bne.b fout_ext_exc # yes
rts
fout_ext_a7:
bsr.l _mem_write2 # write ext prec number to memory
tst.l %d1 # did dstore fail?
bne.w fout_ext_err # yes
tst.b STAG(%a6) # is operand normalized?
bne.b fout_ext_denorm # no
rts
fout_ext_exc:
lea FP_SCR0(%a6),%a0
bsr.l norm # normalize the mantissa
neg.w %d0 # new exp = -(shft amt)
andi.w &0x7fff,%d0
andi.w &0x8000,FP_SCR0_EX(%a6) # keep only old sign
or.w %d0,FP_SCR0_EX(%a6) # insert new exponent
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
rts
fout_ext_err:
mov.l EXC_A6(%a6),(%a6) # fix stacked a6
bra.l facc_out_x
#########################################################################
#########################################################################
fout_sgl:
andi.b &0x30,%d0 # clear rnd prec
ori.b &s_mode*0x10,%d0 # insert sgl prec
mov.l %d0,L_SCR3(%a6) # save rnd prec,mode on stack
#
#
mov.w SRC_EX(%a0),%d0 # extract exponent
andi.w &0x7fff,%d0 # strip sign
cmpi.w %d0,&SGL_HI # will operand overflow?
bgt.w fout_sgl_ovfl # yes; go handle OVFL
beq.w fout_sgl_may_ovfl # maybe; go handle possible OVFL
cmpi.w %d0,&SGL_LO # will operand underflow?
blt.w fout_sgl_unfl # yes; go handle underflow
#
#
fout_sgl_exg:
fmovm.x SRC(%a0),&0x80 # fetch fop from stack
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fmov.s %fp0,%d0 # store does convert and round
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d1 # save FPSR
or.w %d1,2+USER_FPSR(%a6) # set possible inex2/ainex
fout_sgl_exg_write:
mov.b 1+EXC_OPWORD(%a6),%d1 # extract dst mode
andi.b &0x38,%d1 # is mode == 0? (Dreg dst)
beq.b fout_sgl_exg_write_dn # must save to integer regfile
mov.l EXC_EA(%a6),%a0 # stacked <ea> is correct
bsr.l _dmem_write_long # write long
tst.l %d1 # did dstore fail?
bne.l facc_out_l # yes
rts
fout_sgl_exg_write_dn:
mov.b 1+EXC_OPWORD(%a6),%d1 # extract Dn
andi.w &0x7,%d1
bsr.l store_dreg_l
rts
#
#
fout_sgl_unfl:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set UNFL
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
mov.l %a0,-(%sp)
clr.l %d0 # pass: S.F. = 0
cmpi.b STAG(%a6),&DENORM # fetch src optype tag
bne.b fout_sgl_unfl_cont # let DENORMs fall through
lea FP_SCR0(%a6),%a0
bsr.l norm # normalize the DENORM
fout_sgl_unfl_cont:
lea FP_SCR0(%a6),%a0 # pass: ptr to operand
mov.l L_SCR3(%a6),%d1 # pass: rnd prec,mode
bsr.l unf_res # calc default underflow result
lea FP_SCR0(%a6),%a0 # pass: ptr to fop
bsr.l dst_sgl # convert to single prec
mov.b 1+EXC_OPWORD(%a6),%d1 # extract dst mode
andi.b &0x38,%d1 # is mode == 0? (Dreg dst)
beq.b fout_sgl_unfl_dn # must save to integer regfile
mov.l EXC_EA(%a6),%a0 # stacked <ea> is correct
bsr.l _dmem_write_long # write long
tst.l %d1 # did dstore fail?
bne.l facc_out_l # yes
bra.b fout_sgl_unfl_chkexc
fout_sgl_unfl_dn:
mov.b 1+EXC_OPWORD(%a6),%d1 # extract Dn
andi.w &0x7,%d1
bsr.l store_dreg_l
fout_sgl_unfl_chkexc:
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0a,%d1 # is UNFL or INEX enabled?
bne.w fout_sd_exc_unfl # yes
addq.l &0x4,%sp
rts
#
#
fout_sgl_ovfl:
tst.b 3+SRC_HI(%a0) # is result inexact?
bne.b fout_sgl_ovfl_inex2
tst.l SRC_LO(%a0) # is result inexact?
bne.b fout_sgl_ovfl_inex2
ori.w &ovfl_inx_mask,2+USER_FPSR(%a6) # set ovfl/aovfl/ainex
bra.b fout_sgl_ovfl_cont
fout_sgl_ovfl_inex2:
ori.w &ovfinx_mask,2+USER_FPSR(%a6) # set ovfl/aovfl/ainex/inex2
fout_sgl_ovfl_cont:
mov.l %a0,-(%sp)
tst.b SRC_EX(%a0) # is operand negative?
smi %d1 # set if so
mov.l L_SCR3(%a6),%d0 # pass: sgl prec,rnd mode
bsr.l ovf_res # calc OVFL result
fmovm.x (%a0),&0x80 # load default overflow result
fmov.s %fp0,%d0 # store to single
mov.b 1+EXC_OPWORD(%a6),%d1 # extract dst mode
andi.b &0x38,%d1 # is mode == 0? (Dreg dst)
beq.b fout_sgl_ovfl_dn # must save to integer regfile
mov.l EXC_EA(%a6),%a0 # stacked <ea> is correct
bsr.l _dmem_write_long # write long
tst.l %d1 # did dstore fail?
bne.l facc_out_l # yes
bra.b fout_sgl_ovfl_chkexc
fout_sgl_ovfl_dn:
mov.b 1+EXC_OPWORD(%a6),%d1 # extract Dn
andi.w &0x7,%d1
bsr.l store_dreg_l
fout_sgl_ovfl_chkexc:
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0a,%d1 # is UNFL or INEX enabled?
bne.w fout_sd_exc_ovfl # yes
addq.l &0x4,%sp
rts
#
# (1) force the exp to 0x3fff
# (2) do a move w/ appropriate rnd mode
# (3) if exp still equals zero, then insert original exponent
# if exp now equals one, then it overflowed so call ovf_res.
#
fout_sgl_may_ovfl:
mov.w SRC_EX(%a0),%d1 # fetch current sign
andi.w &0x8000,%d1 # keep it,clear exp
ori.w &0x3fff,%d1 # insert exp = 0
mov.w %d1,FP_SCR0_EX(%a6) # insert scaled exp
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6) # copy hi(man)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6) # copy lo(man)
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.x FP_SCR0(%a6),%fp0 # force fop to be rounded
fmov.l &0x0,%fpcr # clear FPCR
fabs.x %fp0 # need absolute value
fcmp.b %fp0,&0x2 # did exponent increase?
fblt.w fout_sgl_exg # no; go finish NORM
bra.w fout_sgl_ovfl # yes; go handle overflow
################
fout_sd_exc_unfl:
mov.l (%sp)+,%a0
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
cmpi.b STAG(%a6),&DENORM # was src a DENORM?
bne.b fout_sd_exc_cont # no
lea FP_SCR0(%a6),%a0
bsr.l norm
neg.l %d0
andi.w &0x7fff,%d0
bfins %d0,FP_SCR0_EX(%a6){&1:&15}
bra.b fout_sd_exc_cont
fout_sd_exc:
fout_sd_exc_ovfl:
mov.l (%sp)+,%a0 # restore a0
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
fout_sd_exc_cont:
bclr &0x7,FP_SCR0_EX(%a6) # clear sign bit
sne.b 2+FP_SCR0_EX(%a6) # set internal sign bit
lea FP_SCR0(%a6),%a0 # pass: ptr to DENORM
mov.b 3+L_SCR3(%a6),%d1
lsr.b &0x4,%d1
andi.w &0x0c,%d1
swap %d1
mov.b 3+L_SCR3(%a6),%d1
lsr.b &0x4,%d1
andi.w &0x03,%d1
clr.l %d0 # pass: zero g,r,s
bsr.l _round # round the DENORM
tst.b 2+FP_SCR0_EX(%a6) # is EXOP negative?
beq.b fout_sd_exc_done # no
bset &0x7,FP_SCR0_EX(%a6) # yes
fout_sd_exc_done:
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
rts
#################################################################
#################################################################
fout_dbl:
andi.b &0x30,%d0 # clear rnd prec
ori.b &d_mode*0x10,%d0 # insert dbl prec
mov.l %d0,L_SCR3(%a6) # save rnd prec,mode on stack
#
#
mov.w SRC_EX(%a0),%d0 # extract exponent
andi.w &0x7fff,%d0 # strip sign
cmpi.w %d0,&DBL_HI # will operand overflow?
bgt.w fout_dbl_ovfl # yes; go handle OVFL
beq.w fout_dbl_may_ovfl # maybe; go handle possible OVFL
cmpi.w %d0,&DBL_LO # will operand underflow?
blt.w fout_dbl_unfl # yes; go handle underflow
#
#
fout_dbl_exg:
fmovm.x SRC(%a0),&0x80 # fetch fop from stack
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fmov.d %fp0,L_SCR1(%a6) # store does convert and round
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d0 # save FPSR
or.w %d0,2+USER_FPSR(%a6) # set possible inex2/ainex
mov.l EXC_EA(%a6),%a1 # pass: dst addr
lea L_SCR1(%a6),%a0 # pass: src addr
movq.l &0x8,%d0 # pass: opsize is 8 bytes
bsr.l _dmem_write # store dbl fop to memory
tst.l %d1 # did dstore fail?
bne.l facc_out_d # yes
rts # no; so we're finished
#
#
fout_dbl_unfl:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set UNFL
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
mov.l %a0,-(%sp)
clr.l %d0 # pass: S.F. = 0
cmpi.b STAG(%a6),&DENORM # fetch src optype tag
bne.b fout_dbl_unfl_cont # let DENORMs fall through
lea FP_SCR0(%a6),%a0
bsr.l norm # normalize the DENORM
fout_dbl_unfl_cont:
lea FP_SCR0(%a6),%a0 # pass: ptr to operand
mov.l L_SCR3(%a6),%d1 # pass: rnd prec,mode
bsr.l unf_res # calc default underflow result
lea FP_SCR0(%a6),%a0 # pass: ptr to fop
bsr.l dst_dbl # convert to single prec
mov.l %d0,L_SCR1(%a6)
mov.l %d1,L_SCR2(%a6)
mov.l EXC_EA(%a6),%a1 # pass: dst addr
lea L_SCR1(%a6),%a0 # pass: src addr
movq.l &0x8,%d0 # pass: opsize is 8 bytes
bsr.l _dmem_write # store dbl fop to memory
tst.l %d1 # did dstore fail?
bne.l facc_out_d # yes
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0a,%d1 # is UNFL or INEX enabled?
bne.w fout_sd_exc_unfl # yes
addq.l &0x4,%sp
rts
#
#
fout_dbl_ovfl:
mov.w 2+SRC_LO(%a0),%d0
andi.w &0x7ff,%d0
bne.b fout_dbl_ovfl_inex2
ori.w &ovfl_inx_mask,2+USER_FPSR(%a6) # set ovfl/aovfl/ainex
bra.b fout_dbl_ovfl_cont
fout_dbl_ovfl_inex2:
ori.w &ovfinx_mask,2+USER_FPSR(%a6) # set ovfl/aovfl/ainex/inex2
fout_dbl_ovfl_cont:
mov.l %a0,-(%sp)
tst.b SRC_EX(%a0) # is operand negative?
smi %d1 # set if so
mov.l L_SCR3(%a6),%d0 # pass: dbl prec,rnd mode
bsr.l ovf_res # calc OVFL result
fmovm.x (%a0),&0x80 # load default overflow result
fmov.d %fp0,L_SCR1(%a6) # store to double
mov.l EXC_EA(%a6),%a1 # pass: dst addr
lea L_SCR1(%a6),%a0 # pass: src addr
movq.l &0x8,%d0 # pass: opsize is 8 bytes
bsr.l _dmem_write # store dbl fop to memory
tst.l %d1 # did dstore fail?
bne.l facc_out_d # yes
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0a,%d1 # is UNFL or INEX enabled?
bne.w fout_sd_exc_ovfl # yes
addq.l &0x4,%sp
rts
#
# (1) force the exp to 0x3fff
# (2) do a move w/ appropriate rnd mode
# (3) if exp still equals zero, then insert original exponent
# if exp now equals one, then it overflowed so call ovf_res.
#
fout_dbl_may_ovfl:
mov.w SRC_EX(%a0),%d1 # fetch current sign
andi.w &0x8000,%d1 # keep it,clear exp
ori.w &0x3fff,%d1 # insert exp = 0
mov.w %d1,FP_SCR0_EX(%a6) # insert scaled exp
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6) # copy hi(man)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6) # copy lo(man)
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.x FP_SCR0(%a6),%fp0 # force fop to be rounded
fmov.l &0x0,%fpcr # clear FPCR
fabs.x %fp0 # need absolute value
fcmp.b %fp0,&0x2 # did exponent increase?
fblt.w fout_dbl_exg # no; go finish NORM
bra.w fout_dbl_ovfl # yes; go handle overflow
#########################################################################
# #
# #
# #
# #
# #
# #
# --------------- --------------- --------------- #
# --------------- --------------- --------------- #
# 95 64 63 62 32 31 11 0 #
# | | #
# | | #
# | | #
# --------------- --------------- #
# --------------- --------------- #
# 63 51 32 31 0 #
# #
#########################################################################
dst_dbl:
clr.l %d0 # clear d0
mov.w FTEMP_EX(%a0),%d0 # get exponent
subi.w &EXT_BIAS,%d0 # subtract extended precision bias
addi.w &DBL_BIAS,%d0 # add double precision bias
tst.b FTEMP_HI(%a0) # is number a denorm?
bmi.b dst_get_dupper # no
subq.w &0x1,%d0 # yes; denorm bias = DBL_BIAS - 1
dst_get_dupper:
swap %d0 # d0 now in upper word
lsl.l &0x4,%d0 # d0 in proper place for dbl prec exp
tst.b FTEMP_EX(%a0) # test sign
bpl.b dst_get_dman # if positive, go process mantissa
bset &0x1f,%d0 # if negative, set sign
dst_get_dman:
mov.l FTEMP_HI(%a0),%d1 # get ms mantissa
bfextu %d1{&1:&20},%d1 # get upper 20 bits of ms
or.l %d1,%d0 # put these bits in ms word of double
mov.l %d0,L_SCR1(%a6) # put the new exp back on the stack
mov.l FTEMP_HI(%a0),%d1 # get ms mantissa
mov.l &21,%d0 # load shift count
lsl.l %d0,%d1 # put lower 11 bits in upper bits
mov.l %d1,L_SCR2(%a6) # build lower lword in memory
mov.l FTEMP_LO(%a0),%d1 # get ls mantissa
bfextu %d1{&0:&21},%d0 # get ls 21 bits of double
mov.l L_SCR2(%a6),%d1
or.l %d0,%d1 # put them in double result
mov.l L_SCR1(%a6),%d0
rts
#########################################################################
# #
# #
# #
# #
# #
# #
# --------------- --------------- --------------- #
# --------------- --------------- --------------- #
# 95 64 63 62 40 32 31 12 0 #
# | | #
# | | #
# | | #
# --------------- #
# --------------- #
# 31 22 0 #
# #
#########################################################################
dst_sgl:
clr.l %d0
mov.w FTEMP_EX(%a0),%d0 # get exponent
subi.w &EXT_BIAS,%d0 # subtract extended precision bias
addi.w &SGL_BIAS,%d0 # add single precision bias
tst.b FTEMP_HI(%a0) # is number a denorm?
bmi.b dst_get_supper # no
subq.w &0x1,%d0 # yes; denorm bias = SGL_BIAS - 1
dst_get_supper:
swap %d0 # put exp in upper word of d0
lsl.l &0x7,%d0 # shift it into single exp bits
tst.b FTEMP_EX(%a0) # test sign
bpl.b dst_get_sman # if positive, continue
bset &0x1f,%d0 # if negative, put in sign first
dst_get_sman:
mov.l FTEMP_HI(%a0),%d1 # get ms mantissa
andi.l &0x7fffff00,%d1 # get upper 23 bits of ms
lsr.l &0x8,%d1 # and put them flush right
or.l %d1,%d0 # put these bits in ms word of single
rts
##############################################################################
fout_pack:
bsr.l _calc_ea_fout # fetch the <ea>
mov.l %a0,-(%sp)
mov.b STAG(%a6),%d0 # fetch input type
bne.w fout_pack_not_norm # input is not NORM
fout_pack_norm:
btst &0x4,EXC_CMDREG(%a6) # static or dynamic?
beq.b fout_pack_s # static
fout_pack_d:
mov.b 1+EXC_CMDREG(%a6),%d1 # fetch dynamic reg
lsr.b &0x4,%d1
andi.w &0x7,%d1
bsr.l fetch_dreg # fetch Dn w/ k-factor
bra.b fout_pack_type
fout_pack_s:
mov.b 1+EXC_CMDREG(%a6),%d0 # fetch static field
fout_pack_type:
bfexts %d0{&25:&7},%d0 # extract k-factor
mov.l %d0,-(%sp)
lea FP_SRC(%a6),%a0 # pass: ptr to input
bsr.l bindec # convert xprec to packed
andi.l &0xcffff00f,FP_SCR0(%a6) # clear unused fields
mov.l (%sp)+,%d0
tst.b 3+FP_SCR0_EX(%a6)
bne.b fout_pack_set
tst.l FP_SCR0_HI(%a6)
bne.b fout_pack_set
tst.l FP_SCR0_LO(%a6)
bne.b fout_pack_set
tst.l %d0
bne.b fout_pack_set
# "mantissa" is all zero which means that the answer is zero. but, the '040
# if the mantissa is zero, I will zero the exponent, too.
andi.w &0xf000,FP_SCR0(%a6)
fout_pack_set:
lea FP_SCR0(%a6),%a0 # pass: src addr
fout_pack_write:
mov.l (%sp)+,%a1 # pass: dst addr
mov.l &0xc,%d0 # pass: opsize is 12 bytes
cmpi.b SPCOND_FLG(%a6),&mda7_flg
beq.b fout_pack_a7
bsr.l _dmem_write # write ext prec number to memory
tst.l %d1 # did dstore fail?
bne.w fout_ext_err # yes
rts
fout_pack_a7:
bsr.l _mem_write2 # write ext prec number to memory
tst.l %d1 # did dstore fail?
bne.w fout_ext_err # yes
rts
fout_pack_not_norm:
cmpi.b %d0,&DENORM # is it a DENORM?
beq.w fout_pack_norm # yes
lea FP_SRC(%a6),%a0
clr.w 2+FP_SRC_EX(%a6)
cmpi.b %d0,&SNAN # is it an SNAN?
beq.b fout_pack_snan # yes
bra.b fout_pack_write # no
fout_pack_snan:
ori.w &snaniop2_mask,FPSR_EXCEPT(%a6) # set SNAN/AIOP
bset &0x6,FP_SRC_HI(%a6) # set snan bit
bra.b fout_pack_write
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
align 0x10
tbl_fmul_ovfl:
long 0x3fff - 0x7ffe # ext_max
long 0x3fff - 0x407e # sgl_max
long 0x3fff - 0x43fe # dbl_max
tbl_fmul_unfl:
long 0x3fff + 0x0001 # ext_unfl
long 0x3fff - 0x3f80 # sgl_unfl
long 0x3fff - 0x3c00 # dbl_unfl
global fsmul
fsmul:
andi.b &0x30,%d0 # clear rnd prec
ori.b &s_mode*0x10,%d0 # insert sgl prec
bra.b fmul
global fdmul
fdmul:
andi.b &0x30,%d0
ori.b &d_mode*0x10,%d0 # insert dbl prec
global fmul
fmul:
mov.l %d0,L_SCR3(%a6) # store rnd info
clr.w %d1
mov.b DTAG(%a6),%d1
lsl.b &0x3,%d1
or.b STAG(%a6),%d1 # combine src tags
bne.w fmul_not_norm # optimize on non-norm input
fmul_norm:
mov.w DST_EX(%a1),FP_SCR1_EX(%a6)
mov.l DST_HI(%a1),FP_SCR1_HI(%a6)
mov.l DST_LO(%a1),FP_SCR1_LO(%a6)
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_to_zero_src # scale src exponent
mov.l %d0,-(%sp) # save scale factor 1
bsr.l scale_to_zero_dst # scale dst exponent
add.l %d0,(%sp) # SCALE_FACTOR = scale1 + scale2
mov.w 2+L_SCR3(%a6),%d1 # fetch precision
lsr.b &0x6,%d1 # shift to lo bits
mov.l (%sp)+,%d0 # load S.F.
cmp.l %d0,(tbl_fmul_ovfl.w,%pc,%d1.w*4) # would result ovfl?
beq.w fmul_may_ovfl # result may rnd to overflow
blt.w fmul_ovfl # result will overflow
cmp.l %d0,(tbl_fmul_unfl.w,%pc,%d1.w*4) # would result unfl?
beq.w fmul_may_unfl # result may rnd to no unfl
bgt.w fmul_unfl # result will underflow
#
# - the result of the multiply operation will neither overflow nor underflow.
# - do the multiply to the proper precision and rounding mode.
# - scale the result exponent using the scale factor. if both operands were
#
fmul_normal:
fmovm.x FP_SCR1(%a6),&0x80 # load dst operand
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fmul.x FP_SCR0(%a6),%fp0 # execute multiply
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fmul_normal_exit:
fmovm.x &0x80,FP_SCR0(%a6) # store out result
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # load {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
or.w %d2,%d1 # concat old sign,new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
rts
#
# - the result of the multiply operation is an overflow.
# - do the multiply to the proper precision and rounding mode in order to
# - calculate the default result and return it in fp0.
# - if overflow or inexact is enabled, we need a multiply result rounded to
#
fmul_ovfl:
fmovm.x FP_SCR1(%a6),&0x80 # load dst operand
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fmul.x FP_SCR0(%a6),%fp0 # execute multiply
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fmul_ovfl_tst:
or.l &ovfl_inx_mask,USER_FPSR(%a6) # set ovfl/aovfl/ainex
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x13,%d1 # is OVFL or INEX enabled?
bne.b fmul_ovfl_ena # yes
fmul_ovfl_dis:
btst &neg_bit,FPSR_CC(%a6) # is result negative?
sne %d1 # set sign param accordingly
mov.l L_SCR3(%a6),%d0 # pass rnd prec,mode
bsr.l ovf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # set INF,N if applicable
fmovm.x (%a0),&0x80 # return default result in fp0
rts
#
# - if precision is extended, then we have the EXOP. simply bias the exponent
#
fmul_ovfl_ena:
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # test the rnd prec
bne.b fmul_ovfl_ena_sd # it's sgl or dbl
fmul_ovfl_ena_cont:
fmovm.x &0x80,FP_SCR0(%a6) # move result to stack
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.w %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
sub.l %d0,%d1 # add scale factor
subi.l &0x6000,%d1 # subtract bias
andi.w &0x7fff,%d1 # clear sign bit
andi.w &0x8000,%d2 # keep old sign
or.w %d2,%d1 # concat old sign,new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
bra.b fmul_ovfl_dis
fmul_ovfl_ena_sd:
fmovm.x FP_SCR1(%a6),&0x80 # load dst operand
mov.l L_SCR3(%a6),%d1
andi.b &0x30,%d1 # keep rnd mode only
fmov.l %d1,%fpcr # set FPCR
fmul.x FP_SCR0(%a6),%fp0 # execute multiply
fmov.l &0x0,%fpcr # clear FPCR
bra.b fmul_ovfl_ena_cont
#
# - the result of the multiply operation MAY overflow.
# - do the multiply to the proper precision and rounding mode in order to
# - calculate the default result and return it in fp0.
#
fmul_may_ovfl:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fmul.x FP_SCR0(%a6),%fp0 # execute multiply
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fabs.x %fp0,%fp1 # make a copy of result
fcmp.b %fp1,&0x2 # is |result| >= 2.b?
fbge.w fmul_ovfl_tst # yes; overflow has occurred
bra.w fmul_normal_exit
#
# - the result of the multiply operation is an underflow.
# - do the multiply to the proper precision and rounding mode in order to
# - calculate the default result and return it in fp0.
# - if overflow or inexact is enabled, we need a multiply result rounded to
#
fmul_unfl:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
fmovm.x FP_SCR1(%a6),&0x80 # load dst operand
fmov.l &rz_mode*0x10,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fmul.x FP_SCR0(%a6),%fp0 # execute multiply
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0b,%d1 # is UNFL or INEX enabled?
bne.b fmul_unfl_ena # yes
fmul_unfl_dis:
fmovm.x &0x80,FP_SCR0(%a6) # store out result
lea FP_SCR0(%a6),%a0 # pass: result addr
mov.l L_SCR3(%a6),%d1 # pass: rnd prec,mode
bsr.l unf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # unf_res2 may have set 'Z'
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
rts
#
#
fmul_unfl_ena:
fmovm.x FP_SCR1(%a6),&0x40 # load dst op
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # is precision extended?
bne.b fmul_unfl_ena_sd # no, sgl or dbl
# if the rnd mode is anything but RZ, then we have to re-do the above
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmul_unfl_ena_cont:
fmov.l &0x0,%fpsr # clear FPSR
fmul.x FP_SCR0(%a6),%fp1 # execute multiply
fmov.l &0x0,%fpcr # clear FPCR
fmovm.x &0x40,FP_SCR0(%a6) # save result to stack
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
addi.l &0x6000,%d1 # add bias
andi.w &0x7fff,%d1
or.w %d2,%d1 # concat old sign,new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
bra.w fmul_unfl_dis
fmul_unfl_ena_sd:
mov.l L_SCR3(%a6),%d1
andi.b &0x30,%d1 # use only rnd mode
fmov.l %d1,%fpcr # set FPCR
bra.b fmul_unfl_ena_cont
# -use the correct rounding mode and precision. this code favors operations
fmul_may_unfl:
fmovm.x FP_SCR1(%a6),&0x80 # load dst operand
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fmul.x FP_SCR0(%a6),%fp0 # execute multiply
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fabs.x %fp0,%fp1 # make a copy of result
fcmp.b %fp1,&0x2 # is |result| > 2.b?
fbgt.w fmul_normal_exit # no; no underflow occurred
fblt.w fmul_unfl # yes; underflow occurred
#
#
fmovm.x FP_SCR1(%a6),&0x40 # load dst operand
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # keep rnd prec
ori.b &rz_mode*0x10,%d1 # insert RZ
fmov.l %d1,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fmul.x FP_SCR0(%a6),%fp1 # execute multiply
fmov.l &0x0,%fpcr # clear FPCR
fabs.x %fp1 # make absolute value
fcmp.b %fp1,&0x2 # is |result| < 2.b?
fbge.w fmul_normal_exit # no; no underflow occurred
bra.w fmul_unfl # yes, underflow occurred
################################################################################
#
#
fmul_not_norm:
mov.w (tbl_fmul_op.b,%pc,%d1.w*2),%d1
jmp (tbl_fmul_op.b,%pc,%d1.w)
swbeg &48
tbl_fmul_op:
short fmul_norm - tbl_fmul_op # NORM x NORM
short fmul_zero - tbl_fmul_op # NORM x ZERO
short fmul_inf_src - tbl_fmul_op # NORM x INF
short fmul_res_qnan - tbl_fmul_op # NORM x QNAN
short fmul_norm - tbl_fmul_op # NORM x DENORM
short fmul_res_snan - tbl_fmul_op # NORM x SNAN
short tbl_fmul_op - tbl_fmul_op #
short tbl_fmul_op - tbl_fmul_op #
short fmul_zero - tbl_fmul_op # ZERO x NORM
short fmul_zero - tbl_fmul_op # ZERO x ZERO
short fmul_res_operr - tbl_fmul_op # ZERO x INF
short fmul_res_qnan - tbl_fmul_op # ZERO x QNAN
short fmul_zero - tbl_fmul_op # ZERO x DENORM
short fmul_res_snan - tbl_fmul_op # ZERO x SNAN
short tbl_fmul_op - tbl_fmul_op #
short tbl_fmul_op - tbl_fmul_op #
short fmul_inf_dst - tbl_fmul_op # INF x NORM
short fmul_res_operr - tbl_fmul_op # INF x ZERO
short fmul_inf_dst - tbl_fmul_op # INF x INF
short fmul_res_qnan - tbl_fmul_op # INF x QNAN
short fmul_inf_dst - tbl_fmul_op # INF x DENORM
short fmul_res_snan - tbl_fmul_op # INF x SNAN
short tbl_fmul_op - tbl_fmul_op #
short tbl_fmul_op - tbl_fmul_op #
short fmul_res_qnan - tbl_fmul_op # QNAN x NORM
short fmul_res_qnan - tbl_fmul_op # QNAN x ZERO
short fmul_res_qnan - tbl_fmul_op # QNAN x INF
short fmul_res_qnan - tbl_fmul_op # QNAN x QNAN
short fmul_res_qnan - tbl_fmul_op # QNAN x DENORM
short fmul_res_snan - tbl_fmul_op # QNAN x SNAN
short tbl_fmul_op - tbl_fmul_op #
short tbl_fmul_op - tbl_fmul_op #
short fmul_norm - tbl_fmul_op # NORM x NORM
short fmul_zero - tbl_fmul_op # NORM x ZERO
short fmul_inf_src - tbl_fmul_op # NORM x INF
short fmul_res_qnan - tbl_fmul_op # NORM x QNAN
short fmul_norm - tbl_fmul_op # NORM x DENORM
short fmul_res_snan - tbl_fmul_op # NORM x SNAN
short tbl_fmul_op - tbl_fmul_op #
short tbl_fmul_op - tbl_fmul_op #
short fmul_res_snan - tbl_fmul_op # SNAN x NORM
short fmul_res_snan - tbl_fmul_op # SNAN x ZERO
short fmul_res_snan - tbl_fmul_op # SNAN x INF
short fmul_res_snan - tbl_fmul_op # SNAN x QNAN
short fmul_res_snan - tbl_fmul_op # SNAN x DENORM
short fmul_res_snan - tbl_fmul_op # SNAN x SNAN
short tbl_fmul_op - tbl_fmul_op #
short tbl_fmul_op - tbl_fmul_op #
fmul_res_operr:
bra.l res_operr
fmul_res_snan:
bra.l res_snan
fmul_res_qnan:
bra.l res_qnan
#
#
global fmul_zero # global for fsglmul
fmul_zero:
mov.b SRC_EX(%a0),%d0 # exclusive or the signs
mov.b DST_EX(%a1),%d1
eor.b %d0,%d1
bpl.b fmul_zero_p # result ZERO is pos.
fmul_zero_n:
fmov.s &0x80000000,%fp0 # load -ZERO
mov.b &z_bmask+neg_bmask,FPSR_CC(%a6) # set Z/N
rts
fmul_zero_p:
fmov.s &0x00000000,%fp0 # load +ZERO
mov.b &z_bmask,FPSR_CC(%a6) # set Z
rts
#
#
#
global fmul_inf_dst # global for fsglmul
fmul_inf_dst:
fmovm.x DST(%a1),&0x80 # return INF result in fp0
mov.b SRC_EX(%a0),%d0 # exclusive or the signs
mov.b DST_EX(%a1),%d1
eor.b %d0,%d1
bpl.b fmul_inf_dst_p # result INF is pos.
fmul_inf_dst_n:
fabs.x %fp0 # clear result sign
fneg.x %fp0 # set result sign
mov.b &inf_bmask+neg_bmask,FPSR_CC(%a6) # set INF/N
rts
fmul_inf_dst_p:
fabs.x %fp0 # clear result sign
mov.b &inf_bmask,FPSR_CC(%a6) # set INF
rts
global fmul_inf_src # global for fsglmul
fmul_inf_src:
fmovm.x SRC(%a0),&0x80 # return INF result in fp0
mov.b SRC_EX(%a0),%d0 # exclusive or the signs
mov.b DST_EX(%a1),%d1
eor.b %d0,%d1
bpl.b fmul_inf_dst_p # result INF is pos.
bra.b fmul_inf_dst_n
#########################################################################
# #
# #
# #
# #
# if the result would have overflowed/underflowed. If so, use unf_res() #
# #
#########################################################################
global fsin
fsin:
andi.b &0x30,%d0 # clear rnd prec
ori.b &s_mode*0x10,%d0 # insert sgl precision
bra.b fin
global fdin
fdin:
andi.b &0x30,%d0 # clear rnd prec
ori.b &d_mode*0x10,%d0 # insert dbl precision
global fin
fin:
mov.l %d0,L_SCR3(%a6) # store rnd info
mov.b STAG(%a6),%d1 # fetch src optype tag
bne.w fin_not_norm # optimize on non-norm input
#
#
fin_norm:
andi.b &0xc0,%d0 # is precision extended?
bne.w fin_not_ext # no, so go handle dbl or sgl
#
#
tst.b SRC_EX(%a0) # is the operand negative?
bpl.b fin_norm_done # no
bset &neg_bit,FPSR_CC(%a6) # yes, so set 'N' ccode bit
fin_norm_done:
fmovm.x SRC(%a0),&0x80 # return result in fp0
rts
#
#
fin_denorm:
andi.b &0xc0,%d0 # is precision extended?
bne.w fin_not_ext # no, so go handle dbl or sgl
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
tst.b SRC_EX(%a0) # is the operand negative?
bpl.b fin_denorm_done # no
bset &neg_bit,FPSR_CC(%a6) # yes, so set 'N' ccode bit
fin_denorm_done:
fmovm.x SRC(%a0),&0x80 # return result in fp0
btst &unfl_bit,FPCR_ENABLE(%a6) # is UNFL enabled?
bne.b fin_denorm_unfl_ena # yes
rts
#
#
fin_denorm_unfl_ena:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
lea FP_SCR0(%a6),%a0 # pass: ptr to operand
bsr.l norm # normalize result
neg.w %d0 # new exponent = -(shft val)
addi.w &0x6000,%d0 # add new bias to exponent
mov.w FP_SCR0_EX(%a6),%d1 # fetch old sign,exp
andi.w &0x8000,%d1 # keep old sign
andi.w &0x7fff,%d0 # clear sign position
or.w %d1,%d0 # concat new exo,old sign
mov.w %d0,FP_SCR0_EX(%a6) # insert new exponent
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
rts
#
#
fin_not_ext:
cmpi.b %d0,&s_mode*0x10 # separate sgl/dbl prec
bne.b fin_dbl
#
#
fin_sgl:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_to_zero_src # calculate scale factor
cmpi.l %d0,&0x3fff-0x3f80 # will move in underflow?
bge.w fin_sd_unfl # yes; go handle underflow
cmpi.l %d0,&0x3fff-0x407e # will move in overflow?
beq.w fin_sd_may_ovfl # maybe; go check
blt.w fin_sd_ovfl # yes; go handle overflow
#
#
fin_sd_normal:
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.x FP_SCR0(%a6),%fp0 # perform move
fmov.l %fpsr,%d1 # save FPSR
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fin_sd_normal_exit:
mov.l %d2,-(%sp) # save d2
fmovm.x &0x80,FP_SCR0(%a6) # store out result
mov.w FP_SCR0_EX(%a6),%d1 # load {sgn,exp}
mov.w %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
sub.l %d0,%d1 # add scale factor
andi.w &0x8000,%d2 # keep old sign
or.w %d1,%d2 # concat old sign,new exponent
mov.w %d2,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x80 # return result in fp0
rts
#
#
fin_dbl:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_to_zero_src # calculate scale factor
cmpi.l %d0,&0x3fff-0x3c00 # will move in underflow?
bge.w fin_sd_unfl # yes; go handle underflow
cmpi.l %d0,&0x3fff-0x43fe # will move in overflow?
beq.w fin_sd_may_ovfl # maybe; go check
blt.w fin_sd_ovfl # yes; go handle overflow
bra.w fin_sd_normal # no; ho handle normalized op
#
#
fin_sd_unfl:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
tst.b FP_SCR0_EX(%a6) # is operand negative?
bpl.b fin_sd_unfl_tst
bset &neg_bit,FPSR_CC(%a6) # set 'N' ccode bit
# if underflow or inexact is enabled, then go calculate the EXOP first.
fin_sd_unfl_tst:
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0b,%d1 # is UNFL or INEX enabled?
bne.b fin_sd_unfl_ena # yes
fin_sd_unfl_dis:
lea FP_SCR0(%a6),%a0 # pass: result addr
mov.l L_SCR3(%a6),%d1 # pass: rnd prec,mode
bsr.l unf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # unf_res may have set 'Z'
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
rts
#
#
fin_sd_unfl_ena:
mov.l FP_SCR0_HI(%a6),FP_SCR1_HI(%a6)
mov.l FP_SCR0_LO(%a6),FP_SCR1_LO(%a6)
mov.w FP_SCR0_EX(%a6),%d1 # load current exponent
mov.l %d2,-(%sp) # save d2
mov.w %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
sub.l %d0,%d1 # subtract scale factor
andi.w &0x8000,%d2 # extract old sign
addi.l &0x6000,%d1 # add new bias
andi.w &0x7fff,%d1
or.w %d1,%d2 # concat old sign,new exp
mov.w %d2,FP_SCR1_EX(%a6) # insert new exponent
fmovm.x FP_SCR1(%a6),&0x40 # return EXOP in fp1
mov.l (%sp)+,%d2 # restore d2
bra.b fin_sd_unfl_dis
#
#
fin_sd_ovfl:
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.x FP_SCR0(%a6),%fp0 # perform move
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d1 # save FPSR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fin_sd_ovfl_tst:
or.l &ovfl_inx_mask,USER_FPSR(%a6) # set ovfl/aovfl/ainex
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x13,%d1 # is OVFL or INEX enabled?
bne.b fin_sd_ovfl_ena # yes
#
#
fin_sd_ovfl_dis:
btst &neg_bit,FPSR_CC(%a6) # is result negative?
sne %d1 # set sign param accordingly
mov.l L_SCR3(%a6),%d0 # pass: prec,mode
bsr.l ovf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # set INF,N if applicable
fmovm.x (%a0),&0x80 # return default result in fp0
rts
#
#
fin_sd_ovfl_ena:
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
sub.l &0x6000,%d1 # subtract bias
andi.w &0x7fff,%d1
or.w %d2,%d1
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
bra.b fin_sd_ovfl_dis
#
#
fin_sd_may_ovfl:
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.x FP_SCR0(%a6),%fp0 # perform the move
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fabs.x %fp0,%fp1 # make a copy of result
fcmp.b %fp1,&0x2 # is |result| >= 2.b?
fbge.w fin_sd_ovfl_tst # yes; overflow has occurred
bra.w fin_sd_normal_exit
##########################################################################
#
#
fin_not_norm:
cmpi.b %d1,&DENORM # weed out DENORM
beq.w fin_denorm
cmpi.b %d1,&SNAN # weed out SNANs
beq.l res_snan_1op
cmpi.b %d1,&QNAN # weed out QNANs
beq.l res_qnan_1op
#
#
fmov.x SRC(%a0),%fp0 # do fmove in
fmov.l %fpsr,%d0 # no exceptions possible
rol.l &0x8,%d0 # put ccodes in lo byte
mov.b %d0,FPSR_CC(%a6) # insert correct ccodes
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
align 0x10
tbl_fdiv_unfl:
long 0x3fff - 0x0000 # ext_unfl
long 0x3fff - 0x3f81 # sgl_unfl
long 0x3fff - 0x3c01 # dbl_unfl
tbl_fdiv_ovfl:
long 0x3fff - 0x7ffe # ext overflow exponent
long 0x3fff - 0x407e # sgl overflow exponent
long 0x3fff - 0x43fe # dbl overflow exponent
global fsdiv
fsdiv:
andi.b &0x30,%d0 # clear rnd prec
ori.b &s_mode*0x10,%d0 # insert sgl prec
bra.b fdiv
global fddiv
fddiv:
andi.b &0x30,%d0 # clear rnd prec
ori.b &d_mode*0x10,%d0 # insert dbl prec
global fdiv
fdiv:
mov.l %d0,L_SCR3(%a6) # store rnd info
clr.w %d1
mov.b DTAG(%a6),%d1
lsl.b &0x3,%d1
or.b STAG(%a6),%d1 # combine src tags
bne.w fdiv_not_norm # optimize on non-norm input
#
#
fdiv_norm:
mov.w DST_EX(%a1),FP_SCR1_EX(%a6)
mov.l DST_HI(%a1),FP_SCR1_HI(%a6)
mov.l DST_LO(%a1),FP_SCR1_LO(%a6)
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_to_zero_src # scale src exponent
mov.l %d0,-(%sp) # save scale factor 1
bsr.l scale_to_zero_dst # scale dst exponent
neg.l (%sp) # SCALE FACTOR = scale1 - scale2
add.l %d0,(%sp)
mov.w 2+L_SCR3(%a6),%d1 # fetch precision
lsr.b &0x6,%d1 # shift to lo bits
mov.l (%sp)+,%d0 # load S.F.
cmp.l %d0,(tbl_fdiv_ovfl.b,%pc,%d1.w*4) # will result overflow?
ble.w fdiv_may_ovfl # result will overflow
cmp.l %d0,(tbl_fdiv_unfl.w,%pc,%d1.w*4) # will result underflow?
beq.w fdiv_may_unfl # maybe
bgt.w fdiv_unfl # yes; go handle underflow
fdiv_normal:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l L_SCR3(%a6),%fpcr # save FPCR
fmov.l &0x0,%fpsr # clear FPSR
fdiv.x FP_SCR0(%a6),%fp0 # perform divide
fmov.l %fpsr,%d1 # save FPSR
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fdiv_normal_exit:
fmovm.x &0x80,FP_SCR0(%a6) # store result on stack
mov.l %d2,-(%sp) # store d2
mov.w FP_SCR0_EX(%a6),%d1 # load {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
or.w %d2,%d1 # concat old sign,new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x80 # return result in fp0
rts
tbl_fdiv_ovfl2:
long 0x7fff
long 0x407f
long 0x43ff
fdiv_no_ovfl:
mov.l (%sp)+,%d0 # restore scale factor
bra.b fdiv_normal_exit
fdiv_may_ovfl:
mov.l %d0,-(%sp) # save scale factor
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # set FPSR
fdiv.x FP_SCR0(%a6),%fp0 # execute divide
fmov.l %fpsr,%d0
fmov.l &0x0,%fpcr
or.l %d0,USER_FPSR(%a6) # save INEX,N
fmovm.x &0x01,-(%sp) # save result to stack
mov.w (%sp),%d0 # fetch new exponent
add.l &0xc,%sp # clear result from stack
andi.l &0x7fff,%d0 # strip sign
sub.l (%sp),%d0 # add scale factor
cmp.l %d0,(tbl_fdiv_ovfl2.b,%pc,%d1.w*4)
blt.b fdiv_no_ovfl
mov.l (%sp)+,%d0
fdiv_ovfl_tst:
or.l &ovfl_inx_mask,USER_FPSR(%a6) # set ovfl/aovfl/ainex
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x13,%d1 # is OVFL or INEX enabled?
bne.b fdiv_ovfl_ena # yes
fdiv_ovfl_dis:
btst &neg_bit,FPSR_CC(%a6) # is result negative?
sne %d1 # set sign param accordingly
mov.l L_SCR3(%a6),%d0 # pass prec:rnd
bsr.l ovf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # set INF if applicable
fmovm.x (%a0),&0x80 # return default result in fp0
rts
fdiv_ovfl_ena:
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # is precision extended?
bne.b fdiv_ovfl_ena_sd # no, do sgl or dbl
fdiv_ovfl_ena_cont:
fmovm.x &0x80,FP_SCR0(%a6) # move result to stack
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.w %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
sub.l %d0,%d1 # add scale factor
subi.l &0x6000,%d1 # subtract bias
andi.w &0x7fff,%d1 # clear sign bit
andi.w &0x8000,%d2 # keep old sign
or.w %d2,%d1 # concat old sign,new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
bra.b fdiv_ovfl_dis
fdiv_ovfl_ena_sd:
fmovm.x FP_SCR1(%a6),&0x80 # load dst operand
mov.l L_SCR3(%a6),%d1
andi.b &0x30,%d1 # keep rnd mode
fmov.l %d1,%fpcr # set FPCR
fdiv.x FP_SCR0(%a6),%fp0 # execute divide
fmov.l &0x0,%fpcr # clear FPCR
bra.b fdiv_ovfl_ena_cont
fdiv_unfl:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l &rz_mode*0x10,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fdiv.x FP_SCR0(%a6),%fp0 # execute divide
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0b,%d1 # is UNFL or INEX enabled?
bne.b fdiv_unfl_ena # yes
fdiv_unfl_dis:
fmovm.x &0x80,FP_SCR0(%a6) # store out result
lea FP_SCR0(%a6),%a0 # pass: result addr
mov.l L_SCR3(%a6),%d1 # pass: rnd prec,mode
bsr.l unf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # 'Z' may have been set
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
rts
#
#
fdiv_unfl_ena:
fmovm.x FP_SCR1(%a6),&0x40 # load dst op
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # is precision extended?
bne.b fdiv_unfl_ena_sd # no, sgl or dbl
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fdiv_unfl_ena_cont:
fmov.l &0x0,%fpsr # clear FPSR
fdiv.x FP_SCR0(%a6),%fp1 # execute divide
fmov.l &0x0,%fpcr # clear FPCR
fmovm.x &0x40,FP_SCR0(%a6) # save result to stack
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factoer
addi.l &0x6000,%d1 # add bias
andi.w &0x7fff,%d1
or.w %d2,%d1 # concat old sign,new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exp
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
bra.w fdiv_unfl_dis
fdiv_unfl_ena_sd:
mov.l L_SCR3(%a6),%d1
andi.b &0x30,%d1 # use only rnd mode
fmov.l %d1,%fpcr # set FPCR
bra.b fdiv_unfl_ena_cont
#
#
fdiv_may_unfl:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fdiv.x FP_SCR0(%a6),%fp0 # execute divide
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fabs.x %fp0,%fp1 # make a copy of result
fcmp.b %fp1,&0x1 # is |result| > 1.b?
fbgt.w fdiv_normal_exit # no; no underflow occurred
fblt.w fdiv_unfl # yes; underflow occurred
#
#
fmovm.x FP_SCR1(%a6),&0x40 # load dst op into fp1
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # keep rnd prec
ori.b &rz_mode*0x10,%d1 # insert RZ
fmov.l %d1,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fdiv.x FP_SCR0(%a6),%fp1 # execute divide
fmov.l &0x0,%fpcr # clear FPCR
fabs.x %fp1 # make absolute value
fcmp.b %fp1,&0x1 # is |result| < 1.b?
fbge.w fdiv_normal_exit # no; no underflow occurred
bra.w fdiv_unfl # yes; underflow occurred
############################################################################
#
#
fdiv_not_norm:
mov.w (tbl_fdiv_op.b,%pc,%d1.w*2),%d1
jmp (tbl_fdiv_op.b,%pc,%d1.w*1)
swbeg &48
tbl_fdiv_op:
short fdiv_norm - tbl_fdiv_op # NORM / NORM
short fdiv_inf_load - tbl_fdiv_op # NORM / ZERO
short fdiv_zero_load - tbl_fdiv_op # NORM / INF
short fdiv_res_qnan - tbl_fdiv_op # NORM / QNAN
short fdiv_norm - tbl_fdiv_op # NORM / DENORM
short fdiv_res_snan - tbl_fdiv_op # NORM / SNAN
short tbl_fdiv_op - tbl_fdiv_op #
short tbl_fdiv_op - tbl_fdiv_op #
short fdiv_zero_load - tbl_fdiv_op # ZERO / NORM
short fdiv_res_operr - tbl_fdiv_op # ZERO / ZERO
short fdiv_zero_load - tbl_fdiv_op # ZERO / INF
short fdiv_res_qnan - tbl_fdiv_op # ZERO / QNAN
short fdiv_zero_load - tbl_fdiv_op # ZERO / DENORM
short fdiv_res_snan - tbl_fdiv_op # ZERO / SNAN
short tbl_fdiv_op - tbl_fdiv_op #
short tbl_fdiv_op - tbl_fdiv_op #
short fdiv_inf_dst - tbl_fdiv_op # INF / NORM
short fdiv_inf_dst - tbl_fdiv_op # INF / ZERO
short fdiv_res_operr - tbl_fdiv_op # INF / INF
short fdiv_res_qnan - tbl_fdiv_op # INF / QNAN
short fdiv_inf_dst - tbl_fdiv_op # INF / DENORM
short fdiv_res_snan - tbl_fdiv_op # INF / SNAN
short tbl_fdiv_op - tbl_fdiv_op #
short tbl_fdiv_op - tbl_fdiv_op #
short fdiv_res_qnan - tbl_fdiv_op # QNAN / NORM
short fdiv_res_qnan - tbl_fdiv_op # QNAN / ZERO
short fdiv_res_qnan - tbl_fdiv_op # QNAN / INF
short fdiv_res_qnan - tbl_fdiv_op # QNAN / QNAN
short fdiv_res_qnan - tbl_fdiv_op # QNAN / DENORM
short fdiv_res_snan - tbl_fdiv_op # QNAN / SNAN
short tbl_fdiv_op - tbl_fdiv_op #
short tbl_fdiv_op - tbl_fdiv_op #
short fdiv_norm - tbl_fdiv_op # DENORM / NORM
short fdiv_inf_load - tbl_fdiv_op # DENORM / ZERO
short fdiv_zero_load - tbl_fdiv_op # DENORM / INF
short fdiv_res_qnan - tbl_fdiv_op # DENORM / QNAN
short fdiv_norm - tbl_fdiv_op # DENORM / DENORM
short fdiv_res_snan - tbl_fdiv_op # DENORM / SNAN
short tbl_fdiv_op - tbl_fdiv_op #
short tbl_fdiv_op - tbl_fdiv_op #
short fdiv_res_snan - tbl_fdiv_op # SNAN / NORM
short fdiv_res_snan - tbl_fdiv_op # SNAN / ZERO
short fdiv_res_snan - tbl_fdiv_op # SNAN / INF
short fdiv_res_snan - tbl_fdiv_op # SNAN / QNAN
short fdiv_res_snan - tbl_fdiv_op # SNAN / DENORM
short fdiv_res_snan - tbl_fdiv_op # SNAN / SNAN
short tbl_fdiv_op - tbl_fdiv_op #
short tbl_fdiv_op - tbl_fdiv_op #
fdiv_res_qnan:
bra.l res_qnan
fdiv_res_snan:
bra.l res_snan
fdiv_res_operr:
bra.l res_operr
global fdiv_zero_load # global for fsgldiv
fdiv_zero_load:
mov.b SRC_EX(%a0),%d0 # result sign is exclusive
mov.b DST_EX(%a1),%d1 # or of input signs.
eor.b %d0,%d1
bpl.b fdiv_zero_load_p # result is positive
fmov.s &0x80000000,%fp0 # load a -ZERO
mov.b &z_bmask+neg_bmask,FPSR_CC(%a6) # set Z/N
rts
fdiv_zero_load_p:
fmov.s &0x00000000,%fp0 # load a +ZERO
mov.b &z_bmask,FPSR_CC(%a6) # set Z
rts
#
#
global fdiv_inf_load # global for fsgldiv
fdiv_inf_load:
ori.w &dz_mask+adz_mask,2+USER_FPSR(%a6) # no; set DZ/ADZ
mov.b SRC_EX(%a0),%d0 # load both signs
mov.b DST_EX(%a1),%d1
eor.b %d0,%d1
bpl.b fdiv_inf_load_p # result is positive
fmov.s &0xff800000,%fp0 # make result -INF
mov.b &inf_bmask+neg_bmask,FPSR_CC(%a6) # set INF/N
rts
fdiv_inf_load_p:
fmov.s &0x7f800000,%fp0 # make result +INF
mov.b &inf_bmask,FPSR_CC(%a6) # set INF
rts
#
#
global fdiv_inf_dst # global for fsgldiv
fdiv_inf_dst:
mov.b DST_EX(%a1),%d0 # load both signs
mov.b SRC_EX(%a0),%d1
eor.b %d0,%d1
bpl.b fdiv_inf_dst_p # result is positive
fmovm.x DST(%a1),&0x80 # return result in fp0
fabs.x %fp0 # clear sign bit
fneg.x %fp0 # set sign bit
mov.b &inf_bmask+neg_bmask,FPSR_CC(%a6) # set INF/NEG
rts
fdiv_inf_dst_p:
fmovm.x DST(%a1),&0x80 # return result in fp0
fabs.x %fp0 # return positive INF
mov.b &inf_bmask,FPSR_CC(%a6) # set INF
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global fsneg
fsneg:
andi.b &0x30,%d0 # clear rnd prec
ori.b &s_mode*0x10,%d0 # insert sgl precision
bra.b fneg
global fdneg
fdneg:
andi.b &0x30,%d0 # clear rnd prec
ori.b &d_mode*0x10,%d0 # insert dbl prec
global fneg
fneg:
mov.l %d0,L_SCR3(%a6) # store rnd info
mov.b STAG(%a6),%d1
bne.w fneg_not_norm # optimize on non-norm input
#
#
fneg_norm:
andi.b &0xc0,%d0 # is precision extended?
bne.w fneg_not_ext # no; go handle sgl or dbl
#
#
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
mov.w SRC_EX(%a0),%d0
eori.w &0x8000,%d0 # negate sign
bpl.b fneg_norm_load # sign is positive
mov.b &neg_bmask,FPSR_CC(%a6) # set 'N' ccode bit
fneg_norm_load:
mov.w %d0,FP_SCR0_EX(%a6)
fmovm.x FP_SCR0(%a6),&0x80 # return result in fp0
rts
#
#
fneg_denorm:
andi.b &0xc0,%d0 # is precision extended?
bne.b fneg_not_ext # no; go handle sgl or dbl
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
mov.w SRC_EX(%a0),%d0
eori.w &0x8000,%d0 # negate sign
bpl.b fneg_denorm_done # no
mov.b &neg_bmask,FPSR_CC(%a6) # yes, set 'N' ccode bit
fneg_denorm_done:
mov.w %d0,FP_SCR0_EX(%a6)
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
btst &unfl_bit,FPCR_ENABLE(%a6) # is UNFL enabled?
bne.b fneg_ext_unfl_ena # yes
rts
#
#
fneg_ext_unfl_ena:
lea FP_SCR0(%a6),%a0 # pass: ptr to operand
bsr.l norm # normalize result
neg.w %d0 # new exponent = -(shft val)
addi.w &0x6000,%d0 # add new bias to exponent
mov.w FP_SCR0_EX(%a6),%d1 # fetch old sign,exp
andi.w &0x8000,%d1 # keep old sign
andi.w &0x7fff,%d0 # clear sign position
or.w %d1,%d0 # concat old sign, new exponent
mov.w %d0,FP_SCR0_EX(%a6) # insert new exponent
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
rts
#
#
fneg_not_ext:
cmpi.b %d0,&s_mode*0x10 # separate sgl/dbl prec
bne.b fneg_dbl
#
#
fneg_sgl:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_to_zero_src # calculate scale factor
cmpi.l %d0,&0x3fff-0x3f80 # will move in underflow?
bge.w fneg_sd_unfl # yes; go handle underflow
cmpi.l %d0,&0x3fff-0x407e # will move in overflow?
beq.w fneg_sd_may_ovfl # maybe; go check
blt.w fneg_sd_ovfl # yes; go handle overflow
#
#
fneg_sd_normal:
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fneg.x FP_SCR0(%a6),%fp0 # perform negation
fmov.l %fpsr,%d1 # save FPSR
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fneg_sd_normal_exit:
mov.l %d2,-(%sp) # save d2
fmovm.x &0x80,FP_SCR0(%a6) # store out result
mov.w FP_SCR0_EX(%a6),%d1 # load sgn,exp
mov.w %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
sub.l %d0,%d1 # add scale factor
andi.w &0x8000,%d2 # keep old sign
or.w %d1,%d2 # concat old sign,new exp
mov.w %d2,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x80 # return result in fp0
rts
#
#
fneg_dbl:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_to_zero_src # calculate scale factor
cmpi.l %d0,&0x3fff-0x3c00 # will move in underflow?
bge.b fneg_sd_unfl # yes; go handle underflow
cmpi.l %d0,&0x3fff-0x43fe # will move in overflow?
beq.w fneg_sd_may_ovfl # maybe; go check
blt.w fneg_sd_ovfl # yes; go handle overflow
bra.w fneg_sd_normal # no; ho handle normalized op
#
#
fneg_sd_unfl:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
eori.b &0x80,FP_SCR0_EX(%a6) # negate sign
bpl.b fneg_sd_unfl_tst
bset &neg_bit,FPSR_CC(%a6) # set 'N' ccode bit
# if underflow or inexact is enabled, go calculate EXOP first.
fneg_sd_unfl_tst:
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0b,%d1 # is UNFL or INEX enabled?
bne.b fneg_sd_unfl_ena # yes
fneg_sd_unfl_dis:
lea FP_SCR0(%a6),%a0 # pass: result addr
mov.l L_SCR3(%a6),%d1 # pass: rnd prec,mode
bsr.l unf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # unf_res may have set 'Z'
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
rts
#
#
fneg_sd_unfl_ena:
mov.l FP_SCR0_HI(%a6),FP_SCR1_HI(%a6)
mov.l FP_SCR0_LO(%a6),FP_SCR1_LO(%a6)
mov.w FP_SCR0_EX(%a6),%d1 # load current exponent
mov.l %d2,-(%sp) # save d2
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # subtract scale factor
addi.l &0x6000,%d1 # add new bias
andi.w &0x7fff,%d1
or.w %d2,%d1 # concat new sign,new exp
mov.w %d1,FP_SCR1_EX(%a6) # insert new exp
fmovm.x FP_SCR1(%a6),&0x40 # return EXOP in fp1
mov.l (%sp)+,%d2 # restore d2
bra.b fneg_sd_unfl_dis
#
#
fneg_sd_ovfl:
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fneg.x FP_SCR0(%a6),%fp0 # perform negation
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d1 # save FPSR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fneg_sd_ovfl_tst:
or.l &ovfl_inx_mask,USER_FPSR(%a6) # set ovfl/aovfl/ainex
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x13,%d1 # is OVFL or INEX enabled?
bne.b fneg_sd_ovfl_ena # yes
#
#
fneg_sd_ovfl_dis:
btst &neg_bit,FPSR_CC(%a6) # is result negative?
sne %d1 # set sign param accordingly
mov.l L_SCR3(%a6),%d0 # pass: prec,mode
bsr.l ovf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # set INF,N if applicable
fmovm.x (%a0),&0x80 # return default result in fp0
rts
#
#
fneg_sd_ovfl_ena:
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
subi.l &0x6000,%d1 # subtract bias
andi.w &0x7fff,%d1
or.w %d2,%d1 # concat sign,exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
mov.l (%sp)+,%d2 # restore d2
bra.b fneg_sd_ovfl_dis
#
#
fneg_sd_may_ovfl:
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fneg.x FP_SCR0(%a6),%fp0 # perform negation
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fabs.x %fp0,%fp1 # make a copy of result
fcmp.b %fp1,&0x2 # is |result| >= 2.b?
fbge.w fneg_sd_ovfl_tst # yes; overflow has occurred
bra.w fneg_sd_normal_exit
##########################################################################
#
#
fneg_not_norm:
cmpi.b %d1,&DENORM # weed out DENORM
beq.w fneg_denorm
cmpi.b %d1,&SNAN # weed out SNAN
beq.l res_snan_1op
cmpi.b %d1,&QNAN # weed out QNAN
beq.l res_qnan_1op
#
#
fneg.x SRC_EX(%a0),%fp0 # do fneg
fmov.l %fpsr,%d0
rol.l &0x8,%d0 # put ccodes in lo byte
mov.b %d0,FPSR_CC(%a6) # insert correct ccodes
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global ftst
ftst:
mov.b STAG(%a6),%d1
bne.b ftst_not_norm # optimize on non-norm input
#
#
ftst_norm:
tst.b SRC_EX(%a0) # is operand negative?
bmi.b ftst_norm_m # yes
rts
ftst_norm_m:
mov.b &neg_bmask,FPSR_CC(%a6) # set 'N' ccode bit
rts
#
#
ftst_not_norm:
cmpi.b %d1,&ZERO # weed out ZERO
beq.b ftst_zero
cmpi.b %d1,&INF # weed out INF
beq.b ftst_inf
cmpi.b %d1,&SNAN # weed out SNAN
beq.l res_snan_1op
cmpi.b %d1,&QNAN # weed out QNAN
beq.l res_qnan_1op
#
#
ftst_denorm:
tst.b SRC_EX(%a0) # is operand negative?
bmi.b ftst_denorm_m # yes
rts
ftst_denorm_m:
mov.b &neg_bmask,FPSR_CC(%a6) # set 'N' ccode bit
rts
#
#
ftst_inf:
tst.b SRC_EX(%a0) # is operand negative?
bmi.b ftst_inf_m # yes
ftst_inf_p:
mov.b &inf_bmask,FPSR_CC(%a6) # set 'I' ccode bit
rts
ftst_inf_m:
mov.b &inf_bmask+neg_bmask,FPSR_CC(%a6) # set 'I','N' ccode bits
rts
#
#
ftst_zero:
tst.b SRC_EX(%a0) # is operand negative?
bmi.b ftst_zero_m # yes
ftst_zero_p:
mov.b &z_bmask,FPSR_CC(%a6) # set 'N' ccode bit
rts
ftst_zero_m:
mov.b &z_bmask+neg_bmask,FPSR_CC(%a6) # set 'Z','N' ccode bits
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global fint
fint:
mov.b STAG(%a6),%d1
bne.b fint_not_norm # optimize on non-norm input
#
#
fint_norm:
andi.b &0x30,%d0 # set prec = ext
fmov.l %d0,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fint.x SRC(%a0),%fp0 # execute fint
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d0 # save FPSR
or.l %d0,USER_FPSR(%a6) # set exception bits
rts
#
#
fint_not_norm:
cmpi.b %d1,&ZERO # weed out ZERO
beq.b fint_zero
cmpi.b %d1,&INF # weed out INF
beq.b fint_inf
cmpi.b %d1,&DENORM # weed out DENORM
beq.b fint_denorm
cmpi.b %d1,&SNAN # weed out SNAN
beq.l res_snan_1op
bra.l res_qnan_1op # weed out QNAN
#
#
#
fint_denorm:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6) # copy sign, zero exp
mov.b &0x80,FP_SCR0_HI(%a6) # force DENORM ==> small NORM
lea FP_SCR0(%a6),%a0
bra.b fint_norm
#
#
fint_zero:
tst.b SRC_EX(%a0) # is ZERO negative?
bmi.b fint_zero_m # yes
fint_zero_p:
fmov.s &0x00000000,%fp0 # return +ZERO in fp0
mov.b &z_bmask,FPSR_CC(%a6) # set 'Z' ccode bit
rts
fint_zero_m:
fmov.s &0x80000000,%fp0 # return -ZERO in fp0
mov.b &z_bmask+neg_bmask,FPSR_CC(%a6) # set 'Z','N' ccode bits
rts
#
#
fint_inf:
fmovm.x SRC(%a0),&0x80 # return result in fp0
tst.b SRC_EX(%a0) # is INF negative?
bmi.b fint_inf_m # yes
fint_inf_p:
mov.b &inf_bmask,FPSR_CC(%a6) # set 'I' ccode bit
rts
fint_inf_m:
mov.b &inf_bmask+neg_bmask,FPSR_CC(%a6) # set 'N','I' ccode bits
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global fintrz
fintrz:
mov.b STAG(%a6),%d1
bne.b fintrz_not_norm # optimize on non-norm input
#
#
fintrz_norm:
fmov.l &0x0,%fpsr # clear FPSR
fintrz.x SRC(%a0),%fp0 # execute fintrz
fmov.l %fpsr,%d0 # save FPSR
or.l %d0,USER_FPSR(%a6) # set exception bits
rts
#
#
fintrz_not_norm:
cmpi.b %d1,&ZERO # weed out ZERO
beq.b fintrz_zero
cmpi.b %d1,&INF # weed out INF
beq.b fintrz_inf
cmpi.b %d1,&DENORM # weed out DENORM
beq.b fintrz_denorm
cmpi.b %d1,&SNAN # weed out SNAN
beq.l res_snan_1op
bra.l res_qnan_1op # weed out QNAN
#
#
#
fintrz_denorm:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6) # copy sign, zero exp
mov.b &0x80,FP_SCR0_HI(%a6) # force DENORM ==> small NORM
lea FP_SCR0(%a6),%a0
bra.b fintrz_norm
#
#
fintrz_zero:
tst.b SRC_EX(%a0) # is ZERO negative?
bmi.b fintrz_zero_m # yes
fintrz_zero_p:
fmov.s &0x00000000,%fp0 # return +ZERO in fp0
mov.b &z_bmask,FPSR_CC(%a6) # set 'Z' ccode bit
rts
fintrz_zero_m:
fmov.s &0x80000000,%fp0 # return -ZERO in fp0
mov.b &z_bmask+neg_bmask,FPSR_CC(%a6) # set 'Z','N' ccode bits
rts
#
#
fintrz_inf:
fmovm.x SRC(%a0),&0x80 # return result in fp0
tst.b SRC_EX(%a0) # is INF negative?
bmi.b fintrz_inf_m # yes
fintrz_inf_p:
mov.b &inf_bmask,FPSR_CC(%a6) # set 'I' ccode bit
rts
fintrz_inf_m:
mov.b &inf_bmask+neg_bmask,FPSR_CC(%a6) # set 'N','I' ccode bits
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global fsabs
fsabs:
andi.b &0x30,%d0 # clear rnd prec
ori.b &s_mode*0x10,%d0 # insert sgl precision
bra.b fabs
global fdabs
fdabs:
andi.b &0x30,%d0 # clear rnd prec
ori.b &d_mode*0x10,%d0 # insert dbl precision
global fabs
fabs:
mov.l %d0,L_SCR3(%a6) # store rnd info
mov.b STAG(%a6),%d1
bne.w fabs_not_norm # optimize on non-norm input
#
#
fabs_norm:
andi.b &0xc0,%d0 # is precision extended?
bne.b fabs_not_ext # no; go handle sgl or dbl
#
#
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
mov.w SRC_EX(%a0),%d1
bclr &15,%d1 # force absolute value
mov.w %d1,FP_SCR0_EX(%a6) # insert exponent
fmovm.x FP_SCR0(%a6),&0x80 # return result in fp0
rts
#
#
fabs_denorm:
andi.b &0xc0,%d0 # is precision extended?
bne.b fabs_not_ext # no
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
mov.w SRC_EX(%a0),%d0
bclr &15,%d0 # clear sign
mov.w %d0,FP_SCR0_EX(%a6) # insert exponent
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
btst &unfl_bit,FPCR_ENABLE(%a6) # is UNFL enabled?
bne.b fabs_ext_unfl_ena
rts
#
#
fabs_ext_unfl_ena:
lea FP_SCR0(%a6),%a0 # pass: ptr to operand
bsr.l norm # normalize result
neg.w %d0 # new exponent = -(shft val)
addi.w &0x6000,%d0 # add new bias to exponent
mov.w FP_SCR0_EX(%a6),%d1 # fetch old sign,exp
andi.w &0x8000,%d1 # keep old sign
andi.w &0x7fff,%d0 # clear sign position
or.w %d1,%d0 # concat old sign, new exponent
mov.w %d0,FP_SCR0_EX(%a6) # insert new exponent
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
rts
#
#
fabs_not_ext:
cmpi.b %d0,&s_mode*0x10 # separate sgl/dbl prec
bne.b fabs_dbl
#
#
fabs_sgl:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_to_zero_src # calculate scale factor
cmpi.l %d0,&0x3fff-0x3f80 # will move in underflow?
bge.w fabs_sd_unfl # yes; go handle underflow
cmpi.l %d0,&0x3fff-0x407e # will move in overflow?
beq.w fabs_sd_may_ovfl # maybe; go check
blt.w fabs_sd_ovfl # yes; go handle overflow
#
#
fabs_sd_normal:
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fabs.x FP_SCR0(%a6),%fp0 # perform absolute
fmov.l %fpsr,%d1 # save FPSR
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fabs_sd_normal_exit:
mov.l %d2,-(%sp) # save d2
fmovm.x &0x80,FP_SCR0(%a6) # store out result
mov.w FP_SCR0_EX(%a6),%d1 # load sgn,exp
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
sub.l %d0,%d1 # add scale factor
andi.w &0x8000,%d2 # keep old sign
or.w %d1,%d2 # concat old sign,new exp
mov.w %d2,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x80 # return result in fp0
rts
#
#
fabs_dbl:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_to_zero_src # calculate scale factor
cmpi.l %d0,&0x3fff-0x3c00 # will move in underflow?
bge.b fabs_sd_unfl # yes; go handle underflow
cmpi.l %d0,&0x3fff-0x43fe # will move in overflow?
beq.w fabs_sd_may_ovfl # maybe; go check
blt.w fabs_sd_ovfl # yes; go handle overflow
bra.w fabs_sd_normal # no; ho handle normalized op
#
#
fabs_sd_unfl:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
bclr &0x7,FP_SCR0_EX(%a6) # force absolute value
# if underflow or inexact is enabled, go calculate EXOP first.
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0b,%d1 # is UNFL or INEX enabled?
bne.b fabs_sd_unfl_ena # yes
fabs_sd_unfl_dis:
lea FP_SCR0(%a6),%a0 # pass: result addr
mov.l L_SCR3(%a6),%d1 # pass: rnd prec,mode
bsr.l unf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # set possible 'Z' ccode
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
rts
#
#
fabs_sd_unfl_ena:
mov.l FP_SCR0_HI(%a6),FP_SCR1_HI(%a6)
mov.l FP_SCR0_LO(%a6),FP_SCR1_LO(%a6)
mov.w FP_SCR0_EX(%a6),%d1 # load current exponent
mov.l %d2,-(%sp) # save d2
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # subtract scale factor
addi.l &0x6000,%d1 # add new bias
andi.w &0x7fff,%d1
or.w %d2,%d1 # concat new sign,new exp
mov.w %d1,FP_SCR1_EX(%a6) # insert new exp
fmovm.x FP_SCR1(%a6),&0x40 # return EXOP in fp1
mov.l (%sp)+,%d2 # restore d2
bra.b fabs_sd_unfl_dis
#
#
fabs_sd_ovfl:
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fabs.x FP_SCR0(%a6),%fp0 # perform absolute
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d1 # save FPSR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fabs_sd_ovfl_tst:
or.l &ovfl_inx_mask,USER_FPSR(%a6) # set ovfl/aovfl/ainex
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x13,%d1 # is OVFL or INEX enabled?
bne.b fabs_sd_ovfl_ena # yes
#
#
fabs_sd_ovfl_dis:
btst &neg_bit,FPSR_CC(%a6) # is result negative?
sne %d1 # set sign param accordingly
mov.l L_SCR3(%a6),%d0 # pass: prec,mode
bsr.l ovf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # set INF,N if applicable
fmovm.x (%a0),&0x80 # return default result in fp0
rts
#
#
fabs_sd_ovfl_ena:
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
subi.l &0x6000,%d1 # subtract bias
andi.w &0x7fff,%d1
or.w %d2,%d1 # concat sign,exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
mov.l (%sp)+,%d2 # restore d2
bra.b fabs_sd_ovfl_dis
#
#
fabs_sd_may_ovfl:
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fabs.x FP_SCR0(%a6),%fp0 # perform absolute
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fabs.x %fp0,%fp1 # make a copy of result
fcmp.b %fp1,&0x2 # is |result| >= 2.b?
fbge.w fabs_sd_ovfl_tst # yes; overflow has occurred
bra.w fabs_sd_normal_exit
##########################################################################
#
#
fabs_not_norm:
cmpi.b %d1,&DENORM # weed out DENORM
beq.w fabs_denorm
cmpi.b %d1,&SNAN # weed out SNAN
beq.l res_snan_1op
cmpi.b %d1,&QNAN # weed out QNAN
beq.l res_qnan_1op
fabs.x SRC(%a0),%fp0 # force absolute value
cmpi.b %d1,&INF # weed out INF
beq.b fabs_inf
fabs_zero:
mov.b &z_bmask,FPSR_CC(%a6) # set 'Z' ccode bit
rts
fabs_inf:
mov.b &inf_bmask,FPSR_CC(%a6) # set 'I' ccode bit
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global fcmp
fcmp:
clr.w %d1
mov.b DTAG(%a6),%d1
lsl.b &0x3,%d1
or.b STAG(%a6),%d1
bne.b fcmp_not_norm # optimize on non-norm input
#
#
fcmp_norm:
fmovm.x DST(%a1),&0x80 # load dst op
fcmp.x %fp0,SRC(%a0) # do compare
fmov.l %fpsr,%d0 # save FPSR
rol.l &0x8,%d0 # extract ccode bits
mov.b %d0,FPSR_CC(%a6) # set ccode bits(no exc bits are set)
rts
#
#
fcmp_not_norm:
mov.w (tbl_fcmp_op.b,%pc,%d1.w*2),%d1
jmp (tbl_fcmp_op.b,%pc,%d1.w*1)
swbeg &48
tbl_fcmp_op:
short fcmp_norm - tbl_fcmp_op # NORM - NORM
short fcmp_norm - tbl_fcmp_op # NORM - ZERO
short fcmp_norm - tbl_fcmp_op # NORM - INF
short fcmp_res_qnan - tbl_fcmp_op # NORM - QNAN
short fcmp_nrm_dnrm - tbl_fcmp_op # NORM - DENORM
short fcmp_res_snan - tbl_fcmp_op # NORM - SNAN
short tbl_fcmp_op - tbl_fcmp_op #
short tbl_fcmp_op - tbl_fcmp_op #
short fcmp_norm - tbl_fcmp_op # ZERO - NORM
short fcmp_norm - tbl_fcmp_op # ZERO - ZERO
short fcmp_norm - tbl_fcmp_op # ZERO - INF
short fcmp_res_qnan - tbl_fcmp_op # ZERO - QNAN
short fcmp_dnrm_s - tbl_fcmp_op # ZERO - DENORM
short fcmp_res_snan - tbl_fcmp_op # ZERO - SNAN
short tbl_fcmp_op - tbl_fcmp_op #
short tbl_fcmp_op - tbl_fcmp_op #
short fcmp_norm - tbl_fcmp_op # INF - NORM
short fcmp_norm - tbl_fcmp_op # INF - ZERO
short fcmp_norm - tbl_fcmp_op # INF - INF
short fcmp_res_qnan - tbl_fcmp_op # INF - QNAN
short fcmp_dnrm_s - tbl_fcmp_op # INF - DENORM
short fcmp_res_snan - tbl_fcmp_op # INF - SNAN
short tbl_fcmp_op - tbl_fcmp_op #
short tbl_fcmp_op - tbl_fcmp_op #
short fcmp_res_qnan - tbl_fcmp_op # QNAN - NORM
short fcmp_res_qnan - tbl_fcmp_op # QNAN - ZERO
short fcmp_res_qnan - tbl_fcmp_op # QNAN - INF
short fcmp_res_qnan - tbl_fcmp_op # QNAN - QNAN
short fcmp_res_qnan - tbl_fcmp_op # QNAN - DENORM
short fcmp_res_snan - tbl_fcmp_op # QNAN - SNAN
short tbl_fcmp_op - tbl_fcmp_op #
short tbl_fcmp_op - tbl_fcmp_op #
short fcmp_dnrm_nrm - tbl_fcmp_op # DENORM - NORM
short fcmp_dnrm_d - tbl_fcmp_op # DENORM - ZERO
short fcmp_dnrm_d - tbl_fcmp_op # DENORM - INF
short fcmp_res_qnan - tbl_fcmp_op # DENORM - QNAN
short fcmp_dnrm_sd - tbl_fcmp_op # DENORM - DENORM
short fcmp_res_snan - tbl_fcmp_op # DENORM - SNAN
short tbl_fcmp_op - tbl_fcmp_op #
short tbl_fcmp_op - tbl_fcmp_op #
short fcmp_res_snan - tbl_fcmp_op # SNAN - NORM
short fcmp_res_snan - tbl_fcmp_op # SNAN - ZERO
short fcmp_res_snan - tbl_fcmp_op # SNAN - INF
short fcmp_res_snan - tbl_fcmp_op # SNAN - QNAN
short fcmp_res_snan - tbl_fcmp_op # SNAN - DENORM
short fcmp_res_snan - tbl_fcmp_op # SNAN - SNAN
short tbl_fcmp_op - tbl_fcmp_op #
short tbl_fcmp_op - tbl_fcmp_op #
# 'N' bit for a negative QNAN or SNAN input so we must squelch it here.
fcmp_res_qnan:
bsr.l res_qnan
andi.b &0xf7,FPSR_CC(%a6)
rts
fcmp_res_snan:
bsr.l res_snan
andi.b &0xf7,FPSR_CC(%a6)
rts
#
# (1) signs are (+) and the DENORM is the dst or
# (2) signs are (-) and the DENORM is the src
#
fcmp_dnrm_s:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),%d0
bset &31,%d0 # DENORM src; make into small norm
mov.l %d0,FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
lea FP_SCR0(%a6),%a0
bra.w fcmp_norm
fcmp_dnrm_d:
mov.l DST_EX(%a1),FP_SCR0_EX(%a6)
mov.l DST_HI(%a1),%d0
bset &31,%d0 # DENORM src; make into small norm
mov.l %d0,FP_SCR0_HI(%a6)
mov.l DST_LO(%a1),FP_SCR0_LO(%a6)
lea FP_SCR0(%a6),%a1
bra.w fcmp_norm
fcmp_dnrm_sd:
mov.w DST_EX(%a1),FP_SCR1_EX(%a6)
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l DST_HI(%a1),%d0
bset &31,%d0 # DENORM dst; make into small norm
mov.l %d0,FP_SCR1_HI(%a6)
mov.l SRC_HI(%a0),%d0
bset &31,%d0 # DENORM dst; make into small norm
mov.l %d0,FP_SCR0_HI(%a6)
mov.l DST_LO(%a1),FP_SCR1_LO(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
lea FP_SCR1(%a6),%a1
lea FP_SCR0(%a6),%a0
bra.w fcmp_norm
fcmp_nrm_dnrm:
mov.b SRC_EX(%a0),%d0 # determine if like signs
mov.b DST_EX(%a1),%d1
eor.b %d0,%d1
bmi.w fcmp_dnrm_s
tst.b %d0 # is src op negative?
bmi.b fcmp_nrm_dnrm_m # yes
rts
fcmp_nrm_dnrm_m:
mov.b &neg_bmask,FPSR_CC(%a6) # set 'Z' ccode bit
rts
fcmp_dnrm_nrm:
mov.b SRC_EX(%a0),%d0 # determine if like signs
mov.b DST_EX(%a1),%d1
eor.b %d0,%d1
bmi.w fcmp_dnrm_d
tst.b %d0 # is src op negative?
bpl.b fcmp_dnrm_nrm_m # no
rts
fcmp_dnrm_nrm_m:
mov.b &neg_bmask,FPSR_CC(%a6) # set 'Z' ccode bit
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global fsglmul
fsglmul:
mov.l %d0,L_SCR3(%a6) # store rnd info
clr.w %d1
mov.b DTAG(%a6),%d1
lsl.b &0x3,%d1
or.b STAG(%a6),%d1
bne.w fsglmul_not_norm # optimize on non-norm input
fsglmul_norm:
mov.w DST_EX(%a1),FP_SCR1_EX(%a6)
mov.l DST_HI(%a1),FP_SCR1_HI(%a6)
mov.l DST_LO(%a1),FP_SCR1_LO(%a6)
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_to_zero_src # scale exponent
mov.l %d0,-(%sp) # save scale factor 1
bsr.l scale_to_zero_dst # scale dst exponent
add.l (%sp)+,%d0 # SCALE_FACTOR = scale1 + scale2
cmpi.l %d0,&0x3fff-0x7ffe # would result ovfl?
beq.w fsglmul_may_ovfl # result may rnd to overflow
blt.w fsglmul_ovfl # result will overflow
cmpi.l %d0,&0x3fff+0x0001 # would result unfl?
beq.w fsglmul_may_unfl # result may rnd to no unfl
bgt.w fsglmul_unfl # result will underflow
fsglmul_normal:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsglmul.x FP_SCR0(%a6),%fp0 # execute sgl multiply
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fsglmul_normal_exit:
fmovm.x &0x80,FP_SCR0(%a6) # store out result
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # load {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
or.w %d2,%d1 # concat old sign,new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x80 # return result in fp0
rts
fsglmul_ovfl:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsglmul.x FP_SCR0(%a6),%fp0 # execute sgl multiply
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fsglmul_ovfl_tst:
or.l &ovfl_inx_mask, USER_FPSR(%a6) # set ovfl/aovfl/ainex
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x13,%d1 # is OVFL or INEX enabled?
bne.b fsglmul_ovfl_ena # yes
fsglmul_ovfl_dis:
btst &neg_bit,FPSR_CC(%a6) # is result negative?
sne %d1 # set sign param accordingly
mov.l L_SCR3(%a6),%d0 # pass prec:rnd
andi.b &0x30,%d0 # force prec = ext
bsr.l ovf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # set INF,N if applicable
fmovm.x (%a0),&0x80 # return default result in fp0
rts
fsglmul_ovfl_ena:
fmovm.x &0x80,FP_SCR0(%a6) # move result to stack
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
sub.l %d0,%d1 # add scale factor
subi.l &0x6000,%d1 # subtract bias
andi.w &0x7fff,%d1
andi.w &0x8000,%d2 # keep old sign
or.w %d2,%d1 # concat old sign,new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
bra.b fsglmul_ovfl_dis
fsglmul_may_ovfl:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsglmul.x FP_SCR0(%a6),%fp0 # execute sgl multiply
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fabs.x %fp0,%fp1 # make a copy of result
fcmp.b %fp1,&0x2 # is |result| >= 2.b?
fbge.w fsglmul_ovfl_tst # yes; overflow has occurred
bra.w fsglmul_normal_exit
fsglmul_unfl:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l &rz_mode*0x10,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsglmul.x FP_SCR0(%a6),%fp0 # execute sgl multiply
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0b,%d1 # is UNFL or INEX enabled?
bne.b fsglmul_unfl_ena # yes
fsglmul_unfl_dis:
fmovm.x &0x80,FP_SCR0(%a6) # store out result
lea FP_SCR0(%a6),%a0 # pass: result addr
mov.l L_SCR3(%a6),%d1 # pass: rnd prec,mode
bsr.l unf_res4 # calculate default result
or.b %d0,FPSR_CC(%a6) # 'Z' bit may have been set
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
rts
#
#
fsglmul_unfl_ena:
fmovm.x FP_SCR1(%a6),&0x40 # load dst op
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsglmul.x FP_SCR0(%a6),%fp1 # execute sgl multiply
fmov.l &0x0,%fpcr # clear FPCR
fmovm.x &0x40,FP_SCR0(%a6) # save result to stack
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
addi.l &0x6000,%d1 # add bias
andi.w &0x7fff,%d1
or.w %d2,%d1 # concat old sign,new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
bra.w fsglmul_unfl_dis
fsglmul_may_unfl:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsglmul.x FP_SCR0(%a6),%fp0 # execute sgl multiply
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fabs.x %fp0,%fp1 # make a copy of result
fcmp.b %fp1,&0x2 # is |result| > 2.b?
fbgt.w fsglmul_normal_exit # no; no underflow occurred
fblt.w fsglmul_unfl # yes; underflow occurred
#
#
fmovm.x FP_SCR1(%a6),&0x40 # load dst op into fp1
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # keep rnd prec
ori.b &rz_mode*0x10,%d1 # insert RZ
fmov.l %d1,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsglmul.x FP_SCR0(%a6),%fp1 # execute sgl multiply
fmov.l &0x0,%fpcr # clear FPCR
fabs.x %fp1 # make absolute value
fcmp.b %fp1,&0x2 # is |result| < 2.b?
fbge.w fsglmul_normal_exit # no; no underflow occurred
bra.w fsglmul_unfl # yes, underflow occurred
##############################################################################
#
#
fsglmul_not_norm:
mov.w (tbl_fsglmul_op.b,%pc,%d1.w*2),%d1
jmp (tbl_fsglmul_op.b,%pc,%d1.w*1)
swbeg &48
tbl_fsglmul_op:
short fsglmul_norm - tbl_fsglmul_op # NORM x NORM
short fsglmul_zero - tbl_fsglmul_op # NORM x ZERO
short fsglmul_inf_src - tbl_fsglmul_op # NORM x INF
short fsglmul_res_qnan - tbl_fsglmul_op # NORM x QNAN
short fsglmul_norm - tbl_fsglmul_op # NORM x DENORM
short fsglmul_res_snan - tbl_fsglmul_op # NORM x SNAN
short tbl_fsglmul_op - tbl_fsglmul_op #
short tbl_fsglmul_op - tbl_fsglmul_op #
short fsglmul_zero - tbl_fsglmul_op # ZERO x NORM
short fsglmul_zero - tbl_fsglmul_op # ZERO x ZERO
short fsglmul_res_operr - tbl_fsglmul_op # ZERO x INF
short fsglmul_res_qnan - tbl_fsglmul_op # ZERO x QNAN
short fsglmul_zero - tbl_fsglmul_op # ZERO x DENORM
short fsglmul_res_snan - tbl_fsglmul_op # ZERO x SNAN
short tbl_fsglmul_op - tbl_fsglmul_op #
short tbl_fsglmul_op - tbl_fsglmul_op #
short fsglmul_inf_dst - tbl_fsglmul_op # INF x NORM
short fsglmul_res_operr - tbl_fsglmul_op # INF x ZERO
short fsglmul_inf_dst - tbl_fsglmul_op # INF x INF
short fsglmul_res_qnan - tbl_fsglmul_op # INF x QNAN
short fsglmul_inf_dst - tbl_fsglmul_op # INF x DENORM
short fsglmul_res_snan - tbl_fsglmul_op # INF x SNAN
short tbl_fsglmul_op - tbl_fsglmul_op #
short tbl_fsglmul_op - tbl_fsglmul_op #
short fsglmul_res_qnan - tbl_fsglmul_op # QNAN x NORM
short fsglmul_res_qnan - tbl_fsglmul_op # QNAN x ZERO
short fsglmul_res_qnan - tbl_fsglmul_op # QNAN x INF
short fsglmul_res_qnan - tbl_fsglmul_op # QNAN x QNAN
short fsglmul_res_qnan - tbl_fsglmul_op # QNAN x DENORM
short fsglmul_res_snan - tbl_fsglmul_op # QNAN x SNAN
short tbl_fsglmul_op - tbl_fsglmul_op #
short tbl_fsglmul_op - tbl_fsglmul_op #
short fsglmul_norm - tbl_fsglmul_op # NORM x NORM
short fsglmul_zero - tbl_fsglmul_op # NORM x ZERO
short fsglmul_inf_src - tbl_fsglmul_op # NORM x INF
short fsglmul_res_qnan - tbl_fsglmul_op # NORM x QNAN
short fsglmul_norm - tbl_fsglmul_op # NORM x DENORM
short fsglmul_res_snan - tbl_fsglmul_op # NORM x SNAN
short tbl_fsglmul_op - tbl_fsglmul_op #
short tbl_fsglmul_op - tbl_fsglmul_op #
short fsglmul_res_snan - tbl_fsglmul_op # SNAN x NORM
short fsglmul_res_snan - tbl_fsglmul_op # SNAN x ZERO
short fsglmul_res_snan - tbl_fsglmul_op # SNAN x INF
short fsglmul_res_snan - tbl_fsglmul_op # SNAN x QNAN
short fsglmul_res_snan - tbl_fsglmul_op # SNAN x DENORM
short fsglmul_res_snan - tbl_fsglmul_op # SNAN x SNAN
short tbl_fsglmul_op - tbl_fsglmul_op #
short tbl_fsglmul_op - tbl_fsglmul_op #
fsglmul_res_operr:
bra.l res_operr
fsglmul_res_snan:
bra.l res_snan
fsglmul_res_qnan:
bra.l res_qnan
fsglmul_zero:
bra.l fmul_zero
fsglmul_inf_src:
bra.l fmul_inf_src
fsglmul_inf_dst:
bra.l fmul_inf_dst
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global fsgldiv
fsgldiv:
mov.l %d0,L_SCR3(%a6) # store rnd info
clr.w %d1
mov.b DTAG(%a6),%d1
lsl.b &0x3,%d1
or.b STAG(%a6),%d1 # combine src tags
bne.w fsgldiv_not_norm # optimize on non-norm input
#
#
fsgldiv_norm:
mov.w DST_EX(%a1),FP_SCR1_EX(%a6)
mov.l DST_HI(%a1),FP_SCR1_HI(%a6)
mov.l DST_LO(%a1),FP_SCR1_LO(%a6)
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_to_zero_src # calculate scale factor 1
mov.l %d0,-(%sp) # save scale factor 1
bsr.l scale_to_zero_dst # calculate scale factor 2
neg.l (%sp) # S.F. = scale1 - scale2
add.l %d0,(%sp)
mov.w 2+L_SCR3(%a6),%d1 # fetch precision,mode
lsr.b &0x6,%d1
mov.l (%sp)+,%d0
cmpi.l %d0,&0x3fff-0x7ffe
ble.w fsgldiv_may_ovfl
cmpi.l %d0,&0x3fff-0x0000 # will result underflow?
beq.w fsgldiv_may_unfl # maybe
bgt.w fsgldiv_unfl # yes; go handle underflow
fsgldiv_normal:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l L_SCR3(%a6),%fpcr # save FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsgldiv.x FP_SCR0(%a6),%fp0 # perform sgl divide
fmov.l %fpsr,%d1 # save FPSR
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fsgldiv_normal_exit:
fmovm.x &0x80,FP_SCR0(%a6) # store result on stack
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # load {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
or.w %d2,%d1 # concat old sign,new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x80 # return result in fp0
rts
fsgldiv_may_ovfl:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # set FPSR
fsgldiv.x FP_SCR0(%a6),%fp0 # execute divide
fmov.l %fpsr,%d1
fmov.l &0x0,%fpcr
or.l %d1,USER_FPSR(%a6) # save INEX,N
fmovm.x &0x01,-(%sp) # save result to stack
mov.w (%sp),%d1 # fetch new exponent
add.l &0xc,%sp # clear result
andi.l &0x7fff,%d1 # strip sign
sub.l %d0,%d1 # add scale factor
cmp.l %d1,&0x7fff # did divide overflow?
blt.b fsgldiv_normal_exit
fsgldiv_ovfl_tst:
or.w &ovfl_inx_mask,2+USER_FPSR(%a6) # set ovfl/aovfl/ainex
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x13,%d1 # is OVFL or INEX enabled?
bne.b fsgldiv_ovfl_ena # yes
fsgldiv_ovfl_dis:
btst &neg_bit,FPSR_CC(%a6) # is result negative
sne %d1 # set sign param accordingly
mov.l L_SCR3(%a6),%d0 # pass prec:rnd
andi.b &0x30,%d0 # kill precision
bsr.l ovf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # set INF if applicable
fmovm.x (%a0),&0x80 # return default result in fp0
rts
fsgldiv_ovfl_ena:
fmovm.x &0x80,FP_SCR0(%a6) # move result to stack
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
subi.l &0x6000,%d1 # subtract new bias
andi.w &0x7fff,%d1 # clear ms bit
or.w %d2,%d1 # concat old sign,new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
bra.b fsgldiv_ovfl_dis
fsgldiv_unfl:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l &rz_mode*0x10,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsgldiv.x FP_SCR0(%a6),%fp0 # execute sgl divide
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0b,%d1 # is UNFL or INEX enabled?
bne.b fsgldiv_unfl_ena # yes
fsgldiv_unfl_dis:
fmovm.x &0x80,FP_SCR0(%a6) # store out result
lea FP_SCR0(%a6),%a0 # pass: result addr
mov.l L_SCR3(%a6),%d1 # pass: rnd prec,mode
bsr.l unf_res4 # calculate default result
or.b %d0,FPSR_CC(%a6) # 'Z' bit may have been set
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
rts
#
#
fsgldiv_unfl_ena:
fmovm.x FP_SCR1(%a6),&0x40 # load dst op
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsgldiv.x FP_SCR0(%a6),%fp1 # execute sgl divide
fmov.l &0x0,%fpcr # clear FPCR
fmovm.x &0x40,FP_SCR0(%a6) # save result to stack
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
addi.l &0x6000,%d1 # add bias
andi.w &0x7fff,%d1 # clear top bit
or.w %d2,%d1 # concat old sign, new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
bra.b fsgldiv_unfl_dis
#
#
fsgldiv_may_unfl:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsgldiv.x FP_SCR0(%a6),%fp0 # execute sgl divide
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fabs.x %fp0,%fp1 # make a copy of result
fcmp.b %fp1,&0x1 # is |result| > 1.b?
fbgt.w fsgldiv_normal_exit # no; no underflow occurred
fblt.w fsgldiv_unfl # yes; underflow occurred
#
#
fmovm.x FP_SCR1(%a6),&0x40 # load dst op into %fp1
clr.l %d1 # clear scratch register
ori.b &rz_mode*0x10,%d1 # force RZ rnd mode
fmov.l %d1,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsgldiv.x FP_SCR0(%a6),%fp1 # execute sgl divide
fmov.l &0x0,%fpcr # clear FPCR
fabs.x %fp1 # make absolute value
fcmp.b %fp1,&0x1 # is |result| < 1.b?
fbge.w fsgldiv_normal_exit # no; no underflow occurred
bra.w fsgldiv_unfl # yes; underflow occurred
############################################################################
#
#
fsgldiv_not_norm:
mov.w (tbl_fsgldiv_op.b,%pc,%d1.w*2),%d1
jmp (tbl_fsgldiv_op.b,%pc,%d1.w*1)
swbeg &48
tbl_fsgldiv_op:
short fsgldiv_norm - tbl_fsgldiv_op # NORM / NORM
short fsgldiv_inf_load - tbl_fsgldiv_op # NORM / ZERO
short fsgldiv_zero_load - tbl_fsgldiv_op # NORM / INF
short fsgldiv_res_qnan - tbl_fsgldiv_op # NORM / QNAN
short fsgldiv_norm - tbl_fsgldiv_op # NORM / DENORM
short fsgldiv_res_snan - tbl_fsgldiv_op # NORM / SNAN
short tbl_fsgldiv_op - tbl_fsgldiv_op #
short tbl_fsgldiv_op - tbl_fsgldiv_op #
short fsgldiv_zero_load - tbl_fsgldiv_op # ZERO / NORM
short fsgldiv_res_operr - tbl_fsgldiv_op # ZERO / ZERO
short fsgldiv_zero_load - tbl_fsgldiv_op # ZERO / INF
short fsgldiv_res_qnan - tbl_fsgldiv_op # ZERO / QNAN
short fsgldiv_zero_load - tbl_fsgldiv_op # ZERO / DENORM
short fsgldiv_res_snan - tbl_fsgldiv_op # ZERO / SNAN
short tbl_fsgldiv_op - tbl_fsgldiv_op #
short tbl_fsgldiv_op - tbl_fsgldiv_op #
short fsgldiv_inf_dst - tbl_fsgldiv_op # INF / NORM
short fsgldiv_inf_dst - tbl_fsgldiv_op # INF / ZERO
short fsgldiv_res_operr - tbl_fsgldiv_op # INF / INF
short fsgldiv_res_qnan - tbl_fsgldiv_op # INF / QNAN
short fsgldiv_inf_dst - tbl_fsgldiv_op # INF / DENORM
short fsgldiv_res_snan - tbl_fsgldiv_op # INF / SNAN
short tbl_fsgldiv_op - tbl_fsgldiv_op #
short tbl_fsgldiv_op - tbl_fsgldiv_op #
short fsgldiv_res_qnan - tbl_fsgldiv_op # QNAN / NORM
short fsgldiv_res_qnan - tbl_fsgldiv_op # QNAN / ZERO
short fsgldiv_res_qnan - tbl_fsgldiv_op # QNAN / INF
short fsgldiv_res_qnan - tbl_fsgldiv_op # QNAN / QNAN
short fsgldiv_res_qnan - tbl_fsgldiv_op # QNAN / DENORM
short fsgldiv_res_snan - tbl_fsgldiv_op # QNAN / SNAN
short tbl_fsgldiv_op - tbl_fsgldiv_op #
short tbl_fsgldiv_op - tbl_fsgldiv_op #
short fsgldiv_norm - tbl_fsgldiv_op # DENORM / NORM
short fsgldiv_inf_load - tbl_fsgldiv_op # DENORM / ZERO
short fsgldiv_zero_load - tbl_fsgldiv_op # DENORM / INF
short fsgldiv_res_qnan - tbl_fsgldiv_op # DENORM / QNAN
short fsgldiv_norm - tbl_fsgldiv_op # DENORM / DENORM
short fsgldiv_res_snan - tbl_fsgldiv_op # DENORM / SNAN
short tbl_fsgldiv_op - tbl_fsgldiv_op #
short tbl_fsgldiv_op - tbl_fsgldiv_op #
short fsgldiv_res_snan - tbl_fsgldiv_op # SNAN / NORM
short fsgldiv_res_snan - tbl_fsgldiv_op # SNAN / ZERO
short fsgldiv_res_snan - tbl_fsgldiv_op # SNAN / INF
short fsgldiv_res_snan - tbl_fsgldiv_op # SNAN / QNAN
short fsgldiv_res_snan - tbl_fsgldiv_op # SNAN / DENORM
short fsgldiv_res_snan - tbl_fsgldiv_op # SNAN / SNAN
short tbl_fsgldiv_op - tbl_fsgldiv_op #
short tbl_fsgldiv_op - tbl_fsgldiv_op #
fsgldiv_res_qnan:
bra.l res_qnan
fsgldiv_res_snan:
bra.l res_snan
fsgldiv_res_operr:
bra.l res_operr
fsgldiv_inf_load:
bra.l fdiv_inf_load
fsgldiv_zero_load:
bra.l fdiv_zero_load
fsgldiv_inf_dst:
bra.l fdiv_inf_dst
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global fsadd
fsadd:
andi.b &0x30,%d0 # clear rnd prec
ori.b &s_mode*0x10,%d0 # insert sgl prec
bra.b fadd
global fdadd
fdadd:
andi.b &0x30,%d0 # clear rnd prec
ori.b &d_mode*0x10,%d0 # insert dbl prec
global fadd
fadd:
mov.l %d0,L_SCR3(%a6) # store rnd info
clr.w %d1
mov.b DTAG(%a6),%d1
lsl.b &0x3,%d1
or.b STAG(%a6),%d1 # combine src tags
bne.w fadd_not_norm # optimize on non-norm input
#
#
fadd_norm:
bsr.l addsub_scaler2 # scale exponents
fadd_zero_entry:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fadd.x FP_SCR0(%a6),%fp0 # execute add
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d1 # fetch INEX2,N,Z
or.l %d1,USER_FPSR(%a6) # save exc and ccode bits
fbeq.w fadd_zero_exit # if result is zero, end now
mov.l %d2,-(%sp) # save d2
fmovm.x &0x01,-(%sp) # save result to stack
mov.w 2+L_SCR3(%a6),%d1
lsr.b &0x6,%d1
mov.w (%sp),%d2 # fetch new sign, exp
andi.l &0x7fff,%d2 # strip sign
sub.l %d0,%d2 # add scale factor
cmp.l %d2,(tbl_fadd_ovfl.b,%pc,%d1.w*4) # is it an overflow?
bge.b fadd_ovfl # yes
cmp.l %d2,(tbl_fadd_unfl.b,%pc,%d1.w*4) # is it an underflow?
blt.w fadd_unfl # yes
beq.w fadd_may_unfl # maybe; go find out
fadd_normal:
mov.w (%sp),%d1
andi.w &0x8000,%d1 # keep sign
or.w %d2,%d1 # concat sign,new exp
mov.w %d1,(%sp) # insert new exponent
fmovm.x (%sp)+,&0x80 # return result in fp0
mov.l (%sp)+,%d2 # restore d2
rts
fadd_zero_exit:
rts
tbl_fadd_ovfl:
long 0x7fff # ext ovfl
long 0x407f # sgl ovfl
long 0x43ff # dbl ovfl
tbl_fadd_unfl:
long 0x0000 # ext unfl
long 0x3f81 # sgl unfl
long 0x3c01 # dbl unfl
fadd_ovfl:
or.l &ovfl_inx_mask,USER_FPSR(%a6) # set ovfl/aovfl/ainex
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x13,%d1 # is OVFL or INEX enabled?
bne.b fadd_ovfl_ena # yes
add.l &0xc,%sp
fadd_ovfl_dis:
btst &neg_bit,FPSR_CC(%a6) # is result negative?
sne %d1 # set sign param accordingly
mov.l L_SCR3(%a6),%d0 # pass prec:rnd
bsr.l ovf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # set INF,N if applicable
fmovm.x (%a0),&0x80 # return default result in fp0
mov.l (%sp)+,%d2 # restore d2
rts
fadd_ovfl_ena:
mov.b L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # is precision extended?
bne.b fadd_ovfl_ena_sd # no; prec = sgl or dbl
fadd_ovfl_ena_cont:
mov.w (%sp),%d1
andi.w &0x8000,%d1 # keep sign
subi.l &0x6000,%d2 # add extra bias
andi.w &0x7fff,%d2
or.w %d2,%d1 # concat sign,new exp
mov.w %d1,(%sp) # insert new exponent
fmovm.x (%sp)+,&0x40 # return EXOP in fp1
bra.b fadd_ovfl_dis
fadd_ovfl_ena_sd:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
mov.l L_SCR3(%a6),%d1
andi.b &0x30,%d1 # keep rnd mode
fmov.l %d1,%fpcr # set FPCR
fadd.x FP_SCR0(%a6),%fp0 # execute add
fmov.l &0x0,%fpcr # clear FPCR
add.l &0xc,%sp
fmovm.x &0x01,-(%sp)
bra.b fadd_ovfl_ena_cont
fadd_unfl:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
add.l &0xc,%sp
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l &rz_mode*0x10,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fadd.x FP_SCR0(%a6),%fp0 # execute add
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d1 # save status
or.l %d1,USER_FPSR(%a6) # save INEX,N
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0b,%d1 # is UNFL or INEX enabled?
bne.b fadd_unfl_ena # yes
fadd_unfl_dis:
fmovm.x &0x80,FP_SCR0(%a6) # store out result
lea FP_SCR0(%a6),%a0 # pass: result addr
mov.l L_SCR3(%a6),%d1 # pass: rnd prec,mode
bsr.l unf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # 'Z' bit may have been set
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
mov.l (%sp)+,%d2 # restore d2
rts
fadd_unfl_ena:
fmovm.x FP_SCR1(%a6),&0x40 # load dst op
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # is precision extended?
bne.b fadd_unfl_ena_sd # no; sgl or dbl
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fadd_unfl_ena_cont:
fmov.l &0x0,%fpsr # clear FPSR
fadd.x FP_SCR0(%a6),%fp1 # execute multiply
fmov.l &0x0,%fpcr # clear FPCR
fmovm.x &0x40,FP_SCR0(%a6) # save result to stack
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
addi.l &0x6000,%d1 # add new bias
andi.w &0x7fff,%d1 # clear top bit
or.w %d2,%d1 # concat sign,new exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
bra.w fadd_unfl_dis
fadd_unfl_ena_sd:
mov.l L_SCR3(%a6),%d1
andi.b &0x30,%d1 # use only rnd mode
fmov.l %d1,%fpcr # set FPCR
bra.b fadd_unfl_ena_cont
#
# if the precision is extended, this result could not have come from an
#
fadd_may_unfl:
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1
beq.w fadd_normal # yes; no underflow occurred
mov.l 0x4(%sp),%d1 # extract hi(man)
cmpi.l %d1,&0x80000000 # is hi(man) = 0x80000000?
bne.w fadd_normal # no; no underflow occurred
tst.l 0x8(%sp) # is lo(man) = 0x0?
bne.w fadd_normal # no; no underflow occurred
btst &inex2_bit,FPSR_EXCEPT(%a6) # is INEX2 set?
beq.w fadd_normal # no; no underflow occurred
#
# 0x8000000000000000 and this mantissa is the result of rounding non-zero
#
fmovm.x FP_SCR1(%a6),&0x40 # load dst op into fp1
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # keep rnd prec
ori.b &rz_mode*0x10,%d1 # insert rnd mode
fmov.l %d1,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fadd.x FP_SCR0(%a6),%fp1 # execute add
fmov.l &0x0,%fpcr # clear FPCR
fabs.x %fp0 # compare absolute values
fabs.x %fp1
fcmp.x %fp0,%fp1 # is first result > second?
fbgt.w fadd_unfl # yes; it's an underflow
bra.w fadd_normal # no; it's not an underflow
##########################################################################
#
#
fadd_not_norm:
mov.w (tbl_fadd_op.b,%pc,%d1.w*2),%d1
jmp (tbl_fadd_op.b,%pc,%d1.w*1)
swbeg &48
tbl_fadd_op:
short fadd_norm - tbl_fadd_op # NORM + NORM
short fadd_zero_src - tbl_fadd_op # NORM + ZERO
short fadd_inf_src - tbl_fadd_op # NORM + INF
short fadd_res_qnan - tbl_fadd_op # NORM + QNAN
short fadd_norm - tbl_fadd_op # NORM + DENORM
short fadd_res_snan - tbl_fadd_op # NORM + SNAN
short tbl_fadd_op - tbl_fadd_op #
short tbl_fadd_op - tbl_fadd_op #
short fadd_zero_dst - tbl_fadd_op # ZERO + NORM
short fadd_zero_2 - tbl_fadd_op # ZERO + ZERO
short fadd_inf_src - tbl_fadd_op # ZERO + INF
short fadd_res_qnan - tbl_fadd_op # NORM + QNAN
short fadd_zero_dst - tbl_fadd_op # ZERO + DENORM
short fadd_res_snan - tbl_fadd_op # NORM + SNAN
short tbl_fadd_op - tbl_fadd_op #
short tbl_fadd_op - tbl_fadd_op #
short fadd_inf_dst - tbl_fadd_op # INF + NORM
short fadd_inf_dst - tbl_fadd_op # INF + ZERO
short fadd_inf_2 - tbl_fadd_op # INF + INF
short fadd_res_qnan - tbl_fadd_op # NORM + QNAN
short fadd_inf_dst - tbl_fadd_op # INF + DENORM
short fadd_res_snan - tbl_fadd_op # NORM + SNAN
short tbl_fadd_op - tbl_fadd_op #
short tbl_fadd_op - tbl_fadd_op #
short fadd_res_qnan - tbl_fadd_op # QNAN + NORM
short fadd_res_qnan - tbl_fadd_op # QNAN + ZERO
short fadd_res_qnan - tbl_fadd_op # QNAN + INF
short fadd_res_qnan - tbl_fadd_op # QNAN + QNAN
short fadd_res_qnan - tbl_fadd_op # QNAN + DENORM
short fadd_res_snan - tbl_fadd_op # QNAN + SNAN
short tbl_fadd_op - tbl_fadd_op #
short tbl_fadd_op - tbl_fadd_op #
short fadd_norm - tbl_fadd_op # DENORM + NORM
short fadd_zero_src - tbl_fadd_op # DENORM + ZERO
short fadd_inf_src - tbl_fadd_op # DENORM + INF
short fadd_res_qnan - tbl_fadd_op # NORM + QNAN
short fadd_norm - tbl_fadd_op # DENORM + DENORM
short fadd_res_snan - tbl_fadd_op # NORM + SNAN
short tbl_fadd_op - tbl_fadd_op #
short tbl_fadd_op - tbl_fadd_op #
short fadd_res_snan - tbl_fadd_op # SNAN + NORM
short fadd_res_snan - tbl_fadd_op # SNAN + ZERO
short fadd_res_snan - tbl_fadd_op # SNAN + INF
short fadd_res_snan - tbl_fadd_op # SNAN + QNAN
short fadd_res_snan - tbl_fadd_op # SNAN + DENORM
short fadd_res_snan - tbl_fadd_op # SNAN + SNAN
short tbl_fadd_op - tbl_fadd_op #
short tbl_fadd_op - tbl_fadd_op #
fadd_res_qnan:
bra.l res_qnan
fadd_res_snan:
bra.l res_snan
#
#
fadd_zero_2:
mov.b SRC_EX(%a0),%d0 # are the signs opposite
mov.b DST_EX(%a1),%d1
eor.b %d0,%d1
bmi.w fadd_zero_2_chk_rm # weed out (-ZERO)+(+ZERO)
tst.b %d0 # are ZEROes positive or negative?
bmi.b fadd_zero_rm # negative
fmov.s &0x00000000,%fp0 # return +ZERO
mov.b &z_bmask,FPSR_CC(%a6) # set Z
rts
#
# - Therefore, we return +ZERO if the rounding modes are RN,RZ, or RP.
# - -ZERO is returned in the case of RM.
#
fadd_zero_2_chk_rm:
mov.b 3+L_SCR3(%a6),%d1
andi.b &0x30,%d1 # extract rnd mode
cmpi.b %d1,&rm_mode*0x10 # is rnd mode == RM?
beq.b fadd_zero_rm # yes
fmov.s &0x00000000,%fp0 # return +ZERO
mov.b &z_bmask,FPSR_CC(%a6) # set Z
rts
fadd_zero_rm:
fmov.s &0x80000000,%fp0 # return -ZERO
mov.b &neg_bmask+z_bmask,FPSR_CC(%a6) # set NEG/Z
rts
#
#
fadd_zero_dst:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_to_zero_src # scale the operand
clr.w FP_SCR1_EX(%a6)
clr.l FP_SCR1_HI(%a6)
clr.l FP_SCR1_LO(%a6)
bra.w fadd_zero_entry # go execute fadd
fadd_zero_src:
mov.w DST_EX(%a1),FP_SCR1_EX(%a6)
mov.l DST_HI(%a1),FP_SCR1_HI(%a6)
mov.l DST_LO(%a1),FP_SCR1_LO(%a6)
bsr.l scale_to_zero_dst # scale the operand
clr.w FP_SCR0_EX(%a6)
clr.l FP_SCR0_HI(%a6)
clr.l FP_SCR0_LO(%a6)
bra.w fadd_zero_entry # go execute fadd
#
#
fadd_inf_2:
mov.b SRC_EX(%a0),%d0 # exclusive or the signs
mov.b DST_EX(%a1),%d1
eor.b %d1,%d0
bmi.l res_operr # weed out (-INF)+(+INF)
#
#
fadd_inf_src:
fmovm.x SRC(%a0),&0x80 # return src INF
tst.b SRC_EX(%a0) # is INF positive?
bpl.b fadd_inf_done # yes; we're done
mov.b &neg_bmask+inf_bmask,FPSR_CC(%a6) # set INF/NEG
rts
#
#
fadd_inf_dst:
fmovm.x DST(%a1),&0x80 # return dst INF
tst.b DST_EX(%a1) # is INF positive?
bpl.b fadd_inf_done # yes; we're done
mov.b &neg_bmask+inf_bmask,FPSR_CC(%a6) # set INF/NEG
rts
fadd_inf_done:
mov.b &inf_bmask,FPSR_CC(%a6) # set INF
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global fssub
fssub:
andi.b &0x30,%d0 # clear rnd prec
ori.b &s_mode*0x10,%d0 # insert sgl prec
bra.b fsub
global fdsub
fdsub:
andi.b &0x30,%d0 # clear rnd prec
ori.b &d_mode*0x10,%d0 # insert dbl prec
global fsub
fsub:
mov.l %d0,L_SCR3(%a6) # store rnd info
clr.w %d1
mov.b DTAG(%a6),%d1
lsl.b &0x3,%d1
or.b STAG(%a6),%d1 # combine src tags
bne.w fsub_not_norm # optimize on non-norm input
#
#
fsub_norm:
bsr.l addsub_scaler2 # scale exponents
fsub_zero_entry:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fsub.x FP_SCR0(%a6),%fp0 # execute subtract
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d1 # fetch INEX2, N, Z
or.l %d1,USER_FPSR(%a6) # save exc and ccode bits
fbeq.w fsub_zero_exit # if result zero, end now
mov.l %d2,-(%sp) # save d2
fmovm.x &0x01,-(%sp) # save result to stack
mov.w 2+L_SCR3(%a6),%d1
lsr.b &0x6,%d1
mov.w (%sp),%d2 # fetch new exponent
andi.l &0x7fff,%d2 # strip sign
sub.l %d0,%d2 # add scale factor
cmp.l %d2,(tbl_fsub_ovfl.b,%pc,%d1.w*4) # is it an overflow?
bge.b fsub_ovfl # yes
cmp.l %d2,(tbl_fsub_unfl.b,%pc,%d1.w*4) # is it an underflow?
blt.w fsub_unfl # yes
beq.w fsub_may_unfl # maybe; go find out
fsub_normal:
mov.w (%sp),%d1
andi.w &0x8000,%d1 # keep sign
or.w %d2,%d1 # insert new exponent
mov.w %d1,(%sp) # insert new exponent
fmovm.x (%sp)+,&0x80 # return result in fp0
mov.l (%sp)+,%d2 # restore d2
rts
fsub_zero_exit:
rts
tbl_fsub_ovfl:
long 0x7fff # ext ovfl
long 0x407f # sgl ovfl
long 0x43ff # dbl ovfl
tbl_fsub_unfl:
long 0x0000 # ext unfl
long 0x3f81 # sgl unfl
long 0x3c01 # dbl unfl
fsub_ovfl:
or.l &ovfl_inx_mask,USER_FPSR(%a6) # set ovfl/aovfl/ainex
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x13,%d1 # is OVFL or INEX enabled?
bne.b fsub_ovfl_ena # yes
add.l &0xc,%sp
fsub_ovfl_dis:
btst &neg_bit,FPSR_CC(%a6) # is result negative?
sne %d1 # set sign param accordingly
mov.l L_SCR3(%a6),%d0 # pass prec:rnd
bsr.l ovf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # set INF,N if applicable
fmovm.x (%a0),&0x80 # return default result in fp0
mov.l (%sp)+,%d2 # restore d2
rts
fsub_ovfl_ena:
mov.b L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # is precision extended?
bne.b fsub_ovfl_ena_sd # no
fsub_ovfl_ena_cont:
mov.w (%sp),%d1 # fetch {sgn,exp}
andi.w &0x8000,%d1 # keep sign
subi.l &0x6000,%d2 # subtract new bias
andi.w &0x7fff,%d2 # clear top bit
or.w %d2,%d1 # concat sign,exp
mov.w %d1,(%sp) # insert new exponent
fmovm.x (%sp)+,&0x40 # return EXOP in fp1
bra.b fsub_ovfl_dis
fsub_ovfl_ena_sd:
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
mov.l L_SCR3(%a6),%d1
andi.b &0x30,%d1 # clear rnd prec
fmov.l %d1,%fpcr # set FPCR
fsub.x FP_SCR0(%a6),%fp0 # execute subtract
fmov.l &0x0,%fpcr # clear FPCR
add.l &0xc,%sp
fmovm.x &0x01,-(%sp)
bra.b fsub_ovfl_ena_cont
fsub_unfl:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
add.l &0xc,%sp
fmovm.x FP_SCR1(%a6),&0x80 # load dst op
fmov.l &rz_mode*0x10,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsub.x FP_SCR0(%a6),%fp0 # execute subtract
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d1 # save status
or.l %d1,USER_FPSR(%a6)
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0b,%d1 # is UNFL or INEX enabled?
bne.b fsub_unfl_ena # yes
fsub_unfl_dis:
fmovm.x &0x80,FP_SCR0(%a6) # store out result
lea FP_SCR0(%a6),%a0 # pass: result addr
mov.l L_SCR3(%a6),%d1 # pass: rnd prec,mode
bsr.l unf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # 'Z' may have been set
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
mov.l (%sp)+,%d2 # restore d2
rts
fsub_unfl_ena:
fmovm.x FP_SCR1(%a6),&0x40
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # is precision extended?
bne.b fsub_unfl_ena_sd # no
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fsub_unfl_ena_cont:
fmov.l &0x0,%fpsr # clear FPSR
fsub.x FP_SCR0(%a6),%fp1 # execute subtract
fmov.l &0x0,%fpcr # clear FPCR
fmovm.x &0x40,FP_SCR0(%a6) # store result to stack
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
addi.l &0x6000,%d1 # subtract new bias
andi.w &0x7fff,%d1 # clear top bit
or.w %d2,%d1 # concat sgn,exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
bra.w fsub_unfl_dis
fsub_unfl_ena_sd:
mov.l L_SCR3(%a6),%d1
andi.b &0x30,%d1 # clear rnd prec
fmov.l %d1,%fpcr # set FPCR
bra.b fsub_unfl_ena_cont
#
# if the precision is extended, this result could not have come from an
#
fsub_may_unfl:
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # fetch rnd prec
beq.w fsub_normal # yes; no underflow occurred
mov.l 0x4(%sp),%d1
cmpi.l %d1,&0x80000000 # is hi(man) = 0x80000000?
bne.w fsub_normal # no; no underflow occurred
tst.l 0x8(%sp) # is lo(man) = 0x0?
bne.w fsub_normal # no; no underflow occurred
btst &inex2_bit,FPSR_EXCEPT(%a6) # is INEX2 set?
beq.w fsub_normal # no; no underflow occurred
#
# 0x8000000000000000 and this mantissa is the result of rounding non-zero
#
fmovm.x FP_SCR1(%a6),&0x40 # load dst op into fp1
mov.l L_SCR3(%a6),%d1
andi.b &0xc0,%d1 # keep rnd prec
ori.b &rz_mode*0x10,%d1 # insert rnd mode
fmov.l %d1,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsub.x FP_SCR0(%a6),%fp1 # execute subtract
fmov.l &0x0,%fpcr # clear FPCR
fabs.x %fp0 # compare absolute values
fabs.x %fp1
fcmp.x %fp0,%fp1 # is first result > second?
fbgt.w fsub_unfl # yes; it's an underflow
bra.w fsub_normal # no; it's not an underflow
##########################################################################
#
#
fsub_not_norm:
mov.w (tbl_fsub_op.b,%pc,%d1.w*2),%d1
jmp (tbl_fsub_op.b,%pc,%d1.w*1)
swbeg &48
tbl_fsub_op:
short fsub_norm - tbl_fsub_op # NORM - NORM
short fsub_zero_src - tbl_fsub_op # NORM - ZERO
short fsub_inf_src - tbl_fsub_op # NORM - INF
short fsub_res_qnan - tbl_fsub_op # NORM - QNAN
short fsub_norm - tbl_fsub_op # NORM - DENORM
short fsub_res_snan - tbl_fsub_op # NORM - SNAN
short tbl_fsub_op - tbl_fsub_op #
short tbl_fsub_op - tbl_fsub_op #
short fsub_zero_dst - tbl_fsub_op # ZERO - NORM
short fsub_zero_2 - tbl_fsub_op # ZERO - ZERO
short fsub_inf_src - tbl_fsub_op # ZERO - INF
short fsub_res_qnan - tbl_fsub_op # NORM - QNAN
short fsub_zero_dst - tbl_fsub_op # ZERO - DENORM
short fsub_res_snan - tbl_fsub_op # NORM - SNAN
short tbl_fsub_op - tbl_fsub_op #
short tbl_fsub_op - tbl_fsub_op #
short fsub_inf_dst - tbl_fsub_op # INF - NORM
short fsub_inf_dst - tbl_fsub_op # INF - ZERO
short fsub_inf_2 - tbl_fsub_op # INF - INF
short fsub_res_qnan - tbl_fsub_op # NORM - QNAN
short fsub_inf_dst - tbl_fsub_op # INF - DENORM
short fsub_res_snan - tbl_fsub_op # NORM - SNAN
short tbl_fsub_op - tbl_fsub_op #
short tbl_fsub_op - tbl_fsub_op #
short fsub_res_qnan - tbl_fsub_op # QNAN - NORM
short fsub_res_qnan - tbl_fsub_op # QNAN - ZERO
short fsub_res_qnan - tbl_fsub_op # QNAN - INF
short fsub_res_qnan - tbl_fsub_op # QNAN - QNAN
short fsub_res_qnan - tbl_fsub_op # QNAN - DENORM
short fsub_res_snan - tbl_fsub_op # QNAN - SNAN
short tbl_fsub_op - tbl_fsub_op #
short tbl_fsub_op - tbl_fsub_op #
short fsub_norm - tbl_fsub_op # DENORM - NORM
short fsub_zero_src - tbl_fsub_op # DENORM - ZERO
short fsub_inf_src - tbl_fsub_op # DENORM - INF
short fsub_res_qnan - tbl_fsub_op # NORM - QNAN
short fsub_norm - tbl_fsub_op # DENORM - DENORM
short fsub_res_snan - tbl_fsub_op # NORM - SNAN
short tbl_fsub_op - tbl_fsub_op #
short tbl_fsub_op - tbl_fsub_op #
short fsub_res_snan - tbl_fsub_op # SNAN - NORM
short fsub_res_snan - tbl_fsub_op # SNAN - ZERO
short fsub_res_snan - tbl_fsub_op # SNAN - INF
short fsub_res_snan - tbl_fsub_op # SNAN - QNAN
short fsub_res_snan - tbl_fsub_op # SNAN - DENORM
short fsub_res_snan - tbl_fsub_op # SNAN - SNAN
short tbl_fsub_op - tbl_fsub_op #
short tbl_fsub_op - tbl_fsub_op #
fsub_res_qnan:
bra.l res_qnan
fsub_res_snan:
bra.l res_snan
#
#
fsub_zero_2:
mov.b SRC_EX(%a0),%d0
mov.b DST_EX(%a1),%d1
eor.b %d1,%d0
bpl.b fsub_zero_2_chk_rm
tst.b %d0 # is dst negative?
bmi.b fsub_zero_2_rm # yes
fmov.s &0x00000000,%fp0 # no; return +ZERO
mov.b &z_bmask,FPSR_CC(%a6) # set Z
rts
#
# - Therefore, we return +ZERO if the rounding mode is RN,RZ, or RP
# - -ZERO is returned in the case of RM.
#
fsub_zero_2_chk_rm:
mov.b 3+L_SCR3(%a6),%d1
andi.b &0x30,%d1 # extract rnd mode
cmpi.b %d1,&rm_mode*0x10 # is rnd mode = RM?
beq.b fsub_zero_2_rm # yes
fmov.s &0x00000000,%fp0 # no; return +ZERO
mov.b &z_bmask,FPSR_CC(%a6) # set Z
rts
fsub_zero_2_rm:
fmov.s &0x80000000,%fp0 # return -ZERO
mov.b &z_bmask+neg_bmask,FPSR_CC(%a6) # set Z/NEG
rts
#
#
fsub_zero_dst:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_to_zero_src # scale the operand
clr.w FP_SCR1_EX(%a6)
clr.l FP_SCR1_HI(%a6)
clr.l FP_SCR1_LO(%a6)
bra.w fsub_zero_entry # go execute fsub
fsub_zero_src:
mov.w DST_EX(%a1),FP_SCR1_EX(%a6)
mov.l DST_HI(%a1),FP_SCR1_HI(%a6)
mov.l DST_LO(%a1),FP_SCR1_LO(%a6)
bsr.l scale_to_zero_dst # scale the operand
clr.w FP_SCR0_EX(%a6)
clr.l FP_SCR0_HI(%a6)
clr.l FP_SCR0_LO(%a6)
bra.w fsub_zero_entry # go execute fsub
#
#
fsub_inf_2:
mov.b SRC_EX(%a0),%d0 # exclusive or the signs
mov.b DST_EX(%a1),%d1
eor.b %d1,%d0
bpl.l res_operr # weed out (-INF)+(+INF)
fsub_inf_src:
fmovm.x SRC(%a0),&0x80 # return src INF
fneg.x %fp0 # invert sign
fbge.w fsub_inf_done # sign is now positive
mov.b &neg_bmask+inf_bmask,FPSR_CC(%a6) # set INF/NEG
rts
fsub_inf_dst:
fmovm.x DST(%a1),&0x80 # return dst INF
tst.b DST_EX(%a1) # is INF negative?
bpl.b fsub_inf_done # no
mov.b &neg_bmask+inf_bmask,FPSR_CC(%a6) # set INF/NEG
rts
fsub_inf_done:
mov.b &inf_bmask,FPSR_CC(%a6) # set INF
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global fssqrt
fssqrt:
andi.b &0x30,%d0 # clear rnd prec
ori.b &s_mode*0x10,%d0 # insert sgl precision
bra.b fsqrt
global fdsqrt
fdsqrt:
andi.b &0x30,%d0 # clear rnd prec
ori.b &d_mode*0x10,%d0 # insert dbl precision
global fsqrt
fsqrt:
mov.l %d0,L_SCR3(%a6) # store rnd info
clr.w %d1
mov.b STAG(%a6),%d1
bne.w fsqrt_not_norm # optimize on non-norm input
#
#
fsqrt_norm:
tst.b SRC_EX(%a0) # is operand negative?
bmi.l res_operr # yes
andi.b &0xc0,%d0 # is precision extended?
bne.b fsqrt_not_ext # no; go handle sgl or dbl
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsqrt.x (%a0),%fp0 # execute square root
fmov.l %fpsr,%d1
or.l %d1,USER_FPSR(%a6) # set N,INEX
rts
fsqrt_denorm:
tst.b SRC_EX(%a0) # is operand negative?
bmi.l res_operr # yes
andi.b &0xc0,%d0 # is precision extended?
bne.b fsqrt_not_ext # no; go handle sgl or dbl
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_sqrt # calculate scale factor
bra.w fsqrt_sd_normal
#
#
fsqrt_not_ext:
cmpi.b %d0,&s_mode*0x10 # separate sgl/dbl prec
bne.w fsqrt_dbl
#
#
fsqrt_sgl:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_sqrt # calculate scale factor
cmpi.l %d0,&0x3fff-0x3f81 # will move in underflow?
beq.w fsqrt_sd_may_unfl
bgt.w fsqrt_sd_unfl # yes; go handle underflow
cmpi.l %d0,&0x3fff-0x407f # will move in overflow?
beq.w fsqrt_sd_may_ovfl # maybe; go check
blt.w fsqrt_sd_ovfl # yes; go handle overflow
#
#
fsqrt_sd_normal:
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fsqrt.x FP_SCR0(%a6),%fp0 # perform absolute
fmov.l %fpsr,%d1 # save FPSR
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fsqrt_sd_normal_exit:
mov.l %d2,-(%sp) # save d2
fmovm.x &0x80,FP_SCR0(%a6) # store out result
mov.w FP_SCR0_EX(%a6),%d1 # load sgn,exp
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
sub.l %d0,%d1 # add scale factor
andi.w &0x8000,%d2 # keep old sign
or.w %d1,%d2 # concat old sign,new exp
mov.w %d2,FP_SCR0_EX(%a6) # insert new exponent
mov.l (%sp)+,%d2 # restore d2
fmovm.x FP_SCR0(%a6),&0x80 # return result in fp0
rts
#
#
fsqrt_dbl:
mov.w SRC_EX(%a0),FP_SCR0_EX(%a6)
mov.l SRC_HI(%a0),FP_SCR0_HI(%a6)
mov.l SRC_LO(%a0),FP_SCR0_LO(%a6)
bsr.l scale_sqrt # calculate scale factor
cmpi.l %d0,&0x3fff-0x3c01 # will move in underflow?
beq.w fsqrt_sd_may_unfl
bgt.b fsqrt_sd_unfl # yes; go handle underflow
cmpi.l %d0,&0x3fff-0x43ff # will move in overflow?
beq.w fsqrt_sd_may_ovfl # maybe; go check
blt.w fsqrt_sd_ovfl # yes; go handle overflow
bra.w fsqrt_sd_normal # no; ho handle normalized op
fsqrt_sd_may_unfl:
btst &0x0,1+FP_SCR0_EX(%a6) # is exponent 0x3fff?
bne.w fsqrt_sd_normal # yes, so no underflow
#
#
fsqrt_sd_unfl:
bset &unfl_bit,FPSR_EXCEPT(%a6) # set unfl exc bit
fmov.l &rz_mode*0x10,%fpcr # set FPCR
fmov.l &0x0,%fpsr # clear FPSR
fsqrt.x FP_SCR0(%a6),%fp0 # execute square root
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
# if underflow or inexact is enabled, go calculate EXOP first.
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x0b,%d1 # is UNFL or INEX enabled?
bne.b fsqrt_sd_unfl_ena # yes
fsqrt_sd_unfl_dis:
fmovm.x &0x80,FP_SCR0(%a6) # store out result
lea FP_SCR0(%a6),%a0 # pass: result addr
mov.l L_SCR3(%a6),%d1 # pass: rnd prec,mode
bsr.l unf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # set possible 'Z' ccode
fmovm.x FP_SCR0(%a6),&0x80 # return default result in fp0
rts
#
#
fsqrt_sd_unfl_ena:
mov.l FP_SCR0_HI(%a6),FP_SCR1_HI(%a6)
mov.l FP_SCR0_LO(%a6),FP_SCR1_LO(%a6)
mov.w FP_SCR0_EX(%a6),%d1 # load current exponent
mov.l %d2,-(%sp) # save d2
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # subtract scale factor
addi.l &0x6000,%d1 # add new bias
andi.w &0x7fff,%d1
or.w %d2,%d1 # concat new sign,new exp
mov.w %d1,FP_SCR1_EX(%a6) # insert new exp
fmovm.x FP_SCR1(%a6),&0x40 # return EXOP in fp1
mov.l (%sp)+,%d2 # restore d2
bra.b fsqrt_sd_unfl_dis
#
#
fsqrt_sd_ovfl:
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fsqrt.x FP_SCR0(%a6),%fp0 # perform square root
fmov.l &0x0,%fpcr # clear FPCR
fmov.l %fpsr,%d1 # save FPSR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fsqrt_sd_ovfl_tst:
or.l &ovfl_inx_mask,USER_FPSR(%a6) # set ovfl/aovfl/ainex
mov.b FPCR_ENABLE(%a6),%d1
andi.b &0x13,%d1 # is OVFL or INEX enabled?
bne.b fsqrt_sd_ovfl_ena # yes
#
#
fsqrt_sd_ovfl_dis:
btst &neg_bit,FPSR_CC(%a6) # is result negative?
sne %d1 # set sign param accordingly
mov.l L_SCR3(%a6),%d0 # pass: prec,mode
bsr.l ovf_res # calculate default result
or.b %d0,FPSR_CC(%a6) # set INF,N if applicable
fmovm.x (%a0),&0x80 # return default result in fp0
rts
#
#
fsqrt_sd_ovfl_ena:
mov.l %d2,-(%sp) # save d2
mov.w FP_SCR0_EX(%a6),%d1 # fetch {sgn,exp}
mov.l %d1,%d2 # make a copy
andi.l &0x7fff,%d1 # strip sign
andi.w &0x8000,%d2 # keep old sign
sub.l %d0,%d1 # add scale factor
subi.l &0x6000,%d1 # subtract bias
andi.w &0x7fff,%d1
or.w %d2,%d1 # concat sign,exp
mov.w %d1,FP_SCR0_EX(%a6) # insert new exponent
fmovm.x FP_SCR0(%a6),&0x40 # return EXOP in fp1
mov.l (%sp)+,%d2 # restore d2
bra.b fsqrt_sd_ovfl_dis
#
#
fsqrt_sd_may_ovfl:
btst &0x0,1+FP_SCR0_EX(%a6) # is exponent 0x3fff?
bne.w fsqrt_sd_ovfl # yes, so overflow
fmov.l &0x0,%fpsr # clear FPSR
fmov.l L_SCR3(%a6),%fpcr # set FPCR
fsqrt.x FP_SCR0(%a6),%fp0 # perform absolute
fmov.l %fpsr,%d1 # save status
fmov.l &0x0,%fpcr # clear FPCR
or.l %d1,USER_FPSR(%a6) # save INEX2,N
fmov.x %fp0,%fp1 # make a copy of result
fcmp.b %fp1,&0x1 # is |result| >= 1.b?
fbge.w fsqrt_sd_ovfl_tst # yes; overflow has occurred
bra.w fsqrt_sd_normal_exit
##########################################################################
#
#
fsqrt_not_norm:
cmpi.b %d1,&DENORM # weed out DENORM
beq.w fsqrt_denorm
cmpi.b %d1,&ZERO # weed out ZERO
beq.b fsqrt_zero
cmpi.b %d1,&INF # weed out INF
beq.b fsqrt_inf
cmpi.b %d1,&SNAN # weed out SNAN
beq.l res_snan_1op
bra.l res_qnan_1op
#
#
fsqrt_zero:
tst.b SRC_EX(%a0) # is ZERO positive or negative?
bmi.b fsqrt_zero_m # negative
fsqrt_zero_p:
fmov.s &0x00000000,%fp0 # return +ZERO
mov.b &z_bmask,FPSR_CC(%a6) # set 'Z' ccode bit
rts
fsqrt_zero_m:
fmov.s &0x80000000,%fp0 # return -ZERO
mov.b &z_bmask+neg_bmask,FPSR_CC(%a6) # set 'Z','N' ccode bits
rts
fsqrt_inf:
tst.b SRC_EX(%a0) # is INF positive or negative?
bmi.l res_operr # negative
fsqrt_inf_p:
fmovm.x SRC(%a0),&0x80 # return +INF in fp0
mov.b &inf_bmask,FPSR_CC(%a6) # set 'I' ccode bit
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global fetch_dreg
fetch_dreg:
mov.w (tbl_fdreg.b,%pc,%d1.w*2),%d0
jmp (tbl_fdreg.b,%pc,%d0.w*1)
tbl_fdreg:
short fdreg0 - tbl_fdreg
short fdreg1 - tbl_fdreg
short fdreg2 - tbl_fdreg
short fdreg3 - tbl_fdreg
short fdreg4 - tbl_fdreg
short fdreg5 - tbl_fdreg
short fdreg6 - tbl_fdreg
short fdreg7 - tbl_fdreg
short fdreg8 - tbl_fdreg
short fdreg9 - tbl_fdreg
short fdrega - tbl_fdreg
short fdregb - tbl_fdreg
short fdregc - tbl_fdreg
short fdregd - tbl_fdreg
short fdrege - tbl_fdreg
short fdregf - tbl_fdreg
fdreg0:
mov.l EXC_DREGS+0x0(%a6),%d0
rts
fdreg1:
mov.l EXC_DREGS+0x4(%a6),%d0
rts
fdreg2:
mov.l %d2,%d0
rts
fdreg3:
mov.l %d3,%d0
rts
fdreg4:
mov.l %d4,%d0
rts
fdreg5:
mov.l %d5,%d0
rts
fdreg6:
mov.l %d6,%d0
rts
fdreg7:
mov.l %d7,%d0
rts
fdreg8:
mov.l EXC_DREGS+0x8(%a6),%d0
rts
fdreg9:
mov.l EXC_DREGS+0xc(%a6),%d0
rts
fdrega:
mov.l %a2,%d0
rts
fdregb:
mov.l %a3,%d0
rts
fdregc:
mov.l %a4,%d0
rts
fdregd:
mov.l %a5,%d0
rts
fdrege:
mov.l (%a6),%d0
rts
fdregf:
mov.l EXC_A7(%a6),%d0
rts
#########################################################################
# #
# #
# #
# (data register is updated) #
# #
# #
#########################################################################
global store_dreg_l
store_dreg_l:
mov.w (tbl_sdregl.b,%pc,%d1.w*2),%d1
jmp (tbl_sdregl.b,%pc,%d1.w*1)
tbl_sdregl:
short sdregl0 - tbl_sdregl
short sdregl1 - tbl_sdregl
short sdregl2 - tbl_sdregl
short sdregl3 - tbl_sdregl
short sdregl4 - tbl_sdregl
short sdregl5 - tbl_sdregl
short sdregl6 - tbl_sdregl
short sdregl7 - tbl_sdregl
sdregl0:
mov.l %d0,EXC_DREGS+0x0(%a6)
rts
sdregl1:
mov.l %d0,EXC_DREGS+0x4(%a6)
rts
sdregl2:
mov.l %d0,%d2
rts
sdregl3:
mov.l %d0,%d3
rts
sdregl4:
mov.l %d0,%d4
rts
sdregl5:
mov.l %d0,%d5
rts
sdregl6:
mov.l %d0,%d6
rts
sdregl7:
mov.l %d0,%d7
rts
#########################################################################
# #
# #
# #
# (data register is updated) #
# #
# #
#########################################################################
global store_dreg_w
store_dreg_w:
mov.w (tbl_sdregw.b,%pc,%d1.w*2),%d1
jmp (tbl_sdregw.b,%pc,%d1.w*1)
tbl_sdregw:
short sdregw0 - tbl_sdregw
short sdregw1 - tbl_sdregw
short sdregw2 - tbl_sdregw
short sdregw3 - tbl_sdregw
short sdregw4 - tbl_sdregw
short sdregw5 - tbl_sdregw
short sdregw6 - tbl_sdregw
short sdregw7 - tbl_sdregw
sdregw0:
mov.w %d0,2+EXC_DREGS+0x0(%a6)
rts
sdregw1:
mov.w %d0,2+EXC_DREGS+0x4(%a6)
rts
sdregw2:
mov.w %d0,%d2
rts
sdregw3:
mov.w %d0,%d3
rts
sdregw4:
mov.w %d0,%d4
rts
sdregw5:
mov.w %d0,%d5
rts
sdregw6:
mov.w %d0,%d6
rts
sdregw7:
mov.w %d0,%d7
rts
#########################################################################
# #
# #
# #
# (data register is updated) #
# #
# #
#########################################################################
global store_dreg_b
store_dreg_b:
mov.w (tbl_sdregb.b,%pc,%d1.w*2),%d1
jmp (tbl_sdregb.b,%pc,%d1.w*1)
tbl_sdregb:
short sdregb0 - tbl_sdregb
short sdregb1 - tbl_sdregb
short sdregb2 - tbl_sdregb
short sdregb3 - tbl_sdregb
short sdregb4 - tbl_sdregb
short sdregb5 - tbl_sdregb
short sdregb6 - tbl_sdregb
short sdregb7 - tbl_sdregb
sdregb0:
mov.b %d0,3+EXC_DREGS+0x0(%a6)
rts
sdregb1:
mov.b %d0,3+EXC_DREGS+0x4(%a6)
rts
sdregb2:
mov.b %d0,%d2
rts
sdregb3:
mov.b %d0,%d3
rts
sdregb4:
mov.b %d0,%d4
rts
sdregb5:
mov.b %d0,%d5
rts
sdregb6:
mov.b %d0,%d6
rts
sdregb7:
mov.b %d0,%d7
rts
#########################################################################
# #
# #
# #
# (address register is updated) #
# #
# #
#########################################################################
global inc_areg
inc_areg:
mov.w (tbl_iareg.b,%pc,%d1.w*2),%d1
jmp (tbl_iareg.b,%pc,%d1.w*1)
tbl_iareg:
short iareg0 - tbl_iareg
short iareg1 - tbl_iareg
short iareg2 - tbl_iareg
short iareg3 - tbl_iareg
short iareg4 - tbl_iareg
short iareg5 - tbl_iareg
short iareg6 - tbl_iareg
short iareg7 - tbl_iareg
iareg0: add.l %d0,EXC_DREGS+0x8(%a6)
rts
iareg1: add.l %d0,EXC_DREGS+0xc(%a6)
rts
iareg2: add.l %d0,%a2
rts
iareg3: add.l %d0,%a3
rts
iareg4: add.l %d0,%a4
rts
iareg5: add.l %d0,%a5
rts
iareg6: add.l %d0,(%a6)
rts
iareg7: mov.b &mia7_flg,SPCOND_FLG(%a6)
cmpi.b %d0,&0x1
beq.b iareg7b
add.l %d0,EXC_A7(%a6)
rts
iareg7b:
addq.l &0x2,EXC_A7(%a6)
rts
#########################################################################
# #
# #
# #
# (address register is updated) #
# #
# #
#########################################################################
global dec_areg
dec_areg:
mov.w (tbl_dareg.b,%pc,%d1.w*2),%d1
jmp (tbl_dareg.b,%pc,%d1.w*1)
tbl_dareg:
short dareg0 - tbl_dareg
short dareg1 - tbl_dareg
short dareg2 - tbl_dareg
short dareg3 - tbl_dareg
short dareg4 - tbl_dareg
short dareg5 - tbl_dareg
short dareg6 - tbl_dareg
short dareg7 - tbl_dareg
dareg0: sub.l %d0,EXC_DREGS+0x8(%a6)
rts
dareg1: sub.l %d0,EXC_DREGS+0xc(%a6)
rts
dareg2: sub.l %d0,%a2
rts
dareg3: sub.l %d0,%a3
rts
dareg4: sub.l %d0,%a4
rts
dareg5: sub.l %d0,%a5
rts
dareg6: sub.l %d0,(%a6)
rts
dareg7: mov.b &mda7_flg,SPCOND_FLG(%a6)
cmpi.b %d0,&0x1
beq.b dareg7b
sub.l %d0,EXC_A7(%a6)
rts
dareg7b:
subq.l &0x2,EXC_A7(%a6)
rts
##############################################################################
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global load_fpn1
load_fpn1:
mov.w (tbl_load_fpn1.b,%pc,%d0.w*2), %d0
jmp (tbl_load_fpn1.b,%pc,%d0.w*1)
tbl_load_fpn1:
short load_fpn1_0 - tbl_load_fpn1
short load_fpn1_1 - tbl_load_fpn1
short load_fpn1_2 - tbl_load_fpn1
short load_fpn1_3 - tbl_load_fpn1
short load_fpn1_4 - tbl_load_fpn1
short load_fpn1_5 - tbl_load_fpn1
short load_fpn1_6 - tbl_load_fpn1
short load_fpn1_7 - tbl_load_fpn1
load_fpn1_0:
mov.l 0+EXC_FP0(%a6), 0+FP_SRC(%a6)
mov.l 4+EXC_FP0(%a6), 4+FP_SRC(%a6)
mov.l 8+EXC_FP0(%a6), 8+FP_SRC(%a6)
lea FP_SRC(%a6), %a0
rts
load_fpn1_1:
mov.l 0+EXC_FP1(%a6), 0+FP_SRC(%a6)
mov.l 4+EXC_FP1(%a6), 4+FP_SRC(%a6)
mov.l 8+EXC_FP1(%a6), 8+FP_SRC(%a6)
lea FP_SRC(%a6), %a0
rts
load_fpn1_2:
fmovm.x &0x20, FP_SRC(%a6)
lea FP_SRC(%a6), %a0
rts
load_fpn1_3:
fmovm.x &0x10, FP_SRC(%a6)
lea FP_SRC(%a6), %a0
rts
load_fpn1_4:
fmovm.x &0x08, FP_SRC(%a6)
lea FP_SRC(%a6), %a0
rts
load_fpn1_5:
fmovm.x &0x04, FP_SRC(%a6)
lea FP_SRC(%a6), %a0
rts
load_fpn1_6:
fmovm.x &0x02, FP_SRC(%a6)
lea FP_SRC(%a6), %a0
rts
load_fpn1_7:
fmovm.x &0x01, FP_SRC(%a6)
lea FP_SRC(%a6), %a0
rts
#############################################################################
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global load_fpn2
load_fpn2:
mov.w (tbl_load_fpn2.b,%pc,%d0.w*2), %d0
jmp (tbl_load_fpn2.b,%pc,%d0.w*1)
tbl_load_fpn2:
short load_fpn2_0 - tbl_load_fpn2
short load_fpn2_1 - tbl_load_fpn2
short load_fpn2_2 - tbl_load_fpn2
short load_fpn2_3 - tbl_load_fpn2
short load_fpn2_4 - tbl_load_fpn2
short load_fpn2_5 - tbl_load_fpn2
short load_fpn2_6 - tbl_load_fpn2
short load_fpn2_7 - tbl_load_fpn2
load_fpn2_0:
mov.l 0+EXC_FP0(%a6), 0+FP_DST(%a6)
mov.l 4+EXC_FP0(%a6), 4+FP_DST(%a6)
mov.l 8+EXC_FP0(%a6), 8+FP_DST(%a6)
lea FP_DST(%a6), %a0
rts
load_fpn2_1:
mov.l 0+EXC_FP1(%a6), 0+FP_DST(%a6)
mov.l 4+EXC_FP1(%a6), 4+FP_DST(%a6)
mov.l 8+EXC_FP1(%a6), 8+FP_DST(%a6)
lea FP_DST(%a6), %a0
rts
load_fpn2_2:
fmovm.x &0x20, FP_DST(%a6)
lea FP_DST(%a6), %a0
rts
load_fpn2_3:
fmovm.x &0x10, FP_DST(%a6)
lea FP_DST(%a6), %a0
rts
load_fpn2_4:
fmovm.x &0x08, FP_DST(%a6)
lea FP_DST(%a6), %a0
rts
load_fpn2_5:
fmovm.x &0x04, FP_DST(%a6)
lea FP_DST(%a6), %a0
rts
load_fpn2_6:
fmovm.x &0x02, FP_DST(%a6)
lea FP_DST(%a6), %a0
rts
load_fpn2_7:
fmovm.x &0x01, FP_DST(%a6)
lea FP_DST(%a6), %a0
rts
#############################################################################
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global store_fpreg
store_fpreg:
mov.w (tbl_store_fpreg.b,%pc,%d0.w*2), %d0
jmp (tbl_store_fpreg.b,%pc,%d0.w*1)
tbl_store_fpreg:
short store_fpreg_0 - tbl_store_fpreg
short store_fpreg_1 - tbl_store_fpreg
short store_fpreg_2 - tbl_store_fpreg
short store_fpreg_3 - tbl_store_fpreg
short store_fpreg_4 - tbl_store_fpreg
short store_fpreg_5 - tbl_store_fpreg
short store_fpreg_6 - tbl_store_fpreg
short store_fpreg_7 - tbl_store_fpreg
store_fpreg_0:
fmovm.x &0x80, EXC_FP0(%a6)
rts
store_fpreg_1:
fmovm.x &0x80, EXC_FP1(%a6)
rts
store_fpreg_2:
fmovm.x &0x01, -(%sp)
fmovm.x (%sp)+, &0x20
rts
store_fpreg_3:
fmovm.x &0x01, -(%sp)
fmovm.x (%sp)+, &0x10
rts
store_fpreg_4:
fmovm.x &0x01, -(%sp)
fmovm.x (%sp)+, &0x08
rts
store_fpreg_5:
fmovm.x &0x01, -(%sp)
fmovm.x (%sp)+, &0x04
rts
store_fpreg_6:
fmovm.x &0x01, -(%sp)
fmovm.x (%sp)+, &0x02
rts
store_fpreg_7:
fmovm.x &0x01, -(%sp)
fmovm.x (%sp)+, &0x01
rts
#########################################################################
# #
# #
# #
# #
# #
#########################################################################
global get_packed
get_packed:
mov.l &0xc,%d0 # packed is 12 bytes
bsr.l _dcalc_ea # fetch <ea>; correct An
lea FP_SRC(%a6),%a1 # pass: ptr to super dst
mov.l &0xc,%d0 # pass: 12 bytes
bsr.l _dmem_read # read packed operand
tst.l %d1 # did dfetch fail?
bne.l facc_in_x # yes
bfextu FP_SRC(%a6){&1:&15},%d0 # get exp
cmpi.w %d0,&0x7fff # INF or NAN?
bne.b gp_try_zero # no
rts # operand is an INF or NAN
gp_try_zero:
mov.b 3+FP_SRC(%a6),%d0 # get byte 4
andi.b &0x0f,%d0 # clear all but last nybble
bne.b gp_not_spec # not a zero
tst.l FP_SRC_HI(%a6) # is lw 2 zero?
bne.b gp_not_spec # not a zero
tst.l FP_SRC_LO(%a6) # is lw 3 zero?
bne.b gp_not_spec # not a zero
rts # operand is a ZERO
gp_not_spec:
lea FP_SRC(%a6),%a0 # pass: ptr to packed op
bsr.l decbin # convert to extended
fmovm.x &0x80,FP_SRC(%a6) # make this the srcop
rts
#########################################################################
# #
# #
# #
# #
# #
# #
# if negative, count the trailing zeros. Set the adjusted #
# #
# #
# #
# 10^(2^n) values. To reduce the error in forming factors #
# #
# #
# #
#########################################################################
#
# 10**{1,2,4,8,16,32,64,128,256,512,1024,2048,4096}. No rounding
#
RTABLE:
byte 0,0,0,0
byte 2,3,2,3
byte 2,3,3,2
byte 3,2,2,3
set FNIBS,7
set FSTRT,0
set ESTRT,4
set EDIGITS,2
global decbin
decbin:
mov.l 0x0(%a0),FP_SCR0_EX(%a6) # make a copy of input
mov.l 0x4(%a0),FP_SCR0_HI(%a6) # so we don't alter it
mov.l 0x8(%a0),FP_SCR0_LO(%a6)
lea FP_SCR0(%a6),%a0
movm.l &0x3c00,-(%sp) # save d2-d5
fmovm.x &0x1,-(%sp) # save fp1
#
# 1. Copy bcd value in memory for use as a working copy.
# 2. Calculate absolute value of exponent in d1 by mul and add.
# 3. Correct for exponent sign.
# 4. Subtract 16 to compensate for interpreting the mant as all integer digits.
# (i.e., all digits assumed left of the decimal point.)
#
#
# (*) d0: temp digit storage
# (*) d1: accumulator for binary exponent
# (*) d2: digit count
# (*) d3: offset pointer
# ( ) d4: first word of bcd
# ( ) a0: pointer to working bcd value
# ( ) a6: pointer to original bcd value
# (*) FP_SCR1: working copy of original bcd value
# (*) L_SCR1: copy of original exponent word
#
calc_e:
mov.l &EDIGITS,%d2 # # of nibbles (digits) in fraction part
mov.l &ESTRT,%d3 # counter to pick up digits
mov.l (%a0),%d4 # get first word of bcd
clr.l %d1 # zero d1 for accumulator
e_gd:
mulu.l &0xa,%d1 # mul partial product by one digit place
bfextu %d4{%d3:&4},%d0 # get the digit and zero extend into d0
add.l %d0,%d1 # d1 = d1 + d0
addq.b &4,%d3 # advance d3 to the next digit
dbf.w %d2,e_gd # if we have used all 3 digits, exit loop
btst &30,%d4 # get SE
beq.b e_pos # don't negate if pos
neg.l %d1 # negate before subtracting
e_pos:
sub.l &16,%d1 # sub to compensate for shift of mant
bge.b e_save # if still pos, do not neg
neg.l %d1 # now negative, make pos and set SE
or.l &0x40000000,%d4 # set SE in d4,
or.l &0x40000000,(%a0) # and in working bcd
e_save:
mov.l %d1,-(%sp) # save exp on stack
#
#
# 1. Calculate absolute value of mantissa in fp0 by mul and add.
# 2. Correct for mantissa sign.
# (i.e., all digits assumed left of the decimal point.)
#
#
# (*) d0: temp digit storage
# (*) d1: lword counter
# (*) d2: digit count
# (*) d3: offset pointer
# ( ) d4: words 2 and 3 of bcd
# ( ) a0: pointer to working bcd value
# ( ) a6: pointer to original bcd value
# (*) fp0: mantissa accumulator
# ( ) FP_SCR1: working copy of original bcd value
# ( ) L_SCR1: copy of original exponent word
#
calc_m:
mov.l &1,%d1 # word counter, init to 1
fmov.s &0x00000000,%fp0 # accumulator
#
#
#
bfextu (%a0){&28:&4},%d0 # integer part is ls digit in long word
fadd.b %d0,%fp0 # add digit to sum in fp0
#
#
#
loadlw:
mov.l (%a0,%d1.L*4),%d4 # load mantissa lonqword into d4
mov.l &FSTRT,%d3 # counter to pick up digits
mov.l &FNIBS,%d2 # reset number of digits per a0 ptr
md2b:
fmul.s &0x41200000,%fp0 # fp0 = fp0 * 10
bfextu %d4{%d3:&4},%d0 # get the digit and zero extend
fadd.b %d0,%fp0 # fp0 = fp0 + digit
#
#
# else continue with this long word.
#
addq.b &4,%d3 # advance d3 to the next digit
dbf.w %d2,md2b # check for last digit in this lw
nextlw:
addq.l &1,%d1 # inc lw pointer in mantissa
cmp.l %d1,&2 # test for last lw
ble.b loadlw # if not, get last one
#
#
m_sign:
btst &31,(%a0) # test sign of the mantissa
beq.b ap_st_z # if clear, go to append/strip zeros
fneg.x %fp0 # if set, negate fp0
#
#
# if the exp was positive, and added if it was negative. The purpose
#
# 1. Branch on the sign of the adjusted exponent.
# 2p.(positive exp)
# 2. Check M16 and the digits in lwords 2 and 3 in descending order.
# 3. Add one for each zero encountered until a non-zero digit.
# 4. Subtract the count from the exp.
# 5. Check if the exp has crossed zero in #3 above; make the exp abs
# 6. Multiply the mantissa by 10**count.
# 2n.(negative exp)
# 2. Check the digits in lwords 3 and 2 in descending order.
# 3. Add one for each zero encountered until a non-zero digit.
# 4. Add the count to the exp.
# 5. Check if the exp has crossed zero in #3 above; clear SE.
# 6. Divide the mantissa by 10**count.
#
# *Why 27? If the adjusted exponent is within -28 < expA < 28, than
#
#
# (*) d0: temp digit storage
# (*) d1: zero count
# (*) d2: digit count
# (*) d3: offset pointer
# ( ) d4: first word of bcd
# (*) d5: lword counter
# ( ) a0: pointer to working bcd value
# ( ) FP_SCR1: working copy of original bcd value
# ( ) L_SCR1: copy of original exponent word
#
#
#
ap_st_z:
mov.l (%sp),%d1 # load expA for range test
cmp.l %d1,&27 # test is with 27
ble.w pwrten # if abs(expA) <28, skip ap/st zeros
btst &30,(%a0) # check sign of exp
bne.b ap_st_n # if neg, go to neg side
clr.l %d1 # zero count reg
mov.l (%a0),%d4 # load lword 1 to d4
bfextu %d4{&28:&4},%d0 # get M16 in d0
bne.b ap_p_fx # if M16 is non-zero, go fix exp
addq.l &1,%d1 # inc zero count
mov.l &1,%d5 # init lword counter
mov.l (%a0,%d5.L*4),%d4 # get lword 2 to d4
bne.b ap_p_cl # if lw 2 is zero, skip it
addq.l &8,%d1 # and inc count by 8
addq.l &1,%d5 # inc lword counter
mov.l (%a0,%d5.L*4),%d4 # get lword 3 to d4
ap_p_cl:
clr.l %d3 # init offset reg
mov.l &7,%d2 # init digit counter
ap_p_gd:
bfextu %d4{%d3:&4},%d0 # get digit
bne.b ap_p_fx # if non-zero, go to fix exp
addq.l &4,%d3 # point to next digit
addq.l &1,%d1 # inc digit counter
dbf.w %d2,ap_p_gd # get next digit
ap_p_fx:
mov.l %d1,%d0 # copy counter to d2
mov.l (%sp),%d1 # get adjusted exp from memory
sub.l %d0,%d1 # subtract count from exp
bge.b ap_p_fm # if still pos, go to pwrten
neg.l %d1 # now its neg; get abs
mov.l (%a0),%d4 # load lword 1 to d4
or.l &0x40000000,%d4 # and set SE in d4
or.l &0x40000000,(%a0) # and in memory
#
#
ap_p_fm:
lea.l PTENRN(%pc),%a1 # get address of power-of-ten table
clr.l %d3 # init table index
fmov.s &0x3f800000,%fp1 # init fp1 to 1
mov.l &3,%d2 # init d2 to count bits in counter
ap_p_el:
asr.l &1,%d0 # shift lsb into carry
bcc.b ap_p_en # if 1, mul fp1 by pwrten factor
fmul.x (%a1,%d3),%fp1 # mul by 10**(d3_bit_no)
ap_p_en:
add.l &12,%d3 # inc d3 to next rtable entry
tst.l %d0 # check if d0 is zero
bne.b ap_p_el # if not, get next bit
fmul.x %fp1,%fp0 # mul mantissa by 10**(no_bits_shifted)
bra.b pwrten # go calc pwrten
#
#
ap_st_n:
clr.l %d1 # clr counter
mov.l &2,%d5 # set up d5 to point to lword 3
mov.l (%a0,%d5.L*4),%d4 # get lword 3
bne.b ap_n_cl # if not zero, check digits
sub.l &1,%d5 # dec d5 to point to lword 2
addq.l &8,%d1 # inc counter by 8
mov.l (%a0,%d5.L*4),%d4 # get lword 2
ap_n_cl:
mov.l &28,%d3 # point to last digit
mov.l &7,%d2 # init digit counter
ap_n_gd:
bfextu %d4{%d3:&4},%d0 # get digit
bne.b ap_n_fx # if non-zero, go to exp fix
subq.l &4,%d3 # point to previous digit
addq.l &1,%d1 # inc digit counter
dbf.w %d2,ap_n_gd # get next digit
ap_n_fx:
mov.l %d1,%d0 # copy counter to d0
mov.l (%sp),%d1 # get adjusted exp from memory
sub.l %d0,%d1 # subtract count from exp
bgt.b ap_n_fm # if still pos, go fix mantissa
neg.l %d1 # take abs of exp and clr SE
mov.l (%a0),%d4 # load lword 1 to d4
and.l &0xbfffffff,%d4 # and clr SE in d4
and.l &0xbfffffff,(%a0) # and in memory
#
#
ap_n_fm:
lea.l PTENRN(%pc),%a1 # get address of power-of-ten table
clr.l %d3 # init table index
fmov.s &0x3f800000,%fp1 # init fp1 to 1
mov.l &3,%d2 # init d2 to count bits in counter
ap_n_el:
asr.l &1,%d0 # shift lsb into carry
bcc.b ap_n_en # if 1, mul fp1 by pwrten factor
fmul.x (%a1,%d3),%fp1 # mul by 10**(d3_bit_no)
ap_n_en:
add.l &12,%d3 # inc d3 to next rtable entry
tst.l %d0 # check if d0 is zero
bne.b ap_n_el # if not, get next bit
fdiv.x %fp1,%fp0 # div mantissa by 10**(no_bits_shifted)
#
#
#
#
# (*) d0: temp
# ( ) d1: exponent
# (*) d2: {FPCR[6:5],SM,SE} as index in RTABLE; temp
# (*) d3: FPCR work copy
# ( ) d4: first word of bcd
# (*) a1: RTABLE pointer
# (*) d0: temp
# ( ) d1: exponent
# (*) d3: PWRTxx table index
# ( ) a0: pointer to working copy of bcd
# (*) a1: PWRTxx pointer
# (*) fp1: power-of-ten accumulator
#
#
#
#
# + + RP RP
# - + RP RM
# + - RP RM
# - - RP RP
#
# + + RM RM
# - + RM RP
# + - RM RP
# - - RM RM
#
# + + RZ RM
# - + RZ RM
# + - RZ RP
# - - RZ RP
#
#
pwrten:
mov.l USER_FPCR(%a6),%d3 # get user's FPCR
bfextu %d3{&26:&2},%d2 # isolate rounding mode bits
mov.l (%a0),%d4 # reload 1st bcd word to d4
asl.l &2,%d2 # format d2 to be
bfextu %d4{&0:&2},%d0 # {FPCR[6],FPCR[5],SM,SE}
add.l %d0,%d2 # in d2 as index into RTABLE
lea.l RTABLE(%pc),%a1 # load rtable base
mov.b (%a1,%d2),%d0 # load new rounding bits from table
clr.l %d3 # clear d3 to force no exc and extended
bfins %d0,%d3{&26:&2} # stuff new rounding bits in FPCR
fmov.l %d3,%fpcr # write new FPCR
asr.l &1,%d0 # write correct PTENxx table
bcc.b not_rp # to a1
lea.l PTENRP(%pc),%a1 # it is RP
bra.b calc_p # go to init section
not_rp:
asr.l &1,%d0 # keep checking
bcc.b not_rm
lea.l PTENRM(%pc),%a1 # it is RM
bra.b calc_p # go to init section
not_rm:
lea.l PTENRN(%pc),%a1 # it is RN
calc_p:
mov.l %d1,%d0 # copy exp to d0;use d0
bpl.b no_neg # if exp is negative,
neg.l %d0 # invert it
or.l &0x40000000,(%a0) # and set SE bit
no_neg:
clr.l %d3 # table index
fmov.s &0x3f800000,%fp1 # init fp1 to 1
e_loop:
asr.l &1,%d0 # shift next bit into carry
bcc.b e_next # if zero, skip the mul
fmul.x (%a1,%d3),%fp1 # mul by 10**(d3_bit_no)
e_next:
add.l &12,%d3 # inc d3 to next rtable entry
tst.l %d0 # check if d0 is zero
bne.b e_loop # not zero, continue shifting
#
#
# else divide fp0/fp1.
#
# ( ) a0: pointer to working bcd value
# (*) fp0: mantissa accumulator
# ( ) fp1: scaling factor - 10**(abs(exp))
#
pnorm:
btst &30,(%a0) # test the sign of the exponent
beq.b mul # if clear, go to multiply
div:
fdiv.x %fp1,%fp0 # exp is negative, so divide mant by exp
bra.b end_dec
mul:
fmul.x %fp1,%fp0 # exp is positive, so multiply by exp
#
#
#
#
end_dec:
fmov.l %fpsr,%d0 # get status register
bclr &inex2_bit+8,%d0 # test for inex2 and clear it
beq.b no_exc # skip this if no exc
ori.w &inx1a_mask,2+USER_FPSR(%a6) # set INEX1/AINEX
no_exc:
add.l &0x4,%sp # clear 1 lw param
fmovm.x (%sp)+,&0x40 # restore fp1
movm.l (%sp)+,&0x3c # restore d2-d5
fmov.l &0x0,%fpcr
fmov.l &0x0,%fpsr
rts
#########################################################################
# #
# #
# #
# #
# #
# #
# #
# #
# #
# if it is a positive number, or the number of digits #
# #
# 10^^(abs(ISCALE)) using a rounding mode which is a #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#########################################################################
set BINDEC_FLG, EXC_TEMP # DENORM flag
PLOG2:
long 0x3FFD0000,0x9A209A84,0xFBCFF798,0x00000000
PLOG2UP1:
long 0x3FFD0000,0x9A209A84,0xFBCFF799,0x00000000
FONE:
long 0x3F800000,0x00000000,0x00000000,0x00000000
FTWO:
long 0x40000000,0x00000000,0x00000000,0x00000000
FTEN:
long 0x41200000,0x00000000,0x00000000,0x00000000
F4933:
long 0x459A2800,0x00000000,0x00000000,0x00000000
RBDTBL:
byte 0,0,0,0
byte 3,3,2,2
byte 3,2,2,3
byte 2,3,3,2
#
#
global bindec
bindec:
movm.l &0x3f20,-(%sp) # {%d2-%d7/%a2}
fmovm.x &0x7,-(%sp) # {%fp0-%fp2}
#
fmov.l &rm_mode*0x10,%fpcr # set RM and ext
mov.l (%a0),L_SCR2(%a6) # save exponent for sign check
mov.l %d0,%d7 # move k-factor to d7
clr.b BINDEC_FLG(%a6) # clr norm/denorm flag
cmpi.b STAG(%a6),&DENORM # is input a DENORM?
bne.w A2_str # no; input is a NORM
#
#
un_de_norm:
mov.w (%a0),%d0
and.w &0x7fff,%d0 # strip sign of normalized exp
mov.l 4(%a0),%d1
mov.l 8(%a0),%d2
norm_loop:
sub.w &1,%d0
lsl.l &1,%d2
roxl.l &1,%d1
tst.l %d1
bge.b norm_loop
#
#
tst.w %d0
bgt.b pos_exp # if greater than zero, it is a norm
st BINDEC_FLG(%a6) # set flag for denorm
pos_exp:
and.w &0x7fff,%d0 # strip sign of normalized exp
mov.w %d0,(%a0)
mov.l %d1,4(%a0)
mov.l %d2,8(%a0)
#
A2_str:
mov.l (%a0),FP_SCR1(%a6) # move input to work space
mov.l 4(%a0),FP_SCR1+4(%a6) # move input to work space
mov.l 8(%a0),FP_SCR1+8(%a6) # move input to work space
and.l &0x7fffffff,FP_SCR1(%a6) # create abs(X)
#
tst.b BINDEC_FLG(%a6) # check for denorm
beq.b A3_cont # if clr, continue with norm
mov.l &-4933,%d6 # force ILOG = -4933
bra.b A4_str
A3_cont:
mov.w FP_SCR1(%a6),%d0 # move exp to d0
mov.w &0x3fff,FP_SCR1(%a6) # replace exponent with 0x3fff
fmov.x FP_SCR1(%a6),%fp0 # now fp0 has 1.f
sub.w &0x3fff,%d0 # strip off bias
fadd.w %d0,%fp0 # add in exp
fsub.s FONE(%pc),%fp0 # subtract off 1.0
fbge.w pos_res # if pos, branch
fmul.x PLOG2UP1(%pc),%fp0 # if neg, mul by LOG2UP1
fmov.l %fp0,%d6 # put ILOG in d6 as a lword
bra.b A4_str # go move out ILOG
pos_res:
fmul.x PLOG2(%pc),%fp0 # if pos, mul by LOG2
fmov.l %fp0,%d6 # put ILOG in d6 as a lword
A4_str:
fmov.l &0,%fpsr # zero all of fpsr - nothing needed
clr.w %d5 # clear ICTR
#
A6_str:
tst.l %d7 # branch on sign of k
ble.b k_neg # if k <= 0, LEN = ILOG + 1 - k
mov.l %d7,%d4 # if k > 0, LEN = k
bra.b len_ck # skip to LEN check
k_neg:
mov.l %d6,%d4 # first load ILOG to d4
sub.l %d7,%d4 # subtract off k
addq.l &1,%d4 # add in the 1
len_ck:
tst.l %d4 # LEN check: branch on sign of LEN
ble.b LEN_ng # if neg, set LEN = 1
cmp.l %d4,&17 # test if LEN > 17
ble.b A7_str # if not, forget it
mov.l &17,%d4 # set max LEN = 17
tst.l %d7 # if negative, never set OPERR
ble.b A7_str # if positive, continue
or.l &opaop_mask,USER_FPSR(%a6) # set OPERR & AIOP in USER_FPSR
bra.b A7_str # finished here
LEN_ng:
mov.l &1,%d4 # min LEN is 1
#
# ----------------------------------------------
#
A7_str:
tst.l %d7 # test sign of k
bgt.b k_pos # if pos and > 0, skip this
cmp.l %d7,%d6 # test k - ILOG
blt.b k_pos # if ILOG >= k, skip this
mov.l %d7,%d6 # if ((k<0) & (ILOG < k)) ILOG = k
k_pos:
mov.l %d6,%d0 # calc ILOG + 1 - LEN in d0
addq.l &1,%d0 # add the 1
sub.l %d4,%d0 # sub off LEN
swap %d5 # use upper word of d5 for LAMBDA
clr.w %d5 # set it zero initially
clr.w %d2 # set up d2 for very small case
tst.l %d0 # test sign of ISCALE
bge.b iscale # if pos, skip next inst
addq.w &1,%d5 # if neg, set LAMBDA true
cmp.l %d0,&0xffffecd4 # test iscale <= -4908
bgt.b no_inf # if false, skip rest
add.l &24,%d0 # add in 24 to iscale
mov.l &24,%d2 # put 24 in d2 for A9
no_inf:
neg.l %d0 # and take abs of ISCALE
iscale:
fmov.s FONE(%pc),%fp1 # init fp1 to 1
bfextu USER_FPCR(%a6){&26:&2},%d1 # get initial rmode bits
lsl.w &1,%d1 # put them in bits 2:1
add.w %d5,%d1 # add in LAMBDA
lsl.w &1,%d1 # put them in bits 3:1
tst.l L_SCR2(%a6) # test sign of original x
bge.b x_pos # if pos, don't set bit 0
addq.l &1,%d1 # if neg, set bit 0
x_pos:
lea.l RBDTBL(%pc),%a2 # load rbdtbl base
mov.b (%a2,%d1),%d3 # load d3 with new rmode
lsl.l &4,%d3 # put bits in proper position
fmov.l %d3,%fpcr # load bits into fpu
lsr.l &4,%d3 # put bits in proper position
tst.b %d3 # decode new rmode for pten table
bne.b not_rn # if zero, it is RN
lea.l PTENRN(%pc),%a1 # load a1 with RN table base
bra.b rmode # exit decode
not_rn:
lsr.b &1,%d3 # get lsb in carry
bcc.b not_rp2 # if carry clear, it is RM
lea.l PTENRP(%pc),%a1 # load a1 with RP table base
bra.b rmode # exit decode
not_rp2:
lea.l PTENRM(%pc),%a1 # load a1 with RM table base
rmode:
clr.l %d3 # clr table index
e_loop2:
lsr.l &1,%d0 # shift next bit into carry
bcc.b e_next2 # if zero, skip the mul
fmul.x (%a1,%d3),%fp1 # mul by 10**(d3_bit_no)
e_next2:
add.l &12,%d3 # inc d3 to next pwrten table entry
tst.l %d0 # test if ISCALE is zero
bne.b e_loop2 # if not, loop
#
fmov.l &0,%fpsr # clr INEX
fmov.l &rz_mode*0x10,%fpcr # set RZ rounding mode
# 10^24 is exact. If the input was denormalized, we must
#
A9_str:
fmov.x (%a0),%fp0 # load X from memory
fabs.x %fp0 # use abs(X)
tst.w %d5 # LAMBDA is in lower word of d5
bne.b sc_mul # if neg (LAMBDA = 1), scale by mul
fdiv.x %fp1,%fp0 # calculate X / SCALE -> Y to fp0
bra.w A10_st # branch to A10
sc_mul:
tst.b BINDEC_FLG(%a6) # check for denorm
beq.w A9_norm # if norm, continue with mul
fmovm.x &0x2,-(%sp) # save 10^ISCALE to stack
mov.w (%sp),%d3 # grab exponent
andi.w &0x7fff,%d3 # clear sign
ori.w &0x8000,(%a0) # make DENORM exp negative
add.w (%a0),%d3 # add DENORM exp to 10^ISCALE exp
subi.w &0x3fff,%d3 # subtract BIAS
add.w 36(%a1),%d3
subi.w &0x3fff,%d3 # subtract BIAS
add.w 48(%a1),%d3
subi.w &0x3fff,%d3 # subtract BIAS
bmi.w sc_mul_err # is result is DENORM, punt!!!
andi.w &0x8000,(%sp) # keep sign
or.w %d3,(%sp) # insert new exponent
andi.w &0x7fff,(%a0) # clear sign bit on DENORM again
mov.l 0x8(%a0),-(%sp) # put input op mantissa on stk
mov.l 0x4(%a0),-(%sp)
mov.l &0x3fff0000,-(%sp) # force exp to zero
fmovm.x (%sp)+,&0x80 # load normalized DENORM into fp0
fmul.x (%sp)+,%fp0
mov.l 36+8(%a1),-(%sp) # get 10^8 mantissa
mov.l 36+4(%a1),-(%sp)
mov.l &0x3fff0000,-(%sp) # force exp to zero
mov.l 48+8(%a1),-(%sp) # get 10^16 mantissa
mov.l 48+4(%a1),-(%sp)
mov.l &0x3fff0000,-(%sp)# force exp to zero
fmul.x (%sp)+,%fp0 # multiply fp0 by 10^8
fmul.x (%sp)+,%fp0 # multiply fp0 by 10^16
bra.b A10_st
sc_mul_err:
bra.b sc_mul_err
A9_norm:
tst.w %d2 # test for small exp case
beq.b A9_con # if zero, continue as normal
fmul.x 36(%a1),%fp0 # multiply fp0 by 10^8
fmul.x 48(%a1),%fp0 # multiply fp0 by 10^16
A9_con:
fmul.x %fp1,%fp0 # calculate X * SCALE -> Y to fp0
#
A10_st:
fmov.l %fpsr,%d0 # get FPSR
fmov.x %fp0,FP_SCR1(%a6) # move Y to memory
lea.l FP_SCR1(%a6),%a2 # load a2 with ptr to FP_SCR1
btst &9,%d0 # check if INEX2 set
beq.b A11_st # if clear, skip rest
or.l &1,8(%a2) # or in 1 to lsb of mantissa
fmov.x FP_SCR1(%a6),%fp0 # write adjusted Y back to fpu
A11_st:
mov.l USER_FPCR(%a6),L_SCR1(%a6) # save it for later
and.l &0x00000030,USER_FPCR(%a6) # set size to ext,
# ;block exceptions
#
A12_st:
movm.l &0xc0c0,-(%sp) # save regs used by sintd0 {%d0-%d1/%a0-%a1}
mov.l L_SCR1(%a6),-(%sp)
mov.l L_SCR2(%a6),-(%sp)
lea.l FP_SCR1(%a6),%a0 # a0 is ptr to FP_SCR1(a6)
fmov.x %fp0,(%a0) # move Y to memory at FP_SCR1(a6)
tst.l L_SCR2(%a6) # test sign of original operand
bge.b do_fint12 # if pos, use Y
or.l &0x80000000,(%a0) # if neg, use -Y
do_fint12:
mov.l USER_FPSR(%a6),-(%sp)
fmov.l USER_FPCR(%a6),%fpcr
fmov.l &0x0,%fpsr # clear the AEXC bits!!!
## mov.l USER_FPCR(%a6),%d0 # ext prec/keep rnd mode
## andi.l &0x00000030,%d0
## fmov.l %d0,%fpcr
fint.x FP_SCR1(%a6),%fp0 # do fint()
fmov.l %fpsr,%d0
or.w %d0,FPSR_EXCEPT(%a6)
## fmov.l &0x0,%fpcr
## fmov.l %fpsr,%d0 # don't keep ccodes
## or.w %d0,FPSR_EXCEPT(%a6)
mov.b (%sp),USER_FPSR(%a6)
add.l &4,%sp
mov.l (%sp)+,L_SCR2(%a6)
mov.l (%sp)+,L_SCR1(%a6)
movm.l (%sp)+,&0x303 # restore regs used by sint {%d0-%d1/%a0-%a1}
mov.l L_SCR2(%a6),FP_SCR1(%a6) # restore original exponent
mov.l L_SCR1(%a6),USER_FPCR(%a6) # restore user's FPCR
#
#
A13_st:
swap %d5 # put ICTR in lower word of d5
tst.w %d5 # check if ICTR = 0
bne not_zr # if non-zero, go to second test
#
#
fmov.s FONE(%pc),%fp2 # init fp2 to 1.0
mov.l %d4,%d0 # put LEN in d0
subq.l &1,%d0 # d0 = LEN -1
clr.l %d3 # clr table index
l_loop:
lsr.l &1,%d0 # shift next bit into carry
bcc.b l_next # if zero, skip the mul
fmul.x (%a1,%d3),%fp2 # mul by 10**(d3_bit_no)
l_next:
add.l &12,%d3 # inc d3 to next pwrten table entry
tst.l %d0 # test if LEN is zero
bne.b l_loop # if not, loop
#
# 10^LEN-1 is computed for this test and A14. If the input was
#
tst.b BINDEC_FLG(%a6) # check if input was norm
beq.b A13_con # if norm, continue with checking
fabs.x %fp0 # take abs of YINT
bra test_2
#
#
A13_con:
fabs.x %fp0 # take abs of YINT
fcmp.x %fp0,%fp2 # compare abs(YINT) with 10^(LEN-1)
fbge.w test_2 # if greater, do next test
subq.l &1,%d6 # subtract 1 from ILOG
mov.w &1,%d5 # set ICTR
fmov.l &rm_mode*0x10,%fpcr # set rmode to RM
fmul.s FTEN(%pc),%fp2 # compute 10^LEN
bra.w A6_str # return to A6 and recompute YINT
test_2:
fmul.s FTEN(%pc),%fp2 # compute 10^LEN
fcmp.x %fp0,%fp2 # compare abs(YINT) with 10^LEN
fblt.w A14_st # if less, all is ok, go to A14
fbgt.w fix_ex # if greater, fix and redo
fdiv.s FTEN(%pc),%fp0 # if equal, divide by 10
addq.l &1,%d6 # and inc ILOG
bra.b A14_st # and continue elsewhere
fix_ex:
addq.l &1,%d6 # increment ILOG by 1
mov.w &1,%d5 # set ICTR
fmov.l &rm_mode*0x10,%fpcr # set rmode to RM
bra.w A6_str # return to A6 and recompute YINT
#
# 10^LEN is again computed using whatever table is in a1 since the
#
not_zr:
fmov.s FONE(%pc),%fp2 # init fp2 to 1.0
mov.l %d4,%d0 # put LEN in d0
clr.l %d3 # clr table index
z_loop:
lsr.l &1,%d0 # shift next bit into carry
bcc.b z_next # if zero, skip the mul
fmul.x (%a1,%d3),%fp2 # mul by 10**(d3_bit_no)
z_next:
add.l &12,%d3 # inc d3 to next pwrten table entry
tst.l %d0 # test if LEN is zero
bne.b z_loop # if not, loop
fabs.x %fp0 # get abs(YINT)
fcmp.x %fp0,%fp2 # check if abs(YINT) = 10^LEN
fbneq.w A14_st # if not, skip this
fdiv.s FTEN(%pc),%fp0 # divide abs(YINT) by 10
addq.l &1,%d6 # and inc ILOG by 1
addq.l &1,%d4 # and inc LEN
fmul.s FTEN(%pc),%fp2 # if LEN++, the get 10^^LEN
#
#
# /ptr to first mantissa byte in result string
A14_st:
fmov.l &rz_mode*0x10,%fpcr # force rz for conversion
fdiv.x %fp2,%fp0 # divide abs(YINT) by 10^LEN
lea.l FP_SCR0(%a6),%a0
fmov.x %fp0,(%a0) # move abs(YINT)/10^LEN to memory
mov.l 4(%a0),%d2 # move 2nd word of FP_RES to d2
mov.l 8(%a0),%d3 # move 3rd word of FP_RES to d3
clr.l 4(%a0) # zero word 2 of FP_RES
clr.l 8(%a0) # zero word 3 of FP_RES
mov.l (%a0),%d0 # move exponent to d0
swap %d0 # put exponent in lower word
beq.b no_sft # if zero, don't shift
sub.l &0x3ffd,%d0 # sub bias less 2 to make fract
tst.l %d0 # check if > 1
bgt.b no_sft # if so, don't shift
neg.l %d0 # make exp positive
m_loop:
lsr.l &1,%d2 # shift d2:d3 right, add 0s
roxr.l &1,%d3 # the number of places
dbf.w %d0,m_loop # given in d0
no_sft:
tst.l %d2 # check for mantissa of zero
bne.b no_zr # if not, go on
tst.l %d3 # continue zero check
beq.b zer_m # if zero, go directly to binstr
no_zr:
clr.l %d1 # put zero in d1 for addx
add.l &0x00000080,%d3 # inc at bit 7
addx.l %d1,%d2 # continue inc
and.l &0xffffff80,%d3 # strip off lsb not used by 882
zer_m:
mov.l %d4,%d0 # put LEN in d0 for binstr call
addq.l &3,%a0 # a0 points to M16 byte in result
bsr binstr # call binstr to convert mant
#
#
# 32 16 15 0
# -----------------------------------------
# | 0 | e3 | e2 | e1 | e4 | X | X | X |
# -----------------------------------------
#
#
A15_st:
tst.b BINDEC_FLG(%a6) # check for denorm
beq.b not_denorm
ftest.x %fp0 # test for zero
fbeq.w den_zero # if zero, use k-factor or 4933
fmov.l %d6,%fp0 # float ILOG
fabs.x %fp0 # get abs of ILOG
bra.b convrt
den_zero:
tst.l %d7 # check sign of the k-factor
blt.b use_ilog # if negative, use ILOG
fmov.s F4933(%pc),%fp0 # force exponent to 4933
bra.b convrt # do it
use_ilog:
fmov.l %d6,%fp0 # float ILOG
fabs.x %fp0 # get abs of ILOG
bra.b convrt
not_denorm:
ftest.x %fp0 # test for zero
fbneq.w not_zero # if zero, force exponent
fmov.s FONE(%pc),%fp0 # force exponent to 1
bra.b convrt # do it
not_zero:
fmov.l %d6,%fp0 # float ILOG
fabs.x %fp0 # get abs of ILOG
convrt:
fdiv.x 24(%a1),%fp0 # compute ILOG/10^4
fmov.x %fp0,FP_SCR1(%a6) # store fp0 in memory
mov.l 4(%a2),%d2 # move word 2 to d2
mov.l 8(%a2),%d3 # move word 3 to d3
mov.w (%a2),%d0 # move exp to d0
beq.b x_loop_fin # if zero, skip the shift
sub.w &0x3ffd,%d0 # subtract off bias
neg.w %d0 # make exp positive
x_loop:
lsr.l &1,%d2 # shift d2:d3 right
roxr.l &1,%d3 # the number of places
dbf.w %d0,x_loop # given in d0
x_loop_fin:
clr.l %d1 # put zero in d1 for addx
add.l &0x00000080,%d3 # inc at bit 6
addx.l %d1,%d2 # continue inc
and.l &0xffffff80,%d3 # strip off lsb not used by 882
mov.l &4,%d0 # put 4 in d0 for binstr call
lea.l L_SCR1(%a6),%a0 # a0 is ptr to L_SCR1 for exp digits
bsr binstr # call binstr to convert exp
mov.l L_SCR1(%a6),%d0 # load L_SCR1 lword to d0
mov.l &12,%d1 # use d1 for shift count
lsr.l %d1,%d0 # shift d0 right by 12
bfins %d0,FP_SCR0(%a6){&4:&12} # put e3:e2:e1 in FP_SCR0
lsr.l %d1,%d0 # shift d0 right by 12
bfins %d0,FP_SCR0(%a6){&16:&4} # put e4 in FP_SCR0
tst.b %d0 # check if e4 is zero
beq.b A16_st # if zero, skip rest
or.l &opaop_mask,USER_FPSR(%a6) # set OPERR & AIOP in USER_FPSR
#
A16_st:
clr.l %d0 # clr d0 for collection of signs
and.b &0x0f,FP_SCR0(%a6) # clear first nibble of FP_SCR0
tst.l L_SCR2(%a6) # check sign of original mantissa
bge.b mant_p # if pos, don't set SM
mov.l &2,%d0 # move 2 in to d0 for SM
mant_p:
tst.l %d6 # check sign of ILOG
bge.b wr_sgn # if pos, don't set SE
addq.l &1,%d0 # set bit 0 in d0 for SE
wr_sgn:
bfins %d0,FP_SCR0(%a6){&0:&2} # insert SM and SE into FP_SCR0
fmov.l &0,%fpsr # clear possible inex2/ainex bits
fmovm.x (%sp)+,&0xe0 # {%fp0-%fp2}
movm.l (%sp)+,&0x4fc # {%d2-%d7/%a2}
rts
global PTENRN
PTENRN:
long 0x40020000,0xA0000000,0x00000000 # 10 ^ 1
long 0x40050000,0xC8000000,0x00000000 # 10 ^ 2
long 0x400C0000,0x9C400000,0x00000000 # 10 ^ 4
long 0x40190000,0xBEBC2000,0x00000000 # 10 ^ 8
long 0x40340000,0x8E1BC9BF,0x04000000 # 10 ^ 16
long 0x40690000,0x9DC5ADA8,0x2B70B59E # 10 ^ 32
long 0x40D30000,0xC2781F49,0xFFCFA6D5 # 10 ^ 64
long 0x41A80000,0x93BA47C9,0x80E98CE0 # 10 ^ 128
long 0x43510000,0xAA7EEBFB,0x9DF9DE8E # 10 ^ 256
long 0x46A30000,0xE319A0AE,0xA60E91C7 # 10 ^ 512
long 0x4D480000,0xC9767586,0x81750C17 # 10 ^ 1024
long 0x5A920000,0x9E8B3B5D,0xC53D5DE5 # 10 ^ 2048
long 0x75250000,0xC4605202,0x8A20979B # 10 ^ 4096
global PTENRP
PTENRP:
long 0x40020000,0xA0000000,0x00000000 # 10 ^ 1
long 0x40050000,0xC8000000,0x00000000 # 10 ^ 2
long 0x400C0000,0x9C400000,0x00000000 # 10 ^ 4
long 0x40190000,0xBEBC2000,0x00000000 # 10 ^ 8
long 0x40340000,0x8E1BC9BF,0x04000000 # 10 ^ 16
long 0x40690000,0x9DC5ADA8,0x2B70B59E # 10 ^ 32
long 0x40D30000,0xC2781F49,0xFFCFA6D6 # 10 ^ 64
long 0x41A80000,0x93BA47C9,0x80E98CE0 # 10 ^ 128
long 0x43510000,0xAA7EEBFB,0x9DF9DE8E # 10 ^ 256
long 0x46A30000,0xE319A0AE,0xA60E91C7 # 10 ^ 512
long 0x4D480000,0xC9767586,0x81750C18 # 10 ^ 1024
long 0x5A920000,0x9E8B3B5D,0xC53D5DE5 # 10 ^ 2048
long 0x75250000,0xC4605202,0x8A20979B # 10 ^ 4096
global PTENRM
PTENRM:
long 0x40020000,0xA0000000,0x00000000 # 10 ^ 1
long 0x40050000,0xC8000000,0x00000000 # 10 ^ 2
long 0x400C0000,0x9C400000,0x00000000 # 10 ^ 4
long 0x40190000,0xBEBC2000,0x00000000 # 10 ^ 8
long 0x40340000,0x8E1BC9BF,0x04000000 # 10 ^ 16
long 0x40690000,0x9DC5ADA8,0x2B70B59D # 10 ^ 32
long 0x40D30000,0xC2781F49,0xFFCFA6D5 # 10 ^ 64
long 0x41A80000,0x93BA47C9,0x80E98CDF # 10 ^ 128
long 0x43510000,0xAA7EEBFB,0x9DF9DE8D # 10 ^ 256
long 0x46A30000,0xE319A0AE,0xA60E91C6 # 10 ^ 512
long 0x4D480000,0xC9767586,0x81750C17 # 10 ^ 1024
long 0x5A920000,0x9E8B3B5D,0xC53D5DE4 # 10 ^ 2048
long 0x75250000,0xC4605202,0x8A20979A # 10 ^ 4096
#########################################################################
# #
# (This pointer must point to byte 4 of the first #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#########################################################################
#
#
#
global binstr
binstr:
movm.l &0xff00,-(%sp) # {%d0-%d7}
#
#
mov.l &1,%d7 # init d7 for second digit
subq.l &1,%d0 # for dbf d0 would have LEN+1 passes
#
#
loop:
mov.l %d2,%d4 # copy the fraction before muls
mov.l %d3,%d5 # to d4:d5
#
#
bfextu %d2{&0:&3},%d1 # copy 3 msbs of d2 into d1
asl.l &3,%d2 # shift d2 left by 3 places
bfextu %d3{&0:&3},%d6 # copy 3 msbs of d3 into d6
asl.l &3,%d3 # shift d3 left by 3 places
or.l %d6,%d2 # or in msbs from d3 into d2
#
#
asl.l &1,%d5 # mul d5 by 2
roxl.l &1,%d4 # mul d4 by 2
swap %d6 # put 0 in d6 lower word
addx.w %d6,%d1 # add in extend from mul by 2
#
#
add.l %d5,%d3 # add lower 32 bits
nop # ERRATA FIX #13 (Rev. 1.2 6/6/90)
addx.l %d4,%d2 # add with extend upper 32 bits
nop # ERRATA FIX #13 (Rev. 1.2 6/6/90)
addx.w %d6,%d1 # add in extend from add to d1
swap %d6 # with d6 = 0; put 0 in upper word
#
#
tst.w %d7 # if zero, store digit & to loop
beq.b first_d # if non-zero, form byte & write
sec_d:
swap %d7 # bring first digit to word d7b
asl.w &4,%d7 # first digit in upper 4 bits d7b
add.w %d1,%d7 # add in ls digit to d7b
mov.b %d7,(%a0)+ # store d7b byte in memory
swap %d7 # put LEN counter in word d7a
clr.w %d7 # set d7a to signal no digits done
dbf.w %d0,loop # do loop some more!
bra.b end_bstr # finished, so exit
first_d:
swap %d7 # put digit word in d7b
mov.w %d1,%d7 # put new digit in d7b
swap %d7 # put LEN counter in word d7a
addq.w &1,%d7 # set d7a to signal first digit done
dbf.w %d0,loop # do loop some more!
swap %d7 # put last digit in string
lsl.w &4,%d7 # move it to upper 4 bits
mov.b %d7,(%a0)+ # store it in memory string
#
#
end_bstr:
movm.l (%sp)+,&0xff # {%d0-%d7}
rts
#########################################################################
# #
# #
# #
# #
# #
# -(an)+ register gets returned to its pre-exception value and then #
# #
#########################################################################
facc_in_b:
movq.l &0x1,%d0 # one byte
bsr.w restore # fix An
mov.w &0x0121,EXC_VOFF(%a6) # set FSLW
bra.w facc_finish
facc_in_w:
movq.l &0x2,%d0 # two bytes
bsr.w restore # fix An
mov.w &0x0141,EXC_VOFF(%a6) # set FSLW
bra.b facc_finish
facc_in_l:
movq.l &0x4,%d0 # four bytes
bsr.w restore # fix An
mov.w &0x0101,EXC_VOFF(%a6) # set FSLW
bra.b facc_finish
facc_in_d:
movq.l &0x8,%d0 # eight bytes
bsr.w restore # fix An
mov.w &0x0161,EXC_VOFF(%a6) # set FSLW
bra.b facc_finish
facc_in_x:
movq.l &0xc,%d0 # twelve bytes
bsr.w restore # fix An
mov.w &0x0161,EXC_VOFF(%a6) # set FSLW
bra.b facc_finish
################################################################
facc_out_b:
movq.l &0x1,%d0 # one byte
bsr.w restore # restore An
mov.w &0x00a1,EXC_VOFF(%a6) # set FSLW
bra.b facc_finish
facc_out_w:
movq.l &0x2,%d0 # two bytes
bsr.w restore # restore An
mov.w &0x00c1,EXC_VOFF(%a6) # set FSLW
bra.b facc_finish
facc_out_l:
movq.l &0x4,%d0 # four bytes
bsr.w restore # restore An
mov.w &0x0081,EXC_VOFF(%a6) # set FSLW
bra.b facc_finish
facc_out_d:
movq.l &0x8,%d0 # eight bytes
bsr.w restore # restore An
mov.w &0x00e1,EXC_VOFF(%a6) # set FSLW
bra.b facc_finish
facc_out_x:
mov.l &0xc,%d0 # twelve bytes
bsr.w restore # restore An
mov.w &0x00e1,EXC_VOFF(%a6) # set FSLW
facc_finish:
mov.l USER_FPIAR(%a6),EXC_PC(%a6) # store current PC
fmovm.x EXC_FPREGS(%a6),&0xc0 # restore fp0-fp1
fmovm.l USER_FPCR(%a6),%fpcr,%fpsr,%fpiar # restore ctrl regs
movm.l EXC_DREGS(%a6),&0x0303 # restore d0-d1/a0-a1
unlk %a6
mov.l (%sp),-(%sp) # store SR, hi(PC)
mov.l 0x8(%sp),0x4(%sp) # store lo(PC)
mov.l 0xc(%sp),0x8(%sp) # store EA
mov.l &0x00000001,0xc(%sp) # store FSLW
mov.w 0x6(%sp),0xc(%sp) # fix FSLW (size)
mov.w &0x4008,0x6(%sp) # store voff
btst &0x5,(%sp) # supervisor or user mode?
beq.b facc_out2 # user
bset &0x2,0xd(%sp) # set supervisor TM bit
facc_out2:
bra.l _real_access
##################################################################
# if the effective addressing mode was predecrement or postincrement,
restore:
mov.b EXC_OPWORD+0x1(%a6),%d1
andi.b &0x38,%d1 # extract opmode
cmpi.b %d1,&0x18 # postinc?
beq.w rest_inc
cmpi.b %d1,&0x20 # predec?
beq.w rest_dec
rts
rest_inc:
mov.b EXC_OPWORD+0x1(%a6),%d1
andi.w &0x0007,%d1 # fetch An
mov.w (tbl_rest_inc.b,%pc,%d1.w*2),%d1
jmp (tbl_rest_inc.b,%pc,%d1.w*1)
tbl_rest_inc:
short ri_a0 - tbl_rest_inc
short ri_a1 - tbl_rest_inc
short ri_a2 - tbl_rest_inc
short ri_a3 - tbl_rest_inc
short ri_a4 - tbl_rest_inc
short ri_a5 - tbl_rest_inc
short ri_a6 - tbl_rest_inc
short ri_a7 - tbl_rest_inc
ri_a0:
sub.l %d0,EXC_DREGS+0x8(%a6) # fix stacked a0
rts
ri_a1:
sub.l %d0,EXC_DREGS+0xc(%a6) # fix stacked a1
rts
ri_a2:
sub.l %d0,%a2 # fix a2
rts
ri_a3:
sub.l %d0,%a3 # fix a3
rts
ri_a4:
sub.l %d0,%a4 # fix a4
rts
ri_a5:
sub.l %d0,%a5 # fix a5
rts
ri_a6:
sub.l %d0,(%a6) # fix stacked a6
rts
# if it's a fmove out instruction, we don't have to fix a7
ri_a7:
cmpi.b EXC_VOFF(%a6),&0x30 # move in or out?
bne.b ri_a7_done # out
btst &0x5,EXC_SR(%a6) # user or supervisor?
bne.b ri_a7_done # supervisor
movc %usp,%a0 # restore USP
sub.l %d0,%a0
movc %a0,%usp
ri_a7_done:
rts
rest_dec:
neg.l %d0
bra.b rest_inc