fpu: Remove pickNaNMulAdd, default-NaN ifdefs
v2 cover fpu: Remove pickNaNMulAdd, default-NaN ifdefs
(Apologies for this patchset being both big and having a wide CC list; the good news is that this is the last lot of fpu ifdef cleanup that needs to touch all the targets.)
This patchset does the same thing we already did for pickNaN() to pickNaNMulAdd() -- it replaces the compile-time ifdef ladder that selected target-specific NaN propagation behaviour with checking some runtime selectable settings in the float_status. The motivation is:
* this will let us have multiple targets in one QEMU binary
* the Arm FEAT_AFP architectural feature includes letting the guest select a NaN propagation rule at runtime
This is patches 1-26 (which were in the v1 of this series).
It then does a similar thing for making targets select the default NaN value at runtime rather than relying on a compile-time ifdef. This is patches 34-54, which are new in v2.
In between those two, patches 27-33 do some minor cleanup:
* prefer to initialize scratch float_status structs from the target's env->fp_status rather than as all-zeroes, so that when we add new config fields to float_status we don't need to also remember to update half a dozen scratch float_status structs too. (Some still remain in target/riscv where plumbing in the env pointer through the macro magic seemed more effort than it was worth.)
* remove an ifdef in floatx80_default_nan() by creating the NaN value from parts64_default_nan() in the same way we already do for the 128-bit NaN
This is intended to be a no-behaviour-change refactor, except for:
* the arm linux-user nwfpe handling will change its floatx80 default NaN value
* hppa, i386, sh4, tricore now correctly raise Invalid for (0 * inf) + NaN
Changes v1->v2:
* update comments on x86 to include the spec references rather than TODO notes to check the spec
* fixed clash of float_infzeronan_none and float_infzeronan_dnan_never values
* patches 14 and 27-54 are new
* patch 15 is a rework of the old patch 14 to follow RTH's suggestion to make it data driven rather than a big switch statement
(The remaining ifdefs in fpu/ fall into two categories:
* ones done purely for performance to skip a runtime check, which can be removed without any behaviour change, like the one in snan_bit_is_one()
* various ones related to floatx80 behaviour, where currently we use ifdefs to select essentially i386 vs m68k handling
I'll probably come back and look at these when this series has gone upstream.)
thanks
-- PMM
Peter Maydell (54):
fpu: handle raising Invalid for infzero in pick_nan_muladd
fpu: Check for default_nan_mode before calling pickNaNMulAdd
softfloat: Allow runtime choice of inf * 0 + NaN result tests/fp: Explicitly set inf-zero-nan rule
target/arm: Set FloatInfZeroNaNRule explicitly target/s390: Set FloatInfZeroNaNRule explicitly target/ppc: Set FloatInfZeroNaNRule explicitly target/mips: Set FloatInfZeroNaNRule explicitly target/sparc: Set FloatInfZeroNaNRule explicitly target/xtensa: Set FloatInfZeroNaNRule explicitly target/x86: Set FloatInfZeroNaNRule explicitly target/loongarch: Set FloatInfZeroNaNRule explicitly target/hppa: Set FloatInfZeroNaNRule explicitly
softfloat: Pass have_snan to pickNaNMulAdd
softfloat: Allow runtime choice of NaN propagation for muladd tests/fp: Explicitly set 3-NaN propagation rule target/arm: Set Float3NaNPropRule explicitly target/loongarch: Set Float3NaNPropRule explicitly target/ppc: Set Float3NaNPropRule explicitly target/s390x: Set Float3NaNPropRule explicitly target/sparc: Set Float3NaNPropRule explicitly target/mips: Set Float3NaNPropRule explicitly target/xtensa: Set Float3NaNPropRule explicitly target/i386: Set Float3NaNPropRule explicitly target/hppa: Set Float3NaNPropRule explicitly
fpu: Remove use_first_nan field from float_status target/m68k: Don't pass NULL float_status to floatx80_default_nan()
softfloat: Create floatx80 default NaN from parts64_default_nan target/loongarch: Use normal float_status in fclass_s and fclass_d
helpers
target/m68k: In frem helper, initialize local float_status from
env->fp_status
target/m68k: Init local float_status from env fp_status in gdb get/set
reg
target/sparc: Initialize local scratch float_status from
env->fp_status target/ppc: Use env->fp_status in helper_compute_fprf functions
fpu: Allow runtime choice of default NaN value tests/fp: Set default NaN pattern explicitly target/microblaze: Set default NaN pattern explicitly target/i386: Set default NaN pattern explicitly target/hppa: Set default NaN pattern explicitly target/alpha: Set default NaN pattern explicitly target/arm: Set default NaN pattern explicitly target/loongarch: Set default NaN pattern explicitly target/m68k: Set default NaN pattern explicitly target/mips: Set default NaN pattern explicitly target/openrisc: Set default NaN pattern explicitly target/ppc: Set default NaN pattern explicitly target/sh4: Set default NaN pattern explicitly target/rx: Set default NaN pattern explicitly target/s390x: Set default NaN pattern explicitly target/sparc: Set default NaN pattern explicitly target/xtensa: Set default NaN pattern explicitly target/hexagon: Set default NaN pattern explicitly target/riscv: Set default NaN pattern explicitly target/tricore: Set default NaN pattern explicitly
fpu: Remove default handling for dnan_pattern
include/fpu/softfloat-helpers.h | 38 +++- include/fpu/softfloat-types.h | 89 +++++++++- target/mips/fpu_helper.h | 20 +++ target/sparc/helper.h | 4 +- linux-user/arm/nwfpe/fpa11.c | 5 + target/alpha/cpu.c | 2 + target/arm/cpu.c | 10 ++ target/hexagon/cpu.c | 2 + target/hppa/fpu_helper.c | 12 ++ target/i386/tcg/fpu_helper.c | 12 ++ target/loongarch/tcg/fpu_helper.c | 14 +- target/m68k/cpu.c | 14 +- target/m68k/fpu_helper.c | 6 +- target/m68k/helper.c | 6 +- target/microblaze/cpu.c | 2 + target/mips/msa.c | 10 ++ target/openrisc/cpu.c | 2 + target/ppc/cpu_init.c | 19 ++ target/ppc/fpu_helper.c | 3 +- target/riscv/cpu.c | 2 + target/rx/cpu.c | 2 + target/s390x/cpu.c | 5 + target/sh4/cpu.c | 2 + target/sparc/cpu.c | 6 + target/sparc/fop_helper.c | 8 +- target/sparc/translate.c | 4 +- target/tricore/helper.c | 2 + target/xtensa/cpu.c | 4 + target/xtensa/fpu_helper.c | 3 +- tests/fp/fp-bench.c | 7 + tests/fp/fp-test-log2.c | 1 + tests/fp/fp-test.c | 7 + fpu/softfloat-parts.c.inc | 22 ++- fpu/softfloat-specialize.c.inc | 278 ++++++------------------------ 34 files changed, 357 insertions(+), 266 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/54 fpu: handle raising Invalid for infzero in pick_nan_muladd
For IEEE fused multiply-add, the (0 * inf) + NaN case should raise Invalid for the multiplication of 0 by infinity. Currently we handle this in the per-architecture ifdef ladder in pickNaNMulAdd(). However, since this isn't really architecture specific we can hoist it up to the generic code.
For the cases where the infzero test in pickNaNMulAdd was returning 2, we can delete the check entirely and allow the code to fall into the normal pick-a-NaN handling, because this will return 2 anyway (input 'c' being the only NaN in this case). For the cases where infzero was returning 3 to indicate "return the default NaN", we must retain that "return 3".
For Arm, this looks like it might be a behaviour change because we used to set float_flag_invalid | float_flag_invalid_imz only if C is a quiet NaN. However, it is not, because Arm target code never looks at float_flag_invalid_imz, and for the (0 * inf) + SNaN case we already raised float_flag_invalid via the "abc_mask & float_cmask_snan" check in pick_nan_muladd.
For any target architecture using the "default implementation" at the bottom of the ifdef, this is a behaviour change but will be fixing a bug (where we failed to raise the Invalid exception for (0 * inf + QNaN). The architectures using the default case are:
* hppa
* i386
* sh4
* tricore
The x86, Tricore and SH4 CPU architecture manuals are clear that this should have raised Invalid; HPPA is a bit vaguer but still seems clear enough.
--- fpu/softfloat-parts.c.inc | 13 +++++++------ fpu/softfloat-specialize.c.inc | 29 +---------------------------- 2 files changed, 8 insertions(+), 34 deletions(-)
fpu/softfloat-parts.c.inc +7 -6
@@ -66,19 +66,20 @@ static FloatPartsN *partsN(pick_nan_muladd)(FloatPartsN *a, FloatPartsN *b, int ab_mask, int abc_mask) { int which; + bool infzero = (ab_mask == float_cmask_infzero); if (unlikely(abc_mask & float_cmask_snan)) { float_raise(float_flag_invalid | float_flag_invalid_snan, s); } - which = pickNaNMulAdd(a->cls, b->cls, c->cls, - ab_mask == float_cmask_infzero, s); + if (infzero) { + /* This is (0 * inf) + NaN or (inf * 0) + NaN */ + float_raise(float_flag_invalid | float_flag_invalid_imz, s); + } + + which = pickNaNMulAdd(a->cls, b->cls, c->cls, infzero, s); if (s->default_nan_mode || which == 3) { - /* - * Note that this check is after pickNaNMulAdd so that function - * has an opportunity to set the Invalid flag for infzero. - */ parts_default_nan(a, s); return a; }
fpu/softfloat-specialize.c.inc +1 -28
@@ -480,7 +480,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, * the default NaN */ if (infzero && is_qnan(c_cls)) { - float_raise(float_flag_invalid | float_flag_invalid_imz, status); return 3; }
@@ -507,7 +506,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, * case sets InvalidOp and returns the default NaN */ if (infzero) { - float_raise(float_flag_invalid | float_flag_invalid_imz, status); return 3; } /* Prefer sNaN over qNaN, in the a, b, c order. */
@@ -529,10 +527,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, * For MIPS systems that conform to IEEE754-2008, the (inf,zero,nan) * case sets InvalidOp and returns the input value 'c' */ - if (infzero) { - float_raise(float_flag_invalid | float_flag_invalid_imz, status); - return 2; - } /* Prefer sNaN over qNaN, in the c, a, b order. */ if (is_snan(c_cls)) { return 2;
@@ -553,10 +547,7 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, * For LoongArch systems that conform to IEEE754-2008, the (inf,zero,nan) * case sets InvalidOp and returns the input value 'c' */ - if (infzero) { - float_raise(float_flag_invalid | float_flag_invalid_imz, status); - return 2; - } + /* Prefer sNaN over qNaN, in the c, a, b order. */ if (is_snan(c_cls)) { return 2;
@@ -576,10 +567,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, * to return an input NaN if we have one (ie c) rather than generating * a default NaN */ - if (infzero) { - float_raise(float_flag_invalid | float_flag_invalid_imz, status); - return 2; - } /* If fRA is a NaN return it; otherwise if fRB is a NaN return it; * otherwise return fRC. Note that muladd on PPC is (fRA * fRC) + frB
@@ -592,14 +579,9 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, return 1; } #elif defined(TARGET_RISCV) - /* For RISC-V, InvalidOp is set when multiplicands are Inf and zero */ - if (infzero) { - float_raise(float_flag_invalid | float_flag_invalid_imz, status); - } return 3; /* default NaN */ #elif defined(TARGET_S390X) if (infzero) { - float_raise(float_flag_invalid | float_flag_invalid_imz, status); return 3; }
@@ -617,11 +599,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, return 2; } #elif defined(TARGET_SPARC) - /* For (inf,0,nan) return c. */ - if (infzero) { - float_raise(float_flag_invalid | float_flag_invalid_imz, status); - return 2; - } /* Prefer SNaN over QNaN, order C, B, A. */ if (is_snan(c_cls)) { return 2;
@@ -641,10 +618,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, * For Xtensa, the (inf,zero,nan) case sets InvalidOp and returns * an input NaN if we have one (ie c). */ - if (infzero) { - float_raise(float_flag_invalid | float_flag_invalid_imz, status); - return 2; - } if (status->use_first_nan) { if (is_nan(a_cls)) { return 0;
Signature · 1 line
2.34.1
PATCH v2 2/54 fpu: Check for default_nan_mode before calling pickNaNMulAdd
In reply to Peter MaydellIf the target sets default_nan_mode then we're always going to return the default NaN, and pickNaNMulAdd() no longer has any side effects. For consistency with pickNaN(), check for default_nan_mode before calling pickNaNMulAdd().
When we convert pickNaNMulAdd() to allow runtime selection of the NaN propagation rule, this means we won't have to make the targets which use default_nan_mode also set a propagation rule.
Since RiscV always uses default_nan_mode, this allows us to remove its ifdef case from pickNaNMulAdd().
--- fpu/softfloat-parts.c.inc | 8 ++++++-- fpu/softfloat-specialize.c.inc | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-)
fpu/softfloat-parts.c.inc +6 -2
@@ -77,9 +77,13 @@ static FloatPartsN *partsN(pick_nan_muladd)(FloatPartsN *a, FloatPartsN *b, float_raise(float_flag_invalid | float_flag_invalid_imz, s); } - which = pickNaNMulAdd(a->cls, b->cls, c->cls, infzero, s); + if (s->default_nan_mode) { + which = 3; + } else { + which = pickNaNMulAdd(a->cls, b->cls, c->cls, infzero, s); + } - if (s->default_nan_mode || which == 3) { + if (which == 3) { parts_default_nan(a, s); return a; }
fpu/softfloat-specialize.c.inc +7 -2
@@ -475,6 +475,13 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls, static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, bool infzero, float_status *status) { + /* + * We guarantee not to require the target to tell us how to + * pick a NaN if we're always returning the default NaN. + * But if we're not in default-NaN mode then the target must + * specify. + */ + assert(!status->default_nan_mode); #if defined(TARGET_ARM) /* For ARM, the (inf,zero,qnan) case sets InvalidOp and returns * the default NaN
@@ -578,8 +585,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, } else { return 1; } -#elif defined(TARGET_RISCV) - return 3; /* default NaN */ #elif defined(TARGET_S390X) if (infzero) { return 3;
Signature · 1 line
2.34.1
PATCH v2 3/54 softfloat: Allow runtime choice of inf * 0 + NaN result
In reply to Peter MaydellIEEE 758 does not define a fixed rule for what NaN to return in the case of a fused multiply-add of inf * 0 + NaN. Different architectures thus do different things:
* some return the default NaN
* some return the input NaN
* Arm returns the default NaN if the input NaN is quiet, and the input NaN if it is signalling
We want to make this logic be runtime selected rather than hardcoded into the binary, because:
* this will let us have multiple targets in one QEMU binary
* the Arm FEAT_AFP architectural feature includes letting the guest select a NaN propagation rule at runtime
In this commit we add an enum for the propagation rule, the field in float_status, and the corresponding getters and setters. We change pickNaNMulAdd to honour this, but because all targets still leave this field at its default 0 value, the fallback logic will pick the rule type with the old ifdef ladder.
Note that four architectures both use the muladd softfloat functions and did not have a branch of the ifdef ladder to specify their behaviour (and so were ending up with the "default" case, probably wrongly): i386, HPPA, SH4 and Tricore. SH4 and Tricore both set default_nan_mode, and so will never get into pickNaNMulAdd(). For HPPA and i386 we retain the same behaviour as the old default-case, which is to not ever return the default NaN. This might not be correct but it is not a behaviour change.
---v1->v2: float_infzeronan_dnan_never shouldn't be the same
value as float_infzeronan_none
--- include/fpu/softfloat-helpers.h | 11 ++++ include/fpu/softfloat-types.h | 23 +++++++++ fpu/softfloat-specialize.c.inc | 91 ++++++++++++++++++++++----------- 3 files changed, 95 insertions(+), 30 deletions(-)
include/fpu/softfloat-helpers.h +11 -0
@@ -81,6 +81,12 @@ static inline void set_float_2nan_prop_rule(Float2NaNPropRule rule, status->float_2nan_prop_rule = rule; } +static inline void set_float_infzeronan_rule (FloatInfZeroNaNRule rule, +float_status *status) +{ + status->float_infzeronan_rule = rule; +} +static inline void set_flush_to_zero (bool val,float_status *status) { status->flush_to_zero = val;
@@ -137,6 +143,11 @@ static inline Float2NaNPropRule get_float_2nan_prop_rule(float_status *status)return status->float_2nan_prop_rule; } +static inline FloatInfZeroNaNRule get_float_infzeronan_rule (float_status *status) +{ +return status->float_infzeronan_rule; +} +static inline bool get_flush_to_zero (float_status *status) {return status->flush_to_zero;
include/fpu/softfloat-types.h +23 -0
@@ -207,6 +207,28 @@ typedef enum __attribute__((__packed__)) { float_2nan_prop_x87, } Float2NaNPropRule; +/* +* Rule for result of fused multiply-add 0 * Inf + NaN. +* This must be a NaN, but implementations differ on whether this +* is the input NaN or the default NaN. +* +* You don't need to set this if default_nan_mode is enabled. +* When not in default-NaN mode, it is an error for the target +* not to set the rule in float_status if it uses muladd, and we +* will assert if we need to handle an input NaN and no rule was +* selected. +*/ +typedef enum __attribute__((__packed__)) { +/* No propagation rule specified */ + float_infzeronan_none =0 , +/* Result is never the default NaN (so always the input NaN) */ + float_infzeronan_dnan_never, +/* Result is always the default NaN */ + float_infzeronan_dnan_always, +/* Result is the default NaN if the input NaN is quiet */ + float_infzeronan_dnan_if_qnan, +} FloatInfZeroNaNRule; +/* * Floating Point Status. Individual architectures may maintain * several versions of float_status for different functions. The
@@ -219,6 +241,7 @@ typedef struct float_status {FloatRoundMode float_rounding_mode;FloatX80RoundPrec floatx80_rounding_precision;Float2NaNPropRule float_2nan_prop_rule; +FloatInfZeroNaNRule float_infzeronan_rule;bool tininess_before_rounding;/* should denormalised results go to zero and set the inexact flag? */ bool flush_to_zero;
fpu/softfloat-specialize.c.inc +61 -30
136 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 4/54 tests/fp: Explicitly set inf-zero-nan rule
In reply to Peter MaydellExplicitly set a rule in the softfloat tests for the inf-zero-nan muladd special case. In meson.build we put -DTARGET_ARM in fpcflags, and so we should select here the Arm rule of float_infzeronan_dnan_if_qnan.
--- tests/fp/fp-bench.c | 5 +++++ tests/fp/fp-test.c | 5 +++++ 2 files changed, 10 insertions(+)
tests/fp/fp-bench.c +5 -0
@@ -488,7 +488,12 @@ static void run_bench(void) {bench_func_t f; +/* +* These implementation-defined choices for various things IEEE +* doesn't specify match those used by the Arm architecture. +*/ set_float_2nan_prop_rule (float_2nan_prop_s_ab, &soft_status); +set_float_infzeronan_rule (float_infzeronan_dnan_if_qnan, &soft_status); f = bench_funcs[operation][precision];g_assert (f);
tests/fp/fp-test.c +5 -0
@@ -935,7 +935,12 @@ void run_test(void) {unsigned int i; +/* +* These implementation-defined choices for various things IEEE +* doesn't specify match those used by the Arm architecture. +*/ set_float_2nan_prop_rule (float_2nan_prop_s_ab, &qsf); +set_float_infzeronan_rule (float_infzeronan_dnan_if_qnan, &qsf);genCases_setLevel (test_level); verCases_maxErrorCount = n_max_errors;
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 04/54] tests/fp: Explicitly set inf-zero-nan rule
Quoted 10 lines · Peter Maydell
Explicitly set a rule in the softfloat tests for the inf-zero-nan muladd special case. In meson.build we put -DTARGET_ARM in fpcflags, and so we should select here the Arm rule of
float_infzeronan_dnan_if_qnan.Reviewed-by Richard Henderson <[email protected]>--- tests/fp/fp-bench.c | 5 +++++ tests/fp/fp-test.c | 5 +++++ 2 files changed, 10 insertions(+)
Lost your SoB.
r~
Re: [PATCH v2 for-10.0 04/54] tests/fp: Explicitly set inf-zero-nan rule
Quoted 7 lines · Richard Henderson
Quoted 5 lines · Peter Maydell
Explicitly set a rule in the softfloat tests for the inf-zero-nan muladd special case. In meson.build we put -DTARGET_ARM in fpcflags, and so we should select here the Arm rule of
float_infzeronan_dnan_if_qnan.
Quoted 7 lines
Quoted 5 lines
Reviewed-by Richard Henderson <[email protected]>--- tests/fp/fp-bench.c | 5 +++++ tests/fp/fp-test.c | 5 +++++ 2 files changed, 10 insertions(+)Lost your SoB.
Whoops; here it is:
-- PMM
PATCH v2 5/54 target/arm: Set FloatInfZeroNaNRule explicitly
In reply to Peter MaydellSet the FloatInfZeroNaNRule explicitly for the Arm target, so we can remove the ifdef from pickNaNMulAdd().
--- target/arm/cpu.c | 3 +++ fpu/softfloat-specialize.c.inc | 8 +------- 2 files changed, 4 insertions(+), 7 deletions(-)
target/arm/cpu.c +3 -0
@@ -173,11 +173,14 @@ void arm_register_el_change_hook(ARMCPU *cpu, ARMELChangeHookFn *hook,* * tininess-before-rounding * * 2-input NaN propagation prefers SNaN over QNaN, and then * operand A over operand B (see FPProcessNaNs() pseudocode) +* * 0 * Inf + NaN returns the default NaN if the input NaN is quiet, +* and the input NaN if it is signalling */ static void arm_set_default_fp_behaviours (float_status *s) {set_float_detect_tininess (float_tininess_before_rounding, s);set_float_2nan_prop_rule (float_2nan_prop_s_ab, s); +set_float_infzeronan_rule (float_infzeronan_dnan_if_qnan, s); }static void cp_reg_reset (gpointer key,gpointer value,gpointer opaque)
fpu/softfloat-specialize.c.inc +1 -7
@@ -489,13 +489,7 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, /* * Temporarily fall back to ifdef ladder */ -#if defined(TARGET_ARM) - /* - * For ARM, the (inf,zero,qnan) case returns the default NaN, - * but (inf,zero,snan) returns the input NaN. - */ - rule = float_infzeronan_dnan_if_qnan; -#elif defined(TARGET_MIPS) +#if defined(TARGET_MIPS) if (snan_bit_is_one(status)) { /* * For MIPS systems that conform to IEEE754-1985, the (inf,zero,nan)
Signature · 1 line
2.34.1
PATCH v2 6/54 target/s390: Set FloatInfZeroNaNRule explicitly
In reply to Peter MaydellSet the FloatInfZeroNaNRule explicitly for s390, so we can remove the ifdef from pickNaNMulAdd().
--- target/s390x/cpu.c | 2 ++ fpu/softfloat-specialize.c.inc | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-)
target/s390x/cpu.c +2 -0
@@ -206,6 +206,8 @@ static void s390_cpu_reset_hold(Object *obj, ResetType type)set_float_detect_tininess (float_tininess_before_rounding, &env->fpu_status);set_float_2nan_prop_rule (float_2nan_prop_s_ab, &env->fpu_status); +set_float_infzeronan_rule (float_infzeronan_dnan_always, + &env->fpu_status);/* fall through */ case RESET_TYPE_S390_CPU_NORMAL : env->psw.mask &= ~PSW_MASK_RI ;
fpu/softfloat-specialize.c.inc +0 -2
@@ -516,8 +516,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, * a default NaN */ rule = float_infzeronan_dnan_never; -#elif defined(TARGET_S390X) - rule = float_infzeronan_dnan_always; #endif }
Signature · 1 line
2.34.1
PATCH v2 7/54 target/ppc: Set FloatInfZeroNaNRule explicitly
In reply to Peter MaydellSet the FloatInfZeroNaNRule explicitly for the PPC target, so we can remove the ifdef from pickNaNMulAdd().
--- target/ppc/cpu_init.c | 7 +++++++ fpu/softfloat-specialize.c.inc | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-)
target/ppc/cpu_init.c +7 -0
@@ -7270,6 +7270,13 @@ static void ppc_cpu_reset_hold(Object *obj, ResetType type)*/ set_float_2nan_prop_rule (float_2nan_prop_ab, &env->fp_status);set_float_2nan_prop_rule (float_2nan_prop_ab, &env->vec_status); +/* +* For PPC, the (inf,zero,qnan) case sets InvalidOp, but we prefer +* to return an input NaN if we have one (ie c) rather than generating +* a default NaN +*/ +set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status); +set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->vec_status);for (i =0 ; i <ARRAY_SIZE (env->spr_cb); i++) {ppc_spr_t *spr = &env->spr_cb[i];
fpu/softfloat-specialize.c.inc +1 -6
@@ -503,18 +503,13 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, */ rule = float_infzeronan_dnan_never; } -#elif defined(TARGET_PPC) || defined(TARGET_SPARC) || \ +#elif defined(TARGET_SPARC) || \ defined(TARGET_XTENSA) || defined(TARGET_HPPA) || \ defined(TARGET_I386) || defined(TARGET_LOONGARCH) /* * For LoongArch systems that conform to IEEE754-2008, the (inf,zero,nan) * case sets InvalidOp and returns the input value 'c' */ - /* - * For PPC, the (inf,zero,qnan) case sets InvalidOp, but we prefer - * to return an input NaN if we have one (ie c) rather than generating - * a default NaN - */ rule = float_infzeronan_dnan_never; #endif }
Signature · 1 line
2.34.1
PATCH v2 8/54 target/mips: Set FloatInfZeroNaNRule explicitly
In reply to Peter MaydellSet the FloatInfZeroNaNRule explicitly for the MIPS target, so we can remove the ifdef from pickNaNMulAdd().
--- target/mips/fpu_helper.h | 9 +++++++++ target/mips/msa.c | 4 ++++ fpu/softfloat-specialize.c.inc | 16 +--------------- 3 files changed, 14 insertions(+), 15 deletions(-)
target/mips/fpu_helper.h +9 -0
@@ -28,6 +28,7 @@ static inline void restore_flush_mode(CPUMIPSState *env)static inline void restore_snan_bit_mode (CPUMIPSState *env) {bool nan2008 = env->active_fpu.fcr31 & (1 <<FCR31_NAN2008 ); +FloatInfZeroNaNRule izn_rule;/* * With nan2008, SNaNs are silenced in the usual way.
@@ -35,6 +36,14 @@ static inline void restore_snan_bit_mode(CPUMIPSState *env)*/ set_snan_bit_is_one (!nan2008, &env->active_fpu.fp_status);set_default_nan_mode (!nan2008, &env->active_fpu.fp_status); +/* +* For MIPS systems that conform to IEEE754-1985, the (inf,zero,nan) +* case sets InvalidOp and returns the default NaN. +* For MIPS systems that conform to IEEE754-2008, the (inf,zero,nan) +* case sets InvalidOp and returns the input value 'c'. +*/ + izn_rule = nan2008 ? float_infzeronan_dnan_never : float_infzeronan_dnan_always; +set_float_infzeronan_rule (izn_rule, &env->active_fpu.fp_status); }static inline void restore_fp_status (CPUMIPSState *env)
target/mips/msa.c +4 -0
@@ -74,4 +74,8 @@ void msa_reset(CPUMIPSState *env)/* set proper signanling bit meaning ("1" means "quiet") */ set_snan_bit_is_one (0 , &env->active_tc.msa_fp_status); + +/* Inf * 0 + NaN returns the input NaN */ +set_float_infzeronan_rule (float_infzeronan_dnan_never, + &env->active_tc.msa_fp_status); }
fpu/softfloat-specialize.c.inc +1 -15
@@ -489,21 +489,7 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, /* * Temporarily fall back to ifdef ladder */ -#if defined(TARGET_MIPS) - if (snan_bit_is_one(status)) { - /* - * For MIPS systems that conform to IEEE754-1985, the (inf,zero,nan) - * case sets InvalidOp and returns the default NaN - */ - rule = float_infzeronan_dnan_always; - } else { - /* - * For MIPS systems that conform to IEEE754-2008, the (inf,zero,nan) - * case sets InvalidOp and returns the input value 'c' - */ - rule = float_infzeronan_dnan_never; - } -#elif defined(TARGET_SPARC) || \ +#if defined(TARGET_SPARC) || \ defined(TARGET_XTENSA) || defined(TARGET_HPPA) || \ defined(TARGET_I386) || defined(TARGET_LOONGARCH) /*
Signature · 1 line
2.34.1
PATCH v2 9/54 target/sparc: Set FloatInfZeroNaNRule explicitly
In reply to Peter MaydellSet the FloatInfZeroNaNRule explicitly for the SPARC target, so we can remove the ifdef from pickNaNMulAdd().
--- target/sparc/cpu.c | 2 ++ fpu/softfloat-specialize.c.inc | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-)
target/sparc/cpu.c +2 -0
@@ -814,6 +814,8 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)* the CPU state struct so it won't get zeroed on reset. */ set_float_2nan_prop_rule (float_2nan_prop_s_ba, &env->fp_status); +/* For inf * 0 + NaN, return the input NaN */ +set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status);cpu_exec_realizefn (cs, &local_err);if (local_err !=NULL ) {
fpu/softfloat-specialize.c.inc +1 -2
@@ -489,8 +489,7 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, /* * Temporarily fall back to ifdef ladder */ -#if defined(TARGET_SPARC) || \ - defined(TARGET_XTENSA) || defined(TARGET_HPPA) || \ +#if defined(TARGET_XTENSA) || defined(TARGET_HPPA) || \ defined(TARGET_I386) || defined(TARGET_LOONGARCH) /* * For LoongArch systems that conform to IEEE754-2008, the (inf,zero,nan)
Signature · 1 line
2.34.1
PATCH v2 10/54 target/xtensa: Set FloatInfZeroNaNRule explicitly
In reply to Peter MaydellSet the FloatInfZeroNaNRule explicitly for the xtensa target, so we can remove the ifdef from pickNaNMulAdd().
--- target/xtensa/cpu.c | 2 ++ fpu/softfloat-specialize.c.inc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
target/xtensa/cpu.c +2 -0
@@ -133,6 +133,8 @@ static void xtensa_cpu_reset_hold(Object *obj, ResetType type)reset_mmu (env); cs->halted = env->runstall;#endif +/* For inf * 0 + NaN, return the input NaN */ +set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status);set_no_signaling_nans (!dfpu, &env->fp_status);xtensa_use_first_nan (env, !dfpu); }
fpu/softfloat-specialize.c.inc +1 -1
@@ -489,7 +489,7 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, /* * Temporarily fall back to ifdef ladder */ -#if defined(TARGET_XTENSA) || defined(TARGET_HPPA) || \ +#if defined(TARGET_HPPA) || \ defined(TARGET_I386) || defined(TARGET_LOONGARCH) /* * For LoongArch systems that conform to IEEE754-2008, the (inf,zero,nan)
Signature · 1 line
2.34.1
PATCH v2 11/54 target/x86: Set FloatInfZeroNaNRule explicitly
In reply to Peter MaydellSet the FloatInfZeroNaNRule explicitly for the x86 target.
---v1->v2: Update the comment to give the info from the x86 spec rather than a TODO comment saying we need to check it...
--- target/i386/tcg/fpu_helper.c | 7 +++++++ fpu/softfloat-specialize.c.inc | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-)
target/i386/tcg/fpu_helper.c +7 -0
@@ -173,6 +173,13 @@ void cpu_init_fp_statuses(CPUX86State *env)*/ set_float_2nan_prop_rule (float_2nan_prop_x87, &env->mmx_status);set_float_2nan_prop_rule (float_2nan_prop_x87, &env->sse_status); +/* +* Only SSE has multiply-add instructions. In the SDM Section 14.5.2 +* "Fused-Multiply-ADD (FMA) Numeric Behavior" the NaN handling is +* specified -- for 0 * inf + NaN the input NaN is selected, and if +* there are multiple input NaNs athey are selected in the order a, b, c. +*/ +set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->sse_status); }static inline uint8_t save_exception_flags (CPUX86State *env)
fpu/softfloat-specialize.c.inc +1 -1
@@ -490,7 +490,7 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, * Temporarily fall back to ifdef ladder */ #if defined(TARGET_HPPA) || \ - defined(TARGET_I386) || defined(TARGET_LOONGARCH) + defined(TARGET_LOONGARCH) /* * For LoongArch systems that conform to IEEE754-2008, the (inf,zero,nan) * case sets InvalidOp and returns the input value 'c'
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 11/54] target/x86: Set FloatInfZeroNaNRule explicitly
Quoted 17 lines · Peter Maydell
Set the FloatInfZeroNaNRule explicitly for the x86 target.
Signed-off-by Peter Maydell <[email protected]>Reviewed-by Richard Henderson <[email protected]>---
v1->v2: Update the comment to give the info from the x86 spec rather than a TODO comment saying we need to check it...--- target/i386/tcg/fpu_helper.c | 7 +++++++ fpu/softfloat-specialize.c.inc | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-)target/i386/tcg/fpu_helper.c +0
-0
target/i386/tcg/fpu_helper.c void cpu_init_fp_statuses(CPUX86State *env) · line 180
Quoted 8 lines
target/i386/tcg/fpu_helper.c +5
-0@@ -173,6 +173,13 @@ void cpu_init_fp_statuses(CPUX86State *env)*/ set_float_2nan_prop_rule (float_2nan_prop_x87, &env->mmx_status);set_float_2nan_prop_rule (float_2nan_prop_x87, &env->sse_status); +/* +* Only SSE has multiply-add instructions. In the SDM Section 14.5.2 +* "Fused-Multiply-ADD (FMA) Numeric Behavior" the NaN handling is +* specified -- for 0 * inf + NaN the input NaN is selected, and if +* there are multiple input NaNs athey are selected in the order a, b, c.
"athey"
r~
PATCH v2 12/54 target/loongarch: Set FloatInfZeroNaNRule explicitly
In reply to Peter MaydellSet the FloatInfZeroNaNRule explicitly for the loongarch target.
--- target/loongarch/tcg/fpu_helper.c | 5 +++++ fpu/softfloat-specialize.c.inc | 7 +------ 2 files changed, 6 insertions(+), 6 deletions(-)
target/loongarch/tcg/fpu_helper.c +5 -0
@@ -32,6 +32,11 @@ void restore_fp_status(CPULoongArchState *env) &env->fp_status);set_flush_to_zero (0 , &env->fp_status);set_float_2nan_prop_rule (float_2nan_prop_s_ab, &env->fp_status); +/* +* For LoongArch systems that conform to IEEE754-2008, the (inf,zero,nan) +* case sets InvalidOp and returns the input value 'c' +*/ +set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status); }int ieee_ex_to_loongarch (int xcpt)
fpu/softfloat-specialize.c.inc +1 -6
@@ -489,12 +489,7 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, /* * Temporarily fall back to ifdef ladder */ -#if defined(TARGET_HPPA) || \ - defined(TARGET_LOONGARCH) - /* - * For LoongArch systems that conform to IEEE754-2008, the (inf,zero,nan) - * case sets InvalidOp and returns the input value 'c' - */ +#if defined(TARGET_HPPA) rule = float_infzeronan_dnan_never; #endif }
Signature · 1 line
2.34.1
PATCH v2 13/54 target/hppa: Set FloatInfZeroNaNRule explicitly
In reply to Peter MaydellSet the FloatInfZeroNaNRule explicitly for the HPPA target, so we can remove the ifdef from pickNaNMulAdd().
As this is the last target to be converted to explicitly setting the rule, we can remove the fallback code in pickNaNMulAdd() entirely.
--- target/hppa/fpu_helper.c | 2 ++ fpu/softfloat-specialize.c.inc | 13 +------------ 2 files changed, 3 insertions(+), 12 deletions(-)
target/hppa/fpu_helper.c +2 -0
@@ -55,6 +55,8 @@ void HELPER(loaded_fr0)(CPUHPPAState *env)* HPPA does note implement a CPU reset method at all... */ set_float_2nan_prop_rule (float_2nan_prop_s_ab, &env->fp_status); +/* For inf * 0 + NaN, return the input NaN */ +set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status); }void cpu_hppa_loaded_fr0 (CPUHPPAState *env)
fpu/softfloat-specialize.c.inc +1 -12
@@ -475,8 +475,6 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls, static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, bool infzero, float_status *status) { - FloatInfZeroNaNRule rule = status->float_infzeronan_rule; - /* * We guarantee not to require the target to tell us how to * pick a NaN if we're always returning the default NaN.
@@ -485,21 +483,12 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, */ assert(!status->default_nan_mode); - if (rule == float_infzeronan_none) { - /* - * Temporarily fall back to ifdef ladder - */ -#if defined(TARGET_HPPA) - rule = float_infzeronan_dnan_never; -#endif - } - if (infzero) { /* * Inf * 0 + NaN -- some implementations return the default NaN here, * and some return the input NaN. */ - switch (rule) { + switch (status->float_infzeronan_rule) { case float_infzeronan_dnan_never: return 2; case float_infzeronan_dnan_always:
Signature · 1 line
2.34.1
PATCH v2 14/54 softfloat: Pass have_snan to pickNaNMulAdd
In reply to Peter MaydellThe new implementation of pickNaNMulAdd() will find it convenient to know whether at least one of the three arguments to the muladd was a signaling NaN. We already calculate that in the caller, so pass it in as a new bool have_snan.
--- fpu/softfloat-parts.c.inc | 5 +++-- fpu/softfloat-specialize.c.inc | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
fpu/softfloat-parts.c.inc +3 -2
@@ -67,8 +67,9 @@ static FloatPartsN *partsN(pick_nan_muladd)(FloatPartsN *a, FloatPartsN *b, { int which; bool infzero = (ab_mask == float_cmask_infzero); + bool have_snan = (abc_mask & float_cmask_snan); - if (unlikely(abc_mask & float_cmask_snan)) { + if (unlikely(have_snan)) { float_raise(float_flag_invalid | float_flag_invalid_snan, s); }
@@ -80,7 +81,7 @@ static FloatPartsN *partsN(pick_nan_muladd)(FloatPartsN *a, FloatPartsN *b, if (s->default_nan_mode) { which = 3; } else { - which = pickNaNMulAdd(a->cls, b->cls, c->cls, infzero, s); + which = pickNaNMulAdd(a->cls, b->cls, c->cls, infzero, have_snan, s); } if (which == 3) {
fpu/softfloat-specialize.c.inc +1 -1
@@ -473,7 +473,7 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls, | Return values : 0 : a; 1 : b; 2 : c; 3 : default-NaN *----------------------------------------------------------------------------*/ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, - bool infzero, float_status *status) + bool infzero, bool have_snan, float_status *status) { /* * We guarantee not to require the target to tell us how to
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 14/54] softfloat: Pass have_snan to pickNaNMulAdd
Quoted 10 lines · Peter Maydell
The new implementation of
pickNaNMulAdd()will find it convenient to know whether at least one of the three arguments to the muladd was a signaling NaN. We already calculate that in the caller, so pass it in as a new boolhave_snan.Signed-off-by Peter Maydell<[email protected]>--- fpu/softfloat-parts.c.inc | 5 +++-- fpu/softfloat-specialize.c.inc | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
r~
PATCH v2 15/54 softfloat: Allow runtime choice of NaN propagation for muladd
In reply to Peter MaydellIEEE 758 does not define a fixed rule for which NaN to pick as the result if both operands of a 3-operand fused multiply-add operation are NaNs. As a result different architectures have ended up with different rules for propagating NaNs.
QEMU currently hardcodes the NaN propagation logic into the binary because pickNaNMulAdd() has an ifdef ladder for different targets. We want to make the propagation rule instead be selectable at runtime, because:
* this will let us have multiple targets in one QEMU binary
* the Arm FEAT_AFP architectural feature includes letting the guest select a NaN propagation rule at runtime
In this commit we add an enum for the propagation rule, the field in float_status, and the corresponding getters and setters. We change pickNaNMulAdd to honour this, but because all targets still leave this field at its default 0 value, the fallback logic will pick the rule type with the old ifdef ladder.
It's valid not to set a propagation rule if default_nan_mode is enabled, because in that case there's no need to pick a NaN; all the callers of pickNaNMulAdd() catch this case and skip calling it.
--- include/fpu/softfloat-helpers.h | 11 +++ include/fpu/softfloat-types.h | 55 +++++++++++ fpu/softfloat-specialize.c.inc | 167 ++++++++------------------------ 3 files changed, 107 insertions(+), 126 deletions(-)
include/fpu/softfloat-helpers.h +11 -0
@@ -81,6 +81,12 @@ static inline void set_float_2nan_prop_rule(Float2NaNPropRule rule, status->float_2nan_prop_rule = rule; } +static inline void set_float_3nan_prop_rule (Float3NaNPropRule rule, +float_status *status) +{ + status->float_3nan_prop_rule = rule; +} +static inline void set_float_infzeronan_rule (FloatInfZeroNaNRule rule,float_status *status) {
@@ -143,6 +149,11 @@ static inline Float2NaNPropRule get_float_2nan_prop_rule(float_status *status)return status->float_2nan_prop_rule; } +static inline Float3NaNPropRule get_float_3nan_prop_rule (float_status *status) +{ +return status->float_3nan_prop_rule; +} +static inline FloatInfZeroNaNRule get_float_infzeronan_rule (float_status *status) {return status->float_infzeronan_rule;
include/fpu/softfloat-types.h +55 -0
73 lines not on this page · raw message
fpu/softfloat-specialize.c.inc +41 -126
192 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 15/54] softfloat: Allow runtime choice of NaN propagation for muladd
Quoted 23 lines · Peter Maydell
IEEE 758 does not define a fixed rule for which NaN to pick as the result if both operands of a 3-operand fused multiply-add operation are NaNs. As a result different architectures have ended up with different rules for propagating NaNs.
QEMU currently hardcodes the NaN propagation logic into the binary because
pickNaNMulAdd()has an ifdef ladder for different targets. We want to make the propagation rule instead be selectable at runtime, because:
* this will let us have multiple targets in one QEMU binary
* the ArmFEAT_AFParchitectural feature includes letting the guest select a NaN propagation rule at runtimeIn this commit we add an enum for the propagation rule, the field in
float_status, and the corresponding getters and setters. We change pickNaNMulAdd to honour this, but because all targets still leave this field at its default 0 value, the fallback logic will pick the rule type with the old ifdef ladder.It's valid not to set a propagation rule if
default_nan_modeis enabled, because in that case there's no need to pick a NaN; all the callers ofpickNaNMulAdd()catch this case and skip calling it.
Quoted 6 lines
Signed-off-by Peter Maydell<[email protected]>--- include/fpu/softfloat-helpers.h | 11 +++ include/fpu/softfloat-types.h | 55 +++++++++++ fpu/softfloat-specialize.c.inc | 167 ++++++++------------------------ 3 files changed, 107 insertions(+), 126 deletions(-)
r~
PATCH v2 16/54 tests/fp: Explicitly set 3-NaN propagation rule
In reply to Peter MaydellExplicitly set a rule in the softfloat tests for propagating NaNs in the muladd case. In meson.build we put -DTARGET_ARM in fpcflags, and so we should select here the Arm rule of float_3nan_prop_s_cab.
--- tests/fp/fp-bench.c | 1 + tests/fp/fp-test.c | 1 + 2 files changed, 2 insertions(+)
tests/fp/fp-bench.c +1 -0
@@ -493,6 +493,7 @@ static void run_bench(void)* doesn't specify match those used by the Arm architecture. */ set_float_2nan_prop_rule (float_2nan_prop_s_ab, &soft_status); +set_float_3nan_prop_rule (float_3nan_prop_s_cab, &soft_status);set_float_infzeronan_rule (float_infzeronan_dnan_if_qnan, &soft_status); f = bench_funcs[operation][precision];
tests/fp/fp-test.c +1 -0
@@ -940,6 +940,7 @@ void run_test(void)* doesn't specify match those used by the Arm architecture. */ set_float_2nan_prop_rule (float_2nan_prop_s_ab, &qsf); +set_float_3nan_prop_rule (float_3nan_prop_s_cab, &qsf);set_float_infzeronan_rule (float_infzeronan_dnan_if_qnan, &qsf);genCases_setLevel (test_level);
Signature · 1 line
2.34.1
PATCH v2 17/54 target/arm: Set Float3NaNPropRule explicitly
In reply to Peter MaydellSet the Float3NaNPropRule explicitly for Arm, and remove the ifdef from pickNaNMulAdd().
--- target/arm/cpu.c | 5 +++++ fpu/softfloat-specialize.c.inc | 8 +------- 2 files changed, 6 insertions(+), 7 deletions(-)
target/arm/cpu.c +5 -0
@@ -173,6 +173,10 @@ void arm_register_el_change_hook(ARMCPU *cpu, ARMELChangeHookFn *hook,* * tininess-before-rounding * * 2-input NaN propagation prefers SNaN over QNaN, and then * operand A over operand B (see FPProcessNaNs() pseudocode) +* * 3-input NaN propagation prefers SNaN over QNaN, and then +* operand C over A over B (see FPProcessNaNs3() pseudocode, +* but note that for QEMU muladd is a * b + c, whereas for +* the pseudocode function the arguments are in the order c, a, b. * * 0 * Inf + NaN returns the default NaN if the input NaN is quiet, * and the input NaN if it is signalling */
@@ -180,6 +184,7 @@ static void arm_set_default_fp_behaviours(float_status *s) {set_float_detect_tininess (float_tininess_before_rounding, s);set_float_2nan_prop_rule (float_2nan_prop_s_ab, s); +set_float_3nan_prop_rule (float_3nan_prop_s_cab, s);set_float_infzeronan_rule (float_infzeronan_dnan_if_qnan, s); }
fpu/softfloat-specialize.c.inc +1 -7
@@ -505,13 +505,7 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, } if (rule == float_3nan_prop_none) { -#if defined(TARGET_ARM) - /* - * This looks different from the ARM ARM pseudocode, because the ARM ARM - * puts the operands to a fused mac operation (a*b)+c in the order c,a,b - */ - rule = float_3nan_prop_s_cab; -#elif defined(TARGET_MIPS) +#if defined(TARGET_MIPS) if (snan_bit_is_one(status)) { rule = float_3nan_prop_s_abc; } else {
Signature · 1 line
2.34.1
PATCH v2 18/54 target/loongarch: Set Float3NaNPropRule explicitly
In reply to Peter MaydellSet the Float3NaNPropRule explicitly for loongarch, and remove the ifdef from pickNaNMulAdd().
--- target/loongarch/tcg/fpu_helper.c | 1 + fpu/softfloat-specialize.c.inc | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-)
target/loongarch/tcg/fpu_helper.c +1 -0
@@ -37,6 +37,7 @@ void restore_fp_status(CPULoongArchState *env)* case sets InvalidOp and returns the input value 'c' */ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status); +set_float_3nan_prop_rule (float_3nan_prop_s_cab, &env->fp_status); }int ieee_ex_to_loongarch (int xcpt)
fpu/softfloat-specialize.c.inc +0 -2
@@ -511,8 +511,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, } else { rule = float_3nan_prop_s_cab; } -#elif defined(TARGET_LOONGARCH64) - rule = float_3nan_prop_s_cab; #elif defined(TARGET_PPC) /* * If fRA is a NaN return it; otherwise if fRB is a NaN return it;
Signature · 1 line
2.34.1
PATCH v2 19/54 target/ppc: Set Float3NaNPropRule explicitly
In reply to Peter MaydellSet the Float3NaNPropRule explicitly for PPC, and remove the ifdef from pickNaNMulAdd().
--- target/ppc/cpu_init.c | 8 ++++++++ fpu/softfloat-specialize.c.inc | 6 ------ 2 files changed, 8 insertions(+), 6 deletions(-)
target/ppc/cpu_init.c +8 -0
@@ -7270,6 +7270,14 @@ static void ppc_cpu_reset_hold(Object *obj, ResetType type)*/ set_float_2nan_prop_rule (float_2nan_prop_ab, &env->fp_status);set_float_2nan_prop_rule (float_2nan_prop_ab, &env->vec_status); +/* +* NaN propagation for fused multiply-add: +* if fRA is a NaN return it; otherwise if fRB is a NaN return it; +* otherwise return fRC. Note that muladd on PPC is (fRA * fRC) + frB +* whereas QEMU labels the operands as (a * b) + c. +*/ +set_float_3nan_prop_rule (float_3nan_prop_acb, &env->fp_status); +set_float_3nan_prop_rule (float_3nan_prop_acb, &env->vec_status);/* * For PPC, the (inf,zero,qnan) case sets InvalidOp, but we prefer * to return an input NaN if we have one (ie c) rather than generating
fpu/softfloat-specialize.c.inc +0 -6
@@ -511,12 +511,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, } else { rule = float_3nan_prop_s_cab; } -#elif defined(TARGET_PPC) - /* - * If fRA is a NaN return it; otherwise if fRB is a NaN return it; - * otherwise return fRC. Note that muladd on PPC is (fRA * fRC) + frB - */ - rule = float_3nan_prop_acb; #elif defined(TARGET_S390X) rule = float_3nan_prop_s_abc; #elif defined(TARGET_SPARC)
Signature · 1 line
2.34.1
PATCH v2 20/54 target/s390x: Set Float3NaNPropRule explicitly
In reply to Peter MaydellSet the Float3NaNPropRule explicitly for s390x, and remove the ifdef from pickNaNMulAdd().
--- target/s390x/cpu.c | 1 + fpu/softfloat-specialize.c.inc | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-)
target/s390x/cpu.c +1 -0
@@ -206,6 +206,7 @@ static void s390_cpu_reset_hold(Object *obj, ResetType type)set_float_detect_tininess (float_tininess_before_rounding, &env->fpu_status);set_float_2nan_prop_rule (float_2nan_prop_s_ab, &env->fpu_status); +set_float_3nan_prop_rule (float_3nan_prop_s_abc, &env->fpu_status);set_float_infzeronan_rule (float_infzeronan_dnan_always, &env->fpu_status);/* fall through */
fpu/softfloat-specialize.c.inc +0 -2
@@ -511,8 +511,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, } else { rule = float_3nan_prop_s_cab; } -#elif defined(TARGET_S390X) - rule = float_3nan_prop_s_abc; #elif defined(TARGET_SPARC) rule = float_3nan_prop_s_cba; #elif defined(TARGET_XTENSA)
Signature · 1 line
2.34.1
PATCH v2 21/54 target/sparc: Set Float3NaNPropRule explicitly
In reply to Peter MaydellSet the Float3NaNPropRule explicitly for SPARC, and remove the ifdef from pickNaNMulAdd().
--- target/sparc/cpu.c | 2 ++ fpu/softfloat-specialize.c.inc | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-)
target/sparc/cpu.c +2 -0
@@ -814,6 +814,8 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)* the CPU state struct so it won't get zeroed on reset. */ set_float_2nan_prop_rule (float_2nan_prop_s_ba, &env->fp_status); +/* For fused-multiply add, prefer SNaN over QNaN, then C->B->A */ +set_float_3nan_prop_rule (float_3nan_prop_s_cba, &env->fp_status);/* For inf * 0 + NaN, return the input NaN */ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status);
fpu/softfloat-specialize.c.inc +0 -2
@@ -511,8 +511,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, } else { rule = float_3nan_prop_s_cab; } -#elif defined(TARGET_SPARC) - rule = float_3nan_prop_s_cba; #elif defined(TARGET_XTENSA) if (status->use_first_nan) { rule = float_3nan_prop_abc;
Signature · 1 line
2.34.1
PATCH v2 22/54 target/mips: Set Float3NaNPropRule explicitly
In reply to Peter MaydellSet the Float3NaNPropRule explicitly for Arm, and remove the ifdef from pickNaNMulAdd().
--- target/mips/fpu_helper.h | 4 ++++ target/mips/msa.c | 3 +++ fpu/softfloat-specialize.c.inc | 8 +------- 3 files changed, 8 insertions(+), 7 deletions(-)
target/mips/fpu_helper.h +4 -0
@@ -29,6 +29,7 @@ static inline void restore_snan_bit_mode(CPUMIPSState *env) {bool nan2008 = env->active_fpu.fcr31 & (1 <<FCR31_NAN2008 );FloatInfZeroNaNRule izn_rule; +Float3NaNPropRule nan3_rule;/* * With nan2008, SNaNs are silenced in the usual way.
@@ -44,6 +45,9 @@ static inline void restore_snan_bit_mode(CPUMIPSState *env)*/ izn_rule = nan2008 ? float_infzeronan_dnan_never : float_infzeronan_dnan_always;set_float_infzeronan_rule (izn_rule, &env->active_fpu.fp_status); + nan3_rule = nan2008 ? float_3nan_prop_s_cab : float_3nan_prop_s_abc; +set_float_3nan_prop_rule (nan3_rule, &env->active_fpu.fp_status); + }static inline void restore_fp_status (CPUMIPSState *env)
target/mips/msa.c +3 -0
@@ -66,6 +66,9 @@ void msa_reset(CPUMIPSState *env)set_float_2nan_prop_rule (float_2nan_prop_s_ab, &env->active_tc.msa_fp_status); +set_float_3nan_prop_rule (float_3nan_prop_s_cab, + &env->active_tc.msa_fp_status); +/* clear float_status exception flags */ set_float_exception_flags (0 , &env->active_tc.msa_fp_status);
fpu/softfloat-specialize.c.inc +1 -7
@@ -505,13 +505,7 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, } if (rule == float_3nan_prop_none) { -#if defined(TARGET_MIPS) - if (snan_bit_is_one(status)) { - rule = float_3nan_prop_s_abc; - } else { - rule = float_3nan_prop_s_cab; - } -#elif defined(TARGET_XTENSA) +#if defined(TARGET_XTENSA) if (status->use_first_nan) { rule = float_3nan_prop_abc; } else {
Signature · 1 line
2.34.1
PATCH v2 23/54 target/xtensa: Set Float3NaNPropRule explicitly
In reply to Peter MaydellSet the Float3NaNPropRule explicitly for xtensa, and remove the ifdef from pickNaNMulAdd().
--- target/xtensa/fpu_helper.c | 2 ++ fpu/softfloat-specialize.c.inc | 8 -------- 2 files changed, 2 insertions(+), 8 deletions(-)
target/xtensa/fpu_helper.c +2 -0
@@ -62,6 +62,8 @@ void xtensa_use_first_nan(CPUXtensaState *env, bool use_first)set_use_first_nan (use_first, &env->fp_status);set_float_2nan_prop_rule (use_first ? float_2nan_prop_ab : float_2nan_prop_ba, &env->fp_status); +set_float_3nan_prop_rule (use_first ? float_3nan_prop_abc : float_3nan_prop_cba, + &env->fp_status); }void HELPER (wur_fpu2k_fcr )(CPUXtensaState *env,uint32_t v)
fpu/softfloat-specialize.c.inc +0 -8
@@ -505,15 +505,7 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, } if (rule == float_3nan_prop_none) { -#if defined(TARGET_XTENSA) - if (status->use_first_nan) { - rule = float_3nan_prop_abc; - } else { - rule = float_3nan_prop_cba; - } -#else rule = float_3nan_prop_abc; -#endif } assert(rule != float_3nan_prop_none);
Signature · 1 line
2.34.1
PATCH v2 24/54 target/i386: Set Float3NaNPropRule explicitly
In reply to Peter MaydellSet the Float3NaNPropRule explicitly for i386. We had no i386-specific behaviour in the old ifdef ladder, so we were using the default "prefer a then b then c" fallback; this is actually the correct per-the-spec handling for i386.
---v1->v2: drop comment saying NaN rule is wrong.
--- target/i386/tcg/fpu_helper.c | 1 + 1 file changed, 1 insertion(+)
target/i386/tcg/fpu_helper.c +1 -0
@@ -180,6 +180,7 @@ void cpu_init_fp_statuses(CPUX86State *env)* there are multiple input NaNs athey are selected in the order a, b, c. */ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->sse_status); +set_float_3nan_prop_rule (float_3nan_prop_abc, &env->sse_status); }static inline uint8_t save_exception_flags (CPUX86State *env)
Signature · 1 line
2.34.1
PATCH v2 25/54 target/hppa: Set Float3NaNPropRule explicitly
In reply to Peter MaydellSet the Float3NaNPropRule explicitly for HPPA, and remove the ifdef from pickNaNMulAdd().
HPPA is the only target that was using the default branch of the ifdef ladder (other targets either do not use muladd or set default_nan_mode), so we can remove the ifdef fallback entirely now (allowing the "rule not set" case to fall into the default of the switch statement and assert).
We add a TODO note that the HPPA rule is probably wrong; this is not a behavioural change for this refactoring.
--- target/hppa/fpu_helper.c | 8 ++++++++ fpu/softfloat-specialize.c.inc | 4 ---- 2 files changed, 8 insertions(+), 4 deletions(-)
target/hppa/fpu_helper.c +8 -0
@@ -55,6 +55,14 @@ void HELPER(loaded_fr0)(CPUHPPAState *env)* HPPA does note implement a CPU reset method at all... */ set_float_2nan_prop_rule (float_2nan_prop_s_ab, &env->fp_status); +/* +* TODO: The HPPA architecture reference only documents its NaN +* propagation rule for 2-operand operations. Testing on real hardware +* might be necessary to confirm whether this order for muladd is correct. +* Not preferring the SNaN is almost certainly incorrect as it diverges +* from the documented rules for 2-operand operations. +*/ +set_float_3nan_prop_rule (float_3nan_prop_abc, &env->fp_status);/* For inf * 0 + NaN, return the input NaN */ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status); }
fpu/softfloat-specialize.c.inc +0 -4
@@ -504,10 +504,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, } } - if (rule == float_3nan_prop_none) { - rule = float_3nan_prop_abc; - } - assert(rule != float_3nan_prop_none); if (have_snan && (rule & R_3NAN_SNAN_MASK)) { /* We have at least one SNaN input and should prefer it */
Signature · 1 line
2.34.1
PATCH v2 26/54 fpu: Remove use_first_nan field from float_status
In reply to Peter MaydellThe use_first_nan field in float_status was an xtensa-specific way to select at runtime from two different NaN propagation rules. Now that xtensa is using the target-agnostic NaN propagation rule selection that we've just added, we can remove use_first_nan, because there is no longer any code that reads it.
--- include/fpu/softfloat-helpers.h | 5 ----- include/fpu/softfloat-types.h | 1 - target/xtensa/fpu_helper.c | 1 - 3 files changed, 7 deletions(-)
include/fpu/softfloat-helpers.h +0 -5
@@ -113,11 +113,6 @@ static inline void set_snan_bit_is_one(bool val, float_status *status) status->snan_bit_is_one = val; } -static inline void set_use_first_nan (bool val,float_status *status) -{ - status->use_first_nan = val; -} -static inline void set_no_signaling_nans (bool val,float_status *status) { status->no_signaling_nans = val;
include/fpu/softfloat-types.h +0 -1
@@ -309,7 +309,6 @@ typedef struct float_status {* softfloat-specialize.inc.c) */ bool snan_bit_is_one; -bool use_first_nan;bool no_signaling_nans;/* should overflowed results subtract re_bias to its exponent? */ bool rebias_overflow;
target/xtensa/fpu_helper.c +0 -1
@@ -59,7 +59,6 @@ static const struct {void xtensa_use_first_nan (CPUXtensaState *env,bool use_first) { -set_use_first_nan (use_first, &env->fp_status);set_float_2nan_prop_rule (use_first ? float_2nan_prop_ab : float_2nan_prop_ba, &env->fp_status); set_float_3nan_prop_rule(use_first ? float_3nan_prop_abc : float_3nan_prop_cba,
Signature · 1 line
2.34.1
PATCH v2 27/54 target/m68k: Don't pass NULL float_status to floatx80_default_nan()
In reply to Peter MaydellCurrently m68k_cpu_reset_hold() calls floatx80_default_nan(NULL) to get the NaN bit pattern to reset the FPU registers. This works because it happens that our implementation of floatx80_default_nan() doesn't actually look at the float_status pointer except for TARGET_MIPS. However, this isn't guaranteed, and to be able to remove the ifdef in floatx80_default_nan() we're going to need a real float_status here.
Rearrange m68k_cpu_reset_hold() so that we initialize env->fp_status earlier, and thus can pass it to floatx80_default_nan().
--- target/m68k/cpu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
target/m68k/cpu.c +7 -5
@@ -76,7 +76,7 @@ static void m68k_cpu_reset_hold(Object *obj, ResetType type)CPUState *cs =CPU (obj);M68kCPUClass *mcc =M68K_CPU_GET_CLASS (obj);CPUM68KState *env =cpu_env (cs); -floatx80 nan =floatx80_default_nan (NULL ); +floatx80 nan;int i;if (mcc->parent_phases.hold) {
@@ -89,10 +89,6 @@ static void m68k_cpu_reset_hold(Object *obj, ResetType type)#else cpu_m68k_set_sr (env,SR_S |SR_I );#endif -for (i =0 ; i <8 ; i++) { - env->fregs[i].d = nan; - } -cpu_m68k_set_fpcr (env,0 );/* * M68000 FAMILY PROGRAMMER'S REFERENCE MANUAL * 3.4 FLOATING-POINT INSTRUCTION DETAILS
@@ -109,6 +105,12 @@ static void m68k_cpu_reset_hold(Object *obj, ResetType type)* preceding paragraph for nonsignaling NaNs. */ set_float_2nan_prop_rule (float_2nan_prop_ab, &env->fp_status); + + nan =floatx80_default_nan (&env->fp_status); +for (i =0 ; i <8 ; i++) { + env->fregs[i].d = nan; + } +cpu_m68k_set_fpcr (env,0 ); env->fpsr =0 ;/* TODO: We should set PC from the interrupt vector. */
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 27/54] target/m68k: Don't pass NULL float_status to floatx80_default_nan()
Quoted 8 lines · Peter Maydell
Currently
m68k_cpu_reset_hold()callsfloatx80_default_nan(NULL)to get the NaN bit pattern to reset the FPU registers. This works because it happens that our implementation offloatx80_default_nan()doesn't actually look at thefloat_statuspointer except forTARGET_MIPS. However, this isn't guaranteed, and to be able to remove the ifdef infloatx80_default_nan()we're going to need a realfloat_statushere.
Quoted 7 lines
Rearrange
m68k_cpu_reset_hold()so that we initializeenv->fp_statusearlier, and thus can pass it tofloatx80_default_nan().Signed-off-by Peter Maydell<[email protected]>--- target/m68k/cpu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
r~
PATCH v2 28/54 softfloat: Create floatx80 default NaN from parts64_default_nan
In reply to Peter MaydellWe create our 128-bit default NaN by calling parts64_default_nan() and then adjusting the result. We can do the same trick for creating the floatx80 default NaN, which lets us drop a target ifdef.
floatx80 is used only by:
i386
m68k
arm nwfpe old floating-point emulation emulation support
(which is essentially dead, especially the parts involving floatx80)
PPC (only in the xsrqpxp instruction, which just rounds an input
value by converting to floatx80 and back, so will never generate the default NaN)
The floatx80 default NaN as currently implemented is:
m68k: sign = 0, exp = 1...1, int = 1, frac = 1....1
i386: sign = 1, exp = 1...1, int = 1, frac = 10...0
These are the same as the parts64_default_nan for these architectures.
This is technically a possible behaviour change for arm linux-user nwfpe emulation emulation, because the default NaN will now have the sign bit clear. But we were already generating a different floatx80 default NaN from the real kernel emulation we are supposedly following, which appears to use an all-bits-1 value:
https://elixir.bootlin.com/linux/v6.12/source/arch/arm/nwfpe/softfloat-specialize#L267
This won't affect the only "real" use of the nwfpe emulation, which is ancient binaries that used it as part of the old floating point calling convention; that only uses loads and stores of 32 and 64 bit floats, not any of the floatx80 behaviour the original hardware had. We also get the nwfpe float64 default NaN value wrong:
https://elixir.bootlin.com/linux/v6.12/source/arch/arm/nwfpe/softfloat-specialize#L166
so if we ever cared about this obscure corner the right fix would be to correct that so nwfpe used its own default-NaN setting rather than the Arm VFP one.
--- fpu/softfloat-specialize.c.inc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
fpu/softfloat-specialize.c.inc +10 -10
@@ -227,17 +227,17 @@ static void parts128_silence_nan(FloatParts128 *p, float_status *status) floatx80 floatx80_default_nan(float_status *status) { floatx80 r; + /* + * Extrapolate from the choices made by parts64_default_nan to fill + * in the floatx80 format. We assume that floatx80's explicit + * integer bit is always set (this is true for i386 and m68k, + * which are the only real users of this format). + */ + FloatParts64 p64; + parts64_default_nan(&p64, status); - /* None of the targets that have snan_bit_is_one use floatx80. */ - assert(!snan_bit_is_one(status)); -#if defined(TARGET_M68K) - r.low = UINT64_C(0xFFFFFFFFFFFFFFFF); - r.high = 0x7FFF; -#else - /* X86 */ - r.low = UINT64_C(0xC000000000000000); - r.high = 0xFFFF; -#endif + r.high = 0x7FFF | (p64.sign << 15); + r.low = (1ULL << DECOMPOSED_BINARY_POINT) | p64.frac; return r; }
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 28/54] softfloat: Create floatx80 default NaN from parts64_default_nan
Quoted 36 lines · Peter Maydell
We create our 128-bit default NaN by calling
parts64_default_nan()and then adjusting the result. We can do the same trick for creating the floatx80 default NaN, which lets us drop a target ifdef.floatx80 is used only by:
i386
m68k
arm nwfpe old floating-point emulation emulation support
(which is essentially dead, especially the parts involving floatx80)
PPC (only in the xsrqpxp instruction, which just rounds an input
value by converting to floatx80 and back, so will never generate the default NaN)The floatx80 default NaN as currently implemented is:
m68k: sign = 0, exp = 1...1, int = 1, frac = 1....1
i386: sign = 1, exp = 1...1, int = 1, frac = 10...0These are the same as the
parts64_default_nanfor these architectures.This is technically a possible behaviour change for arm linux-user nwfpe emulation emulation, because the default NaN will now have the sign bit clear. But we were already generating a different floatx80 default NaN from the real kernel emulation we are supposedly following, which appears to use an all-bits-1 value:
https://elixir.bootlin.com/linux/v6.12/source/arch/arm/nwfpe/softfloat-specialize#L267This won't affect the only "real" use of the nwfpe emulation, which is ancient binaries that used it as part of the old floating point calling convention; that only uses loads and stores of 32 and 64 bit floats, not any of the floatx80 behaviour the original hardware had. We also get the nwfpe float64 default NaN value wrong:
https://elixir.bootlin.com/linux/v6.12/source/arch/arm/nwfpe/softfloat-specialize#L166
so if we ever cared about this obscure corner the right fix would be to correct that so nwfpe used its own default-NaN setting rather than the Arm VFP one.
Quoted 4 lines
Signed-off-by Peter Maydell<[email protected]>--- fpu/softfloat-specialize.c.inc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
r~
PATCH v2 29/54 target/loongarch: Use normal float_status in fclass_s and fclass_d helpers
In reply to Peter MaydellIn target/loongarch's helper_fclass_s() and helper_fclass_d() we pass a zero-initialized float_status struct to float32_is_quiet_nan() and float64_is_quiet_nan(), with the cryptic comment "for snan_bit_is_one".
This pattern appears to have been copied from target/riscv, where it is used because the functions there do not have ready access to the CPU state struct. The comment presumably refers to the fact that the main reason the is_quiet_nan() functions want the float_state is because they want to know about the snan_bit_is_one config.
In the loongarch helpers, though, we have the CPU state struct to hand. Use the usual env->fp_status here. This avoids our needing to track that we need to update the initializer of the local float_status structs when the core softfloat code adds new options for targets to configure their behaviour.
---
It would be nice to get the riscv fclass_s etc also not to use a stunt float_status, but plumbing the env through would require fiddling with the macro magic, and in practice for the is_quiet_nan functions it works out OK.
--- target/loongarch/tcg/fpu_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
target/loongarch/tcg/fpu_helper.c +2 -4
@@ -359,8 +359,7 @@ uint64_t helper_fclass_s(CPULoongArchState *env, uint64_t fj) }else if (float32_is_zero_or_denormal (f)) {return sign ?1 <<4 :1 <<8 ; }else if (float32_is_any_nan (f)) { -float_status s = { };/* for snan_bit_is_one */ -return float32_is_quiet_nan (f, &s) ?1 <<1 :1 <<0 ; +return float32_is_quiet_nan (f, &env->fp_status) ?1 <<1 :1 <<0 ; }else {return sign ?1 <<3 :1 <<7 ; }
@@ -378,8 +377,7 @@ uint64_t helper_fclass_d(CPULoongArchState *env, uint64_t fj) }else if (float64_is_zero_or_denormal (f)) {return sign ?1 <<4 :1 <<8 ; }else if (float64_is_any_nan (f)) { -float_status s = { };/* for snan_bit_is_one */ -return float64_is_quiet_nan (f, &s) ?1 <<1 :1 <<0 ; +return float64_is_quiet_nan (f, &env->fp_status) ?1 <<1 :1 <<0 ; }else {return sign ?1 <<3 :1 <<7 ; }
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 29/54] target/loongarch: Use normal float_status in fclass_s and fclass_d helpers
Quoted 18 lines · Peter Maydell
In target/loongarch's
helper_fclass_s()andhelper_fclass_d()we pass a zero-initializedfloat_statusstruct tofloat32_is_quiet_nan()andfloat64_is_quiet_nan(), with the cryptic comment "forsnan_bit_is_one".This pattern appears to have been copied from target/riscv, where it is used because the functions there do not have ready access to the CPU state struct. The comment presumably refers to the fact that the main reason the
is_quiet_nan()functions want thefloat_stateis because they want to know about thesnan_bit_is_oneconfig.In the loongarch helpers, though, we have the CPU state struct to hand. Use the usual
env->fp_statushere. This avoids our needing to track that we need to update the initializer of the localfloat_statusstructs when the core softfloat code adds new options for targets to configure their behaviour.Signed-off-by Peter Maydell <[email protected]>
Quoted 8 lines
---
It would be nice to get the riscvfclass_setc also not to use a stuntfloat_status, but plumbing the env through would require fiddling with the macro magic, and in practice for theis_quiet_nanfunctions it works out OK.--- target/loongarch/tcg/fpu_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
r~
PATCH v2 30/54 target/m68k: In frem helper, initialize local float_status from env->fp_status
In reply to Peter MaydellIn the frem helper, we have a local float_status because we want to execute the floatx80_div() with a custom rounding mode. Instead of zero-initializing the local float_status and then having to set it up with the m68k standard behaviour (including the NaN propagation rule and copying the rounding precision from env->fp_status), initialize it as a complete copy of env->fp_status. This will avoid our having to add new code in this function for every new config knob we add to fp_status.
--- target/m68k/fpu_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
target/m68k/fpu_helper.c +2 -4
@@ -615,15 +615,13 @@ void HELPER(frem)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) fp_rem =floatx80_rem (val1->d, val0->d, &env->fp_status);if (!floatx80_is_any_nan (fp_rem)) { -float_status fp_status = { }; +/* Use local temporary fp_status to set different rounding mode */ +float_status fp_status = env->fp_status;uint32_t quotient;int sign;/* Calculate quotient directly using round to nearest mode */ -set_float_2nan_prop_rule (float_2nan_prop_ab, &fp_status);set_float_rounding_mode (float_round_nearest_even, &fp_status); -set_floatx80_rounding_precision ( -get_floatx80_rounding_precision (&env->fp_status), &fp_status); fp_quot.d =floatx80_div (val1->d, val0->d, &fp_status); sign =extractFloatx80Sign (fp_quot.d);
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 30/54] target/m68k: In frem helper, initialize local float_status from env->fp_status
Quoted 9 lines · Peter Maydell
In the frem helper, we have a local
float_statusbecause we want to execute thefloatx80_div()with a custom rounding mode. Instead of zero-initializing the localfloat_statusand then having to set it up with the m68k standard behaviour (including the NaN propagation rule and copying the rounding precision fromenv->fp_status), initialize it as a complete copy ofenv->fp_status. This will avoid our having to add new code in this function for every new config knob we add tofp_status.
Quoted 4 lines
Signed-off-by Peter Maydell<[email protected]>--- target/m68k/fpu_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
r~
PATCH v2 31/54 target/m68k: Init local float_status from env fp_status in gdb get/set reg
In reply to Peter MaydellIn cf_fpu_gdb_get_reg() and cf_fpu_gdb_set_reg() we do the conversion from float64 to floatx80 using a scratch float_status, because we don't want the conversion to affect the CPU's floating point exception status. Currently we use a zero-initialized float_status. This will get steadily more awkward as we add config knobs to float_status that the target must initialize. Avoid having to add any of that configuration here by instead initializing our local float_status from the env->fp_status.
--- target/m68k/helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
target/m68k/helper.c +4 -2
@@ -36,7 +36,8 @@ static int cf_fpu_gdb_get_reg(CPUState *cs, GByteArray *mem_buf, int n)CPUM68KState *env = &cpu->env;if (n <8 ) { -float_status s = {}; +/* Use scratch float_status so any exceptions don't change CPU state */ +float_status s = env->fp_status;return gdb_get_reg64 (mem_buf,floatx80_to_float64 (env->fregs[n].d, &s)); }switch (n) {
@@ -56,7 +57,8 @@ static int cf_fpu_gdb_set_reg(CPUState *cs, uint8_t *mem_buf, int n)CPUM68KState *env = &cpu->env;if (n <8 ) { -float_status s = {}; +/* Use scratch float_status so any exceptions don't change CPU state */ +float_status s = env->fp_status; env->fregs[n].d =float64_to_floatx80 (ldq_be_p (mem_buf), &s);return 8 ; }
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 31/54] target/m68k: Init local float_status from env fp_status in gdb get/set reg
Quoted 9 lines · Peter Maydell
In
cf_fpu_gdb_get_reg()andcf_fpu_gdb_set_reg()we do the conversion from float64 to floatx80 using a scratchfloat_status, because we don't want the conversion to affect the CPU's floating point exception status. Currently we use a zero-initializedfloat_status. This will get steadily more awkward as we add config knobs tofloat_statusthat the target must initialize. Avoid having to add any of that configuration here by instead initializing our localfloat_statusfrom theenv->fp_status.
Quoted 4 lines
Signed-off-by Peter Maydell<[email protected]>--- target/m68k/helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
r~
PATCH v2 32/54 target/sparc: Initialize local scratch float_status from env->fp_status
In reply to Peter MaydellIn the helper functions flcmps and flcmpd we use a scratch float_status so that we don't change the CPU state if the comparison raises any floating point exception flags. Instead of zero-initializing this scratch float_status, initialize it as a copy of env->fp_status. This avoids the need to explicitly initialize settings like the NaN propagation rule or others we might add to softfloat in future.
To do this we need to pass the CPU env pointer in to the helper.
--- target/sparc/helper.h | 4 ++-- target/sparc/fop_helper.c | 8 ++++---- target/sparc/translate.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-)
target/sparc/helper.h +2 -2
@@ -51,8 +51,8 @@ DEF_HELPER_FLAGS_3(fcmpd, TCG_CALL_NO_WG, i32, env, f64, f64) DEF_HELPER_FLAGS_3(fcmped, TCG_CALL_NO_WG, i32, env, f64, f64) DEF_HELPER_FLAGS_3(fcmpq, TCG_CALL_NO_WG, i32, env, i128, i128) DEF_HELPER_FLAGS_3(fcmpeq, TCG_CALL_NO_WG, i32, env, i128, i128) -DEF_HELPER_FLAGS_2(flcmps, TCG_CALL_NO_RWG_SE, i32, f32, f32) -DEF_HELPER_FLAGS_2(flcmpd, TCG_CALL_NO_RWG_SE, i32, f64, f64) +DEF_HELPER_FLAGS_3(flcmps, TCG_CALL_NO_RWG_SE, i32, env, f32, f32) +DEF_HELPER_FLAGS_3(flcmpd, TCG_CALL_NO_RWG_SE, i32, env, f64, f64) DEF_HELPER_2(raise_exception, noreturn, env, int)DEF_HELPER_FLAGS_3 (faddd,TCG_CALL_NO_WG , f64, env, f64, f64)
target/sparc/fop_helper.c +4 -4
@@ -490,13 +490,13 @@ uint32_t helper_fcmpeq(CPUSPARCState *env, Int128 src1, Int128 src2)return finish_fcmp (env, r,GETPC ()); } -uint32_t helper_flcmps (float32 src1,float32 src2) +uint32_t helper_flcmps (CPUSPARCState *env,float32 src1,float32 src2) {/* * FLCMP never raises an exception nor modifies any FSR fields. * Perform the comparison with a dummy fp environment. */ -float_status discard = { }; +float_status discard = env->fp_status;FloatRelation r;set_float_2nan_prop_rule (float_2nan_prop_s_ba, &discard);
@@ -518,9 +518,9 @@ uint32_t helper_flcmps(float32 src1, float32 src2)g_assert_not_reached (); } -uint32_t helper_flcmpd (float64 src1,float64 src2) +uint32_t helper_flcmpd (CPUSPARCState *env,float64 src1,float64 src2) { -float_status discard = { }; +float_status discard = env->fp_status;FloatRelation r;set_float_2nan_prop_rule (float_2nan_prop_s_ba, &discard);
target/sparc/translate.c +2 -2
@@ -5584,7 +5584,7 @@ static bool trans_FLCMPs(DisasContext *dc, arg_FLCMPs *a) src1 =gen_load_fpr_F (dc, a->rs1); src2 =gen_load_fpr_F (dc, a->rs2); -gen_helper_flcmps (cpu_fcc[a->cc], src1, src2); +gen_helper_flcmps (cpu_fcc[a->cc], tcg_env, src1, src2);return advance_pc (dc); }
@@ -5601,7 +5601,7 @@ static bool trans_FLCMPd(DisasContext *dc, arg_FLCMPd *a) src1 =gen_load_fpr_D (dc, a->rs1); src2 =gen_load_fpr_D (dc, a->rs2); -gen_helper_flcmpd (cpu_fcc[a->cc], src1, src2); +gen_helper_flcmpd (cpu_fcc[a->cc], tcg_env, src1, src2);return advance_pc (dc); }
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 32/54] target/sparc: Initialize local scratch float_status from env->fp_status
Quoted 7 lines · Peter Maydell
In the helper functions flcmps and flcmpd we use a scratch
float_statusso that we don't change the CPU state if the comparison raises any floating point exception flags. Instead of zero-initializing this scratchfloat_status, initialize it as a copy ofenv->fp_status. This avoids the need to explicitly initialize settings like the NaN propagation rule or others we might add to softfloat in future.
Quoted 8 lines
To do this we need to pass the CPU env pointer in to the helper.
Signed-off-by Peter Maydell<[email protected]>--- target/sparc/helper.h | 4 ++-- target/sparc/fop_helper.c | 8 ++++---- target/sparc/translate.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-)
r~
PATCH v2 33/54 target/ppc: Use env->fp_status in helper_compute_fprf functions
In reply to Peter MaydellIn the helper_compute_fprf functions, we pass a dummy float_status in to the is_signaling_nan() function. This is unnecessary, because we have convenient access to the CPU env pointer here and that is already set up with the correct values for the snan_bit_is_one and no_signaling_nans config settings. is_signaling_nan() doesn't ever update the fp_status with any exception flags, so there is no reason not to use env->fp_status here.
Use env->fp_status instead of the dummy fp_status.
--- target/ppc/fpu_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target/ppc/fpu_helper.c +1 -2
@@ -155,8 +155,7 @@ void helper_compute_fprf_##tp(CPUPPCState *env, tp arg) \ } else if (tp##_is_infinity(arg)) { \ fprf = neg ?0x09 <<FPSCR_FPRF :0x05 <<FPSCR_FPRF ; \ }else { \ -float_status dummy = { };/* snan_bit_is_one = 0 */ \ - if (tp##_is_signaling_nan(arg, &dummy)) { \ + if (tp##_is_signaling_nan(arg, &env->fp_status)) { \ fprf =0x00 <<FPSCR_FPRF ; \ }else { \ fprf =0x11 <<FPSCR_FPRF ; \
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 33/54] target/ppc: Use env->fp_status in helper_compute_fprf functions
Quoted 8 lines · Peter Maydell
In the
helper_compute_fprffunctions, we pass a dummyfloat_statusin to theis_signaling_nan()function. This is unnecessary, because we have convenient access to the CPU env pointer here and that is already set up with the correct values for thesnan_bit_is_oneandno_signaling_nansconfig settings.is_signaling_nan()doesn't ever update thefp_statuswith any exception flags, so there is no reason not to useenv->fp_statushere.
Quoted 6 lines
Use
env->fp_statusinstead of the dummyfp_status.Signed-off-by Peter Maydell<[email protected]>--- target/ppc/fpu_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
r~
PATCH v2 34/54 fpu: Allow runtime choice of default NaN value
In reply to Peter MaydellCurrently we hardcode the default NaN value in parts64_default_nan() using a compile-time ifdef ladder. This is awkward for two cases:
* for single-QEMU-binary we can't hard-code target-specifics like this
* for Arm FEAT_AFP the default NaN value depends on FPCR.AH (specifically the sign bit is different)
Add a field to float_status to specify the default NaN value; fall back to the old ifdef behaviour if these are not set.
The default NaN value is specified by setting a uint8_t to a pattern corresponding to the sign and upper fraction parts of the NaN; the lower bits of the fraction are set from bit 0 of the pattern.
--- include/fpu/softfloat-helpers.h | 11 +++++++ include/fpu/softfloat-types.h | 10 ++++++ fpu/softfloat-specialize.c.inc | 55 ++++++++++++++++++++------------- 3 files changed, 54 insertions(+), 22 deletions(-)
include/fpu/softfloat-helpers.h +11 -0
@@ -93,6 +93,12 @@ static inline void set_float_infzeronan_rule(FloatInfZeroNaNRule rule, status->float_infzeronan_rule = rule; } +static inline void set_float_default_nan_pattern (uint8_t dnan_pattern, +float_status *status) +{ + status->default_nan_pattern = dnan_pattern; +} +static inline void set_flush_to_zero (bool val,float_status *status) { status->flush_to_zero = val;
@@ -154,6 +160,11 @@ static inline FloatInfZeroNaNRule get_float_infzeronan_rule(float_status *statusreturn status->float_infzeronan_rule; } +static inline uint8_t get_float_default_nan_pattern (float_status *status) +{ +return status->default_nan_pattern; +} +static inline bool get_flush_to_zero (float_status *status) {return status->flush_to_zero;
include/fpu/softfloat-types.h +10 -0
@@ -303,6 +303,16 @@ typedef struct float_status {/* should denormalised inputs go to zero and set the input_denormal flag? */ bool flush_inputs_to_zero;bool default_nan_mode; +/* +* The pattern to use for the default NaN. Here the high bit specifies +* the default NaN's sign bit, and bits 6..0 specify the high bits of the +* fractional part. The low bits of the fractional part are copies of bit 0. +* The exponent of the default NaN is (as for any NaN) always all 1s. +* Note that a value of 0 here is not a valid NaN. The target must set +* this to the correct non-zero value, or we will assert when trying to +* create a default NaN. +*/ +uint8_t default_nan_pattern;/* * The flags below are not used on all specializations and may * constant fold away (see snan_bit_is_one()/no_signalling_nans() in
fpu/softfloat-specialize.c.inc +33 -22
68 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 34/54] fpu: Allow runtime choice of default NaN value
Quoted 14 lines · Peter Maydell
Currently we hardcode the default NaN value in
parts64_default_nan()using a compile-time ifdef ladder. This is awkward for two cases:
* for single-QEMU-binary we can't hard-code target-specifics like this
* for ArmFEAT_AFPthe default NaN value depends on FPCR.AH (specifically the sign bit is different)Add a field to
float_statusto specify the default NaN value; fall back to the old ifdef behaviour if these are not set.The default NaN value is specified by setting a
uint8_tto a pattern corresponding to the sign and upper fraction parts of the NaN; the lower bits of the fraction are set from bit 0 of the pattern.
Quoted 6 lines
Signed-off-by Peter Maydell<[email protected]>--- include/fpu/softfloat-helpers.h | 11 +++++++ include/fpu/softfloat-types.h | 10 ++++++ fpu/softfloat-specialize.c.inc | 55 ++++++++++++++++++++------------- 3 files changed, 54 insertions(+), 22 deletions(-)
r~
PATCH v2 35/54 tests/fp: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for the tests/fp code.
--- tests/fp/fp-bench.c | 1 + tests/fp/fp-test-log2.c | 1 + tests/fp/fp-test.c | 1 + 3 files changed, 3 insertions(+)
tests/fp/fp-bench.c +1 -0
@@ -495,6 +495,7 @@ static void run_bench(void)set_float_2nan_prop_rule (float_2nan_prop_s_ab, &soft_status);set_float_3nan_prop_rule (float_3nan_prop_s_cab, &soft_status);set_float_infzeronan_rule (float_infzeronan_dnan_if_qnan, &soft_status); +set_float_default_nan_pattern (0b01000000 , &soft_status); f = bench_funcs[operation][precision];g_assert (f);
tests/fp/fp-test-log2.c +1 -0
@@ -71,6 +71,7 @@ int main(int ac, char **av)int i;set_float_2nan_prop_rule (float_2nan_prop_s_ab, &qsf); +set_float_default_nan_pattern (0b01000000 , &qsf);set_float_rounding_mode (float_round_nearest_even, &qsf); test.d =0.0 ;
tests/fp/fp-test.c +1 -0
@@ -941,6 +941,7 @@ void run_test(void)*/ set_float_2nan_prop_rule (float_2nan_prop_s_ab, &qsf);set_float_3nan_prop_rule (float_3nan_prop_s_cab, &qsf); +set_float_default_nan_pattern (0b01000000 , &qsf);set_float_infzeronan_rule (float_infzeronan_dnan_if_qnan, &qsf);genCases_setLevel (test_level);
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 35/54] tests/fp: Set default NaN pattern explicitly
Quoted 8 lines · Peter Maydell
Set the default NaN pattern explicitly for the tests/fp code.
Signed-off-by Peter Maydell <[email protected]>--- tests/fp/fp-bench.c | 1 + tests/fp/fp-test-log2.c | 1 + tests/fp/fp-test.c | 1 + 3 files changed, 3 insertions(+)
r~
PATCH v2 36/54 target/microblaze: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly, and remove the ifdef from parts64_default_nan().
--- target/microblaze/cpu.c | 2 ++ fpu/softfloat-specialize.c.inc | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-)
target/microblaze/cpu.c +2 -0
@@ -207,6 +207,8 @@ static void mb_cpu_reset_hold(Object *obj, ResetType type)* this architecture. */ set_float_2nan_prop_rule (float_2nan_prop_x87, &env->fp_status); +/* Default NaN: sign bit set, most significant frac bit set */ +set_float_default_nan_pattern (0b11000000 , &env->fp_status);#if defined(CONFIG_USER_ONLY )/* start in user mode with interrupts enabled. */
fpu/softfloat-specialize.c.inc +1 -2
@@ -139,8 +139,7 @@ static void parts64_default_nan(FloatParts64 *p, float_status *status) #if defined(TARGET_SPARC) || defined(TARGET_M68K) /* Sign bit clear, all frac bits set */ dnan_pattern = 0b01111111; -#elif defined(TARGET_I386) || defined(TARGET_X86_64) \ - || defined(TARGET_MICROBLAZE) +#elif defined(TARGET_I386) || defined(TARGET_X86_64) /* Sign bit set, most significant frac bit set */ dnan_pattern = 0b11000000; #elif defined(TARGET_HPPA)
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 36/54] target/microblaze: Set default NaN pattern explicitly
Quoted 8 lines · Peter Maydell
Set the default NaN pattern explicitly, and remove the ifdef from
parts64_default_nan().Signed-off-by Peter Maydell <[email protected]>--- target/microblaze/cpu.c | 2 ++ fpu/softfloat-specialize.c.inc | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-)
r~
Quoted 28 lines
target/microblaze/cpu.c +2
-0@@ -207,6 +207,8 @@ static void mb_cpu_reset_hold(Object *obj, ResetType type)* this architecture. */ set_float_2nan_prop_rule (float_2nan_prop_x87, &env->fp_status); +/* Default NaN: sign bit set, most significant frac bit set */ +set_float_default_nan_pattern (0b11000000 , &env->fp_status);#if defined(CONFIG_USER_ONLY )/* start in user mode with interrupts enabled. */ fpu/softfloat-specialize.c.inc +1
-2@@ -139,8 +139,7 @@ static void parts64_default_nan(FloatParts64 *p, float_status *status) #if defined(TARGET_SPARC) || defined(TARGET_M68K) /* Sign bit clear, all frac bits set */ dnan_pattern = 0b01111111; -#elif defined(TARGET_I386) || defined(TARGET_X86_64) \ - || defined(TARGET_MICROBLAZE) +#elif defined(TARGET_I386) || defined(TARGET_X86_64) /* Sign bit set, most significant frac bit set */ dnan_pattern = 0b11000000; #elif defined(TARGET_HPPA)
PATCH v2 37/54 target/i386: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly, and remove the ifdef from parts64_default_nan().
--- target/i386/tcg/fpu_helper.c | 4 ++++ fpu/softfloat-specialize.c.inc | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-)
target/i386/tcg/fpu_helper.c +4 -0
@@ -181,6 +181,10 @@ void cpu_init_fp_statuses(CPUX86State *env)*/ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->sse_status);set_float_3nan_prop_rule (float_3nan_prop_abc, &env->sse_status); +/* Default NaN: sign bit set, most significant frac bit set */ +set_float_default_nan_pattern (0b11000000 , &env->fp_status); +set_float_default_nan_pattern (0b11000000 , &env->mmx_status); +set_float_default_nan_pattern (0b11000000 , &env->sse_status); }static inline uint8_t save_exception_flags (CPUX86State *env)
fpu/softfloat-specialize.c.inc +0 -3
@@ -139,9 +139,6 @@ static void parts64_default_nan(FloatParts64 *p, float_status *status) #if defined(TARGET_SPARC) || defined(TARGET_M68K) /* Sign bit clear, all frac bits set */ dnan_pattern = 0b01111111; -#elif defined(TARGET_I386) || defined(TARGET_X86_64) - /* Sign bit set, most significant frac bit set */ - dnan_pattern = 0b11000000; #elif defined(TARGET_HPPA) /* Sign bit clear, msb-1 frac bit set */ dnan_pattern = 0b00100000;
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 37/54] target/i386: Set default NaN pattern explicitly
Quoted 9 lines · Peter Maydell
Set the default NaN pattern explicitly, and remove the ifdef from
parts64_default_nan().Signed-off-by Peter Maydell <[email protected]>--- target/i386/tcg/fpu_helper.c | 4 ++++ fpu/softfloat-specialize.c.inc | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-)
r~
Quoted 29 lines
target/i386/tcg/fpu_helper.c +4
-0@@ -181,6 +181,10 @@ void cpu_init_fp_statuses(CPUX86State *env)*/ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->sse_status);set_float_3nan_prop_rule (float_3nan_prop_abc, &env->sse_status); +/* Default NaN: sign bit set, most significant frac bit set */ +set_float_default_nan_pattern (0b11000000 , &env->fp_status); +set_float_default_nan_pattern (0b11000000 , &env->mmx_status); +set_float_default_nan_pattern (0b11000000 , &env->sse_status); }static inline uint8_t save_exception_flags (CPUX86State *env)fpu/softfloat-specialize.c.inc +0
-3@@ -139,9 +139,6 @@ static void parts64_default_nan(FloatParts64 *p, float_status *status) #if defined(TARGET_SPARC) || defined(TARGET_M68K) /* Sign bit clear, all frac bits set */ dnan_pattern = 0b01111111; -#elif defined(TARGET_I386) || defined(TARGET_X86_64) - /* Sign bit set, most significant frac bit set */ - dnan_pattern = 0b11000000; #elif defined(TARGET_HPPA) /* Sign bit clear, msb-1 frac bit set */ dnan_pattern = 0b00100000;
PATCH v2 38/54 target/hppa: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly, and remove the ifdef from parts64_default_nan().
--- target/hppa/fpu_helper.c | 2 ++ fpu/softfloat-specialize.c.inc | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-)
target/hppa/fpu_helper.c +2 -0
@@ -65,6 +65,8 @@ void HELPER(loaded_fr0)(CPUHPPAState *env)set_float_3nan_prop_rule (float_3nan_prop_abc, &env->fp_status);/* For inf * 0 + NaN, return the input NaN */ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status); +/* Default NaN: sign bit clear, msb-1 frac bit set */ +set_float_default_nan_pattern (0b00100000 , &env->fp_status); }void cpu_hppa_loaded_fr0 (CPUHPPAState *env)
fpu/softfloat-specialize.c.inc +0 -3
@@ -139,9 +139,6 @@ static void parts64_default_nan(FloatParts64 *p, float_status *status) #if defined(TARGET_SPARC) || defined(TARGET_M68K) /* Sign bit clear, all frac bits set */ dnan_pattern = 0b01111111; -#elif defined(TARGET_HPPA) - /* Sign bit clear, msb-1 frac bit set */ - dnan_pattern = 0b00100000; #elif defined(TARGET_HEXAGON) /* Sign bit set, all frac bits set. */ dnan_pattern = 0b11111111;
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 38/54] target/hppa: Set default NaN pattern explicitly
Quoted 8 lines · Peter Maydell
Set the default NaN pattern explicitly, and remove the ifdef from
parts64_default_nan().Signed-off-by Peter Maydell <[email protected]>--- target/hppa/fpu_helper.c | 2 ++ fpu/softfloat-specialize.c.inc | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-)
r~
Quoted 28 lines
target/hppa/fpu_helper.c +2
-0@@ -65,6 +65,8 @@ void HELPER(loaded_fr0)(CPUHPPAState *env)set_float_3nan_prop_rule (float_3nan_prop_abc, &env->fp_status);/* For inf * 0 + NaN, return the input NaN */ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status); +/* Default NaN: sign bit clear, msb-1 frac bit set */ +set_float_default_nan_pattern (0b00100000 , &env->fp_status); }void cpu_hppa_loaded_fr0 (CPUHPPAState *env)fpu/softfloat-specialize.c.inc +0
-3@@ -139,9 +139,6 @@ static void parts64_default_nan(FloatParts64 *p, float_status *status) #if defined(TARGET_SPARC) || defined(TARGET_M68K) /* Sign bit clear, all frac bits set */ dnan_pattern = 0b01111111; -#elif defined(TARGET_HPPA) - /* Sign bit clear, msb-1 frac bit set */ - dnan_pattern = 0b00100000; #elif defined(TARGET_HEXAGON) /* Sign bit set, all frac bits set. */ dnan_pattern = 0b11111111;
PATCH v2 39/54 target/alpha: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for the alpha target.
--- target/alpha/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
target/alpha/cpu.c +2 -0
@@ -199,6 +199,8 @@ static void alpha_cpu_initfn(Object *obj)* operand in Fa. That is float_2nan_prop_ba. */ set_float_2nan_prop_rule (float_2nan_prop_x87, &env->fp_status); +/* Default NaN: sign bit clear, msb frac bit set */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status);#if defined(CONFIG_USER_ONLY ) env->flags =ENV_FLAG_PS_USER |ENV_FLAG_FEN ; cpu_alpha_store_fpcr(env, (uint64_t)(FPCR_INVD | FPCR_DZED | FPCR_OVFD
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 39/54] target/alpha: Set default NaN pattern explicitly
Quoted 6 lines · Peter Maydell
Set the default NaN pattern explicitly for the alpha target.
Signed-off-by Peter Maydell <[email protected]>--- target/alpha/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
r~
Quoted 14 lines
target/alpha/cpu.c +2
-0@@ -199,6 +199,8 @@ static void alpha_cpu_initfn(Object *obj)* operand in Fa. That is float_2nan_prop_ba. */ set_float_2nan_prop_rule (float_2nan_prop_x87, &env->fp_status); +/* Default NaN: sign bit clear, msb frac bit set */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status);#if defined(CONFIG_USER_ONLY ) env->flags =ENV_FLAG_PS_USER |ENV_FLAG_FEN ; cpu_alpha_store_fpcr(env, (uint64_t)(FPCR_INVD | FPCR_DZED | FPCR_OVFD
PATCH v2 40/54 target/arm: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for the arm target. This includes setting it for the old linux-user nwfpe emulation. For nwfpe, our default doesn't match the real kernel, but we avoid making a behaviour change in this commit.
--- linux-user/arm/nwfpe/fpa11.c | 5 +++++ target/arm/cpu.c | 2 ++ 2 files changed, 7 insertions(+)
linux-user/arm/nwfpe/fpa11.c +5 -0
@@ -69,6 +69,11 @@ void resetFPA11(void)* this late date. */ set_float_2nan_prop_rule (float_2nan_prop_s_ab, &fpa11->fp_status); +/* +* Use the same default NaN value as Arm VFP. This doesn't match +* the Linux kernel's nwfpe emulation, which uses an all-1s value. +*/ +set_float_default_nan_pattern (0b01000000 , &fpa11->fp_status); }void SetRoundingMode (const unsigned int opcode)
target/arm/cpu.c +2 -0
@@ -179,6 +179,7 @@ void arm_register_el_change_hook(ARMCPU *cpu, ARMELChangeHookFn *hook,* the pseudocode function the arguments are in the order c, a, b. * * 0 * Inf + NaN returns the default NaN if the input NaN is quiet, * and the input NaN if it is signalling +* * Default NaN has sign bit clear, msb frac bit set */ static void arm_set_default_fp_behaviours (float_status *s) {
@@ -186,6 +187,7 @@ static void arm_set_default_fp_behaviours(float_status *s)set_float_2nan_prop_rule (float_2nan_prop_s_ab, s);set_float_3nan_prop_rule (float_3nan_prop_s_cab, s);set_float_infzeronan_rule (float_infzeronan_dnan_if_qnan, s); +set_float_default_nan_pattern (0b01000000 , s); }static void cp_reg_reset (gpointer key,gpointer value,gpointer opaque)
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 40/54] target/arm: Set default NaN pattern explicitly
Quoted 10 lines · Peter Maydell
Set the default NaN pattern explicitly for the arm target. This includes setting it for the old linux-user nwfpe emulation. For nwfpe, our default doesn't match the real kernel, but we avoid making a behaviour change in this commit.
Signed-off-by Peter Maydell <[email protected]>--- linux-user/arm/nwfpe/fpa11.c | 5 +++++ target/arm/cpu.c | 2 ++ 2 files changed, 7 insertions(+)
r~
PATCH v2 41/54 target/loongarch: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for loongarch.
--- target/loongarch/tcg/fpu_helper.c | 2 ++ 1 file changed, 2 insertions(+)
target/loongarch/tcg/fpu_helper.c +2 -0
@@ -38,6 +38,8 @@ void restore_fp_status(CPULoongArchState *env)*/ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status);set_float_3nan_prop_rule (float_3nan_prop_s_cab, &env->fp_status); +/* Default NaN: sign bit clear, msb frac bit set */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status); }int ieee_ex_to_loongarch (int xcpt)
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 41/54] target/loongarch: Set default NaN pattern explicitly
Quoted 6 lines · Peter Maydell
Set the default NaN pattern explicitly for loongarch.
Signed-off-by Peter Maydell <[email protected]>--- target/loongarch/tcg/fpu_helper.c | 2 ++ 1 file changed, 2 insertions(+)
r~
Quoted 14 lines
target/loongarch/tcg/fpu_helper.c +2
-0@@ -38,6 +38,8 @@ void restore_fp_status(CPULoongArchState *env)*/ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status);set_float_3nan_prop_rule (float_3nan_prop_s_cab, &env->fp_status); +/* Default NaN: sign bit clear, msb frac bit set */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status); }int ieee_ex_to_loongarch (int xcpt)
PATCH v2 42/54 target/m68k: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for m68k.
--- target/m68k/cpu.c | 2 ++ fpu/softfloat-specialize.c.inc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
target/m68k/cpu.c +2 -0
@@ -105,6 +105,8 @@ static void m68k_cpu_reset_hold(Object *obj, ResetType type)* preceding paragraph for nonsignaling NaNs. */ set_float_2nan_prop_rule (float_2nan_prop_ab, &env->fp_status); +/* Default NaN: sign bit clear, all frac bits set */ +set_float_default_nan_pattern (0b01111111 , &env->fp_status); nan =floatx80_default_nan (&env->fp_status);for (i =0 ; i <8 ; i++) {
fpu/softfloat-specialize.c.inc +1 -1
@@ -136,7 +136,7 @@ static void parts64_default_nan(FloatParts64 *p, float_status *status) uint8_t dnan_pattern = status->default_nan_pattern; if (dnan_pattern == 0) { -#if defined(TARGET_SPARC) || defined(TARGET_M68K) +#if defined(TARGET_SPARC) /* Sign bit clear, all frac bits set */ dnan_pattern = 0b01111111; #elif defined(TARGET_HEXAGON)
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 42/54] target/m68k: Set default NaN pattern explicitly
Quoted 7 lines · Peter Maydell
Set the default NaN pattern explicitly for m68k.
Signed-off-by Peter Maydell <[email protected]>--- target/m68k/cpu.c | 2 ++ fpu/softfloat-specialize.c.inc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
r~
Quoted 27 lines
target/m68k/cpu.c +2
-0@@ -105,6 +105,8 @@ static void m68k_cpu_reset_hold(Object *obj, ResetType type)* preceding paragraph for nonsignaling NaNs. */ set_float_2nan_prop_rule (float_2nan_prop_ab, &env->fp_status); +/* Default NaN: sign bit clear, all frac bits set */ +set_float_default_nan_pattern (0b01111111 , &env->fp_status); nan =floatx80_default_nan (&env->fp_status);for (i =0 ; i <8 ; i++) {fpu/softfloat-specialize.c.inc +1
-1@@ -136,7 +136,7 @@ static void parts64_default_nan(FloatParts64 *p, float_status *status) uint8_t dnan_pattern = status->default_nan_pattern; if (dnan_pattern == 0) { -#if defined(TARGET_SPARC) || defined(TARGET_M68K) +#if defined(TARGET_SPARC) /* Sign bit clear, all frac bits set */ dnan_pattern = 0b01111111; #elif defined(TARGET_HEXAGON)
PATCH v2 43/54 target/mips: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for MIPS. Note that this is our only target which currently changes the default NaN at runtime (which it was previously doing indirectly when it changed the snan_bit_is_one setting).
--- target/mips/fpu_helper.h | 7 +++++++ target/mips/msa.c | 3 +++ 2 files changed, 10 insertions(+)
target/mips/fpu_helper.h +7 -0
@@ -47,6 +47,13 @@ static inline void restore_snan_bit_mode(CPUMIPSState *env)set_float_infzeronan_rule (izn_rule, &env->active_fpu.fp_status); nan3_rule = nan2008 ? float_3nan_prop_s_cab : float_3nan_prop_s_abc;set_float_3nan_prop_rule (nan3_rule, &env->active_fpu.fp_status); +/* +* With nan2008, the default NaN value has the sign bit clear and the +* frac msb set; with the older mode, the sign bit is clear, and all +* frac bits except the msb are set. +*/ +set_float_default_nan_pattern (nan2008 ?0b01000000 :0b00111111 , + &env->active_fpu.fp_status); }
target/mips/msa.c +3 -0
@@ -81,4 +81,7 @@ void msa_reset(CPUMIPSState *env)/* Inf * 0 + NaN returns the input NaN */ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->active_tc.msa_fp_status); +/* Default NaN: sign bit clear, frac msb set */ +set_float_default_nan_pattern (0b01000000 , + &env->active_tc.msa_fp_status); }
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 43/54] target/mips: Set default NaN pattern explicitly
Quoted 10 lines · Peter Maydell
Set the default NaN pattern explicitly for MIPS. Note that this is our only target which currently changes the default NaN at runtime (which it was previously doing indirectly when it changed the
snan_bit_is_onesetting).Signed-off-by Peter Maydell <[email protected]>--- target/mips/fpu_helper.h | 7 +++++++ target/mips/msa.c | 3 +++ 2 files changed, 10 insertions(+)
r~
PATCH v2 44/54 target/openrisc: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for openrisc.
--- target/openrisc/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
target/openrisc/cpu.c +2 -0
@@ -111,6 +111,8 @@ static void openrisc_cpu_reset_hold(Object *obj, ResetType type)*/ set_float_2nan_prop_rule (float_2nan_prop_x87, &cpu->env.fp_status); +/* Default NaN: sign bit clear, frac msb set */ +set_float_default_nan_pattern (0b01000000 , &cpu->env.fp_status);#ifndef CONFIG_USER_ONLY cpu->env.picmr =0x00000000 ;
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 44/54] target/openrisc: Set default NaN pattern explicitly
Quoted 12 lines · Peter Maydell
Set the default NaN pattern explicitly for openrisc.
Signed-off-by Peter Maydell <[email protected]>--- target/openrisc/cpu.c | 2 ++ 1 file changed, 2 insertions(+)target/openrisc/cpu.c +0
-0
target/openrisc/cpu.c static void openrisc_cpu_reset_hold(Object *obj, ResetType type) · line 118
Quoted 8 lines
target/openrisc/cpu.c +2
-0@@ -111,6 +111,8 @@ static void openrisc_cpu_reset_hold(Object *obj, ResetType type)*/ set_float_2nan_prop_rule (float_2nan_prop_x87, &cpu->env.fp_status); +/* Default NaN: sign bit clear, frac msb set */ +set_float_default_nan_pattern (0b01000000 , &cpu->env.fp_status);#ifndef CONFIG_USER_ONLY cpu->env.picmr =0x00000000 ;
r~
PATCH v2 45/54 target/ppc: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for ppc.
--- target/ppc/cpu_init.c | 4 ++++ 1 file changed, 4 insertions(+)
target/ppc/cpu_init.c +4 -0
@@ -7286,6 +7286,10 @@ static void ppc_cpu_reset_hold(Object *obj, ResetType type)set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status);set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->vec_status); +/* Default NaN: sign bit clear, set frac msb */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status); +set_float_default_nan_pattern (0b01000000 , &env->vec_status); +for (i =0 ; i <ARRAY_SIZE (env->spr_cb); i++) {ppc_spr_t *spr = &env->spr_cb[i];
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 45/54] target/ppc: Set default NaN pattern explicitly
Quoted 12 lines · Peter Maydell
Set the default NaN pattern explicitly for ppc.
Signed-off-by Peter Maydell <[email protected]>--- target/ppc/cpu_init.c | 4 ++++ 1 file changed, 4 insertions(+)target/ppc/cpu_init.c +0
-0
target/ppc/cpu_init.c static void ppc_cpu_reset_hold(Object *obj, ResetType type) · line 7295
Quoted 10 lines
target/ppc/cpu_init.c +4
-0@@ -7286,6 +7286,10 @@ static void ppc_cpu_reset_hold(Object *obj, ResetType type)set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status);set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->vec_status); +/* Default NaN: sign bit clear, set frac msb */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status); +set_float_default_nan_pattern (0b01000000 , &env->vec_status); +for (i =0 ; i <ARRAY_SIZE (env->spr_cb); i++) {ppc_spr_t *spr = &env->spr_cb[i];
r~
PATCH v2 46/54 target/sh4: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for sh4. Note that sh4 is one of the only three targets (the others being HPPA and sometimes MIPS) that has snan_bit_is_one set.
--- target/sh4/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
target/sh4/cpu.c +2 -0
@@ -127,6 +127,8 @@ static void superh_cpu_reset_hold(Object *obj, ResetType type)set_flush_to_zero (1 , &env->fp_status);#endif set_default_nan_mode (1 , &env->fp_status); +/* sign bit clear, set all frac bits other than msb */ +set_float_default_nan_pattern (0b00111111 , &env->fp_status); }static void superh_cpu_disas_set_info (CPUState *cpu,disassemble_info *info)
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 46/54] target/sh4: Set default NaN pattern explicitly
Quoted 14 lines · Peter Maydell
Set the default NaN pattern explicitly for sh4. Note that sh4 is one of the only three targets (the others being HPPA and sometimes MIPS) that has
snan_bit_is_oneset.Signed-off-by Peter Maydell <[email protected]>--- target/sh4/cpu.c | 2 ++ 1 file changed, 2 insertions(+)target/sh4/cpu.c +0
-0
target/sh4/cpu.c static void superh_cpu_reset_hold(Object *obj, ResetType type) · line 134
Quoted 8 lines
target/sh4/cpu.c +2
-0@@ -127,6 +127,8 @@ static void superh_cpu_reset_hold(Object *obj, ResetType type)set_flush_to_zero (1 , &env->fp_status);#endif set_default_nan_mode (1 , &env->fp_status); +/* sign bit clear, set all frac bits other than msb */ +set_float_default_nan_pattern (0b00111111 , &env->fp_status); }static void superh_cpu_disas_set_info (CPUState *cpu,disassemble_info *info)
r~
PATCH v2 47/54 target/rx: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for rx.
--- target/rx/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
target/rx/cpu.c +2 -0
@@ -100,6 +100,8 @@ static void rx_cpu_reset_hold(Object *obj, ResetType type)* then prefer dest over source", which is float_2nan_prop_s_ab. */ set_float_2nan_prop_rule (float_2nan_prop_x87, &env->fp_status); +/* Default NaN value: sign bit clear, set frac msb */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status); }static ObjectClass *rx_cpu_class_by_name (const char *cpu_model)
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 47/54] target/rx: Set default NaN pattern explicitly
Quoted 12 lines · Peter Maydell
Set the default NaN pattern explicitly for rx.
Signed-off-by Peter Maydell <[email protected]>--- target/rx/cpu.c | 2 ++ 1 file changed, 2 insertions(+)target/rx/cpu.c +0
-0
target/rx/cpu.c static void rx_cpu_reset_hold(Object *obj, ResetType type) · line 107
Quoted 8 lines
target/rx/cpu.c +2
-0@@ -100,6 +100,8 @@ static void rx_cpu_reset_hold(Object *obj, ResetType type)* then prefer dest over source", which is float_2nan_prop_s_ab. */ set_float_2nan_prop_rule (float_2nan_prop_x87, &env->fp_status); +/* Default NaN value: sign bit clear, set frac msb */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status); }static ObjectClass *rx_cpu_class_by_name (const char *cpu_model)
r~
PATCH v2 48/54 target/s390x: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for s390x.
--- target/s390x/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
target/s390x/cpu.c +2 -0
@@ -209,6 +209,8 @@ static void s390_cpu_reset_hold(Object *obj, ResetType type)set_float_3nan_prop_rule (float_3nan_prop_s_abc, &env->fpu_status);set_float_infzeronan_rule (float_infzeronan_dnan_always, &env->fpu_status); +/* Default NaN value: sign bit clear, frac msb set */ +set_float_default_nan_pattern (0b01000000 , &env->fpu_status);/* fall through */ case RESET_TYPE_S390_CPU_NORMAL : env->psw.mask &= ~PSW_MASK_RI ;
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 48/54] target/s390x: Set default NaN pattern explicitly
Quoted 12 lines · Peter Maydell
Set the default NaN pattern explicitly for s390x.
Signed-off-by Peter Maydell <[email protected]>--- target/s390x/cpu.c | 2 ++ 1 file changed, 2 insertions(+)target/s390x/cpu.c +0
-0
target/s390x/cpu.c static void s390_cpu_reset_hold(Object *obj, ResetType type) · line 216
Quoted 8 lines
target/s390x/cpu.c +2
-0@@ -209,6 +209,8 @@ static void s390_cpu_reset_hold(Object *obj, ResetType type)set_float_3nan_prop_rule (float_3nan_prop_s_abc, &env->fpu_status);set_float_infzeronan_rule (float_infzeronan_dnan_always, &env->fpu_status); +/* Default NaN value: sign bit clear, frac msb set */ +set_float_default_nan_pattern (0b01000000 , &env->fpu_status);/* fall through */ case RESET_TYPE_S390_CPU_NORMAL : env->psw.mask &= ~PSW_MASK_RI ;
r~
PATCH v2 49/54 target/sparc: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for SPARC, and remove the ifdef from parts64_default_nan.
--- target/sparc/cpu.c | 2 ++ fpu/softfloat-specialize.c.inc | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-)
target/sparc/cpu.c +2 -0
@@ -818,6 +818,8 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)set_float_3nan_prop_rule (float_3nan_prop_s_cba, &env->fp_status);/* For inf * 0 + NaN, return the input NaN */ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status); +/* Default NaN value: sign bit clear, all frac bits set */ +set_float_default_nan_pattern (0b01111111 , &env->fp_status);cpu_exec_realizefn (cs, &local_err);if (local_err !=NULL ) {
fpu/softfloat-specialize.c.inc +1 -4
@@ -136,10 +136,7 @@ static void parts64_default_nan(FloatParts64 *p, float_status *status) uint8_t dnan_pattern = status->default_nan_pattern; if (dnan_pattern == 0) { -#if defined(TARGET_SPARC) - /* Sign bit clear, all frac bits set */ - dnan_pattern = 0b01111111; -#elif defined(TARGET_HEXAGON) +#if defined(TARGET_HEXAGON) /* Sign bit set, all frac bits set. */ dnan_pattern = 0b11111111; #else
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 49/54] target/sparc: Set default NaN pattern explicitly
Quoted 8 lines · Peter Maydell
Set the default NaN pattern explicitly for SPARC, and remove the ifdef from
parts64_default_nan.Signed-off-by Peter Maydell <[email protected]>--- target/sparc/cpu.c | 2 ++ fpu/softfloat-specialize.c.inc | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-)
r~
PATCH v2 50/54 target/xtensa: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for xtensa.
--- target/xtensa/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
target/xtensa/cpu.c +2 -0
@@ -136,6 +136,8 @@ static void xtensa_cpu_reset_hold(Object *obj, ResetType type)/* For inf * 0 + NaN, return the input NaN */ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status);set_no_signaling_nans (!dfpu, &env->fp_status); +/* Default NaN value: sign bit clear, set frac msb */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status);xtensa_use_first_nan (env, !dfpu); }
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 50/54] target/xtensa: Set default NaN pattern explicitly
Quoted 12 lines · Peter Maydell
Set the default NaN pattern explicitly for xtensa.
Signed-off-by Peter Maydell <[email protected]>--- target/xtensa/cpu.c | 2 ++ 1 file changed, 2 insertions(+)target/xtensa/cpu.c +0
-0
target/xtensa/cpu.c static void xtensa_cpu_reset_hold(Object *obj, ResetType type) · line 143
Quoted 8 lines
target/xtensa/cpu.c +2
-0@@ -136,6 +136,8 @@ static void xtensa_cpu_reset_hold(Object *obj, ResetType type)/* For inf * 0 + NaN, return the input NaN */ set_float_infzeronan_rule (float_infzeronan_dnan_never, &env->fp_status);set_no_signaling_nans (!dfpu, &env->fp_status); +/* Default NaN value: sign bit clear, set frac msb */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status);xtensa_use_first_nan (env, !dfpu); }
r~
PATCH v2 51/54 target/hexagon: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for hexagon. Remove the ifdef from parts64_default_nan(); the only remaining unconverted targets all use the default case.
--- target/hexagon/cpu.c | 2 ++ fpu/softfloat-specialize.c.inc | 5 ----- 2 files changed, 2 insertions(+), 5 deletions(-)
target/hexagon/cpu.c +2 -0
@@ -286,6 +286,8 @@ static void hexagon_cpu_reset_hold(Object *obj, ResetType type)set_default_nan_mode (1 , &env->fp_status);set_float_detect_tininess (float_tininess_before_rounding, &env->fp_status); +/* Default NaN value: sign bit set, all frac bits set */ +set_float_default_nan_pattern (0b11111111 , &env->fp_status); }static void hexagon_cpu_disas_set_info (CPUState *s,disassemble_info *info)
fpu/softfloat-specialize.c.inc +0 -5
@@ -136,10 +136,6 @@ static void parts64_default_nan(FloatParts64 *p, float_status *status) uint8_t dnan_pattern = status->default_nan_pattern; if (dnan_pattern == 0) { -#if defined(TARGET_HEXAGON) - /* Sign bit set, all frac bits set. */ - dnan_pattern = 0b11111111; -#else /* * This case is true for Alpha, ARM, MIPS, OpenRISC, PPC, RISC-V, * S390, SH4, TriCore, and Xtensa. Our other supported targets
@@ -152,7 +148,6 @@ static void parts64_default_nan(FloatParts64 *p, float_status *status) /* sign bit clear, set frac msb */ dnan_pattern = 0b01000000; } -#endif } assert(dnan_pattern != 0);
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 51/54] target/hexagon: Set default NaN pattern explicitly
Quoted 9 lines · Peter Maydell
Set the default NaN pattern explicitly for hexagon. Remove the ifdef from
parts64_default_nan(); the only remaining unconverted targets all use the default case.Signed-off-by Peter Maydell <[email protected]>--- target/hexagon/cpu.c | 2 ++ fpu/softfloat-specialize.c.inc | 5 ----- 2 files changed, 2 insertions(+), 5 deletions(-)
r~
PATCH v2 52/54 target/riscv: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for riscv.
--- target/riscv/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
target/riscv/cpu.c +2 -0
@@ -1022,6 +1022,8 @@ static void riscv_cpu_reset_hold(Object *obj, ResetType type) cs->exception_index =RISCV_EXCP_NONE ; env->load_res =-1 ;set_default_nan_mode (1 , &env->fp_status); +/* Default NaN value: sign bit clear, frac msb set */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status); env->vill = true;#ifndef CONFIG_USER_ONLY
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 52/54] target/riscv: Set default NaN pattern explicitly
Quoted 12 lines · Peter Maydell
Set the default NaN pattern explicitly for riscv.
Signed-off-by Peter Maydell <[email protected]>--- target/riscv/cpu.c | 2 ++ 1 file changed, 2 insertions(+)target/riscv/cpu.c +0
-0
target/riscv/cpu.c static void riscv_cpu_reset_hold(Object *obj, ResetType type) · line 1029
Quoted 8 lines
target/riscv/cpu.c +2
-0@@ -1022,6 +1022,8 @@ static void riscv_cpu_reset_hold(Object *obj, ResetType type) cs->exception_index =RISCV_EXCP_NONE ; env->load_res =-1 ;set_default_nan_mode (1 , &env->fp_status); +/* Default NaN value: sign bit clear, frac msb set */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status); env->vill = true;#ifndef CONFIG_USER_ONLY
r~
PATCH v2 53/54 target/tricore: Set default NaN pattern explicitly
In reply to Peter MaydellSet the default NaN pattern explicitly for tricore.
--- target/tricore/helper.c | 2 ++ 1 file changed, 2 insertions(+)
target/tricore/helper.c +2 -0
@@ -117,6 +117,8 @@ void fpu_set_state(CPUTriCoreState *env)set_flush_to_zero (1 , &env->fp_status);set_float_detect_tininess (float_tininess_before_rounding, &env->fp_status);set_default_nan_mode (1 , &env->fp_status); +/* Default NaN pattern: sign bit clear, frac msb set */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status); }uint32_t psw_read (CPUTriCoreState *env)
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 53/54] target/tricore: Set default NaN pattern explicitly
Quoted 12 lines · Peter Maydell
Set the default NaN pattern explicitly for tricore.
Signed-off-by Peter Maydell <[email protected]>--- target/tricore/helper.c | 2 ++ 1 file changed, 2 insertions(+)target/tricore/helper.c +0
-0
target/tricore/helper.c void fpu_set_state(CPUTriCoreState *env) · line 124
Quoted 8 lines
target/tricore/helper.c +2
-0@@ -117,6 +117,8 @@ void fpu_set_state(CPUTriCoreState *env)set_flush_to_zero (1 , &env->fp_status);set_float_detect_tininess (float_tininess_before_rounding, &env->fp_status);set_default_nan_mode (1 , &env->fp_status); +/* Default NaN pattern: sign bit clear, frac msb set */ +set_float_default_nan_pattern (0b01000000 , &env->fp_status); }uint32_t psw_read (CPUTriCoreState *env)
r~
PATCH v2 54/54 fpu: Remove default handling for dnan_pattern
In reply to Peter MaydellNow that all our targets have bene converted to explicitly specify their pattern for the default NaN value we can remove the remaining fallback code in parts64_default_nan().
--- fpu/softfloat-specialize.c.inc | 14 -------------- 1 file changed, 14 deletions(-)
fpu/softfloat-specialize.c.inc +0 -14
@@ -135,20 +135,6 @@ static void parts64_default_nan(FloatParts64 *p, float_status *status) uint64_t frac; uint8_t dnan_pattern = status->default_nan_pattern; - if (dnan_pattern == 0) { - /* - * This case is true for Alpha, ARM, MIPS, OpenRISC, PPC, RISC-V, - * S390, SH4, TriCore, and Xtensa. Our other supported targets - * do not have floating-point. - */ - if (snan_bit_is_one(status)) { - /* sign bit clear, set all frac bits other than msb */ - dnan_pattern = 0b00111111; - } else { - /* sign bit clear, set frac msb */ - dnan_pattern = 0b01000000; - } - } assert(dnan_pattern != 0); sign = dnan_pattern >> 7;
Signature · 1 line
2.34.1
Re: [PATCH v2 for-10.0 54/54] fpu: Remove default handling for dnan_pattern
Quoted 5 lines · Peter Maydell
Now that all our targets have bene converted to explicitly specify their pattern for the default NaN value we can remove the remaining fallback code in
parts64_default_nan().Signed-off-by Peter Maydell <[email protected]>
r~
Quoted 13 lines · Peter Maydell
(Apologies for this patchset being both big and having a wide CC list; the good news is that this is the last lot of fpu ifdef cleanup that needs to touch all the targets.)
This patchset does the same thing we already did for
pickNaN()topickNaNMulAdd()-- it replaces the compile-time ifdef ladder that selected target-specific NaN propagation behaviour with checking some runtime selectable settings in thefloat_status. The motivation is:
* this will let us have multiple targets in one QEMU binary
* the ArmFEAT_AFParchitectural feature includes letting the guest select a NaN propagation rule at runtime
This is patches 1-26 (which were in the v1 of this series).
Quoted 3 lines
It then does a similar thing for making targets select the default NaN value at runtime rather than relying on a compile-time ifdef. This is patches 34-54, which are new in v2.
Update needed for is_ebf in target/arm/tcg/vec_helper.c.
I think the best choice is to reverse the copy and test, e.g.
*statusp = env->vfp.fp_status;
set_default_nan_mode(true, statusp);
if (ebf) {
/* EBF=1 needs to do a step with round-to-odd semantics */
*oddstatusp = *statusp;
set_float_rounding_mode(float_round_to_odd, oddstatusp);
} else {
set_flush_to_zero(true, statusp);
set_flush_inputs_to_zero(true, statusp);
set_float_rounding_mode(float_round_to_odd_inf, statusp);
}r~