Subversion Repositories HelenOS-historic

Rev

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

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