Subversion Repositories HelenOS-historic

Rev

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

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