VirtualBox

source: vbox/trunk/src/recompiler_new/fpu/softfloat-native.c@ 18922

Last change on this file since 18922 was 18922, checked in by vboxsync, 16 years ago

Recompiler: Rework 45976 to reduce the chance of breaking Solaris

File size: 8.8 KB
Line 
1/* Native implementation of soft float functions. Only a single status
2 context is supported */
3#include "softfloat.h"
4#include <math.h>
5
6void set_float_rounding_mode(int val STATUS_PARAM)
7{
8 STATUS(float_rounding_mode) = val;
9#if defined(_BSD) && !defined(__APPLE__) || (defined(HOST_SOLARIS) && (HOST_SOLARIS < 10 || HOST_SOLARIS == 11))
10 fpsetround(val);
11#elif defined(__arm__)
12 /* nothing to do */
13#else
14 fesetround(val);
15#endif
16}
17
18#ifdef FLOATX80
19void set_floatx80_rounding_precision(int val STATUS_PARAM)
20{
21 STATUS(floatx80_rounding_precision) = val;
22}
23#endif
24
25#if defined(_BSD) || (defined(HOST_SOLARIS) && HOST_SOLARIS < 10)
26#define lrint(d) ((int32_t)rint(d))
27#define llrint(d) ((int64_t)rint(d))
28#define lrintf(f) ((int32_t)rint(f))
29#define llrintf(f) ((int64_t)rint(f))
30#define sqrtf(f) ((float)sqrt(f))
31#define remainderf(fa, fb) ((float)remainder(fa, fb))
32#define rintf(f) ((float)rint(f))
33/* Some defines which only apply to *BSD */
34# if defined(_BSD)
35# define lrintl(f) ((int32_t)rint(f))
36# define llrintl(f) ((int64_t)rint(f))
37# define rintl(d) ((int32_t)rint(d))
38# define sqrtl(f) (sqrt(f))
39# define remainderl(fa, fb) (remainder(fa, fb))
40# endif
41#endif
42
43#if defined(__powerpc__)
44
45/* correct (but slow) PowerPC rint() (glibc version is incorrect) */
46double qemu_rint(double x)
47{
48 double y = 4503599627370496.0;
49 if (fabs(x) >= y)
50 return x;
51 if (x < 0)
52 y = -y;
53 y = (x + y) - y;
54 if (y == 0.0)
55 y = copysign(y, x);
56 return y;
57}
58
59#define rint qemu_rint
60#endif
61
62/*----------------------------------------------------------------------------
63| Software IEC/IEEE integer-to-floating-point conversion routines.
64*----------------------------------------------------------------------------*/
65float32 int32_to_float32(int v STATUS_PARAM)
66{
67 return (float32)v;
68}
69
70float64 int32_to_float64(int v STATUS_PARAM)
71{
72 return (float64)v;
73}
74
75#ifdef FLOATX80
76floatx80 int32_to_floatx80(int v STATUS_PARAM)
77{
78 return (floatx80)v;
79}
80#endif
81float32 int64_to_float32( int64_t v STATUS_PARAM)
82{
83 return (float32)v;
84}
85float64 int64_to_float64( int64_t v STATUS_PARAM)
86{
87 return (float64)v;
88}
89#ifdef FLOATX80
90floatx80 int64_to_floatx80( int64_t v STATUS_PARAM)
91{
92 return (floatx80)v;
93}
94#endif
95
96/* XXX: this code implements the x86 behaviour, not the IEEE one. */
97#if HOST_LONG_BITS == 32
98#ifndef VBOX
99static inline int long_to_int32(long a)
100#else /* VBOX */
101DECLINLINE(int) long_to_int32(long a)
102#endif /* VBOX */
103{
104 return a;
105}
106#else
107#ifndef VBOX
108static inline int long_to_int32(long a)
109#else /* VBOX */
110DECLINLINE(int) long_to_int32(long a)
111#endif /* VBOX */
112{
113 if (a != (int32_t)a)
114 a = 0x80000000;
115 return a;
116}
117#endif
118
119/*----------------------------------------------------------------------------
120| Software IEC/IEEE single-precision conversion routines.
121*----------------------------------------------------------------------------*/
122int float32_to_int32( float32 a STATUS_PARAM)
123{
124 return long_to_int32(lrintf(a));
125}
126int float32_to_int32_round_to_zero( float32 a STATUS_PARAM)
127{
128 return (int)a;
129}
130int64_t float32_to_int64( float32 a STATUS_PARAM)
131{
132 return llrintf(a);
133}
134
135int64_t float32_to_int64_round_to_zero( float32 a STATUS_PARAM)
136{
137 return (int64_t)a;
138}
139
140float64 float32_to_float64( float32 a STATUS_PARAM)
141{
142 return a;
143}
144#ifdef FLOATX80
145floatx80 float32_to_floatx80( float32 a STATUS_PARAM)
146{
147 return a;
148}
149#endif
150
151/*----------------------------------------------------------------------------
152| Software IEC/IEEE single-precision operations.
153*----------------------------------------------------------------------------*/
154float32 float32_round_to_int( float32 a STATUS_PARAM)
155{
156 return rintf(a);
157}
158
159float32 float32_rem( float32 a, float32 b STATUS_PARAM)
160{
161 return remainderf(a, b);
162}
163
164float32 float32_sqrt( float32 a STATUS_PARAM)
165{
166 return sqrtf(a);
167}
168int float32_compare( float32 a, float32 b STATUS_PARAM )
169{
170 if (a < b) {
171 return -1;
172 } else if (a == b) {
173 return 0;
174 } else if (a > b) {
175 return 1;
176 } else {
177 return 2;
178 }
179}
180int float32_compare_quiet( float32 a, float32 b STATUS_PARAM )
181{
182 if (isless(a, b)) {
183 return -1;
184 } else if (a == b) {
185 return 0;
186 } else if (isgreater(a, b)) {
187 return 1;
188 } else {
189 return 2;
190 }
191}
192int float32_is_signaling_nan( float32 a1)
193{
194 float32u u;
195 uint32_t a;
196 u.f = a1;
197 a = u.i;
198 return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
199}
200
201/*----------------------------------------------------------------------------
202| Software IEC/IEEE double-precision conversion routines.
203*----------------------------------------------------------------------------*/
204int float64_to_int32( float64 a STATUS_PARAM)
205{
206 return long_to_int32(lrint(a));
207}
208int float64_to_int32_round_to_zero( float64 a STATUS_PARAM)
209{
210 return (int)a;
211}
212int64_t float64_to_int64( float64 a STATUS_PARAM)
213{
214 return llrint(a);
215}
216int64_t float64_to_int64_round_to_zero( float64 a STATUS_PARAM)
217{
218 return (int64_t)a;
219}
220float32 float64_to_float32( float64 a STATUS_PARAM)
221{
222 return a;
223}
224#ifdef FLOATX80
225floatx80 float64_to_floatx80( float64 a STATUS_PARAM)
226{
227 return a;
228}
229#endif
230#ifdef FLOAT128
231float128 float64_to_float128( float64 a STATUS_PARAM)
232{
233 return a;
234}
235#endif
236
237/*----------------------------------------------------------------------------
238| Software IEC/IEEE double-precision operations.
239*----------------------------------------------------------------------------*/
240float64 float64_trunc_to_int( float64 a STATUS_PARAM )
241{
242 return trunc(a);
243}
244
245float64 float64_round_to_int( float64 a STATUS_PARAM )
246{
247#if defined(__arm__)
248 switch(STATUS(float_rounding_mode)) {
249 default:
250 case float_round_nearest_even:
251 asm("rndd %0, %1" : "=f" (a) : "f"(a));
252 break;
253 case float_round_down:
254 asm("rnddm %0, %1" : "=f" (a) : "f"(a));
255 break;
256 case float_round_up:
257 asm("rnddp %0, %1" : "=f" (a) : "f"(a));
258 break;
259 case float_round_to_zero:
260 asm("rnddz %0, %1" : "=f" (a) : "f"(a));
261 break;
262 }
263#else
264 return rint(a);
265#endif
266}
267
268float64 float64_rem( float64 a, float64 b STATUS_PARAM)
269{
270 return remainder(a, b);
271}
272
273float64 float64_sqrt( float64 a STATUS_PARAM)
274{
275 return sqrt(a);
276}
277int float64_compare( float64 a, float64 b STATUS_PARAM )
278{
279 if (a < b) {
280 return -1;
281 } else if (a == b) {
282 return 0;
283 } else if (a > b) {
284 return 1;
285 } else {
286 return 2;
287 }
288}
289int float64_compare_quiet( float64 a, float64 b STATUS_PARAM )
290{
291 if (isless(a, b)) {
292 return -1;
293 } else if (a == b) {
294 return 0;
295 } else if (isgreater(a, b)) {
296 return 1;
297 } else {
298 return 2;
299 }
300}
301int float64_is_signaling_nan( float64 a1)
302{
303 float64u u;
304 uint64_t a;
305 u.f = a1;
306 a = u.i;
307 return
308 ( ( ( a>>51 ) & 0xFFF ) == 0xFFE )
309 && ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
310
311}
312
313int float64_is_nan( float64 a1 )
314{
315 float64u u;
316 uint64_t a;
317 u.f = a1;
318 a = u.i;
319
320 return ( LIT64( 0xFFE0000000000000 ) < (bits64) ( a<<1 ) );
321
322}
323
324#ifdef FLOATX80
325
326/*----------------------------------------------------------------------------
327| Software IEC/IEEE extended double-precision conversion routines.
328*----------------------------------------------------------------------------*/
329int floatx80_to_int32( floatx80 a STATUS_PARAM)
330{
331 return long_to_int32(lrintl(a));
332}
333int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM)
334{
335 return (int)a;
336}
337int64_t floatx80_to_int64( floatx80 a STATUS_PARAM)
338{
339 return llrintl(a);
340}
341int64_t floatx80_to_int64_round_to_zero( floatx80 a STATUS_PARAM)
342{
343 return (int64_t)a;
344}
345float32 floatx80_to_float32( floatx80 a STATUS_PARAM)
346{
347 return a;
348}
349float64 floatx80_to_float64( floatx80 a STATUS_PARAM)
350{
351 return a;
352}
353
354/*----------------------------------------------------------------------------
355| Software IEC/IEEE extended double-precision operations.
356*----------------------------------------------------------------------------*/
357floatx80 floatx80_round_to_int( floatx80 a STATUS_PARAM)
358{
359 return rintl(a);
360}
361floatx80 floatx80_rem( floatx80 a, floatx80 b STATUS_PARAM)
362{
363 return remainderl(a, b);
364}
365floatx80 floatx80_sqrt( floatx80 a STATUS_PARAM)
366{
367 return sqrtl(a);
368}
369int floatx80_compare( floatx80 a, floatx80 b STATUS_PARAM )
370{
371 if (a < b) {
372 return -1;
373 } else if (a == b) {
374 return 0;
375 } else if (a > b) {
376 return 1;
377 } else {
378 return 2;
379 }
380}
381int floatx80_compare_quiet( floatx80 a, floatx80 b STATUS_PARAM )
382{
383 if (isless(a, b)) {
384 return -1;
385 } else if (a == b) {
386 return 0;
387 } else if (isgreater(a, b)) {
388 return 1;
389 } else {
390 return 2;
391 }
392}
393int floatx80_is_signaling_nan( floatx80 a1)
394{
395 floatx80u u;
396 u.f = a1;
397 return ( ( u.i.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( u.i.low<<1 );
398}
399
400#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette