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