4 | The entry point sINT computes the rounded integer
5 | equivalent of the input argument, sINTRZ computes
6 | the integer rounded to zero of the input argument.
8 | Entry points sint and sintrz are called from do_func
9 | to emulate the fint and fintrz unimplemented instructions,
10 | respectively. Entry point sintdo is used by bindec.
12 | Input: (Entry points sint and sintrz) Double-extended
13 | number X in the ETEMP space in the floating-point
15 | (Entry point sintdo) Double-extended number X in
16 | location pointed to by the address register a0.
17 | (Entry point sintd) Double-extended denormalized
18 | number X in the ETEMP space in the floating-point
21 | Output: The function returns int(X) or intrz(X) in fp0.
25 | Algorithm: (sint and sintrz)
27 | 1. If exp(X) >= 63, return X.
28 | If exp(X) < 0, return +/- 0 or +/- 1, according to
31 | 2. (X is in range) set rsc = 63 - exp(X). Unnormalize the
32 | result to the exponent $403e.
34 | 3. Round the result in the mode given in USER_FPCR. For
35 | sintrz, force round-to-zero mode.
37 | 4. Normalize the rounded result; store in fp0.
39 | For the denormalized cases, force the correct result
40 | for the given sign and rounding mode.
51 | Copyright (C) Motorola, Inc. 1990
54 | THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA
55 | The copyright notice above does not evidence any
56 | actual or intended publication of such source code.
58 |SINT idnt 2,1 | Motorola 040 Floating Point Software Package
79 bfextu FPCR_MODE(%a6){#2:#2},%d1 |use user's mode for rounding
80 | ;implicitly has extend precision
82 movel %d1,L_SCR1(%a6) |save mode bits
86 | FINT with extended denorm inputs.
90 btstb #5,FPCR_MODE(%a6)
91 beq snzrinx |if round nearest or round zero, +/- 0
92 btstb #4,FPCR_MODE(%a6)
95 btstb #sign_bit,LOCAL_EX(%a0)
97 bsr ld_pone |if round plus inf and pos, answer is +1
100 btstb #sign_bit,LOCAL_EX(%a0)
102 bsr ld_mone |if round mns inf and neg, answer is -1
116 movel #1,L_SCR1(%a6) |use rz mode for rounding
117 | ;implicitly has extend precision
123 | Input: a0 points to an IEEE extended format operand
124 | Output: fp0 has the result
128 | If the subroutine results in an inexact operation, the inx2 and
129 | ainx bits in the USER_FPSR are set.
134 bfextu FPCR_MODE(%a6){#2:#2},%d1 |use user's mode for rounding
135 | ;implicitly has ext precision
137 movel %d1,L_SCR1(%a6) |save mode bits
139 | Real work of sint is in sintexc
142 bclrb #sign_bit,LOCAL_EX(%a0) |convert to internal extended
145 cmpw #0x403e,LOCAL_EX(%a0) |check if (unbiased) exp > 63
146 bgts out_rnge |branch if exp < 63
147 cmpw #0x3ffd,LOCAL_EX(%a0) |check if (unbiased) exp < 0
148 bgt in_rnge |if 63 >= exp > 0, do calc
150 | Input is less than zero. Restore sign, and check for directed
151 | rounding modes. L_SCR1 contains the rmode in the lower byte.
154 btstb #1,L_SCR1+3(%a6) |check for rn and rz
156 tstb LOCAL_SGN(%a0) |check for sign
159 | Sign is +. If rp, load +1.0, if rm, load +0.0
161 cmpib #3,L_SCR1+3(%a6) |check for rp
162 beqs un_ldpone |if rp, load +1.0
163 bsr ld_pzero |if rm, load +0.0
169 | Sign is -. If rm, load -1.0, if rp, load -0.0
172 cmpib #2,L_SCR1+3(%a6) |check for rm
173 beqs un_ldmone |if rm, load -1.0
174 bsr ld_mzero |if rp, load -0.0
180 | Rmode is rn or rz; return signed zero
183 tstb LOCAL_SGN(%a0) |check for sign
192 | Input is greater than 2^63. All bits are significant. Return
196 bfclr LOCAL_SGN(%a0){#0:#8} |change back to IEEE ext format
198 bsetb #sign_bit,LOCAL_EX(%a0)
202 fmovex LOCAL_EX(%a0),%fp0 |if exp > 63
203 | ;then return X to the user
204 | ;there are no fraction bits
209 | ;shift off fraction bits
210 clrl %d0 |clear d0 - initial g,r,s for
212 movel #0x403e,%d1 |set threshold for dnrm_lp
213 | ;assumes a0 points to operand
215 | ;returns unnormalized number
217 | ;output d0 supplies g,r,s
219 movel L_SCR1(%a6),%d1 |use selected rounding mode
222 bsr round |round the unnorm based on users
223 | ;input a0 ptr to ext X
225 | ; d1 PREC/MODE info
226 | ;output a0 ptr to rounded result
227 | ;inexact flag set in USER_FPSR
228 | ;if initial grs set
230 | normalize the rounded result and store value in fp0
232 bsr nrm_set |normalize the unnorm
233 | ;Input: a0 points to operand to
235 | ;Output: a0 points to normalized
237 bfclr LOCAL_SGN(%a0){#0:#8}
239 bsetb #sign_bit,LOCAL_EX(%a0) |return to IEEE extended format
243 fmovex LOCAL_EX(%a0),%fp0 |move result to fp0