Subversion Repositories HelenOS-historic

Rev

Rev 858 | Rev 874 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 858 Rev 865
1
/*
1
/*
2
 * Copyright (C) 2005 Josef Cejka
2
 * Copyright (C) 2005 Josef Cejka
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
#include<softfloat.h>
29
#include<softfloat.h>
30
#include<sftypes.h>
30
#include<sftypes.h>
31
 
31
 
32
#include<add.h>
32
#include<add.h>
33
#include<sub.h>
33
#include<sub.h>
34
#include<mul.h>
34
#include<mul.h>
35
#include<div.h>
35
#include<div.h>
36
 
36
 
37
#include<conversion.h>
37
#include<conversion.h>
38
#include<comparison.h>
38
#include<comparison.h>
39
#include<other.h>
39
#include<other.h>
40
 
40
 
41
#include<arch.h>
41
#include<arch.h>
42
#include<types.h>
42
#include<types.h>
43
#include<functions.h>
43
#include<functions.h>
44
 
44
 
45
/* Arithmetic functions */
45
/* Arithmetic functions */
46
 
46
 
47
float __addsf3(float a, float b)
47
float __addsf3(float a, float b)
48
{
48
{
49
    float32 fa, fb;
49
    float32 fa, fb;
50
    fa.f = a;
50
    fa.f = a;
51
    fb.f = b;
51
    fb.f = b;
52
    if (fa.parts.sign != fb.parts.sign) {
52
    if (fa.parts.sign != fb.parts.sign) {
53
        if (fa.parts.sign) {
53
        if (fa.parts.sign) {
54
            fa.parts.sign = 0;
54
            fa.parts.sign = 0;
55
            return subFloat32(fb, fa).f;
55
            return subFloat32(fb, fa).f;
56
        };
56
        };
57
        fb.parts.sign = 0;
57
        fb.parts.sign = 0;
58
        return subFloat32(fa, fb).f;
58
        return subFloat32(fa, fb).f;
59
    }
59
    }
60
    return addFloat32(fa, fb).f;
60
    return addFloat32(fa, fb).f;
61
}
61
}
62
 
62
 
63
double __adddf3(double a, double b)
63
double __adddf3(double a, double b)
64
{
64
{
65
    float64 da, db;
65
    float64 da, db;
66
    da.d = a;
66
    da.d = a;
67
    db.d = b;
67
    db.d = b;
68
    if (da.parts.sign != db.parts.sign) {
68
    if (da.parts.sign != db.parts.sign) {
69
        if (da.parts.sign) {
69
        if (da.parts.sign) {
70
            da.parts.sign = 0;
70
            da.parts.sign = 0;
71
            return subFloat64(db, da).d;
71
            return subFloat64(db, da).d;
72
        };
72
        };
73
        db.parts.sign = 0;
73
        db.parts.sign = 0;
74
        return subFloat64(da, db).d;
74
        return subFloat64(da, db).d;
75
    }
75
    }
76
    return addFloat64(da, db).d;
76
    return addFloat64(da, db).d;
77
}
77
}
78
 
78
 
79
float __subsf3(float a, float b)
79
float __subsf3(float a, float b)
80
{
80
{
81
    float32 fa, fb;
81
    float32 fa, fb;
82
    fa.f = a;
82
    fa.f = a;
83
    fb.f = b;
83
    fb.f = b;
84
    if (fa.parts.sign != fb.parts.sign) {
84
    if (fa.parts.sign != fb.parts.sign) {
85
        fb.parts.sign = !fb.parts.sign;
85
        fb.parts.sign = !fb.parts.sign;
86
        return addFloat32(fa, fb).f;
86
        return addFloat32(fa, fb).f;
87
    }
87
    }
88
    return subFloat32(fa, fb).f;
88
    return subFloat32(fa, fb).f;
89
}
89
}
90
 
90
 
91
double __subdf3(double a, double b)
91
double __subdf3(double a, double b)
92
{
92
{
93
    float64 da, db;
93
    float64 da, db;
94
    da.d = a;
94
    da.d = a;
95
    db.d = b;
95
    db.d = b;
96
    if (da.parts.sign != db.parts.sign) {
96
    if (da.parts.sign != db.parts.sign) {
97
        db.parts.sign = !db.parts.sign;
97
        db.parts.sign = !db.parts.sign;
98
        return addFloat64(da, db).d;
98
        return addFloat64(da, db).d;
99
    }
99
    }
100
    return subFloat64(da, db).d;
100
    return subFloat64(da, db).d;
101
}
101
}
102
 
102
 
103
float __mulsf3(float a, float b)
103
float __mulsf3(float a, float b)
104
{
104
{
105
    float32 fa, fb;
105
    float32 fa, fb;
106
    fa.f = a;
106
    fa.f = a;
107
    fb.f = b;
107
    fb.f = b;
108
    return  mulFloat32(fa, fb).f;
108
    return  mulFloat32(fa, fb).f;
109
}
109
}
110
 
110
 
111
double __muldf3(double a, double b)
111
double __muldf3(double a, double b)
112
{
112
{
113
    float64 da, db;
113
    float64 da, db;
114
    da.d = a;
114
    da.d = a;
115
    db.d = b;
115
    db.d = b;
116
    return  mulFloat64(da, db).d;
116
    return  mulFloat64(da, db).d;
117
}
117
}
118
 
118
 
119
float __divsf3(float a, float b)
119
float __divsf3(float a, float b)
120
{
120
{
121
    float32 fa, fb;
121
    float32 fa, fb;
122
    fa.f = a;
122
    fa.f = a;
123
    fb.f = b;
123
    fb.f = b;
124
    return  divFloat32(fa, fb).f;
124
    return  divFloat32(fa, fb).f;
125
}
125
}
126
 
126
 
127
double __divdf3(double a, double b)
127
double __divdf3(double a, double b)
128
{
128
{
129
    float64 da, db;
129
    float64 da, db;
130
    da.d = a;
130
    da.d = a;
131
    db.d = b;
131
    db.d = b;
132
    return  divFloat64(da, db).d;
132
    return  divFloat64(da, db).d;
133
}
133
}
134
 
134
 
135
float __negsf2(float a)
135
float __negsf2(float a)
136
{
136
{
137
    float32 fa;
137
    float32 fa;
138
    fa.f = a;
138
    fa.f = a;
139
    fa.parts.sign = !fa.parts.sign;
139
    fa.parts.sign = !fa.parts.sign;
140
    return fa.f;
140
    return fa.f;
141
}
141
}
142
 
142
 
143
double __negdf2(double a)
143
double __negdf2(double a)
144
{
144
{
145
    float64 fa;
145
    float64 fa;
146
    fa.d = a;
146
    fa.d = a;
147
    fa.parts.sign = !fa.parts.sign;
147
    fa.parts.sign = !fa.parts.sign;
148
    return fa.d;
148
    return fa.d;
149
}
149
}
150
 
150
 
151
/* Conversion functions */
151
/* Conversion functions */
152
 
152
 
153
double __extendsfdf2(float a)
153
double __extendsfdf2(float a)
154
{
154
{
155
    float32 fa;
155
    float32 fa;
156
    fa.f = a;
156
    fa.f = a;
157
    return convertFloat32ToFloat64(fa).d;
157
    return convertFloat32ToFloat64(fa).d;
158
}
158
}
159
 
159
 
160
float __truncdfsf2(double a)
160
float __truncdfsf2(double a)
161
{
161
{
162
    float64 da;
162
    float64 da;
163
    da.d = a;
163
    da.d = a;
164
    return convertFloat64ToFloat32(da).f;
164
    return convertFloat64ToFloat32(da).f;
165
}
165
}
166
 
166
 
167
int __fixsfsi(float a)
167
int __fixsfsi(float a)
168
{
168
{
169
    float32 fa;
169
    float32 fa;
170
    fa.f = a;
170
    fa.f = a;
171
   
171
   
172
    return float32_to_int(fa);
172
    return float32_to_int(fa);
173
}
173
}
174
int __fixdfsi(double a)
174
int __fixdfsi(double a)
175
{
175
{
-
 
176
    float64 da;
-
 
177
    da.d = a;
-
 
178
   
-
 
179
    return float64_to_int(da);
176
}
180
}
177
 
181
 
178
long __fixsfdi(float a)
182
long __fixsfdi(float a)
179
{
183
{
180
    float32 fa;
184
    float32 fa;
181
    fa.f = a;
185
    fa.f = a;
182
   
186
   
183
    return float32_to_long(fa);
187
    return float32_to_long(fa);
184
}
188
}
185
long __fixdfdi(double a)
189
long __fixdfdi(double a)
186
{
190
{
-
 
191
    float64 da;
-
 
192
    da.d = a;
-
 
193
   
-
 
194
    return float64_to_long(da);
187
}
195
}
188
 
196
 
189
long long __fixsfti(float a)
197
long long __fixsfti(float a)
190
{
198
{
-
 
199
    float32 fa;
-
 
200
    fa.f = a;
-
 
201
   
-
 
202
    return float32_to_longlong(fa);
191
}
203
}
192
long long __fixdfti(double a)
204
long long __fixdfti(double a)
193
{
205
{
-
 
206
    float64 da;
-
 
207
    da.d = a;
-
 
208
   
-
 
209
    return float64_to_longlong(da);
194
}
210
}
195
 
211
 
196
unsigned int __fixunssfsi(float a)
212
unsigned int __fixunssfsi(float a)
197
{
213
{
198
    float32 fa;
214
    float32 fa;
199
    fa.f = a;
215
    fa.f = a;
200
   
216
   
201
    return float32_to_uint(fa);
217
    return float32_to_uint(fa);
202
}
218
}
203
unsigned int __fixunsdfsi(double a)
219
unsigned int __fixunsdfsi(double a)
204
{
220
{
-
 
221
    float64 da;
-
 
222
    da.d = a;
-
 
223
   
-
 
224
    return float64_to_uint(da);
205
}
225
}
206
 
226
 
207
unsigned long __fixunssfdi(float a)
227
unsigned long __fixunssfdi(float a)
208
{
228
{
209
    float32 fa;
229
    float32 fa;
210
    fa.f = a;
230
    fa.f = a;
211
   
231
   
212
    return float32_to_ulong(fa);
232
    return float32_to_ulong(fa);
213
}
233
}
214
unsigned long __fixunsdfdi(double a)
234
unsigned long __fixunsdfdi(double a)
215
{
235
{
-
 
236
    float64 da;
-
 
237
    da.d = a;
-
 
238
   
-
 
239
    return float64_to_ulong(da);
216
}
240
}
217
 
241
 
218
unsigned long long __fixunssfti(float a)
242
unsigned long long __fixunssfti(float a)
219
{
243
{
-
 
244
    float32 fa;
-
 
245
    fa.f = a;
-
 
246
   
-
 
247
    return float32_to_ulonglong(fa);
220
}
248
}
221
unsigned long long __fixunsdfti(double a)
249
unsigned long long __fixunsdfti(double a)
222
{
250
{
-
 
251
    float64 da;
-
 
252
    da.d = a;
-
 
253
   
-
 
254
    return float64_to_ulonglong(da);
223
}
255
}
224
 
256
 
225
float __floatsisf(int i)
257
float __floatsisf(int i)
226
{
258
{
227
}
259
}
228
double __floatsidf(int i)
260
double __floatsidf(int i)
229
{
261
{
230
}
262
}
231
 
263
 
232
float __floatdisf(long i)
264
float __floatdisf(long i)
233
{
265
{
234
}
266
}
235
double __floatdidf(long i)
267
double __floatdidf(long i)
236
{
268
{
237
}
269
}
238
 
270
 
239
float __floattisf(long long i)
271
float __floattisf(long long i)
240
{
272
{
241
}
273
}
242
double __floattidf(long long i)
274
double __floattidf(long long i)
243
{
275
{
244
}
276
}
245
 
277
 
246
float __floatunsisf(unsigned int i)
278
float __floatunsisf(unsigned int i)
247
{
279
{
248
}
280
}
249
double __floatunsidf(unsigned int i)
281
double __floatunsidf(unsigned int i)
250
{
282
{
251
}
283
}
252
 
284
 
253
float __floatundisf(unsigned long i)
285
float __floatundisf(unsigned long i)
254
{
286
{
255
}
287
}
256
double __floatundidf(unsigned long i)
288
double __floatundidf(unsigned long i)
257
{
289
{
258
}
290
}
259
 
291
 
260
float __floatuntisf(unsigned long long i)
292
float __floatuntisf(unsigned long long i)
261
{
293
{
262
}
294
}
263
double __floatuntidf(unsigned long long i)
295
double __floatuntidf(unsigned long long i)
264
{
296
{
265
}
297
}
266
 
298
 
267
/* Comparison functions */
299
/* Comparison functions */
268
/* Comparison functions */
300
/* Comparison functions */
269
 
301
 
270
/* a<b .. -1
302
/* a<b .. -1
271
 * a=b ..  0
303
 * a=b ..  0
272
 * a>b ..  1
304
 * a>b ..  1
273
 * */
305
 * */
274
 
306
 
275
int __cmpsf2(float a, float b)
307
int __cmpsf2(float a, float b)
276
{
308
{
277
    float32 fa, fb;
309
    float32 fa, fb;
278
    fa.f = a;
310
    fa.f = a;
279
    fb.f = b;
311
    fb.f = b;
280
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
312
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
281
        return 1; /* no special constant for unordered - maybe signaled? */
313
        return 1; /* no special constant for unordered - maybe signaled? */
282
    };
314
    };
283
 
315
 
284
   
316
   
285
    if (isFloat32eq(fa, fb)) {
317
    if (isFloat32eq(fa, fb)) {
286
        return 0;
318
        return 0;
287
    };
319
    };
288
   
320
   
289
    if (isFloat32lt(fa, fb)) {
321
    if (isFloat32lt(fa, fb)) {
290
        return -1;
322
        return -1;
291
        };
323
        };
292
    return 1;
324
    return 1;
293
}
325
}
294
 
326
 
295
int __unordsf2(float a, float b)
327
int __unordsf2(float a, float b)
296
{
328
{
297
    float32 fa, fb;
329
    float32 fa, fb;
298
    fa.f = a;
330
    fa.f = a;
299
    fb.f = b;
331
    fb.f = b;
300
    return ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) );
332
    return ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) );
301
}
333
}
302
 
334
 
303
/**
335
/**
304
 * @return zero, if neither argument is a NaN and are equal
336
 * @return zero, if neither argument is a NaN and are equal
305
 * */
337
 * */
306
int __eqsf2(float a, float b)
338
int __eqsf2(float a, float b)
307
{
339
{
308
    float32 fa, fb;
340
    float32 fa, fb;
309
    fa.f = a;
341
    fa.f = a;
310
    fb.f = b;
342
    fb.f = b;
311
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
343
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
312
        /* TODO: sigNaNs*/
344
        /* TODO: sigNaNs*/
313
        return 1;
345
        return 1;
314
        };
346
        };
315
    return isFloat32eq(fa, fb) - 1;
347
    return isFloat32eq(fa, fb) - 1;
316
}
348
}
317
 
349
 
318
/* strange behavior, but it was in gcc documentation */
350
/* strange behavior, but it was in gcc documentation */
319
int __nesf2(float a, float b)
351
int __nesf2(float a, float b)
320
{
352
{
321
    return __eqsf2(a, b);
353
    return __eqsf2(a, b);
322
}
354
}
323
 
355
 
324
/* return value >= 0 if a>=b and neither is NaN */
356
/* return value >= 0 if a>=b and neither is NaN */
325
int __gesf2(float a, float b)
357
int __gesf2(float a, float b)
326
{
358
{
327
    float32 fa, fb;
359
    float32 fa, fb;
328
    fa.f = a;
360
    fa.f = a;
329
    fb.f = b;
361
    fb.f = b;
330
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
362
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
331
        /* TODO: sigNaNs*/
363
        /* TODO: sigNaNs*/
332
        return -1;
364
        return -1;
333
        };
365
        };
334
   
366
   
335
    if (isFloat32eq(fa, fb)) {
367
    if (isFloat32eq(fa, fb)) {
336
        return 0;
368
        return 0;
337
    };
369
    };
338
   
370
   
339
    if (isFloat32gt(fa, fb)) {
371
    if (isFloat32gt(fa, fb)) {
340
        return 1;
372
        return 1;
341
        };
373
        };
342
   
374
   
343
    return -1;
375
    return -1;
344
}
376
}
345
 
377
 
346
/** Return negative value, if a<b and neither is NaN*/
378
/** Return negative value, if a<b and neither is NaN*/
347
int __ltsf2(float a, float b)
379
int __ltsf2(float a, float b)
348
{
380
{
349
    float32 fa, fb;
381
    float32 fa, fb;
350
    fa.f = a;
382
    fa.f = a;
351
    fb.f = b;
383
    fb.f = b;
352
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
384
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
353
        /* TODO: sigNaNs*/
385
        /* TODO: sigNaNs*/
354
        return 1;
386
        return 1;
355
        };
387
        };
356
    if (isFloat32lt(fa, fb)) {
388
    if (isFloat32lt(fa, fb)) {
357
        return -1;
389
        return -1;
358
        };
390
        };
359
    return 0;
391
    return 0;
360
}
392
}
361
 
393
 
362
/* return value <= 0 if a<=b and neither is NaN */
394
/* return value <= 0 if a<=b and neither is NaN */
363
int __lesf2(float a, float b)
395
int __lesf2(float a, float b)
364
{
396
{
365
    float32 fa, fb;
397
    float32 fa, fb;
366
    fa.f = a;
398
    fa.f = a;
367
    fb.f = b;
399
    fb.f = b;
368
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
400
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
369
        /* TODO: sigNaNs*/
401
        /* TODO: sigNaNs*/
370
        return 1;
402
        return 1;
371
        };
403
        };
372
   
404
   
373
    if (isFloat32eq(fa, fb)) {
405
    if (isFloat32eq(fa, fb)) {
374
        return 0;
406
        return 0;
375
    };
407
    };
376
   
408
   
377
    if (isFloat32lt(fa, fb)) {
409
    if (isFloat32lt(fa, fb)) {
378
        return -1;
410
        return -1;
379
        };
411
        };
380
   
412
   
381
    return 1;
413
    return 1;
382
}
414
}
383
 
415
 
384
/** Return positive value, if a>b and neither is NaN*/
416
/** Return positive value, if a>b and neither is NaN*/
385
int __gtsf2(float a, float b)
417
int __gtsf2(float a, float b)
386
{
418
{
387
    float32 fa, fb;
419
    float32 fa, fb;
388
    fa.f = a;
420
    fa.f = a;
389
    fb.f = b;
421
    fb.f = b;
390
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
422
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
391
        /* TODO: sigNaNs*/
423
        /* TODO: sigNaNs*/
392
        return -1;
424
        return -1;
393
        };
425
        };
394
    if (isFloat32gt(fa, fb)) {
426
    if (isFloat32gt(fa, fb)) {
395
        return 1;
427
        return 1;
396
        };
428
        };
397
    return 0;
429
    return 0;
398
}
430
}
399
 
431
 
400
/* Other functions */
432
/* Other functions */
401
 
433
 
402
float __powisf2(float a, int b)
434
float __powisf2(float a, int b)
403
{
435
{
404
/* TODO: */
436
/* TODO: */
405
}
437
}
406
 
438
 
407
float __mulsc3(float a, float b, float c, float d)
439
float __mulsc3(float a, float b, float c, float d)
408
{
440
{
409
/* TODO: */
441
/* TODO: */
410
}
442
}
411
 
443
 
412
float __divsc3(float a, float b, float c, float d)
444
float __divsc3(float a, float b, float c, float d)
413
{
445
{
414
/* TODO: */
446
/* TODO: */
415
}
447
}
416
 
448
 
417
 
449