Rev 858 | Rev 874 | 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 | |
857 | cejka | 41 | #include<arch.h> |
42 | #include<types.h> |
||
43 | #include<functions.h> |
||
44 | |||
647 | cejka | 45 | /* Arithmetic functions */ |
542 | cejka | 46 | |
47 | float __addsf3(float a, float b) |
||
48 | { |
||
49 | float32 fa, fb; |
||
804 | cejka | 50 | fa.f = a; |
51 | fb.f = b; |
||
52 | if (fa.parts.sign != fb.parts.sign) { |
||
647 | cejka | 53 | if (fa.parts.sign) { |
804 | cejka | 54 | fa.parts.sign = 0; |
55 | return subFloat32(fb, fa).f; |
||
647 | cejka | 56 | }; |
804 | cejka | 57 | fb.parts.sign = 0; |
58 | return subFloat32(fa, fb).f; |
||
647 | cejka | 59 | } |
804 | cejka | 60 | return addFloat32(fa, fb).f; |
698 | cejka | 61 | } |
542 | cejka | 62 | |
734 | cejka | 63 | double __adddf3(double a, double b) |
64 | { |
||
65 | float64 da, db; |
||
804 | cejka | 66 | da.d = a; |
67 | db.d = b; |
||
68 | if (da.parts.sign != db.parts.sign) { |
||
734 | cejka | 69 | if (da.parts.sign) { |
804 | cejka | 70 | da.parts.sign = 0; |
71 | return subFloat64(db, da).d; |
||
734 | cejka | 72 | }; |
804 | cejka | 73 | db.parts.sign = 0; |
74 | return subFloat64(da, db).d; |
||
734 | cejka | 75 | } |
804 | cejka | 76 | return addFloat64(da, db).d; |
734 | cejka | 77 | } |
78 | |||
542 | cejka | 79 | float __subsf3(float a, float b) |
80 | { |
||
81 | float32 fa, fb; |
||
804 | cejka | 82 | fa.f = a; |
83 | fb.f = b; |
||
84 | if (fa.parts.sign != fb.parts.sign) { |
||
85 | fb.parts.sign = !fb.parts.sign; |
||
86 | return addFloat32(fa, fb).f; |
||
647 | cejka | 87 | } |
804 | cejka | 88 | return subFloat32(fa, fb).f; |
698 | cejka | 89 | } |
542 | cejka | 90 | |
734 | cejka | 91 | double __subdf3(double a, double b) |
92 | { |
||
93 | float64 da, db; |
||
94 | da.d = a; |
||
95 | db.d = b; |
||
96 | if (da.parts.sign != db.parts.sign) { |
||
97 | db.parts.sign = !db.parts.sign; |
||
98 | return addFloat64(da, db).d; |
||
99 | } |
||
100 | return subFloat64(da, db).d; |
||
101 | } |
||
102 | |||
688 | cejka | 103 | float __mulsf3(float a, float b) |
104 | { |
||
105 | float32 fa, fb; |
||
804 | cejka | 106 | fa.f = a; |
107 | fb.f = b; |
||
688 | cejka | 108 | return mulFloat32(fa, fb).f; |
109 | } |
||
110 | |||
737 | cejka | 111 | double __muldf3(double a, double b) |
112 | { |
||
113 | float64 da, db; |
||
114 | da.d = a; |
||
115 | db.d = b; |
||
116 | return mulFloat64(da, db).d; |
||
117 | } |
||
118 | |||
697 | cejka | 119 | float __divsf3(float a, float b) |
120 | { |
||
121 | float32 fa, fb; |
||
804 | cejka | 122 | fa.f = a; |
123 | fb.f = b; |
||
124 | return divFloat32(fa, fb).f; |
||
698 | cejka | 125 | } |
697 | cejka | 126 | |
828 | cejka | 127 | double __divdf3(double a, double b) |
128 | { |
||
129 | float64 da, db; |
||
130 | da.d = a; |
||
131 | db.d = b; |
||
132 | return divFloat64(da, db).d; |
||
133 | } |
||
134 | |||
542 | cejka | 135 | float __negsf2(float a) |
136 | { |
||
137 | float32 fa; |
||
804 | cejka | 138 | fa.f = a; |
139 | fa.parts.sign = !fa.parts.sign; |
||
542 | cejka | 140 | return fa.f; |
698 | cejka | 141 | } |
542 | cejka | 142 | |
143 | double __negdf2(double a) |
||
144 | { |
||
145 | float64 fa; |
||
804 | cejka | 146 | fa.d = a; |
147 | fa.parts.sign = !fa.parts.sign; |
||
563 | cejka | 148 | return fa.d; |
698 | cejka | 149 | } |
542 | cejka | 150 | |
647 | cejka | 151 | /* Conversion functions */ |
542 | cejka | 152 | |
697 | cejka | 153 | double __extendsfdf2(float a) |
154 | { |
||
155 | float32 fa; |
||
156 | fa.f = a; |
||
157 | return convertFloat32ToFloat64(fa).d; |
||
698 | cejka | 158 | } |
697 | cejka | 159 | |
160 | float __truncdfsf2(double a) |
||
161 | { |
||
162 | float64 da; |
||
163 | da.d = a; |
||
164 | return convertFloat64ToFloat32(da).f; |
||
165 | } |
||
698 | cejka | 166 | |
857 | cejka | 167 | int __fixsfsi(float a) |
168 | { |
||
169 | float32 fa; |
||
170 | fa.f = a; |
||
171 | |||
172 | return float32_to_int(fa); |
||
173 | } |
||
174 | int __fixdfsi(double a) |
||
175 | { |
||
865 | cejka | 176 | float64 da; |
177 | da.d = a; |
||
178 | |||
179 | return float64_to_int(da); |
||
857 | cejka | 180 | } |
181 | |||
182 | long __fixsfdi(float a) |
||
183 | { |
||
184 | float32 fa; |
||
185 | fa.f = a; |
||
186 | |||
187 | return float32_to_long(fa); |
||
188 | } |
||
189 | long __fixdfdi(double a) |
||
190 | { |
||
865 | cejka | 191 | float64 da; |
192 | da.d = a; |
||
193 | |||
194 | return float64_to_long(da); |
||
857 | cejka | 195 | } |
196 | |||
197 | long long __fixsfti(float a) |
||
198 | { |
||
865 | cejka | 199 | float32 fa; |
200 | fa.f = a; |
||
201 | |||
202 | return float32_to_longlong(fa); |
||
857 | cejka | 203 | } |
204 | long long __fixdfti(double a) |
||
205 | { |
||
865 | cejka | 206 | float64 da; |
207 | da.d = a; |
||
208 | |||
209 | return float64_to_longlong(da); |
||
857 | cejka | 210 | } |
211 | |||
212 | unsigned int __fixunssfsi(float a) |
||
213 | { |
||
214 | float32 fa; |
||
215 | fa.f = a; |
||
216 | |||
217 | return float32_to_uint(fa); |
||
218 | } |
||
219 | unsigned int __fixunsdfsi(double a) |
||
220 | { |
||
865 | cejka | 221 | float64 da; |
222 | da.d = a; |
||
223 | |||
224 | return float64_to_uint(da); |
||
857 | cejka | 225 | } |
226 | |||
227 | unsigned long __fixunssfdi(float a) |
||
228 | { |
||
229 | float32 fa; |
||
230 | fa.f = a; |
||
231 | |||
858 | cejka | 232 | return float32_to_ulong(fa); |
857 | cejka | 233 | } |
234 | unsigned long __fixunsdfdi(double a) |
||
235 | { |
||
865 | cejka | 236 | float64 da; |
237 | da.d = a; |
||
238 | |||
239 | return float64_to_ulong(da); |
||
857 | cejka | 240 | } |
241 | |||
242 | unsigned long long __fixunssfti(float a) |
||
243 | { |
||
865 | cejka | 244 | float32 fa; |
245 | fa.f = a; |
||
246 | |||
247 | return float32_to_ulonglong(fa); |
||
857 | cejka | 248 | } |
249 | unsigned long long __fixunsdfti(double a) |
||
250 | { |
||
865 | cejka | 251 | float64 da; |
252 | da.d = a; |
||
253 | |||
254 | return float64_to_ulonglong(da); |
||
857 | cejka | 255 | } |
256 | |||
257 | float __floatsisf(int i) |
||
258 | { |
||
259 | } |
||
260 | double __floatsidf(int i) |
||
261 | { |
||
262 | } |
||
263 | |||
264 | float __floatdisf(long i) |
||
265 | { |
||
266 | } |
||
267 | double __floatdidf(long i) |
||
268 | { |
||
269 | } |
||
270 | |||
271 | float __floattisf(long long i) |
||
272 | { |
||
273 | } |
||
274 | double __floattidf(long long i) |
||
275 | { |
||
276 | } |
||
277 | |||
278 | float __floatunsisf(unsigned int i) |
||
279 | { |
||
280 | } |
||
281 | double __floatunsidf(unsigned int i) |
||
282 | { |
||
283 | } |
||
284 | |||
285 | float __floatundisf(unsigned long i) |
||
286 | { |
||
287 | } |
||
288 | double __floatundidf(unsigned long i) |
||
289 | { |
||
290 | } |
||
291 | |||
292 | float __floatuntisf(unsigned long long i) |
||
293 | { |
||
294 | } |
||
295 | double __floatuntidf(unsigned long long i) |
||
296 | { |
||
297 | } |
||
298 | |||
647 | cejka | 299 | /* Comparison functions */ |
857 | cejka | 300 | /* Comparison functions */ |
542 | cejka | 301 | |
652 | cejka | 302 | /* a<b .. -1 |
303 | * a=b .. 0 |
||
304 | * a>b .. 1 |
||
305 | * */ |
||
306 | |||
660 | cejka | 307 | int __cmpsf2(float a, float b) |
652 | cejka | 308 | { |
804 | cejka | 309 | float32 fa, fb; |
310 | fa.f = a; |
||
311 | fb.f = b; |
||
312 | if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) { |
||
652 | cejka | 313 | return 1; /* no special constant for unordered - maybe signaled? */ |
314 | }; |
||
315 | |||
316 | |||
804 | cejka | 317 | if (isFloat32eq(fa, fb)) { |
652 | cejka | 318 | return 0; |
319 | }; |
||
320 | |||
804 | cejka | 321 | if (isFloat32lt(fa, fb)) { |
652 | cejka | 322 | return -1; |
323 | }; |
||
324 | return 1; |
||
325 | } |
||
326 | |||
327 | int __unordsf2(float a, float b) |
||
328 | { |
||
804 | cejka | 329 | float32 fa, fb; |
330 | fa.f = a; |
||
331 | fb.f = b; |
||
332 | return ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ); |
||
698 | cejka | 333 | } |
652 | cejka | 334 | |
335 | /** |
||
336 | * @return zero, if neither argument is a NaN and are equal |
||
337 | * */ |
||
338 | int __eqsf2(float a, float b) |
||
339 | { |
||
804 | cejka | 340 | float32 fa, fb; |
341 | fa.f = a; |
||
342 | fb.f = b; |
||
343 | if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) { |
||
652 | cejka | 344 | /* TODO: sigNaNs*/ |
345 | return 1; |
||
346 | }; |
||
804 | cejka | 347 | return isFloat32eq(fa, fb) - 1; |
698 | cejka | 348 | } |
652 | cejka | 349 | |
350 | /* strange behavior, but it was in gcc documentation */ |
||
351 | int __nesf2(float a, float b) |
||
352 | { |
||
804 | cejka | 353 | return __eqsf2(a, b); |
698 | cejka | 354 | } |
653 | cejka | 355 | |
356 | /* return value >= 0 if a>=b and neither is NaN */ |
||
357 | int __gesf2(float a, float b) |
||
358 | { |
||
804 | cejka | 359 | float32 fa, fb; |
360 | fa.f = a; |
||
361 | fb.f = b; |
||
362 | if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) { |
||
653 | cejka | 363 | /* TODO: sigNaNs*/ |
660 | cejka | 364 | return -1; |
653 | cejka | 365 | }; |
366 | |||
804 | cejka | 367 | if (isFloat32eq(fa, fb)) { |
653 | cejka | 368 | return 0; |
369 | }; |
||
370 | |||
804 | cejka | 371 | if (isFloat32gt(fa, fb)) { |
653 | cejka | 372 | return 1; |
373 | }; |
||
374 | |||
375 | return -1; |
||
376 | } |
||
377 | |||
378 | /** Return negative value, if a<b and neither is NaN*/ |
||
379 | int __ltsf2(float a, float b) |
||
380 | { |
||
804 | cejka | 381 | float32 fa, fb; |
382 | fa.f = a; |
||
383 | fb.f = b; |
||
384 | if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) { |
||
653 | cejka | 385 | /* TODO: sigNaNs*/ |
386 | return 1; |
||
387 | }; |
||
388 | if (isFloat32lt(fa, fb)) { |
||
389 | return -1; |
||
390 | }; |
||
391 | return 0; |
||
392 | } |
||
393 | |||
394 | /* return value <= 0 if a<=b and neither is NaN */ |
||
395 | int __lesf2(float a, float b) |
||
396 | { |
||
804 | cejka | 397 | float32 fa, fb; |
398 | fa.f = a; |
||
399 | fb.f = b; |
||
400 | if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) { |
||
653 | cejka | 401 | /* TODO: sigNaNs*/ |
402 | return 1; |
||
403 | }; |
||
404 | |||
804 | cejka | 405 | if (isFloat32eq(fa, fb)) { |
653 | cejka | 406 | return 0; |
407 | }; |
||
408 | |||
804 | cejka | 409 | if (isFloat32lt(fa, fb)) { |
653 | cejka | 410 | return -1; |
411 | }; |
||
412 | |||
413 | return 1; |
||
414 | } |
||
415 | |||
416 | /** Return positive value, if a>b and neither is NaN*/ |
||
660 | cejka | 417 | int __gtsf2(float a, float b) |
653 | cejka | 418 | { |
804 | cejka | 419 | float32 fa, fb; |
420 | fa.f = a; |
||
421 | fb.f = b; |
||
422 | if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) { |
||
653 | cejka | 423 | /* TODO: sigNaNs*/ |
660 | cejka | 424 | return -1; |
653 | cejka | 425 | }; |
426 | if (isFloat32gt(fa, fb)) { |
||
427 | return 1; |
||
428 | }; |
||
429 | return 0; |
||
430 | } |
||
431 | |||
647 | cejka | 432 | /* Other functions */ |
542 | cejka | 433 | |
698 | cejka | 434 | float __powisf2(float a, int b) |
435 | { |
||
804 | cejka | 436 | /* TODO: */ |
698 | cejka | 437 | } |
438 | |||
439 | float __mulsc3(float a, float b, float c, float d) |
||
440 | { |
||
804 | cejka | 441 | /* TODO: */ |
698 | cejka | 442 | } |
443 | |||
444 | float __divsc3(float a, float b, float c, float d) |
||
445 | { |
||
804 | cejka | 446 | /* TODO: */ |
698 | cejka | 447 | } |
448 |