18c2ecf20Sopenharmony_ci|
28c2ecf20Sopenharmony_ci|	sgetem.sa 3.1 12/10/90
38c2ecf20Sopenharmony_ci|
48c2ecf20Sopenharmony_ci|	The entry point sGETEXP returns the exponent portion
58c2ecf20Sopenharmony_ci|	of the input argument.  The exponent bias is removed
68c2ecf20Sopenharmony_ci|	and the exponent value is returned as an extended
78c2ecf20Sopenharmony_ci|	precision number in fp0.  sGETEXPD handles denormalized
88c2ecf20Sopenharmony_ci|	numbers.
98c2ecf20Sopenharmony_ci|
108c2ecf20Sopenharmony_ci|	The entry point sGETMAN extracts the mantissa of the
118c2ecf20Sopenharmony_ci|	input argument.  The mantissa is converted to an
128c2ecf20Sopenharmony_ci|	extended precision number and returned in fp0.  The
138c2ecf20Sopenharmony_ci|	range of the result is [1.0 - 2.0).
148c2ecf20Sopenharmony_ci|
158c2ecf20Sopenharmony_ci|
168c2ecf20Sopenharmony_ci|	Input:  Double-extended number X in the ETEMP space in
178c2ecf20Sopenharmony_ci|		the floating-point save stack.
188c2ecf20Sopenharmony_ci|
198c2ecf20Sopenharmony_ci|	Output:	The functions return exp(X) or man(X) in fp0.
208c2ecf20Sopenharmony_ci|
218c2ecf20Sopenharmony_ci|	Modified: fp0.
228c2ecf20Sopenharmony_ci|
238c2ecf20Sopenharmony_ci|
248c2ecf20Sopenharmony_ci|		Copyright (C) Motorola, Inc. 1990
258c2ecf20Sopenharmony_ci|			All Rights Reserved
268c2ecf20Sopenharmony_ci|
278c2ecf20Sopenharmony_ci|       For details on the license for this file, please see the
288c2ecf20Sopenharmony_ci|       file, README, in this same directory.
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci|SGETEM	idnt	2,1 | Motorola 040 Floating Point Software Package
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	|section 8
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include "fpsp.h"
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	|xref	nrm_set
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci|
398c2ecf20Sopenharmony_ci| This entry point is used by the unimplemented instruction exception
408c2ecf20Sopenharmony_ci| handler.  It points a0 to the input operand.
418c2ecf20Sopenharmony_ci|
428c2ecf20Sopenharmony_ci|
438c2ecf20Sopenharmony_ci|
448c2ecf20Sopenharmony_ci|	SGETEXP
458c2ecf20Sopenharmony_ci|
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	.global	sgetexp
488c2ecf20Sopenharmony_cisgetexp:
498c2ecf20Sopenharmony_ci	movew	LOCAL_EX(%a0),%d0	|get the exponent
508c2ecf20Sopenharmony_ci	bclrl	#15,%d0		|clear the sign bit
518c2ecf20Sopenharmony_ci	subw	#0x3fff,%d0	|subtract off the bias
528c2ecf20Sopenharmony_ci	fmovew  %d0,%fp0		|move the exp to fp0
538c2ecf20Sopenharmony_ci	rts
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	.global	sgetexpd
568c2ecf20Sopenharmony_cisgetexpd:
578c2ecf20Sopenharmony_ci	bclrb	#sign_bit,LOCAL_EX(%a0)
588c2ecf20Sopenharmony_ci	bsr	nrm_set		|normalize (exp will go negative)
598c2ecf20Sopenharmony_ci	movew	LOCAL_EX(%a0),%d0	|load resulting exponent into d0
608c2ecf20Sopenharmony_ci	subw	#0x3fff,%d0	|subtract off the bias
618c2ecf20Sopenharmony_ci	fmovew	%d0,%fp0		|move the exp to fp0
628c2ecf20Sopenharmony_ci	rts
638c2ecf20Sopenharmony_ci|
648c2ecf20Sopenharmony_ci|
658c2ecf20Sopenharmony_ci| This entry point is used by the unimplemented instruction exception
668c2ecf20Sopenharmony_ci| handler.  It points a0 to the input operand.
678c2ecf20Sopenharmony_ci|
688c2ecf20Sopenharmony_ci|
698c2ecf20Sopenharmony_ci|
708c2ecf20Sopenharmony_ci|	SGETMAN
718c2ecf20Sopenharmony_ci|
728c2ecf20Sopenharmony_ci|
738c2ecf20Sopenharmony_ci| For normalized numbers, leave the mantissa alone, simply load
748c2ecf20Sopenharmony_ci| with an exponent of +/- $3fff.
758c2ecf20Sopenharmony_ci|
768c2ecf20Sopenharmony_ci	.global	sgetman
778c2ecf20Sopenharmony_cisgetman:
788c2ecf20Sopenharmony_ci	movel	USER_FPCR(%a6),%d0
798c2ecf20Sopenharmony_ci	andil	#0xffffff00,%d0	|clear rounding precision and mode
808c2ecf20Sopenharmony_ci	fmovel	%d0,%fpcr		|this fpcr setting is used by the 882
818c2ecf20Sopenharmony_ci	movew	LOCAL_EX(%a0),%d0	|get the exp (really just want sign bit)
828c2ecf20Sopenharmony_ci	orw	#0x7fff,%d0	|clear old exp
838c2ecf20Sopenharmony_ci	bclrl	#14,%d0		|make it the new exp +-3fff
848c2ecf20Sopenharmony_ci	movew	%d0,LOCAL_EX(%a0)	|move the sign & exp back to fsave stack
858c2ecf20Sopenharmony_ci	fmovex	(%a0),%fp0	|put new value back in fp0
868c2ecf20Sopenharmony_ci	rts
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci|
898c2ecf20Sopenharmony_ci| For denormalized numbers, shift the mantissa until the j-bit = 1,
908c2ecf20Sopenharmony_ci| then load the exponent with +/1 $3fff.
918c2ecf20Sopenharmony_ci|
928c2ecf20Sopenharmony_ci	.global	sgetmand
938c2ecf20Sopenharmony_cisgetmand:
948c2ecf20Sopenharmony_ci	movel	LOCAL_HI(%a0),%d0	|load ms mant in d0
958c2ecf20Sopenharmony_ci	movel	LOCAL_LO(%a0),%d1	|load ls mant in d1
968c2ecf20Sopenharmony_ci	bsr	shft		|shift mantissa bits till msbit is set
978c2ecf20Sopenharmony_ci	movel	%d0,LOCAL_HI(%a0)	|put ms mant back on stack
988c2ecf20Sopenharmony_ci	movel	%d1,LOCAL_LO(%a0)	|put ls mant back on stack
998c2ecf20Sopenharmony_ci	bras	sgetman
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci|
1028c2ecf20Sopenharmony_ci|	SHFT
1038c2ecf20Sopenharmony_ci|
1048c2ecf20Sopenharmony_ci|	Shifts the mantissa bits until msbit is set.
1058c2ecf20Sopenharmony_ci|	input:
1068c2ecf20Sopenharmony_ci|		ms mantissa part in d0
1078c2ecf20Sopenharmony_ci|		ls mantissa part in d1
1088c2ecf20Sopenharmony_ci|	output:
1098c2ecf20Sopenharmony_ci|		shifted bits in d0 and d1
1108c2ecf20Sopenharmony_cishft:
1118c2ecf20Sopenharmony_ci	tstl	%d0		|if any bits set in ms mant
1128c2ecf20Sopenharmony_ci	bnes	upper		|then branch
1138c2ecf20Sopenharmony_ci|				;else no bits set in ms mant
1148c2ecf20Sopenharmony_ci	tstl	%d1		|test if any bits set in ls mant
1158c2ecf20Sopenharmony_ci	bnes	cont		|if set then continue
1168c2ecf20Sopenharmony_ci	bras	shft_end	|else return
1178c2ecf20Sopenharmony_cicont:
1188c2ecf20Sopenharmony_ci	movel	%d3,-(%a7)	|save d3
1198c2ecf20Sopenharmony_ci	exg	%d0,%d1		|shift ls mant to ms mant
1208c2ecf20Sopenharmony_ci	bfffo	%d0{#0:#32},%d3	|find first 1 in ls mant to d0
1218c2ecf20Sopenharmony_ci	lsll	%d3,%d0		|shift first 1 to integer bit in ms mant
1228c2ecf20Sopenharmony_ci	movel	(%a7)+,%d3	|restore d3
1238c2ecf20Sopenharmony_ci	bras	shft_end
1248c2ecf20Sopenharmony_ciupper:
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	moveml	%d3/%d5/%d6,-(%a7)	|save registers
1278c2ecf20Sopenharmony_ci	bfffo	%d0{#0:#32},%d3	|find first 1 in ls mant to d0
1288c2ecf20Sopenharmony_ci	lsll	%d3,%d0		|shift ms mant until j-bit is set
1298c2ecf20Sopenharmony_ci	movel	%d1,%d6		|save ls mant in d6
1308c2ecf20Sopenharmony_ci	lsll	%d3,%d1		|shift ls mant by count
1318c2ecf20Sopenharmony_ci	movel	#32,%d5
1328c2ecf20Sopenharmony_ci	subl	%d3,%d5		|sub 32 from shift for ls mant
1338c2ecf20Sopenharmony_ci	lsrl	%d5,%d6		|shift off all bits but those that will
1348c2ecf20Sopenharmony_ci|				;be shifted into ms mant
1358c2ecf20Sopenharmony_ci	orl	%d6,%d0		|shift the ls mant bits into the ms mant
1368c2ecf20Sopenharmony_ci	moveml	(%a7)+,%d3/%d5/%d6	|restore registers
1378c2ecf20Sopenharmony_cishft_end:
1388c2ecf20Sopenharmony_ci	rts
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	|end
141