OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libcpu/] [m68k/] [m68040/] [fpsp/] [sint.S] - Blame information for rev 173

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.