Commit 1b2b0af50d4845aa867b2bdbb57dc62149e3ce1a
1 parent
e774a278
64 bit fix
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1842 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
20 additions
and
5 deletions
fpu/softfloat-native.c
@@ -23,8 +23,8 @@ void set_floatx80_rounding_precision(int val STATUS_PARAM) | @@ -23,8 +23,8 @@ void set_floatx80_rounding_precision(int val STATUS_PARAM) | ||
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | #if defined(_BSD) | 25 | #if defined(_BSD) |
26 | -#define lrint(d) ((int32_t)rint(d)) | ||
27 | -#define llrint(d) ((int64_t)rint(d)) | 26 | +#define lrint(d) ((long)rint(d)) |
27 | +#define llrint(d) ((long long)rint(d)) | ||
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #if defined(__powerpc__) | 30 | #if defined(__powerpc__) |
@@ -80,12 +80,27 @@ floatx80 int64_to_floatx80( int64_t v STATUS_PARAM) | @@ -80,12 +80,27 @@ floatx80 int64_to_floatx80( int64_t v STATUS_PARAM) | ||
80 | } | 80 | } |
81 | #endif | 81 | #endif |
82 | 82 | ||
83 | +/* XXX: this code implements the x86 behaviour, not the IEEE one. */ | ||
84 | +#if HOST_LONG_BITS == 32 | ||
85 | +static inline int long_to_int32(long a) | ||
86 | +{ | ||
87 | + return a; | ||
88 | +} | ||
89 | +#else | ||
90 | +static inline int long_to_int32(long a) | ||
91 | +{ | ||
92 | + if (a != (int32_t)a) | ||
93 | + a = 0x80000000; | ||
94 | + return a; | ||
95 | +} | ||
96 | +#endif | ||
97 | + | ||
83 | /*---------------------------------------------------------------------------- | 98 | /*---------------------------------------------------------------------------- |
84 | | Software IEC/IEEE single-precision conversion routines. | 99 | | Software IEC/IEEE single-precision conversion routines. |
85 | *----------------------------------------------------------------------------*/ | 100 | *----------------------------------------------------------------------------*/ |
86 | int float32_to_int32( float32 a STATUS_PARAM) | 101 | int float32_to_int32( float32 a STATUS_PARAM) |
87 | { | 102 | { |
88 | - return lrintf(a); | 103 | + return long_to_int32(lrintf(a)); |
89 | } | 104 | } |
90 | int float32_to_int32_round_to_zero( float32 a STATUS_PARAM) | 105 | int float32_to_int32_round_to_zero( float32 a STATUS_PARAM) |
91 | { | 106 | { |
@@ -167,7 +182,7 @@ char float32_is_signaling_nan( float32 a1) | @@ -167,7 +182,7 @@ char float32_is_signaling_nan( float32 a1) | ||
167 | *----------------------------------------------------------------------------*/ | 182 | *----------------------------------------------------------------------------*/ |
168 | int float64_to_int32( float64 a STATUS_PARAM) | 183 | int float64_to_int32( float64 a STATUS_PARAM) |
169 | { | 184 | { |
170 | - return lrint(a); | 185 | + return long_to_int32(lrint(a)); |
171 | } | 186 | } |
172 | int float64_to_int32_round_to_zero( float64 a STATUS_PARAM) | 187 | int float64_to_int32_round_to_zero( float64 a STATUS_PARAM) |
173 | { | 188 | { |
@@ -276,7 +291,7 @@ char float64_is_signaling_nan( float64 a1) | @@ -276,7 +291,7 @@ char float64_is_signaling_nan( float64 a1) | ||
276 | *----------------------------------------------------------------------------*/ | 291 | *----------------------------------------------------------------------------*/ |
277 | int floatx80_to_int32( floatx80 a STATUS_PARAM) | 292 | int floatx80_to_int32( floatx80 a STATUS_PARAM) |
278 | { | 293 | { |
279 | - return lrintl(a); | 294 | + return long_to_int32(lrintl(a)); |
280 | } | 295 | } |
281 | int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM) | 296 | int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM) |
282 | { | 297 | { |