1 | // |
---|
2 | // |
---|
3 | // sint.sa 3.1 12/10/90 |
---|
4 | // |
---|
5 | // The entry point sINT computes the rounded integer |
---|
6 | // equivalent of the input argument, sINTRZ computes |
---|
7 | // the integer rounded to zero of the input argument. |
---|
8 | // |
---|
9 | // Entry points sint and sintrz are called from do_func |
---|
10 | // to emulate the fint and fintrz unimplemented instructions, |
---|
11 | // respectively. Entry point sintdo is used by bindec. |
---|
12 | // |
---|
13 | // Input: (Entry points sint and sintrz) Double-extended |
---|
14 | // number X in the ETEMP space in the floating-point |
---|
15 | // save stack. |
---|
16 | // (Entry point sintdo) Double-extended number X in |
---|
17 | // location pointed to by the address register a0. |
---|
18 | // (Entry point sintd) Double-extended denormalized |
---|
19 | // number X in the ETEMP space in the floating-point |
---|
20 | // save stack. |
---|
21 | // |
---|
22 | // Output: The function returns int(X) or intrz(X) in fp0. |
---|
23 | // |
---|
24 | // Modifies: fp0. |
---|
25 | // |
---|
26 | // Algorithm: (sint and sintrz) |
---|
27 | // |
---|
28 | // 1. If exp(X) >= 63, return X. |
---|
29 | // If exp(X) < 0, return +/- 0 or +/- 1, according to |
---|
30 | // the rounding mode. |
---|
31 | // |
---|
32 | // 2. (X is in range) set rsc = 63 - exp(X). Unnormalize the |
---|
33 | // result to the exponent $403e. |
---|
34 | // |
---|
35 | // 3. Round the result in the mode given in USER_FPCR. For |
---|
36 | // sintrz, force round-to-zero mode. |
---|
37 | // |
---|
38 | // 4. Normalize the rounded result; store in fp0. |
---|
39 | // |
---|
40 | // For the denormalized cases, force the correct result |
---|
41 | // for the given sign and rounding mode. |
---|
42 | // |
---|
43 | // Sign(X) |
---|
44 | // RMODE + - |
---|
45 | // ----- -------- |
---|
46 | // RN +0 -0 |
---|
47 | // RZ +0 -0 |
---|
48 | // RM +0 -1 |
---|
49 | // RP +1 -0 |
---|
50 | // |
---|
51 | // |
---|
52 | // Copyright (C) Motorola, Inc. 1990 |
---|
53 | // All Rights Reserved |
---|
54 | // |
---|
55 | // THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA |
---|
56 | // The copyright notice above does not evidence any |
---|
57 | // actual or intended publication of such source code. |
---|
58 | |
---|
59 | //SINT idnt 2,1 | Motorola 040 Floating Point Software Package |
---|
60 | |
---|
61 | |section 8 |
---|
62 | |
---|
63 | #include "fpsp.defs" |
---|
64 | |
---|
65 | |xref dnrm_lp |
---|
66 | |xref nrm_set |
---|
67 | |xref round |
---|
68 | |xref t_inx2 |
---|
69 | |xref ld_pone |
---|
70 | |xref ld_mone |
---|
71 | |xref ld_pzero |
---|
72 | |xref ld_mzero |
---|
73 | |xref snzrinx |
---|
74 | |
---|
75 | // |
---|
76 | // FINT |
---|
77 | // |
---|
78 | .global sint |
---|
79 | sint: |
---|
80 | bfextu FPCR_MODE(%a6){#2:#2},%d1 //use user's mode for rounding |
---|
81 | // ;implicitly has extend precision |
---|
82 | // ;in upper word. |
---|
83 | movel %d1,L_SCR1(%a6) //save mode bits |
---|
84 | bras sintexc |
---|
85 | |
---|
86 | // |
---|
87 | // FINT with extended denorm inputs. |
---|
88 | // |
---|
89 | .global sintd |
---|
90 | sintd: |
---|
91 | btstb #5,FPCR_MODE(%a6) |
---|
92 | beq snzrinx //if round nearest or round zero, +/- 0 |
---|
93 | btstb #4,FPCR_MODE(%a6) |
---|
94 | beqs rnd_mns |
---|
95 | rnd_pls: |
---|
96 | btstb #sign_bit,LOCAL_EX(%a0) |
---|
97 | bnes sintmz |
---|
98 | bsr ld_pone //if round plus inf and pos, answer is +1 |
---|
99 | bra t_inx2 |
---|
100 | rnd_mns: |
---|
101 | btstb #sign_bit,LOCAL_EX(%a0) |
---|
102 | beqs sintpz |
---|
103 | bsr ld_mone //if round mns inf and neg, answer is -1 |
---|
104 | bra t_inx2 |
---|
105 | sintpz: |
---|
106 | bsr ld_pzero |
---|
107 | bra t_inx2 |
---|
108 | sintmz: |
---|
109 | bsr ld_mzero |
---|
110 | bra t_inx2 |
---|
111 | |
---|
112 | // |
---|
113 | // FINTRZ |
---|
114 | // |
---|
115 | .global sintrz |
---|
116 | sintrz: |
---|
117 | movel #1,L_SCR1(%a6) //use rz mode for rounding |
---|
118 | // ;implicitly has extend precision |
---|
119 | // ;in upper word. |
---|
120 | bras sintexc |
---|
121 | // |
---|
122 | // SINTDO |
---|
123 | // |
---|
124 | // Input: a0 points to an IEEE extended format operand |
---|
125 | // Output: fp0 has the result |
---|
126 | // |
---|
127 | // Exceptions: |
---|
128 | // |
---|
129 | // If the subroutine results in an inexact operation, the inx2 and |
---|
130 | // ainx bits in the USER_FPSR are set. |
---|
131 | // |
---|
132 | // |
---|
133 | .global sintdo |
---|
134 | sintdo: |
---|
135 | bfextu FPCR_MODE(%a6){#2:#2},%d1 //use user's mode for rounding |
---|
136 | // ;implicitly has ext precision |
---|
137 | // ;in upper word. |
---|
138 | movel %d1,L_SCR1(%a6) //save mode bits |
---|
139 | // |
---|
140 | // Real work of sint is in sintexc |
---|
141 | // |
---|
142 | sintexc: |
---|
143 | bclrb #sign_bit,LOCAL_EX(%a0) //convert to internal extended |
---|
144 | // ;format |
---|
145 | sne LOCAL_SGN(%a0) |
---|
146 | cmpw #0x403e,LOCAL_EX(%a0) //check if (unbiased) exp > 63 |
---|
147 | bgts out_rnge //branch if exp < 63 |
---|
148 | cmpw #0x3ffd,LOCAL_EX(%a0) //check if (unbiased) exp < 0 |
---|
149 | bgt in_rnge //if 63 >= exp > 0, do calc |
---|
150 | // |
---|
151 | // Input is less than zero. Restore sign, and check for directed |
---|
152 | // rounding modes. L_SCR1 contains the rmode in the lower byte. |
---|
153 | // |
---|
154 | un_rnge: |
---|
155 | btstb #1,L_SCR1+3(%a6) //check for rn and rz |
---|
156 | beqs un_rnrz |
---|
157 | tstb LOCAL_SGN(%a0) //check for sign |
---|
158 | bnes un_rmrp_neg |
---|
159 | // |
---|
160 | // Sign is +. If rp, load +1.0, if rm, load +0.0 |
---|
161 | // |
---|
162 | cmpib #3,L_SCR1+3(%a6) //check for rp |
---|
163 | beqs un_ldpone //if rp, load +1.0 |
---|
164 | bsr ld_pzero //if rm, load +0.0 |
---|
165 | bra t_inx2 |
---|
166 | un_ldpone: |
---|
167 | bsr ld_pone |
---|
168 | bra t_inx2 |
---|
169 | // |
---|
170 | // Sign is -. If rm, load -1.0, if rp, load -0.0 |
---|
171 | // |
---|
172 | un_rmrp_neg: |
---|
173 | cmpib #2,L_SCR1+3(%a6) //check for rm |
---|
174 | beqs un_ldmone //if rm, load -1.0 |
---|
175 | bsr ld_mzero //if rp, load -0.0 |
---|
176 | bra t_inx2 |
---|
177 | un_ldmone: |
---|
178 | bsr ld_mone |
---|
179 | bra t_inx2 |
---|
180 | // |
---|
181 | // Rmode is rn or rz; return signed zero |
---|
182 | // |
---|
183 | un_rnrz: |
---|
184 | tstb LOCAL_SGN(%a0) //check for sign |
---|
185 | bnes un_rnrz_neg |
---|
186 | bsr ld_pzero |
---|
187 | bra t_inx2 |
---|
188 | un_rnrz_neg: |
---|
189 | bsr ld_mzero |
---|
190 | bra t_inx2 |
---|
191 | |
---|
192 | // |
---|
193 | // Input is greater than 2^63. All bits are significant. Return |
---|
194 | // the input. |
---|
195 | // |
---|
196 | out_rnge: |
---|
197 | bfclr LOCAL_SGN(%a0){#0:#8} //change back to IEEE ext format |
---|
198 | beqs intps |
---|
199 | bsetb #sign_bit,LOCAL_EX(%a0) |
---|
200 | intps: |
---|
201 | fmovel %fpcr,-(%sp) |
---|
202 | fmovel #0,%fpcr |
---|
203 | fmovex LOCAL_EX(%a0),%fp0 //if exp > 63 |
---|
204 | // ;then return X to the user |
---|
205 | // ;there are no fraction bits |
---|
206 | fmovel (%sp)+,%fpcr |
---|
207 | rts |
---|
208 | |
---|
209 | in_rnge: |
---|
210 | // ;shift off fraction bits |
---|
211 | clrl %d0 //clear d0 - initial g,r,s for |
---|
212 | // ;dnrm_lp |
---|
213 | movel #0x403e,%d1 //set threshold for dnrm_lp |
---|
214 | // ;assumes a0 points to operand |
---|
215 | bsr dnrm_lp |
---|
216 | // ;returns unnormalized number |
---|
217 | // ;pointed by a0 |
---|
218 | // ;output d0 supplies g,r,s |
---|
219 | // ;used by round |
---|
220 | movel L_SCR1(%a6),%d1 //use selected rounding mode |
---|
221 | // |
---|
222 | // |
---|
223 | bsr round //round the unnorm based on users |
---|
224 | // ;input a0 ptr to ext X |
---|
225 | // ; d0 g,r,s bits |
---|
226 | // ; d1 PREC/MODE info |
---|
227 | // ;output a0 ptr to rounded result |
---|
228 | // ;inexact flag set in USER_FPSR |
---|
229 | // ;if initial grs set |
---|
230 | // |
---|
231 | // normalize the rounded result and store value in fp0 |
---|
232 | // |
---|
233 | bsr nrm_set //normalize the unnorm |
---|
234 | // ;Input: a0 points to operand to |
---|
235 | // ;be normalized |
---|
236 | // ;Output: a0 points to normalized |
---|
237 | // ;result |
---|
238 | bfclr LOCAL_SGN(%a0){#0:#8} |
---|
239 | beqs nrmrndp |
---|
240 | bsetb #sign_bit,LOCAL_EX(%a0) //return to IEEE extended format |
---|
241 | nrmrndp: |
---|
242 | fmovel %fpcr,-(%sp) |
---|
243 | fmovel #0,%fpcr |
---|
244 | fmovex LOCAL_EX(%a0),%fp0 //move result to fp0 |
---|
245 | fmovel (%sp)+,%fpcr |
---|
246 | rts |
---|
247 | |
---|
248 | |end |
---|