sgetem.sa revision 1.1.1.1 1 1.1 mycroft * MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
2 1.1 mycroft * M68000 Hi-Performance Microprocessor Division
3 1.1 mycroft * M68040 Software Package
4 1.1 mycroft *
5 1.1 mycroft * M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
6 1.1 mycroft * All rights reserved.
7 1.1 mycroft *
8 1.1 mycroft * THE SOFTWARE is provided on an "AS IS" basis and without warranty.
9 1.1 mycroft * To the maximum extent permitted by applicable law,
10 1.1 mycroft * MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
11 1.1 mycroft * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
12 1.1 mycroft * PARTICULAR PURPOSE and any warranty against infringement with
13 1.1 mycroft * regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
14 1.1 mycroft * and any accompanying written materials.
15 1.1 mycroft *
16 1.1 mycroft * To the maximum extent permitted by applicable law,
17 1.1 mycroft * IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
18 1.1 mycroft * (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
19 1.1 mycroft * PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
20 1.1 mycroft * OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
21 1.1 mycroft * SOFTWARE. Motorola assumes no responsibility for the maintenance
22 1.1 mycroft * and support of the SOFTWARE.
23 1.1 mycroft *
24 1.1 mycroft * You are hereby granted a copyright license to use, modify, and
25 1.1 mycroft * distribute the SOFTWARE so long as this entire notice is retained
26 1.1 mycroft * without alteration in any modified and/or redistributed versions,
27 1.1 mycroft * and that such modified versions are clearly identified as such.
28 1.1 mycroft * No licenses are granted by implication, estoppel or otherwise
29 1.1 mycroft * under any patents or trademarks of Motorola, Inc.
30 1.1 mycroft
31 1.1 mycroft *
32 1.1 mycroft * sgetem.sa 3.1 12/10/90
33 1.1 mycroft *
34 1.1 mycroft * The entry point sGETEXP returns the exponent portion
35 1.1 mycroft * of the input argument. The exponent bias is removed
36 1.1 mycroft * and the exponent value is returned as an extended
37 1.1 mycroft * precision number in fp0. sGETEXPD handles denormalized
38 1.1 mycroft * numbers.
39 1.1 mycroft *
40 1.1 mycroft * The entry point sGETMAN extracts the mantissa of the
41 1.1 mycroft * input argument. The mantissa is converted to an
42 1.1 mycroft * extended precision number and returned in fp0. The
43 1.1 mycroft * range of the result is [1.0 - 2.0).
44 1.1 mycroft *
45 1.1 mycroft *
46 1.1 mycroft * Input: Double-extended number X in the ETEMP space in
47 1.1 mycroft * the floating-point save stack.
48 1.1 mycroft *
49 1.1 mycroft * Output: The functions return exp(X) or man(X) in fp0.
50 1.1 mycroft *
51 1.1 mycroft * Modified: fp0.
52 1.1 mycroft *
53 1.1 mycroft
54 1.1 mycroft SGETEM IDNT 2,1 Motorola 040 Floating Point Software Package
55 1.1 mycroft
56 1.1 mycroft section 8
57 1.1 mycroft
58 1.1 mycroft include fpsp.h
59 1.1 mycroft
60 1.1 mycroft xref nrm_set
61 1.1 mycroft
62 1.1 mycroft *
63 1.1 mycroft * This entry point is used by the unimplemented instruction exception
64 1.1 mycroft * handler. It points a0 to the input operand.
65 1.1 mycroft *
66 1.1 mycroft *
67 1.1 mycroft *
68 1.1 mycroft * SGETEXP
69 1.1 mycroft *
70 1.1 mycroft
71 1.1 mycroft xdef sgetexp
72 1.1 mycroft sgetexp:
73 1.1 mycroft move.w LOCAL_EX(a0),d0 ;get the exponent
74 1.1 mycroft bclr.l #15,d0 ;clear the sign bit
75 1.1 mycroft sub.w #$3fff,d0 ;subtract off the bias
76 1.1 mycroft fmove.w d0,fp0 ;move the exp to fp0
77 1.1 mycroft rts
78 1.1 mycroft
79 1.1 mycroft xdef sgetexpd
80 1.1 mycroft sgetexpd:
81 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0)
82 1.1 mycroft bsr nrm_set ;normalize (exp will go negative)
83 1.1 mycroft move.w LOCAL_EX(a0),d0 ;load resulting exponent into d0
84 1.1 mycroft sub.w #$3fff,d0 ;subtract off the bias
85 1.1 mycroft fmove.w d0,fp0 ;move the exp to fp0
86 1.1 mycroft rts
87 1.1 mycroft *
88 1.1 mycroft *
89 1.1 mycroft * This entry point is used by the unimplemented instruction exception
90 1.1 mycroft * handler. It points a0 to the input operand.
91 1.1 mycroft *
92 1.1 mycroft *
93 1.1 mycroft *
94 1.1 mycroft * SGETMAN
95 1.1 mycroft *
96 1.1 mycroft *
97 1.1 mycroft * For normalized numbers, leave the mantissa alone, simply load
98 1.1 mycroft * with an exponent of +/- $3fff.
99 1.1 mycroft *
100 1.1 mycroft xdef sgetman
101 1.1 mycroft sgetman:
102 1.1 mycroft move.l USER_FPCR(a6),d0
103 1.1 mycroft andi.l #$ffffff00,d0 ;clear rounding precision and mode
104 1.1 mycroft fmove.l d0,fpcr ;this fpcr setting is used by the 882
105 1.1 mycroft move.w LOCAL_EX(a0),d0 ;get the exp (really just want sign bit)
106 1.1 mycroft or.w #$7fff,d0 ;clear old exp
107 1.1 mycroft bclr.l #14,d0 ;make it the new exp +-3fff
108 1.1 mycroft move.w d0,LOCAL_EX(a0) ;move the sign & exp back to fsave stack
109 1.1 mycroft fmove.x (a0),fp0 ;put new value back in fp0
110 1.1 mycroft rts
111 1.1 mycroft
112 1.1 mycroft *
113 1.1 mycroft * For denormalized numbers, shift the mantissa until the j-bit = 1,
114 1.1 mycroft * then load the exponent with +/1 $3fff.
115 1.1 mycroft *
116 1.1 mycroft xdef sgetmand
117 1.1 mycroft sgetmand:
118 1.1 mycroft move.l LOCAL_HI(a0),d0 ;load ms mant in d0
119 1.1 mycroft move.l LOCAL_LO(a0),d1 ;load ls mant in d1
120 1.1 mycroft bsr shft ;shift mantissa bits till msbit is set
121 1.1 mycroft move.l d0,LOCAL_HI(a0) ;put ms mant back on stack
122 1.1 mycroft move.l d1,LOCAL_LO(a0) ;put ls mant back on stack
123 1.1 mycroft bra.b sgetman
124 1.1 mycroft
125 1.1 mycroft *
126 1.1 mycroft * SHFT
127 1.1 mycroft *
128 1.1 mycroft * Shifts the mantissa bits until msbit is set.
129 1.1 mycroft * input:
130 1.1 mycroft * ms mantissa part in d0
131 1.1 mycroft * ls mantissa part in d1
132 1.1 mycroft * output:
133 1.1 mycroft * shifted bits in d0 and d1
134 1.1 mycroft shft:
135 1.1 mycroft tst.l d0 ;if any bits set in ms mant
136 1.1 mycroft bne.b upper ;then branch
137 1.1 mycroft * ;else no bits set in ms mant
138 1.1 mycroft tst.l d1 ;test if any bits set in ls mant
139 1.1 mycroft bne.b cont ;if set then continue
140 1.1 mycroft bra.b shft_end ;else return
141 1.1 mycroft cont:
142 1.1 mycroft move.l d3,-(a7) ;save d3
143 1.1 mycroft exg d0,d1 ;shift ls mant to ms mant
144 1.1 mycroft bfffo d0{0:32},d3 ;find first 1 in ls mant to d0
145 1.1 mycroft lsl.l d3,d0 ;shift first 1 to integer bit in ms mant
146 1.1 mycroft move.l (a7)+,d3 ;restore d3
147 1.1 mycroft bra.b shft_end
148 1.1 mycroft upper:
149 1.1 mycroft
150 1.1 mycroft movem.l d3/d5/d6,-(a7) ;save registers
151 1.1 mycroft bfffo d0{0:32},d3 ;find first 1 in ls mant to d0
152 1.1 mycroft lsl.l d3,d0 ;shift ms mant until j-bit is set
153 1.1 mycroft move.l d1,d6 ;save ls mant in d6
154 1.1 mycroft lsl.l d3,d1 ;shift ls mant by count
155 1.1 mycroft move.l #32,d5
156 1.1 mycroft sub.l d3,d5 ;sub 32 from shift for ls mant
157 1.1 mycroft lsr.l d5,d6 ;shift off all bits but those that will
158 1.1 mycroft * ;be shifted into ms mant
159 1.1 mycroft or.l d6,d0 ;shift the ls mant bits into the ms mant
160 1.1 mycroft movem.l (a7)+,d3/d5/d6 ;restore registers
161 1.1 mycroft shft_end:
162 1.1 mycroft rts
163 1.1 mycroft
164 1.1 mycroft end
165