Subversion Repositories HelenOS-historic

Rev

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

Rev 734 Rev 737
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
/* Arithmetic functions */
41
/* Arithmetic functions */
42
 
42
 
43
float __addsf3(float a, float b)
43
float __addsf3(float a, float b)
44
{
44
{
45
    float32 fa, fb;
45
    float32 fa, fb;
46
    fa.f=a;
46
    fa.f=a;
47
    fb.f=b;
47
    fb.f=b;
48
    if (fa.parts.sign!=fb.parts.sign) {
48
    if (fa.parts.sign!=fb.parts.sign) {
49
        if (fa.parts.sign) {
49
        if (fa.parts.sign) {
50
            fa.parts.sign=0;
50
            fa.parts.sign=0;
51
            return subFloat32(fb,fa).f;
51
            return subFloat32(fb,fa).f;
52
        };
52
        };
53
        fb.parts.sign=0;
53
        fb.parts.sign=0;
54
        return subFloat32(fa,fb).f;
54
        return subFloat32(fa,fb).f;
55
    }
55
    }
56
    return addFloat32(fa,fb).f;
56
    return addFloat32(fa,fb).f;
57
}
57
}
58
 
58
 
59
double __adddf3(double a, double b)
59
double __adddf3(double a, double b)
60
{
60
{
61
    float64 da, db;
61
    float64 da, db;
62
    da.d=a;
62
    da.d=a;
63
    db.d=b;
63
    db.d=b;
64
    if (da.parts.sign!=db.parts.sign) {
64
    if (da.parts.sign!=db.parts.sign) {
65
        if (da.parts.sign) {
65
        if (da.parts.sign) {
66
            da.parts.sign=0;
66
            da.parts.sign=0;
67
            return subFloat64(db,da).d;
67
            return subFloat64(db,da).d;
68
        };
68
        };
69
        db.parts.sign=0;
69
        db.parts.sign=0;
70
        return subFloat64(da,db).d;
70
        return subFloat64(da,db).d;
71
    }
71
    }
72
    return addFloat64(da,db).d;
72
    return addFloat64(da,db).d;
73
}
73
}
74
 
74
 
75
float __subsf3(float a, float b)
75
float __subsf3(float a, float b)
76
{
76
{
77
    float32 fa, fb;
77
    float32 fa, fb;
78
    fa.f=a;
78
    fa.f=a;
79
    fb.f=b;
79
    fb.f=b;
80
    if (fa.parts.sign!=fb.parts.sign) {
80
    if (fa.parts.sign!=fb.parts.sign) {
81
        fb.parts.sign=!fb.parts.sign;
81
        fb.parts.sign=!fb.parts.sign;
82
        return addFloat32(fa,fb).f;
82
        return addFloat32(fa,fb).f;
83
    }
83
    }
84
    return subFloat32(fa,fb).f;
84
    return subFloat32(fa,fb).f;
85
}
85
}
86
 
86
 
87
double __subdf3(double a, double b)
87
double __subdf3(double a, double b)
88
{
88
{
89
    float64 da, db;
89
    float64 da, db;
90
    da.d = a;
90
    da.d = a;
91
    db.d = b;
91
    db.d = b;
92
    if (da.parts.sign != db.parts.sign) {
92
    if (da.parts.sign != db.parts.sign) {
93
        db.parts.sign = !db.parts.sign;
93
        db.parts.sign = !db.parts.sign;
94
        return addFloat64(da, db).d;
94
        return addFloat64(da, db).d;
95
    }
95
    }
96
    return subFloat64(da, db).d;
96
    return subFloat64(da, db).d;
97
}
97
}
98
 
98
 
99
float __mulsf3(float a, float b)
99
float __mulsf3(float a, float b)
100
{
100
{
101
    float32 fa, fb;
101
    float32 fa, fb;
102
    fa.f=a;
102
    fa.f=a;
103
    fb.f=b;
103
    fb.f=b;
104
    return  mulFloat32(fa, fb).f;
104
    return  mulFloat32(fa, fb).f;
105
}
105
}
106
 
106
 
-
 
107
double __muldf3(double a, double b)
-
 
108
{
-
 
109
    float64 da, db;
-
 
110
    da.d = a;
-
 
111
    db.d = b;
-
 
112
    return  mulFloat64(da, db).d;
-
 
113
}
-
 
114
 
107
float __divsf3(float a, float b)
115
float __divsf3(float a, float b)
108
{
116
{
109
    float32 fa, fb;
117
    float32 fa, fb;
110
    fa.f=a;
118
    fa.f=a;
111
    fb.f=b;
119
    fb.f=b;
112
    //return    divFloat32(fa, fb).f;
120
    //return    divFloat32(fa, fb).f;
113
}
121
}
114
 
122
 
115
float __negsf2(float a)
123
float __negsf2(float a)
116
{
124
{
117
    float32 fa;
125
    float32 fa;
118
    fa.f=a;
126
    fa.f=a;
119
    fa.parts.sign=!fa.parts.sign;
127
    fa.parts.sign=!fa.parts.sign;
120
    return fa.f;
128
    return fa.f;
121
}
129
}
122
 
130
 
123
double __negdf2(double a)
131
double __negdf2(double a)
124
{
132
{
125
    float64 fa;
133
    float64 fa;
126
    fa.d=a;
134
    fa.d=a;
127
    fa.parts.sign=!fa.parts.sign;
135
    fa.parts.sign=!fa.parts.sign;
128
    return fa.d;
136
    return fa.d;
129
}
137
}
130
 
138
 
131
/* Conversion functions */
139
/* Conversion functions */
132
 
140
 
133
double __extendsfdf2(float a)
141
double __extendsfdf2(float a)
134
{
142
{
135
    float32 fa;
143
    float32 fa;
136
    fa.f = a;
144
    fa.f = a;
137
    return convertFloat32ToFloat64(fa).d;
145
    return convertFloat32ToFloat64(fa).d;
138
}
146
}
139
 
147
 
140
float __truncdfsf2(double a)
148
float __truncdfsf2(double a)
141
{
149
{
142
    float64 da;
150
    float64 da;
143
    da.d = a;
151
    da.d = a;
144
    return convertFloat64ToFloat32(da).f;
152
    return convertFloat64ToFloat32(da).f;
145
}
153
}
146
 
154
 
147
/* Comparison functions */
155
/* Comparison functions */
148
 
156
 
149
/* a<b .. -1
157
/* a<b .. -1
150
 * a=b ..  0
158
 * a=b ..  0
151
 * a>b ..  1
159
 * a>b ..  1
152
 * */
160
 * */
153
 
161
 
154
int __cmpsf2(float a, float b)
162
int __cmpsf2(float a, float b)
155
{
163
{
156
    float32 fa,fb;
164
    float32 fa,fb;
157
    fa.f=a;
165
    fa.f=a;
158
    fb.f=b;
166
    fb.f=b;
159
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
167
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
160
        return 1; /* no special constant for unordered - maybe signaled? */
168
        return 1; /* no special constant for unordered - maybe signaled? */
161
    };
169
    };
162
 
170
 
163
   
171
   
164
    if (isFloat32eq(fa,fb)) {
172
    if (isFloat32eq(fa,fb)) {
165
        return 0;
173
        return 0;
166
    };
174
    };
167
   
175
   
168
    if (isFloat32lt(fa,fb)) {
176
    if (isFloat32lt(fa,fb)) {
169
        return -1;
177
        return -1;
170
        };
178
        };
171
    return 1;
179
    return 1;
172
}
180
}
173
 
181
 
174
int __unordsf2(float a, float b)
182
int __unordsf2(float a, float b)
175
{
183
{
176
    float32 fa,fb;
184
    float32 fa,fb;
177
    fa.f=a;
185
    fa.f=a;
178
    fb.f=b;
186
    fb.f=b;
179
    return ((isFloat32NaN(fa))||(isFloat32NaN(fb)));
187
    return ((isFloat32NaN(fa))||(isFloat32NaN(fb)));
180
}
188
}
181
 
189
 
182
/**
190
/**
183
 * @return zero, if neither argument is a NaN and are equal
191
 * @return zero, if neither argument is a NaN and are equal
184
 * */
192
 * */
185
int __eqsf2(float a, float b)
193
int __eqsf2(float a, float b)
186
{
194
{
187
    float32 fa,fb;
195
    float32 fa,fb;
188
    fa.f=a;
196
    fa.f=a;
189
    fb.f=b;
197
    fb.f=b;
190
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
198
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
191
        /* TODO: sigNaNs*/
199
        /* TODO: sigNaNs*/
192
        return 1;
200
        return 1;
193
        };
201
        };
194
    return isFloat32eq(fa,fb)-1;
202
    return isFloat32eq(fa,fb)-1;
195
}
203
}
196
 
204
 
197
/* strange behavior, but it was in gcc documentation */
205
/* strange behavior, but it was in gcc documentation */
198
int __nesf2(float a, float b)
206
int __nesf2(float a, float b)
199
{
207
{
200
    return __eqsf2(a,b);
208
    return __eqsf2(a,b);
201
}
209
}
202
 
210
 
203
/* return value >= 0 if a>=b and neither is NaN */
211
/* return value >= 0 if a>=b and neither is NaN */
204
int __gesf2(float a, float b)
212
int __gesf2(float a, float b)
205
{
213
{
206
    float32 fa,fb;
214
    float32 fa,fb;
207
    fa.f=a;
215
    fa.f=a;
208
    fb.f=b;
216
    fb.f=b;
209
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
217
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
210
        /* TODO: sigNaNs*/
218
        /* TODO: sigNaNs*/
211
        return -1;
219
        return -1;
212
        };
220
        };
213
   
221
   
214
    if (isFloat32eq(fa,fb)) {
222
    if (isFloat32eq(fa,fb)) {
215
        return 0;
223
        return 0;
216
    };
224
    };
217
   
225
   
218
    if (isFloat32gt(fa,fb)) {
226
    if (isFloat32gt(fa,fb)) {
219
        return 1;
227
        return 1;
220
        };
228
        };
221
   
229
   
222
    return -1;
230
    return -1;
223
}
231
}
224
 
232
 
225
/** Return negative value, if a<b and neither is NaN*/
233
/** Return negative value, if a<b and neither is NaN*/
226
int __ltsf2(float a, float b)
234
int __ltsf2(float a, float b)
227
{
235
{
228
    float32 fa,fb;
236
    float32 fa,fb;
229
    fa.f=a;
237
    fa.f=a;
230
    fb.f=b;
238
    fb.f=b;
231
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
239
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
232
        /* TODO: sigNaNs*/
240
        /* TODO: sigNaNs*/
233
        return 1;
241
        return 1;
234
        };
242
        };
235
    if (isFloat32lt(fa, fb)) {
243
    if (isFloat32lt(fa, fb)) {
236
        return -1;
244
        return -1;
237
        };
245
        };
238
    return 0;
246
    return 0;
239
}
247
}
240
 
248
 
241
/* return value <= 0 if a<=b and neither is NaN */
249
/* return value <= 0 if a<=b and neither is NaN */
242
int __lesf2(float a, float b)
250
int __lesf2(float a, float b)
243
{
251
{
244
    float32 fa,fb;
252
    float32 fa,fb;
245
    fa.f=a;
253
    fa.f=a;
246
    fb.f=b;
254
    fb.f=b;
247
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
255
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
248
        /* TODO: sigNaNs*/
256
        /* TODO: sigNaNs*/
249
        return 1;
257
        return 1;
250
        };
258
        };
251
   
259
   
252
    if (isFloat32eq(fa,fb)) {
260
    if (isFloat32eq(fa,fb)) {
253
        return 0;
261
        return 0;
254
    };
262
    };
255
   
263
   
256
    if (isFloat32lt(fa,fb)) {
264
    if (isFloat32lt(fa,fb)) {
257
        return -1;
265
        return -1;
258
        };
266
        };
259
   
267
   
260
    return 1;
268
    return 1;
261
}
269
}
262
 
270
 
263
/** Return positive value, if a>b and neither is NaN*/
271
/** Return positive value, if a>b and neither is NaN*/
264
int __gtsf2(float a, float b)
272
int __gtsf2(float a, float b)
265
{
273
{
266
    float32 fa,fb;
274
    float32 fa,fb;
267
    fa.f=a;
275
    fa.f=a;
268
    fb.f=b;
276
    fb.f=b;
269
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
277
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
270
        /* TODO: sigNaNs*/
278
        /* TODO: sigNaNs*/
271
        return -1;
279
        return -1;
272
        };
280
        };
273
    if (isFloat32gt(fa, fb)) {
281
    if (isFloat32gt(fa, fb)) {
274
        return 1;
282
        return 1;
275
        };
283
        };
276
    return 0;
284
    return 0;
277
}
285
}
278
 
286
 
279
/* Other functions */
287
/* Other functions */
280
 
288
 
281
float __powisf2(float a, int b)
289
float __powisf2(float a, int b)
282
{
290
{
283
//TODO: 
291
//TODO: 
284
}
292
}
285
 
293
 
286
float __mulsc3(float a, float b, float c, float d)
294
float __mulsc3(float a, float b, float c, float d)
287
{
295
{
288
//TODO:
296
//TODO:
289
}
297
}
290
 
298
 
291
float __divsc3(float a, float b, float c, float d)
299
float __divsc3(float a, float b, float c, float d)
292
{
300
{
293
//TODO:
301
//TODO:
294
}
302
}
295
 
303
 
296
 
304