target/arm: Implement FEAT_EBF16
cover target/arm: Implement FEAT_EBF16
This patchset implements the optional FEAT_EBF16 architectural feature. This feature only does one thing: it adds a new bit FPCR.EBF to the floating point control register, so that the guest can enable a slightly different set of semantics for the bfloat16 dot-product instructions (BFDOT, BFMMLA, BFMOPA, BFMOPS; also BFVDOT when we eventually implement SME2). When the bit is set:
* they honour FPCR.RMode to set the rounding mode
* they honour the FPCR bits controlling flushing of denormals
* they can generate default NaN and infinity as intermediate sum-of-products
* the intermediate rounding handling changes
In the Arm ARM these changes only affect the pseudocode BFDotAdd function, which in QEMU we implement in bfdotadd().
A lot of this series is plumbing -- we need the CPU env pointer now in the helper functions which call bfdotadd(), so we need to pass it through from the generated code. Once we have it, we can refactor the callsites in a manner suggested by RTH, so that we have bfdotadd() specialized for EBF=0 and bfdotadd_ebf() specialized for EBF=1. This lets us hoist the setup out of the inner loop:
float_status fpst, fpst_odd;
if (is_ebf(env, &fpst, &fpst_odd)) {
for (...) {
x = bfdotadd_ebf(..., &fpst, &fpst_odd);
}
} else {
for (...) {
x = bfdotadd(..., &fpst);
}}
The implementation itself requires a fused paired-multiply-and-add; we use the same trick we already have in f16_dotadd() to implement this.
Not intended for 9.1, obviously, but I figured since I'd written and tested it I might as well send it out to the list.
Based-on: <[email protected]> ("target/arm: Handle denormals correctly for FMOPA (widening)") both for textual reasons and because that patch introduces the do_outprod_env() utility function we use here.
thanks
-- PMM
Peter Maydell (8):
target/arm: Allow setting the FPCR.EBF bit for FEAT_EBF16 target/arm: Pass env pointer through to sme_bfmopa helper target/arm: Pass env pointer through to gvec_bfdot helper target/arm: Pass env pointer through to gvec_bfdot_idx helper target/arm: Pass env pointer through to gvec_bfmmla helper target/arm: Prepare bfdotadd() callers for FEAT_EBF support target/arm: Implement FPCR.EBF=1 semantics for bfdotadd() target/arm: Enable FEAT_EBF16 in the "max" CPU
docs/system/arm/emulation.rst | 1 + target/arm/cpu-features.h | 5 + target/arm/cpu.h | 1 + target/arm/helper.h | 12 +- target/arm/tcg/helper-sme.h | 4 +- target/arm/tcg/vec_internal.h | 37 +++++- target/arm/tcg/cpu64.c | 4 +- target/arm/tcg/sme_helper.c | 78 ++++++++---- target/arm/tcg/translate-a64.c | 40 ++++++- target/arm/tcg/translate-neon.c | 43 ++++++- target/arm/tcg/translate-sme.c | 3 +- target/arm/tcg/translate-sve.c | 25 +++- target/arm/tcg/vec_helper.c | 202 +++++++++++++++++++++++++------- target/arm/vfp_helper.c | 8 +- 14 files changed, 371 insertions(+), 92 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/8 target/arm: Allow setting the FPCR.EBF bit for FEAT_EBF16
FEAT_EBF16 adds one new bit to the FPCR floating point control register. Allow this bit to be read and written when the ID registers indicate the presence of the feature.
Note that because this new bit is not in FPSCR_FPCR_MASK the bit is not visible in the AArch32 FPSCR, and FPSCR writes do not affect it.
--- target/arm/cpu-features.h | 5 +++++ target/arm/cpu.h | 1 + target/arm/vfp_helper.c | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-)
target/arm/cpu-features.h +5 -0
@@ -556,6 +556,11 @@ static inline bool isar_feature_aa64_bf16(const ARMISARegisters *id)return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,BF16 ) !=0 ; } +static inline bool isar_feature_aa64_ebf16 (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,BF16 ) >1 ; +} +static inline bool isar_feature_aa64_rcpc_8_3 (const ARMISARegisters *id) {return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,LRCPC ) !=0 ;
target/arm/cpu.h +1 -0
@@ -1707,6 +1707,7 @@ void vfp_set_fpscr(CPUARMState *env, uint32_t val);#define FPCR_OFE (1 << 10)/* Overflow exception trap enable */ #define FPCR_UFE (1 << 11)/* Underflow exception trap enable */ #define FPCR_IXE (1 << 12)/* Inexact exception trap enable */ +#define FPCR_EBF (1 << 13)/* Extended BFloat16 behaviors */ #define FPCR_IDE (1 << 15)/* Input Denormal exception trap enable */ #define FPCR_LEN_MASK (7 << 16)/* LEN, A-profile only */ #define FPCR_FZ16 (1 << 19)/* ARMv8.2+, FP16 flush-to-zero */
target/arm/vfp_helper.c +6 -2
@@ -254,6 +254,10 @@ static void vfp_set_fpcr_masked(CPUARMState *env, uint32_t val, uint32_t mask) val &= ~FPCR_FZ16 ; } +if (!cpu_isar_feature (aa64_ebf16, cpu)) { + val &= ~FPCR_EBF ; + } +vfp_set_fpcr_to_host (env, val, mask);if (mask & (FPCR_LEN_MASK |FPCR_STRIDE_MASK )) {
@@ -278,12 +282,12 @@ static void vfp_set_fpcr_masked(CPUARMState *env, uint32_t val, uint32_t mask)* We don't implement trapped exception handling, so the * trap enable bits, IDE|IXE|UFE|OFE|DZE|IOE are all RAZ/WI (not RES0!) * -* The FPCR bits we keep in vfp.fpcr are AHP, DN, FZ, RMode +* The FPCR bits we keep in vfp.fpcr are AHP, DN, FZ, RMode, EBF * and FZ16. Len, Stride and LTPSIZE we just handled. Store those bits * there, and zero any of the other FPCR bits and the RES0 and RAZ/WI * bits. */ - val &=FPCR_AHP |FPCR_DN |FPCR_FZ |FPCR_RMODE_MASK |FPCR_FZ16 ; + val &=FPCR_AHP |FPCR_DN |FPCR_FZ |FPCR_RMODE_MASK |FPCR_FZ16 |FPCR_EBF ; env->vfp.fpcr &= ~mask; env->vfp.fpcr |= val; }
Signature · 1 line
2.34.1
Re: [PATCH 1/8] target/arm: Allow setting the FPCR.EBF bit for FEAT_EBF16
Quoted 7 lines · Peter Maydell
FEAT_EBF16adds one new bit to the FPCR floating point control register. Allow this bit to be read and written when the ID registers indicate the presence of the feature.Note that because this new bit is not in
FPSCR_FPCR_MASKthe bit is not visible in the AArch32 FPSCR, and FPSCR writes do not affect it.
Quoted 6 lines
Signed-off-by Peter Maydell<[email protected]>--- target/arm/cpu-features.h | 5 +++++ target/arm/cpu.h | 1 + target/arm/vfp_helper.c | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-)
r~
PATCH 2/8 target/arm: Pass env pointer through to sme_bfmopa helper
In reply to Peter MaydellTo implement the FEAT_EBF16 semantics, we are going to need the CPUARMState env pointer in every helper function which calls bfdotadd().
Pass the env pointer through from generated code to the sme_bfmopa helper. (We'll add the code that uses it when we've adjusted all the helpers to have access to the env pointer.)
--- target/arm/tcg/helper-sme.h | 4 ++-- target/arm/tcg/sme_helper.c | 4 ++-- target/arm/tcg/translate-sme.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
target/arm/tcg/helper-sme.h +2 -2
@@ -126,8 +126,8 @@ DEF_HELPER_FLAGS_7(sme_fmopa_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_7(sme_fmopa_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, ptr, ptr, i32) -DEF_HELPER_FLAGS_6(sme_bfmopa, TCG_CALL_NO_RWG, - void, ptr, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_7(sme_bfmopa, TCG_CALL_NO_RWG, + void, env, ptr, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_6(sme_smopa_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_6(sme_umopa_s, TCG_CALL_NO_RWG,
target/arm/tcg/sme_helper.c +2 -2
@@ -1080,8 +1080,8 @@ void HELPER(sme_fmopa_h)(CPUARMState *env, } } -void HELPER (sme_bfmopa )(void *vza,void *vzn,void *vzm,void *vpn, -void *vpm,uint32_t desc) +void HELPER (sme_bfmopa )(CPUARMState *env,void *vza,void *vzn,void *vzm, +void *vpn,void *vpm,uint32_t desc) {intptr_t row, col, oprsz =simd_maxsz (desc);uint32_t neg =simd_data (desc) *0x80008000u ;
target/arm/tcg/translate-sme.c +1 -1
@@ -355,7 +355,7 @@ TRANS_FEAT(FMOPA_d, aa64_sme_f64f64, do_outprod_fpst, a, MO_64, FPST_FPCR, gen_helper_sme_fmopa_d)/* TODO: FEAT_EBF16 */ -TRANS_FEAT(BFMOPA, aa64_sme, do_outprod, a, MO_32, gen_helper_sme_bfmopa) +TRANS_FEAT(BFMOPA, aa64_sme, do_outprod_env, a, MO_32, gen_helper_sme_bfmopa) TRANS_FEAT(SMOPA_s, aa64_sme, do_outprod, a, MO_32, gen_helper_sme_smopa_s)TRANS_FEAT (UMOPA_s, aa64_sme, do_outprod, a,MO_32 , gen_helper_sme_umopa_s)
Signature · 1 line
2.34.1
Re: [PATCH 2/8] target/arm: Pass env pointer through to sme_bfmopa helper
Quoted 35 lines · Peter Maydell
To implement the
FEAT_EBF16semantics, we are going to need the CPUARMState env pointer in every helper function which callsbfdotadd().Pass the env pointer through from generated code to the
sme_bfmopahelper. (We'll add the code that uses it when we've adjusted all the helpers to have access to the env pointer.)Signed-off-by Peter Maydell <[email protected]>--- target/arm/tcg/helper-sme.h | 4 ++-- target/arm/tcg/sme_helper.c | 4 ++-- target/arm/tcg/translate-sme.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)target/arm/tcg/helper-sme.h +2
-2@@ -126,8 +126,8 @@ DEF_HELPER_FLAGS_7(sme_fmopa_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_7(sme_fmopa_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, ptr, ptr, i32) -DEF_HELPER_FLAGS_6(sme_bfmopa, TCG_CALL_NO_RWG, - void, ptr, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_7(sme_bfmopa, TCG_CALL_NO_RWG, + void, env, ptr, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_6(sme_smopa_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_6(sme_umopa_s, TCG_CALL_NO_RWG,target/arm/tcg/sme_helper.c +0
-0
target/arm/tcg/sme_helper.c void HELPER(sme_fmopa_h)(CPUARMState *env, · line 1084
Quoted 7 lines
target/arm/tcg/sme_helper.c +2
-2@@ -1080,8 +1080,8 @@ void HELPER(sme_fmopa_h)(CPUARMState *env, } } -void HELPER (sme_bfmopa )(void *vza,void *vzn,void *vzm,void *vpn, -void *vpm,uint32_t desc) +void HELPER (sme_bfmopa )(CPUARMState *env,void *vza,void *vzn,void *vzm, +void *vpn,void *vpm,uint32_t desc)
Per this morning's review of do_outprod_env, I think env should be penultimate, as for other gen_helper_gvec_5_ptr functions.
Otherwise,
r~
Quoted 16 lines
target/arm/tcg/sme_helper.c +0
-0{intptr_t row, col, oprsz =simd_maxsz (desc);uint32_t neg =simd_data (desc) *0x80008000u ;target/arm/tcg/translate-sme.c +1
-1@@ -355,7 +355,7 @@ TRANS_FEAT(FMOPA_d, aa64_sme_f64f64, do_outprod_fpst, a, MO_64, FPST_FPCR, gen_helper_sme_fmopa_d)/* TODO: FEAT_EBF16 */ -TRANS_FEAT(BFMOPA, aa64_sme, do_outprod, a, MO_32, gen_helper_sme_bfmopa) +TRANS_FEAT(BFMOPA, aa64_sme, do_outprod_env, a, MO_32, gen_helper_sme_bfmopa) TRANS_FEAT(SMOPA_s, aa64_sme, do_outprod, a, MO_32, gen_helper_sme_smopa_s)TRANS_FEAT (UMOPA_s, aa64_sme, do_outprod, a,MO_32 , gen_helper_sme_umopa_s)
PATCH 3/8 target/arm: Pass env pointer through to gvec_bfdot helper
In reply to Peter MaydellPass the env pointer through to the gvec_bfdot helper, so we can use it to add support for FEAT_EBF16.
--- target/arm/helper.h | 4 ++-- target/arm/tcg/translate-a64.c | 27 ++++++++++++++++++++++++- target/arm/tcg/translate-neon.c | 35 +++++++++++++++++++++++++++++++-- target/arm/tcg/translate-sve.c | 15 +++++++++++++- target/arm/tcg/vec_helper.c | 3 ++- 5 files changed, 77 insertions(+), 7 deletions(-)
target/arm/helper.h +2 -2
@@ -1027,8 +1027,8 @@ DEF_HELPER_FLAGS_5(gvec_ummla_b, TCG_CALL_NO_RWG,DEF_HELPER_FLAGS_5 (gvec_usmmla_b,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, i32) -DEF_HELPER_FLAGS_5 (gvec_bfdot,TCG_CALL_NO_RWG , - void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_6 (gvec_bfdot,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, ptr, i32)DEF_HELPER_FLAGS_5 (gvec_bfdot_idx,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, i32)
target/arm/tcg/translate-a64.c +26 -1
@@ -735,6 +735,22 @@ static void gen_gvec_op4_ool(DisasContext *s, bool is_q, int rd, int rn, is_q ? 16 : 8, vec_full_reg_size(s), data, fn); } +/* +* Expand a 4-operand operation using an out-of-line helper that takes +* a pointer to the CPU env. +*/ +static void gen_gvec_op4_env (DisasContext *s,bool is_q,int rd,int rn, +int rm,int ra,int data, +gen_helper_gvec_4_ptr *fn) +{ +tcg_gen_gvec_4_ptr (vec_full_reg_offset (s, rd), +vec_full_reg_offset (s, rn), +vec_full_reg_offset (s, rm), +vec_full_reg_offset (s, ra), + tcg_env, + is_q ?16 :8 ,vec_full_reg_size (s), data, fn); +} +/* * Expand a 4-operand + fpstatus pointer + simd data value operation using * an out-of-line helper.
@@ -5601,10 +5617,19 @@ static bool do_dot_vector(DisasContext *s, arg_qrrr_e *a,return true; } +static bool do_dot_vector_env (DisasContext *s,arg_qrrr_e *a, +gen_helper_gvec_4_ptr *fn) +{ +if (fp_access_check (s)) { +gen_gvec_op4_env (s, a->q, a->rd, a->rn, a->rm, a->rd,0 , fn); + } +return true; +} + TRANS_FEAT(SDOT_v, aa64_dp, do_dot_vector, a, gen_helper_gvec_sdot_b) TRANS_FEAT(UDOT_v, aa64_dp, do_dot_vector, a, gen_helper_gvec_udot_b) TRANS_FEAT(USDOT_v, aa64_i8mm, do_dot_vector, a, gen_helper_gvec_usdot_b) -TRANS_FEAT(BFDOT_v, aa64_bf16, do_dot_vector, a, gen_helper_gvec_bfdot) +TRANS_FEAT(BFDOT_v, aa64_bf16, do_dot_vector_env, a, gen_helper_gvec_bfdot) TRANS_FEAT(BFMMLA, aa64_bf16, do_dot_vector, a, gen_helper_gvec_bfmmla) TRANS_FEAT(SMMLA, aa64_i8mm, do_dot_vector, a, gen_helper_gvec_smmla_b)TRANS_FEAT (UMMLA , aa64_i8mm, do_dot_vector, a, gen_helper_gvec_ummla_b)
target/arm/tcg/translate-neon.c +33 -2
@@ -148,6 +148,37 @@ static bool do_neon_ddda(DisasContext *s, int q, int vd, int vn, int vm,return true; } +static bool do_neon_ddda_env (DisasContext *s,int q,int vd,int vn,int vm, +int data,gen_helper_gvec_4_ptr *fn_gvec) +{ +/* UNDEF accesses to D16-D31 if they don't exist. */ +if (((vd | vn | vm) &0x10 ) && !dc_isar_feature (aa32_simd_r32, s)) { +return false; + } + +/* +* UNDEF accesses to odd registers for each bit of Q. +* Q will be 0b111 for all Q-reg instructions, otherwise +* when we have mixed Q- and D-reg inputs. +*/ +if (((vd &1 ) *4 | (vn &1 ) *2 | (vm &1 )) & q) { +return false; + } + +if (!vfp_access_check (s)) { +return true; + } + +int opr_sz = q ?16 :8 ; +tcg_gen_gvec_4_ptr (vfp_reg_offset (1 , vd), +vfp_reg_offset (1 , vn), +vfp_reg_offset (1 , vm), +vfp_reg_offset (1 , vd), + tcg_env, + opr_sz, opr_sz, data, fn_gvec); +return true; +} +static bool do_neon_ddda_fpst (DisasContext *s,int q,int vd,int vn,int vm,int data,ARMFPStatusFlavour fp_flavour,gen_helper_gvec_4_ptr *fn_gvec_ptr)
@@ -266,8 +297,8 @@ static bool trans_VDOT_b16(DisasContext *s, arg_VDOT_b16 *a)if (!dc_isar_feature (aa32_bf16, s)) {return false; } -return do_neon_ddda (s, a->q *7 , a->vd, a->vn, a->vm,0 , - gen_helper_gvec_bfdot); +return do_neon_ddda_env (s, a->q *7 , a->vd, a->vn, a->vm,0 , + gen_helper_gvec_bfdot); }static bool trans_VFML (DisasContext *s,arg_VFML *a)
target/arm/tcg/translate-sve.c +14 -1
@@ -238,6 +238,19 @@ static bool gen_gvec_fpst_zzzz(DisasContext *s, gen_helper_gvec_4_ptr *fn,return ret; } +static bool gen_gvec_env_zzzz (DisasContext *s,gen_helper_gvec_4_ptr *fn, +int rd,int rn,int rm,int ra, +int data) +{ +return gen_gvec_ptr_zzzz (s, fn, rd, rn, rm, ra, data, tcg_env); +} + +static bool gen_gvec_env_arg_zzzz (DisasContext *s,gen_helper_gvec_4_ptr *fn, +arg_rrrr_esz *a,int data) +{ +return gen_gvec_env_zzzz (s, fn, a->rd, a->rn, a->rm, a->ra, data); +} +/* Invoke an out-of-line helper on 4 Zregs, 1 Preg, plus fpst. */ static bool gen_gvec_fpst_zzzzp(DisasContext *s, gen_helper_gvec_5_ptr *fn, int rd, int rn, int rm, int ra, int pg,
@@ -7099,7 +7112,7 @@ TRANS_FEAT_NONSTREAMING(USMMLA, aa64_sve_i8mm, gen_gvec_ool_arg_zzzz,TRANS_FEAT_NONSTREAMING (UMMLA , aa64_sve_i8mm, gen_gvec_ool_arg_zzzz, gen_helper_gvec_ummla_b, a, 0) -TRANS_FEAT (BFDOT_zzzz, aa64_sve_bf16, gen_gvec_ool_arg_zzzz, +TRANS_FEAT (BFDOT_zzzz, aa64_sve_bf16, gen_gvec_env_arg_zzzz, gen_helper_gvec_bfdot, a, 0)TRANS_FEAT (BFDOT_zzxz, aa64_sve_bf16, gen_gvec_ool_arg_zzxz, gen_helper_gvec_bfdot_idx, a)
target/arm/tcg/vec_helper.c +2 -1
@@ -2814,7 +2814,8 @@ float32 bfdotadd(float32 sum, uint32_t e1, uint32_t e2)return t1; } -void HELPER (gvec_bfdot )(void *vd,void *vn,void *vm,void *va,uint32_t desc) +void HELPER (gvec_bfdot )(void *vd,void *vn,void *vm,void *va, +void *envp,uint32_t desc) {intptr_t i, opr_sz =simd_oprsz (desc);float32 *d = vd, *a = va;
Signature · 1 line
2.34.1
Re: [PATCH 3/8] target/arm: Pass env pointer through to gvec_bfdot helper
Quoted 17 lines · Peter Maydell
Pass the env pointer through to the
gvec_bfdothelper, so we can use it to add support forFEAT_EBF16.Signed-off-by Peter Maydell <[email protected]>--- target/arm/helper.h | 4 ++-- target/arm/tcg/translate-a64.c | 27 ++++++++++++++++++++++++- target/arm/tcg/translate-neon.c | 35 +++++++++++++++++++++++++++++++-- target/arm/tcg/translate-sve.c | 15 +++++++++++++- target/arm/tcg/vec_helper.c | 3 ++- 5 files changed, 77 insertions(+), 7 deletions(-)target/arm/helper.h +0
-0
target/arm/helper.h DEF_HELPER_FLAGS_5(gvec_ummla_b, TCG_CALL_NO_RWG, · line 1031
Quoted 7 lines
target/arm/helper.h +2
-2@@ -1027,8 +1027,8 @@ DEF_HELPER_FLAGS_5(gvec_ummla_b, TCG_CALL_NO_RWG,DEF_HELPER_FLAGS_5 (gvec_usmmla_b,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, i32) -DEF_HELPER_FLAGS_5 (gvec_bfdot,TCG_CALL_NO_RWG , - void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_6 (gvec_bfdot,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, ptr, i32)
Because env expands to TCGv_ptr in the translation context, I suspect that you can use that here. Worth a try, anyway, so that
target/arm/helper.h DEF_HELPER_FLAGS_5(gvec_ummla_b, TCG_CALL_NO_RWG, · line 1033
Quoted 3 lines
target/arm/helper.h +2
-1-void HELPER (gvec_bfdot )(void *vd,void *vn,void *vm,void *va,uint32_t desc) +void HELPER (gvec_bfdot )(void *vd,void *vn,void *vm,void *va, +void *envp,uint32_t desc)
this doesn't have to use void *.
Either way,
r~
Re: [PATCH 3/8] target/arm: Pass env pointer through to gvec_bfdot helper
Quoted 30 lines · Richard Henderson
Quoted 17 lines · Peter Maydell
Pass the env pointer through to the
gvec_bfdothelper, so we can use it to add support forFEAT_EBF16.Signed-off-by Peter Maydell <[email protected]>--- target/arm/helper.h | 4 ++-- target/arm/tcg/translate-a64.c | 27 ++++++++++++++++++++++++- target/arm/tcg/translate-neon.c | 35 +++++++++++++++++++++++++++++++-- target/arm/tcg/translate-sve.c | 15 +++++++++++++- target/arm/tcg/vec_helper.c | 3 ++- 5 files changed, 77 insertions(+), 7 deletions(-)target/arm/helper.h +0
-0target/arm/helper.h DEF_HELPER_FLAGS_5(gvec_ummla_b, TCG_CALL_NO_RWG, · line 1031
Quoted 7 lines
target/arm/helper.h +2
-2@@ -1027,8 +1027,8 @@ DEF_HELPER_FLAGS_5(gvec_ummla_b, TCG_CALL_NO_RWG,DEF_HELPER_FLAGS_5 (gvec_usmmla_b,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, i32) -DEF_HELPER_FLAGS_5 (gvec_bfdot,TCG_CALL_NO_RWG , - void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_6 (gvec_bfdot,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, ptr, i32)Because env expands to
TCGv_ptrin the translation context, I suspect that you can use that here. Worth a try, anyway, so that
Quoted 5 lines
target/arm/helper.h DEF_HELPER_FLAGS_5(gvec_ummla_b, TCG_CALL_NO_RWG, · line 1033
Quoted 3 lines
target/arm/helper.h +2
-1-void HELPER (gvec_bfdot )(void *vd,void *vn,void *vm,void *va,uint32_t desc) +void HELPER (gvec_bfdot )(void *vd,void *vn,void *vm,void *va, +void *envp,uint32_t desc)this doesn't have to use void *.
I thought I'd tried that, but obviously I didn't hit on the right combination of types in the prototype/definition. This does work, so I've changed the patchset to use it.
thanks
-- PMM
PATCH 4/8 target/arm: Pass env pointer through to gvec_bfdot_idx helper
In reply to Peter MaydellPass the env pointer through to the gvec_bfdot_idx helper, so we can use it to add support for FEAT_EBF16.
--- target/arm/helper.h | 4 ++-- target/arm/tcg/translate-a64.c | 11 ++++++++++- target/arm/tcg/translate-neon.c | 4 ++-- target/arm/tcg/translate-sve.c | 8 +++++++- target/arm/tcg/vec_helper.c | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-)
target/arm/helper.h +2 -2
@@ -1029,8 +1029,8 @@ DEF_HELPER_FLAGS_5(gvec_usmmla_b, TCG_CALL_NO_RWG,DEF_HELPER_FLAGS_6 (gvec_bfdot,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, ptr, i32) -DEF_HELPER_FLAGS_5 (gvec_bfdot_idx,TCG_CALL_NO_RWG , - void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_6 (gvec_bfdot_idx,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, ptr, i32)DEF_HELPER_FLAGS_5 (gvec_bfmmla,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, i32)
target/arm/tcg/translate-a64.c +10 -1
@@ -6403,13 +6403,22 @@ static bool do_dot_vector_idx(DisasContext *s, arg_qrrx_e *a,return true; } +static bool do_dot_vector_idx_env (DisasContext *s,arg_qrrx_e *a, +gen_helper_gvec_4_ptr *fn) +{ +if (fp_access_check (s)) { +gen_gvec_op4_env (s, a->q, a->rd, a->rn, a->rm, a->rd, a->idx, fn); + } +return true; +} + TRANS_FEAT(SDOT_vi, aa64_dp, do_dot_vector_idx, a, gen_helper_gvec_sdot_idx_b) TRANS_FEAT(UDOT_vi, aa64_dp, do_dot_vector_idx, a, gen_helper_gvec_udot_idx_b)TRANS_FEAT (SUDOT_vi, aa64_i8mm, do_dot_vector_idx, a, gen_helper_gvec_sudot_idx_b)TRANS_FEAT (USDOT_vi, aa64_i8mm, do_dot_vector_idx, a, gen_helper_gvec_usdot_idx_b) -TRANS_FEAT (BFDOT_vi, aa64_bf16, do_dot_vector_idx, a, +TRANS_FEAT (BFDOT_vi, aa64_bf16, do_dot_vector_idx_env, a, gen_helper_gvec_bfdot_idx)static bool trans_BFMLAL_vi (DisasContext *s,arg_qrrx_e *a)
target/arm/tcg/translate-neon.c +2 -2
@@ -391,8 +391,8 @@ static bool trans_VDOT_b16_scal(DisasContext *s, arg_VDOT_b16_scal *a)if (!dc_isar_feature (aa32_bf16, s)) {return false; } -return do_neon_ddda (s, a->q *6 , a->vd, a->vn, a->vm, a->index, - gen_helper_gvec_bfdot_idx); +return do_neon_ddda_env (s, a->q *6 , a->vd, a->vn, a->vm, a->index, + gen_helper_gvec_bfdot_idx); }static bool trans_VFML_scalar (DisasContext *s,arg_VFML_scalar *a)
target/arm/tcg/translate-sve.c +7 -1
@@ -251,6 +251,12 @@ static bool gen_gvec_env_arg_zzzz(DisasContext *s, gen_helper_gvec_4_ptr *fn,return gen_gvec_env_zzzz (s, fn, a->rd, a->rn, a->rm, a->ra, data); } +static bool gen_gvec_env_arg_zzxz (DisasContext *s,gen_helper_gvec_4_ptr *fn, +arg_rrxr_esz *a) +{ +return gen_gvec_env_zzzz (s, fn, a->rd, a->rn, a->rm, a->ra, a->index); +} +/* Invoke an out-of-line helper on 4 Zregs, 1 Preg, plus fpst. */ static bool gen_gvec_fpst_zzzzp(DisasContext *s, gen_helper_gvec_5_ptr *fn, int rd, int rn, int rm, int ra, int pg,
@@ -7114,7 +7120,7 @@ TRANS_FEAT_NONSTREAMING(UMMLA, aa64_sve_i8mm, gen_gvec_ool_arg_zzzz,TRANS_FEAT (BFDOT_zzzz, aa64_sve_bf16, gen_gvec_env_arg_zzzz, gen_helper_gvec_bfdot, a, 0) -TRANS_FEAT (BFDOT_zzxz, aa64_sve_bf16, gen_gvec_ool_arg_zzxz, +TRANS_FEAT (BFDOT_zzxz, aa64_sve_bf16, gen_gvec_env_arg_zzxz, gen_helper_gvec_bfdot_idx, a) TRANS_FEAT_NONSTREAMING(BFMMLA, aa64_sve_bf16, gen_gvec_ool_arg_zzzz,
target/arm/tcg/vec_helper.c +1 -1
@@ -2828,7 +2828,7 @@ void HELPER(gvec_bfdot)(void *vd, void *vn, void *vm, void *va, }void HELPER (gvec_bfdot_idx )(void *vd,void *vn,void *vm, -void *va,uint32_t desc) +void *va,void *envp,uint32_t desc) {intptr_t i, j, opr_sz =simd_oprsz (desc);intptr_t index =simd_data (desc);
Signature · 1 line
2.34.1
Re: [PATCH 4/8] target/arm: Pass env pointer through to gvec_bfdot_idx helper
Quoted 11 lines · Peter Maydell
Pass the env pointer through to the
gvec_bfdot_idxhelper, so we can use it to add support forFEAT_EBF16.Signed-off-by Peter Maydell <[email protected]>--- target/arm/helper.h | 4 ++-- target/arm/tcg/translate-a64.c | 11 ++++++++++- target/arm/tcg/translate-neon.c | 4 ++-- target/arm/tcg/translate-sve.c | 8 +++++++- target/arm/tcg/vec_helper.c | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-)
r~
PATCH 5/8 target/arm: Pass env pointer through to gvec_bfmmla helper
In reply to Peter MaydellPass the env pointer through to the gvec_bfmmla helper, so we can use it to add support for FEAT_EBF16.
--- target/arm/helper.h | 4 ++-- target/arm/tcg/translate-a64.c | 2 +- target/arm/tcg/translate-neon.c | 4 ++-- target/arm/tcg/translate-sve.c | 2 +- target/arm/tcg/vec_helper.c | 3 ++- 5 files changed, 8 insertions(+), 7 deletions(-)
target/arm/helper.h +2 -2
@@ -1032,8 +1032,8 @@ DEF_HELPER_FLAGS_6(gvec_bfdot, TCG_CALL_NO_RWG,DEF_HELPER_FLAGS_6 (gvec_bfdot_idx,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, ptr, i32) -DEF_HELPER_FLAGS_5 (gvec_bfmmla,TCG_CALL_NO_RWG , - void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_6 (gvec_bfmmla,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, ptr, i32)DEF_HELPER_FLAGS_6 (gvec_bfmlal,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, ptr, i32)
target/arm/tcg/translate-a64.c +1 -1
@@ -5630,7 +5630,7 @@ TRANS_FEAT(SDOT_v, aa64_dp, do_dot_vector, a, gen_helper_gvec_sdot_b) TRANS_FEAT(UDOT_v, aa64_dp, do_dot_vector, a, gen_helper_gvec_udot_b) TRANS_FEAT(USDOT_v, aa64_i8mm, do_dot_vector, a, gen_helper_gvec_usdot_b) TRANS_FEAT(BFDOT_v, aa64_bf16, do_dot_vector_env, a, gen_helper_gvec_bfdot) -TRANS_FEAT(BFMMLA, aa64_bf16, do_dot_vector, a, gen_helper_gvec_bfmmla) +TRANS_FEAT(BFMMLA, aa64_bf16, do_dot_vector_env, a, gen_helper_gvec_bfmmla) TRANS_FEAT(SMMLA, aa64_i8mm, do_dot_vector, a, gen_helper_gvec_smmla_b) TRANS_FEAT(UMMLA, aa64_i8mm, do_dot_vector, a, gen_helper_gvec_ummla_b)TRANS_FEAT (USMMLA , aa64_i8mm, do_dot_vector, a, gen_helper_gvec_usmmla_b)
target/arm/tcg/translate-neon.c +2 -2
@@ -3730,8 +3730,8 @@ static bool trans_VMMLA_b16(DisasContext *s, arg_VMMLA_b16 *a)if (!dc_isar_feature (aa32_bf16, s)) {return false; } -return do_neon_ddda (s,7 , a->vd, a->vn, a->vm,0 , - gen_helper_gvec_bfmmla); +return do_neon_ddda_env (s,7 , a->vd, a->vn, a->vm,0 , + gen_helper_gvec_bfmmla); }static bool trans_VFMA_b16 (DisasContext *s,arg_VFMA_b16 *a)
target/arm/tcg/translate-sve.c +1 -1
@@ -7123,7 +7123,7 @@ TRANS_FEAT(BFDOT_zzzz, aa64_sve_bf16, gen_gvec_env_arg_zzzz,TRANS_FEAT (BFDOT_zzxz, aa64_sve_bf16, gen_gvec_env_arg_zzxz, gen_helper_gvec_bfdot_idx, a) -TRANS_FEAT_NONSTREAMING (BFMMLA , aa64_sve_bf16, gen_gvec_ool_arg_zzzz, +TRANS_FEAT_NONSTREAMING (BFMMLA , aa64_sve_bf16, gen_gvec_env_arg_zzzz, gen_helper_gvec_bfmmla, a, 0)static bool do_BFMLAL_zzzw (DisasContext *s,arg_rrrr_esz *a,bool sel)
target/arm/tcg/vec_helper.c +2 -1
@@ -2847,7 +2847,8 @@ void HELPER(gvec_bfdot_idx)(void *vd, void *vn, void *vm,clear_tail (d, opr_sz,simd_maxsz (desc)); } -void HELPER (gvec_bfmmla )(void *vd,void *vn,void *vm,void *va,uint32_t desc) +void HELPER (gvec_bfmmla )(void *vd,void *vn,void *vm,void *va, +void *envp,uint32_t desc) {intptr_t s, opr_sz =simd_oprsz (desc);float32 *d = vd, *a = va;
Signature · 1 line
2.34.1
Re: [PATCH 5/8] target/arm: Pass env pointer through to gvec_bfmmla helper
Quoted 11 lines · Peter Maydell
Pass the env pointer through to the
gvec_bfmmlahelper, so we can use it to add support forFEAT_EBF16.Signed-off-by Peter Maydell<[email protected]>--- target/arm/helper.h | 4 ++-- target/arm/tcg/translate-a64.c | 2 +- target/arm/tcg/translate-neon.c | 4 ++-- target/arm/tcg/translate-sve.c | 2 +- target/arm/tcg/vec_helper.c | 3 ++- 5 files changed, 8 insertions(+), 7 deletions(-)
r~
PATCH 6/8 target/arm: Prepare bfdotadd() callers for FEAT_EBF support
In reply to Peter MaydellWe use bfdotadd() in four callsites for various helper functions. Currently this all assumes that we have the FPCR.EBF=0 semantics. For FPCR.EBF=1 we will need to:
* call a different routine to bfdotadd() because we need to do a fused multiply-add rather than separate multiply and add steps
* use a different float_status that honours the FPCR rounding mode and denormal-flushing fields
* pass in an extra float_status that has been set up to perform round-to-odd rounding
To prepare for this, refactor all the callsites so that instead of
for (...) {
x = bfdotadd(...);}
they are:
float_status fpst, fpst_odd;
if (is_ebf(env, &fpst, &fpst_odd)) {
for (...) {
x = bfdotadd_ebf(..., &fpst, &fpst_odd);
}
} else {
for (...) {
x = bfdotadd(..., &fpst);
}}
For the moment the is_ebf() function always returns false, sets up fpst for EBF=0 semantics and never sets up fpst_odd; bfdotadd_ebf() will assert if called. We'll fill in the handling for EBF=1 in the next commit.
This change should be a zero-behaviour-change refactor.
--- target/arm/tcg/vec_internal.h | 37 ++++++++- target/arm/tcg/sme_helper.c | 74 ++++++++++++------ target/arm/tcg/vec_helper.c | 141 +++++++++++++++++++++++++--------- 3 files changed, 192 insertions(+), 60 deletions(-)
target/arm/tcg/vec_internal.h +35 -2
@@ -223,13 +223,46 @@ int64_t do_sqrdmlah_d(int64_t, int64_t, int64_t, bool, bool);* bfdotadd: * @sum: addend * @e1, @e2: multiplicand vectors +* @fpst: floating-point status to use * * BFloat16 2-way dot product of @e1 & @e2, accumulating with @sum. * The @e1 and @e2 operands correspond to the 32-bit source vector * slots and contain two Bfloat16 values each. * -* Corresponds to the ARM pseudocode function BFDotAdd. +* Corresponds to the ARM pseudocode function BFDotAdd, specialized +* for the FPCR.EBF == 0 case. */ -float32 bfdotadd (float32 sum,uint32_t e1,uint32_t e2); +float32 bfdotadd (float32 sum,uint32_t e1,uint32_t e2,float_status *fpst); +/** +* bfdotadd_ebf: +* @sum: addend +* @e1, @e2: multiplicand vectors +* @fpst: floating-point status to use +* @fpst_odd: floating-point status to use for round-to-odd operations +* +* BFloat16 2-way dot product of @e1 & @e2, accumulating with @sum. +* The @e1 and @e2 operands correspond to the 32-bit source vector +* slots and contain two Bfloat16 values each. +* +* Corresponds to the ARM pseudocode function BFDotAdd, specialized +* for the FPCR.EBF == 1 case. +*/ +float32 bfdotadd_ebf (float32 sum,uint32_t e1,uint32_t e2, +float_status *fpst,float_status *fpst_odd); + +/** +* is_ebf: +* @env: CPU state +* @statusp: pointer to floating point status to fill in +* @oddstatusp: pointer to floating point status to fill in for round-to-odd +* +* Determine whether a BFDotAdd operation should use FPCR.EBF = 0 +* or FPCR.EBF = 1 semantics. On return, has initialized *statusp +* and *oddstatusp to suitable float_status arguments to use with either +* bfdotadd() or bfdotadd_ebf(). +* Returns true for EBF = 1, false for EBF = 0. (The caller should use this +* to decide whether to call bfdotadd() or bfdotadd_ebf().) +*/ +bool is_ebf (CPUARMState *env,float_status *statusp,float_status *oddstatusp);#endif /* TARGET_ARM_VEC_INTERNAL_H */
target/arm/tcg/sme_helper.c +52 -22
84 lines not on this page · raw message
target/arm/tcg/vec_helper.c +105 -36
199 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 6/8] target/arm: Prepare bfdotadd() callers for FEAT_EBF support
Quoted 32 lines · Peter Maydell
We use
bfdotadd()in four callsites for various helper functions. Currently this all assumes that we have the FPCR.EBF=0 semantics. For FPCR.EBF=1 we will need to:
* call a different routine tobfdotadd()because we need to do a fused multiply-add rather than separate multiply and add steps
* use a differentfloat_statusthat honours the FPCR rounding mode and denormal-flushing fields
* pass in an extrafloat_statusthat has been set up to perform round-to-odd roundingTo prepare for this, refactor all the callsites so that instead of
for (...) { x = bfdotadd(...); }they are:
float_status fpst, fpst_odd; if (is_ebf(env, &fpst, &fpst_odd)) { for (...) { x = bfdotadd_ebf(..., &fpst, &fpst_odd); } } else { for (...) { x = bfdotadd(..., &fpst); } }For the moment the
is_ebf()function always returns false, sets up fpst for EBF=0 semantics and never sets upfpst_odd;bfdotadd_ebf()will assert if called. We'll fill in the handling for EBF=1 in the next commit.
Quoted 8 lines
This change should be a zero-behaviour-change refactor.
Signed-off-by Peter Maydell<[email protected]>--- target/arm/tcg/vec_internal.h | 37 ++++++++- target/arm/tcg/sme_helper.c | 74 ++++++++++++------ target/arm/tcg/vec_helper.c | 141 +++++++++++++++++++++++++--------- 3 files changed, 192 insertions(+), 60 deletions(-)
r~
Re: [PATCH 6/8] target/arm: Prepare bfdotadd() callers for FEAT_EBF support
In reply to Peter MaydellQuoted 10 lines · Peter Maydell
target/arm/tcg/vec_helper.c +1
-1@@ -2790,7 +2790,7 @@ DO_MMLA_B(gvec_usmmla_b, do_usmmla_b)* BFloat16 Dot Product */ -float32 bfdotadd (float32 sum,uint32_t e1,uint32_t e2) +bool is_ebf (CPUARMState *env,float_status *statusp,float_status *oddstatusp) {/* FPCR is ignored for BFDOT and BFMMLA. */ float_status bf_status = {
target/arm/tcg/vec_helper.c float32 bfdotadd(float32 sum, uint32_t e1, uint32_t e2) · line 2806
Quoted 7 lines
target/arm/tcg/vec_helper.c +4
-0@@ -2800,29 +2800,50 @@ float32 bfdotadd(float32 sum, uint32_t e1, uint32_t e2) .flush_inputs_to_zero = true, .default_nan_mode = true, }; + + *statusp = bf_status; +return false; +}
Looking at the next patch, I think dropping the local variable is better.
*statusp = (float_status){
...
};r~
Re: [PATCH 6/8] target/arm: Prepare bfdotadd() callers for FEAT_EBF support
Quoted 22 lines · Richard Henderson
Quoted 10 lines · Peter Maydell
target/arm/tcg/vec_helper.c +1
-1@@ -2790,7 +2790,7 @@ DO_MMLA_B(gvec_usmmla_b, do_usmmla_b)* BFloat16 Dot Product */ -float32 bfdotadd (float32 sum,uint32_t e1,uint32_t e2) +bool is_ebf (CPUARMState *env,float_status *statusp,float_status *oddstatusp) {/* FPCR is ignored for BFDOT and BFMMLA. */ float_status bf_status = {target/arm/tcg/vec_helper.c float32 bfdotadd(float32 sum, uint32_t e1, uint32_t e2) · line 2806
Quoted 7 lines
target/arm/tcg/vec_helper.c +4
-0@@ -2800,29 +2800,50 @@ float32 bfdotadd(float32 sum, uint32_t e1, uint32_t e2) .flush_inputs_to_zero = true, .default_nan_mode = true, }; + + *statusp = bf_status; +return false; +}Looking at the next patch, I think dropping the local variable is better.
Quoted 3 lines
*statusp = (float_status){
...
};Yes, I agree; I've updated this patch and the next accordingly.
-- PMM
PATCH 7/8 target/arm: Implement FPCR.EBF=1 semantics for bfdotadd()
In reply to Peter MaydellImplement the FPCR.EBF=1 semantics for bfdotadd() operations:
* is_ebf() sets up fpst and fpst_odd
* bfdotadd_ebf() implements the fused paired-multiply-and-add operation that we need
The paired-multiply-and-add is similar to f16_dotadd() and we use the same trick here as in that function, but the inputs here are bfloat16 rather than float16.
--- target/arm/tcg/vec_helper.c | 57 +++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-)
target/arm/tcg/vec_helper.c +54 -3
@@ -2792,7 +2792,20 @@ DO_MMLA_B(gvec_usmmla_b, do_usmmla_b)bool is_ebf (CPUARMState *env,float_status *statusp,float_status *oddstatusp) { -/* FPCR is ignored for BFDOT and BFMMLA. */ +/* +* For BFDOT, BFMMLA, etc, the behaviour depends on FPCR.EBF. +* For EBF = 0, we ignore the FPCR bits which determine rounding +* mode and denormal-flushing, and we do unfused multiplies and +* additions with intermediate rounding of all products and sums. +* For EBF = 1, we honour FPCR rounding mode and denormal-flushing bits, +* and we perform a fused two-way sum-of-products without intermediate +* rounding of the products. +* In either case, we don't set fp exception flags. +* +* EBF is AArch64 only, so even if it's set in the FPCR it has +* no effect on AArch32 instructions. +*/ +bool ebf =is_a64 (env) && env->vfp.fpcr &FPCR_EBF ;float_status bf_status = { .tininess_before_rounding = float_tininess_before_rounding, .float_rounding_mode = float_round_to_odd_inf,
@@ -2801,8 +2814,19 @@ bool is_ebf(CPUARMState *env, float_status *statusp, float_status *oddstatusp) .default_nan_mode = true, }; +if (ebf) { +float_status *fpst = &env->vfp.fp_status; +set_flush_to_zero (get_flush_to_zero (fpst), &bf_status); +set_flush_inputs_to_zero (get_flush_inputs_to_zero (fpst), &bf_status); +set_float_rounding_mode (get_float_rounding_mode (fpst), &bf_status); + +/* EBF=1 needs to do a step with round-to-odd semantics */ + *oddstatusp = bf_status; +set_float_rounding_mode (float_round_to_odd, oddstatusp); + } + *statusp = bf_status; -return false; +return ebf; }float32 bfdotadd (float32 sum,uint32_t e1,uint32_t e2,float_status *fpst)
@@ -2824,7 +2848,34 @@ float32 bfdotadd(float32 sum, uint32_t e1, uint32_t e2, float_status *fpst)float32 bfdotadd_ebf (float32 sum,uint32_t e1,uint32_t e2,float_status *fpst,float_status *fpst_odd) { -g_assert_not_reached (); +/* +* Compare f16_dotadd() in sme_helper.c, but here we have +* bfloat16 inputs. In particular that means that we do not +* want the FPCR.FZ16 flush semantics, so we use the normal +* float_status for the input handling here. +*/ +float64 e1r =float32_to_float64 (e1 <<16 , fpst); +float64 e1c =float32_to_float64 (e1 &0xffff0000u , fpst); +float64 e2r =float32_to_float64 (e2 <<16 , fpst); +float64 e2c =float32_to_float64 (e2 &0xffff0000u , fpst); +float64 t64; +float32 t32; + +/* +* The ARM pseudocode function FPDot performs both multiplies +* and the add with a single rounding operation. Emulate this +* by performing the first multiply in round-to-odd, then doing +* the second multiply as fused multiply-add, and rounding to +* float32 all in one step. +*/ + t64 =float64_mul (e1r, e2r, fpst_odd); + t64 =float64r32_muladd (e1c, e2c, t64,0 , fpst); + +/* This conversion is exact, because we've already rounded. */ + t32 =float64_to_float32 (t64, fpst); + +/* The final accumulation step is not fused. */ +return float32_add (sum, t32, fpst); } void HELPER(gvec_bfdot)(void *vd, void *vn, void *vm, void *va,
Signature · 1 line
2.34.1
Re: [PATCH 7/8] target/arm: Implement FPCR.EBF=1 semantics for bfdotadd()
Quoted 5 lines · Peter Maydell
Implement the FPCR.EBF=1 semantics for
bfdotadd()operations:
*is_ebf()sets up fpst andfpst_odd
*bfdotadd_ebf()implements the fused paired-multiply-and-add operation that we need
Quoted 8 lines
The paired-multiply-and-add is similar to
f16_dotadd()and we use the same trick here as in that function, but the inputs here are bfloat16 rather than float16.Signed-off-by Peter Maydell<[email protected]>--- target/arm/tcg/vec_helper.c | 57 +++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-)
r~
PATCH 8/8 target/arm: Enable FEAT_EBF16 in the "max" CPU
In reply to Peter MaydellNow that we've implemented the required behaviour for FEAT_EBF16, we can enable it for the "max" CPU type, list it in our documentation, and delete a TODO comment about it being missing.
--- docs/system/arm/emulation.rst | 1 + target/arm/tcg/cpu64.c | 4 ++-- target/arm/tcg/translate-sme.c | 1 - 3 files changed, 3 insertions(+), 3 deletions(-)
docs/system/arm/emulation.rst +1 -0
@@ -45,6 +45,7 @@ the following architecture extensions: - FEAT_DotProd (Advanced SIMD dot product instructions) - FEAT_DoubleFault (Double Fault Extension) - FEAT_E0PD (Preventing EL0 access to halves of address maps) +- FEAT_EBF16 (AArch64 Extended BFloat16 instructions) - FEAT_ECV (Enhanced Counter Virtualization) - FEAT_EL0 (Support for execution at EL0) - FEAT_EL1 (Support for execution at EL1)
target/arm/tcg/cpu64.c +2 -2
@@ -1160,7 +1160,7 @@ void aarch64_max_tcg_initfn(Object *obj) t =FIELD_DP64 (t,ID_AA64ISAR1 ,FRINTTS ,1 );/* FEAT_FRINTTS */ t =FIELD_DP64 (t,ID_AA64ISAR1 ,SB ,1 );/* FEAT_SB */ t =FIELD_DP64 (t,ID_AA64ISAR1 ,SPECRES ,1 );/* FEAT_SPECRES */ - t =FIELD_DP64 (t,ID_AA64ISAR1 ,BF16 ,1 );/* FEAT_BF16 */ + t =FIELD_DP64 (t,ID_AA64ISAR1 ,BF16 ,2 );/* FEAT_BF16, FEAT_EBF16 */ t =FIELD_DP64 (t,ID_AA64ISAR1 ,DGH ,1 );/* FEAT_DGH */ t =FIELD_DP64 (t,ID_AA64ISAR1 ,I8MM ,1 );/* FEAT_I8MM */ cpu->isar.id_aa64isar1 = t;
@@ -1244,7 +1244,7 @@ void aarch64_max_tcg_initfn(Object *obj) t =FIELD_DP64 (t,ID_AA64ZFR0 ,SVEVER ,1 ); t =FIELD_DP64 (t,ID_AA64ZFR0 ,AES ,2 );/* FEAT_SVE_PMULL128 */ t =FIELD_DP64 (t,ID_AA64ZFR0 ,BITPERM ,1 );/* FEAT_SVE_BitPerm */ - t =FIELD_DP64 (t,ID_AA64ZFR0 ,BFLOAT16 ,1 );/* FEAT_BF16 */ + t =FIELD_DP64 (t,ID_AA64ZFR0 ,BFLOAT16 ,2 );/* FEAT_BF16, FEAT_EBF16 */ t =FIELD_DP64 (t,ID_AA64ZFR0 ,SHA3 ,1 );/* FEAT_SVE_SHA3 */ t =FIELD_DP64 (t,ID_AA64ZFR0 ,SM4 ,1 );/* FEAT_SVE_SM4 */ t =FIELD_DP64 (t,ID_AA64ZFR0 ,I8MM ,1 );/* FEAT_I8MM */
target/arm/tcg/translate-sme.c +0 -1
@@ -354,7 +354,6 @@ TRANS_FEAT(FMOPA_s, aa64_sme, do_outprod_fpst, a,TRANS_FEAT (FMOPA_d, aa64_sme_f64f64, do_outprod_fpst, a, MO_64, FPST_FPCR, gen_helper_sme_fmopa_d) -/* TODO: FEAT_EBF16 */ TRANS_FEAT(BFMOPA, aa64_sme, do_outprod_env, a, MO_32, gen_helper_sme_bfmopa)TRANS_FEAT (SMOPA_s, aa64_sme, do_outprod, a,MO_32 , gen_helper_sme_smopa_s)
Signature · 1 line
2.34.1
Re: [PATCH 8/8] target/arm: Enable FEAT_EBF16 in the "max" CPU
Quoted 10 lines · Peter Maydell
Now that we've implemented the required behaviour for
FEAT_EBF16, we can enable it for the "max" CPU type, list it in our documentation, and delete a TODO comment about it being missing.Signed-off-by Peter Maydell<[email protected]>--- docs/system/arm/emulation.rst | 1 + target/arm/tcg/cpu64.c | 4 ++-- target/arm/tcg/translate-sme.c | 1 - 3 files changed, 3 insertions(+), 3 deletions(-)
r~