18c2ecf20Sopenharmony_ci|
28c2ecf20Sopenharmony_ci|	smovecr.sa 3.1 12/10/90
38c2ecf20Sopenharmony_ci|
48c2ecf20Sopenharmony_ci|	The entry point sMOVECR returns the constant at the
58c2ecf20Sopenharmony_ci|	offset given in the instruction field.
68c2ecf20Sopenharmony_ci|
78c2ecf20Sopenharmony_ci|	Input: An offset in the instruction word.
88c2ecf20Sopenharmony_ci|
98c2ecf20Sopenharmony_ci|	Output:	The constant rounded to the user's rounding
108c2ecf20Sopenharmony_ci|		mode unchecked for overflow.
118c2ecf20Sopenharmony_ci|
128c2ecf20Sopenharmony_ci|	Modified: fp0.
138c2ecf20Sopenharmony_ci|
148c2ecf20Sopenharmony_ci|
158c2ecf20Sopenharmony_ci|		Copyright (C) Motorola, Inc. 1990
168c2ecf20Sopenharmony_ci|			All Rights Reserved
178c2ecf20Sopenharmony_ci|
188c2ecf20Sopenharmony_ci|       For details on the license for this file, please see the
198c2ecf20Sopenharmony_ci|       file, README, in this same directory.
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci|SMOVECR	idnt	2,1 | Motorola 040 Floating Point Software Package
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci	|section 8
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#include "fpsp.h"
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	|xref	nrm_set
288c2ecf20Sopenharmony_ci	|xref	round
298c2ecf20Sopenharmony_ci	|xref	PIRN
308c2ecf20Sopenharmony_ci	|xref	PIRZRM
318c2ecf20Sopenharmony_ci	|xref	PIRP
328c2ecf20Sopenharmony_ci	|xref	SMALRN
338c2ecf20Sopenharmony_ci	|xref	SMALRZRM
348c2ecf20Sopenharmony_ci	|xref	SMALRP
358c2ecf20Sopenharmony_ci	|xref	BIGRN
368c2ecf20Sopenharmony_ci	|xref	BIGRZRM
378c2ecf20Sopenharmony_ci	|xref	BIGRP
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciFZERO:	.long	00000000
408c2ecf20Sopenharmony_ci|
418c2ecf20Sopenharmony_ci|	FMOVECR
428c2ecf20Sopenharmony_ci|
438c2ecf20Sopenharmony_ci	.global	smovcr
448c2ecf20Sopenharmony_cismovcr:
458c2ecf20Sopenharmony_ci	bfextu	CMDREG1B(%a6){#9:#7},%d0 |get offset
468c2ecf20Sopenharmony_ci	bfextu	USER_FPCR(%a6){#26:#2},%d1 |get rmode
478c2ecf20Sopenharmony_ci|
488c2ecf20Sopenharmony_ci| check range of offset
498c2ecf20Sopenharmony_ci|
508c2ecf20Sopenharmony_ci	tstb	%d0		|if zero, offset is to pi
518c2ecf20Sopenharmony_ci	beqs	PI_TBL		|it is pi
528c2ecf20Sopenharmony_ci	cmpib	#0x0a,%d0		|check range $01 - $0a
538c2ecf20Sopenharmony_ci	bles	Z_VAL		|if in this range, return zero
548c2ecf20Sopenharmony_ci	cmpib	#0x0e,%d0		|check range $0b - $0e
558c2ecf20Sopenharmony_ci	bles	SM_TBL		|valid constants in this range
568c2ecf20Sopenharmony_ci	cmpib	#0x2f,%d0		|check range $10 - $2f
578c2ecf20Sopenharmony_ci	bles	Z_VAL		|if in this range, return zero
588c2ecf20Sopenharmony_ci	cmpib	#0x3f,%d0		|check range $30 - $3f
598c2ecf20Sopenharmony_ci	ble	BG_TBL		|valid constants in this range
608c2ecf20Sopenharmony_ciZ_VAL:
618c2ecf20Sopenharmony_ci	fmoves	FZERO,%fp0
628c2ecf20Sopenharmony_ci	rts
638c2ecf20Sopenharmony_ciPI_TBL:
648c2ecf20Sopenharmony_ci	tstb	%d1		|offset is zero, check for rmode
658c2ecf20Sopenharmony_ci	beqs	PI_RN		|if zero, rn mode
668c2ecf20Sopenharmony_ci	cmpib	#0x3,%d1		|check for rp
678c2ecf20Sopenharmony_ci	beqs	PI_RP		|if 3, rp mode
688c2ecf20Sopenharmony_ciPI_RZRM:
698c2ecf20Sopenharmony_ci	leal	PIRZRM,%a0	|rmode is rz or rm, load PIRZRM in a0
708c2ecf20Sopenharmony_ci	bra	set_finx
718c2ecf20Sopenharmony_ciPI_RN:
728c2ecf20Sopenharmony_ci	leal	PIRN,%a0		|rmode is rn, load PIRN in a0
738c2ecf20Sopenharmony_ci	bra	set_finx
748c2ecf20Sopenharmony_ciPI_RP:
758c2ecf20Sopenharmony_ci	leal	PIRP,%a0		|rmode is rp, load PIRP in a0
768c2ecf20Sopenharmony_ci	bra	set_finx
778c2ecf20Sopenharmony_ciSM_TBL:
788c2ecf20Sopenharmony_ci	subil	#0xb,%d0		|make offset in 0 - 4 range
798c2ecf20Sopenharmony_ci	tstb	%d1		|check for rmode
808c2ecf20Sopenharmony_ci	beqs	SM_RN		|if zero, rn mode
818c2ecf20Sopenharmony_ci	cmpib	#0x3,%d1		|check for rp
828c2ecf20Sopenharmony_ci	beqs	SM_RP		|if 3, rp mode
838c2ecf20Sopenharmony_ciSM_RZRM:
848c2ecf20Sopenharmony_ci	leal	SMALRZRM,%a0	|rmode is rz or rm, load SMRZRM in a0
858c2ecf20Sopenharmony_ci	cmpib	#0x2,%d0		|check if result is inex
868c2ecf20Sopenharmony_ci	ble	set_finx	|if 0 - 2, it is inexact
878c2ecf20Sopenharmony_ci	bra	no_finx		|if 3, it is exact
888c2ecf20Sopenharmony_ciSM_RN:
898c2ecf20Sopenharmony_ci	leal	SMALRN,%a0	|rmode is rn, load SMRN in a0
908c2ecf20Sopenharmony_ci	cmpib	#0x2,%d0		|check if result is inex
918c2ecf20Sopenharmony_ci	ble	set_finx	|if 0 - 2, it is inexact
928c2ecf20Sopenharmony_ci	bra	no_finx		|if 3, it is exact
938c2ecf20Sopenharmony_ciSM_RP:
948c2ecf20Sopenharmony_ci	leal	SMALRP,%a0	|rmode is rp, load SMRP in a0
958c2ecf20Sopenharmony_ci	cmpib	#0x2,%d0		|check if result is inex
968c2ecf20Sopenharmony_ci	ble	set_finx	|if 0 - 2, it is inexact
978c2ecf20Sopenharmony_ci	bra	no_finx		|if 3, it is exact
988c2ecf20Sopenharmony_ciBG_TBL:
998c2ecf20Sopenharmony_ci	subil	#0x30,%d0		|make offset in 0 - f range
1008c2ecf20Sopenharmony_ci	tstb	%d1		|check for rmode
1018c2ecf20Sopenharmony_ci	beqs	BG_RN		|if zero, rn mode
1028c2ecf20Sopenharmony_ci	cmpib	#0x3,%d1		|check for rp
1038c2ecf20Sopenharmony_ci	beqs	BG_RP		|if 3, rp mode
1048c2ecf20Sopenharmony_ciBG_RZRM:
1058c2ecf20Sopenharmony_ci	leal	BIGRZRM,%a0	|rmode is rz or rm, load BGRZRM in a0
1068c2ecf20Sopenharmony_ci	cmpib	#0x1,%d0		|check if result is inex
1078c2ecf20Sopenharmony_ci	ble	set_finx	|if 0 - 1, it is inexact
1088c2ecf20Sopenharmony_ci	cmpib	#0x7,%d0		|second check
1098c2ecf20Sopenharmony_ci	ble	no_finx		|if 0 - 7, it is exact
1108c2ecf20Sopenharmony_ci	bra	set_finx	|if 8 - f, it is inexact
1118c2ecf20Sopenharmony_ciBG_RN:
1128c2ecf20Sopenharmony_ci	leal	BIGRN,%a0	|rmode is rn, load BGRN in a0
1138c2ecf20Sopenharmony_ci	cmpib	#0x1,%d0		|check if result is inex
1148c2ecf20Sopenharmony_ci	ble	set_finx	|if 0 - 1, it is inexact
1158c2ecf20Sopenharmony_ci	cmpib	#0x7,%d0		|second check
1168c2ecf20Sopenharmony_ci	ble	no_finx		|if 0 - 7, it is exact
1178c2ecf20Sopenharmony_ci	bra	set_finx	|if 8 - f, it is inexact
1188c2ecf20Sopenharmony_ciBG_RP:
1198c2ecf20Sopenharmony_ci	leal	BIGRP,%a0	|rmode is rp, load SMRP in a0
1208c2ecf20Sopenharmony_ci	cmpib	#0x1,%d0		|check if result is inex
1218c2ecf20Sopenharmony_ci	ble	set_finx	|if 0 - 1, it is inexact
1228c2ecf20Sopenharmony_ci	cmpib	#0x7,%d0		|second check
1238c2ecf20Sopenharmony_ci	ble	no_finx		|if 0 - 7, it is exact
1248c2ecf20Sopenharmony_ci|	bra	set_finx	;if 8 - f, it is inexact
1258c2ecf20Sopenharmony_ciset_finx:
1268c2ecf20Sopenharmony_ci	orl	#inx2a_mask,USER_FPSR(%a6) |set inex2/ainex
1278c2ecf20Sopenharmony_cino_finx:
1288c2ecf20Sopenharmony_ci	mulul	#12,%d0			|use offset to point into tables
1298c2ecf20Sopenharmony_ci	movel	%d1,L_SCR1(%a6)		|load mode for round call
1308c2ecf20Sopenharmony_ci	bfextu	USER_FPCR(%a6){#24:#2},%d1	|get precision
1318c2ecf20Sopenharmony_ci	tstl	%d1			|check if extended precision
1328c2ecf20Sopenharmony_ci|
1338c2ecf20Sopenharmony_ci| Precision is extended
1348c2ecf20Sopenharmony_ci|
1358c2ecf20Sopenharmony_ci	bnes	not_ext			|if extended, do not call round
1368c2ecf20Sopenharmony_ci	fmovemx (%a0,%d0),%fp0-%fp0		|return result in fp0
1378c2ecf20Sopenharmony_ci	rts
1388c2ecf20Sopenharmony_ci|
1398c2ecf20Sopenharmony_ci| Precision is single or double
1408c2ecf20Sopenharmony_ci|
1418c2ecf20Sopenharmony_cinot_ext:
1428c2ecf20Sopenharmony_ci	swap	%d1			|rnd prec in upper word of d1
1438c2ecf20Sopenharmony_ci	addl	L_SCR1(%a6),%d1		|merge rmode in low word of d1
1448c2ecf20Sopenharmony_ci	movel	(%a0,%d0),FP_SCR1(%a6)	|load first word to temp storage
1458c2ecf20Sopenharmony_ci	movel	4(%a0,%d0),FP_SCR1+4(%a6)	|load second word
1468c2ecf20Sopenharmony_ci	movel	8(%a0,%d0),FP_SCR1+8(%a6)	|load third word
1478c2ecf20Sopenharmony_ci	clrl	%d0			|clear g,r,s
1488c2ecf20Sopenharmony_ci	lea	FP_SCR1(%a6),%a0
1498c2ecf20Sopenharmony_ci	btstb	#sign_bit,LOCAL_EX(%a0)
1508c2ecf20Sopenharmony_ci	sne	LOCAL_SGN(%a0)		|convert to internal ext. format
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	bsr	round			|go round the mantissa
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	bfclr	LOCAL_SGN(%a0){#0:#8}	|convert back to IEEE ext format
1558c2ecf20Sopenharmony_ci	beqs	fin_fcr
1568c2ecf20Sopenharmony_ci	bsetb	#sign_bit,LOCAL_EX(%a0)
1578c2ecf20Sopenharmony_cifin_fcr:
1588c2ecf20Sopenharmony_ci	fmovemx (%a0),%fp0-%fp0
1598c2ecf20Sopenharmony_ci	rts
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci	|end
162