target/arm: Fix some FEAT_AFP corner cases
cover target/arm: Fix some FEAT_AFP corner cases
There are a few corner cases where when we implemented FEAT_AFP we didn't update the instructions to get the FPCR.AH = 1 handling right:
* SVE2 FMAXP and FMINP need to do the AH=1 style max/min
* SVE FCVTLT to halfprec needs to use the F16 FPCR
* FLOGB needs to report when it consumed a denormal
This patchset implements fixes for these.
thanks
-- PMM
Peter Maydell (3):
target/arm: SVE2 FMAXP, FMINP must honour AH=1 target/arm: Use FPST_A64_F16 for SVE FCVTLT_hs target/arm: Set correct fp flags for FLOGB when FPCR.AH = 1
target/arm/tcg/helper-sve-defs.h | 14 ++++++++++++++ target/arm/tcg/sve_helper.c | 11 +++++++++++ target/arm/tcg/translate-sve.c | 6 +++--- 3 files changed, 28 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 target/arm: SVE2 FMAXP, FMINP must honour AH=1
The behaviour of floating-point maximum and minimum insns has some odd special cases when FPCR.AH=1. We get this right in most places (for instance, the ASIMD FMAXP, FMINP) but forgot about it for the SVE2 versions of FMAXP and FMINP.
--- target/arm/tcg/helper-sve-defs.h | 14 ++++++++++++++ target/arm/tcg/sve_helper.c | 8 ++++++++ target/arm/tcg/translate-sve.c | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-)
target/arm/tcg/helper-sve-defs.h +14 -0
@@ -2914,6 +2914,20 @@ DEF_HELPER_FLAGS_6(sve2_fminp_zpzz_s, TCG_CALL_NO_RWG,DEF_HELPER_FLAGS_6 (sve2_fminp_zpzz_d,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, fpst, i32) +DEF_HELPER_FLAGS_6 (sve2_ah_fmaxp_zpzz_h,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, fpst, i32) +DEF_HELPER_FLAGS_6 (sve2_ah_fmaxp_zpzz_s,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, fpst, i32) +DEF_HELPER_FLAGS_6 (sve2_ah_fmaxp_zpzz_d,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, fpst, i32) + +DEF_HELPER_FLAGS_6 (sve2_ah_fminp_zpzz_h,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, fpst, i32) +DEF_HELPER_FLAGS_6 (sve2_ah_fminp_zpzz_s,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, fpst, i32) +DEF_HELPER_FLAGS_6 (sve2_ah_fminp_zpzz_d,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, fpst, i32) + DEF_HELPER_FLAGS_5(sve2_eor3, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_5(sve2_bcax, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32)DEF_HELPER_FLAGS_5 (sve2_bsl1n,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, i32)
target/arm/tcg/sve_helper.c +8 -0
@@ -778,6 +778,14 @@ DO_ZPZZ_PAIR_FP(sve2_fminp_zpzz_h, float16, H1_2, float16_min) DO_ZPZZ_PAIR_FP(sve2_fminp_zpzz_s, float32, H1_4, float32_min) DO_ZPZZ_PAIR_FP(sve2_fminp_zpzz_d, float64, H1_8, float64_min) +DO_ZPZZ_PAIR_FP(sve2_ah_fmaxp_zpzz_h, float16, H1_2, helper_vfp_ah_maxh) +DO_ZPZZ_PAIR_FP(sve2_ah_fmaxp_zpzz_s, float32, H1_4, helper_vfp_ah_maxs) +DO_ZPZZ_PAIR_FP(sve2_ah_fmaxp_zpzz_d, float64, H1_8, helper_vfp_ah_maxd) + +DO_ZPZZ_PAIR_FP(sve2_ah_fminp_zpzz_h, float16, H1_2, helper_vfp_ah_minh) +DO_ZPZZ_PAIR_FP(sve2_ah_fminp_zpzz_s, float32, H1_4, helper_vfp_ah_mins) +DO_ZPZZ_PAIR_FP(sve2_ah_fminp_zpzz_d, float64, H1_8, helper_vfp_ah_mind) +#undef DO_ZPZZ_PAIR_FP/* Three-operand expander, controlled by a predicate, in which the
target/arm/tcg/translate-sve.c +2 -2
@@ -7667,8 +7667,8 @@ TRANS_FEAT_NONSTREAMING(HISTSEG, aa64_sve2, gen_gvec_ool_arg_zzz, DO_ZPZZ_FP(FADDP, aa64_sme_or_sve2, sve2_faddp_zpzz) DO_ZPZZ_FP(FMAXNMP, aa64_sme_or_sve2, sve2_fmaxnmp_zpzz) DO_ZPZZ_FP(FMINNMP, aa64_sme_or_sve2, sve2_fminnmp_zpzz) -DO_ZPZZ_FP(FMAXP, aa64_sme_or_sve2, sve2_fmaxp_zpzz) -DO_ZPZZ_FP(FMINP, aa64_sme_or_sve2, sve2_fminp_zpzz) +DO_ZPZZ_AH_FP(FMAXP, aa64_sme_or_sve2, sve2_fmaxp_zpzz, sve2_ah_fmaxp_zpzz) +DO_ZPZZ_AH_FP(FMINP, aa64_sme_or_sve2, sve2_fminp_zpzz, sve2_ah_fminp_zpzz)static bool do_fmmla (DisasContext *s,arg_rrrr_esz *a,gen_helper_gvec_4_ptr *fn)
Signature · 1 line
2.43.0
Re: [PATCH 1/3] target/arm: SVE2 FMAXP, FMINP must honour AH=1
Quoted 8 lines · Peter Maydell
The behaviour of floating-point maximum and minimum insns has some odd special cases when FPCR.AH=1. We get this right in most places (for instance, the ASIMD FMAXP, FMINP) but forgot about it for the SVE2 versions of FMAXP and FMINP.
Fixes 384433e70983 ("target/arm: Implement FPCR.AH semantics for FMINP and FMAXP")Signed-off-by Peter Maydell <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH 2/3 target/arm: Use FPST_A64_F16 for SVE FCVTLT_hs
In reply to Peter MaydellThe SVE FCVTLT_hs operation produces a halfprec result, so we should use the FPST_A64_F16 fpstatus for it. Getting this wrong means we will incorrectly set FPCR.IDC for input-denormals when FPCR.AH=1.
We missed this instruction when we updated the halfproc-to-other conversion insns to use FPST_A64_F16 in commit e07b48995aaa as part of implementing FEAT_AHP.
--- target/arm/tcg/translate-sve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/tcg/translate-sve.c +1 -1
@@ -7827,7 +7827,7 @@ TRANS_FEAT(BFCVTNT, aa64_sme_sve_bf16, gen_gvec_fpst_arg_zpz, s->fpcr_ah ? FPST_AH : FPST_A64) TRANS_FEAT(FCVTLT_hs, aa64_sme_or_sve2, gen_gvec_fpst_arg_zpz, - gen_helper_sve2_fcvtlt_hs, a, 0, FPST_A64) + gen_helper_sve2_fcvtlt_hs, a, 0, FPST_A64_F16)TRANS_FEAT (FCVTLT_sd, aa64_sme_or_sve2, gen_gvec_fpst_arg_zpz, gen_helper_sve2_fcvtlt_sd, a,0 ,FPST_A64 )
Signature · 1 line
2.43.0
Re: [PATCH 2/3] target/arm: Use FPST_A64_F16 for SVE FCVTLT_hs
Quoted 2 lines · Peter Maydell
The SVE
FCVTLT_hsoperation produces a halfprec result, so we should use theFPST_A64_F16fpstatus for it.
Maybe I'm reading the Arm ARM wrong (I can't find FCVTLT_hs but I can see FCVTLT in the SVE encodings). But these are all widening operations so I can see halfprec to single, not the other way around.
Quoted 26 lines
Getting this wrong means we
will incorrectly set FPCR.IDC for input-denormals when FPCR.AH=1.We missed this instruction when we updated the halfproc-to-other conversion insns to use
FPST_A64_F16in commite07b48995aaaas part of implementingFEAT_AHP.Fixes e07b48995aaa ("target/arm: Use FPST_A64_F16 for halfprec-to-other conversions")aSigned-off-by Peter Maydell <[email protected]>--- target/arm/tcg/translate-sve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/arm/tcg/translate-sve.c +1
-1@@ -7827,7 +7827,7 @@ TRANS_FEAT(BFCVTNT, aa64_sme_sve_bf16, gen_gvec_fpst_arg_zpz, s->fpcr_ah ? FPST_AH : FPST_A64) TRANS_FEAT(FCVTLT_hs, aa64_sme_or_sve2, gen_gvec_fpst_arg_zpz, - gen_helper_sve2_fcvtlt_hs, a, 0, FPST_A64) + gen_helper_sve2_fcvtlt_hs, a, 0, FPST_A64_F16)TRANS_FEAT (FCVTLT_sd, aa64_sme_or_sve2, gen_gvec_fpst_arg_zpz, gen_helper_sve2_fcvtlt_sd, a,0 ,FPST_A64 )
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH 2/3] target/arm: Use FPST_A64_F16 for SVE FCVTLT_hs
Quoted 9 lines · Alex Bennée
Quoted 2 lines · Peter Maydell
The SVE
FCVTLT_hsoperation produces a halfprec result, so we should use theFPST_A64_F16fpstatus for it.Maybe I'm reading the Arm ARM wrong (I can't find
FCVTLT_hsbut I can see FCVTLT in the SVE encodings). But these are all widening operations so I can see halfprec to single, not the other way around.
Yes, I got the commit message wrong here; this is half to single, and we need to use the A64_F16 fpstatus for conversions from halfprec, not conversions to it. The e07b48995aaa commit message does a better job of explaining this than I did this time around.
The _hs is how the QEMU decode file splits the half to single and the single to double encodings, which are the same insn mnememonic in the architecture.
Improved commit message:
===begin===
We should be using the F16-specific float_status for conversions from half-precision, because halfprec inputs never set Input Denormal. If we use the FPST_A64 fpstatus then we will incorrectly set FPCR.IDC for input-denormals when FPCR.AH=1.
In commit e07b48995aaa we updated most of the halfprec-to-other conversion insns to use FPST_A64_F16 as part of implementing FEAT_AHP. However we missed the SVE FCVTLT instruction, which has a halfprec-to-single encoding.
Correct the FPST we use for the hs variant of FCVTLT.
[cc, fixes, &c]
===endit===
thanks
-- PMM
Alex Bennée
Reviewed-byRe: [PATCH 2/3] target/arm: Use FPST_A64_F16 for SVE FCVTLT_hs
Quoted 33 lines · Peter Maydell
Quoted 9 lines · Alex Bennée
Quoted 2 lines · Peter Maydell
The SVE
FCVTLT_hsoperation produces a halfprec result, so we should use theFPST_A64_F16fpstatus for it.Maybe I'm reading the Arm ARM wrong (I can't find
FCVTLT_hsbut I can see FCVTLT in the SVE encodings). But these are all widening operations so I can see halfprec to single, not the other way around.Yes, I got the commit message wrong here; this is half to single, and we need to use the
A64_F16fpstatus for conversions from halfprec, not conversions to it. Thee07b48995aaacommit message does a better job of explaining this than I did this time around.The
_hsis how the QEMU decode file splits the half to single and the single to double encodings, which are the same insn mnememonic in the architecture.Improved commit message:
===begin===
We should be using the F16-specificfloat_statusfor conversions from half-precision, because halfprec inputs never set Input Denormal. If we use theFPST_A64fpstatus then we will incorrectly set FPCR.IDC for input-denormals when FPCR.AH=1.In commit
e07b48995aaawe updated most of the halfprec-to-other conversion insns to useFPST_A64_F16as part of implementingFEAT_AHP. However we missed the SVE FCVTLT instruction, which has a halfprec-to-single encoding.
Quoted 5 lines
Correct the FPST we use for the hs variant of FCVTLT.
[cc, fixes, &c]
===endit===
Quoted 3 lines
thanks
-- PMM
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH 2/3] target/arm: Use FPST_A64_F16 for SVE FCVTLT_hs
In reply to Peter MaydellQuoted 1 line · Peter Maydell
The SVE
FCVTLT_hsoperation produces a halfprec result, so we should
halfprec input.
Quoted 19 lines
use the
FPST_A64_F16fpstatus for it. Getting this wrong means we will incorrectly set FPCR.IDC for input-denormals when FPCR.AH=1.We missed this instruction when we updated the halfproc-to-other conversion insns to use
FPST_A64_F16in commite07b48995aaaas part of implementingFEAT_AHP.Fixes e07b48995aaa ("target/arm: Use FPST_A64_F16 for halfprec-to-other conversions")aSigned-off-by Peter Maydell <[email protected]>--- target/arm/tcg/translate-sve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/arm/tcg/translate-sve.c +0
-0
target/arm/tcg/translate-sve.c TRANS_FEAT(BFCVTNT, aa64_sme_sve_bf16, gen_gvec_fpst_arg_zpz, · line 7833
Quoted 8 lines
target/arm/tcg/translate-sve.c +1
-1@@ -7827,7 +7827,7 @@ TRANS_FEAT(BFCVTNT, aa64_sme_sve_bf16, gen_gvec_fpst_arg_zpz, s->fpcr_ah ? FPST_AH : FPST_A64) TRANS_FEAT(FCVTLT_hs, aa64_sme_or_sve2, gen_gvec_fpst_arg_zpz, - gen_helper_sve2_fcvtlt_hs, a, 0, FPST_A64) + gen_helper_sve2_fcvtlt_hs, a, 0, FPST_A64_F16)TRANS_FEAT (FCVTLT_sd, aa64_sme_or_sve2, gen_gvec_fpst_arg_zpz, gen_helper_sve2_fcvtlt_sd, a,0 ,FPST_A64 )
Otherwise,
r~
PATCH 3/3 target/arm: Set correct fp flags for FLOGB when FPCR.AH = 1
In reply to Peter MaydellOur implementation of the FLOGB insn does the operations entirely in the helper function, without needing to use fpu functions. This means it needs to handle all the fp status flags itself. We aren't setting float_flag_input_denormal_used when we use (i.e. do not flush to zero) an input denormal, which means that FPCR.IDC isn't set when it should be for FPCR.AH=1. We missed this when we added float_flag_input_denormal_used and made the fpu/ code set it.
Add the missing float_raise().
--- target/arm/tcg/sve_helper.c | 3 +++ 1 file changed, 3 insertions(+)
target/arm/tcg/sve_helper.c +3 -0
@@ -5036,6 +5036,7 @@ static int16_t do_float16_logb_as_int(float16 a, float_status *s)if (frac !=0 ) {if (!get_flush_inputs_to_zero (s)) {/* denormal: bias - fractional_zeros */ +float_raise (float_flag_input_denormal_used, s);return -15 -clz32 (frac); }/* flush to zero */
@@ -5064,6 +5065,7 @@ static int32_t do_float32_logb_as_int(float32 a, float_status *s)if (frac !=0 ) {if (!get_flush_inputs_to_zero (s)) {/* denormal: bias - fractional_zeros */ +float_raise (float_flag_input_denormal_used, s);return -127 -clz32 (frac); }/* flush to zero */
@@ -5092,6 +5094,7 @@ static int64_t do_float64_logb_as_int(float64 a, float_status *s)if (frac !=0 ) {if (!get_flush_inputs_to_zero (s)) {/* denormal: bias - fractional_zeros */ +float_raise (float_flag_input_denormal_used, s);return -1023 -clz64 (frac); }/* flush to zero */
Signature · 1 line
2.43.0
Re: [PATCH 3/3] target/arm: Set correct fp flags for FLOGB when FPCR.AH = 1
Quoted 9 lines · Peter Maydell
Our implementation of the FLOGB insn does the operations entirely in the helper function, without needing to use fpu functions. This means it needs to handle all the fp status flags itself. We aren't setting
float_flag_input_denormal_usedwhen we use (i.e. do not flush to zero) an input denormal, which means that FPCR.IDC isn't set when it should be for FPCR.AH=1. We missed this when we addedfloat_flag_input_denormal_usedand made the fpu/ code set it.
Quoted 5 lines
Add the missing
float_raise().Fixes d38a57a3f ("target/arm: Enable FEAT_AFP for '-cpu max'")Signed-off-by Peter Maydell <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH 3/3] target/arm: Set correct fp flags for FLOGB when FPCR.AH = 1
In reply to Peter MaydellQuoted 9 lines · Peter Maydell
Our implementation of the FLOGB insn does the operations entirely in the helper function, without needing to use fpu functions. This means it needs to handle all the fp status flags itself. We aren't setting
float_flag_input_denormal_usedwhen we use (i.e. do not flush to zero) an input denormal, which means that FPCR.IDC isn't set when it should be for FPCR.AH=1. We missed this when we addedfloat_flag_input_denormal_usedand made the fpu/ code set it.
Quoted 8 lines
Add the missing
float_raise().Fixes d38a57a3f ("target/arm: Enable FEAT_AFP for '-cpu max'")Signed-off-by Peter Maydell<[email protected]>--- target/arm/tcg/sve_helper.c | 3 +++ 1 file changed, 3 insertions(+)
r~