|
43 | 43 |
|
44 | 44 | #define WAY_BIG_EXP 4096
|
45 | 45 |
|
46 |
| -typedef union { |
47 |
| - double f; |
48 |
| - uint64_t i; |
49 |
| - struct { |
50 |
| - uint64_t mant:52; |
51 |
| - uint64_t exp:11; |
52 |
| - uint64_t sign:1; |
53 |
| - }; |
54 |
| -} Double; |
55 |
| - |
56 | 46 | static uint64_t float64_getmant(float64 f64)
|
57 | 47 | {
|
58 |
| - Double a = { .i = f64 }; |
| 48 | + uint64_t mant = extract64(f64, 0, 52); |
59 | 49 | if (float64_is_normal(f64)) {
|
60 |
| - return a.mant | 1ULL << 52; |
| 50 | + return mant | 1ULL << 52; |
61 | 51 | }
|
62 | 52 | if (float64_is_zero(f64)) {
|
63 | 53 | return 0;
|
64 | 54 | }
|
65 | 55 | if (float64_is_denormal(f64)) {
|
66 |
| - return a.mant; |
| 56 | + return mant; |
67 | 57 | }
|
68 | 58 | return ~0ULL;
|
69 | 59 | }
|
70 | 60 |
|
71 | 61 | int32_t float64_getexp(float64 f64)
|
72 | 62 | {
|
73 |
| - Double a = { .i = f64 }; |
| 63 | + int exp = extract64(f64, 52, 11); |
74 | 64 | if (float64_is_normal(f64)) {
|
75 |
| - return a.exp; |
| 65 | + return exp; |
76 | 66 | }
|
77 | 67 | if (float64_is_denormal(f64)) {
|
78 |
| - return a.exp + 1; |
| 68 | + return exp + 1; |
79 | 69 | }
|
80 | 70 | return -1;
|
81 | 71 | }
|
@@ -346,6 +336,8 @@ float32 infinite_float32(uint8_t sign)
|
346 | 336 | /* Return a maximum finite value with the requested sign */
|
347 | 337 | static float64 accum_round_float64(Accum a, float_status *fp_status)
|
348 | 338 | {
|
| 339 | + uint64_t ret; |
| 340 | + |
349 | 341 | if ((int128_gethi(a.mant) == 0) && (int128_getlo(a.mant) == 0)
|
350 | 342 | && ((a.guard | a.round | a.sticky) == 0)) {
|
351 | 343 | /* result zero */
|
@@ -455,22 +447,16 @@ static float64 accum_round_float64(Accum a, float_status *fp_status)
|
455 | 447 | }
|
456 | 448 | }
|
457 | 449 | /* Underflow? */
|
458 |
| - if (int128_getlo(a.mant) & (1ULL << DF_MANTBITS)) { |
| 450 | + ret = int128_getlo(a.mant); |
| 451 | + if (ret & (1ULL << DF_MANTBITS)) { |
459 | 452 | /* Leading one means: No, we're normal. So, we should be done... */
|
460 |
| - Double ret; |
461 |
| - ret.i = 0; |
462 |
| - ret.sign = a.sign; |
463 |
| - ret.exp = a.exp; |
464 |
| - ret.mant = int128_getlo(a.mant); |
465 |
| - return ret.i; |
466 |
| - } |
467 |
| - assert(a.exp == 1); |
468 |
| - Double ret; |
469 |
| - ret.i = 0; |
470 |
| - ret.sign = a.sign; |
471 |
| - ret.exp = 0; |
472 |
| - ret.mant = int128_getlo(a.mant); |
473 |
| - return ret.i; |
| 453 | + ret = deposit64(ret, 52, 11, a.exp); |
| 454 | + } else { |
| 455 | + assert(a.exp == 1); |
| 456 | + ret = deposit64(ret, 52, 11, 0); |
| 457 | + } |
| 458 | + ret = deposit64(ret, 63, 1, a.sign); |
| 459 | + return ret; |
474 | 460 | }
|
475 | 461 |
|
476 | 462 | float64 internal_mpyhh(float64 a, float64 b,
|
|
0 commit comments