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