Home | History | Annotate | Line # | Download | only in fpsp
smovecr.sa revision 1.2
      1  1.2      cgd *	$NetBSD: smovecr.sa,v 1.2 1994/10/26 07:49:57 cgd Exp $
      2  1.2      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 *	smovecr.sa 3.1 12/10/90
     35  1.1  mycroft *
     36  1.1  mycroft *	The entry point sMOVECR returns the constant at the
     37  1.1  mycroft *	offset given in the instruction field.
     38  1.1  mycroft *
     39  1.1  mycroft *	Input: An offset in the instruction word.
     40  1.1  mycroft *
     41  1.1  mycroft *	Output:	The constant rounded to the user's rounding
     42  1.1  mycroft *		mode unchecked for overflow.
     43  1.1  mycroft *
     44  1.1  mycroft *	Modified: fp0.
     45  1.1  mycroft *
     46  1.1  mycroft 
     47  1.1  mycroft SMOVECR	IDNT	2,1 Motorola 040 Floating Point Software Package
     48  1.1  mycroft 
     49  1.1  mycroft 	section 8
     50  1.1  mycroft 
     51  1.1  mycroft 	include fpsp.h
     52  1.1  mycroft 
     53  1.1  mycroft 	xref	nrm_set
     54  1.1  mycroft 	xref	round
     55  1.1  mycroft 	xref	PIRN
     56  1.1  mycroft 	xref	PIRZRM
     57  1.1  mycroft 	xref	PIRP
     58  1.1  mycroft 	xref	SMALRN
     59  1.1  mycroft 	xref	SMALRZRM
     60  1.1  mycroft 	xref	SMALRP
     61  1.1  mycroft 	xref	BIGRN
     62  1.1  mycroft 	xref	BIGRZRM
     63  1.1  mycroft 	xref	BIGRP
     64  1.1  mycroft 
     65  1.1  mycroft FZERO	dc.l	00000000
     66  1.1  mycroft *
     67  1.1  mycroft *	FMOVECR 
     68  1.1  mycroft *
     69  1.1  mycroft 	xdef	smovcr
     70  1.1  mycroft smovcr:
     71  1.1  mycroft 	bfextu	CMDREG1B(a6){9:7},d0 ;get offset
     72  1.1  mycroft 	bfextu	USER_FPCR(a6){26:2},d1 ;get rmode
     73  1.1  mycroft *
     74  1.1  mycroft * check range of offset
     75  1.1  mycroft *
     76  1.1  mycroft 	tst.b	d0		;if zero, offset is to pi
     77  1.1  mycroft 	beq.b	PI_TBL		;it is pi
     78  1.1  mycroft 	cmpi.b	#$0a,d0		;check range $01 - $0a
     79  1.1  mycroft 	ble.b	Z_VAL		;if in this range, return zero
     80  1.1  mycroft 	cmpi.b	#$0e,d0		;check range $0b - $0e
     81  1.1  mycroft 	ble.b	SM_TBL		;valid constants in this range
     82  1.1  mycroft 	cmpi.b	#$2f,d0		;check range $10 - $2f
     83  1.1  mycroft 	ble.b	Z_VAL		;if in this range, return zero 
     84  1.1  mycroft 	cmpi.b	#$3f,d0		;check range $30 - $3f
     85  1.1  mycroft 	ble  	BG_TBL		;valid constants in this range
     86  1.1  mycroft Z_VAL:
     87  1.1  mycroft 	fmove.s	FZERO,fp0
     88  1.1  mycroft 	rts
     89  1.1  mycroft PI_TBL:
     90  1.1  mycroft 	tst.b	d1		;offset is zero, check for rmode
     91  1.1  mycroft 	beq.b	PI_RN		;if zero, rn mode
     92  1.1  mycroft 	cmpi.b	#$3,d1		;check for rp
     93  1.1  mycroft 	beq.b	PI_RP		;if 3, rp mode
     94  1.1  mycroft PI_RZRM:
     95  1.1  mycroft 	lea.l	PIRZRM,a0	;rmode is rz or rm, load PIRZRM in a0
     96  1.1  mycroft 	bra	set_finx
     97  1.1  mycroft PI_RN:
     98  1.1  mycroft 	lea.l	PIRN,a0		;rmode is rn, load PIRN in a0
     99  1.1  mycroft 	bra	set_finx
    100  1.1  mycroft PI_RP:
    101  1.1  mycroft 	lea.l	PIRP,a0		;rmode is rp, load PIRP in a0
    102  1.1  mycroft 	bra	set_finx
    103  1.1  mycroft SM_TBL:
    104  1.1  mycroft 	subi.l	#$b,d0		;make offset in 0 - 4 range
    105  1.1  mycroft 	tst.b	d1		;check for rmode
    106  1.1  mycroft 	beq.b	SM_RN		;if zero, rn mode
    107  1.1  mycroft 	cmpi.b	#$3,d1		;check for rp
    108  1.1  mycroft 	beq.b	SM_RP		;if 3, rp mode
    109  1.1  mycroft SM_RZRM:
    110  1.1  mycroft 	lea.l	SMALRZRM,a0	;rmode is rz or rm, load SMRZRM in a0
    111  1.1  mycroft 	cmpi.b	#$2,d0		;check if result is inex
    112  1.1  mycroft 	ble	set_finx	;if 0 - 2, it is inexact
    113  1.1  mycroft 	bra	no_finx		;if 3, it is exact
    114  1.1  mycroft SM_RN:
    115  1.1  mycroft 	lea.l	SMALRN,a0	;rmode is rn, load SMRN in a0
    116  1.1  mycroft 	cmpi.b	#$2,d0		;check if result is inex
    117  1.1  mycroft 	ble	set_finx	;if 0 - 2, it is inexact
    118  1.1  mycroft 	bra	no_finx		;if 3, it is exact
    119  1.1  mycroft SM_RP:
    120  1.1  mycroft 	lea.l	SMALRP,a0	;rmode is rp, load SMRP in a0
    121  1.1  mycroft 	cmpi.b	#$2,d0		;check if result is inex
    122  1.1  mycroft 	ble	set_finx	;if 0 - 2, it is inexact
    123  1.1  mycroft 	bra	no_finx		;if 3, it is exact
    124  1.1  mycroft BG_TBL:
    125  1.1  mycroft 	subi.l	#$30,d0		;make offset in 0 - f range
    126  1.1  mycroft 	tst.b	d1		;check for rmode
    127  1.1  mycroft 	beq.b	BG_RN		;if zero, rn mode
    128  1.1  mycroft 	cmpi.b	#$3,d1		;check for rp
    129  1.1  mycroft 	beq.b	BG_RP		;if 3, rp mode
    130  1.1  mycroft BG_RZRM:
    131  1.1  mycroft 	lea.l	BIGRZRM,a0	;rmode is rz or rm, load BGRZRM in a0
    132  1.1  mycroft 	cmpi.b	#$1,d0		;check if result is inex
    133  1.1  mycroft 	ble	set_finx	;if 0 - 1, it is inexact
    134  1.1  mycroft 	cmpi.b	#$7,d0		;second check
    135  1.1  mycroft 	ble	no_finx		;if 0 - 7, it is exact
    136  1.1  mycroft 	bra	set_finx	;if 8 - f, it is inexact
    137  1.1  mycroft BG_RN:
    138  1.1  mycroft 	lea.l	BIGRN,a0	;rmode is rn, load BGRN in a0
    139  1.1  mycroft 	cmpi.b	#$1,d0		;check if result is inex
    140  1.1  mycroft 	ble	set_finx	;if 0 - 1, it is inexact
    141  1.1  mycroft 	cmpi.b	#$7,d0		;second check
    142  1.1  mycroft 	ble	no_finx		;if 0 - 7, it is exact
    143  1.1  mycroft 	bra	set_finx	;if 8 - f, it is inexact
    144  1.1  mycroft BG_RP:
    145  1.1  mycroft 	lea.l	BIGRP,a0	;rmode is rp, load SMRP in a0
    146  1.1  mycroft 	cmpi.b	#$1,d0		;check if result is inex
    147  1.1  mycroft 	ble	set_finx	;if 0 - 1, it is inexact
    148  1.1  mycroft 	cmpi.b	#$7,d0		;second check
    149  1.1  mycroft 	ble	no_finx		;if 0 - 7, it is exact
    150  1.1  mycroft *	bra	set_finx	;if 8 - f, it is inexact
    151  1.1  mycroft set_finx:
    152  1.1  mycroft 	or.l	#inx2a_mask,USER_FPSR(a6) ;set inex2/ainex
    153  1.1  mycroft no_finx:
    154  1.1  mycroft 	mulu.l	#12,d0			;use offset to point into tables
    155  1.1  mycroft 	move.l	d1,L_SCR1(a6)		;load mode for round call
    156  1.1  mycroft 	bfextu	USER_FPCR(a6){24:2},d1	;get precision
    157  1.1  mycroft 	tst.l	d1			;check if extended precision
    158  1.1  mycroft *
    159  1.1  mycroft * Precision is extended
    160  1.1  mycroft *
    161  1.1  mycroft 	bne.b	not_ext			;if extended, do not call round
    162  1.1  mycroft 	fmovem.x (a0,d0),fp0		;return result in fp0
    163  1.1  mycroft 	rts
    164  1.1  mycroft *
    165  1.1  mycroft * Precision is single or double
    166  1.1  mycroft *
    167  1.1  mycroft not_ext:
    168  1.1  mycroft 	swap	d1			;rnd prec in upper word of d1
    169  1.1  mycroft 	add.l	L_SCR1(a6),d1		;merge rmode in low word of d1
    170  1.1  mycroft 	move.l	(a0,d0),FP_SCR1(a6)	;load first word to temp storage
    171  1.1  mycroft 	move.l	4(a0,d0),FP_SCR1+4(a6)	;load second word
    172  1.1  mycroft 	move.l	8(a0,d0),FP_SCR1+8(a6)	;load third word
    173  1.1  mycroft 	clr.l	d0			;clear g,r,s
    174  1.1  mycroft 	lea	FP_SCR1(a6),a0
    175  1.1  mycroft 	btst.b	#sign_bit,LOCAL_EX(a0)
    176  1.1  mycroft 	sne	LOCAL_SGN(a0)		;convert to internal ext. format
    177  1.1  mycroft 	
    178  1.1  mycroft 	bsr	round			;go round the mantissa
    179  1.1  mycroft 
    180  1.1  mycroft 	bfclr	LOCAL_SGN(a0){0:8}	;convert back to IEEE ext format
    181  1.1  mycroft 	beq.b	fin_fcr
    182  1.1  mycroft 	bset.b	#sign_bit,LOCAL_EX(a0)
    183  1.1  mycroft fin_fcr:
    184  1.1  mycroft 	fmovem.x (a0),fp0
    185  1.1  mycroft 	rts
    186  1.1  mycroft 
    187  1.1  mycroft 	end
    188