Subversion Repositories HelenOS-historic

Rev

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

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