Finish conversion of float128 and floatx80 to FloatParts.

Implement float128_muladd and float128_{min,max}*.
 Optimize int-to-float conversion with hard-float.
 -----BEGIN PGP SIGNATURE-----
 
 iQFRBAABCgA7FiEEekgeeIaLTbaoWgXAZN846K9+IV8FAmC5ReYdHHJpY2hhcmQu
 aGVuZGVyc29uQGxpbmFyby5vcmcACgkQZN846K9+IV8uVgf/Qp3yz7curVx1TgUG
 BXaCOdgBZqDZXEA90y54AXZ1LqOdUAawJAhtzxnX+Aaqzjb85XEZUpg4YawMpWiP
 1vizTFKfetauG3BRFOvz9DDP01OQHNnIp+eqjsUN3U8Arb++9gw6J9qlXatbl7ce
 AaPjhEFttQSHlKoWNIC8VqAJWsh/njVJeEIFdy7GGhWPIYXyQSTnkyf2HyPlMlj0
 ytnVv57DXD2xcci3nuvOrS57ld6GJaWh3QCYUWlTroVBABd0ZgVAUP3ohz6ScAyp
 B0Ou/m3HUsnTqwG41ynrx3xaIHaMNhuiBBxEX2ITH2Q/Sys/0Px7eIfwdi9P5Bkl
 0ukhOQ==
 =5A1K
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/rth-gitlab/tags/pull-fpu-20210603' into staging

Finish conversion of float128 and floatx80 to FloatParts.
Implement float128_muladd and float128_{min,max}*.
Optimize int-to-float conversion with hard-float.

# gpg: Signature made Thu 03 Jun 2021 22:13:10 BST
# gpg:                using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F
# gpg:                issuer "richard.henderson@linaro.org"
# gpg: Good signature from "Richard Henderson <richard.henderson@linaro.org>" [full]
# Primary key fingerprint: 7A48 1E78 868B 4DB6 A85A  05C0 64DF 38E8 AF7E 215F

* remotes/rth-gitlab/tags/pull-fpu-20210603: (29 commits)
  softfloat: Use hard-float for {u}int64_to_float{32,64}
  tests/fp: Enable more tests
  softfloat: Convert modrem operations to FloatParts
  softfloat: Move floatN_log2 to softfloat-parts.c.inc
  softfloat: Convert float32_exp2 to FloatParts
  softfloat: Convert floatx80 compare to FloatParts
  softfloat: Convert floatx80_scalbn to FloatParts
  softfloat: Convert floatx80 to integer to FloatParts
  softfloat: Convert floatx80 float conversions to FloatParts
  softfloat: Convert integer to floatx80 to FloatParts
  softfloat: Convert floatx80_round_to_int to FloatParts
  softfloat: Convert floatx80_round to FloatParts
  softfloat: Convert floatx80_sqrt to FloatParts
  softfloat: Convert floatx80_div to FloatParts
  softfloat: Convert floatx80_mul to FloatParts
  softfloat: Convert floatx80_add/sub to FloatParts
  tests/fp/fp-test: Reverse order of floatx80 precision tests
  softfloat: Adjust parts_uncanon_normal for floatx80
  softfloat: Introduce Floatx80RoundPrec
  softfloat: Reduce FloatFmt
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2021-06-04 10:04:11 +01:00
commit 5a95f5ce3c
15 changed files with 2249 additions and 3898 deletions

View File

@ -140,20 +140,156 @@ static void partsN(canonicalize)(FloatPartsN *p, float_status *status,
* fraction; these bits will be removed. The exponent will be biased
* by EXP_BIAS and must be bounded by [EXP_MAX-1, 0].
*/
static void partsN(uncanon)(FloatPartsN *p, float_status *s,
const FloatFmt *fmt)
static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s,
const FloatFmt *fmt)
{
const int exp_max = fmt->exp_max;
const int frac_shift = fmt->frac_shift;
const uint64_t frac_lsb = fmt->frac_lsb;
const uint64_t frac_lsbm1 = fmt->frac_lsbm1;
const uint64_t round_mask = fmt->round_mask;
const uint64_t roundeven_mask = fmt->roundeven_mask;
const uint64_t frac_lsb = round_mask + 1;
const uint64_t frac_lsbm1 = round_mask ^ (round_mask >> 1);
const uint64_t roundeven_mask = round_mask | frac_lsb;
uint64_t inc;
bool overflow_norm;
bool overflow_norm = false;
int exp, flags = 0;
if (unlikely(p->cls != float_class_normal)) {
switch (s->float_rounding_mode) {
case float_round_nearest_even:
if (N > 64 && frac_lsb == 0) {
inc = ((p->frac_hi & 1) || (p->frac_lo & round_mask) != frac_lsbm1
? frac_lsbm1 : 0);
} else {
inc = ((p->frac_lo & roundeven_mask) != frac_lsbm1
? frac_lsbm1 : 0);
}
break;
case float_round_ties_away:
inc = frac_lsbm1;
break;
case float_round_to_zero:
overflow_norm = true;
inc = 0;
break;
case float_round_up:
inc = p->sign ? 0 : round_mask;
overflow_norm = p->sign;
break;
case float_round_down:
inc = p->sign ? round_mask : 0;
overflow_norm = !p->sign;
break;
case float_round_to_odd:
overflow_norm = true;
/* fall through */
case float_round_to_odd_inf:
if (N > 64 && frac_lsb == 0) {
inc = p->frac_hi & 1 ? 0 : round_mask;
} else {
inc = p->frac_lo & frac_lsb ? 0 : round_mask;
}
break;
default:
g_assert_not_reached();
}
exp = p->exp + fmt->exp_bias;
if (likely(exp > 0)) {
if (p->frac_lo & round_mask) {
flags |= float_flag_inexact;
if (frac_addi(p, p, inc)) {
frac_shr(p, 1);
p->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
exp++;
}
p->frac_lo &= ~round_mask;
}
if (fmt->arm_althp) {
/* ARM Alt HP eschews Inf and NaN for a wider exponent. */
if (unlikely(exp > exp_max)) {
/* Overflow. Return the maximum normal. */
flags = float_flag_invalid;
exp = exp_max;
frac_allones(p);
p->frac_lo &= ~round_mask;
}
} else if (unlikely(exp >= exp_max)) {
flags |= float_flag_overflow | float_flag_inexact;
if (overflow_norm) {
exp = exp_max - 1;
frac_allones(p);
p->frac_lo &= ~round_mask;
} else {
p->cls = float_class_inf;
exp = exp_max;
frac_clear(p);
}
}
frac_shr(p, frac_shift);
} else if (s->flush_to_zero) {
flags |= float_flag_output_denormal;
p->cls = float_class_zero;
exp = 0;
frac_clear(p);
} else {
bool is_tiny = s->tininess_before_rounding || exp < 0;
if (!is_tiny) {
FloatPartsN discard;
is_tiny = !frac_addi(&discard, p, inc);
}
frac_shrjam(p, 1 - exp);
if (p->frac_lo & round_mask) {
/* Need to recompute round-to-even/round-to-odd. */
switch (s->float_rounding_mode) {
case float_round_nearest_even:
if (N > 64 && frac_lsb == 0) {
inc = ((p->frac_hi & 1) ||
(p->frac_lo & round_mask) != frac_lsbm1
? frac_lsbm1 : 0);
} else {
inc = ((p->frac_lo & roundeven_mask) != frac_lsbm1
? frac_lsbm1 : 0);
}
break;
case float_round_to_odd:
case float_round_to_odd_inf:
if (N > 64 && frac_lsb == 0) {
inc = p->frac_hi & 1 ? 0 : round_mask;
} else {
inc = p->frac_lo & frac_lsb ? 0 : round_mask;
}
break;
default:
break;
}
flags |= float_flag_inexact;
frac_addi(p, p, inc);
p->frac_lo &= ~round_mask;
}
exp = (p->frac_hi & DECOMPOSED_IMPLICIT_BIT) != 0;
frac_shr(p, frac_shift);
if (is_tiny && (flags & float_flag_inexact)) {
flags |= float_flag_underflow;
}
if (exp == 0 && frac_eqz(p)) {
p->cls = float_class_zero;
}
}
p->exp = exp;
float_raise(flags, s);
}
static void partsN(uncanon)(FloatPartsN *p, float_status *s,
const FloatFmt *fmt)
{
if (likely(p->cls == float_class_normal)) {
parts_uncanon_normal(p, s, fmt);
} else {
switch (p->cls) {
case float_class_zero:
p->exp = 0;
@ -175,113 +311,6 @@ static void partsN(uncanon)(FloatPartsN *p, float_status *s,
}
g_assert_not_reached();
}
overflow_norm = false;
switch (s->float_rounding_mode) {
case float_round_nearest_even:
inc = ((p->frac_lo & roundeven_mask) != frac_lsbm1 ? frac_lsbm1 : 0);
break;
case float_round_ties_away:
inc = frac_lsbm1;
break;
case float_round_to_zero:
overflow_norm = true;
inc = 0;
break;
case float_round_up:
inc = p->sign ? 0 : round_mask;
overflow_norm = p->sign;
break;
case float_round_down:
inc = p->sign ? round_mask : 0;
overflow_norm = !p->sign;
break;
case float_round_to_odd:
overflow_norm = true;
/* fall through */
case float_round_to_odd_inf:
inc = p->frac_lo & frac_lsb ? 0 : round_mask;
break;
default:
g_assert_not_reached();
}
exp = p->exp + fmt->exp_bias;
if (likely(exp > 0)) {
if (p->frac_lo & round_mask) {
flags |= float_flag_inexact;
if (frac_addi(p, p, inc)) {
frac_shr(p, 1);
p->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
exp++;
}
}
frac_shr(p, frac_shift);
if (fmt->arm_althp) {
/* ARM Alt HP eschews Inf and NaN for a wider exponent. */
if (unlikely(exp > exp_max)) {
/* Overflow. Return the maximum normal. */
flags = float_flag_invalid;
exp = exp_max;
frac_allones(p);
}
} else if (unlikely(exp >= exp_max)) {
flags |= float_flag_overflow | float_flag_inexact;
if (overflow_norm) {
exp = exp_max - 1;
frac_allones(p);
} else {
p->cls = float_class_inf;
exp = exp_max;
frac_clear(p);
}
}
} else if (s->flush_to_zero) {
flags |= float_flag_output_denormal;
p->cls = float_class_zero;
exp = 0;
frac_clear(p);
} else {
bool is_tiny = s->tininess_before_rounding || exp < 0;
if (!is_tiny) {
FloatPartsN discard;
is_tiny = !frac_addi(&discard, p, inc);
}
frac_shrjam(p, 1 - exp);
if (p->frac_lo & round_mask) {
/* Need to recompute round-to-even/round-to-odd. */
switch (s->float_rounding_mode) {
case float_round_nearest_even:
inc = ((p->frac_lo & roundeven_mask) != frac_lsbm1
? frac_lsbm1 : 0);
break;
case float_round_to_odd:
case float_round_to_odd_inf:
inc = p->frac_lo & frac_lsb ? 0 : round_mask;
break;
default:
break;
}
flags |= float_flag_inexact;
frac_addi(p, p, inc);
}
exp = (p->frac_hi & DECOMPOSED_IMPLICIT_BIT) != 0;
frac_shr(p, frac_shift);
if (is_tiny && (flags & float_flag_inexact)) {
flags |= float_flag_underflow;
}
if (exp == 0 && frac_eqz(p)) {
p->cls = float_class_zero;
}
}
p->exp = exp;
float_raise(flags, s);
}
/*
@ -597,6 +626,246 @@ static FloatPartsN *partsN(div)(FloatPartsN *a, FloatPartsN *b,
return a;
}
/*
* Floating point remainder, per IEC/IEEE, or modulus.
*/
static FloatPartsN *partsN(modrem)(FloatPartsN *a, FloatPartsN *b,
uint64_t *mod_quot, float_status *s)
{
int ab_mask = float_cmask(a->cls) | float_cmask(b->cls);
if (likely(ab_mask == float_cmask_normal)) {
frac_modrem(a, b, mod_quot);
return a;
}
if (mod_quot) {
*mod_quot = 0;
}
/* All the NaN cases */
if (unlikely(ab_mask & float_cmask_anynan)) {
return parts_pick_nan(a, b, s);
}
/* Inf % N; N % 0 */
if (a->cls == float_class_inf || b->cls == float_class_zero) {
float_raise(float_flag_invalid, s);
parts_default_nan(a, s);
return a;
}
/* N % Inf; 0 % N */
g_assert(b->cls == float_class_inf || a->cls == float_class_zero);
return a;
}
/*
* Square Root
*
* The base algorithm is lifted from
* https://git.musl-libc.org/cgit/musl/tree/src/math/sqrtf.c
* https://git.musl-libc.org/cgit/musl/tree/src/math/sqrt.c
* https://git.musl-libc.org/cgit/musl/tree/src/math/sqrtl.c
* and is thus MIT licenced.
*/
static void partsN(sqrt)(FloatPartsN *a, float_status *status,
const FloatFmt *fmt)
{
const uint32_t three32 = 3u << 30;
const uint64_t three64 = 3ull << 62;
uint32_t d32, m32, r32, s32, u32; /* 32-bit computation */
uint64_t d64, m64, r64, s64, u64; /* 64-bit computation */
uint64_t dh, dl, rh, rl, sh, sl, uh, ul; /* 128-bit computation */
uint64_t d0h, d0l, d1h, d1l, d2h, d2l;
uint64_t discard;
bool exp_odd;
size_t index;
if (unlikely(a->cls != float_class_normal)) {
switch (a->cls) {
case float_class_snan:
case float_class_qnan:
parts_return_nan(a, status);
return;
case float_class_zero:
return;
case float_class_inf:
if (unlikely(a->sign)) {
goto d_nan;
}
return;
default:
g_assert_not_reached();
}
}
if (unlikely(a->sign)) {
goto d_nan;
}
/*
* Argument reduction.
* x = 4^e frac; with integer e, and frac in [1, 4)
* m = frac fixed point at bit 62, since we're in base 4.
* If base-2 exponent is odd, exchange that for multiply by 2,
* which results in no shift.
*/
exp_odd = a->exp & 1;
index = extract64(a->frac_hi, 57, 6) | (!exp_odd << 6);
if (!exp_odd) {
frac_shr(a, 1);
}
/*
* Approximate r ~= 1/sqrt(m) and s ~= sqrt(m) when m in [1, 4).
*
* Initial estimate:
* 7-bit lookup table (1-bit exponent and 6-bit significand).
*
* The relative error (e = r0*sqrt(m)-1) of a linear estimate
* (r0 = a*m + b) is |e| < 0.085955 ~ 0x1.6p-4 at best;
* a table lookup is faster and needs one less iteration.
* The 7-bit table gives |e| < 0x1.fdp-9.
*
* A Newton-Raphson iteration for r is
* s = m*r
* d = s*r
* u = 3 - d
* r = r*u/2
*
* Fixed point representations:
* m, s, d, u, three are all 2.30; r is 0.32
*/
m64 = a->frac_hi;
m32 = m64 >> 32;
r32 = rsqrt_tab[index] << 16;
/* |r*sqrt(m) - 1| < 0x1.FDp-9 */
s32 = ((uint64_t)m32 * r32) >> 32;
d32 = ((uint64_t)s32 * r32) >> 32;
u32 = three32 - d32;
if (N == 64) {
/* float64 or smaller */
r32 = ((uint64_t)r32 * u32) >> 31;
/* |r*sqrt(m) - 1| < 0x1.7Bp-16 */
s32 = ((uint64_t)m32 * r32) >> 32;
d32 = ((uint64_t)s32 * r32) >> 32;
u32 = three32 - d32;
if (fmt->frac_size <= 23) {
/* float32 or smaller */
s32 = ((uint64_t)s32 * u32) >> 32; /* 3.29 */
s32 = (s32 - 1) >> 6; /* 9.23 */
/* s < sqrt(m) < s + 0x1.08p-23 */
/* compute nearest rounded result to 2.23 bits */
uint32_t d0 = (m32 << 16) - s32 * s32;
uint32_t d1 = s32 - d0;
uint32_t d2 = d1 + s32 + 1;
s32 += d1 >> 31;
a->frac_hi = (uint64_t)s32 << (64 - 25);
/* increment or decrement for inexact */
if (d2 != 0) {
a->frac_hi += ((int32_t)(d1 ^ d2) < 0 ? -1 : 1);
}
goto done;
}
/* float64 */
r64 = (uint64_t)r32 * u32 * 2;
/* |r*sqrt(m) - 1| < 0x1.37-p29; convert to 64-bit arithmetic */
mul64To128(m64, r64, &s64, &discard);
mul64To128(s64, r64, &d64, &discard);
u64 = three64 - d64;
mul64To128(s64, u64, &s64, &discard); /* 3.61 */
s64 = (s64 - 2) >> 9; /* 12.52 */
/* Compute nearest rounded result */
uint64_t d0 = (m64 << 42) - s64 * s64;
uint64_t d1 = s64 - d0;
uint64_t d2 = d1 + s64 + 1;
s64 += d1 >> 63;
a->frac_hi = s64 << (64 - 54);
/* increment or decrement for inexact */
if (d2 != 0) {
a->frac_hi += ((int64_t)(d1 ^ d2) < 0 ? -1 : 1);
}
goto done;
}
r64 = (uint64_t)r32 * u32 * 2;
/* |r*sqrt(m) - 1| < 0x1.7Bp-16; convert to 64-bit arithmetic */
mul64To128(m64, r64, &s64, &discard);
mul64To128(s64, r64, &d64, &discard);
u64 = three64 - d64;
mul64To128(u64, r64, &r64, &discard);
r64 <<= 1;
/* |r*sqrt(m) - 1| < 0x1.a5p-31 */
mul64To128(m64, r64, &s64, &discard);
mul64To128(s64, r64, &d64, &discard);
u64 = three64 - d64;
mul64To128(u64, r64, &rh, &rl);
add128(rh, rl, rh, rl, &rh, &rl);
/* |r*sqrt(m) - 1| < 0x1.c001p-59; change to 128-bit arithmetic */
mul128To256(a->frac_hi, a->frac_lo, rh, rl, &sh, &sl, &discard, &discard);
mul128To256(sh, sl, rh, rl, &dh, &dl, &discard, &discard);
sub128(three64, 0, dh, dl, &uh, &ul);
mul128To256(uh, ul, sh, sl, &sh, &sl, &discard, &discard); /* 3.125 */
/* -0x1p-116 < s - sqrt(m) < 0x3.8001p-125 */
sub128(sh, sl, 0, 4, &sh, &sl);
shift128Right(sh, sl, 13, &sh, &sl); /* 16.112 */
/* s < sqrt(m) < s + 1ulp */
/* Compute nearest rounded result */
mul64To128(sl, sl, &d0h, &d0l);
d0h += 2 * sh * sl;
sub128(a->frac_lo << 34, 0, d0h, d0l, &d0h, &d0l);
sub128(sh, sl, d0h, d0l, &d1h, &d1l);
add128(sh, sl, 0, 1, &d2h, &d2l);
add128(d2h, d2l, d1h, d1l, &d2h, &d2l);
add128(sh, sl, 0, d1h >> 63, &sh, &sl);
shift128Left(sh, sl, 128 - 114, &sh, &sl);
/* increment or decrement for inexact */
if (d2h | d2l) {
if ((int64_t)(d1h ^ d2h) < 0) {
sub128(sh, sl, 0, 1, &sh, &sl);
} else {
add128(sh, sl, 0, 1, &sh, &sl);
}
}
a->frac_lo = sl;
a->frac_hi = sh;
done:
/* Convert back from base 4 to base 2. */
a->exp >>= 1;
if (!(a->frac_hi & DECOMPOSED_IMPLICIT_BIT)) {
frac_add(a, a, a);
} else {
a->exp += 1;
}
return;
d_nan:
float_raise(float_flag_invalid, status);
parts_default_nan(a, status);
}
/*
* Rounds the floating-point value `a' to an integer, and returns the
* result as a floating-point value. The operation is performed
@ -763,7 +1032,7 @@ static void partsN(round_to_int)(FloatPartsN *a, FloatRoundMode rmode,
* the largest positive integer is returned. Otherwise, if the
* conversion overflows, the largest integer with the same sign as `a'
* is returned.
*/
*/
static int64_t partsN(float_to_sint)(FloatPartsN *p, FloatRoundMode rmode,
int scale, int64_t min, int64_t max,
float_status *s)
@ -817,3 +1086,407 @@ static int64_t partsN(float_to_sint)(FloatPartsN *p, FloatRoundMode rmode,
float_raise(flags, s);
return r;
}
/*
* Returns the result of converting the floating-point value `a' to
* the unsigned integer format. The conversion is performed according
* to the IEC/IEEE Standard for Binary Floating-Point
* Arithmetic---which means in particular that the conversion is
* rounded according to the current rounding mode. If `a' is a NaN,
* the largest unsigned integer is returned. Otherwise, if the
* conversion overflows, the largest unsigned integer is returned. If
* the 'a' is negative, the result is rounded and zero is returned;
* values that do not round to zero will raise the inexact exception
* flag.
*/
static uint64_t partsN(float_to_uint)(FloatPartsN *p, FloatRoundMode rmode,
int scale, uint64_t max, float_status *s)
{
int flags = 0;
uint64_t r;
switch (p->cls) {
case float_class_snan:
case float_class_qnan:
flags = float_flag_invalid;
r = max;
break;
case float_class_inf:
flags = float_flag_invalid;
r = p->sign ? 0 : max;
break;
case float_class_zero:
return 0;
case float_class_normal:
/* TODO: N - 2 is frac_size for rounding; could use input fmt. */
if (parts_round_to_int_normal(p, rmode, scale, N - 2)) {
flags = float_flag_inexact;
if (p->cls == float_class_zero) {
r = 0;
break;
}
}
if (p->sign) {
flags = float_flag_invalid;
r = 0;
} else if (p->exp > DECOMPOSED_BINARY_POINT) {
flags = float_flag_invalid;
r = max;
} else {
r = p->frac_hi >> (DECOMPOSED_BINARY_POINT - p->exp);
if (r > max) {
flags = float_flag_invalid;
r = max;
}
}
break;
default:
g_assert_not_reached();
}
float_raise(flags, s);
return r;
}
/*
* Integer to float conversions
*
* Returns the result of converting the two's complement integer `a'
* to the floating-point format. The conversion is performed according
* to the IEC/IEEE Standard for Binary Floating-Point Arithmetic.
*/
static void partsN(sint_to_float)(FloatPartsN *p, int64_t a,
int scale, float_status *s)
{
uint64_t f = a;
int shift;
memset(p, 0, sizeof(*p));
if (a == 0) {
p->cls = float_class_zero;
return;
}
p->cls = float_class_normal;
if (a < 0) {
f = -f;
p->sign = true;
}
shift = clz64(f);
scale = MIN(MAX(scale, -0x10000), 0x10000);
p->exp = DECOMPOSED_BINARY_POINT - shift + scale;
p->frac_hi = f << shift;
}
/*
* Unsigned Integer to float conversions
*
* Returns the result of converting the unsigned integer `a' to the
* floating-point format. The conversion is performed according to the
* IEC/IEEE Standard for Binary Floating-Point Arithmetic.
*/
static void partsN(uint_to_float)(FloatPartsN *p, uint64_t a,
int scale, float_status *status)
{
memset(p, 0, sizeof(*p));
if (a == 0) {
p->cls = float_class_zero;
} else {
int shift = clz64(a);
scale = MIN(MAX(scale, -0x10000), 0x10000);
p->cls = float_class_normal;
p->exp = DECOMPOSED_BINARY_POINT - shift + scale;
p->frac_hi = a << shift;
}
}
/*
* Float min/max.
*/
static FloatPartsN *partsN(minmax)(FloatPartsN *a, FloatPartsN *b,
float_status *s, int flags)
{
int ab_mask = float_cmask(a->cls) | float_cmask(b->cls);
int a_exp, b_exp, cmp;
if (unlikely(ab_mask & float_cmask_anynan)) {
/*
* For minnum/maxnum, if one operand is a QNaN, and the other
* operand is numerical, then return numerical argument.
*/
if ((flags & minmax_isnum)
&& !(ab_mask & float_cmask_snan)
&& (ab_mask & ~float_cmask_qnan)) {
return is_nan(a->cls) ? b : a;
}
return parts_pick_nan(a, b, s);
}
a_exp = a->exp;
b_exp = b->exp;
if (unlikely(ab_mask != float_cmask_normal)) {
switch (a->cls) {
case float_class_normal:
break;
case float_class_inf:
a_exp = INT16_MAX;
break;
case float_class_zero:
a_exp = INT16_MIN;
break;
default:
g_assert_not_reached();
break;
}
switch (b->cls) {
case float_class_normal:
break;
case float_class_inf:
b_exp = INT16_MAX;
break;
case float_class_zero:
b_exp = INT16_MIN;
break;
default:
g_assert_not_reached();
break;
}
}
/* Compare magnitudes. */
cmp = a_exp - b_exp;
if (cmp == 0) {
cmp = frac_cmp(a, b);
}
/*
* Take the sign into account.
* For ismag, only do this if the magnitudes are equal.
*/
if (!(flags & minmax_ismag) || cmp == 0) {
if (a->sign != b->sign) {
/* For differing signs, the negative operand is less. */
cmp = a->sign ? -1 : 1;
} else if (a->sign) {
/* For two negative operands, invert the magnitude comparison. */
cmp = -cmp;
}
}
if (flags & minmax_ismin) {
cmp = -cmp;
}
return cmp < 0 ? b : a;
}
/*
* Floating point compare
*/
static FloatRelation partsN(compare)(FloatPartsN *a, FloatPartsN *b,
float_status *s, bool is_quiet)
{
int ab_mask = float_cmask(a->cls) | float_cmask(b->cls);
int cmp;
if (likely(ab_mask == float_cmask_normal)) {
if (a->sign != b->sign) {
goto a_sign;
}
if (a->exp != b->exp) {
cmp = a->exp < b->exp ? -1 : 1;
} else {
cmp = frac_cmp(a, b);
}
if (a->sign) {
cmp = -cmp;
}
return cmp;
}
if (unlikely(ab_mask & float_cmask_anynan)) {
if (!is_quiet || (ab_mask & float_cmask_snan)) {
float_raise(float_flag_invalid, s);
}
return float_relation_unordered;
}
if (ab_mask & float_cmask_zero) {
if (ab_mask == float_cmask_zero) {
return float_relation_equal;
} else if (a->cls == float_class_zero) {
goto b_sign;
} else {
goto a_sign;
}
}
if (ab_mask == float_cmask_inf) {
if (a->sign == b->sign) {
return float_relation_equal;
}
} else if (b->cls == float_class_inf) {
goto b_sign;
} else {
g_assert(a->cls == float_class_inf);
}
a_sign:
return a->sign ? float_relation_less : float_relation_greater;
b_sign:
return b->sign ? float_relation_greater : float_relation_less;
}
/*
* Multiply A by 2 raised to the power N.
*/
static void partsN(scalbn)(FloatPartsN *a, int n, float_status *s)
{
switch (a->cls) {
case float_class_snan:
case float_class_qnan:
parts_return_nan(a, s);
break;
case float_class_zero:
case float_class_inf:
break;
case float_class_normal:
a->exp += MIN(MAX(n, -0x10000), 0x10000);
break;
default:
g_assert_not_reached();
}
}
/*
* Return log2(A)
*/
static void partsN(log2)(FloatPartsN *a, float_status *s, const FloatFmt *fmt)
{
uint64_t a0, a1, r, t, ign;
FloatPartsN f;
int i, n, a_exp, f_exp;
if (unlikely(a->cls != float_class_normal)) {
switch (a->cls) {
case float_class_snan:
case float_class_qnan:
parts_return_nan(a, s);
return;
case float_class_zero:
/* log2(0) = -inf */
a->cls = float_class_inf;
a->sign = 1;
return;
case float_class_inf:
if (unlikely(a->sign)) {
goto d_nan;
}
return;
default:
break;
}
g_assert_not_reached();
}
if (unlikely(a->sign)) {
goto d_nan;
}
/* TODO: This algorithm looses bits too quickly for float128. */
g_assert(N == 64);
a_exp = a->exp;
f_exp = -1;
r = 0;
t = DECOMPOSED_IMPLICIT_BIT;
a0 = a->frac_hi;
a1 = 0;
n = fmt->frac_size + 2;
if (unlikely(a_exp == -1)) {
/*
* When a_exp == -1, we're computing the log2 of a value [0.5,1.0).
* When the value is very close to 1.0, there are lots of 1's in
* the msb parts of the fraction. At the end, when we subtract
* this value from -1.0, we can see a catastrophic loss of precision,
* as 0x800..000 - 0x7ff..ffx becomes 0x000..00y, leaving only the
* bits of y in the final result. To minimize this, compute as many
* digits as we can.
* ??? This case needs another algorithm to avoid this.
*/
n = fmt->frac_size * 2 + 2;
/* Don't compute a value overlapping the sticky bit */
n = MIN(n, 62);
}
for (i = 0; i < n; i++) {
if (a1) {
mul128To256(a0, a1, a0, a1, &a0, &a1, &ign, &ign);
} else if (a0 & 0xffffffffull) {
mul64To128(a0, a0, &a0, &a1);
} else if (a0 & ~DECOMPOSED_IMPLICIT_BIT) {
a0 >>= 32;
a0 *= a0;
} else {
goto exact;
}
if (a0 & DECOMPOSED_IMPLICIT_BIT) {
if (unlikely(a_exp == 0 && r == 0)) {
/*
* When a_exp == 0, we're computing the log2 of a value
* [1.0,2.0). When the value is very close to 1.0, there
* are lots of 0's in the msb parts of the fraction.
* We need to compute more digits to produce a correct
* result -- restart at the top of the fraction.
* ??? This is likely to lose precision quickly, as for
* float128; we may need another method.
*/
f_exp -= i;
t = r = DECOMPOSED_IMPLICIT_BIT;
i = 0;
} else {
r |= t;
}
} else {
add128(a0, a1, a0, a1, &a0, &a1);
}
t >>= 1;
}
/* Set sticky for inexact. */
r |= (a1 || a0 & ~DECOMPOSED_IMPLICIT_BIT);
exact:
parts_sint_to_float(a, a_exp, 0, s);
if (r == 0) {
return;
}
memset(&f, 0, sizeof(f));
f.cls = float_class_normal;
f.frac_hi = r;
f.exp = f_exp - frac_normalize(&f);
if (a_exp < 0) {
parts_sub_normal(a, &f);
} else if (a_exp > 0) {
parts_add_normal(a, &f);
} else {
*a = f;
}
return;
d_nan:
float_raise(float_flag_invalid, s);
parts_default_nan(a, s);
}

View File

@ -256,14 +256,6 @@ floatx80 floatx80_default_nan(float_status *status)
const floatx80 floatx80_infinity
= make_floatx80_init(floatx80_infinity_high, floatx80_infinity_low);
/*----------------------------------------------------------------------------
| Internal canonical NaN format.
*----------------------------------------------------------------------------*/
typedef struct {
bool sign;
uint64_t high, low;
} commonNaNT;
/*----------------------------------------------------------------------------
| Returns 1 if the half-precision floating-point value `a' is a quiet
| NaN; otherwise returns 0.
@ -379,46 +371,6 @@ bool float32_is_signaling_nan(float32 a_, float_status *status)
}
}
/*----------------------------------------------------------------------------
| Returns the result of converting the single-precision floating-point NaN
| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid
| exception is raised.
*----------------------------------------------------------------------------*/
static commonNaNT float32ToCommonNaN(float32 a, float_status *status)
{
commonNaNT z;
if (float32_is_signaling_nan(a, status)) {
float_raise(float_flag_invalid, status);
}
z.sign = float32_val(a) >> 31;
z.low = 0;
z.high = ((uint64_t)float32_val(a)) << 41;
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the canonical NaN `a' to the single-
| precision floating-point format.
*----------------------------------------------------------------------------*/
static float32 commonNaNToFloat32(commonNaNT a, float_status *status)
{
uint32_t mantissa = a.high >> 41;
if (status->default_nan_mode) {
return float32_default_nan(status);
}
if (mantissa) {
return make_float32(
(((uint32_t)a.sign) << 31) | 0x7F800000 | (a.high >> 41));
} else {
return float32_default_nan(status);
}
}
/*----------------------------------------------------------------------------
| Select which NaN to propagate for a two-input operation.
| IEEE754 doesn't specify all the details of this, so the
@ -689,62 +641,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls,
#endif
}
/*----------------------------------------------------------------------------
| Takes two single-precision floating-point values `a' and `b', one of which
| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a
| signaling NaN, the invalid exception is raised.
*----------------------------------------------------------------------------*/
static float32 propagateFloat32NaN(float32 a, float32 b, float_status *status)
{
bool aIsLargerSignificand;
uint32_t av, bv;
FloatClass a_cls, b_cls;
/* This is not complete, but is good enough for pickNaN. */
a_cls = (!float32_is_any_nan(a)
? float_class_normal
: float32_is_signaling_nan(a, status)
? float_class_snan
: float_class_qnan);
b_cls = (!float32_is_any_nan(b)
? float_class_normal
: float32_is_signaling_nan(b, status)
? float_class_snan
: float_class_qnan);
av = float32_val(a);
bv = float32_val(b);
if (is_snan(a_cls) || is_snan(b_cls)) {
float_raise(float_flag_invalid, status);
}
if (status->default_nan_mode) {
return float32_default_nan(status);
}
if ((uint32_t)(av << 1) < (uint32_t)(bv << 1)) {
aIsLargerSignificand = 0;
} else if ((uint32_t)(bv << 1) < (uint32_t)(av << 1)) {
aIsLargerSignificand = 1;
} else {
aIsLargerSignificand = (av < bv) ? 1 : 0;
}
if (pickNaN(a_cls, b_cls, aIsLargerSignificand, status)) {
if (is_snan(b_cls)) {
return float32_silence_nan(b, status);
}
return b;
} else {
if (is_snan(a_cls)) {
return float32_silence_nan(a, status);
}
return a;
}
}
/*----------------------------------------------------------------------------
| Returns 1 if the double-precision floating-point value `a' is a quiet
| NaN; otherwise returns 0.
@ -785,104 +681,6 @@ bool float64_is_signaling_nan(float64 a_, float_status *status)
}
}
/*----------------------------------------------------------------------------
| Returns the result of converting the double-precision floating-point NaN
| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid
| exception is raised.
*----------------------------------------------------------------------------*/
static commonNaNT float64ToCommonNaN(float64 a, float_status *status)
{
commonNaNT z;
if (float64_is_signaling_nan(a, status)) {
float_raise(float_flag_invalid, status);
}
z.sign = float64_val(a) >> 63;
z.low = 0;
z.high = float64_val(a) << 12;
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the canonical NaN `a' to the double-
| precision floating-point format.
*----------------------------------------------------------------------------*/
static float64 commonNaNToFloat64(commonNaNT a, float_status *status)
{
uint64_t mantissa = a.high >> 12;
if (status->default_nan_mode) {
return float64_default_nan(status);
}
if (mantissa) {
return make_float64(
(((uint64_t) a.sign) << 63)
| UINT64_C(0x7FF0000000000000)
| (a.high >> 12));
} else {
return float64_default_nan(status);
}
}
/*----------------------------------------------------------------------------
| Takes two double-precision floating-point values `a' and `b', one of which
| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a
| signaling NaN, the invalid exception is raised.
*----------------------------------------------------------------------------*/
static float64 propagateFloat64NaN(float64 a, float64 b, float_status *status)
{
bool aIsLargerSignificand;
uint64_t av, bv;
FloatClass a_cls, b_cls;
/* This is not complete, but is good enough for pickNaN. */
a_cls = (!float64_is_any_nan(a)
? float_class_normal
: float64_is_signaling_nan(a, status)
? float_class_snan
: float_class_qnan);
b_cls = (!float64_is_any_nan(b)
? float_class_normal
: float64_is_signaling_nan(b, status)
? float_class_snan
: float_class_qnan);
av = float64_val(a);
bv = float64_val(b);
if (is_snan(a_cls) || is_snan(b_cls)) {
float_raise(float_flag_invalid, status);
}
if (status->default_nan_mode) {
return float64_default_nan(status);
}
if ((uint64_t)(av << 1) < (uint64_t)(bv << 1)) {
aIsLargerSignificand = 0;
} else if ((uint64_t)(bv << 1) < (uint64_t)(av << 1)) {
aIsLargerSignificand = 1;
} else {
aIsLargerSignificand = (av < bv) ? 1 : 0;
}
if (pickNaN(a_cls, b_cls, aIsLargerSignificand, status)) {
if (is_snan(b_cls)) {
return float64_silence_nan(b, status);
}
return b;
} else {
if (is_snan(a_cls)) {
return float64_silence_nan(a, status);
}
return a;
}
}
/*----------------------------------------------------------------------------
| Returns 1 if the extended double-precision floating-point value `a' is a
| quiet NaN; otherwise returns 0. This slightly differs from the same
@ -946,55 +744,6 @@ floatx80 floatx80_silence_nan(floatx80 a, float_status *status)
return a;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the extended double-precision floating-
| point NaN `a' to the canonical NaN format. If `a' is a signaling NaN, the
| invalid exception is raised.
*----------------------------------------------------------------------------*/
static commonNaNT floatx80ToCommonNaN(floatx80 a, float_status *status)
{
floatx80 dflt;
commonNaNT z;
if (floatx80_is_signaling_nan(a, status)) {
float_raise(float_flag_invalid, status);
}
if (a.low >> 63) {
z.sign = a.high >> 15;
z.low = 0;
z.high = a.low << 1;
} else {
dflt = floatx80_default_nan(status);
z.sign = dflt.high >> 15;
z.low = 0;
z.high = dflt.low << 1;
}
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the canonical NaN `a' to the extended
| double-precision floating-point format.
*----------------------------------------------------------------------------*/
static floatx80 commonNaNToFloatx80(commonNaNT a, float_status *status)
{
floatx80 z;
if (status->default_nan_mode) {
return floatx80_default_nan(status);
}
if (a.high >> 1) {
z.low = UINT64_C(0x8000000000000000) | a.high >> 1;
z.high = (((uint16_t)a.sign) << 15) | 0x7FFF;
} else {
z = floatx80_default_nan(status);
}
return z;
}
/*----------------------------------------------------------------------------
| Takes two extended double-precision floating-point values `a' and `b', one
| of which is a NaN, and returns the appropriate NaN result. If either `a' or
@ -1086,92 +835,3 @@ bool float128_is_signaling_nan(float128 a, float_status *status)
}
}
}
/*----------------------------------------------------------------------------
| Returns the result of converting the quadruple-precision floating-point NaN
| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid
| exception is raised.
*----------------------------------------------------------------------------*/
static commonNaNT float128ToCommonNaN(float128 a, float_status *status)
{
commonNaNT z;
if (float128_is_signaling_nan(a, status)) {
float_raise(float_flag_invalid, status);
}
z.sign = a.high >> 63;
shortShift128Left(a.high, a.low, 16, &z.high, &z.low);
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the canonical NaN `a' to the quadruple-
| precision floating-point format.
*----------------------------------------------------------------------------*/
static float128 commonNaNToFloat128(commonNaNT a, float_status *status)
{
float128 z;
if (status->default_nan_mode) {
return float128_default_nan(status);
}
shift128Right(a.high, a.low, 16, &z.high, &z.low);
z.high |= (((uint64_t)a.sign) << 63) | UINT64_C(0x7FFF000000000000);
return z;
}
/*----------------------------------------------------------------------------
| Takes two quadruple-precision floating-point values `a' and `b', one of
| which is a NaN, and returns the appropriate NaN result. If either `a' or
| `b' is a signaling NaN, the invalid exception is raised.
*----------------------------------------------------------------------------*/
static float128 propagateFloat128NaN(float128 a, float128 b,
float_status *status)
{
bool aIsLargerSignificand;
FloatClass a_cls, b_cls;
/* This is not complete, but is good enough for pickNaN. */
a_cls = (!float128_is_any_nan(a)
? float_class_normal
: float128_is_signaling_nan(a, status)
? float_class_snan
: float_class_qnan);
b_cls = (!float128_is_any_nan(b)
? float_class_normal
: float128_is_signaling_nan(b, status)
? float_class_snan
: float_class_qnan);
if (is_snan(a_cls) || is_snan(b_cls)) {
float_raise(float_flag_invalid, status);
}
if (status->default_nan_mode) {
return float128_default_nan(status);
}
if (lt128(a.high << 1, a.low, b.high << 1, b.low)) {
aIsLargerSignificand = 0;
} else if (lt128(b.high << 1, b.low, a.high << 1, a.low)) {
aIsLargerSignificand = 1;
} else {
aIsLargerSignificand = (a.high < b.high) ? 1 : 0;
}
if (pickNaN(a_cls, b_cls, aIsLargerSignificand, status)) {
if (is_snan(b_cls)) {
return float128_silence_nan(b, status);
}
return b;
} else {
if (is_snan(a_cls)) {
return float128_silence_nan(a, status);
}
return a;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -69,7 +69,7 @@ static inline void set_float_exception_flags(int val, float_status *status)
status->float_exception_flags = val;
}
static inline void set_floatx80_rounding_precision(int val,
static inline void set_floatx80_rounding_precision(FloatX80RoundPrec val,
float_status *status)
{
status->floatx80_rounding_precision = val;
@ -120,7 +120,8 @@ static inline int get_float_exception_flags(float_status *status)
return status->float_exception_flags;
}
static inline int get_floatx80_rounding_precision(float_status *status)
static inline FloatX80RoundPrec
get_floatx80_rounding_precision(float_status *status)
{
return status->floatx80_rounding_precision;
}

View File

@ -745,4 +745,38 @@ static inline bool ne128(uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1)
return a0 != b0 || a1 != b1;
}
/*
* Similarly, comparisons of 192-bit values.
*/
static inline bool eq192(uint64_t a0, uint64_t a1, uint64_t a2,
uint64_t b0, uint64_t b1, uint64_t b2)
{
return ((a0 ^ b0) | (a1 ^ b1) | (a2 ^ b2)) == 0;
}
static inline bool le192(uint64_t a0, uint64_t a1, uint64_t a2,
uint64_t b0, uint64_t b1, uint64_t b2)
{
if (a0 != b0) {
return a0 < b0;
}
if (a1 != b1) {
return a1 < b1;
}
return a2 <= b2;
}
static inline bool lt192(uint64_t a0, uint64_t a1, uint64_t a2,
uint64_t b0, uint64_t b1, uint64_t b2)
{
if (a0 != b0) {
return a0 < b0;
}
if (a1 != b1) {
return a1 < b1;
}
return a2 < b2;
}
#endif

View File

@ -154,6 +154,14 @@ enum {
float_flag_output_denormal = 128
};
/*
* Rounding precision for floatx80.
*/
typedef enum __attribute__((__packed__)) {
floatx80_precision_x,
floatx80_precision_d,
floatx80_precision_s,
} FloatX80RoundPrec;
/*
* Floating Point Status. Individual architectures may maintain
@ -165,7 +173,7 @@ enum {
typedef struct float_status {
FloatRoundMode float_rounding_mode;
uint8_t float_exception_flags;
signed char floatx80_rounding_precision;
FloatX80RoundPrec floatx80_rounding_precision;
bool tininess_before_rounding;
/* should denormalised results go to zero and set the inexact flag? */
bool flush_to_zero;

View File

@ -1152,7 +1152,7 @@ floatx80 propagateFloatx80NaN(floatx80 a, floatx80 b, float_status *status);
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
floatx80 roundAndPackFloatx80(int8_t roundingPrecision, bool zSign,
floatx80 roundAndPackFloatx80(FloatX80RoundPrec roundingPrecision, bool zSign,
int32_t zExp, uint64_t zSig0, uint64_t zSig1,
float_status *status);
@ -1165,7 +1165,7 @@ floatx80 roundAndPackFloatx80(int8_t roundingPrecision, bool zSign,
| normalized.
*----------------------------------------------------------------------------*/
floatx80 normalizeRoundAndPackFloatx80(int8_t roundingPrecision,
floatx80 normalizeRoundAndPackFloatx80(FloatX80RoundPrec roundingPrecision,
bool zSign, int32_t zExp,
uint64_t zSig0, uint64_t zSig1,
float_status *status);
@ -1204,6 +1204,12 @@ float128 float128_rem(float128, float128, float_status *status);
float128 float128_sqrt(float128, float_status *status);
FloatRelation float128_compare(float128, float128, float_status *status);
FloatRelation float128_compare_quiet(float128, float128, float_status *status);
float128 float128_min(float128, float128, float_status *status);
float128 float128_max(float128, float128, float_status *status);
float128 float128_minnum(float128, float128, float_status *status);
float128 float128_maxnum(float128, float128, float_status *status);
float128 float128_minnummag(float128, float128, float_status *status);
float128 float128_maxnummag(float128, float128, float_status *status);
bool float128_is_quiet_nan(float128, float_status *status);
bool float128_is_signaling_nan(float128, float_status *status);
float128 float128_silence_nan(float128, float_status *status);

View File

@ -97,37 +97,38 @@ void SetRoundingMode(const unsigned int opcode)
void SetRoundingPrecision(const unsigned int opcode)
{
int rounding_precision;
FPA11 *fpa11 = GET_FPA11();
FloatX80RoundPrec rounding_precision;
FPA11 *fpa11 = GET_FPA11();
#ifdef MAINTAIN_FPCR
fpa11->fpcr &= ~MASK_ROUNDING_PRECISION;
fpa11->fpcr &= ~MASK_ROUNDING_PRECISION;
#endif
switch (opcode & MASK_ROUNDING_PRECISION)
{
case ROUND_SINGLE:
rounding_precision = 32;
switch (opcode & MASK_ROUNDING_PRECISION) {
case ROUND_SINGLE:
rounding_precision = floatx80_precision_s;
#ifdef MAINTAIN_FPCR
fpa11->fpcr |= ROUND_SINGLE;
fpa11->fpcr |= ROUND_SINGLE;
#endif
break;
break;
case ROUND_DOUBLE:
rounding_precision = 64;
case ROUND_DOUBLE:
rounding_precision = floatx80_precision_d;
#ifdef MAINTAIN_FPCR
fpa11->fpcr |= ROUND_DOUBLE;
fpa11->fpcr |= ROUND_DOUBLE;
#endif
break;
break;
case ROUND_EXTENDED:
rounding_precision = 80;
case ROUND_EXTENDED:
rounding_precision = floatx80_precision_x;
#ifdef MAINTAIN_FPCR
fpa11->fpcr |= ROUND_EXTENDED;
fpa11->fpcr |= ROUND_EXTENDED;
#endif
break;
break;
default: rounding_precision = 80;
}
set_floatx80_rounding_precision(rounding_precision, &fpa11->fp_status);
default:
rounding_precision = floatx80_precision_x;
break;
}
set_floatx80_rounding_precision(rounding_precision, &fpa11->fp_status);
}
/* Emulate the instruction in the opcode. */

View File

@ -673,38 +673,40 @@ uint32_t helper_fnstcw(CPUX86State *env)
void update_fp_status(CPUX86State *env)
{
int rnd_type;
FloatRoundMode rnd_mode;
FloatX80RoundPrec rnd_prec;
/* set rounding mode */
switch (env->fpuc & FPU_RC_MASK) {
default:
case FPU_RC_NEAR:
rnd_type = float_round_nearest_even;
rnd_mode = float_round_nearest_even;
break;
case FPU_RC_DOWN:
rnd_type = float_round_down;
rnd_mode = float_round_down;
break;
case FPU_RC_UP:
rnd_type = float_round_up;
rnd_mode = float_round_up;
break;
case FPU_RC_CHOP:
rnd_type = float_round_to_zero;
rnd_mode = float_round_to_zero;
break;
}
set_float_rounding_mode(rnd_type, &env->fp_status);
set_float_rounding_mode(rnd_mode, &env->fp_status);
switch ((env->fpuc >> 8) & 3) {
case 0:
rnd_type = 32;
rnd_prec = floatx80_precision_s;
break;
case 2:
rnd_type = 64;
rnd_prec = floatx80_precision_d;
break;
case 3:
default:
rnd_type = 80;
rnd_prec = floatx80_precision_x;
break;
}
set_floatx80_rounding_precision(rnd_type, &env->fp_status);
set_floatx80_rounding_precision(rnd_prec, &env->fp_status);
}
void helper_fldcw(CPUX86State *env, uint32_t val)
@ -1074,7 +1076,8 @@ void helper_f2xm1(CPUX86State *env)
&sig2);
/* This result is inexact. */
sig1 |= 1;
ST0 = normalizeRoundAndPackFloatx80(80, sign, exp, sig0, sig1,
ST0 = normalizeRoundAndPackFloatx80(floatx80_precision_x,
sign, exp, sig0, sig1,
&env->fp_status);
}
} else {
@ -1083,9 +1086,10 @@ void helper_f2xm1(CPUX86State *env)
int32_t n, aexp, bexp;
uint64_t asig0, asig1, asig2, bsig0, bsig1;
FloatRoundMode save_mode = env->fp_status.float_rounding_mode;
signed char save_prec = env->fp_status.floatx80_rounding_precision;
FloatX80RoundPrec save_prec =
env->fp_status.floatx80_rounding_precision;
env->fp_status.float_rounding_mode = float_round_nearest_even;
env->fp_status.floatx80_rounding_precision = 80;
env->fp_status.floatx80_rounding_precision = floatx80_precision_x;
/* Find the nearest multiple of 1/32 to the argument. */
tmp = floatx80_scalbn(ST0, 5, &env->fp_status);
@ -1183,7 +1187,8 @@ void helper_f2xm1(CPUX86State *env)
env->fp_status.float_rounding_mode = save_mode;
/* This result is inexact. */
asig1 |= 1;
ST0 = normalizeRoundAndPackFloatx80(80, asign, aexp, asig0, asig1,
ST0 = normalizeRoundAndPackFloatx80(floatx80_precision_x,
asign, aexp, asig0, asig1,
&env->fp_status);
}
@ -1301,8 +1306,9 @@ void helper_fpatan(CPUX86State *env)
* division is exact, the result of fpatan is still inexact
* (and underflowing where appropriate).
*/
signed char save_prec = env->fp_status.floatx80_rounding_precision;
env->fp_status.floatx80_rounding_precision = 80;
FloatX80RoundPrec save_prec =
env->fp_status.floatx80_rounding_precision;
env->fp_status.floatx80_rounding_precision = floatx80_precision_x;
ST1 = floatx80_div(ST1, ST0, &env->fp_status);
env->fp_status.floatx80_rounding_precision = save_prec;
if (!floatx80_is_zero(ST1) &&
@ -1321,7 +1327,8 @@ void helper_fpatan(CPUX86State *env)
if (exp == 0) {
normalizeFloatx80Subnormal(sig, &exp, &sig);
}
ST1 = normalizeRoundAndPackFloatx80(80, sign, exp, sig - 1,
ST1 = normalizeRoundAndPackFloatx80(floatx80_precision_x,
sign, exp, sig - 1,
-1, &env->fp_status);
}
} else {
@ -1377,9 +1384,10 @@ void helper_fpatan(CPUX86State *env)
uint64_t azsig2, azsig3, axsig0, axsig1;
floatx80 x8;
FloatRoundMode save_mode = env->fp_status.float_rounding_mode;
signed char save_prec = env->fp_status.floatx80_rounding_precision;
FloatX80RoundPrec save_prec =
env->fp_status.floatx80_rounding_precision;
env->fp_status.float_rounding_mode = float_round_nearest_even;
env->fp_status.floatx80_rounding_precision = 80;
env->fp_status.floatx80_rounding_precision = floatx80_precision_x;
if (arg0_exp == 0) {
normalizeFloatx80Subnormal(arg0_sig, &arg0_exp, &arg0_sig);
@ -1448,7 +1456,8 @@ void helper_fpatan(CPUX86State *env)
* Split x as x = t + y, where t = n/8 is the nearest
* multiple of 1/8 to x.
*/
x8 = normalizeRoundAndPackFloatx80(80, false, xexp + 3, xsig0,
x8 = normalizeRoundAndPackFloatx80(floatx80_precision_x,
false, xexp + 3, xsig0,
xsig1, &env->fp_status);
n = floatx80_to_int32(x8, &env->fp_status);
if (n == 0) {
@ -1569,7 +1578,7 @@ void helper_fpatan(CPUX86State *env)
/* Compute z^2. */
mul128To256(zsig0, zsig1, zsig0, zsig1,
&z2sig0, &z2sig1, &z2sig2, &z2sig3);
z2 = normalizeRoundAndPackFloatx80(80, false,
z2 = normalizeRoundAndPackFloatx80(floatx80_precision_x, false,
zexp + zexp - 0x3ffe,
z2sig0, z2sig1,
&env->fp_status);
@ -1689,7 +1698,7 @@ void helper_fpatan(CPUX86State *env)
}
/* This result is inexact. */
rsig1 |= 1;
ST1 = normalizeRoundAndPackFloatx80(80, rsign, rexp,
ST1 = normalizeRoundAndPackFloatx80(floatx80_precision_x, rsign, rexp,
rsig0, rsig1, &env->fp_status);
}
@ -1890,7 +1899,8 @@ static void helper_fyl2x_common(CPUX86State *env, floatx80 arg, int32_t *exp,
*/
mul128To256(tsig0, tsig1, tsig0, tsig1,
&t2sig0, &t2sig1, &t2sig2, &t2sig3);
t2 = normalizeRoundAndPackFloatx80(80, false, texp + texp - 0x3ffe,
t2 = normalizeRoundAndPackFloatx80(floatx80_precision_x, false,
texp + texp - 0x3ffe,
t2sig0, t2sig1, &env->fp_status);
/* Compute the lower parts of the polynomial expansion. */
@ -2004,15 +2014,17 @@ void helper_fyl2xp1(CPUX86State *env)
exp += arg1_exp - 0x3ffe;
/* This result is inexact. */
sig1 |= 1;
ST1 = normalizeRoundAndPackFloatx80(80, arg0_sign ^ arg1_sign, exp,
ST1 = normalizeRoundAndPackFloatx80(floatx80_precision_x,
arg0_sign ^ arg1_sign, exp,
sig0, sig1, &env->fp_status);
} else {
int32_t aexp;
uint64_t asig0, asig1, asig2;
FloatRoundMode save_mode = env->fp_status.float_rounding_mode;
signed char save_prec = env->fp_status.floatx80_rounding_precision;
FloatX80RoundPrec save_prec =
env->fp_status.floatx80_rounding_precision;
env->fp_status.float_rounding_mode = float_round_nearest_even;
env->fp_status.floatx80_rounding_precision = 80;
env->fp_status.floatx80_rounding_precision = floatx80_precision_x;
helper_fyl2x_common(env, ST0, &aexp, &asig0, &asig1);
/*
@ -2027,7 +2039,8 @@ void helper_fyl2xp1(CPUX86State *env)
/* This result is inexact. */
asig1 |= 1;
env->fp_status.float_rounding_mode = save_mode;
ST1 = normalizeRoundAndPackFloatx80(80, arg0_sign ^ arg1_sign, aexp,
ST1 = normalizeRoundAndPackFloatx80(floatx80_precision_x,
arg0_sign ^ arg1_sign, aexp,
asig0, asig1, &env->fp_status);
env->fp_status.floatx80_rounding_precision = save_prec;
}
@ -2111,9 +2124,10 @@ void helper_fyl2x(CPUX86State *env)
int32_t int_exp;
floatx80 arg0_m1;
FloatRoundMode save_mode = env->fp_status.float_rounding_mode;
signed char save_prec = env->fp_status.floatx80_rounding_precision;
FloatX80RoundPrec save_prec =
env->fp_status.floatx80_rounding_precision;
env->fp_status.float_rounding_mode = float_round_nearest_even;
env->fp_status.floatx80_rounding_precision = 80;
env->fp_status.floatx80_rounding_precision = floatx80_precision_x;
if (arg0_exp == 0) {
normalizeFloatx80Subnormal(arg0_sig, &arg0_exp, &arg0_sig);
@ -2170,7 +2184,8 @@ void helper_fyl2x(CPUX86State *env)
/* This result is inexact. */
asig1 |= 1;
env->fp_status.float_rounding_mode = save_mode;
ST1 = normalizeRoundAndPackFloatx80(80, asign ^ arg1_sign, aexp,
ST1 = normalizeRoundAndPackFloatx80(floatx80_precision_x,
asign ^ arg1_sign, aexp,
asig0, asig1, &env->fp_status);
}
@ -2252,12 +2267,12 @@ void helper_fscale(CPUX86State *env)
}
} else {
int n;
signed char save = env->fp_status.floatx80_rounding_precision;
FloatX80RoundPrec save = env->fp_status.floatx80_rounding_precision;
uint8_t save_flags = get_float_exception_flags(&env->fp_status);
set_float_exception_flags(0, &env->fp_status);
n = floatx80_to_int32_round_to_zero(ST1, &env->fp_status);
set_float_exception_flags(save_flags, &env->fp_status);
env->fp_status.floatx80_rounding_precision = 80;
env->fp_status.floatx80_rounding_precision = floatx80_precision_x;
ST0 = floatx80_scalbn(ST0, n, &env->fp_status);
env->fp_status.floatx80_rounding_precision = save;
}

View File

@ -94,13 +94,13 @@ static void m68k_restore_precision_mode(CPUM68KState *env)
{
switch (env->fpcr & FPCR_PREC_MASK) {
case FPCR_PREC_X: /* extended */
set_floatx80_rounding_precision(80, &env->fp_status);
set_floatx80_rounding_precision(floatx80_precision_x, &env->fp_status);
break;
case FPCR_PREC_S: /* single */
set_floatx80_rounding_precision(32, &env->fp_status);
set_floatx80_rounding_precision(floatx80_precision_s, &env->fp_status);
break;
case FPCR_PREC_D: /* double */
set_floatx80_rounding_precision(64, &env->fp_status);
set_floatx80_rounding_precision(floatx80_precision_d, &env->fp_status);
break;
case FPCR_PREC_U: /* undefined */
default:
@ -111,9 +111,9 @@ static void m68k_restore_precision_mode(CPUM68KState *env)
static void cf_restore_precision_mode(CPUM68KState *env)
{
if (env->fpcr & FPCR_PREC_S) { /* single */
set_floatx80_rounding_precision(32, &env->fp_status);
set_floatx80_rounding_precision(floatx80_precision_s, &env->fp_status);
} else { /* double */
set_floatx80_rounding_precision(64, &env->fp_status);
set_floatx80_rounding_precision(floatx80_precision_d, &env->fp_status);
}
}
@ -166,8 +166,8 @@ void HELPER(set_fpcr)(CPUM68KState *env, uint32_t val)
#define PREC_BEGIN(prec) \
do { \
int old; \
old = get_floatx80_rounding_precision(&env->fp_status); \
FloatX80RoundPrec old = \
get_floatx80_rounding_precision(&env->fp_status); \
set_floatx80_rounding_precision(prec, &env->fp_status) \
#define PREC_END() \
@ -176,14 +176,14 @@ void HELPER(set_fpcr)(CPUM68KState *env, uint32_t val)
void HELPER(fsround)(CPUM68KState *env, FPReg *res, FPReg *val)
{
PREC_BEGIN(32);
PREC_BEGIN(floatx80_precision_s);
res->d = floatx80_round(val->d, &env->fp_status);
PREC_END();
}
void HELPER(fdround)(CPUM68KState *env, FPReg *res, FPReg *val)
{
PREC_BEGIN(64);
PREC_BEGIN(floatx80_precision_d);
res->d = floatx80_round(val->d, &env->fp_status);
PREC_END();
}
@ -195,14 +195,14 @@ void HELPER(fsqrt)(CPUM68KState *env, FPReg *res, FPReg *val)
void HELPER(fssqrt)(CPUM68KState *env, FPReg *res, FPReg *val)
{
PREC_BEGIN(32);
PREC_BEGIN(floatx80_precision_s);
res->d = floatx80_sqrt(val->d, &env->fp_status);
PREC_END();
}
void HELPER(fdsqrt)(CPUM68KState *env, FPReg *res, FPReg *val)
{
PREC_BEGIN(64);
PREC_BEGIN(floatx80_precision_d);
res->d = floatx80_sqrt(val->d, &env->fp_status);
PREC_END();
}
@ -214,14 +214,14 @@ void HELPER(fabs)(CPUM68KState *env, FPReg *res, FPReg *val)
void HELPER(fsabs)(CPUM68KState *env, FPReg *res, FPReg *val)
{
PREC_BEGIN(32);
PREC_BEGIN(floatx80_precision_s);
res->d = floatx80_round(floatx80_abs(val->d), &env->fp_status);
PREC_END();
}
void HELPER(fdabs)(CPUM68KState *env, FPReg *res, FPReg *val)
{
PREC_BEGIN(64);
PREC_BEGIN(floatx80_precision_d);
res->d = floatx80_round(floatx80_abs(val->d), &env->fp_status);
PREC_END();
}
@ -233,14 +233,14 @@ void HELPER(fneg)(CPUM68KState *env, FPReg *res, FPReg *val)
void HELPER(fsneg)(CPUM68KState *env, FPReg *res, FPReg *val)
{
PREC_BEGIN(32);
PREC_BEGIN(floatx80_precision_s);
res->d = floatx80_round(floatx80_chs(val->d), &env->fp_status);
PREC_END();
}
void HELPER(fdneg)(CPUM68KState *env, FPReg *res, FPReg *val)
{
PREC_BEGIN(64);
PREC_BEGIN(floatx80_precision_d);
res->d = floatx80_round(floatx80_chs(val->d), &env->fp_status);
PREC_END();
}
@ -252,14 +252,14 @@ void HELPER(fadd)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
void HELPER(fsadd)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
{
PREC_BEGIN(32);
PREC_BEGIN(floatx80_precision_s);
res->d = floatx80_add(val0->d, val1->d, &env->fp_status);
PREC_END();
}
void HELPER(fdadd)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
{
PREC_BEGIN(64);
PREC_BEGIN(floatx80_precision_d);
res->d = floatx80_add(val0->d, val1->d, &env->fp_status);
PREC_END();
}
@ -271,14 +271,14 @@ void HELPER(fsub)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
void HELPER(fssub)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
{
PREC_BEGIN(32);
PREC_BEGIN(floatx80_precision_s);
res->d = floatx80_sub(val1->d, val0->d, &env->fp_status);
PREC_END();
}
void HELPER(fdsub)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
{
PREC_BEGIN(64);
PREC_BEGIN(floatx80_precision_d);
res->d = floatx80_sub(val1->d, val0->d, &env->fp_status);
PREC_END();
}
@ -290,14 +290,14 @@ void HELPER(fmul)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
void HELPER(fsmul)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
{
PREC_BEGIN(32);
PREC_BEGIN(floatx80_precision_s);
res->d = floatx80_mul(val0->d, val1->d, &env->fp_status);
PREC_END();
}
void HELPER(fdmul)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
{
PREC_BEGIN(64);
PREC_BEGIN(floatx80_precision_d);
res->d = floatx80_mul(val0->d, val1->d, &env->fp_status);
PREC_END();
}
@ -307,7 +307,7 @@ void HELPER(fsglmul)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
FloatRoundMode rounding_mode = get_float_rounding_mode(&env->fp_status);
floatx80 a, b;
PREC_BEGIN(32);
PREC_BEGIN(floatx80_precision_s);
set_float_rounding_mode(float_round_to_zero, &env->fp_status);
a = floatx80_round(val0->d, &env->fp_status);
b = floatx80_round(val1->d, &env->fp_status);
@ -323,14 +323,14 @@ void HELPER(fdiv)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
void HELPER(fsdiv)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
{
PREC_BEGIN(32);
PREC_BEGIN(floatx80_precision_s);
res->d = floatx80_div(val1->d, val0->d, &env->fp_status);
PREC_END();
}
void HELPER(fddiv)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
{
PREC_BEGIN(64);
PREC_BEGIN(floatx80_precision_d);
res->d = floatx80_div(val1->d, val0->d, &env->fp_status);
PREC_END();
}
@ -340,7 +340,7 @@ void HELPER(fsgldiv)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
FloatRoundMode rounding_mode = get_float_rounding_mode(&env->fp_status);
floatx80 a, b;
PREC_BEGIN(32);
PREC_BEGIN(floatx80_precision_s);
set_float_rounding_mode(float_round_to_zero, &env->fp_status);
a = floatx80_round(val1->d, &env->fp_status);
b = floatx80_round(val0->d, &env->fp_status);

View File

@ -227,7 +227,8 @@ floatx80 floatx80_lognp1(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig, fSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact, j, k;
floatx80 fp0, fp1, fp2, fp3, f, logof2, klog2, saveu;
@ -270,7 +271,7 @@ floatx80 floatx80_lognp1(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
compact = floatx80_make_compact(aExp, aSig);
@ -426,7 +427,8 @@ floatx80 floatx80_logn(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig, fSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact, j, k, adjk;
floatx80 fp0, fp1, fp2, fp3, f, logof2, klog2, saveu;
@ -469,7 +471,7 @@ floatx80 floatx80_logn(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
compact = floatx80_make_compact(aExp, aSig);
@ -594,7 +596,8 @@ floatx80 floatx80_log10(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
floatx80 fp0, fp1;
@ -626,7 +629,7 @@ floatx80 floatx80_log10(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
fp0 = floatx80_logn(a, status);
fp1 = packFloatx80(0, 0x3FFD, UINT64_C(0xDE5BD8A937287195)); /* INV_L10 */
@ -651,7 +654,8 @@ floatx80 floatx80_log2(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
floatx80 fp0, fp1;
@ -686,7 +690,7 @@ floatx80 floatx80_log2(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
if (aSig == one_sig) { /* X is 2^k */
status->float_rounding_mode = user_rnd_mode;
@ -718,7 +722,8 @@ floatx80 floatx80_etox(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact, n, j, k, m, m1;
floatx80 fp0, fp1, fp2, fp3, l2, scale, adjscale;
@ -746,7 +751,7 @@ floatx80 floatx80_etox(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
adjflag = 0;
@ -902,7 +907,8 @@ floatx80 floatx80_twotox(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact, n, j, l, m, m1;
floatx80 fp0, fp1, fp2, fp3, adjfact, fact1, fact2;
@ -929,7 +935,7 @@ floatx80 floatx80_twotox(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
fp0 = a;
@ -1052,7 +1058,8 @@ floatx80 floatx80_tentox(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact, n, j, l, m, m1;
floatx80 fp0, fp1, fp2, fp3, adjfact, fact1, fact2;
@ -1079,7 +1086,7 @@ floatx80 floatx80_tentox(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
fp0 = a;
@ -1207,7 +1214,8 @@ floatx80 floatx80_tan(floatx80 a, float_status *status)
int32_t aExp, xExp;
uint64_t aSig, xSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact, l, n, j;
floatx80 fp0, fp1, fp2, fp3, fp4, fp5, invtwopi, twopi1, twopi2;
@ -1233,7 +1241,7 @@ floatx80 floatx80_tan(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
compact = floatx80_make_compact(aExp, aSig);
@ -1417,7 +1425,8 @@ floatx80 floatx80_sin(floatx80 a, float_status *status)
int32_t aExp, xExp;
uint64_t aSig, xSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact, l, n, j;
floatx80 fp0, fp1, fp2, fp3, fp4, fp5, x, invtwopi, twopi1, twopi2;
@ -1443,7 +1452,7 @@ floatx80 floatx80_sin(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
compact = floatx80_make_compact(aExp, aSig);
@ -1656,7 +1665,8 @@ floatx80 floatx80_cos(floatx80 a, float_status *status)
int32_t aExp, xExp;
uint64_t aSig, xSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact, l, n, j;
floatx80 fp0, fp1, fp2, fp3, fp4, fp5, x, invtwopi, twopi1, twopi2;
@ -1682,7 +1692,7 @@ floatx80 floatx80_cos(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
compact = floatx80_make_compact(aExp, aSig);
@ -1893,7 +1903,8 @@ floatx80 floatx80_atan(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact, tbl_index;
floatx80 fp0, fp1, fp2, fp3, xsave;
@ -1920,7 +1931,7 @@ floatx80 floatx80_atan(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
if (compact < 0x3FFB8000 || compact > 0x4002FFFF) {
/* |X| >= 16 or |X| < 1/16 */
@ -2090,7 +2101,8 @@ floatx80 floatx80_asin(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact;
floatx80 fp0, fp1, fp2, one;
@ -2124,7 +2136,7 @@ floatx80 floatx80_asin(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
one = packFloatx80(0, one_exp, one_sig);
fp0 = a;
@ -2155,7 +2167,8 @@ floatx80 floatx80_acos(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact;
floatx80 fp0, fp1, one;
@ -2193,7 +2206,7 @@ floatx80 floatx80_acos(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
one = packFloatx80(0, one_exp, one_sig);
fp0 = a;
@ -2224,7 +2237,8 @@ floatx80 floatx80_atanh(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact;
floatx80 fp0, fp1, fp2, one;
@ -2257,7 +2271,7 @@ floatx80 floatx80_atanh(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
one = packFloatx80(0, one_exp, one_sig);
fp2 = packFloatx80(aSign, 0x3FFE, one_sig); /* SIGN(X) * (1/2) */
@ -2289,7 +2303,8 @@ floatx80 floatx80_etoxm1(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact, n, j, m, m1;
floatx80 fp0, fp1, fp2, fp3, l2, sc, onebysc;
@ -2316,7 +2331,7 @@ floatx80 floatx80_etoxm1(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
if (aExp >= 0x3FFD) { /* |X| >= 1/4 */
compact = floatx80_make_compact(aExp, aSig);
@ -2541,7 +2556,8 @@ floatx80 floatx80_tanh(floatx80 a, float_status *status)
int32_t aExp, vExp;
uint64_t aSig, vSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact;
floatx80 fp0, fp1;
@ -2565,7 +2581,7 @@ floatx80 floatx80_tanh(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
compact = floatx80_make_compact(aExp, aSig);
@ -2656,7 +2672,8 @@ floatx80 floatx80_sinh(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact;
floatx80 fp0, fp1, fp2;
@ -2681,7 +2698,7 @@ floatx80 floatx80_sinh(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
compact = floatx80_make_compact(aExp, aSig);
@ -2744,7 +2761,8 @@ floatx80 floatx80_cosh(floatx80 a, float_status *status)
int32_t aExp;
uint64_t aSig;
int8_t user_rnd_mode, user_rnd_prec;
FloatRoundMode user_rnd_mode;
FloatX80RoundPrec user_rnd_prec;
int32_t compact;
floatx80 fp0, fp1;
@ -2767,7 +2785,7 @@ floatx80 floatx80_cosh(floatx80 a, float_status *status)
user_rnd_mode = status->float_rounding_mode;
user_rnd_prec = status->floatx80_rounding_precision;
status->float_rounding_mode = float_round_nearest_even;
status->floatx80_rounding_precision = 80;
status->floatx80_rounding_precision = floatx80_precision_x;
compact = floatx80_make_compact(aExp, aSig);

118
tests/fp/fp-test-log2.c Normal file
View File

@ -0,0 +1,118 @@
/*
* fp-test-log2.c - test QEMU's softfloat log2
*
* Copyright (C) 2020, Linaro, Ltd.
*
* License: GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#ifndef HW_POISON_H
#error Must define HW_POISON_H to work around TARGET_* poisoning
#endif
#include "qemu/osdep.h"
#include "qemu/cutils.h"
#include <math.h>
#include "fpu/softfloat.h"
typedef union {
double d;
float64 i;
} ufloat64;
static int errors;
static void compare(ufloat64 test, ufloat64 real, ufloat64 soft, bool exact)
{
int msb;
uint64_t ulp = UINT64_MAX;
if (real.i == soft.i) {
return;
}
msb = 63 - __builtin_clzll(real.i ^ soft.i);
if (msb < 52) {
if (real.i > soft.i) {
ulp = real.i - soft.i;
} else {
ulp = soft.i - real.i;
}
}
/* glibc allows 3 ulp error in its libm-test-ulps; allow 4 here */
if (!exact && ulp <= 4) {
return;
}
printf("test: %016" PRIx64 " %+.13a\n"
" sf: %016" PRIx64 " %+.13a\n"
"libm: %016" PRIx64 " %+.13a\n",
test.i, test.d, soft.i, soft.d, real.i, real.d);
if (msb == 63) {
printf("Error in sign!\n\n");
} else if (msb >= 52) {
printf("Error in exponent: %d\n\n",
(int)(soft.i >> 52) - (int)(real.i >> 52));
} else {
printf("Error in fraction: %" PRIu64 " ulp\n\n", ulp);
}
if (++errors == 20) {
exit(1);
}
}
int main(int ac, char **av)
{
ufloat64 test, real, soft;
float_status qsf = {0};
int i;
set_float_rounding_mode(float_round_nearest_even, &qsf);
test.d = 0.0;
real.d = -__builtin_inf();
soft.i = float64_log2(test.i, &qsf);
compare(test, real, soft, true);
test.d = 1.0;
real.d = 0.0;
soft.i = float64_log2(test.i, &qsf);
compare(test, real, soft, true);
test.d = 2.0;
real.d = 1.0;
soft.i = float64_log2(test.i, &qsf);
compare(test, real, soft, true);
test.d = 4.0;
real.d = 2.0;
soft.i = float64_log2(test.i, &qsf);
compare(test, real, soft, true);
test.d = 0x1p64;
real.d = 64.0;
soft.i = float64_log2(test.i, &qsf);
compare(test, real, soft, true);
test.d = __builtin_inf();
real.d = __builtin_inf();
soft.i = float64_log2(test.i, &qsf);
compare(test, real, soft, true);
for (i = 0; i < 10000; ++i) {
test.d = drand48() + 1.0; /* [1.0, 2.0) */
real.d = log2(test.d);
soft.i = float64_log2(test.i, &qsf);
compare(test, real, soft, false);
test.d = drand48() * 100; /* [0.0, 100) */
real.d = log2(test.d);
soft.i = float64_log2(test.i, &qsf);
compare(test, real, soft, false);
}
return 0;
}

View File

@ -963,18 +963,21 @@ static void QEMU_NORETURN run_test(void)
verCases_usesExact = !!(attrs & FUNC_ARG_EXACT);
for (k = 0; k < 3; k++) {
int prec80 = 32;
FloatX80RoundPrec qsf_prec80 = floatx80_precision_x;
int prec80 = 80;
int l;
if (k == 1) {
prec80 = 64;
qsf_prec80 = floatx80_precision_d;
} else if (k == 2) {
prec80 = 80;
prec80 = 32;
qsf_prec80 = floatx80_precision_s;
}
verCases_roundingPrecision = 0;
slow_extF80_roundingPrecision = prec80;
qsf.floatx80_rounding_precision = prec80;
qsf.floatx80_rounding_precision = qsf_prec80;
if (attrs & FUNC_EFF_ROUNDINGPRECISION) {
verCases_roundingPrecision = prec80;

View File

@ -556,7 +556,9 @@ softfloat_conv_tests = {
'extF80_to_f64 extF80_to_f128 ' +
'f128_to_f16',
'int-to-float': 'i32_to_f16 i64_to_f16 i32_to_f32 i64_to_f32 ' +
'i32_to_f64 i64_to_f64 i32_to_f128 i64_to_f128',
'i32_to_f64 i64_to_f64 ' +
'i32_to_extF80 i64_to_extF80 ' +
'i32_to_f128 i64_to_f128',
'uint-to-float': 'ui32_to_f16 ui64_to_f16 ui32_to_f32 ui64_to_f32 ' +
'ui32_to_f64 ui64_to_f64 ui64_to_f128 ' +
'ui32_to_extF80 ui64_to_extF80',
@ -581,7 +583,7 @@ softfloat_conv_tests = {
'extF80_to_ui64 extF80_to_ui64_r_minMag ' +
'f128_to_ui64 f128_to_ui64_r_minMag',
'round-to-integer': 'f16_roundToInt f32_roundToInt ' +
'f64_roundToInt f128_roundToInt'
'f64_roundToInt extF80_roundToInt f128_roundToInt'
}
softfloat_tests = {
'eq_signaling' : 'compare',
@ -602,24 +604,20 @@ fptest_args = ['-s', '-l', '1']
fptest_rounding_args = ['-r', 'all']
# Conversion Routines:
# FIXME: i32_to_extF80 (broken), i64_to_extF80 (broken)
# extF80_roundToInt (broken)
foreach k, v : softfloat_conv_tests
test('fp-test-' + k, fptest,
args: fptest_args + fptest_rounding_args + v.split(),
suite: ['softfloat', 'softfloat-conv'])
endforeach
# FIXME: extF80_{lt_quiet, rem} (broken),
# extF80_{mulAdd} (missing)
foreach k, v : softfloat_tests
extF80_broken = ['lt_quiet', 'rem'].contains(k)
test('fp-test-' + k, fptest,
args: fptest_args + fptest_rounding_args +
['f16_' + k, 'f32_' + k, 'f64_' + k, 'f128_' + k] +
(extF80_broken ? [] : ['extF80_' + k]),
['f16_' + k, 'f32_' + k, 'f64_' + k, 'f128_' + k, 'extF80_' + k],
suite: ['softfloat', 'softfloat-' + v])
endforeach
# FIXME: extF80_{mulAdd} (missing)
test('fp-test-mulAdd', fptest,
# no fptest_rounding_args
args: fptest_args +
@ -634,3 +632,14 @@ fpbench = executable(
include_directories: [sfinc, include_directories(tfdir)],
c_args: fpcflags,
)
fptestlog2 = executable(
'fp-test-log2',
['fp-test-log2.c', '../../fpu/softfloat.c'],
link_with: [libsoftfloat],
dependencies: [qemuutil],
include_directories: [sfinc],
c_args: fpcflags,
)
test('fp-test-log2', fptestlog2,
suite: ['softfloat', 'softfloat-ops'])

View File

@ -643,7 +643,7 @@ WRAP_CMP80(qemu_extF80M_eq, floatx80_eq_quiet)
WRAP_CMP80(qemu_extF80M_le, floatx80_le)
WRAP_CMP80(qemu_extF80M_lt, floatx80_lt)
WRAP_CMP80(qemu_extF80M_le_quiet, floatx80_le_quiet)
WRAP_CMP80(qemu_extF80M_lt_quiet, floatx80_le_quiet)
WRAP_CMP80(qemu_extF80M_lt_quiet, floatx80_lt_quiet)
#undef WRAP_CMP80
#define WRAP_CMP128(name, func) \