xref: /openbmc/linux/arch/m68k/fpsp040/sgetem.S (revision e00d82d0)
11da177e4SLinus Torvalds|
21da177e4SLinus Torvalds|	sgetem.sa 3.1 12/10/90
31da177e4SLinus Torvalds|
41da177e4SLinus Torvalds|	The entry point sGETEXP returns the exponent portion
51da177e4SLinus Torvalds|	of the input argument.  The exponent bias is removed
61da177e4SLinus Torvalds|	and the exponent value is returned as an extended
71da177e4SLinus Torvalds|	precision number in fp0.  sGETEXPD handles denormalized
81da177e4SLinus Torvalds|	numbers.
91da177e4SLinus Torvalds|
101da177e4SLinus Torvalds|	The entry point sGETMAN extracts the mantissa of the
111da177e4SLinus Torvalds|	input argument.  The mantissa is converted to an
121da177e4SLinus Torvalds|	extended precision number and returned in fp0.  The
131da177e4SLinus Torvalds|	range of the result is [1.0 - 2.0).
141da177e4SLinus Torvalds|
151da177e4SLinus Torvalds|
161da177e4SLinus Torvalds|	Input:  Double-extended number X in the ETEMP space in
171da177e4SLinus Torvalds|		the floating-point save stack.
181da177e4SLinus Torvalds|
191da177e4SLinus Torvalds|	Output:	The functions return exp(X) or man(X) in fp0.
201da177e4SLinus Torvalds|
211da177e4SLinus Torvalds|	Modified: fp0.
221da177e4SLinus Torvalds|
231da177e4SLinus Torvalds|
241da177e4SLinus Torvalds|		Copyright (C) Motorola, Inc. 1990
251da177e4SLinus Torvalds|			All Rights Reserved
261da177e4SLinus Torvalds|
27e00d82d0SMatt Waddel|       For details on the license for this file, please see the
28e00d82d0SMatt Waddel|       file, README, in this same directory.
291da177e4SLinus Torvalds
301da177e4SLinus Torvalds|SGETEM	idnt	2,1 | Motorola 040 Floating Point Software Package
311da177e4SLinus Torvalds
321da177e4SLinus Torvalds	|section 8
331da177e4SLinus Torvalds
341da177e4SLinus Torvalds#include "fpsp.h"
351da177e4SLinus Torvalds
361da177e4SLinus Torvalds	|xref	nrm_set
371da177e4SLinus Torvalds
381da177e4SLinus Torvalds|
391da177e4SLinus Torvalds| This entry point is used by the unimplemented instruction exception
401da177e4SLinus Torvalds| handler.  It points a0 to the input operand.
411da177e4SLinus Torvalds|
421da177e4SLinus Torvalds|
431da177e4SLinus Torvalds|
441da177e4SLinus Torvalds|	SGETEXP
451da177e4SLinus Torvalds|
461da177e4SLinus Torvalds
471da177e4SLinus Torvalds	.global	sgetexp
481da177e4SLinus Torvaldssgetexp:
491da177e4SLinus Torvalds	movew	LOCAL_EX(%a0),%d0	|get the exponent
501da177e4SLinus Torvalds	bclrl	#15,%d0		|clear the sign bit
511da177e4SLinus Torvalds	subw	#0x3fff,%d0	|subtract off the bias
521da177e4SLinus Torvalds	fmovew  %d0,%fp0		|move the exp to fp0
531da177e4SLinus Torvalds	rts
541da177e4SLinus Torvalds
551da177e4SLinus Torvalds	.global	sgetexpd
561da177e4SLinus Torvaldssgetexpd:
571da177e4SLinus Torvalds	bclrb	#sign_bit,LOCAL_EX(%a0)
581da177e4SLinus Torvalds	bsr	nrm_set		|normalize (exp will go negative)
591da177e4SLinus Torvalds	movew	LOCAL_EX(%a0),%d0	|load resulting exponent into d0
601da177e4SLinus Torvalds	subw	#0x3fff,%d0	|subtract off the bias
611da177e4SLinus Torvalds	fmovew	%d0,%fp0		|move the exp to fp0
621da177e4SLinus Torvalds	rts
631da177e4SLinus Torvalds|
641da177e4SLinus Torvalds|
651da177e4SLinus Torvalds| This entry point is used by the unimplemented instruction exception
661da177e4SLinus Torvalds| handler.  It points a0 to the input operand.
671da177e4SLinus Torvalds|
681da177e4SLinus Torvalds|
691da177e4SLinus Torvalds|
701da177e4SLinus Torvalds|	SGETMAN
711da177e4SLinus Torvalds|
721da177e4SLinus Torvalds|
731da177e4SLinus Torvalds| For normalized numbers, leave the mantissa alone, simply load
741da177e4SLinus Torvalds| with an exponent of +/- $3fff.
751da177e4SLinus Torvalds|
761da177e4SLinus Torvalds	.global	sgetman
771da177e4SLinus Torvaldssgetman:
781da177e4SLinus Torvalds	movel	USER_FPCR(%a6),%d0
791da177e4SLinus Torvalds	andil	#0xffffff00,%d0	|clear rounding precision and mode
801da177e4SLinus Torvalds	fmovel	%d0,%fpcr		|this fpcr setting is used by the 882
811da177e4SLinus Torvalds	movew	LOCAL_EX(%a0),%d0	|get the exp (really just want sign bit)
821da177e4SLinus Torvalds	orw	#0x7fff,%d0	|clear old exp
831da177e4SLinus Torvalds	bclrl	#14,%d0		|make it the new exp +-3fff
841da177e4SLinus Torvalds	movew	%d0,LOCAL_EX(%a0)	|move the sign & exp back to fsave stack
851da177e4SLinus Torvalds	fmovex	(%a0),%fp0	|put new value back in fp0
861da177e4SLinus Torvalds	rts
871da177e4SLinus Torvalds
881da177e4SLinus Torvalds|
891da177e4SLinus Torvalds| For denormalized numbers, shift the mantissa until the j-bit = 1,
901da177e4SLinus Torvalds| then load the exponent with +/1 $3fff.
911da177e4SLinus Torvalds|
921da177e4SLinus Torvalds	.global	sgetmand
931da177e4SLinus Torvaldssgetmand:
941da177e4SLinus Torvalds	movel	LOCAL_HI(%a0),%d0	|load ms mant in d0
951da177e4SLinus Torvalds	movel	LOCAL_LO(%a0),%d1	|load ls mant in d1
961da177e4SLinus Torvalds	bsr	shft		|shift mantissa bits till msbit is set
971da177e4SLinus Torvalds	movel	%d0,LOCAL_HI(%a0)	|put ms mant back on stack
981da177e4SLinus Torvalds	movel	%d1,LOCAL_LO(%a0)	|put ls mant back on stack
991da177e4SLinus Torvalds	bras	sgetman
1001da177e4SLinus Torvalds
1011da177e4SLinus Torvalds|
1021da177e4SLinus Torvalds|	SHFT
1031da177e4SLinus Torvalds|
1041da177e4SLinus Torvalds|	Shifts the mantissa bits until msbit is set.
1051da177e4SLinus Torvalds|	input:
1061da177e4SLinus Torvalds|		ms mantissa part in d0
1071da177e4SLinus Torvalds|		ls mantissa part in d1
1081da177e4SLinus Torvalds|	output:
1091da177e4SLinus Torvalds|		shifted bits in d0 and d1
1101da177e4SLinus Torvaldsshft:
1111da177e4SLinus Torvalds	tstl	%d0		|if any bits set in ms mant
1121da177e4SLinus Torvalds	bnes	upper		|then branch
1131da177e4SLinus Torvalds|				;else no bits set in ms mant
1141da177e4SLinus Torvalds	tstl	%d1		|test if any bits set in ls mant
1151da177e4SLinus Torvalds	bnes	cont		|if set then continue
1161da177e4SLinus Torvalds	bras	shft_end	|else return
1171da177e4SLinus Torvaldscont:
1181da177e4SLinus Torvalds	movel	%d3,-(%a7)	|save d3
1191da177e4SLinus Torvalds	exg	%d0,%d1		|shift ls mant to ms mant
1201da177e4SLinus Torvalds	bfffo	%d0{#0:#32},%d3	|find first 1 in ls mant to d0
1211da177e4SLinus Torvalds	lsll	%d3,%d0		|shift first 1 to integer bit in ms mant
1221da177e4SLinus Torvalds	movel	(%a7)+,%d3	|restore d3
1231da177e4SLinus Torvalds	bras	shft_end
1241da177e4SLinus Torvaldsupper:
1251da177e4SLinus Torvalds
1261da177e4SLinus Torvalds	moveml	%d3/%d5/%d6,-(%a7)	|save registers
1271da177e4SLinus Torvalds	bfffo	%d0{#0:#32},%d3	|find first 1 in ls mant to d0
1281da177e4SLinus Torvalds	lsll	%d3,%d0		|shift ms mant until j-bit is set
1291da177e4SLinus Torvalds	movel	%d1,%d6		|save ls mant in d6
1301da177e4SLinus Torvalds	lsll	%d3,%d1		|shift ls mant by count
1311da177e4SLinus Torvalds	movel	#32,%d5
1321da177e4SLinus Torvalds	subl	%d3,%d5		|sub 32 from shift for ls mant
1331da177e4SLinus Torvalds	lsrl	%d5,%d6		|shift off all bits but those that will
1341da177e4SLinus Torvalds|				;be shifted into ms mant
1351da177e4SLinus Torvalds	orl	%d6,%d0		|shift the ls mant bits into the ms mant
1361da177e4SLinus Torvalds	moveml	(%a7)+,%d3/%d5/%d6	|restore registers
1371da177e4SLinus Torvaldsshft_end:
1381da177e4SLinus Torvalds	rts
1391da177e4SLinus Torvalds
1401da177e4SLinus Torvalds	|end
141