Skip to content

Commit 8429306

Browse files
committed
target/hexagon: Remove Double
This structure, with bitfields, is incorrect for big-endian. Use extract64 and deposit64 instead. Reviewed-by: Brian Cain <[email protected]> Signed-off-by: Richard Henderson <[email protected]>
1 parent fefc970 commit 8429306

File tree

1 file changed

+17
-31
lines changed

1 file changed

+17
-31
lines changed

target/hexagon/fma_emu.c

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,39 +43,29 @@
4343

4444
#define WAY_BIG_EXP 4096
4545

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-
5646
static uint64_t float64_getmant(float64 f64)
5747
{
58-
Double a = { .i = f64 };
48+
uint64_t mant = extract64(f64, 0, 52);
5949
if (float64_is_normal(f64)) {
60-
return a.mant | 1ULL << 52;
50+
return mant | 1ULL << 52;
6151
}
6252
if (float64_is_zero(f64)) {
6353
return 0;
6454
}
6555
if (float64_is_denormal(f64)) {
66-
return a.mant;
56+
return mant;
6757
}
6858
return ~0ULL;
6959
}
7060

7161
int32_t float64_getexp(float64 f64)
7262
{
73-
Double a = { .i = f64 };
63+
int exp = extract64(f64, 52, 11);
7464
if (float64_is_normal(f64)) {
75-
return a.exp;
65+
return exp;
7666
}
7767
if (float64_is_denormal(f64)) {
78-
return a.exp + 1;
68+
return exp + 1;
7969
}
8070
return -1;
8171
}
@@ -346,6 +336,8 @@ float32 infinite_float32(uint8_t sign)
346336
/* Return a maximum finite value with the requested sign */
347337
static float64 accum_round_float64(Accum a, float_status *fp_status)
348338
{
339+
uint64_t ret;
340+
349341
if ((int128_gethi(a.mant) == 0) && (int128_getlo(a.mant) == 0)
350342
&& ((a.guard | a.round | a.sticky) == 0)) {
351343
/* result zero */
@@ -455,22 +447,16 @@ static float64 accum_round_float64(Accum a, float_status *fp_status)
455447
}
456448
}
457449
/* Underflow? */
458-
if (int128_getlo(a.mant) & (1ULL << DF_MANTBITS)) {
450+
ret = int128_getlo(a.mant);
451+
if (ret & (1ULL << DF_MANTBITS)) {
459452
/* 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;
474460
}
475461

476462
float64 internal_mpyhh(float64 a, float64 b,

0 commit comments

Comments
 (0)