xref: /OK3568_Linux_fs/kernel/arch/m68k/fpsp040/sgetem.S (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun|
2*4882a593Smuzhiyun|	sgetem.sa 3.1 12/10/90
3*4882a593Smuzhiyun|
4*4882a593Smuzhiyun|	The entry point sGETEXP returns the exponent portion
5*4882a593Smuzhiyun|	of the input argument.  The exponent bias is removed
6*4882a593Smuzhiyun|	and the exponent value is returned as an extended
7*4882a593Smuzhiyun|	precision number in fp0.  sGETEXPD handles denormalized
8*4882a593Smuzhiyun|	numbers.
9*4882a593Smuzhiyun|
10*4882a593Smuzhiyun|	The entry point sGETMAN extracts the mantissa of the
11*4882a593Smuzhiyun|	input argument.  The mantissa is converted to an
12*4882a593Smuzhiyun|	extended precision number and returned in fp0.  The
13*4882a593Smuzhiyun|	range of the result is [1.0 - 2.0).
14*4882a593Smuzhiyun|
15*4882a593Smuzhiyun|
16*4882a593Smuzhiyun|	Input:  Double-extended number X in the ETEMP space in
17*4882a593Smuzhiyun|		the floating-point save stack.
18*4882a593Smuzhiyun|
19*4882a593Smuzhiyun|	Output:	The functions return exp(X) or man(X) in fp0.
20*4882a593Smuzhiyun|
21*4882a593Smuzhiyun|	Modified: fp0.
22*4882a593Smuzhiyun|
23*4882a593Smuzhiyun|
24*4882a593Smuzhiyun|		Copyright (C) Motorola, Inc. 1990
25*4882a593Smuzhiyun|			All Rights Reserved
26*4882a593Smuzhiyun|
27*4882a593Smuzhiyun|       For details on the license for this file, please see the
28*4882a593Smuzhiyun|       file, README, in this same directory.
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun|SGETEM	idnt	2,1 | Motorola 040 Floating Point Software Package
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun	|section 8
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun#include "fpsp.h"
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun	|xref	nrm_set
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun|
39*4882a593Smuzhiyun| This entry point is used by the unimplemented instruction exception
40*4882a593Smuzhiyun| handler.  It points a0 to the input operand.
41*4882a593Smuzhiyun|
42*4882a593Smuzhiyun|
43*4882a593Smuzhiyun|
44*4882a593Smuzhiyun|	SGETEXP
45*4882a593Smuzhiyun|
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun	.global	sgetexp
48*4882a593Smuzhiyunsgetexp:
49*4882a593Smuzhiyun	movew	LOCAL_EX(%a0),%d0	|get the exponent
50*4882a593Smuzhiyun	bclrl	#15,%d0		|clear the sign bit
51*4882a593Smuzhiyun	subw	#0x3fff,%d0	|subtract off the bias
52*4882a593Smuzhiyun	fmovew  %d0,%fp0		|move the exp to fp0
53*4882a593Smuzhiyun	rts
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun	.global	sgetexpd
56*4882a593Smuzhiyunsgetexpd:
57*4882a593Smuzhiyun	bclrb	#sign_bit,LOCAL_EX(%a0)
58*4882a593Smuzhiyun	bsr	nrm_set		|normalize (exp will go negative)
59*4882a593Smuzhiyun	movew	LOCAL_EX(%a0),%d0	|load resulting exponent into d0
60*4882a593Smuzhiyun	subw	#0x3fff,%d0	|subtract off the bias
61*4882a593Smuzhiyun	fmovew	%d0,%fp0		|move the exp to fp0
62*4882a593Smuzhiyun	rts
63*4882a593Smuzhiyun|
64*4882a593Smuzhiyun|
65*4882a593Smuzhiyun| This entry point is used by the unimplemented instruction exception
66*4882a593Smuzhiyun| handler.  It points a0 to the input operand.
67*4882a593Smuzhiyun|
68*4882a593Smuzhiyun|
69*4882a593Smuzhiyun|
70*4882a593Smuzhiyun|	SGETMAN
71*4882a593Smuzhiyun|
72*4882a593Smuzhiyun|
73*4882a593Smuzhiyun| For normalized numbers, leave the mantissa alone, simply load
74*4882a593Smuzhiyun| with an exponent of +/- $3fff.
75*4882a593Smuzhiyun|
76*4882a593Smuzhiyun	.global	sgetman
77*4882a593Smuzhiyunsgetman:
78*4882a593Smuzhiyun	movel	USER_FPCR(%a6),%d0
79*4882a593Smuzhiyun	andil	#0xffffff00,%d0	|clear rounding precision and mode
80*4882a593Smuzhiyun	fmovel	%d0,%fpcr		|this fpcr setting is used by the 882
81*4882a593Smuzhiyun	movew	LOCAL_EX(%a0),%d0	|get the exp (really just want sign bit)
82*4882a593Smuzhiyun	orw	#0x7fff,%d0	|clear old exp
83*4882a593Smuzhiyun	bclrl	#14,%d0		|make it the new exp +-3fff
84*4882a593Smuzhiyun	movew	%d0,LOCAL_EX(%a0)	|move the sign & exp back to fsave stack
85*4882a593Smuzhiyun	fmovex	(%a0),%fp0	|put new value back in fp0
86*4882a593Smuzhiyun	rts
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun|
89*4882a593Smuzhiyun| For denormalized numbers, shift the mantissa until the j-bit = 1,
90*4882a593Smuzhiyun| then load the exponent with +/1 $3fff.
91*4882a593Smuzhiyun|
92*4882a593Smuzhiyun	.global	sgetmand
93*4882a593Smuzhiyunsgetmand:
94*4882a593Smuzhiyun	movel	LOCAL_HI(%a0),%d0	|load ms mant in d0
95*4882a593Smuzhiyun	movel	LOCAL_LO(%a0),%d1	|load ls mant in d1
96*4882a593Smuzhiyun	bsr	shft		|shift mantissa bits till msbit is set
97*4882a593Smuzhiyun	movel	%d0,LOCAL_HI(%a0)	|put ms mant back on stack
98*4882a593Smuzhiyun	movel	%d1,LOCAL_LO(%a0)	|put ls mant back on stack
99*4882a593Smuzhiyun	bras	sgetman
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun|
102*4882a593Smuzhiyun|	SHFT
103*4882a593Smuzhiyun|
104*4882a593Smuzhiyun|	Shifts the mantissa bits until msbit is set.
105*4882a593Smuzhiyun|	input:
106*4882a593Smuzhiyun|		ms mantissa part in d0
107*4882a593Smuzhiyun|		ls mantissa part in d1
108*4882a593Smuzhiyun|	output:
109*4882a593Smuzhiyun|		shifted bits in d0 and d1
110*4882a593Smuzhiyunshft:
111*4882a593Smuzhiyun	tstl	%d0		|if any bits set in ms mant
112*4882a593Smuzhiyun	bnes	upper		|then branch
113*4882a593Smuzhiyun|				;else no bits set in ms mant
114*4882a593Smuzhiyun	tstl	%d1		|test if any bits set in ls mant
115*4882a593Smuzhiyun	bnes	cont		|if set then continue
116*4882a593Smuzhiyun	bras	shft_end	|else return
117*4882a593Smuzhiyuncont:
118*4882a593Smuzhiyun	movel	%d3,-(%a7)	|save d3
119*4882a593Smuzhiyun	exg	%d0,%d1		|shift ls mant to ms mant
120*4882a593Smuzhiyun	bfffo	%d0{#0:#32},%d3	|find first 1 in ls mant to d0
121*4882a593Smuzhiyun	lsll	%d3,%d0		|shift first 1 to integer bit in ms mant
122*4882a593Smuzhiyun	movel	(%a7)+,%d3	|restore d3
123*4882a593Smuzhiyun	bras	shft_end
124*4882a593Smuzhiyunupper:
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun	moveml	%d3/%d5/%d6,-(%a7)	|save registers
127*4882a593Smuzhiyun	bfffo	%d0{#0:#32},%d3	|find first 1 in ls mant to d0
128*4882a593Smuzhiyun	lsll	%d3,%d0		|shift ms mant until j-bit is set
129*4882a593Smuzhiyun	movel	%d1,%d6		|save ls mant in d6
130*4882a593Smuzhiyun	lsll	%d3,%d1		|shift ls mant by count
131*4882a593Smuzhiyun	movel	#32,%d5
132*4882a593Smuzhiyun	subl	%d3,%d5		|sub 32 from shift for ls mant
133*4882a593Smuzhiyun	lsrl	%d5,%d6		|shift off all bits but those that will
134*4882a593Smuzhiyun|				;be shifted into ms mant
135*4882a593Smuzhiyun	orl	%d6,%d0		|shift the ls mant bits into the ms mant
136*4882a593Smuzhiyun	moveml	(%a7)+,%d3/%d5/%d6	|restore registers
137*4882a593Smuzhiyunshft_end:
138*4882a593Smuzhiyun	rts
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun	|end
141