Subversion Repositories HelenOS-historic

Rev

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

Rev 828 Rev 857
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>
-
 
42
#include<types.h>
-
 
43
#include<functions.h>
-
 
44
 
41
/* Arithmetic functions */
45
/* Arithmetic functions */
42
 
46
 
43
float __addsf3(float a, float b)
47
float __addsf3(float a, float b)
44
{
48
{
45
    float32 fa, fb;
49
    float32 fa, fb;
46
    fa.f = a;
50
    fa.f = a;
47
    fb.f = b;
51
    fb.f = b;
48
    if (fa.parts.sign != fb.parts.sign) {
52
    if (fa.parts.sign != fb.parts.sign) {
49
        if (fa.parts.sign) {
53
        if (fa.parts.sign) {
50
            fa.parts.sign = 0;
54
            fa.parts.sign = 0;
51
            return subFloat32(fb, fa).f;
55
            return subFloat32(fb, fa).f;
52
        };
56
        };
53
        fb.parts.sign = 0;
57
        fb.parts.sign = 0;
54
        return subFloat32(fa, fb).f;
58
        return subFloat32(fa, fb).f;
55
    }
59
    }
56
    return addFloat32(fa, fb).f;
60
    return addFloat32(fa, fb).f;
57
}
61
}
58
 
62
 
59
double __adddf3(double a, double b)
63
double __adddf3(double a, double b)
60
{
64
{
61
    float64 da, db;
65
    float64 da, db;
62
    da.d = a;
66
    da.d = a;
63
    db.d = b;
67
    db.d = b;
64
    if (da.parts.sign != db.parts.sign) {
68
    if (da.parts.sign != db.parts.sign) {
65
        if (da.parts.sign) {
69
        if (da.parts.sign) {
66
            da.parts.sign = 0;
70
            da.parts.sign = 0;
67
            return subFloat64(db, da).d;
71
            return subFloat64(db, da).d;
68
        };
72
        };
69
        db.parts.sign = 0;
73
        db.parts.sign = 0;
70
        return subFloat64(da, db).d;
74
        return subFloat64(da, db).d;
71
    }
75
    }
72
    return addFloat64(da, db).d;
76
    return addFloat64(da, db).d;
73
}
77
}
74
 
78
 
75
float __subsf3(float a, float b)
79
float __subsf3(float a, float b)
76
{
80
{
77
    float32 fa, fb;
81
    float32 fa, fb;
78
    fa.f = a;
82
    fa.f = a;
79
    fb.f = b;
83
    fb.f = b;
80
    if (fa.parts.sign != fb.parts.sign) {
84
    if (fa.parts.sign != fb.parts.sign) {
81
        fb.parts.sign = !fb.parts.sign;
85
        fb.parts.sign = !fb.parts.sign;
82
        return addFloat32(fa, fb).f;
86
        return addFloat32(fa, fb).f;
83
    }
87
    }
84
    return subFloat32(fa, fb).f;
88
    return subFloat32(fa, fb).f;
85
}
89
}
86
 
90
 
87
double __subdf3(double a, double b)
91
double __subdf3(double a, double b)
88
{
92
{
89
    float64 da, db;
93
    float64 da, db;
90
    da.d = a;
94
    da.d = a;
91
    db.d = b;
95
    db.d = b;
92
    if (da.parts.sign != db.parts.sign) {
96
    if (da.parts.sign != db.parts.sign) {
93
        db.parts.sign = !db.parts.sign;
97
        db.parts.sign = !db.parts.sign;
94
        return addFloat64(da, db).d;
98
        return addFloat64(da, db).d;
95
    }
99
    }
96
    return subFloat64(da, db).d;
100
    return subFloat64(da, db).d;
97
}
101
}
98
 
102
 
99
float __mulsf3(float a, float b)
103
float __mulsf3(float a, float b)
100
{
104
{
101
    float32 fa, fb;
105
    float32 fa, fb;
102
    fa.f = a;
106
    fa.f = a;
103
    fb.f = b;
107
    fb.f = b;
104
    return  mulFloat32(fa, fb).f;
108
    return  mulFloat32(fa, fb).f;
105
}
109
}
106
 
110
 
107
double __muldf3(double a, double b)
111
double __muldf3(double a, double b)
108
{
112
{
109
    float64 da, db;
113
    float64 da, db;
110
    da.d = a;
114
    da.d = a;
111
    db.d = b;
115
    db.d = b;
112
    return  mulFloat64(da, db).d;
116
    return  mulFloat64(da, db).d;
113
}
117
}
114
 
118
 
115
float __divsf3(float a, float b)
119
float __divsf3(float a, float b)
116
{
120
{
117
    float32 fa, fb;
121
    float32 fa, fb;
118
    fa.f = a;
122
    fa.f = a;
119
    fb.f = b;
123
    fb.f = b;
120
    return  divFloat32(fa, fb).f;
124
    return  divFloat32(fa, fb).f;
121
}
125
}
122
 
126
 
123
double __divdf3(double a, double b)
127
double __divdf3(double a, double b)
124
{
128
{
125
    float64 da, db;
129
    float64 da, db;
126
    da.d = a;
130
    da.d = a;
127
    db.d = b;
131
    db.d = b;
128
    return  divFloat64(da, db).d;
132
    return  divFloat64(da, db).d;
129
}
133
}
130
 
134
 
131
float __negsf2(float a)
135
float __negsf2(float a)
132
{
136
{
133
    float32 fa;
137
    float32 fa;
134
    fa.f = a;
138
    fa.f = a;
135
    fa.parts.sign = !fa.parts.sign;
139
    fa.parts.sign = !fa.parts.sign;
136
    return fa.f;
140
    return fa.f;
137
}
141
}
138
 
142
 
139
double __negdf2(double a)
143
double __negdf2(double a)
140
{
144
{
141
    float64 fa;
145
    float64 fa;
142
    fa.d = a;
146
    fa.d = a;
143
    fa.parts.sign = !fa.parts.sign;
147
    fa.parts.sign = !fa.parts.sign;
144
    return fa.d;
148
    return fa.d;
145
}
149
}
146
 
150
 
147
/* Conversion functions */
151
/* Conversion functions */
148
 
152
 
149
double __extendsfdf2(float a)
153
double __extendsfdf2(float a)
150
{
154
{
151
    float32 fa;
155
    float32 fa;
152
    fa.f = a;
156
    fa.f = a;
153
    return convertFloat32ToFloat64(fa).d;
157
    return convertFloat32ToFloat64(fa).d;
154
}
158
}
155
 
159
 
156
float __truncdfsf2(double a)
160
float __truncdfsf2(double a)
157
{
161
{
158
    float64 da;
162
    float64 da;
159
    da.d = a;
163
    da.d = a;
160
    return convertFloat64ToFloat32(da).f;
164
    return convertFloat64ToFloat32(da).f;
161
}
165
}
162
 
166
 
-
 
167
int __fixsfsi(float a)
-
 
168
{
-
 
169
    float32 fa;
-
 
170
    fa.f = a;
-
 
171
   
-
 
172
    return float32_to_int(fa);
-
 
173
}
-
 
174
int __fixdfsi(double a)
-
 
175
{
-
 
176
}
-
 
177
 
-
 
178
long __fixsfdi(float a)
-
 
179
{
-
 
180
    float32 fa;
-
 
181
    fa.f = a;
-
 
182
   
-
 
183
    return float32_to_long(fa);
-
 
184
}
-
 
185
long __fixdfdi(double a)
-
 
186
{
-
 
187
}
-
 
188
 
-
 
189
long long __fixsfti(float a)
-
 
190
{
-
 
191
}
-
 
192
long long __fixdfti(double a)
-
 
193
{
-
 
194
}
-
 
195
 
-
 
196
unsigned int __fixunssfsi(float a)
-
 
197
{
-
 
198
    float32 fa;
-
 
199
    fa.f = a;
-
 
200
   
-
 
201
    return float32_to_uint(fa);
-
 
202
}
-
 
203
unsigned int __fixunsdfsi(double a)
-
 
204
{
-
 
205
}
-
 
206
 
-
 
207
unsigned long __fixunssfdi(float a)
-
 
208
{
-
 
209
    float32 fa;
-
 
210
    fa.f = a;
-
 
211
   
-
 
212
    return float32_to_long(fa);
-
 
213
}
-
 
214
unsigned long __fixunsdfdi(double a)
-
 
215
{
-
 
216
}
-
 
217
 
-
 
218
unsigned long long __fixunssfti(float a)
-
 
219
{
-
 
220
}
-
 
221
unsigned long long __fixunsdfti(double a)
-
 
222
{
-
 
223
}
-
 
224
 
-
 
225
float __floatsisf(int i)
-
 
226
{
-
 
227
}
-
 
228
double __floatsidf(int i)
-
 
229
{
-
 
230
}
-
 
231
 
-
 
232
float __floatdisf(long i)
-
 
233
{
-
 
234
}
-
 
235
double __floatdidf(long i)
-
 
236
{
-
 
237
}
-
 
238
 
-
 
239
float __floattisf(long long i)
-
 
240
{
-
 
241
}
-
 
242
double __floattidf(long long i)
-
 
243
{
-
 
244
}
-
 
245
 
-
 
246
float __floatunsisf(unsigned int i)
-
 
247
{
-
 
248
}
-
 
249
double __floatunsidf(unsigned int i)
-
 
250
{
-
 
251
}
-
 
252
 
-
 
253
float __floatundisf(unsigned long i)
-
 
254
{
-
 
255
}
-
 
256
double __floatundidf(unsigned long i)
-
 
257
{
-
 
258
}
-
 
259
 
-
 
260
float __floatuntisf(unsigned long long i)
-
 
261
{
-
 
262
}
-
 
263
double __floatuntidf(unsigned long long i)
-
 
264
{
-
 
265
}
-
 
266
 
-
 
267
/* Comparison functions */
163
/* Comparison functions */
268
/* Comparison functions */
164
 
269
 
165
/* a<b .. -1
270
/* a<b .. -1
166
 * a=b ..  0
271
 * a=b ..  0
167
 * a>b ..  1
272
 * a>b ..  1
168
 * */
273
 * */
169
 
274
 
170
int __cmpsf2(float a, float b)
275
int __cmpsf2(float a, float b)
171
{
276
{
172
    float32 fa, fb;
277
    float32 fa, fb;
173
    fa.f = a;
278
    fa.f = a;
174
    fb.f = b;
279
    fb.f = b;
175
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
280
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
176
        return 1; /* no special constant for unordered - maybe signaled? */
281
        return 1; /* no special constant for unordered - maybe signaled? */
177
    };
282
    };
178
 
283
 
179
   
284
   
180
    if (isFloat32eq(fa, fb)) {
285
    if (isFloat32eq(fa, fb)) {
181
        return 0;
286
        return 0;
182
    };
287
    };
183
   
288
   
184
    if (isFloat32lt(fa, fb)) {
289
    if (isFloat32lt(fa, fb)) {
185
        return -1;
290
        return -1;
186
        };
291
        };
187
    return 1;
292
    return 1;
188
}
293
}
189
 
294
 
190
int __unordsf2(float a, float b)
295
int __unordsf2(float a, float b)
191
{
296
{
192
    float32 fa, fb;
297
    float32 fa, fb;
193
    fa.f = a;
298
    fa.f = a;
194
    fb.f = b;
299
    fb.f = b;
195
    return ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) );
300
    return ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) );
196
}
301
}
197
 
302
 
198
/**
303
/**
199
 * @return zero, if neither argument is a NaN and are equal
304
 * @return zero, if neither argument is a NaN and are equal
200
 * */
305
 * */
201
int __eqsf2(float a, float b)
306
int __eqsf2(float a, float b)
202
{
307
{
203
    float32 fa, fb;
308
    float32 fa, fb;
204
    fa.f = a;
309
    fa.f = a;
205
    fb.f = b;
310
    fb.f = b;
206
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
311
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
207
        /* TODO: sigNaNs*/
312
        /* TODO: sigNaNs*/
208
        return 1;
313
        return 1;
209
        };
314
        };
210
    return isFloat32eq(fa, fb) - 1;
315
    return isFloat32eq(fa, fb) - 1;
211
}
316
}
212
 
317
 
213
/* strange behavior, but it was in gcc documentation */
318
/* strange behavior, but it was in gcc documentation */
214
int __nesf2(float a, float b)
319
int __nesf2(float a, float b)
215
{
320
{
216
    return __eqsf2(a, b);
321
    return __eqsf2(a, b);
217
}
322
}
218
 
323
 
219
/* return value >= 0 if a>=b and neither is NaN */
324
/* return value >= 0 if a>=b and neither is NaN */
220
int __gesf2(float a, float b)
325
int __gesf2(float a, float b)
221
{
326
{
222
    float32 fa, fb;
327
    float32 fa, fb;
223
    fa.f = a;
328
    fa.f = a;
224
    fb.f = b;
329
    fb.f = b;
225
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
330
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
226
        /* TODO: sigNaNs*/
331
        /* TODO: sigNaNs*/
227
        return -1;
332
        return -1;
228
        };
333
        };
229
   
334
   
230
    if (isFloat32eq(fa, fb)) {
335
    if (isFloat32eq(fa, fb)) {
231
        return 0;
336
        return 0;
232
    };
337
    };
233
   
338
   
234
    if (isFloat32gt(fa, fb)) {
339
    if (isFloat32gt(fa, fb)) {
235
        return 1;
340
        return 1;
236
        };
341
        };
237
   
342
   
238
    return -1;
343
    return -1;
239
}
344
}
240
 
345
 
241
/** Return negative value, if a<b and neither is NaN*/
346
/** Return negative value, if a<b and neither is NaN*/
242
int __ltsf2(float a, float b)
347
int __ltsf2(float a, float b)
243
{
348
{
244
    float32 fa, fb;
349
    float32 fa, fb;
245
    fa.f = a;
350
    fa.f = a;
246
    fb.f = b;
351
    fb.f = b;
247
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
352
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
248
        /* TODO: sigNaNs*/
353
        /* TODO: sigNaNs*/
249
        return 1;
354
        return 1;
250
        };
355
        };
251
    if (isFloat32lt(fa, fb)) {
356
    if (isFloat32lt(fa, fb)) {
252
        return -1;
357
        return -1;
253
        };
358
        };
254
    return 0;
359
    return 0;
255
}
360
}
256
 
361
 
257
/* return value <= 0 if a<=b and neither is NaN */
362
/* return value <= 0 if a<=b and neither is NaN */
258
int __lesf2(float a, float b)
363
int __lesf2(float a, float b)
259
{
364
{
260
    float32 fa, fb;
365
    float32 fa, fb;
261
    fa.f = a;
366
    fa.f = a;
262
    fb.f = b;
367
    fb.f = b;
263
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
368
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
264
        /* TODO: sigNaNs*/
369
        /* TODO: sigNaNs*/
265
        return 1;
370
        return 1;
266
        };
371
        };
267
   
372
   
268
    if (isFloat32eq(fa, fb)) {
373
    if (isFloat32eq(fa, fb)) {
269
        return 0;
374
        return 0;
270
    };
375
    };
271
   
376
   
272
    if (isFloat32lt(fa, fb)) {
377
    if (isFloat32lt(fa, fb)) {
273
        return -1;
378
        return -1;
274
        };
379
        };
275
   
380
   
276
    return 1;
381
    return 1;
277
}
382
}
278
 
383
 
279
/** Return positive value, if a>b and neither is NaN*/
384
/** Return positive value, if a>b and neither is NaN*/
280
int __gtsf2(float a, float b)
385
int __gtsf2(float a, float b)
281
{
386
{
282
    float32 fa, fb;
387
    float32 fa, fb;
283
    fa.f = a;
388
    fa.f = a;
284
    fb.f = b;
389
    fb.f = b;
285
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
390
    if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
286
        /* TODO: sigNaNs*/
391
        /* TODO: sigNaNs*/
287
        return -1;
392
        return -1;
288
        };
393
        };
289
    if (isFloat32gt(fa, fb)) {
394
    if (isFloat32gt(fa, fb)) {
290
        return 1;
395
        return 1;
291
        };
396
        };
292
    return 0;
397
    return 0;
293
}
398
}
294
 
399
 
295
/* Other functions */
400
/* Other functions */
296
 
401
 
297
float __powisf2(float a, int b)
402
float __powisf2(float a, int b)
298
{
403
{
299
/* TODO: */
404
/* TODO: */
300
}
405
}
301
 
406
 
302
float __mulsc3(float a, float b, float c, float d)
407
float __mulsc3(float a, float b, float c, float d)
303
{
408
{
304
/* TODO: */
409
/* TODO: */
305
}
410
}
306
 
411
 
307
float __divsc3(float a, float b, float c, float d)
412
float __divsc3(float a, float b, float c, float d)
308
{
413
{
309
/* TODO: */
414
/* TODO: */
310
}
415
}
311
 
416
 
312
 
417