source: mainline/softfloat/generic/softfloat.c@ fbd6f81

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fbd6f81 was f37d769, checked in by Josef Cejka <malyzelenyhnus@…>, 19 years ago

Int32 and int64 → double conversions.

  • Property mode set to 100644
File size: 8.0 KB
RevLine 
[211bd8a5]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>
[b5440cf]30#include<sftypes.h>
[12c6f2d]31
32#include<add.h>
33#include<sub.h>
34#include<mul.h>
35#include<div.h>
36
[b5440cf]37#include<conversion.h>
38#include<comparison.h>
39#include<other.h>
[211bd8a5]40
[afffa1e]41#include<arch.h>
42#include<types.h>
43#include<functions.h>
44
[b5440cf]45/* Arithmetic functions */
[e799e3a]46
47float __addsf3(float a, float b)
48{
49 float32 fa, fb;
[1266543]50 fa.f = a;
51 fb.f = b;
52 if (fa.parts.sign != fb.parts.sign) {
[b5440cf]53 if (fa.parts.sign) {
[1266543]54 fa.parts.sign = 0;
55 return subFloat32(fb, fa).f;
[b5440cf]56 };
[1266543]57 fb.parts.sign = 0;
58 return subFloat32(fa, fb).f;
[b5440cf]59 }
[1266543]60 return addFloat32(fa, fb).f;
[56a39dde]61}
[e799e3a]62
[a96c570]63double __adddf3(double a, double b)
64{
65 float64 da, db;
[1266543]66 da.d = a;
67 db.d = b;
68 if (da.parts.sign != db.parts.sign) {
[a96c570]69 if (da.parts.sign) {
[1266543]70 da.parts.sign = 0;
71 return subFloat64(db, da).d;
[a96c570]72 };
[1266543]73 db.parts.sign = 0;
74 return subFloat64(da, db).d;
[a96c570]75 }
[1266543]76 return addFloat64(da, db).d;
[a96c570]77}
78
[e799e3a]79float __subsf3(float a, float b)
80{
81 float32 fa, fb;
[1266543]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;
[b5440cf]87 }
[1266543]88 return subFloat32(fa, fb).f;
[56a39dde]89}
[e799e3a]90
[a96c570]91double __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
[3af72dc]103float __mulsf3(float a, float b)
104{
105 float32 fa, fb;
[1266543]106 fa.f = a;
107 fb.f = b;
[3af72dc]108 return mulFloat32(fa, fb).f;
109}
110
[bff16dd]111double __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
[feef1cd]119float __divsf3(float a, float b)
120{
121 float32 fa, fb;
[1266543]122 fa.f = a;
123 fb.f = b;
124 return divFloat32(fa, fb).f;
[56a39dde]125}
[feef1cd]126
[e6a40ac]127double __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
[e799e3a]135float __negsf2(float a)
136{
137 float32 fa;
[1266543]138 fa.f = a;
139 fa.parts.sign = !fa.parts.sign;
[e799e3a]140 return fa.f;
[56a39dde]141}
[e799e3a]142
143double __negdf2(double a)
144{
145 float64 fa;
[1266543]146 fa.d = a;
147 fa.parts.sign = !fa.parts.sign;
[7afd2aca]148 return fa.d;
[56a39dde]149}
[e799e3a]150
[b5440cf]151/* Conversion functions */
[e799e3a]152
[feef1cd]153double __extendsfdf2(float a)
154{
155 float32 fa;
156 fa.f = a;
157 return convertFloat32ToFloat64(fa).d;
[56a39dde]158}
[feef1cd]159
160float __truncdfsf2(double a)
161{
162 float64 da;
163 da.d = a;
164 return convertFloat64ToFloat32(da).f;
165}
[56a39dde]166
[afffa1e]167int __fixsfsi(float a)
168{
169 float32 fa;
170 fa.f = a;
171
172 return float32_to_int(fa);
173}
174int __fixdfsi(double a)
175{
[a82695c]176 float64 da;
177 da.d = a;
178
179 return float64_to_int(da);
[afffa1e]180}
181
182long __fixsfdi(float a)
183{
184 float32 fa;
185 fa.f = a;
186
187 return float32_to_long(fa);
188}
189long __fixdfdi(double a)
190{
[a82695c]191 float64 da;
192 da.d = a;
193
194 return float64_to_long(da);
[afffa1e]195}
196
197long long __fixsfti(float a)
198{
[a82695c]199 float32 fa;
200 fa.f = a;
201
202 return float32_to_longlong(fa);
[afffa1e]203}
204long long __fixdfti(double a)
205{
[a82695c]206 float64 da;
207 da.d = a;
208
209 return float64_to_longlong(da);
[afffa1e]210}
211
212unsigned int __fixunssfsi(float a)
213{
214 float32 fa;
215 fa.f = a;
216
217 return float32_to_uint(fa);
218}
219unsigned int __fixunsdfsi(double a)
220{
[a82695c]221 float64 da;
222 da.d = a;
223
224 return float64_to_uint(da);
[afffa1e]225}
226
227unsigned long __fixunssfdi(float a)
228{
229 float32 fa;
230 fa.f = a;
231
[2cb202e]232 return float32_to_ulong(fa);
[afffa1e]233}
234unsigned long __fixunsdfdi(double a)
235{
[a82695c]236 float64 da;
237 da.d = a;
238
239 return float64_to_ulong(da);
[afffa1e]240}
241
242unsigned long long __fixunssfti(float a)
243{
[a82695c]244 float32 fa;
245 fa.f = a;
246
247 return float32_to_ulonglong(fa);
[afffa1e]248}
249unsigned long long __fixunsdfti(double a)
250{
[a82695c]251 float64 da;
252 da.d = a;
253
254 return float64_to_ulonglong(da);
[afffa1e]255}
256
257float __floatsisf(int i)
258{
[1d83419]259 float32 fa;
260
261 fa = int_to_float32(i);
262 return fa.f;
[afffa1e]263}
264double __floatsidf(int i)
265{
[f37d769]266 float64 da;
267
268 da = int_to_float64(i);
269 return da.d;
[afffa1e]270}
271
272float __floatdisf(long i)
273{
[1d83419]274 float32 fa;
275
276 fa = long_to_float32(i);
277 return fa.f;
[afffa1e]278}
279double __floatdidf(long i)
280{
[f37d769]281 float64 da;
282
283 da = long_to_float64(i);
284 return da.d;
[afffa1e]285}
286
287float __floattisf(long long i)
288{
[1d83419]289 float32 fa;
290
291 fa = longlong_to_float32(i);
292 return fa.f;
[afffa1e]293}
294double __floattidf(long long i)
295{
[f37d769]296 float64 da;
297
298 da = longlong_to_float64(i);
299 return da.d;
[afffa1e]300}
301
302float __floatunsisf(unsigned int i)
303{
[1d83419]304 float32 fa;
305
306 fa = uint_to_float32(i);
307 return fa.f;
[afffa1e]308}
309double __floatunsidf(unsigned int i)
310{
[f37d769]311 float64 da;
312
313 da = uint_to_float64(i);
314 return da.d;
[afffa1e]315}
316
317float __floatundisf(unsigned long i)
318{
[1d83419]319 float32 fa;
320
321 fa = ulong_to_float32(i);
322 return fa.f;
[afffa1e]323}
324double __floatundidf(unsigned long i)
325{
[f37d769]326 float64 da;
327
328 da = ulong_to_float64(i);
329 return da.d;
[afffa1e]330}
331
332float __floatuntisf(unsigned long long i)
333{
[1d83419]334 float32 fa;
335
336 fa = ulonglong_to_float32(i);
337 return fa.f;
[afffa1e]338}
339double __floatuntidf(unsigned long long i)
340{
[f37d769]341 float64 da;
342
343 da = ulonglong_to_float64(i);
344 return da.d;
[afffa1e]345}
346
347/* Comparison functions */
[b5440cf]348/* Comparison functions */
[e799e3a]349
[7e557805]350/* a<b .. -1
351 * a=b .. 0
352 * a>b .. 1
353 * */
354
[cf4a823]355int __cmpsf2(float a, float b)
[7e557805]356{
[1266543]357 float32 fa, fb;
358 fa.f = a;
359 fb.f = b;
360 if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
[7e557805]361 return 1; /* no special constant for unordered - maybe signaled? */
362 };
363
364
[1266543]365 if (isFloat32eq(fa, fb)) {
[7e557805]366 return 0;
367 };
368
[1266543]369 if (isFloat32lt(fa, fb)) {
[7e557805]370 return -1;
371 };
372 return 1;
373}
374
375int __unordsf2(float a, float b)
376{
[1266543]377 float32 fa, fb;
378 fa.f = a;
379 fb.f = b;
380 return ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) );
[56a39dde]381}
[7e557805]382
383/**
384 * @return zero, if neither argument is a NaN and are equal
385 * */
386int __eqsf2(float a, float b)
387{
[1266543]388 float32 fa, fb;
389 fa.f = a;
390 fb.f = b;
391 if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
[7e557805]392 /* TODO: sigNaNs*/
393 return 1;
394 };
[1266543]395 return isFloat32eq(fa, fb) - 1;
[56a39dde]396}
[7e557805]397
398/* strange behavior, but it was in gcc documentation */
399int __nesf2(float a, float b)
400{
[1266543]401 return __eqsf2(a, b);
[56a39dde]402}
[e649dfa]403
404/* return value >= 0 if a>=b and neither is NaN */
405int __gesf2(float a, float b)
406{
[1266543]407 float32 fa, fb;
408 fa.f = a;
409 fb.f = b;
410 if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
[e649dfa]411 /* TODO: sigNaNs*/
[cf4a823]412 return -1;
[e649dfa]413 };
414
[1266543]415 if (isFloat32eq(fa, fb)) {
[e649dfa]416 return 0;
417 };
418
[1266543]419 if (isFloat32gt(fa, fb)) {
[e649dfa]420 return 1;
421 };
422
423 return -1;
424}
425
426/** Return negative value, if a<b and neither is NaN*/
427int __ltsf2(float a, float b)
428{
[1266543]429 float32 fa, fb;
430 fa.f = a;
431 fb.f = b;
432 if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
[e649dfa]433 /* TODO: sigNaNs*/
434 return 1;
435 };
436 if (isFloat32lt(fa, fb)) {
437 return -1;
438 };
439 return 0;
440}
441
442/* return value <= 0 if a<=b and neither is NaN */
443int __lesf2(float a, float b)
444{
[1266543]445 float32 fa, fb;
446 fa.f = a;
447 fb.f = b;
448 if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
[e649dfa]449 /* TODO: sigNaNs*/
450 return 1;
451 };
452
[1266543]453 if (isFloat32eq(fa, fb)) {
[e649dfa]454 return 0;
455 };
456
[1266543]457 if (isFloat32lt(fa, fb)) {
[e649dfa]458 return -1;
459 };
460
461 return 1;
462}
463
464/** Return positive value, if a>b and neither is NaN*/
[cf4a823]465int __gtsf2(float a, float b)
[e649dfa]466{
[1266543]467 float32 fa, fb;
468 fa.f = a;
469 fb.f = b;
470 if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
[e649dfa]471 /* TODO: sigNaNs*/
[cf4a823]472 return -1;
[e649dfa]473 };
474 if (isFloat32gt(fa, fb)) {
475 return 1;
476 };
477 return 0;
478}
479
[b5440cf]480/* Other functions */
[e799e3a]481
[56a39dde]482float __powisf2(float a, int b)
483{
[1266543]484/* TODO: */
[56a39dde]485}
486
487float __mulsc3(float a, float b, float c, float d)
488{
[1266543]489/* TODO: */
[56a39dde]490}
491
492float __divsc3(float a, float b, float c, float d)
493{
[1266543]494/* TODO: */
[56a39dde]495}
496
Note: See TracBrowser for help on using the repository browser.