Subversion Repositories HelenOS-historic

Rev

Rev 698 | Rev 734 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
535 cejka 1
/*
2
 * Copyright (C) 2005 Josef Cejka
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
#include<softfloat.h>
647 cejka 30
#include<sftypes.h>
731 cejka 31
 
32
#include<add.h>
33
#include<sub.h>
34
#include<mul.h>
35
#include<div.h>
36
 
647 cejka 37
#include<conversion.h>
38
#include<comparison.h>
39
#include<other.h>
535 cejka 40
 
647 cejka 41
/* Arithmetic functions */
542 cejka 42
 
43
float __addsf3(float a, float b)
44
{
45
    float32 fa, fb;
563 cejka 46
    fa.f=a;
47
    fb.f=b;
647 cejka 48
    if (fa.parts.sign!=fb.parts.sign) {
49
        if (fa.parts.sign) {
50
            fa.parts.sign=0;
51
            return subFloat32(fb,fa).f;
52
        };
53
        fb.parts.sign=0;
54
        return subFloat32(fa,fb).f;
55
    }
563 cejka 56
    return addFloat32(fa,fb).f;
698 cejka 57
}
542 cejka 58
 
59
float __subsf3(float a, float b)
60
{
61
    float32 fa, fb;
563 cejka 62
    fa.f=a;
63
    fb.f=b;
647 cejka 64
    if (fa.parts.sign!=fb.parts.sign) {
660 cejka 65
        fb.parts.sign=!fb.parts.sign;
647 cejka 66
        return addFloat32(fa,fb).f;
67
    }
563 cejka 68
    return subFloat32(fa,fb).f;
698 cejka 69
}
542 cejka 70
 
688 cejka 71
float __mulsf3(float a, float b)
72
{
73
    float32 fa, fb;
74
    fa.f=a;
75
    fb.f=b;
76
    return  mulFloat32(fa, fb).f;
77
}
78
 
697 cejka 79
float __divsf3(float a, float b)
80
{
81
    float32 fa, fb;
82
    fa.f=a;
83
    fb.f=b;
731 cejka 84
    //return    divFloat32(fa, fb).f;
698 cejka 85
}
697 cejka 86
 
542 cejka 87
float __negsf2(float a)
88
{
89
    float32 fa;
90
    fa.f=a;
91
    fa.parts.sign=!fa.parts.sign;
92
    return fa.f;
698 cejka 93
}
542 cejka 94
 
95
double __negdf2(double a)
96
{
97
    float64 fa;
563 cejka 98
    fa.d=a;
542 cejka 99
    fa.parts.sign=!fa.parts.sign;
563 cejka 100
    return fa.d;
698 cejka 101
}
542 cejka 102
 
647 cejka 103
/* Conversion functions */
542 cejka 104
 
697 cejka 105
double __extendsfdf2(float a)
106
{
107
    float32 fa;
108
    fa.f = a;
109
    return convertFloat32ToFloat64(fa).d;
698 cejka 110
}
697 cejka 111
 
112
float __truncdfsf2(double a)
113
{
114
    float64 da;
115
    da.d = a;
116
    return convertFloat64ToFloat32(da).f;
117
}
698 cejka 118
 
647 cejka 119
/* Comparison functions */
542 cejka 120
 
652 cejka 121
/* a<b .. -1
122
 * a=b ..  0
123
 * a>b ..  1
124
 * */
125
 
660 cejka 126
int __cmpsf2(float a, float b)
652 cejka 127
{
128
    float32 fa,fb;
129
    fa.f=a;
130
    fb.f=b;
131
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
132
        return 1; /* no special constant for unordered - maybe signaled? */
133
    };
134
 
135
 
136
    if (isFloat32eq(fa,fb)) {
137
        return 0;
138
    };
139
 
140
    if (isFloat32lt(fa,fb)) {
141
        return -1;
142
        };
143
    return 1;
144
}
145
 
146
int __unordsf2(float a, float b)
147
{
148
    float32 fa,fb;
149
    fa.f=a;
150
    fb.f=b;
151
    return ((isFloat32NaN(fa))||(isFloat32NaN(fb)));
698 cejka 152
}
652 cejka 153
 
154
/**
155
 * @return zero, if neither argument is a NaN and are equal
156
 * */
157
int __eqsf2(float a, float b)
158
{
159
    float32 fa,fb;
160
    fa.f=a;
161
    fb.f=b;
162
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
163
        /* TODO: sigNaNs*/
164
        return 1;
165
        };
166
    return isFloat32eq(fa,fb)-1;
698 cejka 167
}
652 cejka 168
 
169
/* strange behavior, but it was in gcc documentation */
170
int __nesf2(float a, float b)
171
{
172
    return __eqsf2(a,b);
698 cejka 173
}
653 cejka 174
 
175
/* return value >= 0 if a>=b and neither is NaN */
176
int __gesf2(float a, float b)
177
{
178
    float32 fa,fb;
179
    fa.f=a;
180
    fb.f=b;
181
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
182
        /* TODO: sigNaNs*/
660 cejka 183
        return -1;
653 cejka 184
        };
185
 
186
    if (isFloat32eq(fa,fb)) {
187
        return 0;
188
    };
189
 
190
    if (isFloat32gt(fa,fb)) {
191
        return 1;
192
        };
193
 
194
    return -1;
195
}
196
 
197
/** Return negative value, if a<b and neither is NaN*/
198
int __ltsf2(float a, float b)
199
{
200
    float32 fa,fb;
201
    fa.f=a;
202
    fb.f=b;
203
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
204
        /* TODO: sigNaNs*/
205
        return 1;
206
        };
207
    if (isFloat32lt(fa, fb)) {
208
        return -1;
209
        };
210
    return 0;
211
}
212
 
213
/* return value <= 0 if a<=b and neither is NaN */
214
int __lesf2(float a, float b)
215
{
216
    float32 fa,fb;
217
    fa.f=a;
218
    fb.f=b;
219
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
220
        /* TODO: sigNaNs*/
221
        return 1;
222
        };
223
 
224
    if (isFloat32eq(fa,fb)) {
225
        return 0;
226
    };
227
 
228
    if (isFloat32lt(fa,fb)) {
229
        return -1;
230
        };
231
 
232
    return 1;
233
}
234
 
235
/** Return positive value, if a>b and neither is NaN*/
660 cejka 236
int __gtsf2(float a, float b)
653 cejka 237
{
238
    float32 fa,fb;
239
    fa.f=a;
240
    fb.f=b;
241
    if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
242
        /* TODO: sigNaNs*/
660 cejka 243
        return -1;
653 cejka 244
        };
245
    if (isFloat32gt(fa, fb)) {
246
        return 1;
247
        };
248
    return 0;
249
}
250
 
647 cejka 251
/* Other functions */
542 cejka 252
 
698 cejka 253
float __powisf2(float a, int b)
254
{
255
//TODO: 
256
}
257
 
258
float __mulsc3(float a, float b, float c, float d)
259
{
260
//TODO:
261
}
262
 
263
float __divsc3(float a, float b, float c, float d)
264
{
265
//TODO:
266
}
267