root / fpu / softfloat-native.c @ 298e01b6
History | View | Annotate | Download (10.5 kB)
1 | 158142c2 | bellard | /* Native implementation of soft float functions. Only a single status
|
---|---|---|---|
2 | 158142c2 | bellard | context is supported */
|
3 | 158142c2 | bellard | #include "softfloat.h" |
4 | 158142c2 | bellard | #include <math.h> |
5 | 158142c2 | bellard | |
6 | 158142c2 | bellard | void set_float_rounding_mode(int val STATUS_PARAM) |
7 | 158142c2 | bellard | { |
8 | 158142c2 | bellard | STATUS(float_rounding_mode) = val; |
9 | fdbb4691 | bellard | #if defined(_BSD) && !defined(__APPLE__) || (defined(HOST_SOLARIS) && HOST_SOLARIS < 10) |
10 | 158142c2 | bellard | fpsetround(val); |
11 | 158142c2 | bellard | #elif defined(__arm__)
|
12 | 158142c2 | bellard | /* nothing to do */
|
13 | 158142c2 | bellard | #else
|
14 | 158142c2 | bellard | fesetround(val); |
15 | 158142c2 | bellard | #endif
|
16 | 158142c2 | bellard | } |
17 | 158142c2 | bellard | |
18 | 158142c2 | bellard | #ifdef FLOATX80
|
19 | 158142c2 | bellard | void set_floatx80_rounding_precision(int val STATUS_PARAM) |
20 | 158142c2 | bellard | { |
21 | 158142c2 | bellard | STATUS(floatx80_rounding_precision) = val; |
22 | 158142c2 | bellard | } |
23 | 158142c2 | bellard | #endif
|
24 | 158142c2 | bellard | |
25 | fdbb4691 | bellard | #if defined(_BSD) || (defined(HOST_SOLARIS) && HOST_SOLARIS < 10) |
26 | fdbb4691 | bellard | #define lrint(d) ((int32_t)rint(d))
|
27 | fdbb4691 | bellard | #define llrint(d) ((int64_t)rint(d))
|
28 | fdbb4691 | bellard | #define lrintf(f) ((int32_t)rint(f))
|
29 | fdbb4691 | bellard | #define llrintf(f) ((int64_t)rint(f))
|
30 | fdbb4691 | bellard | #define sqrtf(f) ((float)sqrt(f)) |
31 | fdbb4691 | bellard | #define remainderf(fa, fb) ((float)remainder(fa, fb)) |
32 | fdbb4691 | bellard | #define rintf(f) ((float)rint(f)) |
33 | fc81ba53 | ths | #if !defined(__sparc__) && defined(HOST_SOLARIS) && HOST_SOLARIS < 10 |
34 | 0475a5ca | ths | extern long double rintl(long double); |
35 | 0475a5ca | ths | extern long double scalbnl(long double, int); |
36 | 0475a5ca | ths | |
37 | 0475a5ca | ths | long long |
38 | 0475a5ca | ths | llrintl(long double x) { |
39 | 0475a5ca | ths | return ((long long) rintl(x)); |
40 | 0475a5ca | ths | } |
41 | 0475a5ca | ths | |
42 | 0475a5ca | ths | long
|
43 | 0475a5ca | ths | lrintl(long double x) { |
44 | 0475a5ca | ths | return ((long) rintl(x)); |
45 | 0475a5ca | ths | } |
46 | 0475a5ca | ths | |
47 | 0475a5ca | ths | long double |
48 | 0475a5ca | ths | ldexpl(long double x, int n) { |
49 | 0475a5ca | ths | return (scalbnl(x, n));
|
50 | 0475a5ca | ths | } |
51 | 0475a5ca | ths | #endif
|
52 | 158142c2 | bellard | #endif
|
53 | 158142c2 | bellard | |
54 | 158142c2 | bellard | #if defined(__powerpc__)
|
55 | 158142c2 | bellard | |
56 | 158142c2 | bellard | /* correct (but slow) PowerPC rint() (glibc version is incorrect) */
|
57 | 158142c2 | bellard | double qemu_rint(double x) |
58 | 158142c2 | bellard | { |
59 | 158142c2 | bellard | double y = 4503599627370496.0; |
60 | 158142c2 | bellard | if (fabs(x) >= y)
|
61 | 158142c2 | bellard | return x;
|
62 | 5fafdf24 | ths | if (x < 0) |
63 | 158142c2 | bellard | y = -y; |
64 | 158142c2 | bellard | y = (x + y) - y; |
65 | 158142c2 | bellard | if (y == 0.0) |
66 | 158142c2 | bellard | y = copysign(y, x); |
67 | 158142c2 | bellard | return y;
|
68 | 158142c2 | bellard | } |
69 | 158142c2 | bellard | |
70 | 158142c2 | bellard | #define rint qemu_rint
|
71 | 158142c2 | bellard | #endif
|
72 | 158142c2 | bellard | |
73 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
74 | 158142c2 | bellard | | Software IEC/IEEE integer-to-floating-point conversion routines.
|
75 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
76 | 158142c2 | bellard | float32 int32_to_float32(int v STATUS_PARAM)
|
77 | 158142c2 | bellard | { |
78 | 158142c2 | bellard | return (float32)v;
|
79 | 158142c2 | bellard | } |
80 | 158142c2 | bellard | |
81 | 75d62a58 | j_mayer | float32 uint32_to_float32(unsigned int v STATUS_PARAM) |
82 | 75d62a58 | j_mayer | { |
83 | 75d62a58 | j_mayer | return (float32)v;
|
84 | 75d62a58 | j_mayer | } |
85 | 75d62a58 | j_mayer | |
86 | 158142c2 | bellard | float64 int32_to_float64(int v STATUS_PARAM)
|
87 | 158142c2 | bellard | { |
88 | 158142c2 | bellard | return (float64)v;
|
89 | 158142c2 | bellard | } |
90 | 158142c2 | bellard | |
91 | 75d62a58 | j_mayer | float64 uint32_to_float64(unsigned int v STATUS_PARAM) |
92 | 75d62a58 | j_mayer | { |
93 | 75d62a58 | j_mayer | return (float64)v;
|
94 | 75d62a58 | j_mayer | } |
95 | 75d62a58 | j_mayer | |
96 | 158142c2 | bellard | #ifdef FLOATX80
|
97 | 158142c2 | bellard | floatx80 int32_to_floatx80(int v STATUS_PARAM)
|
98 | 158142c2 | bellard | { |
99 | 158142c2 | bellard | return (floatx80)v;
|
100 | 158142c2 | bellard | } |
101 | 158142c2 | bellard | #endif
|
102 | 158142c2 | bellard | float32 int64_to_float32( int64_t v STATUS_PARAM) |
103 | 158142c2 | bellard | { |
104 | 158142c2 | bellard | return (float32)v;
|
105 | 158142c2 | bellard | } |
106 | 75d62a58 | j_mayer | float32 uint64_to_float32( uint64_t v STATUS_PARAM) |
107 | 75d62a58 | j_mayer | { |
108 | 75d62a58 | j_mayer | return (float32)v;
|
109 | 75d62a58 | j_mayer | } |
110 | 158142c2 | bellard | float64 int64_to_float64( int64_t v STATUS_PARAM) |
111 | 158142c2 | bellard | { |
112 | 158142c2 | bellard | return (float64)v;
|
113 | 158142c2 | bellard | } |
114 | 75d62a58 | j_mayer | float64 uint64_to_float64( uint64_t v STATUS_PARAM) |
115 | 75d62a58 | j_mayer | { |
116 | 75d62a58 | j_mayer | return (float64)v;
|
117 | 75d62a58 | j_mayer | } |
118 | 158142c2 | bellard | #ifdef FLOATX80
|
119 | 158142c2 | bellard | floatx80 int64_to_floatx80( int64_t v STATUS_PARAM) |
120 | 158142c2 | bellard | { |
121 | 158142c2 | bellard | return (floatx80)v;
|
122 | 158142c2 | bellard | } |
123 | 158142c2 | bellard | #endif
|
124 | 158142c2 | bellard | |
125 | 1b2b0af5 | bellard | /* XXX: this code implements the x86 behaviour, not the IEEE one. */
|
126 | 1b2b0af5 | bellard | #if HOST_LONG_BITS == 32 |
127 | 1b2b0af5 | bellard | static inline int long_to_int32(long a) |
128 | 1b2b0af5 | bellard | { |
129 | 1b2b0af5 | bellard | return a;
|
130 | 1b2b0af5 | bellard | } |
131 | 1b2b0af5 | bellard | #else
|
132 | 1b2b0af5 | bellard | static inline int long_to_int32(long a) |
133 | 1b2b0af5 | bellard | { |
134 | 5fafdf24 | ths | if (a != (int32_t)a)
|
135 | 1b2b0af5 | bellard | a = 0x80000000;
|
136 | 1b2b0af5 | bellard | return a;
|
137 | 1b2b0af5 | bellard | } |
138 | 1b2b0af5 | bellard | #endif
|
139 | 1b2b0af5 | bellard | |
140 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
141 | 158142c2 | bellard | | Software IEC/IEEE single-precision conversion routines.
|
142 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
143 | 158142c2 | bellard | int float32_to_int32( float32 a STATUS_PARAM)
|
144 | 158142c2 | bellard | { |
145 | 1b2b0af5 | bellard | return long_to_int32(lrintf(a));
|
146 | 158142c2 | bellard | } |
147 | 158142c2 | bellard | int float32_to_int32_round_to_zero( float32 a STATUS_PARAM)
|
148 | 158142c2 | bellard | { |
149 | 158142c2 | bellard | return (int)a; |
150 | 158142c2 | bellard | } |
151 | 158142c2 | bellard | int64_t float32_to_int64( float32 a STATUS_PARAM) |
152 | 158142c2 | bellard | { |
153 | 158142c2 | bellard | return llrintf(a);
|
154 | 158142c2 | bellard | } |
155 | 158142c2 | bellard | |
156 | 158142c2 | bellard | int64_t float32_to_int64_round_to_zero( float32 a STATUS_PARAM) |
157 | 158142c2 | bellard | { |
158 | 158142c2 | bellard | return (int64_t)a;
|
159 | 158142c2 | bellard | } |
160 | 158142c2 | bellard | |
161 | 158142c2 | bellard | float64 float32_to_float64( float32 a STATUS_PARAM) |
162 | 158142c2 | bellard | { |
163 | 158142c2 | bellard | return a;
|
164 | 158142c2 | bellard | } |
165 | 158142c2 | bellard | #ifdef FLOATX80
|
166 | 158142c2 | bellard | floatx80 float32_to_floatx80( float32 a STATUS_PARAM) |
167 | 158142c2 | bellard | { |
168 | 158142c2 | bellard | return a;
|
169 | 158142c2 | bellard | } |
170 | 158142c2 | bellard | #endif
|
171 | 158142c2 | bellard | |
172 | 75d62a58 | j_mayer | unsigned int float32_to_uint32( float32 a STATUS_PARAM) |
173 | 75d62a58 | j_mayer | { |
174 | 75d62a58 | j_mayer | int64_t v; |
175 | 75d62a58 | j_mayer | unsigned int res; |
176 | 75d62a58 | j_mayer | |
177 | 75d62a58 | j_mayer | v = llrintf(a); |
178 | 75d62a58 | j_mayer | if (v < 0) { |
179 | 75d62a58 | j_mayer | res = 0;
|
180 | 75d62a58 | j_mayer | } else if (v > 0xffffffff) { |
181 | 75d62a58 | j_mayer | res = 0xffffffff;
|
182 | 75d62a58 | j_mayer | } else {
|
183 | 75d62a58 | j_mayer | res = v; |
184 | 75d62a58 | j_mayer | } |
185 | 75d62a58 | j_mayer | return res;
|
186 | 75d62a58 | j_mayer | } |
187 | 75d62a58 | j_mayer | unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM) |
188 | 75d62a58 | j_mayer | { |
189 | 75d62a58 | j_mayer | int64_t v; |
190 | 75d62a58 | j_mayer | unsigned int res; |
191 | 75d62a58 | j_mayer | |
192 | 75d62a58 | j_mayer | v = (int64_t)a; |
193 | 75d62a58 | j_mayer | if (v < 0) { |
194 | 75d62a58 | j_mayer | res = 0;
|
195 | 75d62a58 | j_mayer | } else if (v > 0xffffffff) { |
196 | 75d62a58 | j_mayer | res = 0xffffffff;
|
197 | 75d62a58 | j_mayer | } else {
|
198 | 75d62a58 | j_mayer | res = v; |
199 | 75d62a58 | j_mayer | } |
200 | 75d62a58 | j_mayer | return res;
|
201 | 75d62a58 | j_mayer | } |
202 | 75d62a58 | j_mayer | |
203 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
204 | 158142c2 | bellard | | Software IEC/IEEE single-precision operations.
|
205 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
206 | 158142c2 | bellard | float32 float32_round_to_int( float32 a STATUS_PARAM) |
207 | 158142c2 | bellard | { |
208 | 158142c2 | bellard | return rintf(a);
|
209 | 158142c2 | bellard | } |
210 | 158142c2 | bellard | |
211 | b109f9f8 | bellard | float32 float32_rem( float32 a, float32 b STATUS_PARAM) |
212 | b109f9f8 | bellard | { |
213 | b109f9f8 | bellard | return remainderf(a, b);
|
214 | b109f9f8 | bellard | } |
215 | b109f9f8 | bellard | |
216 | 158142c2 | bellard | float32 float32_sqrt( float32 a STATUS_PARAM) |
217 | 158142c2 | bellard | { |
218 | 158142c2 | bellard | return sqrtf(a);
|
219 | 158142c2 | bellard | } |
220 | 750afe93 | bellard | int float32_compare( float32 a, float32 b STATUS_PARAM )
|
221 | b109f9f8 | bellard | { |
222 | b109f9f8 | bellard | if (a < b) {
|
223 | b109f9f8 | bellard | return -1; |
224 | b109f9f8 | bellard | } else if (a == b) { |
225 | b109f9f8 | bellard | return 0; |
226 | b109f9f8 | bellard | } else if (a > b) { |
227 | b109f9f8 | bellard | return 1; |
228 | b109f9f8 | bellard | } else {
|
229 | b109f9f8 | bellard | return 2; |
230 | b109f9f8 | bellard | } |
231 | b109f9f8 | bellard | } |
232 | 750afe93 | bellard | int float32_compare_quiet( float32 a, float32 b STATUS_PARAM )
|
233 | b109f9f8 | bellard | { |
234 | b109f9f8 | bellard | if (isless(a, b)) {
|
235 | b109f9f8 | bellard | return -1; |
236 | b109f9f8 | bellard | } else if (a == b) { |
237 | b109f9f8 | bellard | return 0; |
238 | b109f9f8 | bellard | } else if (isgreater(a, b)) { |
239 | b109f9f8 | bellard | return 1; |
240 | b109f9f8 | bellard | } else {
|
241 | b109f9f8 | bellard | return 2; |
242 | b109f9f8 | bellard | } |
243 | b109f9f8 | bellard | } |
244 | 750afe93 | bellard | int float32_is_signaling_nan( float32 a1)
|
245 | 158142c2 | bellard | { |
246 | 158142c2 | bellard | float32u u; |
247 | 158142c2 | bellard | uint32_t a; |
248 | 158142c2 | bellard | u.f = a1; |
249 | 158142c2 | bellard | a = u.i; |
250 | 158142c2 | bellard | return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF ); |
251 | 158142c2 | bellard | } |
252 | 158142c2 | bellard | |
253 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
254 | 158142c2 | bellard | | Software IEC/IEEE double-precision conversion routines.
|
255 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
256 | 158142c2 | bellard | int float64_to_int32( float64 a STATUS_PARAM)
|
257 | 158142c2 | bellard | { |
258 | 1b2b0af5 | bellard | return long_to_int32(lrint(a));
|
259 | 158142c2 | bellard | } |
260 | 158142c2 | bellard | int float64_to_int32_round_to_zero( float64 a STATUS_PARAM)
|
261 | 158142c2 | bellard | { |
262 | 158142c2 | bellard | return (int)a; |
263 | 158142c2 | bellard | } |
264 | 158142c2 | bellard | int64_t float64_to_int64( float64 a STATUS_PARAM) |
265 | 158142c2 | bellard | { |
266 | 158142c2 | bellard | return llrint(a);
|
267 | 158142c2 | bellard | } |
268 | 158142c2 | bellard | int64_t float64_to_int64_round_to_zero( float64 a STATUS_PARAM) |
269 | 158142c2 | bellard | { |
270 | 158142c2 | bellard | return (int64_t)a;
|
271 | 158142c2 | bellard | } |
272 | 158142c2 | bellard | float32 float64_to_float32( float64 a STATUS_PARAM) |
273 | 158142c2 | bellard | { |
274 | 158142c2 | bellard | return a;
|
275 | 158142c2 | bellard | } |
276 | 158142c2 | bellard | #ifdef FLOATX80
|
277 | 158142c2 | bellard | floatx80 float64_to_floatx80( float64 a STATUS_PARAM) |
278 | 158142c2 | bellard | { |
279 | 158142c2 | bellard | return a;
|
280 | 158142c2 | bellard | } |
281 | 158142c2 | bellard | #endif
|
282 | 158142c2 | bellard | #ifdef FLOAT128
|
283 | 158142c2 | bellard | float128 float64_to_float128( float64 a STATUS_PARAM) |
284 | 158142c2 | bellard | { |
285 | 158142c2 | bellard | return a;
|
286 | 158142c2 | bellard | } |
287 | 158142c2 | bellard | #endif
|
288 | 158142c2 | bellard | |
289 | 75d62a58 | j_mayer | unsigned int float64_to_uint32( float64 a STATUS_PARAM) |
290 | 75d62a58 | j_mayer | { |
291 | 75d62a58 | j_mayer | int64_t v; |
292 | 75d62a58 | j_mayer | unsigned int res; |
293 | 75d62a58 | j_mayer | |
294 | 75d62a58 | j_mayer | v = llrint(a); |
295 | 75d62a58 | j_mayer | if (v < 0) { |
296 | 75d62a58 | j_mayer | res = 0;
|
297 | 75d62a58 | j_mayer | } else if (v > 0xffffffff) { |
298 | 75d62a58 | j_mayer | res = 0xffffffff;
|
299 | 75d62a58 | j_mayer | } else {
|
300 | 75d62a58 | j_mayer | res = v; |
301 | 75d62a58 | j_mayer | } |
302 | 75d62a58 | j_mayer | return res;
|
303 | 75d62a58 | j_mayer | } |
304 | 75d62a58 | j_mayer | unsigned int float64_to_uint32_round_to_zero( float64 a STATUS_PARAM) |
305 | 75d62a58 | j_mayer | { |
306 | 75d62a58 | j_mayer | int64_t v; |
307 | 75d62a58 | j_mayer | unsigned int res; |
308 | 75d62a58 | j_mayer | |
309 | 75d62a58 | j_mayer | v = (int64_t)a; |
310 | 75d62a58 | j_mayer | if (v < 0) { |
311 | 75d62a58 | j_mayer | res = 0;
|
312 | 75d62a58 | j_mayer | } else if (v > 0xffffffff) { |
313 | 75d62a58 | j_mayer | res = 0xffffffff;
|
314 | 75d62a58 | j_mayer | } else {
|
315 | 75d62a58 | j_mayer | res = v; |
316 | 75d62a58 | j_mayer | } |
317 | 75d62a58 | j_mayer | return res;
|
318 | 75d62a58 | j_mayer | } |
319 | 75d62a58 | j_mayer | uint64_t float64_to_uint64 (float64 a STATUS_PARAM) |
320 | 75d62a58 | j_mayer | { |
321 | 75d62a58 | j_mayer | int64_t v; |
322 | 75d62a58 | j_mayer | |
323 | 75d62a58 | j_mayer | v = llrint(a + (float64)INT64_MIN); |
324 | 75d62a58 | j_mayer | |
325 | 75d62a58 | j_mayer | return v - INT64_MIN;
|
326 | 75d62a58 | j_mayer | } |
327 | 75d62a58 | j_mayer | uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM) |
328 | 75d62a58 | j_mayer | { |
329 | 75d62a58 | j_mayer | int64_t v; |
330 | 75d62a58 | j_mayer | |
331 | 75d62a58 | j_mayer | v = (int64_t)(a + (float64)INT64_MIN); |
332 | 75d62a58 | j_mayer | |
333 | 75d62a58 | j_mayer | return v - INT64_MIN;
|
334 | 75d62a58 | j_mayer | } |
335 | 75d62a58 | j_mayer | |
336 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
337 | 158142c2 | bellard | | Software IEC/IEEE double-precision operations.
|
338 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
339 | fc81ba53 | ths | #if defined(__sun__) && defined(HOST_SOLARIS) && HOST_SOLARIS < 10 |
340 | 63a654bb | ths | static inline float64 trunc(float64 x) |
341 | 63a654bb | ths | { |
342 | 63a654bb | ths | return x < 0 ? -floor(-x) : floor(x); |
343 | 63a654bb | ths | } |
344 | 63a654bb | ths | #endif
|
345 | e6e5906b | pbrook | float64 float64_trunc_to_int( float64 a STATUS_PARAM ) |
346 | e6e5906b | pbrook | { |
347 | e6e5906b | pbrook | return trunc(a);
|
348 | e6e5906b | pbrook | } |
349 | e6e5906b | pbrook | |
350 | 158142c2 | bellard | float64 float64_round_to_int( float64 a STATUS_PARAM ) |
351 | 158142c2 | bellard | { |
352 | 158142c2 | bellard | #if defined(__arm__)
|
353 | 158142c2 | bellard | switch(STATUS(float_rounding_mode)) {
|
354 | 158142c2 | bellard | default:
|
355 | 158142c2 | bellard | case float_round_nearest_even:
|
356 | 158142c2 | bellard | asm("rndd %0, %1" : "=f" (a) : "f"(a)); |
357 | 158142c2 | bellard | break;
|
358 | 158142c2 | bellard | case float_round_down:
|
359 | 158142c2 | bellard | asm("rnddm %0, %1" : "=f" (a) : "f"(a)); |
360 | 158142c2 | bellard | break;
|
361 | 158142c2 | bellard | case float_round_up:
|
362 | 158142c2 | bellard | asm("rnddp %0, %1" : "=f" (a) : "f"(a)); |
363 | 158142c2 | bellard | break;
|
364 | 158142c2 | bellard | case float_round_to_zero:
|
365 | 158142c2 | bellard | asm("rnddz %0, %1" : "=f" (a) : "f"(a)); |
366 | 158142c2 | bellard | break;
|
367 | 158142c2 | bellard | } |
368 | 158142c2 | bellard | #else
|
369 | 158142c2 | bellard | return rint(a);
|
370 | 158142c2 | bellard | #endif
|
371 | 158142c2 | bellard | } |
372 | 158142c2 | bellard | |
373 | b109f9f8 | bellard | float64 float64_rem( float64 a, float64 b STATUS_PARAM) |
374 | b109f9f8 | bellard | { |
375 | b109f9f8 | bellard | return remainder(a, b);
|
376 | b109f9f8 | bellard | } |
377 | b109f9f8 | bellard | |
378 | 158142c2 | bellard | float64 float64_sqrt( float64 a STATUS_PARAM) |
379 | 158142c2 | bellard | { |
380 | 158142c2 | bellard | return sqrt(a);
|
381 | 158142c2 | bellard | } |
382 | 750afe93 | bellard | int float64_compare( float64 a, float64 b STATUS_PARAM )
|
383 | b109f9f8 | bellard | { |
384 | b109f9f8 | bellard | if (a < b) {
|
385 | b109f9f8 | bellard | return -1; |
386 | b109f9f8 | bellard | } else if (a == b) { |
387 | b109f9f8 | bellard | return 0; |
388 | b109f9f8 | bellard | } else if (a > b) { |
389 | b109f9f8 | bellard | return 1; |
390 | b109f9f8 | bellard | } else {
|
391 | b109f9f8 | bellard | return 2; |
392 | b109f9f8 | bellard | } |
393 | b109f9f8 | bellard | } |
394 | 750afe93 | bellard | int float64_compare_quiet( float64 a, float64 b STATUS_PARAM )
|
395 | b109f9f8 | bellard | { |
396 | b109f9f8 | bellard | if (isless(a, b)) {
|
397 | b109f9f8 | bellard | return -1; |
398 | b109f9f8 | bellard | } else if (a == b) { |
399 | b109f9f8 | bellard | return 0; |
400 | b109f9f8 | bellard | } else if (isgreater(a, b)) { |
401 | b109f9f8 | bellard | return 1; |
402 | b109f9f8 | bellard | } else {
|
403 | b109f9f8 | bellard | return 2; |
404 | b109f9f8 | bellard | } |
405 | b109f9f8 | bellard | } |
406 | 750afe93 | bellard | int float64_is_signaling_nan( float64 a1)
|
407 | 158142c2 | bellard | { |
408 | 158142c2 | bellard | float64u u; |
409 | 158142c2 | bellard | uint64_t a; |
410 | 158142c2 | bellard | u.f = a1; |
411 | 158142c2 | bellard | a = u.i; |
412 | 158142c2 | bellard | return
|
413 | 158142c2 | bellard | ( ( ( a>>51 ) & 0xFFF ) == 0xFFE ) |
414 | 158142c2 | bellard | && ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
|
415 | 158142c2 | bellard | |
416 | 158142c2 | bellard | } |
417 | 158142c2 | bellard | |
418 | 750afe93 | bellard | int float64_is_nan( float64 a1 )
|
419 | e6e5906b | pbrook | { |
420 | e6e5906b | pbrook | float64u u; |
421 | e6e5906b | pbrook | uint64_t a; |
422 | e6e5906b | pbrook | u.f = a1; |
423 | e6e5906b | pbrook | a = u.i; |
424 | e6e5906b | pbrook | |
425 | e6e5906b | pbrook | return ( LIT64( 0xFFE0000000000000 ) < (bits64) ( a<<1 ) ); |
426 | e6e5906b | pbrook | |
427 | e6e5906b | pbrook | } |
428 | e6e5906b | pbrook | |
429 | 158142c2 | bellard | #ifdef FLOATX80
|
430 | 158142c2 | bellard | |
431 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
432 | 158142c2 | bellard | | Software IEC/IEEE extended double-precision conversion routines.
|
433 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
434 | 158142c2 | bellard | int floatx80_to_int32( floatx80 a STATUS_PARAM)
|
435 | 158142c2 | bellard | { |
436 | 1b2b0af5 | bellard | return long_to_int32(lrintl(a));
|
437 | 158142c2 | bellard | } |
438 | 158142c2 | bellard | int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM)
|
439 | 158142c2 | bellard | { |
440 | 158142c2 | bellard | return (int)a; |
441 | 158142c2 | bellard | } |
442 | 158142c2 | bellard | int64_t floatx80_to_int64( floatx80 a STATUS_PARAM) |
443 | 158142c2 | bellard | { |
444 | 158142c2 | bellard | return llrintl(a);
|
445 | 158142c2 | bellard | } |
446 | 158142c2 | bellard | int64_t floatx80_to_int64_round_to_zero( floatx80 a STATUS_PARAM) |
447 | 158142c2 | bellard | { |
448 | 158142c2 | bellard | return (int64_t)a;
|
449 | 158142c2 | bellard | } |
450 | 158142c2 | bellard | float32 floatx80_to_float32( floatx80 a STATUS_PARAM) |
451 | 158142c2 | bellard | { |
452 | 158142c2 | bellard | return a;
|
453 | 158142c2 | bellard | } |
454 | 158142c2 | bellard | float64 floatx80_to_float64( floatx80 a STATUS_PARAM) |
455 | 158142c2 | bellard | { |
456 | 158142c2 | bellard | return a;
|
457 | 158142c2 | bellard | } |
458 | 158142c2 | bellard | |
459 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
460 | 158142c2 | bellard | | Software IEC/IEEE extended double-precision operations.
|
461 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
462 | 158142c2 | bellard | floatx80 floatx80_round_to_int( floatx80 a STATUS_PARAM) |
463 | 158142c2 | bellard | { |
464 | 158142c2 | bellard | return rintl(a);
|
465 | 158142c2 | bellard | } |
466 | b109f9f8 | bellard | floatx80 floatx80_rem( floatx80 a, floatx80 b STATUS_PARAM) |
467 | b109f9f8 | bellard | { |
468 | b109f9f8 | bellard | return remainderl(a, b);
|
469 | b109f9f8 | bellard | } |
470 | 158142c2 | bellard | floatx80 floatx80_sqrt( floatx80 a STATUS_PARAM) |
471 | 158142c2 | bellard | { |
472 | 158142c2 | bellard | return sqrtl(a);
|
473 | 158142c2 | bellard | } |
474 | 750afe93 | bellard | int floatx80_compare( floatx80 a, floatx80 b STATUS_PARAM )
|
475 | b109f9f8 | bellard | { |
476 | b109f9f8 | bellard | if (a < b) {
|
477 | b109f9f8 | bellard | return -1; |
478 | b109f9f8 | bellard | } else if (a == b) { |
479 | b109f9f8 | bellard | return 0; |
480 | b109f9f8 | bellard | } else if (a > b) { |
481 | b109f9f8 | bellard | return 1; |
482 | b109f9f8 | bellard | } else {
|
483 | b109f9f8 | bellard | return 2; |
484 | b109f9f8 | bellard | } |
485 | b109f9f8 | bellard | } |
486 | 750afe93 | bellard | int floatx80_compare_quiet( floatx80 a, floatx80 b STATUS_PARAM )
|
487 | b109f9f8 | bellard | { |
488 | b109f9f8 | bellard | if (isless(a, b)) {
|
489 | b109f9f8 | bellard | return -1; |
490 | b109f9f8 | bellard | } else if (a == b) { |
491 | b109f9f8 | bellard | return 0; |
492 | b109f9f8 | bellard | } else if (isgreater(a, b)) { |
493 | b109f9f8 | bellard | return 1; |
494 | b109f9f8 | bellard | } else {
|
495 | b109f9f8 | bellard | return 2; |
496 | b109f9f8 | bellard | } |
497 | b109f9f8 | bellard | } |
498 | 750afe93 | bellard | int floatx80_is_signaling_nan( floatx80 a1)
|
499 | 158142c2 | bellard | { |
500 | 158142c2 | bellard | floatx80u u; |
501 | 158142c2 | bellard | u.f = a1; |
502 | 158142c2 | bellard | return ( ( u.i.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( u.i.low<<1 ); |
503 | 158142c2 | bellard | } |
504 | 158142c2 | bellard | |
505 | 158142c2 | bellard | #endif |