~vcs-imports/qemu/git

« back to all changes in this revision

Viewing changes to fpu/softfloat-native.c

  • Committer: bellard
  • Date: 2007-02-05 20:46:55 UTC
  • Revision ID: git-v1:7b9c30c5eecdbfc08ce18e4d386a5486289f0f78
update


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2394 c046a42c-6fe2-441c-8c8c-71466251a162

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#define sqrtf(f)                ((float)sqrt(f))
31
31
#define remainderf(fa, fb)      ((float)remainder(fa, fb))
32
32
#define rintf(f)                ((float)rint(f))
33
 
#if !defined(__sparc__) && defined(HOST_SOLARIS) && HOST_SOLARIS < 10
34
 
extern long double rintl(long double);
35
 
extern long double scalbnl(long double, int);
36
 
 
37
 
long long
38
 
llrintl(long double x) {
39
 
        return ((long long) rintl(x));
40
 
}
41
 
 
42
 
long
43
 
lrintl(long double x) {
44
 
        return ((long) rintl(x));
45
 
}
46
 
 
47
 
long double
48
 
ldexpl(long double x, int n) {
49
 
        return (scalbnl(x, n));
50
 
}
51
 
#endif
52
33
#endif
53
34
 
54
35
#if defined(__powerpc__)
59
40
    double y = 4503599627370496.0;
60
41
    if (fabs(x) >= y)
61
42
        return x;
62
 
    if (x < 0)
 
43
    if (x < 0) 
63
44
        y = -y;
64
45
    y = (x + y) - y;
65
46
    if (y == 0.0)
78
59
    return (float32)v;
79
60
}
80
61
 
81
 
float32 uint32_to_float32(unsigned int v STATUS_PARAM)
82
 
{
83
 
    return (float32)v;
84
 
}
85
 
 
86
62
float64 int32_to_float64(int v STATUS_PARAM)
87
63
{
88
64
    return (float64)v;
89
65
}
90
66
 
91
 
float64 uint32_to_float64(unsigned int v STATUS_PARAM)
92
 
{
93
 
    return (float64)v;
94
 
}
95
 
 
96
67
#ifdef FLOATX80
97
68
floatx80 int32_to_floatx80(int v STATUS_PARAM)
98
69
{
103
74
{
104
75
    return (float32)v;
105
76
}
106
 
float32 uint64_to_float32( uint64_t v STATUS_PARAM)
107
 
{
108
 
    return (float32)v;
109
 
}
110
77
float64 int64_to_float64( int64_t v STATUS_PARAM)
111
78
{
112
79
    return (float64)v;
113
80
}
114
 
float64 uint64_to_float64( uint64_t v STATUS_PARAM)
115
 
{
116
 
    return (float64)v;
117
 
}
118
81
#ifdef FLOATX80
119
82
floatx80 int64_to_floatx80( int64_t v STATUS_PARAM)
120
83
{
131
94
#else
132
95
static inline int long_to_int32(long a)
133
96
{
134
 
    if (a != (int32_t)a)
 
97
    if (a != (int32_t)a) 
135
98
        a = 0x80000000;
136
99
    return a;
137
100
}
169
132
}
170
133
#endif
171
134
 
172
 
unsigned int float32_to_uint32( float32 a STATUS_PARAM)
173
 
{
174
 
    int64_t v;
175
 
    unsigned int res;
176
 
 
177
 
    v = llrintf(a);
178
 
    if (v < 0) {
179
 
        res = 0;
180
 
    } else if (v > 0xffffffff) {
181
 
        res = 0xffffffff;
182
 
    } else {
183
 
        res = v;
184
 
    }
185
 
    return res;
186
 
}
187
 
unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM)
188
 
{
189
 
    int64_t v;
190
 
    unsigned int res;
191
 
 
192
 
    v = (int64_t)a;
193
 
    if (v < 0) {
194
 
        res = 0;
195
 
    } else if (v > 0xffffffff) {
196
 
        res = 0xffffffff;
197
 
    } else {
198
 
        res = v;
199
 
    }
200
 
    return res;
201
 
}
202
 
 
203
135
/*----------------------------------------------------------------------------
204
136
| Software IEC/IEEE single-precision operations.
205
137
*----------------------------------------------------------------------------*/
286
218
}
287
219
#endif
288
220
 
289
 
unsigned int float64_to_uint32( float64 a STATUS_PARAM)
290
 
{
291
 
    int64_t v;
292
 
    unsigned int res;
293
 
 
294
 
    v = llrint(a);
295
 
    if (v < 0) {
296
 
        res = 0;
297
 
    } else if (v > 0xffffffff) {
298
 
        res = 0xffffffff;
299
 
    } else {
300
 
        res = v;
301
 
    }
302
 
    return res;
303
 
}
304
 
unsigned int float64_to_uint32_round_to_zero( float64 a STATUS_PARAM)
305
 
{
306
 
    int64_t v;
307
 
    unsigned int res;
308
 
 
309
 
    v = (int64_t)a;
310
 
    if (v < 0) {
311
 
        res = 0;
312
 
    } else if (v > 0xffffffff) {
313
 
        res = 0xffffffff;
314
 
    } else {
315
 
        res = v;
316
 
    }
317
 
    return res;
318
 
}
319
 
uint64_t float64_to_uint64 (float64 a STATUS_PARAM)
320
 
{
321
 
    int64_t v;
322
 
 
323
 
    v = llrint(a + (float64)INT64_MIN);
324
 
 
325
 
    return v - INT64_MIN;
326
 
}
327
 
uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM)
328
 
{
329
 
    int64_t v;
330
 
 
331
 
    v = (int64_t)(a + (float64)INT64_MIN);
332
 
 
333
 
    return v - INT64_MIN;
334
 
}
335
 
 
336
221
/*----------------------------------------------------------------------------
337
222
| Software IEC/IEEE double-precision operations.
338
223
*----------------------------------------------------------------------------*/
339
 
#if defined(__sun__) && defined(HOST_SOLARIS) && HOST_SOLARIS < 10
340
 
static inline float64 trunc(float64 x)
341
 
{
342
 
    return x < 0 ? -floor(-x) : floor(x);
343
 
}
344
 
#endif
345
224
float64 float64_trunc_to_int( float64 a STATUS_PARAM )
346
225
{
347
226
    return trunc(a);