Home | History | Annotate | Line # | Download | only in fpsp
MONADIC.GEN revision 1.1
      1 *	MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
      2 *	M68000 Hi-Performance Microprocessor Division
      3 *	M68040 Software Package 
      4 *
      5 *	M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
      6 *	All rights reserved.
      7 *
      8 *	THE SOFTWARE is provided on an "AS IS" basis and without warranty.
      9 *	To the maximum extent permitted by applicable law,
     10 *	MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
     11 *	INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
     12 *	PARTICULAR PURPOSE and any warranty against infringement with
     13 *	regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
     14 *	and any accompanying written materials. 
     15 *
     16 *	To the maximum extent permitted by applicable law,
     17 *	IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
     18 *	(INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
     19 *	PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
     20 *	OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
     21 *	SOFTWARE.  Motorola assumes no responsibility for the maintenance
     22 *	and support of the SOFTWARE.  
     23 *
     24 *	You are hereby granted a copyright license to use, modify, and
     25 *	distribute the SOFTWARE so long as this entire notice is retained
     26 *	without alteration in any modified and/or redistributed versions,
     27 *	and that such modified versions are clearly identified as such.
     28 *	No licenses are granted by implication, estoppel or otherwise
     29 *	under any patents or trademarks of Motorola, Inc.
     30 
     31 *
     32 *	MONADIC.GEN 1.5 5/18/92
     33 *
     34 *	MONADIC.GEN 1.4 1/16/92
     35 *
     36 *	MONADIC.GEN 1.3 4/30/91
     37 *
     38 *	MONADIC.GEN --- generic MONADIC template
     39 *
     40 *	This version saves all registers that will be used by the emulation
     41 *	routines and restores all but FP0 on exit.  The FPSR is
     42 *	updated to reflect the result of the operation.  Return value
     43 *	is placed in FP0 for single, double and extended results.
     44 *	
     45 *	The package subroutines expect the incoming FPCR to be zeroed
     46 *	since they need extended precision to work properly.  The
     47 *	'final' FPCR is expected in d1 so that the calculated result
     48 *	can be properly sized and rounded.  Also, if the incoming FPCR
     49 *	has enabled any exceptions, the exception will be taken on the
     50 *	final fmovem in this template.
     51 *
     52 *	Customizations:  
     53 *		1. Remove the movem.l at the entry and exit of
     54 *		   each routine if your compiler treats those 
     55 *		   registers as scratch.
     56 *		2. Likewise, don't save FP0/FP1 if they are scratch
     57 *		   registers.
     58 *		3. Delete handling of the fpsr if you only care about
     59 *		   the result.  
     60 *		4. Some (most?) C compilers convert all float arguments
     61 *		   to double, and provide no support at all for extended
     62 *		   precision so remove the _OPs_ and _OPx_ entry points.
     63 *		5. Move the result to d0/d1 if the compiler is that old.
     64 *
     65 
     66 	xref	tag
     67 	xref	_OPr_
     68 	xref	_OPz_
     69 	xref	_OPi_
     70 	xref	_OPn_
     71 	xref	_OPm_
     72 
     73 	xdef	_OPs_
     74 _OPs_:
     75 	link	a6,#-LOCAL_SIZE
     76 	movem.l	d0-d1/a0-a1,USER_DA(a6)
     77 	fmovem.x fp0-fp3,USER_FP0(a6)
     78 	fmove.l	fpsr,USER_FPSR(a6)
     79 	fmove.l	fpcr,USER_FPCR(a6)
     80 	fmove.l	fpcr,d1		; user's rounding mode/precision
     81 	fmove.l	#0,fpcr		; force rounding mode/prec to extended,rn
     82 *
     83 *	copy, convert and tag input argument
     84 *
     85 	fmove.s	8(a6),fp0
     86 	fmove.x	fp0,ETEMP(a6)
     87 	lea	ETEMP(a6),a0
     88 	bsr	tag
     89 	move.b	d0,STAG(a6)
     90 	tst.b	d0
     91 	bne.b	_TMP_2
     92 	bsr	_OPr_		; normalized (regular) number
     93 	bra.b	_TMP_6
     94 _TMP_2:
     95 	cmp.b	#$20,d0		; zero?
     96 	bne.b	_TMP_3
     97 	bsr	_OPz_
     98 	bra.b	_TMP_6
     99 _TMP_3:
    100 	cmp.b	#$40,d0		; infinity?
    101 	bne.b	_TMP_4
    102 	bsr	_OPi_
    103 	bra.b	_TMP_6
    104 _TMP_4:
    105 	cmp.b	#$60,d0		; NaN?
    106 	bne.b	_TMP_5
    107 	bsr	_OPn_
    108 	bra.b	_TMP_6
    109 _TMP_5:
    110 	bsr	_OPm_		; assuming a denorm...
    111 
    112 _TMP_6:
    113 	fmove.l	fpsr,d0		; update status register
    114 	or.b	USER_FPSR+3(a6),d0	;add previously accrued exceptions
    115 	fmove.l	d0,fpsr
    116 *
    117 *	Result is now in FP0
    118 *
    119 	movem.l	USER_DA(a6),d0-d1/a0-a1
    120 	fmovem.x USER_FP1(a6),fp1-fp3	; note: FP0 not restored
    121 	unlk	a6
    122 	rts
    123 
    124 	xdef	_OPd_
    125 _OPd_:
    126 	link	a6,#-LOCAL_SIZE
    127 	movem.l	d0-d1/a0-a1,USER_DA(a6)
    128 	fmovem.x fp0-fp3,USER_FP0(a6)
    129 	fmove.l	fpsr,USER_FPSR(a6)
    130 	fmove.l	fpcr,USER_FPCR(a6)
    131 	fmove.l	fpcr,d1		; user's rounding mode/precision
    132 	fmove.l	#0,fpcr		; force rounding mode/prec to extended,rn
    133 *
    134 *	copy, convert and tag input argument
    135 *
    136 	fmove.d	8(a6),fp0
    137 	fmove.x	fp0,ETEMP(a6)
    138 	lea	ETEMP(a6),a0
    139 	bsr	tag
    140 	move.b	d0,STAG(a6)
    141 	tst.b	d0
    142 	bne.b	_TMP_7
    143 	bsr	_OPr_		; normalized (regular) number
    144 	bra.b	_TMP_B
    145 _TMP_7:
    146 	cmp.b	#$20,d0		; zero?
    147 	bne.b	_TMP_8
    148 	bsr	_OPz_
    149 	bra.b	_TMP_B
    150 _TMP_8:
    151 	cmp.b	#$40,d0		; infinity?
    152 	bne.b	_TMP_9
    153 	bsr	_OPi_
    154 	bra.b	_TMP_B
    155 _TMP_9:
    156 	cmp.b	#$60,d0		; NaN?
    157 	bne.b	_TMP_A
    158 	bsr	_OPn_
    159 	bra.b	_TMP_B
    160 _TMP_A:
    161 	bsr	_OPm_		; assuming a denorm...
    162 
    163 _TMP_B:
    164 	fmove.l	fpsr,d0		; update status register
    165 	or.b	USER_FPSR+3(a6),d0	;add previously accrued exceptions
    166 	fmove.l	d0,fpsr
    167 *
    168 *	Result is now in FP0
    169 *
    170 	movem.l	USER_DA(a6),d0-d1/a0-a1
    171 	fmovem.x USER_FP1(a6),fp1-fp3	; note: FP0 not restored
    172 	unlk	a6
    173 	rts
    174 
    175 	xdef	_OPx_
    176 _OPx_:
    177 	link	a6,#-LOCAL_SIZE
    178 	movem.l	d0-d1/a0-a1,USER_DA(a6)
    179 	fmovem.x fp0-fp3,USER_FP0(a6)
    180 	fmove.l	fpsr,USER_FPSR(a6)
    181 	fmove.l	fpcr,USER_FPCR(a6)
    182 	fmove.l	fpcr,d1		; user's rounding mode/precision
    183 	fmove.l	#0,fpcr		; force rounding mode/prec to extended,rn
    184 *
    185 *	copy, convert and tag input argument
    186 *
    187 	fmove.x	8(a6),fp0
    188 	fmove.x	fp0,ETEMP(a6)
    189 	lea	ETEMP(a6),a0
    190 	bsr	tag
    191 	move.b	d0,STAG(a6)
    192 	tst.b	d0
    193 	bne.b	_TMP_C
    194 	bsr	_OPr_		; normalized (regular) number
    195 	bra.b	_TMP_G
    196 _TMP_C:
    197 	cmp.b	#$20,d0		; zero?
    198 	bne.b	_TMP_D
    199 	bsr	_OPz_
    200 	bra.b	_TMP_G
    201 _TMP_D:
    202 	cmp.b	#$40,d0		; infinity?
    203 	bne.b	_TMP_E
    204 	bsr	_OPi_
    205 	bra.b	_TMP_G
    206 _TMP_E:
    207 	cmp.b	#$60,d0		; NaN?
    208 	bne.b	_TMP_F
    209 	bsr	_OPn_
    210 	bra.b	_TMP_G
    211 _TMP_F:
    212 	bsr	_OPm_		; assuming a denorm...
    213 
    214 _TMP_G:
    215 	fmove.l	fpsr,d0		; update status register
    216 	or.b	USER_FPSR+3(a6),d0	;add previously accrued exceptions
    217 	fmove.l	d0,fpsr
    218 *
    219 *	Result is now in FP0
    220 *
    221 	movem.l	USER_DA(a6),d0-d1/a0-a1
    222 	fmovem.x USER_FP1(a6),fp1-fp3	; note: FP0 not restored
    223 	unlk	a6
    224 	rts
    225 
    226