VirtualBox

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

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

Recompiler: Make the recompiler work on FreeBSD (some math functions have a different name)

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