Refactor get_fpstatus_ptr() ready for AArch32 fp16
cover Refactor get_fpstatus_ptr() ready for AArch32 fp16
This patchset refactors the existing get_fpstatus_ptr() functions, and fixes a bug where we weren't getting FZ16 right for AArch32 VCMLA, VCADD of fp16 types.
We currently have two versions of get_fpstatus_ptr(), which both take an effectively boolean argument:
* the one for A64 takes "bool is_f16" to distinguish fp16 from other ops
* the one for A32/T32 takes "int neon" to distinguish Neon from other ops
This is confusing, and to implement ARMv8.2-FP16 the A32/T32 one will need to make a four-way distinction between "non-Neon, FP16", "non-Neon, single/double", "Neon, FP16" and "Neon, single/double". The A64 version will then be a strict subset of the A32/T32 version.
The patchset creates a single fpstatus_ptr() function which takes an enum selecting between the 4 possible fpstatus options. It then adds the implementation of the "Neon standard FPST for f16". Finally, we can then use to fix a bug in the VCMLA/VCADD fp16 handling where we were using FPST_STD rather than FPST_STD_F16. (The difference is that the former will not honour FPSCR.FZ16.)
Based-on: [email protected] ("[PATCH 0/7] target/arm: copro decode cleanup)
but only textually; there are no semantic dependencies to that series.
thanks
-- PMM
Peter Maydell (4):
target/arm: Replace A64 get_fpstatus_ptr() with generic fpstatus_ptr() target/arm: Make A32/T32 use new fpstatus_ptr() API target/arm: Implement FPST_STD_F16 fpstatus
target/arm: Use correct FPST for VCMLA, VCADD on fp16
target/arm/cpu.h | 9 +++- target/arm/translate-a64.h | 1 - target/arm/translate.h | 52 +++++++++++++++++++ target/arm/cpu.c | 3 ++ target/arm/translate-a64.c | 89 +++++++++++++-------------------- target/arm/translate-neon.inc.c | 28 +++++------ target/arm/translate-sve.c | 34 ++++++------- target/arm/translate-vfp.inc.c | 44 ++++++++-------- target/arm/translate.c | 13 ----- target/arm/vfp_helper.c | 5 ++ 10 files changed, 156 insertions(+), 122 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/4 target/arm: Replace A64 get_fpstatus_ptr() with generic fpstatus_ptr()
We currently have two versions of get_fpstatus_ptr(), which both take an effectively boolean argument:
* the one for A64 takes "bool is_f16" to distinguish fp16 from other ops
* the one for A32/T32 takes "int neon" to distinguish Neon from other ops
This is confusing, and to implement ARMv8.2-FP16 the A32/T32 one will need to make a four-way distinction between "non-Neon, FP16", "non-Neon, single/double", "Neon, FP16" and "Neon, single/double". The A64 version will then be a strict subset of the A32/T32 version.
To clean this all up, we want to go to a single implementation which takes an enum argument with values FPST_FPCR, FPST_STD, FPST_FPCR_F16, and FPST_STD_F16. We rename the function to fpstatus_ptr() so that unconverted code gets a compilation error rather than silently passing the wrong thing to the new function.
This commit implements that new API, and converts A64 to use it:
get_fpstatus_ptr(false) -> fpstatus_ptr(FPST_FPCR) get_fpstatus_ptr(true) -> fpstatus_ptr(FPST_FPCR_F16)
---
This patch has a handful of 83-character lines; I felt they were better than the ugly linewrap that would be needed. All the callsite changes were done with editor search-and-replace.
--- target/arm/translate-a64.h | 1 - target/arm/translate.h | 51 ++++++++++++++++++++++ target/arm/translate-a64.c | 89 +++++++++++++++----------------------- target/arm/translate-sve.c | 34 +++++++-------- 4 files changed, 103 insertions(+), 72 deletions(-)
target/arm/translate-a64.h +0 -1
@@ -37,7 +37,6 @@ TCGv_i64 cpu_reg_sp(DisasContext *s, int reg);TCGv_i64 read_cpu_reg (DisasContext *s,int reg,int sf);TCGv_i64 read_cpu_reg_sp (DisasContext *s,int reg,int sf);void write_fp_dreg (DisasContext *s,int reg,TCGv_i64 v); -TCGv_ptr get_fpstatus_ptr (bool );bool logic_imm_decode_wmask (uint64_t *result,unsigned int immn,unsigned int imms,unsigned int immr);bool sve_access_check (DisasContext *s);
target/arm/translate.h +51 -0
55 lines not on this page · raw message
target/arm/translate-a64.c +35 -54
302 lines not on this page · raw message
target/arm/translate-sve.c +17 -17
@@ -3470,7 +3470,7 @@ static bool trans_FMLA_zzxz(DisasContext *s, arg_FMLA_zzxz *a)if (sve_access_check (s)) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_4_ptr(vec_full_reg_offset(s, a->rd), vec_full_reg_offset(s, a->rn), vec_full_reg_offset(s, a->rm),
@@ -3496,7 +3496,7 @@ static bool trans_FMUL_zzx(DisasContext *s, arg_FMUL_zzx *a)if (sve_access_check (s)) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, a->rd), vec_full_reg_offset(s, a->rn), vec_full_reg_offset(s, a->rm),
@@ -3528,7 +3528,7 @@ static void do_reduce(DisasContext *s, arg_rpr_esz *a,tcg_gen_addi_ptr (t_zn, cpu_env,vec_full_reg_offset (s, a->rn));tcg_gen_addi_ptr (t_pg, cpu_env,pred_full_reg_offset (s, a->pg)); - status =get_fpstatus_ptr (a->esz ==MO_16 ); + status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR );fn (temp, t_zn, t_pg, status, t_desc);tcg_temp_free_ptr (t_zn);
@@ -3570,7 +3570,7 @@ DO_VPZ(FMAXV, fmaxv)static void do_zz_fp (DisasContext *s,arg_rr_esz *a,gen_helper_gvec_2_ptr *fn) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_2_ptr(vec_full_reg_offset(s, a->rd), vec_full_reg_offset(s, a->rn),
@@ -3618,7 +3618,7 @@ static void do_ppz_fp(DisasContext *s, arg_rpr_esz *a, gen_helper_gvec_3_ptr *fn) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_3_ptr(pred_full_reg_offset(s, a->rd), vec_full_reg_offset(s, a->rn),
@@ -3670,7 +3670,7 @@ static bool trans_FTMAD(DisasContext *s, arg_FTMAD *a) }if (sve_access_check (s)) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, a->rd), vec_full_reg_offset(s, a->rn), vec_full_reg_offset(s, a->rm),
@@ -3710,7 +3710,7 @@ static bool trans_FADDA(DisasContext *s, arg_rprr_esz *a) t_pg =tcg_temp_new_ptr ();tcg_gen_addi_ptr (t_rm, cpu_env,vec_full_reg_offset (s, a->rm));tcg_gen_addi_ptr (t_pg, cpu_env,pred_full_reg_offset (s, a->pg)); - t_fpst =get_fpstatus_ptr (a->esz ==MO_16 ); + t_fpst =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); t_desc =tcg_const_i32 (simd_desc (vsz, vsz,0 )); fns[a->esz -1 ](t_val, t_val, t_rm, t_pg, t_fpst, t_desc);
@@ -3737,7 +3737,7 @@ static bool do_zzz_fp(DisasContext *s, arg_rrr_esz *a, }if (sve_access_check (s)) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, a->rd), vec_full_reg_offset(s, a->rn), vec_full_reg_offset(s, a->rm),
@@ -3779,7 +3779,7 @@ static bool do_zpzz_fp(DisasContext *s, arg_rprr_esz *a, }if (sve_access_check (s)) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_4_ptr(vec_full_reg_offset(s, a->rd), vec_full_reg_offset(s, a->rn), vec_full_reg_offset(s, a->rm),
@@ -3831,7 +3831,7 @@ static void do_fp_scalar(DisasContext *s, int zd, int zn, int pg, bool is_fp16,tcg_gen_addi_ptr (t_zn, cpu_env,vec_full_reg_offset (s, zn));tcg_gen_addi_ptr (t_pg, cpu_env,pred_full_reg_offset (s, pg)); - status =get_fpstatus_ptr (is_fp16); + status =fpstatus_ptr (is_fp16 ?FPST_FPCR_F16 :FPST_FPCR ); desc =tcg_const_i32 (simd_desc (vsz, vsz,0 ));fn (t_zd, t_zn, t_pg, scalar, status, desc);
@@ -3895,7 +3895,7 @@ static bool do_fp_cmp(DisasContext *s, arg_rprr_esz *a, }if (sve_access_check (s)) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_4_ptr(pred_full_reg_offset(s, a->rd), vec_full_reg_offset(s, a->rn), vec_full_reg_offset(s, a->rm),
@@ -3939,7 +3939,7 @@ static bool trans_FCADD(DisasContext *s, arg_FCADD *a) }if (sve_access_check (s)) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_4_ptr(vec_full_reg_offset(s, a->rd), vec_full_reg_offset(s, a->rn), vec_full_reg_offset(s, a->rm),
@@ -3958,7 +3958,7 @@ static bool do_fmla(DisasContext *s, arg_rprrr_esz *a, }if (sve_access_check (s)) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_5_ptr(vec_full_reg_offset(s, a->rd), vec_full_reg_offset(s, a->rn), vec_full_reg_offset(s, a->rm),
@@ -4001,7 +4001,7 @@ static bool trans_FCMLA_zpzzz(DisasContext *s, arg_FCMLA_zpzzz *a) }if (sve_access_check (s)) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_5_ptr(vec_full_reg_offset(s, a->rd), vec_full_reg_offset(s, a->rn), vec_full_reg_offset(s, a->rm),
@@ -4024,7 +4024,7 @@ static bool trans_FCMLA_zzxz(DisasContext *s, arg_FCMLA_zzxz *a)tcg_debug_assert (a->rd == a->ra);if (sve_access_check (s)) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, a->rd), vec_full_reg_offset(s, a->rn), vec_full_reg_offset(s, a->rm),
@@ -4045,7 +4045,7 @@ static bool do_zpz_ptr(DisasContext *s, int rd, int rn, int pg, {if (sve_access_check (s)) {unsigned vsz =vec_full_reg_size (s); -TCGv_ptr status =get_fpstatus_ptr (is_fp16); +TCGv_ptr status =fpstatus_ptr (is_fp16 ?FPST_FPCR_F16 :FPST_FPCR ); tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn), pred_full_reg_offset(s, pg),
@@ -4191,7 +4191,7 @@ static bool do_frint_mode(DisasContext *s, arg_rpr_esz *a, int mode)if (sve_access_check (s)) {unsigned vsz =vec_full_reg_size (s);TCGv_i32 tmode =tcg_const_i32 (mode); -TCGv_ptr status =get_fpstatus_ptr (a->esz ==MO_16 ); +TCGv_ptr status =fpstatus_ptr (a->esz ==MO_16 ?FPST_FPCR_F16 :FPST_FPCR );gen_helper_set_rmode (tmode, tmode, status);
Signature · 1 line
2.20.1
Re: [PATCH 1/4] target/arm: Replace A64 get_fpstatus_ptr() with generic fpstatus_ptr()
Quoted 16 lines · Peter Maydell
We currently have two versions of
get_fpstatus_ptr(), which both take an effectively boolean argument:
* the one for A64 takes "boolis_f16" to distinguish fp16 from other ops
* the one for A32/T32 takes "int neon" to distinguish Neon from other opsThis is confusing, and to implement ARMv8.2-FP16 the A32/T32 one will need to make a four-way distinction between "non-Neon, FP16", "non-Neon, single/double", "Neon, FP16" and "Neon, single/double". The A64 version will then be a strict subset of the A32/T32 version.
To clean this all up, we want to go to a single implementation which takes an enum argument with values
FPST_FPCR,FPST_STD,FPST_FPCR_F16, andFPST_STD_F16. We rename the function tofpstatus_ptr()so that unconverted code gets a compilation error rather than silently passing the wrong thing to the new function.
Quoted 5 lines
This commit implements that new API, and converts A64 to use it:
get_fpstatus_ptr(false)->fpstatus_ptr(FPST_FPCR)get_fpstatus_ptr(true)->fpstatus_ptr(FPST_FPCR_F16)Signed-off-by Peter Maydell <[email protected]>
How many more can they add ;-)
Signature · 1 line
Alex Bennée
PATCH 2/4 target/arm: Make A32/T32 use new fpstatus_ptr() API
In reply to Peter MaydellMake A32/T32 code use the new fpstatus_ptr() API:
get_fpstatus_ptr(0) -> fpstatus_ptr(FPST_FPCR)
get_fpstatus_ptr(1) -> fpstatus_ptr(FPST_STD)
--- target/arm/translate-neon.inc.c | 28 ++++++++++----------- target/arm/translate-vfp.inc.c | 44 ++++++++++++++++----------------- target/arm/translate.c | 13 ---------- 3 files changed, 36 insertions(+), 49 deletions(-)
target/arm/translate-neon.inc.c +14 -14
@@ -181,7 +181,7 @@ static bool trans_VCMLA(DisasContext *s, arg_VCMLA *a) } opr_sz = (1 + a->q) *8 ; - fpst =get_fpstatus_ptr (1 ); + fpst =fpstatus_ptr (FPST_STD ); fn_gvec_ptr = a->size ? gen_helper_gvec_fcmlas : gen_helper_gvec_fcmlah; tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd), vfp_reg_offset(1, a->vn),
@@ -218,7 +218,7 @@ static bool trans_VCADD(DisasContext *s, arg_VCADD *a) } opr_sz = (1 + a->q) *8 ; - fpst =get_fpstatus_ptr (1 ); + fpst =fpstatus_ptr (FPST_STD ); fn_gvec_ptr = a->size ? gen_helper_gvec_fcadds : gen_helper_gvec_fcaddh; tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd), vfp_reg_offset(1, a->vn),
@@ -322,7 +322,7 @@ static bool trans_VCMLA_scalar(DisasContext *s, arg_VCMLA_scalar *a) fn_gvec_ptr = (a->size ? gen_helper_gvec_fcmlas_idx : gen_helper_gvec_fcmlah_idx); opr_sz = (1 + a->q) *8 ; - fpst =get_fpstatus_ptr (1 ); + fpst =fpstatus_ptr (FPST_STD ); tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd), vfp_reg_offset(1, a->vn), vfp_reg_offset(1, a->vm),
@@ -358,7 +358,7 @@ static bool trans_VDOT_scalar(DisasContext *s, arg_VDOT_scalar *a) fn_gvec = a->u ? gen_helper_gvec_udot_idx_b : gen_helper_gvec_sdot_idx_b; opr_sz = (1 + a->q) *8 ; - fpst =get_fpstatus_ptr (1 ); + fpst =fpstatus_ptr (FPST_STD ); tcg_gen_gvec_3_ool(vfp_reg_offset(1, a->vd), vfp_reg_offset(1, a->vn), vfp_reg_offset(1, a->rm),
@@ -1063,7 +1063,7 @@ static bool do_3same_fp(DisasContext *s, arg_3same *a, VFPGen3OpSPFn *fn,return true; } -TCGv_ptr fpstatus =get_fpstatus_ptr (1 ); +TCGv_ptr fpstatus =fpstatus_ptr (FPST_STD );for (pass =0 ; pass < (a->q ?4 :2 ); pass++) { tmp =neon_load_reg (a->vn, pass); tmp2 =neon_load_reg (a->vm, pass);
@@ -1091,7 +1091,7 @@ static bool do_3same_fp(DisasContext *s, arg_3same *a, VFPGen3OpSPFn *fn, uint32_t rn_ofs, uint32_t rm_ofs, \ uint32_t oprsz, uint32_t maxsz) \ { \ - TCGv_ptr fpst = get_fpstatus_ptr(1); \ + TCGv_ptr fpst = fpstatus_ptr(FPST_STD); \tcg_gen_gvec_3_ptr (rd_ofs, rn_ofs, rm_ofs, fpst, \ oprsz, maxsz,0 ,FUNC ); \tcg_temp_free_ptr (fpst); \
@@ -1287,7 +1287,7 @@ static bool do_3same_fp_pair(DisasContext *s, arg_3same *a, VFPGen3OpSPFn *fn)* early. Since Q is 0 there are always just two passes, so instead * of a complicated loop over each pass we just unroll. */ - fpstatus =get_fpstatus_ptr (1 ); + fpstatus =fpstatus_ptr (FPST_STD ); tmp =neon_load_reg (a->vn,0 ); tmp2 =neon_load_reg (a->vn,1 );fn (tmp, tmp, tmp2, fpstatus);
@@ -1790,7 +1790,7 @@ static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a,return true; } - fpstatus =get_fpstatus_ptr (1 ); + fpstatus =fpstatus_ptr (FPST_STD ); shiftv =tcg_const_i32 (a->shift);for (pass =0 ; pass < (a->q ?4 :2 ); pass++) { tmp =neon_load_reg (a->vm, pass);
@@ -2591,7 +2591,7 @@ static bool trans_VMLS_2sc(DisasContext *s, arg_2scalar *a)#define WRAP_FP_FN (WRAPNAME ,FUNC ) \ static void WRAPNAME(TCGv_i32 rd, TCGv_i32 rn, TCGv_i32 rm) \ { \ - TCGv_ptr fpstatus = get_fpstatus_ptr(1); \ + TCGv_ptr fpstatus = fpstatus_ptr(FPST_STD); \ FUNC(rd, rn, rm, fpstatus); \ tcg_temp_free_ptr(fpstatus); \ }
@@ -3480,7 +3480,7 @@ static bool trans_VCVT_F16_F32(DisasContext *s, arg_2misc *a)return true; } - fpst =get_fpstatus_ptr (true); + fpst =fpstatus_ptr (FPST_STD ); ahp =get_ahp_flag (); tmp =neon_load_reg (a->vm,0 );gen_helper_vfp_fcvt_f32_to_f16 (tmp, tmp, fpst, ahp);
@@ -3528,7 +3528,7 @@ static bool trans_VCVT_F32_F16(DisasContext *s, arg_2misc *a)return true; } - fpst =get_fpstatus_ptr (true); + fpst =fpstatus_ptr (FPST_STD ); ahp =get_ahp_flag (); tmp3 =tcg_temp_new_i32 (); tmp =neon_load_reg (a->vm,0 );
@@ -3838,7 +3838,7 @@ static bool do_2misc_fp(DisasContext *s, arg_2misc *a,return true; } - fpst =get_fpstatus_ptr (1 ); + fpst =fpstatus_ptr (FPST_STD );for (pass =0 ; pass < (a->q ?4 :2 ); pass++) {TCGv_i32 tmp =neon_load_reg (a->vm, pass);fn (tmp, tmp, fpst);
@@ -3932,7 +3932,7 @@ static bool do_vrint(DisasContext *s, arg_2misc *a, int rmode)return true; } - fpst =get_fpstatus_ptr (1 ); + fpst =fpstatus_ptr (FPST_STD ); tcg_rmode =tcg_const_i32 (arm_rmode_to_sf (rmode));gen_helper_set_neon_rmode (tcg_rmode, tcg_rmode, cpu_env);for (pass =0 ; pass < (a->q ?4 :2 ); pass++) {
@@ -3993,7 +3993,7 @@ static bool do_vcvt(DisasContext *s, arg_2misc *a, int rmode, bool is_signed)return true; } - fpst =get_fpstatus_ptr (1 ); + fpst =fpstatus_ptr (FPST_STD ); tcg_shift =tcg_const_i32 (0 ); tcg_rmode =tcg_const_i32 (arm_rmode_to_sf (rmode));gen_helper_set_neon_rmode (tcg_rmode, tcg_rmode, cpu_env);
target/arm/translate-vfp.inc.c +22 -22
176 lines not on this page · raw message
target/arm/translate.c +0 -13
@@ -1094,19 +1094,6 @@ static inline void gen_hlt(DisasContext *s, int imm)unallocated_encoding (s); } -static TCGv_ptr get_fpstatus_ptr (int neon) -{ -TCGv_ptr statusptr =tcg_temp_new_ptr (); -int offset; -if (neon) { - offset = offsetof(CPUARMState, vfp.standard_fp_status); - }else { - offset = offsetof(CPUARMState, vfp.fp_status); - } -tcg_gen_addi_ptr (statusptr, cpu_env, offset); -return statusptr; -} -static inline long vfp_reg_offset (bool dp,unsigned reg) {if (dp) {
Signature · 1 line
2.20.1
Re: [PATCH 2/4] target/arm: Make A32/T32 use new fpstatus_ptr() API
Quoted 5 lines · Peter Maydell
Make A32/T32 code use the new
fpstatus_ptr()API:
get_fpstatus_ptr(0)->fpstatus_ptr(FPST_FPCR)
get_fpstatus_ptr(1)->fpstatus_ptr(FPST_STD)Signed-off-by Peter Maydell <[email protected]>
<snip>
Signature · 1 line
Alex Bennée
PATCH 3/4 target/arm: Implement FPST_STD_F16 fpstatus
In reply to Peter MaydellArchitecturally, Neon FP16 operations use the "standard FPSCR" like all other Neon operations. However, this is defined in the Arm ARM pseudocode as "a fixed value, except that FZ16 (and AHP) follow the FPSCR bits". In QEMU, the softfloat float_status doesn't include separate flush-to-zero for FP16 operations, so we must keep separate fp_status for "Neon non-FP16" and "Neon fp16" operations, in the same way we do already for the non-Neon "fp_status" vs "fp_status_f16".
Add the extra float_status field to the CPU state structure, ensure it is correctly initialized and updated on FPSCR writes, and make fpstatus_ptr(FPST_STD_F16) return a pointer to it.
--- target/arm/cpu.h | 9 ++++++++- target/arm/translate.h | 3 ++- target/arm/cpu.c | 3 +++ target/arm/vfp_helper.c | 5 +++++ 4 files changed, 18 insertions(+), 2 deletions(-)
target/arm/cpu.h +8 -1
@@ -609,6 +609,8 @@ typedef struct CPUARMState {* fp_status: is the "normal" fp status. * fp_status_fp16: used for half-precision calculations * standard_fp_status : the ARM "Standard FPSCR Value" +* standard_fp_status_fp16 : used for half-precision +* calculations with the ARM "Standard FPSCR Value" * * Half-precision operations are governed by a separate * flush-to-zero control bit in FPSCR:FZ16. We pass a separate
@@ -619,15 +621,20 @@ typedef struct CPUARMState {* Neon) which the architecture defines as controlled by the * standard FPSCR value rather than the FPSCR. * +* The "standard FPSCR but for fp16 ops" is needed because +* the "standard FPSCR" tracks the FPSCR.FZ16 bit rather than +* using a fixed value for it. +* * To avoid having to transfer exception bits around, we simply * say that the FPSCR cumulative exception flags are the logical -* OR of the flags in the three fp statuses. This relies on the +* OR of the flags in the four fp statuses. This relies on the * only thing which needs to read the exception flags being * an explicit FPSCR read. */ float_status fp_status;float_status fp_status_f16;float_status standard_fp_status; +float_status standard_fp_status_f16;/* ZCR_EL[1-3] */ uint64_t zcr_el[4 ];
target/arm/translate.h +2 -1
@@ -436,7 +436,8 @@ static inline TCGv_ptr fpstatus_ptr(ARMFPStatusFlavour flavour) offset = offsetof(CPUARMState, vfp.standard_fp_status);break ;case FPST_STD_F16 : -/* Not yet used or implemented: fall through to assert */ + offset = offsetof(CPUARMState, vfp.standard_fp_status_f16); +break ;default :g_assert_not_reached (); }
target/arm/cpu.c +3 -0
@@ -391,12 +391,15 @@ static void arm_cpu_reset(DeviceState *dev)set_flush_to_zero (1 , &env->vfp.standard_fp_status);set_flush_inputs_to_zero (1 , &env->vfp.standard_fp_status);set_default_nan_mode (1 , &env->vfp.standard_fp_status); +set_default_nan_mode (1 , &env->vfp.standard_fp_status_f16);set_float_detect_tininess (float_tininess_before_rounding, &env->vfp.fp_status);set_float_detect_tininess (float_tininess_before_rounding, &env->vfp.standard_fp_status);set_float_detect_tininess (float_tininess_before_rounding, &env->vfp.fp_status_f16); +set_float_detect_tininess (float_tininess_before_rounding, + &env->vfp.standard_fp_status_f16);#ifndef CONFIG_USER_ONLY if (kvm_enabled ()) {kvm_arm_reset_vcpu (cpu);
target/arm/vfp_helper.c +5 -0
@@ -93,6 +93,8 @@ static uint32_t vfp_get_fpscr_from_host(CPUARMState *env)/* FZ16 does not generate an input denormal exception. */ i |= (get_float_exception_flags (&env->vfp.fp_status_f16) & ~float_flag_input_denormal); + i |= (get_float_exception_flags (&env->vfp.standard_fp_status_f16) + & ~float_flag_input_denormal);return vfp_exceptbits_from_host (i); }
@@ -124,7 +126,9 @@ static void vfp_set_fpscr_to_host(CPUARMState *env, uint32_t val)if (changed &FPCR_FZ16 ) {bool ftz_enabled = val &FPCR_FZ16 ;set_flush_to_zero (ftz_enabled, &env->vfp.fp_status_f16); +set_flush_to_zero (ftz_enabled, &env->vfp.standard_fp_status_f16);set_flush_inputs_to_zero (ftz_enabled, &env->vfp.fp_status_f16); +set_flush_inputs_to_zero (ftz_enabled, &env->vfp.standard_fp_status_f16); }if (changed &FPCR_FZ ) {bool ftz_enabled = val &FPCR_FZ ;
@@ -146,6 +150,7 @@ static void vfp_set_fpscr_to_host(CPUARMState *env, uint32_t val)set_float_exception_flags (i, &env->vfp.fp_status);set_float_exception_flags (0 , &env->vfp.fp_status_f16);set_float_exception_flags (0 , &env->vfp.standard_fp_status); + set_float_exception_flags(0, &env->vfp.standard_fp_status_f16); }#else
Signature · 1 line
2.20.1
Re: [PATCH 3/4] target/arm: Implement FPST_STD_F16 fpstatus
Quoted 8 lines · Peter Maydell
Architecturally, Neon FP16 operations use the "standard FPSCR" like all other Neon operations. However, this is defined in the Arm ARM pseudocode as "a fixed value, except that FZ16 (and AHP) follow the FPSCR bits". In QEMU, the softfloat
float_statusdoesn't include separate flush-to-zero for FP16 operations, so we must keep separatefp_statusfor "Neon non-FP16" and "Neon fp16" operations, in the same way we do already for the non-Neon "fp_status" vs "fp_status_f16".
Quoted 5 lines
Add the extra
float_statusfield to the CPU state structure, ensure it is correctly initialized and updated on FPSCR writes, and makefpstatus_ptr(FPST_STD_F16)return a pointer to it.Signed-off-by Peter Maydell <[email protected]>
Signature · 1 line
Alex Bennée
PATCH 4/4 target/arm: Use correct FPST for VCMLA, VCADD on fp16
In reply to Peter MaydellWhen we implemented the VCMLA and VCADD insns we put in the code to handle fp16, but left it using the standard fp status flags. Correct them to use FPST_STD_F16 for fp16 operations.
--- target/arm/translate-neon.inc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target/arm/translate-neon.inc.c +3 -3
@@ -181,7 +181,7 @@ static bool trans_VCMLA(DisasContext *s, arg_VCMLA *a) } opr_sz = (1 + a->q) *8 ; - fpst =fpstatus_ptr (FPST_STD ); + fpst =fpstatus_ptr (a->size ==0 ?FPST_STD_F16 :FPST_STD ); fn_gvec_ptr = a->size ? gen_helper_gvec_fcmlas : gen_helper_gvec_fcmlah; tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd), vfp_reg_offset(1, a->vn),
@@ -218,7 +218,7 @@ static bool trans_VCADD(DisasContext *s, arg_VCADD *a) } opr_sz = (1 + a->q) *8 ; - fpst =fpstatus_ptr (FPST_STD ); + fpst =fpstatus_ptr (a->size ==0 ?FPST_STD_F16 :FPST_STD ); fn_gvec_ptr = a->size ? gen_helper_gvec_fcadds : gen_helper_gvec_fcaddh; tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd), vfp_reg_offset(1, a->vn),
@@ -322,7 +322,7 @@ static bool trans_VCMLA_scalar(DisasContext *s, arg_VCMLA_scalar *a) fn_gvec_ptr = (a->size ? gen_helper_gvec_fcmlas_idx : gen_helper_gvec_fcmlah_idx); opr_sz = (1 + a->q) *8 ; - fpst =fpstatus_ptr (FPST_STD ); + fpst =fpstatus_ptr (a->size ==0 ?FPST_STD_F16 :FPST_STD ); tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd), vfp_reg_offset(1, a->vn), vfp_reg_offset(1, a->vm),
Signature · 1 line
2.20.1
Re: [PATCH 4/4] target/arm: Use correct FPST for VCMLA, VCADD on fp16
Quoted 5 lines · Peter Maydell
When we implemented the VCMLA and VCADD insns we put in the code to handle fp16, but left it using the standard fp status flags. Correct them to use
FPST_STD_F16for fp16 operations.Signed-off-by Peter Maydell <[email protected]>
Signature · 1 line
Alex Bennée
Quoted 5 lines · Peter Maydell
Peter Maydell (4):
target/arm: Replace A64get_fpstatus_ptr()with genericfpstatus_ptr()target/arm: Make A32/T32 use newfpstatus_ptr()API target/arm: ImplementFPST_STD_F16fpstatus
target/arm: Use correct FPST for VCMLA, VCADD on fp16
r~