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