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