2
* Copyright (c) 2005 Josef Cejka
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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.
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.
29
/** @addtogroup softfloat generic
31
* @brief Architecture independent parts of FPU software emulation library.
45
#include<conversion.h>
46
#include<comparison.h>
51
/* Arithmetic functions */
53
float __addsf3(float a, float b)
58
if (fa.parts.sign != fb.parts.sign) {
61
return subFloat32(fb, fa).f;
64
return subFloat32(fa, fb).f;
66
return addFloat32(fa, fb).f;
69
double __adddf3(double a, double b)
74
if (da.parts.sign != db.parts.sign) {
77
return subFloat64(db, da).d;
80
return subFloat64(da, db).d;
82
return addFloat64(da, db).d;
85
float __subsf3(float a, float b)
90
if (fa.parts.sign != fb.parts.sign) {
91
fb.parts.sign = !fb.parts.sign;
92
return addFloat32(fa, fb).f;
94
return subFloat32(fa, fb).f;
97
double __subdf3(double a, double b)
102
if (da.parts.sign != db.parts.sign) {
103
db.parts.sign = !db.parts.sign;
104
return addFloat64(da, db).d;
106
return subFloat64(da, db).d;
109
float __mulsf3(float a, float b)
114
return mulFloat32(fa, fb).f;
117
double __muldf3(double a, double b)
122
return mulFloat64(da, db).d;
125
float __divsf3(float a, float b)
130
return divFloat32(fa, fb).f;
133
double __divdf3(double a, double b)
138
return divFloat64(da, db).d;
141
float __negsf2(float a)
145
fa.parts.sign = !fa.parts.sign;
149
double __negdf2(double a)
153
fa.parts.sign = !fa.parts.sign;
157
/* Conversion functions */
159
double __extendsfdf2(float a)
163
return convertFloat32ToFloat64(fa).d;
166
float __truncdfsf2(double a)
170
return convertFloat64ToFloat32(da).f;
173
int __fixsfsi(float a)
178
return float32_to_int(fa);
180
int __fixdfsi(double a)
185
return float64_to_int(da);
188
long __fixsfdi(float a)
193
return float32_to_long(fa);
195
long __fixdfdi(double a)
200
return float64_to_long(da);
203
long long __fixsfti(float a)
208
return float32_to_longlong(fa);
210
long long __fixdfti(double a)
215
return float64_to_longlong(da);
218
unsigned int __fixunssfsi(float a)
223
return float32_to_uint(fa);
225
unsigned int __fixunsdfsi(double a)
230
return float64_to_uint(da);
233
unsigned long __fixunssfdi(float a)
238
return float32_to_ulong(fa);
240
unsigned long __fixunsdfdi(double a)
245
return float64_to_ulong(da);
248
unsigned long long __fixunssfti(float a)
253
return float32_to_ulonglong(fa);
255
unsigned long long __fixunsdfti(double a)
260
return float64_to_ulonglong(da);
263
float __floatsisf(int i)
267
fa = int_to_float32(i);
270
double __floatsidf(int i)
274
da = int_to_float64(i);
278
float __floatdisf(long i)
282
fa = long_to_float32(i);
285
double __floatdidf(long i)
289
da = long_to_float64(i);
293
float __floattisf(long long i)
297
fa = longlong_to_float32(i);
300
double __floattidf(long long i)
304
da = longlong_to_float64(i);
308
float __floatunsisf(unsigned int i)
312
fa = uint_to_float32(i);
315
double __floatunsidf(unsigned int i)
319
da = uint_to_float64(i);
323
float __floatundisf(unsigned long i)
327
fa = ulong_to_float32(i);
330
double __floatundidf(unsigned long i)
334
da = ulong_to_float64(i);
338
float __floatuntisf(unsigned long long i)
342
fa = ulonglong_to_float32(i);
345
double __floatuntidf(unsigned long long i)
349
da = ulonglong_to_float64(i);
353
/* Comparison functions */
354
/* Comparison functions */
361
int __cmpsf2(float a, float b)
366
if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
367
return 1; /* no special constant for unordered - maybe signaled? */
371
if (isFloat32eq(fa, fb)) {
375
if (isFloat32lt(fa, fb)) {
381
int __unordsf2(float a, float b)
386
return ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) );
390
* @return zero, if neither argument is a NaN and are equal
392
int __eqsf2(float a, float b)
397
if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
401
return isFloat32eq(fa, fb) - 1;
404
/* strange behavior, but it was in gcc documentation */
405
int __nesf2(float a, float b)
407
return __eqsf2(a, b);
410
/* return value >= 0 if a>=b and neither is NaN */
411
int __gesf2(float a, float b)
416
if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
421
if (isFloat32eq(fa, fb)) {
425
if (isFloat32gt(fa, fb)) {
432
/** Return negative value, if a<b and neither is NaN*/
433
int __ltsf2(float a, float b)
438
if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
442
if (isFloat32lt(fa, fb)) {
448
/* return value <= 0 if a<=b and neither is NaN */
449
int __lesf2(float a, float b)
454
if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
459
if (isFloat32eq(fa, fb)) {
463
if (isFloat32lt(fa, fb)) {
470
/** Return positive value, if a>b and neither is NaN*/
471
int __gtsf2(float a, float b)
476
if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
480
if (isFloat32gt(fa, fb)) {
486
/* Other functions */
488
float __powisf2(float a, int b)
492
fa.binary = FLOAT32_NAN;