target/arm: Scalable Matrix Extension
v2 cover target/arm: Scalable Matrix Extension
Changes for v2:
* Incorporate feedback from v1.
Richard Henderson (71):
target/arm: Rename TBFLAG_A64 ZCR_LEN to VL linux-user/aarch64: Introduce sve_vq
target/arm: Remove route_to_el2 check from sve_exception_el target/arm: Remove fp checks from sve_exception_el target/arm: Add el_is_in_host
target/arm: Use el_is_in_host for sve_zcr_len_for_el target/arm: Use el_is_in_host for sve_exception_el target/arm: Hoist arm_is_el2_enabled check in sve_exception_el target/arm: Do not use aarch64_sve_zcr_get_valid_len in reset target/arm: Merge aarch64_sve_zcr_get_valid_len into caller target/arm: Use uint32_t instead of bitmap for sve vq's target/arm: Rename sve_zcr_len_for_el to sve_vqm1_for_el target/arm: Split out load/store primitives to sve_ldst_internal.h target/arm: Export sve contiguous ldst support functions target/arm: Move expand_pred_b to vec_internal.h target/arm: Use expand_pred_b in mve_helper.c
target/arm: Move expand_pred_h to vec_internal.h target/arm: Export bfdotadd from vec_helper.c
target/arm: Add isar_feature_aa64_sme
target/arm: Add ID_AA64SMFR0_EL1
target/arm: Implement TPIDR2_EL0
target/arm: Add SMEEXC_EL to TB flags
target/arm: Add syn_smetrap
target/arm: Add ARM_CP_SME
target/arm: Add SVCR
target/arm: Add SMCR_ELx
target/arm: Add SMIDR_EL1, SMPRI_EL1, SMPRIMAP_EL2 target/arm: Add PSTATE.{SM,ZA} to TB flags
target/arm: Add the SME ZA storage to CPUARMState target/arm: Implement SMSTART, SMSTOP
target/arm: Move error for sve%d property to arm_cpu_sve_finalize target/arm: Create ARMVQMap
target/arm: Generalize cpu_arm_{get,set}_vq
target/arm: Generalize cpu_arm_{get,set}_default_vec_len target/arm: Move arm_cpu_*_finalize to internals.h target/arm: Unexport aarch64_add_*_properties
target/arm: Add cpu properties for SME
target/arm: Introduce sve_vqm1_for_el_sm
target/arm: Add SVL to TB flags
target/arm: Move pred_{full,gvec}_reg_{offset,size} to translate-a64.h target/arm: Add infrastructure for disas_sme
target/arm: Trap AdvSIMD usage when Streaming SVE is active target/arm: Implement SME RDSVL, ADDSVL, ADDSPL target/arm: Implement SME ZERO
target/arm: Implement SME MOVA
target/arm: Implement SME LD1, ST1
target/arm: Export unpredicated ld/st from translate-sve.c target/arm: Implement SME LDR, STR
target/arm: Implement SME ADDHA, ADDVA
target/arm: Implement FMOPA, FMOPS (non-widening) target/arm: Implement BFMOPA, BFMOPS
target/arm: Implement FMOPA, FMOPS (widening)
target/arm: Implement SME integer outer product target/arm: Implement PSEL
target/arm: Implement REVD
target/arm: Implement SCLAMP, UCLAMP
target/arm: Reset streaming sve state on exception boundaries target/arm: Enable SME for -cpu max
linux-user/aarch64: Clear tpidr2_el0 if CLONE_SETTLS linux-user/aarch64: Reset PSTATE.SM on syscalls linux-user/aarch64: Add SM bit to SVE signal context linux-user/aarch64: Tidy target_restore_sigframe error return linux-user/aarch64: Do not allow duplicate or short sve records linux-user/aarch64: Verify extra record lock succeeded linux-user/aarch64: Move sve record checks into restore linux-user/aarch64: Implement SME signal handling
linux-user: Rename sve prctls
linux-user/aarch64: Implement PR_SME_GET_VL, PR_SME_SET_VL target/arm: Only set ZEN in reset if SVE present target/arm: Enable SME for user-only
linux-user/aarch64: Add SME related hwcap entries
linux-user/aarch64/target_cpu.h | 5 +- linux-user/aarch64/target_prctl.h | 76 +- target/arm/cpregs.h | 5 + target/arm/cpu.h | 146 +++- target/arm/helper-sme.h | 146 ++++ target/arm/helper-sve.h | 4 + target/arm/helper.h | 19 + target/arm/internals.h | 22 +- target/arm/kvm_arm.h | 7 +- target/arm/sve_ldst_internal.h | 221 ++++++ target/arm/syndrome.h | 14 + target/arm/translate-a64.h | 55 +- target/arm/translate.h | 16 +- target/arm/vec_internal.h | 28 +- linux-user/aarch64/cpu_loop.c | 9 + linux-user/aarch64/signal.c | 242 +++++- linux-user/elfload.c | 20 + linux-user/syscall.c | 28 +- target/arm/arch_dump.c | 2 +- target/arm/cpu.c | 39 +- target/arm/cpu64.c | 311 +++++--- target/arm/gdbstub64.c | 2 +- target/arm/helper.c | 395 ++++++++-- target/arm/kvm64.c | 47 +- target/arm/machine.c | 34 + target/arm/mve_helper.c | 6 +- target/arm/sme_helper.c | 1174 +++++++++++++++++++++++++++++ target/arm/sve_helper.c | 260 ++----- target/arm/translate-a64.c | 147 +++- target/arm/translate-sme.c | 353 +++++++++ target/arm/translate-sve.c | 283 +++++-- target/arm/translate-vfp.c | 13 + target/arm/translate.c | 1 + target/arm/vec_helper.c | 52 +- docs/system/arm/emulation.rst | 4 + target/arm/meson.build | 4 + target/arm/sme-fa64.decode | 89 +++ target/arm/sme.decode | 88 +++ target/arm/sve.decode | 31 +- 39 files changed, 3804 insertions(+), 594 deletions(-) create mode 100644 target/arm/helper-sme.h create mode 100644 target/arm/sve_ldst_internal.h create mode 100644 target/arm/sme_helper.c create mode 100644 target/arm/translate-sme.c create mode 100644 target/arm/sme-fa64.decode create mode 100644 target/arm/sme.decode
Signature · 1 line
2.34.1
PATCH v2 1/71 target/arm: Rename TBFLAG_A64 ZCR_LEN to VL
With SME, the vector length does not only come from ZCR_ELx. Comment that this is either NVL or SVL, like the pseudocode.
---
v2: Renamed from SVE_LEN to VL.
--- target/arm/cpu.h | 3 ++- target/arm/translate-a64.h | 2 +- target/arm/translate.h | 2 +- target/arm/helper.c | 2 +- target/arm/translate-a64.c | 2 +- target/arm/translate-sve.c | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-)
target/arm/cpu.h +2 -1
@@ -3241,7 +3241,8 @@ FIELD(TBFLAG_M32, MVE_NO_PRED, 5, 1) /* Not cached. */*/ FIELD(TBFLAG_A64, TBII, 0, 2)FIELD (TBFLAG_A64 ,SVEEXC_EL ,2 ,2 ) -FIELD(TBFLAG_A64, ZCR_LEN, 4, 4) +/* The current vector length, either NVL or SVL. */ +FIELD(TBFLAG_A64, VL, 4, 4) FIELD(TBFLAG_A64, PAUTH_ACTIVE, 8, 1) FIELD(TBFLAG_A64, BT, 9, 1)FIELD (TBFLAG_A64 ,BTYPE ,10 ,2 )/* Not cached. */
target/arm/translate-a64.h +1 -1
@@ -104,7 +104,7 @@ static inline TCGv_ptr vec_full_reg_ptr(DisasContext *s, int regno)/* Return the byte size of the "whole" vector register, VL / 8. */ static inline int vec_full_reg_size (DisasContext *s) { -return s->sve_len; +return s->vl; }bool disas_sve (DisasContext *,uint32_t );
target/arm/translate.h +1 -1
@@ -42,7 +42,7 @@ typedef struct DisasContext {bool ns;/* Use non-secure CPREG bank on access */ int fp_excp_el;/* FP exception EL or 0 if enabled */ int sve_excp_el;/* SVE exception EL or 0 if enabled */ -int sve_len;/* SVE vector length in bytes */ +int vl;/* current vector length in bytes */ /* Flag indicating that exceptions from secure mode are routed to EL3. */ bool secure_routed_to_el3;bool vfp_enabled;/* FP enabled via FPSCR.EN */
target/arm/helper.c +1 -1
@@ -13696,7 +13696,7 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, zcr_len =sve_zcr_len_for_el (env, el); }DP_TBFLAG_A64 (flags,SVEEXC_EL , sve_el); -DP_TBFLAG_A64 (flags,ZCR_LEN , zcr_len); +DP_TBFLAG_A64 (flags,VL , zcr_len); } sctlr =regime_sctlr (env, stage1);
target/arm/translate-a64.c +1 -1
@@ -14608,7 +14608,7 @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, dc->align_mem =EX_TBFLAG_ANY (tb_flags,ALIGN_MEM ); dc->pstate_il =EX_TBFLAG_ANY (tb_flags,PSTATE__IL ); dc->sve_excp_el =EX_TBFLAG_A64 (tb_flags,SVEEXC_EL ); - dc->sve_len = (EX_TBFLAG_A64 (tb_flags,ZCR_LEN ) +1 ) *16 ; + dc->vl = (EX_TBFLAG_A64 (tb_flags,VL ) +1 ) *16 ; dc->pauth_active =EX_TBFLAG_A64 (tb_flags,PAUTH_ACTIVE ); dc->bt =EX_TBFLAG_A64 (tb_flags,BT ); dc->btype =EX_TBFLAG_A64 (tb_flags,BTYPE );
target/arm/translate-sve.c +1 -1
@@ -111,7 +111,7 @@ static inline int pred_full_reg_offset(DisasContext *s, int regno)/* Return the byte size of the whole predicate register, VL / 64. */ static inline int pred_full_reg_size (DisasContext *s) { -return s->sve_len >>3 ; +return s->vl >>3 ; }/* Round up the size of a register to a size allowed by
Signature · 1 line
2.34.1
PATCH v2 2/71 linux-user/aarch64: Introduce sve_vq
In reply to Richard HendersonAdd an interface function to extract the digested vector length rather than the raw zcr_el[1] value. This fixes an incorrect return from do_prctl_set_vl where we didn't take into account the set of vector lengths supported by the cpu.
---
v2: Add sve_vq_cached rather than directly access hflags.
v3: Rename to sve_vq.
--- linux-user/aarch64/target_prctl.h | 20 +++++++++++++------- target/arm/cpu.h | 11 +++++++++++ linux-user/aarch64/signal.c | 4 ++-- 3 files changed, 26 insertions(+), 9 deletions(-)
linux-user/aarch64/target_prctl.h +13 -7
@@ -10,7 +10,7 @@ static abi_long do_prctl_get_vl(CPUArchState *env) {ARMCPU *cpu =env_archcpu (env);if (cpu_isar_feature (aa64_sve, cpu)) { -return ((cpu->env.vfp.zcr_el[1 ] &0xf ) +1 ) *16 ; +return sve_vq (env) *16 ; }return -TARGET_EINVAL ; }
@@ -25,18 +25,24 @@ static abi_long do_prctl_set_vl(CPUArchState *env, abi_long arg2)*/ if (cpu_isar_feature (aa64_sve,env_archcpu (env)) && arg2 >=0 && arg2 <=512 *16 && !(arg2 &15 )) { -ARMCPU *cpu =env_archcpu (env);uint32_t vq, old_vq; - old_vq = (env->vfp.zcr_el[1 ] &0xf ) +1 ; - vq =MAX (arg2 /16 ,1 ); - vq =MIN (vq, cpu->sve_max_vq); + old_vq =sve_vq (env); +/* +* Bound the value of arg2, so that we know that it fits into +* the 4-bit field in ZCR_EL1. Rely on the hflags rebuild to +* sort out the length supported by the cpu. +*/ + vq =MAX (arg2 /16 ,1 ); + vq =MIN (vq,ARM_MAX_VQ ); + env->vfp.zcr_el[1 ] = vq -1 ; +arm_rebuild_hflags (env); + + vq =sve_vq (env);if (vq < old_vq) {aarch64_sve_narrow_vq (env, vq); } - env->vfp.zcr_el[1 ] = vq -1 ; -arm_rebuild_hflags (env);return vq *16 ; }return -TARGET_EINVAL ;
target/arm/cpu.h +11 -0
@@ -3286,6 +3286,17 @@ static inline int cpu_mmu_index(CPUARMState *env, bool ifetch)return EX_TBFLAG_ANY (env->hflags,MMUIDX ); } +/** +* sve_vq +* @env: the cpu context +* +* Return the VL cached within env->hflags, in units of quadwords. +*/ +static inline int sve_vq (CPUARMState *env) +{ +return EX_TBFLAG_A64 (env->hflags,VL ) +1 ; +} +static inline bool bswap_code (bool sctlr_b) {#ifdef CONFIG_USER_ONLY
linux-user/aarch64/signal.c +2 -2
@@ -315,7 +315,7 @@ static int target_restore_sigframe(CPUARMState *env,case TARGET_SVE_MAGIC :if (cpu_isar_feature (aa64_sve,env_archcpu (env))) { - vq = (env->vfp.zcr_el[1 ] &0xf ) +1 ; + vq =sve_vq (env); sve_size =QEMU_ALIGN_UP (TARGET_SVE_SIG_CONTEXT_SIZE (vq),16 );if (!sve && size == sve_size) { sve = (struct target_sve_context *)ctx;
@@ -434,7 +434,7 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,/* SVE state needs saving only if it exists. */ if (cpu_isar_feature (aa64_sve,env_archcpu (env))) { - vq = (env->vfp.zcr_el[1 ] &0xf ) +1 ; + vq =sve_vq (env); sve_size =QEMU_ALIGN_UP (TARGET_SVE_SIG_CONTEXT_SIZE (vq),16 ); sve_ofs =alloc_sigframe_space (sve_size, &layout); }
Signature · 1 line
2.34.1
PATCH v2 3/71 target/arm: Remove route_to_el2 check from sve_exception_el
In reply to Richard HendersonWe handle this routing in raise_exception. Promoting the value early means that we can't directly compare FPEXC_EL and SVEEXC_EL.
--- target/arm/helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target/arm/helper.c +1 -2
@@ -6159,8 +6159,7 @@ int sve_exception_el(CPUARMState *env, int el)/* fall through */ case 0 :case 2 : -/* route_to_el2 */ -return hcr_el2 &HCR_TGE ?2 :1 ; +return 1 ; }/* Check CPACR.FPEN. */
Signature · 1 line
2.34.1
PATCH v2 4/71 target/arm: Remove fp checks from sve_exception_el
In reply to Richard HendersonInstead of checking these bits in fp_exception_el and also in sve_exception_el, document that we must compare the results. The only place where we have not already checked that FP EL is zero is in rebuild_hflags_a64.
--- target/arm/helper.c | 58 +++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 39 deletions(-)
target/arm/helper.c +19 -39
@@ -6139,11 +6139,15 @@ static const ARMCPRegInfo minimal_ras_reginfo[] = { .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.vsesr_el2) }, }; -/* Return the exception level to which exceptions should be taken -* via SVEAccessTrap. If an exception should be routed through -* AArch64.AdvSIMDFPAccessTrap, return 0; fp_exception_el should -* take care of raising that exception. -* C.f. the ARM pseudocode function CheckSVEEnabled. +/* +* Return the exception level to which exceptions should be taken +* via SVEAccessTrap. This excludes the check for whether the exception +* should be routed through AArch64.AdvSIMDFPAccessTrap. That can easily +* be found by testing 0 < fp_exception_el < sve_exception_el. +* +* C.f. the ARM pseudocode function CheckSVEEnabled. Note that the +* pseudocode does *not* separate out the FP trap checks, but has them +* all in one function. */ int sve_exception_el (CPUARMState *env,int el) {
@@ -6161,18 +6165,6 @@ int sve_exception_el(CPUARMState *env, int el)case 2 :return 1 ; } - -/* Check CPACR.FPEN. */ -switch (FIELD_EX64 (env->cp15.cpacr_el1,CPACR_EL1 ,FPEN )) { -case 1 : -if (el !=0 ) { -break ; - } -/* fall through */ -case 0 : -case 2 : -return 0 ; - } }/*
@@ -6190,24 +6182,10 @@ int sve_exception_el(CPUARMState *env, int el)case 2 :return 2 ; } - -switch (FIELD_EX32 (env->cp15.cptr_el[2 ],CPTR_EL2 ,FPEN )) { -case 1 : -if (el ==2 || !(hcr_el2 &HCR_TGE )) { -break ; - } -/* fall through */ -case 0 : -case 2 : -return 0 ; - } }else if (arm_is_el2_enabled (env)) {if (FIELD_EX64 (env->cp15.cptr_el[2 ],CPTR_EL2 ,TZ )) {return 2 ; } -if (FIELD_EX64 (env->cp15.cptr_el[2 ],CPTR_EL2 ,TFP )) { -return 0 ; - } } }
@@ -13683,19 +13661,21 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el,if (cpu_isar_feature (aa64_sve,env_archcpu (env))) {int sve_el =sve_exception_el (env, el); -uint32_t zcr_len;/* -* If SVE is disabled, but FP is enabled, -* then the effective len is 0. +* If either FP or SVE are disabled, translator does not need len. +* If SVE EL > FP EL, FP exception has precedence, and translator +* does not need SVE EL. Save potential re-translations by forcing +* the unneeded data to zero. */ -if (sve_el !=0 && fp_el ==0 ) { - zcr_len =0 ; - }else { - zcr_len =sve_zcr_len_for_el (env, el); +if (fp_el !=0 ) { +if (sve_el > fp_el) { + sve_el =0 ; + } + }else if (sve_el ==0 ) { +DP_TBFLAG_A64 (flags,VL ,sve_zcr_len_for_el (env, el)); }DP_TBFLAG_A64 (flags,SVEEXC_EL , sve_el); -DP_TBFLAG_A64 (flags,VL , zcr_len); } sctlr =regime_sctlr (env, stage1);
Signature · 1 line
2.34.1
PATCH v2 5/71 target/arm: Add el_is_in_host
In reply to Richard HendersonThis (newish) ARM pseudocode function is easier to work with than open-coded tests for HCR_E2H etc. Use of the function will be staged into the code base in parts.
--- target/arm/internals.h | 2 ++ target/arm/helper.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
target/arm/internals.h +2 -0
@@ -1328,6 +1328,8 @@ static inline void define_cortex_a72_a57_a53_cp_reginfo(ARMCPU *cpu) { }void define_cortex_a72_a57_a53_cp_reginfo (ARMCPU *cpu);#endif +bool el_is_in_host (CPUARMState *env,int el); +void aa32_max_features (ARMCPU *cpu);#endif
target/arm/helper.c +28 -0
@@ -5292,6 +5292,34 @@ uint64_t arm_hcr_el2_eff(CPUARMState *env)return ret; } +/* +* Corresponds to ARM pseudocode function ELIsInHost(). +*/ +bool el_is_in_host (CPUARMState *env,int el) +{ +uint64_t mask; + +/* +* Since we only care about E2H and TGE, we can skip arm_hcr_el2_eff(). +* Perform the simplest bit tests first, and validate EL2 afterward. +*/ +if (el &1 ) { +return false;/* EL1 or EL3 */ + } + +/* +* Note that hcr_write() checks isar_feature_aa64_vh(), +* aka HaveVirtHostExt(), in allowing HCR_E2H to be set. +*/ + mask = el ?HCR_E2H :HCR_E2H |HCR_TGE ; +if ((env->cp15.hcr_el2 & mask) != mask) { +return false; + } + +/* TGE and/or E2H set: double check those bits are currently legal. */ +return arm_is_el2_enabled (env) &&arm_el_is_aa64 (env,2 ); +} +static void hcrx_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) {
Signature · 1 line
2.34.1
PATCH v2 6/71 target/arm: Use el_is_in_host for sve_zcr_len_for_el
In reply to Richard HendersonThe ARM pseudocode function NVL uses this predicate now, and I think it's a bit clearer. Simplify the pseudocode condition by noting that IsInHost is always false for EL1.
--- target/arm/helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target/arm/helper.c +1 -2
@@ -6248,8 +6248,7 @@ uint32_t sve_zcr_len_for_el(CPUARMState *env, int el)ARMCPU *cpu =env_archcpu (env);uint32_t zcr_len = cpu->sve_max_vq -1 ; -if (el <=1 && - (arm_hcr_el2_eff (env) & (HCR_E2H |HCR_TGE )) != (HCR_E2H |HCR_TGE )) { +if (el <=1 && !el_is_in_host (env, el)) { zcr_len =MIN (zcr_len,0xf & (uint32_t )env->vfp.zcr_el[1 ]); }if (el <=2 &&arm_feature (env,ARM_FEATURE_EL2 )) {
Signature · 1 line
2.34.1
PATCH v2 7/71 target/arm: Use el_is_in_host for sve_exception_el
In reply to Richard HendersonThe ARM pseudocode function CheckNormalSVEEnabled uses this predicate now, and I think it's a bit clearer.
--- target/arm/helper.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
target/arm/helper.c +2 -3
@@ -6180,9 +6180,7 @@ static const ARMCPRegInfo minimal_ras_reginfo[] = {int sve_exception_el (CPUARMState *env,int el) {#ifndef CONFIG_USER_ONLY -uint64_t hcr_el2 =arm_hcr_el2_eff (env); - -if (el <=1 && (hcr_el2 & (HCR_E2H |HCR_TGE )) != (HCR_E2H |HCR_TGE )) { +if (el <=1 && !el_is_in_host (env, el)) {switch (FIELD_EX64 (env->cp15.cpacr_el1,CPACR_EL1 ,ZEN )) {case 1 :if (el !=0 ) {
@@ -6199,6 +6197,7 @@ int sve_exception_el(CPUARMState *env, int el)* CPTR_EL2 changes format with HCR_EL2.E2H (regardless of TGE). */ if (el <=2 ) { +uint64_t hcr_el2 =arm_hcr_el2_eff (env);if (hcr_el2 &HCR_E2H ) {switch (FIELD_EX64 (env->cp15.cptr_el[2 ],CPTR_EL2 ,ZEN )) {case 1 :
Signature · 1 line
2.34.1
PATCH v2 8/71 target/arm: Hoist arm_is_el2_enabled check in sve_exception_el
In reply to Richard HendersonThis check is buried within arm_hcr_el2_eff(), but since we have to have the explicit check for CPTR_EL2.TZ, we might as well just check it once at the beginning of the block.
Once this is done, we can test HCR_EL2.{E2H,TGE} directly, rather than going through arm_hcr_el2_eff().
--- target/arm/helper.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
target/arm/helper.c +5 -8
@@ -6193,15 +6193,12 @@ int sve_exception_el(CPUARMState *env, int el) } } -/* -* CPTR_EL2 changes format with HCR_EL2.E2H (regardless of TGE). -*/ -if (el <=2 ) { -uint64_t hcr_el2 =arm_hcr_el2_eff (env); -if (hcr_el2 &HCR_E2H ) { +if (el <=2 &&arm_is_el2_enabled (env)) { +/* CPTR_EL2 changes format with HCR_EL2.E2H (regardless of TGE). */ +if (env->cp15.hcr_el2 &HCR_E2H ) {switch (FIELD_EX64 (env->cp15.cptr_el[2 ],CPTR_EL2 ,ZEN )) {case 1 : -if (el !=0 || !(hcr_el2 &HCR_TGE )) { +if (el !=0 || !(env->cp15.hcr_el2 &HCR_TGE )) {break ; }/* fall through */
@@ -6209,7 +6206,7 @@ int sve_exception_el(CPUARMState *env, int el)case 2 :return 2 ; } - }else if (arm_is_el2_enabled (env)) { + }else {if (FIELD_EX64 (env->cp15.cptr_el[2 ],CPTR_EL2 ,TZ )) {return 2 ; }
Signature · 1 line
2.34.1
PATCH v2 9/71 target/arm: Do not use aarch64_sve_zcr_get_valid_len in reset
In reply to Richard HendersonWe don't need to constrain the value set in zcr_el[1], because it will be done by sve_zcr_len_for_el.
--- target/arm/cpu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target/arm/cpu.c +1 -2
@@ -208,8 +208,7 @@ static void arm_cpu_reset(DeviceState *dev) CPACR_EL1, ZEN, 3);/* with reasonable vector length */ if (cpu_isar_feature (aa64_sve, cpu)) { - env->vfp.zcr_el[1 ] = -aarch64_sve_zcr_get_valid_len (cpu, cpu->sve_default_vq -1 ); + env->vfp.zcr_el[1 ] = cpu->sve_default_vq -1 ; }/* * Enable 48-bit address space (TODO: take reserved_va into account).
Signature · 1 line
2.34.1
PATCH v2 10/71 target/arm: Merge aarch64_sve_zcr_get_valid_len into caller
In reply to Richard HendersonThis function is used only once, and will need modification for Streaming SVE mode.
--- target/arm/internals.h | 11 ----------- target/arm/helper.c | 30 +++++++++++------------------- 2 files changed, 11 insertions(+), 30 deletions(-)
target/arm/internals.h +0 -11
@@ -189,17 +189,6 @@ void arm_translate_init(void);void arm_cpu_synchronize_from_tb (CPUState *cs,const TranslationBlock *tb);#endif /* CONFIG_TCG */ -/** -* aarch64_sve_zcr_get_valid_len: -* @cpu: cpu context -* @start_len: maximum len to consider -* -* Return the maximum supported sve vector length <= @start_len. -* Note that both @start_len and the return value are in units -* of ZCR_ELx.LEN, so the vector bit length is (x + 1) * 128. -*/ -uint32_t aarch64_sve_zcr_get_valid_len (ARMCPU *cpu,uint32_t start_len); -enum arm_fprounding {FPROUNDING_TIEEVEN ,FPROUNDING_POSINF ,
target/arm/helper.c +11 -19
@@ -6222,39 +6222,31 @@ int sve_exception_el(CPUARMState *env, int el)return 0 ; } -uint32_t aarch64_sve_zcr_get_valid_len (ARMCPU *cpu,uint32_t start_len) -{ -uint32_t end_len; - - start_len =MIN (start_len,ARM_MAX_VQ -1 ); - end_len = start_len; - -if (!test_bit (start_len, cpu->sve_vq_map)) { - end_len =find_last_bit (cpu->sve_vq_map, start_len); -assert (end_len < start_len); - } -return end_len; -} -/* * Given that SVE is enabled, return the vector length for EL. */ uint32_t sve_zcr_len_for_el (CPUARMState *env,int el) {ARMCPU *cpu =env_archcpu (env); -uint32_t zcr_len = cpu->sve_max_vq -1 ; +uint32_t len = cpu->sve_max_vq -1 ; +uint32_t end_len;if (el <=1 && !el_is_in_host (env, el)) { - zcr_len =MIN (zcr_len,0xf & (uint32_t )env->vfp.zcr_el[1 ]); + len =MIN (len,0xf & (uint32_t )env->vfp.zcr_el[1 ]); }if (el <=2 &&arm_feature (env,ARM_FEATURE_EL2 )) { - zcr_len =MIN (zcr_len,0xf & (uint32_t )env->vfp.zcr_el[2 ]); + len =MIN (len,0xf & (uint32_t )env->vfp.zcr_el[2 ]); }if (arm_feature (env,ARM_FEATURE_EL3 )) { - zcr_len =MIN (zcr_len,0xf & (uint32_t )env->vfp.zcr_el[3 ]); + len =MIN (len,0xf & (uint32_t )env->vfp.zcr_el[3 ]); } -return aarch64_sve_zcr_get_valid_len (cpu, zcr_len); + end_len = len; +if (!test_bit (len, cpu->sve_vq_map)) { + end_len =find_last_bit (cpu->sve_vq_map, len); +assert (end_len < len); + } +return end_len; } static void zcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
Signature · 1 line
2.34.1
PATCH v2 11/71 target/arm: Use uint32_t instead of bitmap for sve vq's
In reply to Richard HendersonThe bitmap need only hold 15 bits; bitmap is over-complicated. We can simplify operations quite a bit with plain logical ops.
The introduction of SVE_VQ_POW2_MAP eliminates the need for looping in order to search for powers of two. Simply perform the logical ops and use count leading or trailing zeros as required to find the result.
--- target/arm/cpu.h | 6 +-- target/arm/internals.h | 5 ++ target/arm/kvm_arm.h | 7 ++- target/arm/cpu64.c | 117 ++++++++++++++++++++--------------------- target/arm/helper.c | 9 +--- target/arm/kvm64.c | 36 +++---------- 6 files changed, 75 insertions(+), 105 deletions(-)
target/arm/cpu.h +3 -3
@@ -1041,9 +1041,9 @@ struct ArchCPU {* Bits set in sve_vq_supported represent valid vector lengths for * the CPU type. */ -DECLARE_BITMAP (sve_vq_map,ARM_MAX_VQ ); -DECLARE_BITMAP (sve_vq_init,ARM_MAX_VQ ); -DECLARE_BITMAP (sve_vq_supported,ARM_MAX_VQ ); +uint32_t sve_vq_map; +uint32_t sve_vq_init; +uint32_t sve_vq_supported;/* Generic timer counter frequency, in Hz */ uint64_t gt_cntfrq_hz;
target/arm/internals.h +5 -0
@@ -1321,4 +1321,9 @@ bool el_is_in_host(CPUARMState *env, int el);void aa32_max_features (ARMCPU *cpu); +/* Powers of 2 for sve_vq_map et al. */ +#define SVE_VQ_POW2_MAP \ + ((1 << (1 - 1)) | (1 << (2 - 1)) | \ + (1 << (4 - 1)) | (1 << (8 - 1)) | (1 << (16 - 1))) +#endif
target/arm/kvm_arm.h +3 -4
@@ -239,13 +239,12 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf);/** * kvm_arm_sve_get_vls: * @cs: CPUState -* @map: bitmap to fill in * * Get all the SVE vector lengths supported by the KVM host, setting * the bits corresponding to their length in quadwords minus one -* (vq - 1) in @map up to ARM_MAX_VQ. +* (vq - 1) up to ARM_MAX_VQ. Return the resulting map. */ -void kvm_arm_sve_get_vls (CPUState *cs,unsigned long *map); +uint32_t kvm_arm_sve_get_vls (CPUState *cs);/** * kvm_arm_set_cpu_features_from_host:
@@ -439,7 +438,7 @@ static inline void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp)g_assert_not_reached (); } -static inline void kvm_arm_sve_get_vls (CPUState *cs,unsigned long *map) +static inline uint32_t kvm_arm_sve_get_vls (CPUState *cs) {g_assert_not_reached (); }
target/arm/cpu64.c +56 -61
218 lines not on this page · raw message
target/arm/helper.c +2 -7
@@ -6229,7 +6229,6 @@ uint32_t sve_zcr_len_for_el(CPUARMState *env, int el) {ARMCPU *cpu =env_archcpu (env);uint32_t len = cpu->sve_max_vq -1 ; -uint32_t end_len;if (el <=1 && !el_is_in_host (env, el)) { len =MIN (len,0xf & (uint32_t )env->vfp.zcr_el[1 ]);
@@ -6241,12 +6240,8 @@ uint32_t sve_zcr_len_for_el(CPUARMState *env, int el) len =MIN (len,0xf & (uint32_t )env->vfp.zcr_el[3 ]); } - end_len = len; -if (!test_bit (len, cpu->sve_vq_map)) { - end_len =find_last_bit (cpu->sve_vq_map, len); -assert (end_len < len); - } -return end_len; + len =31 -clz32 (cpu->sve_vq_map &MAKE_64BIT_MASK (0 , len +1 )); +return len; } static void zcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
target/arm/kvm64.c +6 -30
@@ -760,15 +760,13 @@ bool kvm_arm_steal_time_supported(void)QEMU_BUILD_BUG_ON (KVM_ARM64_SVE_VQ_MIN !=1 ); -void kvm_arm_sve_get_vls (CPUState *cs,unsigned long *map) +uint32_t kvm_arm_sve_get_vls (CPUState *cs) {/* Only call this function if kvm_arm_sve_supported() returns true. */ static uint64_t vls[KVM_ARM64_SVE_VLS_WORDS ];static bool probed;uint32_t vq =0 ; -int i, j; - -bitmap_zero (map,ARM_MAX_VQ ); +int i;/* * KVM ensures all host CPUs support the same set of vector lengths.
@@ -809,46 +807,24 @@ void kvm_arm_sve_get_vls(CPUState *cs, unsigned long *map)if (vq >ARM_MAX_VQ ) {warn_report ("KVM supports vector lengths larger than " "QEMU can enable" ); + vls[0 ] &=MAKE_64BIT_MASK (0 ,ARM_MAX_VQ ); } } -for (i =0 ; i <KVM_ARM64_SVE_VLS_WORDS ; ++i) { -if (!vls[i]) { -continue ; - } -for (j =1 ; j <=64 ; ++j) { - vq = j + i *64 ; -if (vq >ARM_MAX_VQ ) { -return ; - } -if (vls[i] & (1UL << (j -1 ))) { -set_bit (vq -1 , map); - } - } - } +return vls[0 ]; }static int kvm_arm_sve_set_vls (CPUState *cs) { -uint64_t vls[KVM_ARM64_SVE_VLS_WORDS ] = {0 }; +ARMCPU *cpu =ARM_CPU (cs); +uint64_t vls[KVM_ARM64_SVE_VLS_WORDS ] = { cpu->sve_vq_map };struct kvm_one_reg reg = { .id =KVM_REG_ARM64_SVE_VLS , .addr = (uint64_t )&vls[0 ], }; -ARMCPU *cpu =ARM_CPU (cs); -uint32_t vq; -int i, j;assert (cpu->sve_max_vq <=KVM_ARM64_SVE_VQ_MAX ); -for (vq =1 ; vq <= cpu->sve_max_vq; ++vq) { -if (test_bit (vq -1 , cpu->sve_vq_map)) { - i = (vq -1 ) /64 ; - j = (vq -1 ) %64 ; - vls[i] |=1UL << j; - } - } -return kvm_vcpu_ioctl (cs,KVM_SET_ONE_REG , ®); }
Signature · 1 line
2.34.1
PATCH v2 12/71 target/arm: Rename sve_zcr_len_for_el to sve_vqm1_for_el
In reply to Richard HendersonThis will be used for both Normal and Streaming SVE, and the value does not necessarily come from ZCR_ELx. While we're at it, emphasize the units in which the value is returned.
Patch produced by
git grep -l sve_zcr_len_for_el | \
xargs -n1 sed -i 's/sve_zcr_len_for_el/sve_vqm1_for_el/g'and then adding a function comment.
--- target/arm/cpu.h | 11 ++++++++++- target/arm/arch_dump.c | 2 +- target/arm/cpu.c | 2 +- target/arm/gdbstub64.c | 2 +- target/arm/helper.c | 12 ++++++------ 5 files changed, 19 insertions(+), 10 deletions(-)
target/arm/cpu.h +10 -1
@@ -1132,7 +1132,16 @@ void aarch64_sync_64_to_32(CPUARMState *env);int fp_exception_el (CPUARMState *env,int cur_el);int sve_exception_el (CPUARMState *env,int cur_el); -uint32_t sve_zcr_len_for_el (CPUARMState *env,int el); + +/** +* sve_vqm1_for_el: +* @env: CPUARMState +* @el: exception level +* +* Compute the current SVE vector length for @el, in units of +* Quadwords Minus 1 -- the same scale used for ZCR_ELx.LEN. +*/ +uint32_t sve_vqm1_for_el (CPUARMState *env,int el);static inline bool is_a64 (CPUARMState *env) {
target/arm/arch_dump.c +1 -1
@@ -166,7 +166,7 @@ static off_t sve_fpcr_offset(uint32_t vq)static uint32_t sve_current_vq (CPUARMState *env) { -return sve_zcr_len_for_el (env,arm_current_el (env)) +1 ; +return sve_vqm1_for_el (env,arm_current_el (env)) +1 ; }static size_t sve_size_vq (uint32_t vq)
target/arm/cpu.c +1 -1
@@ -925,7 +925,7 @@ static void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags) vfp_get_fpcr(env), vfp_get_fpsr(env));if (cpu_isar_feature (aa64_sve, cpu) &&sve_exception_el (env, el) ==0 ) { -int j, zcr_len =sve_zcr_len_for_el (env, el); +int j, zcr_len =sve_vqm1_for_el (env, el);for (i =0 ; i <=FFR_PRED_NUM ; i++) {bool eol;
target/arm/gdbstub64.c +1 -1
@@ -152,7 +152,7 @@ int arm_gdb_get_svereg(CPUARMState *env, GByteArray *buf, int reg)* We report in Vector Granules (VG) which is 64bit in a Z reg * while the ZCR works in Vector Quads (VQ) which is 128bit chunks. */ -int vq =sve_zcr_len_for_el (env,arm_current_el (env)) +1 ; +int vq =sve_vqm1_for_el (env,arm_current_el (env)) +1 ;return gdb_get_reg64 (buf, vq *2 ); }default :
target/arm/helper.c +6 -6
@@ -6225,7 +6225,7 @@ int sve_exception_el(CPUARMState *env, int el)/* * Given that SVE is enabled, return the vector length for EL. */ -uint32_t sve_zcr_len_for_el (CPUARMState *env,int el) +uint32_t sve_vqm1_for_el (CPUARMState *env,int el) {ARMCPU *cpu =env_archcpu (env);uint32_t len = cpu->sve_max_vq -1 ;
@@ -6248,7 +6248,7 @@ static void zcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) {int cur_el =arm_current_el (env); -int old_len =sve_zcr_len_for_el (env, cur_el); +int old_len =sve_vqm1_for_el (env, cur_el);int new_len;/* Bits other than [3:0] are RAZ/WI. */
@@ -6259,7 +6259,7 @@ static void zcr_write(CPUARMState *env, const ARMCPRegInfo *ri,* Because we arrived here, we know both FP and SVE are enabled; * otherwise we would have trapped access to the ZCR_ELn register. */ - new_len =sve_zcr_len_for_el (env, cur_el); + new_len =sve_vqm1_for_el (env, cur_el);if (new_len < old_len) {aarch64_sve_narrow_vq (env, new_len +1 ); }
@@ -13683,7 +13683,7 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, sve_el =0 ; } }else if (sve_el ==0 ) { -DP_TBFLAG_A64 (flags,VL ,sve_zcr_len_for_el (env, el)); +DP_TBFLAG_A64 (flags,VL ,sve_vqm1_for_el (env, el)); }DP_TBFLAG_A64 (flags,SVEEXC_EL , sve_el); }
@@ -14049,10 +14049,10 @@ void aarch64_sve_change_el(CPUARMState *env, int old_el,*/ old_a64 = old_el ?arm_el_is_aa64 (env, old_el) : el0_a64; old_len = (old_a64 && !sve_exception_el (env, old_el) - ?sve_zcr_len_for_el (env, old_el) :0 ); + ?sve_vqm1_for_el (env, old_el) :0 ); new_a64 = new_el ?arm_el_is_aa64 (env, new_el) : el0_a64; new_len = (new_a64 && !sve_exception_el (env, new_el) - ?sve_zcr_len_for_el (env, new_el) :0 ); + ?sve_vqm1_for_el (env, new_el) :0 );/* When changing vector length, clear inaccessible state. */ if (new_len < old_len) {
Signature · 1 line
2.34.1
PATCH v2 13/71 target/arm: Split out load/store primitives to sve_ldst_internal.h
In reply to Richard HendersonBegin creation of sve_ldst_internal.h by moving the primitives that access host and tlb memory.
--- target/arm/sve_ldst_internal.h | 127 +++++++++++++++++++++++++++++++++ target/arm/sve_helper.c | 107 +-------------------------- 2 files changed, 128 insertions(+), 106 deletions(-) create mode 100644 target/arm/sve_ldst_internal.h
target/arm/sve_ldst_internal.h new file +127 -0
@@ -0,0 +1,127 @@ +/* +* ARM SVE Load/Store Helpers +* +* Copyright (c) 2018-2022 Linaro +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef TARGET_ARM_SVE_LDST_INTERNAL_H +#define TARGET_ARM_SVE_LDST_INTERNAL_H + +#include "exec/cpu_ldst.h" + +/* +* Load one element into @vd + @reg_off from @host. +* The controlling predicate is known to be true. +*/ +typedef void sve_ldst1_host_fn (void *vd,intptr_t reg_off,void *host); + +/* +* Load one element into @vd + @reg_off from (@env, @vaddr, @ra). +* The controlling predicate is known to be true. +*/ +typedef void sve_ldst1_tlb_fn (CPUARMState *env,void *vd,intptr_t reg_off, +target_ulong vaddr,uintptr_t retaddr); + +/* +* Generate the above primitives. +*/ + +#define DO_LD_HOST (NAME ,H ,TYPEE ,TYPEM ,HOST ) \ +static inline void sve_##NAME##_host(void *vd, intptr_t reg_off, void *host) \ +{ TYPEM val = HOST(host); *(TYPEE *)(vd + H(reg_off)) = val; } + +#define DO_ST_HOST (NAME ,H ,TYPEE ,TYPEM ,HOST ) \ +static inline void sve_##NAME##_host(void *vd, intptr_t reg_off, void *host) \ +{ TYPEM val = *(TYPEE *)(vd + H(reg_off)); HOST(host, val); } + +#define DO_LD_TLB (NAME ,H ,TYPEE ,TYPEM ,TLB ) \ +static inline void sve_##NAME##_tlb(CPUARMState *env, void *vd, \ + intptr_t reg_off, target_ulong addr, uintptr_t ra) \ +{ \ + TYPEM val = TLB(env, useronly_clean_ptr(addr), ra); \ + *(TYPEE *)(vd + H(reg_off)) = val; \ +} + +#define DO_ST_TLB (NAME ,H ,TYPEE ,TYPEM ,TLB ) \ +static inline void sve_##NAME##_tlb(CPUARMState *env, void *vd, \ + intptr_t reg_off, target_ulong addr, uintptr_t ra) \ +{ \ + TYPEM val = *(TYPEE *)(vd + H(reg_off)); \ + TLB(env, useronly_clean_ptr(addr), val, ra); \ +} + +#define DO_LD_PRIM_1 (NAME ,H ,TE ,TM ) \ + DO_LD_HOST(NAME, H, TE, TM, ldub_p) \ + DO_LD_TLB(NAME, H, TE, TM, cpu_ldub_data_ra) + +DO_LD_PRIM_1(ld1bb, H1, uint8_t, uint8_t) +DO_LD_PRIM_1(ld1bhu, H1_2, uint16_t, uint8_t) +DO_LD_PRIM_1(ld1bhs, H1_2, uint16_t, int8_t) +DO_LD_PRIM_1(ld1bsu, H1_4, uint32_t, uint8_t) +DO_LD_PRIM_1(ld1bss, H1_4, uint32_t, int8_t) +DO_LD_PRIM_1(ld1bdu, H1_8, uint64_t, uint8_t) +DO_LD_PRIM_1(ld1bds, H1_8, uint64_t, int8_t) + +#define DO_ST_PRIM_1 (NAME ,H ,TE ,TM ) \ + DO_ST_HOST(st1##NAME, H, TE, TM, stb_p) \ + DO_ST_TLB(st1##NAME, H, TE, TM, cpu_stb_data_ra) + +DO_ST_PRIM_1(bb, H1, uint8_t, uint8_t) +DO_ST_PRIM_1(bh, H1_2, uint16_t, uint8_t) +DO_ST_PRIM_1(bs, H1_4, uint32_t, uint8_t) +DO_ST_PRIM_1(bd, H1_8, uint64_t, uint8_t) + +#define DO_LD_PRIM_2 (NAME ,H ,TE ,TM ,LD ) \ + DO_LD_HOST(ld1##NAME##_be, H, TE, TM, LD##_be_p) \ + DO_LD_HOST(ld1##NAME##_le, H, TE, TM, LD##_le_p) \ + DO_LD_TLB(ld1##NAME##_be, H, TE, TM, cpu_##LD##_be_data_ra) \ + DO_LD_TLB(ld1##NAME##_le, H, TE, TM, cpu_##LD##_le_data_ra) + +#define DO_ST_PRIM_2 (NAME ,H ,TE ,TM ,ST ) \ + DO_ST_HOST(st1##NAME##_be, H, TE, TM, ST##_be_p) \ + DO_ST_HOST(st1##NAME##_le, H, TE, TM, ST##_le_p) \ + DO_ST_TLB(st1##NAME##_be, H, TE, TM, cpu_##ST##_be_data_ra) \ + DO_ST_TLB(st1##NAME##_le, H, TE, TM, cpu_##ST##_le_data_ra) + +DO_LD_PRIM_2(hh, H1_2, uint16_t, uint16_t, lduw) +DO_LD_PRIM_2(hsu, H1_4, uint32_t, uint16_t, lduw) +DO_LD_PRIM_2(hss, H1_4, uint32_t, int16_t, lduw) +DO_LD_PRIM_2(hdu, H1_8, uint64_t, uint16_t, lduw) +DO_LD_PRIM_2(hds, H1_8, uint64_t, int16_t, lduw) + +DO_ST_PRIM_2(hh, H1_2, uint16_t, uint16_t, stw) +DO_ST_PRIM_2(hs, H1_4, uint32_t, uint16_t, stw) +DO_ST_PRIM_2(hd, H1_8, uint64_t, uint16_t, stw) + +DO_LD_PRIM_2(ss, H1_4, uint32_t, uint32_t, ldl) +DO_LD_PRIM_2(sdu, H1_8, uint64_t, uint32_t, ldl) +DO_LD_PRIM_2(sds, H1_8, uint64_t, int32_t, ldl) + +DO_ST_PRIM_2(ss, H1_4, uint32_t, uint32_t, stl) +DO_ST_PRIM_2(sd, H1_8, uint64_t, uint32_t, stl) + +DO_LD_PRIM_2(dd, H1_8, uint64_t, uint64_t, ldq) +DO_ST_PRIM_2(dd, H1_8, uint64_t, uint64_t, stq) + +#undef DO_LD_TLB +#undef DO_ST_TLB +#undef DO_LD_HOST +#undef DO_LD_PRIM_1 +#undef DO_ST_PRIM_1 +#undef DO_LD_PRIM_2 +#undef DO_ST_PRIM_2 + +#endif /* TARGET_ARM_SVE_LDST_INTERNAL_H */
target/arm/sve_helper.c +1 -106
124 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 14/71 target/arm: Export sve contiguous ldst support functions
In reply to Richard HendersonExport all of the support functions for performing bulk fault analysis on a set of elements at contiguous addresses controlled by a predicate.
--- target/arm/sve_ldst_internal.h | 94 ++++++++++++++++++++++++++++++++++ target/arm/sve_helper.c | 87 ++++++------------------------- 2 files changed, 111 insertions(+), 70 deletions(-)
target/arm/sve_ldst_internal.h +94 -0
@@ -124,4 +124,98 @@ DO_ST_PRIM_2(dd, H1_8, uint64_t, uint64_t, stq)#undef DO_LD_PRIM_2#undef DO_ST_PRIM_2 +/* +* Resolve the guest virtual address to info->host and info->flags. +* If @nofault, return false if the page is invalid, otherwise +* exit via page fault exception. +*/ + +typedef struct { +void *host; +int flags; +MemTxAttrs attrs; +}SVEHostPage ; + +bool sve_probe_page (SVEHostPage *info,bool nofault,CPUARMState *env, +target_ulong addr,int mem_off,MMUAccessType access_type, +int mmu_idx,uintptr_t retaddr); + +/* +* Analyse contiguous data, protected by a governing predicate. +*/ + +typedef enum { +FAULT_NO , +FAULT_FIRST , +FAULT_ALL , +}SVEContFault ; + +typedef struct { +/* +* First and last element wholly contained within the two pages. +* mem_off_first[0] and reg_off_first[0] are always set >= 0. +* reg_off_last[0] may be < 0 if the first element crosses pages. +* All of mem_off_first[1], reg_off_first[1] and reg_off_last[1] +* are set >= 0 only if there are complete elements on a second page. +* +* The reg_off_* offsets are relative to the internal vector register. +* The mem_off_first offset is relative to the memory address; the +* two offsets are different when a load operation extends, a store +* operation truncates, or for multi-register operations. +*/ +int16_t mem_off_first[2 ]; +int16_t reg_off_first[2 ]; +int16_t reg_off_last[2 ]; + +/* +* One element that is misaligned and spans both pages, +* or -1 if there is no such active element. +*/ +int16_t mem_off_split; +int16_t reg_off_split; + +/* +* The byte offset at which the entire operation crosses a page boundary. +* Set >= 0 if and only if the entire operation spans two pages. +*/ +int16_t page_split; + +/* TLB data for the two pages. */ +SVEHostPage page[2 ]; +}SVEContLdSt ; + +/* +* Find first active element on each page, and a loose bound for the +* final element on each page. Identify any single element that spans +* the page boundary. Return true if there are any active elements. +*/ +bool sve_cont_ldst_elements (SVEContLdSt *info,target_ulong addr,uint64_t *vg, +intptr_t reg_max,int esz,int msize); + +/* +* Resolve the guest virtual addresses to info->page[]. +* Control the generation of page faults with @fault. Return false if +* there is no work to do, which can only happen with @fault == FAULT_NO. +*/ +bool sve_cont_ldst_pages (SVEContLdSt *info,SVEContFault fault, +CPUARMState *env,target_ulong addr, +MMUAccessType access_type,uintptr_t retaddr); + +#ifdef CONFIG_USER_ONLY +static inline void +sve_cont_ldst_watchpoints (SVEContLdSt *info,CPUARMState *env,uint64_t *vg, +target_ulong addr,int esize,int msize, +int wp_access,uintptr_t retaddr) +{ } +#else +void sve_cont_ldst_watchpoints (SVEContLdSt *info,CPUARMState *env, +uint64_t *vg,target_ulong addr, +int esize,int msize,int wp_access, +uintptr_t retaddr); +#endif + +void sve_cont_ldst_mte_check (SVEContLdSt *info,CPUARMState *env,uint64_t *vg, +target_ulong addr,int esize,int msize, +uint32_t mtedesc,uintptr_t ra); +#endif /* TARGET_ARM_SVE_LDST_INTERNAL_H */
target/arm/sve_helper.c +17 -70
125 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 15/71 target/arm: Move expand_pred_b to vec_internal.h
In reply to Richard HendersonPut the inline function near the array declaration.
--- target/arm/vec_internal.h | 8 +++++++- target/arm/sve_helper.c | 9 --------- 2 files changed, 7 insertions(+), 10 deletions(-)
target/arm/vec_internal.h +7 -1
@@ -50,8 +50,14 @@#define H8 (x) (x)#define H1_8 (x) (x) -/* Data for expanding active predicate bits to bytes, for byte elements. */ +/* +* Expand active predicate bits to bytes, for byte elements. +*/ extern const uint64_t expand_pred_b_data[256 ]; +static inline uint64_t expand_pred_b (uint8_t byte) +{ +return expand_pred_b_data[byte]; +}static inline void clear_tail (void *vd,uintptr_t opr_sz,uintptr_t max_sz) {
target/arm/sve_helper.c +0 -9
@@ -103,15 +103,6 @@ uint32_t HELPER(sve_predtest)(void *vd, void *vg, uint32_t words)return flags; } -/* -* Expand active predicate bits to bytes, for byte elements. -* (The data table itself is in vec_helper.c as MVE also needs it.) -*/ -static inline uint64_t expand_pred_b (uint8_t byte) -{ -return expand_pred_b_data[byte]; -} -/* Similarly for half-word elements. * for (i = 0; i < 256; ++i) { * unsigned long m = 0;
Signature · 1 line
2.34.1
PATCH v2 16/71 target/arm: Use expand_pred_b in mve_helper.c
In reply to Richard HendersonUse the function instead of the array directly.
Because the function performs its own masking, via the uint8_t parameter, we need to do nothing extra within the users: the bits above the first 2 (_uh) or 4 (_uw) will be discarded by assignment to the local bmask variables, and of course _uq uses the entire uint64_t result.
--- target/arm/mve_helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target/arm/mve_helper.c +3 -3
@@ -726,7 +726,7 @@ static void mergemask_sb(int8_t *d, int8_t r, uint16_t mask)static void mergemask_uh (uint16_t *d,uint16_t r,uint16_t mask) { -uint16_t bmask = expand_pred_b_data[mask &3 ]; +uint16_t bmask =expand_pred_b (mask); *d = (*d & ~bmask) | (r & bmask); }
@@ -737,7 +737,7 @@ static void mergemask_sh(int16_t *d, int16_t r, uint16_t mask)static void mergemask_uw (uint32_t *d,uint32_t r,uint16_t mask) { -uint32_t bmask = expand_pred_b_data[mask &0xf ]; +uint32_t bmask =expand_pred_b (mask); *d = (*d & ~bmask) | (r & bmask); }
@@ -748,7 +748,7 @@ static void mergemask_sw(int32_t *d, int32_t r, uint16_t mask)static void mergemask_uq (uint64_t *d,uint64_t r,uint16_t mask) { -uint64_t bmask = expand_pred_b_data[mask &0xff ]; +uint64_t bmask =expand_pred_b (mask); *d = (*d & ~bmask) | (r & bmask); }
Signature · 1 line
2.34.1
PATCH v2 17/71 target/arm: Move expand_pred_h to vec_internal.h
In reply to Richard HendersonMove the data to vec_helper.c and the inline to vec_internal.h.
--- target/arm/vec_internal.h | 7 +++++++ target/arm/sve_helper.c | 29 ----------------------------- target/arm/vec_helper.c | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 29 deletions(-)
target/arm/vec_internal.h +7 -0
@@ -59,6 +59,13 @@ static inline uint64_t expand_pred_b(uint8_t byte)return expand_pred_b_data[byte]; } +/* Similarly for half-word elements. */ +extern const uint64_t expand_pred_h_data[0x55 +1 ]; +static inline uint64_t expand_pred_h (uint8_t byte) +{ +return expand_pred_h_data[byte &0x55 ]; +} +static inline void clear_tail (void *vd,uintptr_t opr_sz,uintptr_t max_sz) {uint64_t *d = vd + opr_sz;
target/arm/sve_helper.c +0 -29
@@ -103,35 +103,6 @@ uint32_t HELPER(sve_predtest)(void *vd, void *vg, uint32_t words)return flags; } -/* Similarly for half-word elements. -* for (i = 0; i < 256; ++i) { -* unsigned long m = 0; -* if (i & 0xaa) { -* continue; -* } -* for (j = 0; j < 8; j += 2) { -* if ((i >> j) & 1) { -* m |= 0xfffful << (j << 3); -* } -* } -* printf("[0x%x] = 0x%016lx,\n", i, m); -* } -*/ -static inline uint64_t expand_pred_h (uint8_t byte) -{ -static const uint64_t word[] = { - [0x01 ] =0x000000000000ffff , [0x04 ] =0x00000000ffff0000 , - [0x05 ] =0x00000000ffffffff , [0x10 ] =0x0000ffff00000000 , - [0x11 ] =0x0000ffff0000ffff , [0x14 ] =0x0000ffffffff0000 , - [0x15 ] =0x0000ffffffffffff , [0x40 ] =0xffff000000000000 , - [0x41 ] =0xffff00000000ffff , [0x44 ] =0xffff0000ffff0000 , - [0x45 ] =0xffff0000ffffffff , [0x50 ] =0xffffffff00000000 , - [0x51 ] =0xffffffff0000ffff , [0x54 ] =0xffffffffffff0000 , - [0x55 ] =0xffffffffffffffff , - }; -return word[byte &0x55 ]; -} -/* Similarly for single word elements. */ static inline uint64_t expand_pred_s (uint8_t byte) {
target/arm/vec_helper.c +26 -0
@@ -127,6 +127,32 @@ const uint64_t expand_pred_b_data[256] = { 0xffffffffffffffff, }; +/* +* Similarly for half-word elements. +* for (i = 0; i < 256; ++i) { +* unsigned long m = 0; +* if (i & 0xaa) { +* continue; +* } +* for (j = 0; j < 8; j += 2) { +* if ((i >> j) & 1) { +* m |= 0xfffful << (j << 3); +* } +* } +* printf("[0x%x] = 0x%016lx,\n", i, m); +* } +*/ +const uint64_t expand_pred_h_data[0x55 +1 ] = { + [0x01 ] =0x000000000000ffff , [0x04 ] =0x00000000ffff0000 , + [0x05 ] =0x00000000ffffffff , [0x10 ] =0x0000ffff00000000 , + [0x11 ] =0x0000ffff0000ffff , [0x14 ] =0x0000ffffffff0000 , + [0x15 ] =0x0000ffffffffffff , [0x40 ] =0xffff000000000000 , + [0x41 ] =0xffff00000000ffff , [0x44 ] =0xffff0000ffff0000 , + [0x45 ] =0xffff0000ffffffff , [0x50 ] =0xffffffff00000000 , + [0x51 ] =0xffffffff0000ffff , [0x54 ] =0xffffffffffff0000 , + [0x55 ] =0xffffffffffffffff , +}; +/* Signed saturating rounding doubling multiply-accumulate high half, 8-bit */ int8_t do_sqrdmlah_b (int8_t src1,int8_t src2,int8_t src3,bool neg,bool round)
Signature · 1 line
2.34.1
PATCH v2 18/71 target/arm: Export bfdotadd from vec_helper.c
In reply to Richard HendersonWe will need this over in sme_helper.c.
--- target/arm/vec_internal.h | 13 +++++++++++++ target/arm/vec_helper.c | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-)
target/arm/vec_internal.h +13 -0
@@ -230,4 +230,17 @@ uint64_t pmull_h(uint64_t op1, uint64_t op2);*/ uint64_t pmull_w (uint64_t op1,uint64_t op2); +/** +* bfdotadd: +* @sum: addend +* @e1, @e2: multiplicand vectors +* +* 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. +*/ +float32 bfdotadd (float32 sum,uint32_t e1,uint32_t e2); +#endif /* TARGET_ARM_VEC_INTERNAL_H */
target/arm/vec_helper.c +1 -1
@@ -2557,7 +2557,7 @@ DO_MMLA_B(gvec_usmmla_b, do_usmmla_b)* BFloat16 Dot Product */ -static float32 bfdotadd (float32 sum,uint32_t e1,uint32_t e2) +float32 bfdotadd (float32 sum,uint32_t e1,uint32_t e2) {/* FPCR is ignored for BFDOT and BFMMLA. */ float_status bf_status = {
Signature · 1 line
2.34.1
PATCH v2 19/71 target/arm: Add isar_feature_aa64_sme
In reply to Richard HendersonThis will be used for implementing FEAT_SME.
--- target/arm/cpu.h | 5 +++++ 1 file changed, 5 insertions(+)
target/arm/cpu.h +5 -0
@@ -4043,6 +4043,11 @@ static inline bool isar_feature_aa64_mte(const ARMISARegisters *id)return FIELD_EX64 (id->id_aa64pfr1,ID_AA64PFR1 ,MTE ) >=2 ; } +static inline bool isar_feature_aa64_sme (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64pfr1,ID_AA64PFR1 ,SME ) !=0 ; +} +static inline bool isar_feature_aa64_pmu_8_1 (const ARMISARegisters *id) { return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) >= 4 &&
Signature · 1 line
2.34.1
PATCH v2 20/71 target/arm: Add ID_AA64SMFR0_EL1
In reply to Richard HendersonThis register is allocated from the existing block of id registers, so it is already RES0 for cpus that do not implement SME.
--- target/arm/cpu.h | 25 +++++++++++++++++++++++++ target/arm/helper.c | 4 ++-- target/arm/kvm64.c | 11 +++++++---- 3 files changed, 34 insertions(+), 6 deletions(-)
target/arm/cpu.h +25 -0
@@ -966,6 +966,7 @@ struct ArchCPU {uint64_t id_aa64dfr0;uint64_t id_aa64dfr1;uint64_t id_aa64zfr0; +uint64_t id_aa64smfr0;uint64_t reset_pmcr_el0; } isar;uint64_t midr;
@@ -2190,6 +2191,15 @@ FIELD(ID_AA64ZFR0, I8MM, 44, 4) FIELD(ID_AA64ZFR0, F32MM, 52, 4) FIELD(ID_AA64ZFR0, F64MM, 56, 4) +FIELD(ID_AA64SMFR0, F32F32, 32, 1) +FIELD(ID_AA64SMFR0, B16F32, 34, 1) +FIELD(ID_AA64SMFR0, F16F32, 35, 1) +FIELD(ID_AA64SMFR0, I8I32, 36, 4) +FIELD(ID_AA64SMFR0, F64F64, 48, 1) +FIELD(ID_AA64SMFR0, I16I64, 52, 4) +FIELD(ID_AA64SMFR0, SMEVER, 56, 4) +FIELD(ID_AA64SMFR0, FA64, 63, 1) + FIELD(ID_DFR0, COPDBG, 0, 4) FIELD(ID_DFR0, COPSDBG, 4, 4)FIELD (ID_DFR0 ,MMAPDBG ,8 ,4 )
@@ -4190,6 +4200,21 @@ static inline bool isar_feature_aa64_sve_f64mm(const ARMISARegisters *id)return FIELD_EX64 (id->id_aa64zfr0,ID_AA64ZFR0 ,F64MM ) !=0 ; } +static inline bool isar_feature_aa64_sme_f64f64 (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64smfr0,ID_AA64SMFR0 ,F64F64 ); +} + +static inline bool isar_feature_aa64_sme_i16i64 (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64smfr0,ID_AA64SMFR0 ,I16I64 ) ==0xf ; +} + +static inline bool isar_feature_aa64_sme_fa64 (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64smfr0,ID_AA64SMFR0 ,FA64 ); +} +/* * Feature tests for "does this exist in either 32-bit or 64-bit?" */
target/arm/helper.c +2 -2
@@ -7732,11 +7732,11 @@ void register_cp_regs_for_features(ARMCPU *cpu) .access = PL1_R, .type = ARM_CP_CONST, .accessfn = access_aa64_tid3, .resetvalue = cpu->isar.id_aa64zfr0 }, - { .name = "ID_AA64PFR5_EL1_RESERVED", .state = ARM_CP_STATE_AA64, + { .name = "ID_AA64SMFR0_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 5, .access = PL1_R, .type = ARM_CP_CONST, .accessfn = access_aa64_tid3, - .resetvalue = 0 }, + .resetvalue = cpu->isar.id_aa64smfr0 }, { .name = "ID_AA64PFR6_EL1_RESERVED", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 6, .access = PL1_R, .type = ARM_CP_CONST,
target/arm/kvm64.c +7 -4
@@ -574,6 +574,8 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) }else { err |=read_sys_reg64 (fdarray[2 ], &ahcf->isar.id_aa64pfr1,ARM64_SYS_REG (3 ,0 ,0 ,4 ,1 )); + err |=read_sys_reg64 (fdarray[2 ], &ahcf->isar.id_aa64smfr0, +ARM64_SYS_REG (3 ,0 ,0 ,4 ,5 )); err |=read_sys_reg64 (fdarray[2 ], &ahcf->isar.id_aa64dfr0,ARM64_SYS_REG (3 ,0 ,0 ,5 ,0 )); err |= read_sys_reg64(fdarray[2], &ahcf->isar.id_aa64dfr1,
@@ -682,10 +684,11 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) ahcf->isar.id_aa64pfr0 = t;/* -* Before v5.1, KVM did not support SVE and did not expose -* ID_AA64ZFR0_EL1 even as RAZ. After v5.1, KVM still does -* not expose the register to "user" requests like this -* unless the host supports SVE. +* There is a range of kernels between kernel commit 73433762fcae +* and f81cb2c3ad41 which have a bug where the kernel doesn't expose +* SYS_ID_AA64ZFR0_EL1 via the ONE_REG API unless the VM has enabled +* SVE support, so we only read it here, rather than together with all +* the other ID registers earlier. */ err |=read_sys_reg64 (fdarray[2 ], &ahcf->isar.id_aa64zfr0,ARM64_SYS_REG (3 ,0 ,0 ,4 ,4 ));
Signature · 1 line
2.34.1
PATCH v2 21/71 target/arm: Implement TPIDR2_EL0
In reply to Richard HendersonThis register is part of SME, but isn't closely related to the rest of the extension.
--- target/arm/cpu.h | 1 + target/arm/helper.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
target/arm/cpu.h +1 -0
@@ -474,6 +474,7 @@ typedef struct CPUArchState { };uint64_t tpidr_el[4 ]; }; +uint64_t tpidr2_el0;/* The secure banks of these registers don't map anywhere */ uint64_t tpidrurw_s;uint64_t tpidrprw_s;
target/arm/helper.c +32 -0
@@ -6283,6 +6283,35 @@ static const ARMCPRegInfo zcr_reginfo[] = { .writefn = zcr_write, .raw_writefn = raw_write }, }; +#ifdef TARGET_AARCH64 +static CPAccessResult access_tpidr2 (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +int el =arm_current_el (env); + +if (el ==0 ) { +uint64_t sctlr =arm_sctlr (env, el); +if (!(sctlr & SCTLR_EnTP2)) { +return CP_ACCESS_TRAP ; + } + } +/* TODO: FEAT_FGT */ +if (el <3 + &&arm_feature (env,ARM_FEATURE_EL3 ) + && !(env->cp15.scr_el3 &SCR_ENTP2 )) { +return CP_ACCESS_TRAP_EL3 ; + } +return CP_ACCESS_OK ; +} + +static const ARMCPRegInfo sme_reginfo[] = { + { .name ="TPIDR2_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =13 , .crm =0 , .opc2 =5 , + .access =PL0_RW , .accessfn = access_tpidr2, + .fieldoffset = offsetof(CPUARMState, cp15.tpidr2_el0) }, +}; +#endif /* TARGET_AARCH64 */ +void hw_watchpoint_update (ARMCPU *cpu,int n) {CPUARMState *env = &cpu->env;
@@ -8444,6 +8473,9 @@ void register_cp_regs_for_features(ARMCPU *cpu) }#ifdef TARGET_AARCH64 +if (cpu_isar_feature (aa64_sme, cpu)) { +define_arm_cp_regs (cpu, sme_reginfo); + }if (cpu_isar_feature (aa64_pauth, cpu)) {define_arm_cp_regs (cpu, pauth_reginfo); }
Signature · 1 line
2.34.1
Re: [PATCH v2 21/71] target/arm: Implement TPIDR2_EL0
Quoted 10 lines · Richard Henderson
This register is part of SME, but isn't closely related to the rest of the extension.
Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu.h | 1 + target/arm/helper.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
thanks
-- PMM
PATCH v2 22/71 target/arm: Add SMEEXC_EL to TB flags
In reply to Richard HendersonThis is CheckSMEAccess, which is the basis for a set of related tests for various SME cpregs and instructions.
--- target/arm/cpu.h | 2 ++ target/arm/translate.h | 1 + target/arm/helper.c | 52 ++++++++++++++++++++++++++++++++++++++ target/arm/translate-a64.c | 1 + 4 files changed, 56 insertions(+)
target/arm/cpu.h +2 -0
@@ -1134,6 +1134,7 @@ void aarch64_sync_64_to_32(CPUARMState *env);int fp_exception_el (CPUARMState *env,int cur_el);int sve_exception_el (CPUARMState *env,int cur_el); +int sme_exception_el (CPUARMState *env,int cur_el);/** * sve_vqm1_for_el:
@@ -3272,6 +3273,7 @@ FIELD(TBFLAG_A64, ATA, 15, 1) FIELD(TBFLAG_A64, TCMA, 16, 2) FIELD(TBFLAG_A64, MTE_ACTIVE, 18, 1) FIELD(TBFLAG_A64, MTE0_ACTIVE, 19, 1) +FIELD (TBFLAG_A64 ,SMEEXC_EL ,20 ,2 )/* * Helpers for using the above.
target/arm/translate.h +1 -0
@@ -42,6 +42,7 @@ typedef struct DisasContext {bool ns;/* Use non-secure CPREG bank on access */ int fp_excp_el;/* FP exception EL or 0 if enabled */ int sve_excp_el;/* SVE exception EL or 0 if enabled */ +int sme_excp_el;/* SME exception EL or 0 if enabled */ int vl;/* current vector length in bytes */ /* Flag indicating that exceptions from secure mode are routed to EL3. */ bool secure_routed_to_el3;
target/arm/helper.c +52 -0
64 lines not on this page · raw message
target/arm/translate-a64.c +1 -0
@@ -14608,6 +14608,7 @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, dc->align_mem =EX_TBFLAG_ANY (tb_flags,ALIGN_MEM ); dc->pstate_il =EX_TBFLAG_ANY (tb_flags,PSTATE__IL ); dc->sve_excp_el =EX_TBFLAG_A64 (tb_flags,SVEEXC_EL ); + dc->sme_excp_el =EX_TBFLAG_A64 (tb_flags,SMEEXC_EL ); dc->vl = (EX_TBFLAG_A64 (tb_flags,VL ) +1 ) *16 ; dc->pauth_active =EX_TBFLAG_A64 (tb_flags,PAUTH_ACTIVE ); dc->bt =EX_TBFLAG_A64 (tb_flags,BT );
Signature · 1 line
2.34.1
PATCH v2 23/71 target/arm: Add syn_smetrap
In reply to Richard HendersonThis will be used for raising various traps for SME.
--- target/arm/syndrome.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
target/arm/syndrome.h +14 -0
@@ -48,6 +48,7 @@ enum arm_exception_class {EC_AA64_SMC =0x17 ,EC_SYSTEMREGISTERTRAP =0x18 ,EC_SVEACCESSTRAP =0x19 , +EC_SMETRAP =0x1d ,EC_INSNABORT =0x20 ,EC_INSNABORT_SAME_EL =0x21 , EC_PCALIGNMENT = 0x22,
@@ -68,6 +69,13 @@ enum arm_exception_class { EC_AA64_BKPT = 0x3c, }; +typedef enum { + SME_ET_AccessTrap, + SME_ET_Streaming, + SME_ET_NotStreaming, + SME_ET_InactiveZA, +}SMEExceptionType ; +#define ARM_EL_EC_SHIFT 26#define ARM_EL_IL_SHIFT 25#define ARM_EL_ISV_SHIFT 24
@@ -206,6 +214,12 @@ static inline uint32_t syn_sve_access_trap(void)return EC_SVEACCESSTRAP <<ARM_EL_EC_SHIFT ; } +static inline uint32_t syn_smetrap (SMEExceptionType etype,bool is_16bit) +{ +return (EC_SMETRAP <<ARM_EL_EC_SHIFT ) + | (is_16bit ?0 :ARM_EL_IL ) | etype; +} +static inline uint32_t syn_pactrap (void ) {return EC_PACTRAP <<ARM_EL_EC_SHIFT ;
Signature · 1 line
2.34.1
PATCH v2 24/71 target/arm: Add ARM_CP_SME
In reply to Richard HendersonThis will be used for controlling access to SME cpregs.
--- target/arm/cpregs.h | 5 +++++ target/arm/translate-a64.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+)
target/arm/cpregs.h +5 -0
@@ -113,6 +113,11 @@ enum {ARM_CP_EL3_NO_EL2_UNDEF =1 <<16 ,ARM_CP_EL3_NO_EL2_KEEP =1 <<17 ,ARM_CP_EL3_NO_EL2_C_NZ =1 <<18 , +/* +* Flag: Access check for this sysreg is constrained by the +* ARM pseudocode function CheckSMEAccess(). +*/ + ARM_CP_SME = 1 << 19, };/*
target/arm/translate-a64.c +18 -0
@@ -1186,6 +1186,22 @@ bool sve_access_check(DisasContext *s)return fp_access_check (s); } +/* +* Check that SME access is enabled, raise an exception if not. +* Note that this function corresponds to CheckSMEAccess and is +* only used directly for cpregs. +*/ +static bool sme_access_check (DisasContext *s) +{ +if (s->sme_excp_el) { +gen_exception_insn (s, s->pc_curr,EXCP_UDEF , +syn_smetrap (SME_ET_AccessTrap, false), + s->sme_excp_el); +return false; + } +return true; +} +/* * This utility function is for doing register extension with an * optional shift. You will likely want to pass a temporary for the
@@ -1958,6 +1974,8 @@ static void handle_sys(DisasContext *s, uint32_t insn, bool isread,return ; }else if ((ri->type &ARM_CP_SVE ) && !sve_access_check (s)) {return ; + }else if ((ri->type &ARM_CP_SME ) && !sme_access_check (s)) { +return ; }if ((tb_cflags (s->base.tb) &CF_USE_ICOUNT ) && (ri->type &ARM_CP_IO )) {
Signature · 1 line
2.34.1
PATCH v2 25/71 target/arm: Add SVCR
In reply to Richard HendersonThis cpreg is used to access two new bits of PSTATE that are not visible via any other mechanism.
--- target/arm/cpu.h | 6 ++++++ target/arm/helper.c | 13 +++++++++++++ 2 files changed, 19 insertions(+)
target/arm/cpu.h +6 -0
@@ -258,6 +258,7 @@ typedef struct CPUArchState {* nRW (also known as M[4]) is kept, inverted, in env->aarch64 * DAIF (exception masks) are kept in env->daif * BTYPE is kept in env->btype +* SM and ZA are kept in env->svcr * all other bits are stored in their correct places in env->pstate */ uint32_t pstate;
@@ -292,6 +293,7 @@ typedef struct CPUArchState {uint32_t condexec_bits;/* IT bits. cpsr[15:10,26:25]. */ uint32_t btype;/* BTI branch type. spsr[11:10]. */ uint64_t daif;/* exception masks, in the bits they are in PSTATE */ +uint64_t svcr;/* PSTATE.{SM,ZA} in the bits they are in SVCR */ uint64_t elr_el[4 ];/* AArch64 exception link regs */ uint64_t sp_el[4 ];/* AArch64 banked stack pointers */
@@ -1428,6 +1430,10 @@ FIELD(CPTR_EL3, TCPAC, 31, 1)#define PSTATE_MODE_EL1t 4#define PSTATE_MODE_EL0t 0 +/* PSTATE bits that are accessed via SVCR and not stored in SPSR_ELx. */ +FIELD(SVCR, SM, 0, 1) +FIELD (SVCR ,ZA ,1 ,1 ) +/* Write a new value to v7m.exception, thus transitioning into or out * of Handler mode; this may result in a change of active stack pointer. */
target/arm/helper.c +13 -0
@@ -6353,11 +6353,24 @@ static CPAccessResult access_tpidr2(CPUARMState *env, const ARMCPRegInfo *ri,return CP_ACCESS_OK ; } +static void svcr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ + value &=R_SVCR_SM_MASK |R_SVCR_ZA_MASK ; +/* TODO: Side effects. */ + env->svcr = value; +} +static const ARMCPRegInfo sme_reginfo[] = { { .name ="TPIDR2_EL0" , .state =ARM_CP_STATE_AA64 , .opc0 =3 , .opc1 =3 , .crn =13 , .crm =0 , .opc2 =5 , .access =PL0_RW , .accessfn = access_tpidr2, .fieldoffset = offsetof(CPUARMState, cp15.tpidr2_el0) }, + { .name ="SVCR" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =4 , .crm =2 , .opc2 =2 , + .access =PL0_RW , .type =ARM_CP_SME , + .fieldoffset = offsetof(CPUARMState , svcr), + .writefn = svcr_write, .raw_writefn = raw_write }, };#endif /* TARGET_AARCH64 */
Signature · 1 line
2.34.1
Re: [PATCH v2 25/71] target/arm: Add SVCR
Quoted 5 lines · Richard Henderson
This cpreg is used to access two new bits of PSTATE that are not visible via any other mechanism.
Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v2 26/71 target/arm: Add SMCR_ELx
In reply to Richard HendersonThese cpregs control the streaming vector length and whether the full a64 instruction set is allowed while in streaming mode.
--- target/arm/cpu.h | 8 ++++++-- target/arm/helper.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-)
target/arm/cpu.h +6 -2
@@ -669,8 +669,8 @@ typedef struct CPUArchState {float_status standard_fp_status;float_status standard_fp_status_f16; -/* ZCR_EL[1-3] */ -uint64_t zcr_el[4 ]; +uint64_t zcr_el[4 ];/* ZCR_EL[1-3] */ +uint64_t smcr_el[4 ];/* SMCR_EL[1-3] */ } vfp;uint64_t exclusive_addr;uint64_t exclusive_val;
@@ -1434,6 +1434,10 @@ FIELD(CPTR_EL3, TCPAC, 31, 1) FIELD(SVCR, SM, 0, 1)FIELD (SVCR ,ZA ,1 ,1 ) +/* Fields for SMCR_ELx. */ +FIELD(SMCR, LEN, 0, 4) +FIELD (SMCR ,FA64 ,31 ,1 ) +/* Write a new value to v7m.exception, thus transitioning into or out * of Handler mode; this may result in a change of active stack pointer. */
target/arm/helper.c +41 -0
59 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 27/71 target/arm: Add SMIDR_EL1, SMPRI_EL1, SMPRIMAP_EL2
In reply to Richard HendersonImplement the streaming mode identification register, and the two streaming priority registers. For QEMU, they are all RES0.
--- target/arm/helper.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
target/arm/helper.c +33 -0
@@ -6355,6 +6355,18 @@ static CPAccessResult access_tpidr2(CPUARMState *env, const ARMCPRegInfo *ri,return CP_ACCESS_OK ; } +static CPAccessResult access_esm (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +/* TODO: FEAT_FGT for SMPRI_EL1 but not SMPRIMAP_EL2 */ +if (arm_current_el (env) <3 + &&arm_feature (env,ARM_FEATURE_EL3 ) + && !FIELD_EX64 (env->cp15.cptr_el[3 ],CPTR_EL3 ,ESM )) { +return CP_ACCESS_TRAP_EL3 ; + } +return CP_ACCESS_OK ; +} +static void svcr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) {
@@ -6412,6 +6424,27 @@ static const ARMCPRegInfo sme_reginfo[] = { .access = PL3_RW, .type = ARM_CP_SME, .fieldoffset = offsetof(CPUARMState, vfp.smcr_el[3]), .writefn = smcr_write, .raw_writefn = raw_write }, + { .name = "SMIDR_EL1", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 1, .crn = 0, .crm = 0, .opc2 = 6, + .access = PL1_R, .accessfn = access_aa64_tid1, +/* +* IMPLEMENTOR = 0 (software) +* REVISION = 0 (implementation defined) +* SMPS = 0 (no streaming execution priority in QEMU) +* AFFINITY = 0 (streaming sve mode not shared with other PEs) +*/ + .type = ARM_CP_CONST, .resetvalue = 0, }, + /* + * Because SMIDR_EL1.SMPS is 0, SMPRI_EL1 and SMPRIMAP_EL2 are RES 0. + */ + { .name = "SMPRI_EL1", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 0, .crn = 1, .crm = 2, .opc2 = 4, + .access = PL1_RW, .accessfn = access_esm, + .type = ARM_CP_CONST, .resetvalue = 0 }, + { .name = "SMPRIMAP_EL2", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 5, + .access = PL2_RW, .accessfn = access_esm, + .type = ARM_CP_CONST, .resetvalue = 0 }, };#endif /* TARGET_AARCH64 */
Signature · 1 line
2.34.1
PATCH v2 28/71 target/arm: Add PSTATE.{SM,ZA} to TB flags
In reply to Richard HendersonThese are required to determine if various insns
are allowed to issue.
--- target/arm/cpu.h | 2 ++ target/arm/translate.h | 4 ++++ target/arm/helper.c | 4 ++++ target/arm/translate-a64.c | 2 ++ 4 files changed, 12 insertions(+)
target/arm/cpu.h +2 -0
@@ -3284,6 +3284,8 @@ FIELD(TBFLAG_A64, TCMA, 16, 2) FIELD(TBFLAG_A64, MTE_ACTIVE, 18, 1) FIELD(TBFLAG_A64, MTE0_ACTIVE, 19, 1) FIELD(TBFLAG_A64, SMEEXC_EL, 20, 2) +FIELD(TBFLAG_A64, PSTATE_SM, 22, 1) +FIELD (TBFLAG_A64 ,PSTATE_ZA ,23 ,1 )/* * Helpers for using the above.
target/arm/translate.h +4 -0
@@ -101,6 +101,10 @@ typedef struct DisasContext {bool align_mem;/* True if PSTATE.IL is set */ bool pstate_il; +/* True if PSTATE.SM is set. */ +bool pstate_sm; +/* True if PSTATE.ZA is set. */ +bool pstate_za;/* True if MVE insns are definitely not predicated by VPR or LTPSIZE */ bool mve_no_pred;/*
target/arm/helper.c +4 -0
@@ -13857,6 +13857,10 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, }if (cpu_isar_feature (aa64_sme,env_archcpu (env))) {DP_TBFLAG_A64 (flags,SMEEXC_EL ,sme_exception_el (env, el)); +if (FIELD_EX64 (env->svcr,SVCR ,SM )) { +DP_TBFLAG_A64 (flags,PSTATE_SM ,1 ); + } +DP_TBFLAG_A64 (flags,PSTATE_ZA ,FIELD_EX64 (env->svcr,SVCR ,ZA )); } sctlr =regime_sctlr (env, stage1);
target/arm/translate-a64.c +2 -0
@@ -14635,6 +14635,8 @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, dc->ata =EX_TBFLAG_A64 (tb_flags,ATA ); dc->mte_active[0 ] =EX_TBFLAG_A64 (tb_flags,MTE_ACTIVE ); dc->mte_active[1 ] =EX_TBFLAG_A64 (tb_flags,MTE0_ACTIVE ); + dc->pstate_sm =EX_TBFLAG_A64 (tb_flags,PSTATE_SM ); + dc->pstate_za =EX_TBFLAG_A64 (tb_flags,PSTATE_ZA ); dc->vec_len =0 ; dc->vec_stride =0 ; dc->cp_regs = arm_cpu->cp_regs;
Signature · 1 line
2.34.1
PATCH v2 29/71 target/arm: Add the SME ZA storage to CPUARMState
In reply to Richard HendersonPlace this late in the resettable section of the structure, to keep the most common element offsets from being > 64k.
--- target/arm/cpu.h | 8 ++++++++ target/arm/machine.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
target/arm/cpu.h +8 -0
@@ -694,6 +694,14 @@ typedef struct CPUArchState { } keys;uint64_t scxtnum_el[4 ]; + +/* +* SME ZA storage -- 256 x 256 byte array, with bytes in host word order, +* as we do with vfp.zregs[]. Because this is so large, keep this toward +* the end of the reset area, to keep the offsets into the rest of the +* structure smaller. +*/ +ARMVectorReg zarray[ARM_MAX_VQ *16 ];#endif #if defined(CONFIG_USER_ONLY )
target/arm/machine.c +34 -0
@@ -167,6 +167,39 @@ static const VMStateDescription vmstate_sve = {VMSTATE_END_OF_LIST () } }; + +static const VMStateDescription vmstate_vreg = { + .name ="vreg" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64_ARRAY (d, ARMVectorReg,ARM_MAX_VQ *2 ), +VMSTATE_END_OF_LIST () + } +}; + +static bool za_needed (void *opaque) +{ +ARMCPU *cpu = opaque; + +/* +* When ZA storage is disabled, its contents are discarded. +* It will be zeroed when ZA storage is re-enabled. +*/ +return FIELD_EX64 (cpu->env.svcr,SVCR ,ZA ); +} + +static const VMStateDescription vmstate_za = { + .name ="cpu/sme" , + .version_id =1 , + .minimum_version_id =1 , + .needed = za_needed, + .fields = (VMStateField []) { +VMSTATE_STRUCT_ARRAY (env.zarray,ARMCPU ,ARM_MAX_VQ *16 ,0 , + vmstate_vreg, ARMVectorReg), +VMSTATE_END_OF_LIST () + } +};#endif /* AARCH64 */ static bool serror_needed (void *opaque)
@@ -884,6 +917,7 @@ const VMStateDescription vmstate_arm_cpu = { &vmstate_m_security, #ifdef TARGET_AARCH64 &vmstate_sve, + &vmstate_za, #endif &vmstate_serror, &vmstate_irq_line_state,
Signature · 1 line
2.34.1
Re: [PATCH v2 29/71] target/arm: Add the SME ZA storage to CPUARMState
Quoted 5 lines · Richard Henderson
Place this late in the resettable section of the structure, to keep the most common element offsets from being > 64k.
Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v2 30/71 target/arm: Implement SMSTART, SMSTOP
In reply to Richard HendersonThese two instructions are aliases of MSR (immediate). Use the two helpers to properly implement svcr_write.
--- target/arm/cpu.h | 1 + target/arm/helper-sme.h | 21 +++++++++++++ target/arm/helper.h | 1 + target/arm/helper.c | 6 ++-- target/arm/sme_helper.c | 61 ++++++++++++++++++++++++++++++++++++++ target/arm/translate-a64.c | 24 +++++++++++++++ target/arm/meson.build | 1 + 7 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 target/arm/helper-sme.h create mode 100644 target/arm/sme_helper.c
target/arm/cpu.h +1 -0
@@ -1106,6 +1106,7 @@ void aarch64_sve_change_el(CPUARMState *env, int old_el, int new_el, bool el0_a64);void aarch64_add_sve_properties (Object *obj);void aarch64_add_pauth_properties (Object *obj); +void arm_reset_sve_state (CPUARMState *env);/* * SVE registers are encoded in KVM's memory in an endianness-invariant format.
target/arm/helper-sme.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* AArch64 SME specific helper definitions +* +* Copyright (c) 2022 Linaro, Ltd +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +DEF_HELPER_FLAGS_2(set_pstate_sm, TCG_CALL_NO_RWG, void, env, i32) +DEF_HELPER_FLAGS_2 (set_pstate_za,TCG_CALL_NO_RWG , void, env, i32)
target/arm/helper.h +1 -0
@@ -1020,6 +1020,7 @@ DEF_HELPER_FLAGS_6(gvec_bfmlal_idx, TCG_CALL_NO_RWG,#ifdef TARGET_AARCH64 #include "helper-a64.h" #include "helper-sve.h" +#include "helper-sme.h" #endif #include "helper-mve.h"
target/arm/helper.c +3 -3
@@ -6370,9 +6370,9 @@ static CPAccessResult access_esm(CPUARMState *env, const ARMCPRegInfo *ri,static void svcr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) { - value &=R_SVCR_SM_MASK |R_SVCR_ZA_MASK ; -/* TODO: Side effects. */ - env->svcr = value; +helper_set_pstate_sm (env,FIELD_EX64 (value,SVCR ,SM )); +helper_set_pstate_za (env,FIELD_EX64 (value,SVCR ,ZA )); +arm_rebuild_hflags (env); } static void smcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
target/arm/sme_helper.c new file +61 -0
61 lines not on this page · raw message
target/arm/translate-a64.c +24 -0
@@ -1761,6 +1761,30 @@ static void handle_msr_i(DisasContext *s, uint32_t insn, }break ; +case 0x1b :/* SVCR* */ +if (!dc_isar_feature (aa64_sme, s) || crm <2 || crm >7 ) { + goto do_unallocated; + } +if (sme_access_check (s)) { +bool i = crm &1 ; +bool changed = false; + +if ((crm &2 ) && i != s->pstate_sm) { +gen_helper_set_pstate_sm (cpu_env,tcg_constant_i32 (i)); + changed = true; + } +if ((crm &4 ) && i != s->pstate_za) { +gen_helper_set_pstate_za (cpu_env,tcg_constant_i32 (i)); + changed = true; + } +if (changed) { +gen_rebuild_hflags (s); + }else { + s->base.is_jmp =DISAS_NEXT ; + } + } +break ; +default : do_unallocated:unallocated_encoding (s);
target/arm/meson.build +1 -0
@@ -47,6 +47,7 @@ arm_ss.add(when: 'TARGET_AARCH64', if_true: files( 'mte_helper.c', 'pauth_helper.c', 'sve_helper.c', + 'sme_helper.c', 'translate-a64.c', 'translate-sve.c', ))
Signature · 1 line
2.34.1
PATCH v2 31/71 target/arm: Move error for sve%d property to arm_cpu_sve_finalize
In reply to Richard HendersonKeep all of the error messages together. This does mean that when setting many sve length properties we'll only generate one error, but we only really need one.
--- target/arm/cpu64.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
target/arm/cpu64.c +7 -8
@@ -487,8 +487,13 @@ void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp) "using only sve<N> properties.\n"); }else {error_setg (errp,"cannot enable sve%d" , vq *128 ); -error_append_hint (errp,"This CPU does not support " -"the vector length %d-bits.\n" , vq *128 ); +if (vq_supported) { +error_append_hint (errp,"This CPU does not support " +"the vector length %d-bits.\n" , vq *128 ); + }else { +error_append_hint (errp,"SVE not supported by KVM " +"on this host\n" ); + } }return ; }else {
@@ -606,12 +611,6 @@ static void cpu_arm_set_sve_vq(Object *obj, Visitor *v, const char *name,return ; } -if (value &&kvm_enabled () && !kvm_arm_sve_supported ()) { -error_setg (errp,"cannot enable %s" , name); -error_append_hint (errp,"SVE not supported by KVM on this host\n" ); -return ; - } - cpu->sve_vq_map =deposit32 (cpu->sve_vq_map, vq -1 ,1 , value); cpu->sve_vq_init |=1 << (vq -1 ); }
Signature · 1 line
2.34.1
Re: [PATCH v2 31/71] target/arm: Move error for sve%d property to arm_cpu_sve_finalize
Quoted 6 lines · Richard Henderson
Keep all of the error messages together. This does mean that when setting many sve length properties we'll only generate one error, but we only really need one.
Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v2 32/71 target/arm: Create ARMVQMap
In reply to Richard HendersonPull the three sve_vq_* values into a structure.
This will be reused for SME.
--- target/arm/cpu.h | 29 ++++++++++++++--------------- target/arm/cpu64.c | 22 +++++++++++----------- target/arm/helper.c | 2 +- target/arm/kvm64.c | 2 +- 4 files changed, 27 insertions(+), 28 deletions(-)
target/arm/cpu.h +14 -15
@@ -793,6 +793,19 @@ typedef enum ARMPSCIState {typedef struct ARMISARegisters ARMISARegisters ; +/* +* In map, each set bit is a supported vector length of (bit-number + 1) * 16 +* bytes, i.e. each bit number + 1 is the vector length in quadwords. +* +* While processing properties during initialization, corresponding init bits +* are set for bits in sve_vq_map that have been set by properties. +* +* Bits set in supported represent valid vector lengths for the CPU type. +*/ +typedef struct { +uint32_t map, init, supported; +}ARMVQMap ; +/** * ARMCPU: * @env: #CPUARMState
@@ -1041,21 +1054,7 @@ struct ArchCPU {uint32_t sve_default_vq;#endif -/* -* In sve_vq_map each set bit is a supported vector length of -* (bit-number + 1) * 16 bytes, i.e. each bit number + 1 is the vector -* length in quadwords. -* -* While processing properties during initialization, corresponding -* sve_vq_init bits are set for bits in sve_vq_map that have been -* set by properties. -* -* Bits set in sve_vq_supported represent valid vector lengths for -* the CPU type. -*/ -uint32_t sve_vq_map; -uint32_t sve_vq_init; -uint32_t sve_vq_supported; +ARMVQMap sve_vq;/* Generic timer counter frequency, in Hz */ uint64_t gt_cntfrq_hz;
target/arm/cpu64.c +11 -11
@@ -355,8 +355,8 @@ void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp)* any of the above. Finally, if SVE is not disabled, then at least one * vector length must be enabled. */ -uint32_t vq_map = cpu->sve_vq_map; -uint32_t vq_init = cpu->sve_vq_init; +uint32_t vq_map = cpu->sve_vq.map; +uint32_t vq_init = cpu->sve_vq.init;uint32_t vq_supported;uint32_t vq_mask =0 ;uint32_t tmp, vq, max_vq =0 ;
@@ -369,14 +369,14 @@ void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp)*/ if (kvm_enabled ()) {if (kvm_arm_sve_supported ()) { - cpu->sve_vq_supported =kvm_arm_sve_get_vls (CPU (cpu)); - vq_supported = cpu->sve_vq_supported; + cpu->sve_vq.supported =kvm_arm_sve_get_vls (CPU (cpu)); + vq_supported = cpu->sve_vq.supported; }else {assert (!cpu_isar_feature (aa64_sve, cpu)); vq_supported =0 ; } }else { - vq_supported = cpu->sve_vq_supported; + vq_supported = cpu->sve_vq.supported; }/*
@@ -534,7 +534,7 @@ void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp)/* From now on sve_max_vq is the actual maximum supported length. */ cpu->sve_max_vq = max_vq; - cpu->sve_vq_map = vq_map; + cpu->sve_vq.map = vq_map; } static void cpu_max_get_sve_max_vq(Object *obj, Visitor *v, const char *name,
@@ -595,7 +595,7 @@ static void cpu_arm_get_sve_vq(Object *obj, Visitor *v, const char *name,if (!cpu_isar_feature (aa64_sve, cpu)) { value = false; }else { - value =extract32 (cpu->sve_vq_map, vq -1 ,1 ); + value =extract32 (cpu->sve_vq.map, vq -1 ,1 ); }visit_type_bool (v, name, &value, errp); }
@@ -611,8 +611,8 @@ static void cpu_arm_set_sve_vq(Object *obj, Visitor *v, const char *name,return ; } - cpu->sve_vq_map =deposit32 (cpu->sve_vq_map, vq -1 ,1 , value); - cpu->sve_vq_init |=1 << (vq -1 ); + cpu->sve_vq.map =deposit32 (cpu->sve_vq.map, vq -1 ,1 , value); + cpu->sve_vq.init |=1 << (vq -1 ); }static bool cpu_arm_get_sve (Object *obj,Error **errp)
@@ -973,7 +973,7 @@ static void aarch64_max_initfn(Object *obj) cpu->dcz_blocksize =7 ;/* 512 bytes */ #endif - cpu->sve_vq_supported =MAKE_64BIT_MASK (0 ,ARM_MAX_VQ ); + cpu->sve_vq.supported =MAKE_64BIT_MASK (0 ,ARM_MAX_VQ );aarch64_add_pauth_properties (obj);aarch64_add_sve_properties (obj);
@@ -1022,7 +1022,7 @@ static void aarch64_a64fx_initfn(Object *obj)/* The A64FX supports only 128, 256 and 512 bit vector lengths */ aarch64_add_sve_properties (obj); - cpu->sve_vq_supported = (1 <<0 )/* 128bit */ + cpu->sve_vq.supported = (1 <<0 )/* 128bit */ | (1 <<1 )/* 256bit */ | (1 <<3 );/* 512bit */
target/arm/helper.c +1 -1
@@ -6291,7 +6291,7 @@ uint32_t sve_vqm1_for_el(CPUARMState *env, int el) len =MIN (len,0xf & (uint32_t )env->vfp.zcr_el[3 ]); } - len =31 -clz32 (cpu->sve_vq_map &MAKE_64BIT_MASK (0 , len +1 )); + len =31 -clz32 (cpu->sve_vq.map &MAKE_64BIT_MASK (0 , len +1 ));return len; }
target/arm/kvm64.c +1 -1
@@ -820,7 +820,7 @@ uint32_t kvm_arm_sve_get_vls(CPUState *cs)static int kvm_arm_sve_set_vls (CPUState *cs) {ARMCPU *cpu =ARM_CPU (cs); -uint64_t vls[KVM_ARM64_SVE_VLS_WORDS ] = { cpu->sve_vq_map }; +uint64_t vls[KVM_ARM64_SVE_VLS_WORDS ] = { cpu->sve_vq.map };struct kvm_one_reg reg = { .id =KVM_REG_ARM64_SVE_VLS , .addr = (uint64_t )&vls[0 ],
Signature · 1 line
2.34.1
Re: [PATCH v2 32/71] target/arm: Create ARMVQMap
Quoted 11 lines · Richard Henderson
Pull the three sve_vq_* values into a structure.
This will be reused for SME.Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu.h | 29 ++++++++++++++--------------- target/arm/cpu64.c | 22 +++++++++++----------- target/arm/helper.c | 2 +- target/arm/kvm64.c | 2 +- 4 files changed, 27 insertions(+), 28 deletions(-)
thanks
-- PMM
PATCH v2 33/71 target/arm: Generalize cpu_arm_{get,set}_vq
In reply to Richard HendersonRename from cpu_arm_{get,set}_sve_vq, and take the ARMVQMap as the opaque parameter.
--- target/arm/cpu64.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
target/arm/cpu64.c +15 -14
@@ -579,15 +579,15 @@ static void cpu_max_set_sve_max_vq(Object *obj, Visitor *v, const char *name, }/* -* Note that cpu_arm_get/set_sve_vq cannot use the simpler -* object_property_add_bool interface because they make use -* of the contents of "name" to determine which bit on which -* to operate. +* Note that cpu_arm_{get,set}_vq cannot use the simpler +* object_property_add_bool interface because they make use of the +* contents of "name" to determine which bit on which to operate. */ -static void cpu_arm_get_sve_vq (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) +static void cpu_arm_get_vq (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) {ARMCPU *cpu =ARM_CPU (obj); +ARMVQMap *vq_map = opaque;uint32_t vq =atoi (&name[3 ]) /128 ;bool value;
@@ -595,15 +595,15 @@ static void cpu_arm_get_sve_vq(Object *obj, Visitor *v, const char *name,if (!cpu_isar_feature (aa64_sve, cpu)) { value = false; }else { - value =extract32 (cpu->sve_vq.map, vq -1 ,1 ); + value =extract32 (vq_map->map, vq -1 ,1 ); }visit_type_bool (v, name, &value, errp); } -static void cpu_arm_set_sve_vq (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) +static void cpu_arm_set_vq (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) { -ARMCPU *cpu =ARM_CPU (obj); +ARMVQMap *vq_map = opaque;uint32_t vq =atoi (&name[3 ]) /128 ;bool value;
@@ -611,8 +611,8 @@ static void cpu_arm_set_sve_vq(Object *obj, Visitor *v, const char *name,return ; } - cpu->sve_vq.map =deposit32 (cpu->sve_vq.map, vq -1 ,1 , value); - cpu->sve_vq.init |=1 << (vq -1 ); + vq_map->map =deposit32 (vq_map->map, vq -1 ,1 , value); + vq_map->init |=1 << (vq -1 ); }static bool cpu_arm_get_sve (Object *obj,Error **errp)
@@ -691,6 +691,7 @@ static void cpu_arm_get_sve_default_vec_len(Object *obj, Visitor *v,void aarch64_add_sve_properties (Object *obj) { +ARMCPU *cpu =ARM_CPU (obj);uint32_t vq;object_property_add_bool (obj,"sve" , cpu_arm_get_sve, cpu_arm_set_sve);
@@ -698,8 +699,8 @@ void aarch64_add_sve_properties(Object *obj)for (vq =1 ; vq <=ARM_MAX_VQ ; ++vq) {char name[8 ];sprintf (name,"sve%d" , vq *128 ); -object_property_add (obj, name,"bool" , cpu_arm_get_sve_vq, - cpu_arm_set_sve_vq,NULL ,NULL ); +object_property_add (obj, name,"bool" , cpu_arm_get_vq, + cpu_arm_set_vq,NULL , &cpu->sve_vq); }#ifdef CONFIG_USER_ONLY
Signature · 1 line
2.34.1
Re: [PATCH v2 33/71] target/arm: Generalize cpu_arm_{get,set}_vq
Quoted 5 lines · Richard Henderson
Rename from cpu_arm_{get,set}_sve_vq, and take the ARMVQMap as the opaque parameter.
Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v2 34/71 target/arm: Generalize cpu_arm_{get, set}_default_vec_len
In reply to Richard HendersonRename from cpu_arm_{get,set}_sve_default_vec_len, and take the pointer to default_vq from opaque.
--- target/arm/cpu64.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
target/arm/cpu64.c +14 -13
@@ -638,11 +638,11 @@ static void cpu_arm_set_sve(Object *obj, bool value, Error **errp)#ifdef CONFIG_USER_ONLY /* Mirror linux /proc/sys/abi/sve_default_vector_length. */ -static void cpu_arm_set_sve_default_vec_len (Object *obj,Visitor *v, -const char *name,void *opaque, -Error **errp) +static void cpu_arm_set_default_vec_len (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) { -ARMCPU *cpu =ARM_CPU (obj); +uint32_t *ptr_default_vq = opaque;int32_t default_len, default_vq, remainder;if (!visit_type_int32 (v, name, &default_len, errp)) {
@@ -651,7 +651,7 @@ static void cpu_arm_set_sve_default_vec_len(Object *obj, Visitor *v,/* Undocumented, but the kernel allows -1 to indicate "maximum". */ if (default_len ==-1 ) { - cpu->sve_default_vq =ARM_MAX_VQ ; + *ptr_default_vq =ARM_MAX_VQ ;return ; }
@@ -675,15 +675,15 @@ static void cpu_arm_set_sve_default_vec_len(Object *obj, Visitor *v,return ; } - cpu->sve_default_vq = default_vq; + *ptr_default_vq = default_vq; } -static void cpu_arm_get_sve_default_vec_len (Object *obj,Visitor *v, -const char *name,void *opaque, -Error **errp) +static void cpu_arm_get_default_vec_len (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) { -ARMCPU *cpu =ARM_CPU (obj); -int32_t value = cpu->sve_default_vq *16 ; +uint32_t *ptr_default_vq = opaque; +int32_t value = *ptr_default_vq *16 ;visit_type_int32 (v, name, &value, errp); }
@@ -706,8 +706,9 @@ void aarch64_add_sve_properties(Object *obj)#ifdef CONFIG_USER_ONLY /* Mirror linux /proc/sys/abi/sve_default_vector_length. */ object_property_add (obj,"sve-default-vector-length" ,"int32" , - cpu_arm_get_sve_default_vec_len, - cpu_arm_set_sve_default_vec_len,NULL ,NULL ); + cpu_arm_get_default_vec_len, + cpu_arm_set_default_vec_len,NULL , + &cpu->sve_default_vq);#endif }
Signature · 1 line
2.34.1
Re: [PATCH v2 34/71] target/arm: Generalize cpu_arm_{get, set}_default_vec_len
Quoted 5 lines · Richard Henderson
Rename from cpu_arm_{get,set}_sve_default_vec_len, and take the pointer to
default_vqfrom opaque.Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v2 35/71 target/arm: Move arm_cpu_*_finalize to internals.h
In reply to Richard HendersonDrop the aa32-only inline fallbacks,
and just use a couple of ifdefs.
--- target/arm/cpu.h | 6 ------ target/arm/internals.h | 3 +++ target/arm/cpu.c | 2 ++ 3 files changed, 5 insertions(+), 6 deletions(-)
target/arm/cpu.h +0 -6
@@ -205,14 +205,8 @@ typedef struct {#ifdef TARGET_AARCH64 # define ARM_MAX_VQ 16 -void arm_cpu_sve_finalize (ARMCPU *cpu,Error **errp); -void arm_cpu_pauth_finalize (ARMCPU *cpu,Error **errp); -void arm_cpu_lpa2_finalize (ARMCPU *cpu,Error **errp);#else # define ARM_MAX_VQ 1 -static inline void arm_cpu_sve_finalize (ARMCPU *cpu,Error **errp) { } -static inline void arm_cpu_pauth_finalize (ARMCPU *cpu,Error **errp) { } -static inline void arm_cpu_lpa2_finalize (ARMCPU *cpu,Error **errp) { }#endif typedef struct ARMVectorReg {
target/arm/internals.h +3 -0
@@ -1309,6 +1309,9 @@ int arm_gdb_get_svereg(CPUARMState *env, GByteArray *buf, int reg);int arm_gdb_set_svereg (CPUARMState *env,uint8_t *buf,int reg);int aarch64_fpu_gdb_get_reg (CPUARMState *env,GByteArray *buf,int reg);int aarch64_fpu_gdb_set_reg (CPUARMState *env,uint8_t *buf,int reg); +void arm_cpu_sve_finalize (ARMCPU *cpu,Error **errp); +void arm_cpu_pauth_finalize (ARMCPU *cpu,Error **errp); +void arm_cpu_lpa2_finalize (ARMCPU *cpu,Error **errp);#endif #ifdef CONFIG_USER_ONLY
target/arm/cpu.c +2 -0
@@ -1421,6 +1421,7 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp) {Error *local_err =NULL ; +#ifdef TARGET_AARCH64 if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) {arm_cpu_sve_finalize (cpu, &local_err);if (local_err !=NULL ) {
@@ -1440,6 +1441,7 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp) return; } } +#endif if (kvm_enabled ()) {kvm_arm_steal_time_finalize (cpu, &local_err);
Signature · 1 line
2.34.1
Re: [PATCH v2 35/71] target/arm: Move arm_cpu_*_finalize to internals.h
Quoted 10 lines · Richard Henderson
Drop the aa32-only inline fallbacks,
and just use a couple of ifdefs.Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu.h | 6 ------ target/arm/internals.h | 3 +++ target/arm/cpu.c | 2 ++ 3 files changed, 5 insertions(+), 6 deletions(-)
I'm not a huge fan of ifdefs in functions, but I guess so.
thanks
-- PMM
PATCH v2 36/71 target/arm: Unexport aarch64_add_*_properties
In reply to Richard HendersonThese functions are not used outside cpu64.c,
so make them static.
--- target/arm/cpu.h | 3 --- target/arm/cpu64.c | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-)
target/arm/cpu.h +0 -3
@@ -1097,8 +1097,6 @@ int aarch64_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);void aarch64_sve_narrow_vq (CPUARMState *env,unsigned vq);void aarch64_sve_change_el (CPUARMState *env,int old_el,int new_el,bool el0_a64); -void aarch64_add_sve_properties (Object *obj); -void aarch64_add_pauth_properties (Object *obj);void arm_reset_sve_state (CPUARMState *env);/*
@@ -1130,7 +1128,6 @@ static inline void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq) { }static inline void aarch64_sve_change_el (CPUARMState *env,int o,int n,bool a) { } -static inline void aarch64_add_sve_properties (Object *obj) { }#endif void aarch64_sync_32_to_64 (CPUARMState *env);
target/arm/cpu64.c +2 -2
@@ -689,7 +689,7 @@ static void cpu_arm_get_default_vec_len(Object *obj, Visitor *v, }#endif -void aarch64_add_sve_properties (Object *obj) +static void aarch64_add_sve_properties (Object *obj) {ARMCPU *cpu =ARM_CPU (obj);uint32_t vq;
@@ -752,7 +752,7 @@ static Property arm_cpu_pauth_property =static Property arm_cpu_pauth_impdef_property =DEFINE_PROP_BOOL ("pauth-impdef" ,ARMCPU , prop_pauth_impdef, false); -void aarch64_add_pauth_properties (Object *obj) +static void aarch64_add_pauth_properties (Object *obj) {ARMCPU *cpu =ARM_CPU (obj);
Signature · 1 line
2.34.1
Re: [PATCH v2 36/71] target/arm: Unexport aarch64_add_*_properties
Quoted 10 lines · Richard Henderson
These functions are not used outside
cpu64.c,
so make them static.Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu.h | 3 --- target/arm/cpu64.c | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-)
thanks
-- PMM
PATCH v2 37/71 target/arm: Add cpu properties for SME
In reply to Richard HendersonMirror the properties for SVE. The main difference is that any arbitrary set of powers of 2 may be supported, and not the stricter constraints that apply to SVE.
Include a property to control FEAT_SME_FA64, as failing to restrict the runtime to the proper subset of insns could be a major point for bugs.
--- target/arm/cpu.h | 2 + target/arm/internals.h | 1 + target/arm/cpu.c | 14 +++-- target/arm/cpu64.c | 114 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 124 insertions(+), 7 deletions(-)
target/arm/cpu.h +2 -0
@@ -1046,9 +1046,11 @@ struct ArchCPU {#ifdef CONFIG_USER_ONLY /* Used to set the default vector length at process start. */ uint32_t sve_default_vq; +uint32_t sme_default_vq;#endif ARMVQMap sve_vq; +ARMVQMap sme_vq;/* Generic timer counter frequency, in Hz */ uint64_t gt_cntfrq_hz;
target/arm/internals.h +1 -0
@@ -1310,6 +1310,7 @@ int arm_gdb_set_svereg(CPUARMState *env, uint8_t *buf, int reg);int aarch64_fpu_gdb_get_reg (CPUARMState *env,GByteArray *buf,int reg);int aarch64_fpu_gdb_set_reg (CPUARMState *env,uint8_t *buf,int reg);void arm_cpu_sve_finalize (ARMCPU *cpu,Error **errp); +void arm_cpu_sme_finalize (ARMCPU *cpu,Error **errp);void arm_cpu_pauth_finalize (ARMCPU *cpu,Error **errp);void arm_cpu_lpa2_finalize (ARMCPU *cpu,Error **errp);#endif
target/arm/cpu.c +11 -3
@@ -1122,11 +1122,13 @@ static void arm_cpu_initfn(Object *obj)#ifdef CONFIG_USER_ONLY # ifdef TARGET_AARCH64 /* -* The linux kernel defaults to 512-bit vectors, when sve is supported. -* See documentation for /proc/sys/abi/sve_default_vector_length, and -* our corresponding sve-default-vector-length cpu property. +* The linux kernel defaults to 512-bit for SVE, and 256-bit for SME. +* These values were chosen to fit within the default signal frame. +* See documentation for /proc/sys/abi/{sve,sme}_default_vector_length, +* and our corresponding cpu property. */ cpu->sve_default_vq =4 ; + cpu->sme_default_vq =2 ;# endif #else /* Our inbound IRQ and FIQ lines */
@@ -1429,6 +1431,12 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp)return ; } +arm_cpu_sme_finalize (cpu, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + } +arm_cpu_pauth_finalize (cpu, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);
target/arm/cpu64.c +110 -4
150 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 37/71] target/arm: Add cpu properties for SME
Quoted 10 lines · Richard Henderson
Mirror the properties for SVE. The main difference is that any arbitrary set of powers of 2 may be supported, and not the stricter constraints that apply to SVE.
Include a property to control
FEAT_SME_FA64, as failing to restrict the runtime to the proper subset of insns could be a major point for bugs.Signed-off-by Richard Henderson <[email protected]>
Still missing the docs :-)
-- PMM
PATCH v2 38/71 target/arm: Introduce sve_vqm1_for_el_sm
In reply to Richard HendersonWhen Streaming SVE mode is enabled, the size is taken from SMCR_ELx instead of ZCR_ELx. The format is shared, but the set of vector lengths is not. Further, Streaming SVE does not require any particular length to be supported.
Adjust sve_vqm1_for_el to pass the current value of PSTATE.SM to the new function.
--- target/arm/cpu.h | 9 +++++++-- target/arm/helper.c | 32 +++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 9 deletions(-)
target/arm/cpu.h +7 -2
@@ -1140,13 +1140,18 @@ int sve_exception_el(CPUARMState *env, int cur_el);int sme_exception_el (CPUARMState *env,int cur_el);/** -* sve_vqm1_for_el: +* sve_vqm1_for_el_sm: * @env: CPUARMState * @el: exception level +* @sm: streaming mode * -* Compute the current SVE vector length for @el, in units of +* Compute the current vector length for @el & @sm, in units of * Quadwords Minus 1 -- the same scale used for ZCR_ELx.LEN. +* If @sm, compute for SVL, otherwise NVL. */ +uint32_t sve_vqm1_for_el_sm (CPUARMState *env,int el,bool sm); + +/* Likewise, but using @sm = PSTATE.SM. */ uint32_t sve_vqm1_for_el (CPUARMState *env,int el);static inline bool is_a64 (CPUARMState *env)
target/arm/helper.c +25 -7
@@ -6276,23 +6276,41 @@ int sme_exception_el(CPUARMState *env, int el)/* * Given that SVE is enabled, return the vector length for EL. */ -uint32_t sve_vqm1_for_el (CPUARMState *env,int el) +uint32_t sve_vqm1_for_el_sm (CPUARMState *env,int el,bool sm) {ARMCPU *cpu =env_archcpu (env); -uint32_t len = cpu->sve_max_vq -1 ; +uint64_t *cr = env->vfp.zcr_el; +uint32_t map = cpu->sve_vq.map; +uint32_t len =ARM_MAX_VQ -1 ; + +if (sm) { + cr = env->vfp.smcr_el; + map = cpu->sme_vq.map; + }if (el <=1 && !el_is_in_host (env, el)) { - len =MIN (len,0xf & (uint32_t )env->vfp.zcr_el[1 ]); + len =MIN (len,0xf & (uint32_t )cr[1 ]); }if (el <=2 &&arm_feature (env,ARM_FEATURE_EL2 )) { - len =MIN (len,0xf & (uint32_t )env->vfp.zcr_el[2 ]); + len =MIN (len,0xf & (uint32_t )cr[2 ]); }if (arm_feature (env,ARM_FEATURE_EL3 )) { - len =MIN (len,0xf & (uint32_t )env->vfp.zcr_el[3 ]); + len =MIN (len,0xf & (uint32_t )cr[3 ]); } - len =31 -clz32 (cpu->sve_vq.map &MAKE_64BIT_MASK (0 , len +1 )); -return len; + map &=MAKE_64BIT_MASK (0 , len +1 ); +if (map !=0 ) { +return 31 -clz32 (map); + } + +/* Bit 0 is always set for Normal SVE -- not so for Streaming SVE. */ +assert (sm); +return ctz32 (cpu->sme_vq.map); +} + +uint32_t sve_vqm1_for_el (CPUARMState *env,int el) +{ +return sve_vqm1_for_el_sm (env, el,FIELD_EX64 (env->svcr,SVCR ,SM )); } static void zcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
Signature · 1 line
2.34.1
Re: [PATCH v2 38/71] target/arm: Introduce sve_vqm1_for_el_sm
Quoted 11 lines · Richard Henderson
When Streaming SVE mode is enabled, the size is taken from
SMCR_ELxinstead ofZCR_ELx. The format is shared, but the set of vector lengths is not. Further, Streaming SVE does not require any particular length to be supported.Adjust
sve_vqm1_for_elto pass the current value of PSTATE.SM to the new function.Signed-off-by Richard Henderson <[email protected]>---
thanks
-- PMM
PATCH v2 39/71 target/arm: Add SVL to TB flags
In reply to Richard HendersonWe need SVL separate from VL for RDSVL at al, as well as ZA storage loads and stores, which do not require PSTATE.SM.
--- target/arm/cpu.h | 12 ++++++++++++ target/arm/translate.h | 1 + target/arm/helper.c | 8 +++++++- target/arm/translate-a64.c | 1 + 4 files changed, 21 insertions(+), 1 deletion(-)
target/arm/cpu.h +12 -0
@@ -3292,6 +3292,7 @@ FIELD(TBFLAG_A64, MTE0_ACTIVE, 19, 1) FIELD(TBFLAG_A64, SMEEXC_EL, 20, 2) FIELD(TBFLAG_A64, PSTATE_SM, 22, 1) FIELD(TBFLAG_A64, PSTATE_ZA, 23, 1) +FIELD (TBFLAG_A64 ,SVL ,24 ,4 )/* * Helpers for using the above.
@@ -3337,6 +3338,17 @@ static inline int sve_vq(CPUARMState *env)return EX_TBFLAG_A64 (env->hflags,VL ) +1 ; } +/** +* sme_vq +* @env: the cpu context +* +* Return the SVL cached within env->hflags, in units of quadwords. +*/ +static inline int sme_vq (CPUARMState *env) +{ +return EX_TBFLAG_A64 (env->hflags,SVL ) +1 ; +} +static inline bool bswap_code (bool sctlr_b) {#ifdef CONFIG_USER_ONLY
target/arm/translate.h +1 -0
@@ -44,6 +44,7 @@ typedef struct DisasContext {int sve_excp_el;/* SVE exception EL or 0 if enabled */ int sme_excp_el;/* SME exception EL or 0 if enabled */ int vl;/* current vector length in bytes */ +int svl;/* current streaming vector length in bytes */ /* Flag indicating that exceptions from secure mode are routed to EL3. */ bool secure_routed_to_el3;bool vfp_enabled;/* FP enabled via FPSCR.EN */
target/arm/helper.c +7 -1
@@ -13874,7 +13874,13 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el,DP_TBFLAG_A64 (flags,SVEEXC_EL , sve_el); }if (cpu_isar_feature (aa64_sme,env_archcpu (env))) { -DP_TBFLAG_A64 (flags,SMEEXC_EL ,sme_exception_el (env, el)); +int sme_el =sme_exception_el (env, el); + +DP_TBFLAG_A64 (flags,SMEEXC_EL , sme_el); +if (sme_el ==0 ) { +/* Similarly, do not compute SVL if SME is disabled. */ +DP_TBFLAG_A64 (flags,SVL ,sve_vqm1_for_el_sm (env, el, true)); + }if (FIELD_EX64 (env->svcr,SVCR ,SM )) {DP_TBFLAG_A64 (flags,PSTATE_SM ,1 ); }
target/arm/translate-a64.c +1 -0
@@ -14652,6 +14652,7 @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, dc->sve_excp_el =EX_TBFLAG_A64 (tb_flags,SVEEXC_EL ); dc->sme_excp_el =EX_TBFLAG_A64 (tb_flags,SMEEXC_EL ); dc->vl = (EX_TBFLAG_A64 (tb_flags,VL ) +1 ) *16 ; + dc->svl = (EX_TBFLAG_A64 (tb_flags,SVL ) +1 ) *16 ; dc->pauth_active =EX_TBFLAG_A64 (tb_flags,PAUTH_ACTIVE ); dc->bt =EX_TBFLAG_A64 (tb_flags,BT ); dc->btype =EX_TBFLAG_A64 (tb_flags,BTYPE );
Signature · 1 line
2.34.1
Re: [PATCH v2 39/71] target/arm: Add SVL to TB flags
Quoted 6 lines · Richard Henderson
We need SVL separate from VL for RDSVL at al, as well as ZA storage loads and stores, which do not require PSTATE.SM.
Signed-off-by Richard Henderson <[email protected]>---
thanks
-- PMM
PATCH v2 40/71 target/arm: Move pred_{full, gvec}_reg_{offset, size} to translate-a64.h
In reply to Richard HendersonWe will need these functions in translate-sme.c.
--- target/arm/translate-a64.h | 38 ++++++++++++++++++++++++++++++++++++++ target/arm/translate-sve.c | 36 ------------------------------------ 2 files changed, 38 insertions(+), 36 deletions(-)
target/arm/translate-a64.h +38 -0
@@ -107,6 +107,44 @@ static inline int vec_full_reg_size(DisasContext *s)return s->vl; } +/* +* Return the offset info CPUARMState of the predicate vector register Pn. +* Note for this purpose, FFR is P16. +*/ +static inline int pred_full_reg_offset (DisasContext *s,int regno) +{ + return offsetof(CPUARMState, vfp.pregs[regno]); +} + +/* Return the byte size of the whole predicate register, VL / 64. */ +static inline int pred_full_reg_size (DisasContext *s) +{ +return s->vl >>3 ; +} + +/* +* Round up the size of a register to a size allowed by +* the tcg vector infrastructure. Any operation which uses this +* size may assume that the bits above pred_full_reg_size are zero, +* and must leave them the same way. +* +* Note that this is not needed for the vector registers as they +* are always properly sized for tcg vectors. +*/ +static inline int size_for_gvec (int size) +{ +if (size <=8 ) { +return 8 ; + }else { +return QEMU_ALIGN_UP (size,16 ); + } +} + +static inline int pred_gvec_reg_size (DisasContext *s) +{ +return size_for_gvec (pred_full_reg_size (s)); +} +bool disas_sve (DisasContext *,uint32_t ); void gen_gvec_rax1(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
target/arm/translate-sve.c +0 -36
@@ -100,42 +100,6 @@ static inline int msz_dtype(DisasContext *s, int msz)* Implement all of the translator functions referenced by the decoder. */ -/* Return the offset info CPUARMState of the predicate vector register Pn. -* Note for this purpose, FFR is P16. -*/ -static inline int pred_full_reg_offset (DisasContext *s,int regno) -{ - return offsetof(CPUARMState, vfp.pregs[regno]); -} - -/* Return the byte size of the whole predicate register, VL / 64. */ -static inline int pred_full_reg_size (DisasContext *s) -{ -return s->vl >>3 ; -} - -/* Round up the size of a register to a size allowed by -* the tcg vector infrastructure. Any operation which uses this -* size may assume that the bits above pred_full_reg_size are zero, -* and must leave them the same way. -* -* Note that this is not needed for the vector registers as they -* are always properly sized for tcg vectors. -*/ -static int size_for_gvec (int size) -{ -if (size <=8 ) { -return 8 ; - }else { -return QEMU_ALIGN_UP (size,16 ); - } -} - -static int pred_gvec_reg_size (DisasContext *s) -{ -return size_for_gvec (pred_full_reg_size (s)); -} -/* Invoke an out-of-line helper on 2 Zregs. */ static bool gen_gvec_ool_zz (DisasContext *s,gen_helper_gvec_2 *fn,int rd,int rn,int data)
Signature · 1 line
2.34.1
Re: [PATCH v2 40/71] target/arm: Move pred_{full, gvec}_reg_{offset, size} to translate-a64.h
Quoted 4 lines · Richard Henderson
We will need these functions in
translate-sme.c.Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v2 41/71 target/arm: Add infrastructure for disas_sme
In reply to Richard HendersonThis includes the build rules for the decoder, and the new file for translation, but excludes any instructions.
--- target/arm/translate-a64.h | 1 + target/arm/translate-a64.c | 7 ++++++- target/arm/translate-sme.c | 35 +++++++++++++++++++++++++++++++++++ target/arm/meson.build | 2 ++ target/arm/sme.decode | 20 ++++++++++++++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 target/arm/translate-sme.c create mode 100644 target/arm/sme.decode
target/arm/translate-a64.h +1 -0
@@ -146,6 +146,7 @@ static inline int pred_gvec_reg_size(DisasContext *s) }bool disas_sve (DisasContext *,uint32_t ); +bool disas_sme (DisasContext *,uint32_t );void gen_gvec_rax1 (unsigned vece,uint32_t rd_ofs,uint32_t rn_ofs,uint32_t rm_ofs,uint32_t opr_sz,uint32_t max_sz);
target/arm/translate-a64.c +6 -1
@@ -14814,7 +14814,12 @@ static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) }switch (extract32 (insn,25 ,4 )) { -case 0x0 :case 0x1 :case 0x3 :/* UNALLOCATED */ +case 0x0 : +if (!disas_sme (s, insn)) { +unallocated_encoding (s); + } +break ; +case 0x1 :case 0x3 :/* UNALLOCATED */ unallocated_encoding (s);break ;case 0x2 :
target/arm/translate-sme.c new file +35 -0
@@ -0,0 +1,35 @@ +/* +* AArch64 SME translation +* +* Copyright (c) 2022 Linaro, Ltd +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "tcg/tcg-op.h" +#include "tcg/tcg-op-gvec.h" +#include "tcg/tcg-gvec-desc.h" +#include "translate.h" +#include "exec/helper-gen.h" +#include "translate-a64.h" +#include "fpu/softfloat.h" + + +/* +* Include the generated decoder. +*/ + +#include "decode-sme.c.inc"
target/arm/meson.build +2 -0
@@ -1,5 +1,6 @@ gen = [ decodetree.process('sve.decode', extra_args: '--decode=disas_sve'), + decodetree.process('sme.decode', extra_args: '--decode=disas_sme'), decodetree.process('neon-shared.decode', extra_args: '--decode=disas_neon_shared'), decodetree.process('neon-dp.decode', extra_args: '--decode=disas_neon_dp'), decodetree.process('neon-ls.decode', extra_args: '--decode=disas_neon_ls'),
@@ -50,6 +51,7 @@ arm_ss.add(when: 'TARGET_AARCH64', if_true: files( 'sme_helper.c', 'translate-a64.c', 'translate-sve.c', + 'translate-sme.c', )) arm_softmmu_ss = ss.source_set()
target/arm/sme.decode new file +20 -0
@@ -0,0 +1,20 @@ +# AArch64 SME instruction descriptions +# +# Copyright (c) 2022 Linaro, Ltd +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see <http://www.gnu.org/licenses/>. + +# +# This file is processed by scripts/decodetree.py +#
Signature · 1 line
2.34.1
Re: [PATCH v2 41/71] target/arm: Add infrastructure for disas_sme
Quoted 32 lines · Richard Henderson
This includes the build rules for the decoder, and the new file for translation, but excludes any instructions.
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate-a64.h | 1 + target/arm/translate-a64.c | 7 ++++++- target/arm/translate-sme.c | 35 +++++++++++++++++++++++++++++++++++ target/arm/meson.build | 2 ++ target/arm/sme.decode | 20 ++++++++++++++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 target/arm/translate-sme.c create mode 100644 target/arm/sme.decodetarget/arm/translate-a64.h +1
-0@@ -146,6 +146,7 @@ static inline int pred_gvec_reg_size(DisasContext *s) }bool disas_sve (DisasContext *,uint32_t ); +bool disas_sme (DisasContext *,uint32_t );void gen_gvec_rax1 (unsigned vece,uint32_t rd_ofs,uint32_t rn_ofs,uint32_t rm_ofs,uint32_t opr_sz,uint32_t max_sz);target/arm/translate-a64.c +0
-0
target/arm/translate-a64.c static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) · line 14821
Quoted 9 lines
target/arm/translate-a64.c +5
-1@@ -14814,7 +14814,12 @@ static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) }switch (extract32 (insn,25 ,4 )) { -case 0x0 :case 0x1 :case 0x3 :/* UNALLOCATED */ +case 0x0 : +if (!disas_sme (s, insn)) { +unallocated_encoding (s); + } +break ;
I still think we should check bit 31 here.
Otherwise
thanks
-- PMM
Re: [PATCH v2 41/71] target/arm: Add infrastructure for disas_sme
Quoted 6 lines · Peter Maydell
target/arm/translate-a64.c static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) · line 14821
Quoted 4 lines
target/arm/translate-a64.c +4
-0+if (!disas_sme (s, insn)) { +unallocated_encoding (s); + } +break ;I still think we should check bit 31 here.
We don't do anything similar over in a32, where we've done the full conversion:
if (disas_a32_uncond(s, insn) ||
disas_vfp_uncond(s, insn) ||
disas_neon_dp(s, insn) ||
disas_neon_ls(s, insn) ||
disas_neon_shared(s, insn)) {
return;
}and there's nothing else within major opcode 0 to conflict.
But if you insist, ok.
r~
Re: [PATCH v2 41/71] target/arm: Add infrastructure for disas_sme
Quoted 11 lines · Richard Henderson
Quoted 6 lines · Peter Maydell
target/arm/translate-a64.c static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) · line 14821
Quoted 4 lines
target/arm/translate-a64.c +4
-0+if (!disas_sme (s, insn)) { +unallocated_encoding (s); + } +break ;I still think we should check bit 31 here.
We don't do anything similar over in a32, where we've done the full conversion:
Quoted 13 lines
if (disas_a32_uncond(s, insn) ||
disas_vfp_uncond(s, insn) ||
disas_neon_dp(s, insn) ||
disas_neon_ls(s, insn) ||
disas_neon_shared(s, insn)) {
return;
}The difference there is that we've basically completed the decodetree conversion. Here we're putting one decodetree disas call inside a legacy decode, so we should put it at the right point in the legacy structure, I think.
Quoted 1 line
and there's nothing else within major opcode 0 to conflict.
Yet :-)
-- PMM
PATCH v2 42/71 target/arm: Trap AdvSIMD usage when Streaming SVE is active
In reply to Richard HendersonThis new behaviour is in the ARM pseudocode function AArch64.CheckFPAdvSIMDEnabled, which applies to AArch32 via AArch32.CheckAdvSIMDOrFPEnabled when the EL to which the trap would be delivered is in AArch64 mode.
Given that ARMv9 drops support for AArch32 outside EL0, the trap EL detection ought to be trivially true, but the pseudocode still contains a number of conditions, and QEMU has not yet committed to dropping A32 support for EL[12] when v9 features are present.
Since the computation of SME_TRAP_SIMD is necessarily different for the two modes, we might as well preserve bits within TBFLAG_ANY and allocate separate bits within TBFLAG_A32 and TBFLAG_A64 instead.
--- target/arm/cpu.h | 6 +++ target/arm/translate.h | 3 ++ target/arm/helper.c | 42 ++++++++++++++++++ target/arm/translate-a64.c | 41 +++++++++++++++++- target/arm/translate-vfp.c | 13 ++++++ target/arm/translate.c | 1 + target/arm/meson.build | 1 + target/arm/sme-fa64.decode | 89 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 target/arm/sme-fa64.decode
target/arm/cpu.h +6 -0
@@ -3256,6 +3256,11 @@ FIELD(TBFLAG_A32, HSTR_ACTIVE, 9, 1)* the same thing as the current security state of the processor! */ FIELD (TBFLAG_A32 ,NS ,10 ,1 ) +/* +* Indicates that SME Streaming mode is active, and SMCR_ELx.FA64 is not. +* This requires an SME trap from AArch32 mode when using NEON. + */ +FIELD (TBFLAG_A32 ,SME_TRAP_SIMD ,11 ,1 )/* * Bit usage when in AArch32 state, for M-profile only.
@@ -3293,6 +3298,7 @@ FIELD(TBFLAG_A64, SMEEXC_EL, 20, 2) FIELD(TBFLAG_A64, PSTATE_SM, 22, 1) FIELD(TBFLAG_A64, PSTATE_ZA, 23, 1) FIELD(TBFLAG_A64, SVL, 24, 4) +FIELD (TBFLAG_A64 ,SME_TRAP_SIMD ,28 ,1 )/* * Helpers for using the above.
target/arm/translate.h +3 -0
@@ -106,6 +106,9 @@ typedef struct DisasContext {bool pstate_sm;/* True if PSTATE.ZA is set. */ bool pstate_za; +/* True if AdvSIMD insns should raise an SME Streaming exception. */ +bool sme_trap_simd; +bool sme_trap_this_insn;/* True if MVE insns are definitely not predicated by VPR or LTPSIZE */ bool mve_no_pred;/*
target/arm/helper.c +42 -0
60 lines not on this page · raw message
target/arm/translate-a64.c +39 -2
77 lines not on this page · raw message
target/arm/translate-vfp.c +13 -0
@@ -224,6 +224,19 @@ static bool vfp_access_check_a(DisasContext *s, bool ignore_vfp_enabled)return false; } +/* +* Note that rebuild_hflags_a32 has already accounted for being in EL0 +* and the higher EL in A64 mode, etc. Unlike A64 mode, there do not +* appear to be any insns which touch VFP which are allowed. +*/ +if (s->sme_trap_simd) { +gen_exception_insn (s, s->pc_curr,EXCP_UDEF , +syn_smetrap (SME_ET_Streaming, + s->base.pc_next - s->pc_curr ==2 ), +default_exception_el (s)); +return false; + } +if (!s->vfp_enabled && !ignore_vfp_enabled) {assert (!arm_dc_feature (s,ARM_FEATURE_M ));unallocated_encoding (s);
target/arm/translate.c +1 -0
@@ -9365,6 +9365,7 @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) dc->vec_len =EX_TBFLAG_A32 (tb_flags,VECLEN ); dc->vec_stride =EX_TBFLAG_A32 (tb_flags,VECSTRIDE ); } + dc->sme_trap_simd =EX_TBFLAG_A32 (tb_flags,SME_TRAP_SIMD ); } dc->cp_regs = cpu->cp_regs; dc->features = env->features;
target/arm/meson.build +1 -0
@@ -1,6 +1,7 @@ gen = [ decodetree.process('sve.decode', extra_args: '--decode=disas_sve'), decodetree.process('sme.decode', extra_args: '--decode=disas_sme'), + decodetree.process('sme-fa64.decode', extra_args: '--static-decode=disas_sme_fa64'), decodetree.process('neon-shared.decode', extra_args: '--decode=disas_neon_shared'), decodetree.process('neon-dp.decode', extra_args: '--decode=disas_neon_dp'), decodetree.process('neon-ls.decode', extra_args: '--decode=disas_neon_ls'),
target/arm/sme-fa64.decode new file +89 -0
89 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 43/71 target/arm: Implement SME RDSVL, ADDSVL, ADDSPL
In reply to Richard HendersonThese SME instructions are nominally within the SVE decode space, so we add them to sve.decode and translate-sve.c.
--- target/arm/translate-a64.h | 1 + target/arm/translate-a64.c | 15 +++++++++++++++ target/arm/translate-sve.c | 38 ++++++++++++++++++++++++++++++++++++++ target/arm/sve.decode | 5 ++++- 4 files changed, 58 insertions(+), 1 deletion(-)
target/arm/translate-a64.h +1 -0
@@ -29,6 +29,7 @@ void write_fp_dreg(DisasContext *s, int reg, TCGv_i64 v);bool logic_imm_decode_wmask (uint64_t *result,unsigned int immn,unsigned int imms,unsigned int immr);bool sve_access_check (DisasContext *s); +bool sme_enabled_check (DisasContext *s);TCGv_i64 clean_data_tbi (DisasContext *s,TCGv_i64 addr);TCGv_i64 gen_mte_check1 (DisasContext *s,TCGv_i64 addr,bool is_write,bool tag_checked,int log2_size);
target/arm/translate-a64.c +15 -0
@@ -1216,6 +1216,21 @@ static bool sme_access_check(DisasContext *s)return true; } +/* Note that this function corresponds to CheckSMEEnabled. */ +bool sme_enabled_check (DisasContext *s) +{ +/* +* Note that unlike sve_excp_el, we have not constrained sme_excp_el +* to be zero when fp_excp_el has priority. This is because we need +* sme_excp_el by itself for cpregs access checks. +*/ +if (!s->fp_excp_el || s->sme_excp_el < s->fp_excp_el) { + s->fp_access_checked = true; +return sme_access_check (s); + } +return fp_access_check_only (s); +} +/* * This utility function is for doing register extension with an * optional shift. You will likely want to pass a temporary for the
target/arm/translate-sve.c +38 -0
@@ -1286,6 +1286,19 @@ static bool trans_ADDVL(DisasContext *s, arg_ADDVL *a)return true; } +static bool trans_ADDSVL (DisasContext *s,arg_ADDSVL *a) +{ +if (!dc_isar_feature (aa64_sme, s)) { +return false; + } +if (sme_enabled_check (s)) { +TCGv_i64 rd =cpu_reg_sp (s, a->rd); +TCGv_i64 rn =cpu_reg_sp (s, a->rn); +tcg_gen_addi_i64 (rd, rn, a->imm * s->svl); + } +return true; +} +static bool trans_ADDPL (DisasContext *s,arg_ADDPL *a) {if (!dc_isar_feature (aa64_sve, s)) {
@@ -1299,6 +1312,19 @@ static bool trans_ADDPL(DisasContext *s, arg_ADDPL *a)return true; } +static bool trans_ADDSPL (DisasContext *s,arg_ADDSPL *a) +{ +if (!dc_isar_feature (aa64_sme, s)) { +return false; + } +if (sme_enabled_check (s)) { +TCGv_i64 rd =cpu_reg_sp (s, a->rd); +TCGv_i64 rn =cpu_reg_sp (s, a->rn); +tcg_gen_addi_i64 (rd, rn, a->imm * (s->svl /8 )); + } +return true; +} +static bool trans_RDVL (DisasContext *s,arg_RDVL *a) {if (!dc_isar_feature (aa64_sve, s)) {
@@ -1311,6 +1337,18 @@ static bool trans_RDVL(DisasContext *s, arg_RDVL *a)return true; } +static bool trans_RDSVL (DisasContext *s,arg_RDSVL *a) +{ +if (!dc_isar_feature (aa64_sme, s)) { +return false; + } +if (sme_enabled_check (s)) { +TCGv_i64 reg =cpu_reg (s, a->rd); +tcg_gen_movi_i64 (reg, a->imm * s->svl); + } +return true; +} +/* *** SVE Compute Vector Address Group */
target/arm/sve.decode +4 -1
@@ -449,14 +449,17 @@ INDEX_ri 00000100 esz:2 1 imm:s5 010001 rn:5 rd:5 # SVE index generation (register start, register increment) INDEX_rr 00000100 .. 1 ..... 010011 ..... ..... @rd_rn_rm -### SVE Stack Allocation Group +### SVE / Streaming SVE Stack Allocation Group # SVE stack frame adjustment ADDVL 00000100 001 ..... 01010 ...... ..... @rd_rn_i6 +ADDSVL 00000100 001 ..... 01011 ...... ..... @rd_rn_i6 ADDPL 00000100 011 ..... 01010 ...... ..... @rd_rn_i6 +ADDSPL 00000100 011 ..... 01011 ...... ..... @rd_rn_i6 # SVE stack frame size RDVL 00000100 101 11111 01010 imm:s6 rd:5 +RDSVL 00000100 101 11111 01011 imm:s6 rd:5 ### SVE Bitwise Shift - Unpredicated Group
Signature · 1 line
2.34.1
PATCH v2 44/71 target/arm: Implement SME ZERO
In reply to Richard Henderson--- target/arm/helper-sme.h | 2 ++ target/arm/translate-a64.h | 1 + target/arm/sme_helper.c | 25 +++++++++++++++++++++++++ target/arm/translate-a64.c | 15 +++++++++++++++ target/arm/translate-sme.c | 13 +++++++++++++ target/arm/sme.decode | 4 ++++ 6 files changed, 60 insertions(+)
target/arm/helper-sme.h +2 -0
@@ -19,3 +19,5 @@ DEF_HELPER_FLAGS_2(set_pstate_sm, TCG_CALL_NO_RWG, void, env, i32) DEF_HELPER_FLAGS_2(set_pstate_za, TCG_CALL_NO_RWG, void, env, i32) + +DEF_HELPER_FLAGS_3 (sme_zero,TCG_CALL_NO_RWG , void, env, i32, i32)
target/arm/translate-a64.h +1 -0
@@ -30,6 +30,7 @@ bool logic_imm_decode_wmask(uint64_t *result, unsigned int immn, unsigned int imms, unsigned int immr);bool sve_access_check (DisasContext *s);bool sme_enabled_check (DisasContext *s); +bool sme_za_enabled_check (DisasContext *s);TCGv_i64 clean_data_tbi (DisasContext *s,TCGv_i64 addr);TCGv_i64 gen_mte_check1 (DisasContext *s,TCGv_i64 addr,bool is_write,bool tag_checked,int log2_size);
target/arm/sme_helper.c +25 -0
@@ -59,3 +59,28 @@ void helper_set_pstate_za(CPUARMState *env, uint32_t i)memset (env->zarray,0 ,sizeof (env->zarray)); } } + +void helper_sme_zero (CPUARMState *env,uint32_t imm,uint32_t svl) +{ +uint32_t i; + +/* +* Special case clearing the entire ZA space. +* This falls into the CONSTRAINED UNPREDICTABLE zeroing of any +* parts of the ZA storage outside of SVL. +*/ +if (imm ==0xff ) { +memset (env->zarray,0 ,sizeof (env->zarray)); +return ; + } + +/* +* Recall that ZAnH.D[m] is spread across ZA[n+8*m]. +* Unless SVL == ARM_MAX_VQ, each row is discontiguous. +*/ +for (i =0 ; i < svl; i++) { +if (imm & (1 << (i %8 ))) { +memset (&env->zarray[i],0 , svl); + } + } +}
target/arm/translate-a64.c +15 -0
@@ -1231,6 +1231,21 @@ bool sme_enabled_check(DisasContext *s)return fp_access_check_only (s); } +/* Note that this function corresponds to CheckSMEAndZAEnabled. */ +bool sme_za_enabled_check (DisasContext *s) +{ +if (!sme_enabled_check (s)) { +return false; + } +if (!s->pstate_za) { +gen_exception_insn (s, s->pc_curr,EXCP_UDEF , +syn_smetrap (SME_ET_InactiveZA, false), +default_exception_el (s)); +return false; + } +return true; +} +/* * This utility function is for doing register extension with an * optional shift. You will likely want to pass a temporary for the
target/arm/translate-sme.c +13 -0
@@ -33,3 +33,16 @@*/ #include "decode-sme.c.inc" + + +static bool trans_ZERO (DisasContext *s,arg_ZERO *a) +{ +if (!dc_isar_feature (aa64_sme, s)) { +return false; + } +if (sme_za_enabled_check (s)) { +gen_helper_sme_zero (cpu_env,tcg_constant_i32 (a->imm), +tcg_constant_i32 (s->svl)); + } +return true; +}
target/arm/sme.decode +4 -0
@@ -18,3 +18,7 @@ # # This file is processed by scripts/decodetree.py # + +### SME Misc + +ZERO 11000000 00 001 00000000000 imm:8
Signature · 1 line
2.34.1
PATCH v2 45/71 target/arm: Implement SME MOVA
In reply to Richard HendersonWe can reuse the SVE functions for implementing moves to/from horizontal tile slices, but we need new ones for moves to/from vertical tile slices.
--- target/arm/helper-sme.h | 11 ++++ target/arm/helper-sve.h | 2 + target/arm/translate-a64.h | 9 +++ target/arm/translate.h | 5 ++ target/arm/sme_helper.c | 110 ++++++++++++++++++++++++++++++++++++- target/arm/sve_helper.c | 12 ++++ target/arm/translate-a64.c | 21 +++++++ target/arm/translate-sme.c | 105 +++++++++++++++++++++++++++++++++++ target/arm/sme.decode | 15 +++++ 9 files changed, 289 insertions(+), 1 deletion(-)
target/arm/helper-sme.h +11 -0
@@ -21,3 +21,14 @@ DEF_HELPER_FLAGS_2(set_pstate_sm, TCG_CALL_NO_RWG, void, env, i32) DEF_HELPER_FLAGS_2(set_pstate_za, TCG_CALL_NO_RWG, void, env, i32) DEF_HELPER_FLAGS_3(sme_zero, TCG_CALL_NO_RWG, void, env, i32, i32) + +DEF_HELPER_FLAGS_4(sme_mova_avz_b, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(sme_mova_zav_b, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(sme_mova_avz_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(sme_mova_zav_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(sme_mova_avz_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(sme_mova_zav_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(sme_mova_avz_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(sme_mova_zav_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(sme_mova_avz_q, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4 (sme_mova_zav_q,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, i32)
target/arm/helper-sve.h +2 -0
@@ -325,6 +325,8 @@ DEF_HELPER_FLAGS_5(sve_sel_zpzz_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_5(sve_sel_zpzz_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5(sve_sel_zpzz_q, TCG_CALL_NO_RWG, + void, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_5(sve2_addp_zpzz_b, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32)
target/arm/translate-a64.h +9 -0
@@ -31,6 +31,7 @@ bool logic_imm_decode_wmask(uint64_t *result, unsigned int immn,bool sve_access_check (DisasContext *s);bool sme_enabled_check (DisasContext *s);bool sme_za_enabled_check (DisasContext *s); +bool sme_smza_enabled_check (DisasContext *s);TCGv_i64 clean_data_tbi (DisasContext *s,TCGv_i64 addr);TCGv_i64 gen_mte_check1 (DisasContext *s,TCGv_i64 addr,bool is_write,bool tag_checked,int log2_size);
@@ -147,6 +148,14 @@ static inline int pred_gvec_reg_size(DisasContext *s)return size_for_gvec (pred_full_reg_size (s)); } +/* Return a newly allocated pointer to the predicate register. */ +static inline TCGv_ptr pred_full_reg_ptr (DisasContext *s,int regno) +{ +TCGv_ptr ret =tcg_temp_new_ptr (); +tcg_gen_addi_ptr (ret, cpu_env,pred_full_reg_offset (s, regno)); +return ret; +} +bool disas_sve (DisasContext *,uint32_t );bool disas_sme (DisasContext *,uint32_t );
target/arm/translate.h +5 -0
@@ -159,6 +159,11 @@ static inline int plus_2(DisasContext *s, int x)return x +2 ; } +static inline int plus_12 (DisasContext *s,int x) +{ +return x +12 ; +} +static inline int times_2 (DisasContext *s,int x) {return x *2 ;
target/arm/sme_helper.c +109 -1
120 lines not on this page · raw message
target/arm/sve_helper.c +12 -0
@@ -3565,6 +3565,18 @@ void HELPER(sve_sel_zpzz_d)(void *vd, void *vn, void *vm, } } +void HELPER (sve_sel_zpzz_q )(void *vd,void *vn,void *vm, +void *vg,uint32_t desc) +{ +intptr_t i, opr_sz =simd_oprsz (desc) /16 ; +Int128 *d = vd, *n = vn, *m = vm; +uint16_t *pg = vg; + +for (i =0 ; i < opr_sz; i +=1 ) { + d[i] = (pg[H2 (i)] &1 ? n : m)[i]; + } +} +/* Two operand comparison controlled by a predicate. * ??? It is very tempting to want to be able to expand this inline * with x86 instructions, e.g.
target/arm/translate-a64.c +21 -0
@@ -1246,6 +1246,27 @@ bool sme_za_enabled_check(DisasContext *s)return true; } +/* Note that this function corresponds to CheckStreamingSVEAndZAEnabled. */ +bool sme_smza_enabled_check (DisasContext *s) +{ +if (!sme_enabled_check (s)) { +return false; + } +if (!s->pstate_sm) { +gen_exception_insn (s, s->pc_curr,EXCP_UDEF , +syn_smetrap (SME_ET_NotStreaming, false), +default_exception_el (s)); +return false; + } +if (!s->pstate_za) { +gen_exception_insn (s, s->pc_curr,EXCP_UDEF , +syn_smetrap (SME_ET_InactiveZA, false), +default_exception_el (s)); +return false; + } +return true; +} +/* * This utility function is for doing register extension with an * optional shift. You will likely want to pass a temporary for the
target/arm/translate-sme.c +105 -0
114 lines not on this page · raw message
target/arm/sme.decode +15 -0
@@ -22,3 +22,18 @@ ### SME Misc ZERO 11000000 00 001 00000000000 imm:8 + +### SME Move into/from Array + +%mova_rs 13:2 !function=plus_12 +&mova esz rs pg zr za_imm v:bool to_vec:bool + +MOVA 11000000 esz:2 00000 0 v:1 .. pg:3 zr:5 0 za_imm:4 \ + &mova to_vec=0 rs=%mova_rs +MOVA 11000000 11 00000 1 v:1 .. pg:3 zr:5 0 za_imm:4 \ + &mova to_vec=0 rs=%mova_rs esz=4 + +MOVA 11000000 esz:2 00001 0 v:1 .. pg:3 0 za_imm:4 zr:5 \ + &mova to_vec=1 rs=%mova_rs +MOVA 11000000 11 00001 1 v:1 .. pg:3 0 za_imm:4 zr:5 \ + &mova to_vec=1 rs=%mova_rs esz=4
Signature · 1 line
2.34.1
PATCH v2 46/71 target/arm: Implement SME LD1, ST1
In reply to Richard HendersonWe cannot reuse the SVE functions for LD[1-4] and ST[1-4], because those functions accept only a Zreg register number. For SME, we want to pass a pointer into ZA storage.
--- target/arm/helper-sme.h | 82 +++++ target/arm/sme_helper.c | 615 +++++++++++++++++++++++++++++++++++++ target/arm/translate-sme.c | 69 +++++ target/arm/sme.decode | 9 + 4 files changed, 775 insertions(+)
target/arm/helper-sme.h +82 -0
@@ -32,3 +32,85 @@ DEF_HELPER_FLAGS_4(sme_mova_avz_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_4(sme_mova_zav_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_4(sme_mova_avz_q, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_4(sme_mova_zav_q, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) + +DEF_HELPER_FLAGS_5(sme_ld1b_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1b_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1b_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1b_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) + +DEF_HELPER_FLAGS_5(sme_ld1h_be_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1h_le_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1h_be_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1h_le_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1h_be_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1h_le_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1h_be_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1h_le_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) + +DEF_HELPER_FLAGS_5(sme_ld1s_be_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1s_le_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1s_be_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1s_le_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1s_be_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1s_le_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1s_be_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1s_le_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) + +DEF_HELPER_FLAGS_5(sme_ld1d_be_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1d_le_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1d_be_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1d_le_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1d_be_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1d_le_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1d_be_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1d_le_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) + +DEF_HELPER_FLAGS_5(sme_ld1q_be_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1q_le_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1q_be_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1q_le_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1q_be_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1q_le_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1q_be_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_ld1q_le_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) + +DEF_HELPER_FLAGS_5(sme_st1b_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1b_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1b_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1b_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) + +DEF_HELPER_FLAGS_5(sme_st1h_be_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1h_le_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1h_be_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1h_le_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1h_be_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1h_le_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1h_be_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1h_le_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) + +DEF_HELPER_FLAGS_5(sme_st1s_be_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1s_le_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1s_be_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1s_le_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1s_be_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1s_le_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1s_be_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1s_le_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) + +DEF_HELPER_FLAGS_5(sme_st1d_be_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1d_le_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1d_be_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1d_le_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1d_be_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1d_le_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1d_be_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1d_le_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) + +DEF_HELPER_FLAGS_5(sme_st1q_be_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1q_le_h, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1q_be_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1q_le_v, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1q_be_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1q_le_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5(sme_st1q_be_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) +DEF_HELPER_FLAGS_5 (sme_st1q_le_v_mte,TCG_CALL_NO_WG , void, env, ptr, ptr, tl, i32)
target/arm/sme_helper.c +615 -0
628 lines not on this page · raw message
target/arm/translate-sme.c +69 -0
72 lines not on this page · raw message
target/arm/sme.decode +9 -0
@@ -37,3 +37,12 @@ MOVA 11000000 esz:2 00001 0 v:1 .. pg:3 0 za_imm:4 zr:5 \ &mova to_vec=1 rs=%mova_rs MOVA 11000000 11 00001 1 v:1 .. pg:3 0 za_imm:4 zr:5 \ &mova to_vec=1 rs=%mova_rs esz=4 + +### SME Memory + +&ldst esz rs pg rn rm za_imm v:bool st:bool + +LDST1 1110000 0 esz:2 st:1 rm:5 v:1 .. pg:3 rn:5 0 za_imm:4 \ + &ldst rs=%mova_rs +LDST1 1110000 111 st:1 rm:5 v:1 .. pg:3 rn:5 0 za_imm:4 \ + &ldst esz=4 rs=%mova_rs
Signature · 1 line
2.34.1
PATCH v2 47/71 target/arm: Export unpredicated ld/st from translate-sve.c
In reply to Richard HendersonAdd a TCGv_ptr base argument, which will be cpu_env for SVE. We will reuse this for SME save and restore array insns.
--- target/arm/translate-a64.h | 3 +++ target/arm/translate-sve.c | 48 ++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 12 deletions(-)
target/arm/translate-a64.h +3 -0
@@ -165,4 +165,7 @@ void gen_gvec_xar(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs, uint32_t rm_ofs, int64_t shift, uint32_t opr_sz, uint32_t max_sz); +void gen_sve_ldr (DisasContext *s,TCGv_ptr ,int vofs,int len,int rn,int imm); +void gen_sve_str (DisasContext *s,TCGv_ptr ,int vofs,int len,int rn,int imm); +#endif /* TARGET_ARM_TRANSLATE_A64_H */
target/arm/translate-sve.c +36 -12
140 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 48/71 target/arm: Implement SME LDR, STR
In reply to Richard HendersonWe can reuse the SVE functions for LDR and STR, passing in the base of the ZA vector and a zero offset.
--- target/arm/translate-sme.c | 23 +++++++++++++++++++++++ target/arm/sme.decode | 7 +++++++ 2 files changed, 30 insertions(+)
target/arm/translate-sme.c +23 -0
@@ -220,3 +220,26 @@ static bool trans_LDST1(DisasContext *s, arg_LDST1 *a)tcg_temp_free_i64 (addr);return true; } + +typedef void GenLdStR (DisasContext *,TCGv_ptr ,int ,int ,int ,int ); + +static bool do_ldst_r (DisasContext *s,arg_ldstr *a,GenLdStR *fn) +{ +int imm = a->imm; +TCGv_ptr base; + +if (!sme_za_enabled_check (s)) { +return true; + } + +/* ZA[n] equates to ZA0H.B[n]. */ + base =get_tile_rowcol (s,MO_8 , a->rv, imm, false); + +fn (s, base,0 , s->svl, a->rn, imm * s->svl); + +tcg_temp_free_ptr (base); +return true; +} + +TRANS_FEAT(LDR, aa64_sme, do_ldst_r, a, gen_sve_ldr) +TRANS_FEAT (STR , aa64_sme, do_ldst_r, a, gen_sve_str)
target/arm/sme.decode +7 -0
@@ -46,3 +46,10 @@ LDST1 1110000 0 esz:2 st:1 rm:5 v:1 .. pg:3 rn:5 0 za_imm:4 \ &ldst rs=%mova_rs LDST1 1110000 111 st:1 rm:5 v:1 .. pg:3 rn:5 0 za_imm:4 \ &ldst esz=4 rs=%mova_rs + +&ldstr rv rn imm +@ldstr ....... ... . ...... .. ... rn:5 . imm:4 \ + &ldstr rv=%mova_rs + +LDR 1110000 100 0 000000 .. 000 ..... 0 .... @ldstr +STR 1110000 100 1 000000 .. 000 ..... 0 .... @ldstr
Signature · 1 line
2.34.1
PATCH v2 49/71 target/arm: Implement SME ADDHA, ADDVA
In reply to Richard Henderson--- target/arm/helper-sme.h | 5 +++ target/arm/sme_helper.c | 90 ++++++++++++++++++++++++++++++++++++++ target/arm/translate-sme.c | 30 +++++++++++++ target/arm/sme.decode | 11 +++++ 4 files changed, 136 insertions(+)
target/arm/helper-sme.h +5 -0
@@ -114,3 +114,8 @@ DEF_HELPER_FLAGS_5(sme_st1q_be_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i DEF_HELPER_FLAGS_5(sme_st1q_le_h_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) DEF_HELPER_FLAGS_5(sme_st1q_be_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) DEF_HELPER_FLAGS_5(sme_st1q_le_v_mte, TCG_CALL_NO_WG, void, env, ptr, ptr, tl, i32) + +DEF_HELPER_FLAGS_5(sme_addha_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5(sme_addva_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5(sme_addha_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5 (sme_addva_d,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, i32)
target/arm/sme_helper.c +90 -0
93 lines not on this page · raw message
target/arm/translate-sme.c +30 -0
@@ -243,3 +243,33 @@ static bool do_ldst_r(DisasContext *s, arg_ldstr *a, GenLdStR *fn) TRANS_FEAT(LDR, aa64_sme, do_ldst_r, a, gen_sve_ldr) TRANS_FEAT(STR, aa64_sme, do_ldst_r, a, gen_sve_str) + +static bool do_adda (DisasContext *s,arg_adda *a,MemOp esz, +gen_helper_gvec_4 *fn) +{ +uint32_t desc =simd_desc (s->svl, s->svl,0 ); +TCGv_ptr za, zn, pn, pm; + +if (!sme_smza_enabled_check (s)) { +return true; + } + +/* Sum XZR+zad to find ZAd. */ + za =get_tile_rowcol (s, esz,31 , a->zad, false); + zn =vec_full_reg_ptr (s, a->zn); + pn =pred_full_reg_ptr (s, a->pn); + pm =pred_full_reg_ptr (s, a->pm); + +fn (za, zn, pn, pm,tcg_constant_i32 (desc)); + +tcg_temp_free_ptr (za); +tcg_temp_free_ptr (zn); +tcg_temp_free_ptr (pn); +tcg_temp_free_ptr (pm); +return true; +} + +TRANS_FEAT(ADDHA_s, aa64_sme, do_adda, a, MO_32, gen_helper_sme_addha_s) +TRANS_FEAT(ADDVA_s, aa64_sme, do_adda, a, MO_32, gen_helper_sme_addva_s) +TRANS_FEAT(ADDHA_d, aa64_sme_i16i64, do_adda, a, MO_64, gen_helper_sme_addha_d) +TRANS_FEAT (ADDVA_d, aa64_sme_i16i64, do_adda, a,MO_64 , gen_helper_sme_addva_d)
target/arm/sme.decode +11 -0
@@ -53,3 +53,14 @@ LDST1 1110000 111 st:1 rm:5 v:1 .. pg:3 rn:5 0 za_imm:4 \ LDR 1110000 100 0 000000 .. 000 ..... 0 .... @ldstr STR 1110000 100 1 000000 .. 000 ..... 0 .... @ldstr + +### SME Add Vector to Array + +&adda zad zn pm pn +@adda_32 ........ .. ..... . pm:3 pn:3 zn:5 ... zad:2 &adda +@adda_64 ........ .. ..... . pm:3 pn:3 zn:5 .. zad:3 &adda + +ADDHA_s 11000000 10 01000 0 ... ... ..... 000 .. @adda_32 +ADDVA_s 11000000 10 01000 1 ... ... ..... 000 .. @adda_32 +ADDHA_d 11000000 11 01000 0 ... ... ..... 00 ... @adda_64 +ADDVA_d 11000000 11 01000 1 ... ... ..... 00 ... @adda_64
Signature · 1 line
2.34.1
PATCH v2 50/71 target/arm: Implement FMOPA, FMOPS (non-widening)
In reply to Richard Henderson--- target/arm/helper-sme.h | 5 +++ target/arm/sme_helper.c | 67 ++++++++++++++++++++++++++++++++++++++ target/arm/translate-sme.c | 33 +++++++++++++++++++ target/arm/sme.decode | 9 +++++ 4 files changed, 114 insertions(+)
target/arm/helper-sme.h +5 -0
@@ -119,3 +119,8 @@ DEF_HELPER_FLAGS_5(sme_addha_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_5(sme_addva_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_5(sme_addha_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_5(sme_addva_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) + +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)
target/arm/sme_helper.c +67 -0
76 lines not on this page · raw message
target/arm/translate-sme.c +33 -0
@@ -273,3 +273,36 @@ TRANS_FEAT(ADDHA_s, aa64_sme, do_adda, a, MO_32, gen_helper_sme_addha_s) TRANS_FEAT(ADDVA_s, aa64_sme, do_adda, a, MO_32, gen_helper_sme_addva_s) TRANS_FEAT(ADDHA_d, aa64_sme_i16i64, do_adda, a, MO_64, gen_helper_sme_addha_d) TRANS_FEAT(ADDVA_d, aa64_sme_i16i64, do_adda, a, MO_64, gen_helper_sme_addva_d) + +static bool do_outprod_fpst (DisasContext *s,arg_op *a,MemOp esz, +gen_helper_gvec_5_ptr *fn) +{ +uint32_t desc =simd_desc (s->svl, s->svl, a->sub); +TCGv_ptr za, zn, zm, pn, pm, fpst; + +if (!sme_smza_enabled_check (s)) { +return true; + } + +/* Sum XZR+zad to find ZAd. */ + za =get_tile_rowcol (s, esz,31 , a->zad, false); + zn =vec_full_reg_ptr (s, a->zn); + zm =vec_full_reg_ptr (s, a->zm); + pn =pred_full_reg_ptr (s, a->pn); + pm =pred_full_reg_ptr (s, a->pm); + fpst =fpstatus_ptr (FPST_FPCR ); + +fn (za, zn, zm, pn, pm, fpst,tcg_constant_i32 (desc)); + +tcg_temp_free_ptr (za); +tcg_temp_free_ptr (zn); +tcg_temp_free_ptr (pn); +tcg_temp_free_ptr (pm); +tcg_temp_free_ptr (fpst); +return true; +} + +TRANS_FEAT (FMOPA_s, aa64_sme, do_outprod_fpst, + a, MO_32, gen_helper_sme_fmopa_s) +TRANS_FEAT (FMOPA_d, aa64_sme_f64f64, do_outprod_fpst, + a,MO_64 , gen_helper_sme_fmopa_d)
target/arm/sme.decode +9 -0
@@ -64,3 +64,12 @@ ADDHA_s 11000000 10 01000 0 ... ... ..... 000 .. @adda_32 ADDVA_s 11000000 10 01000 1 ... ... ..... 000 .. @adda_32 ADDHA_d 11000000 11 01000 0 ... ... ..... 00 ... @adda_64 ADDVA_d 11000000 11 01000 1 ... ... ..... 00 ... @adda_64 + +### SME Outer Product + +&op zad zn zm pm pn sub:bool +@op_32 ........ ... zm:5 pm:3 pn:3 zn:5 sub:1 .. zad:2 &op +@op_64 ........ ... zm:5 pm:3 pn:3 zn:5 sub:1 . zad:3 &op + +FMOPA_s 10000000 100 ..... ... ... ..... . 00 .. @op_32 +FMOPA_d 10000000 110 ..... ... ... ..... . 0 ... @op_64
Signature · 1 line
2.34.1
PATCH v2 51/71 target/arm: Implement BFMOPA, BFMOPS
In reply to Richard Henderson--- target/arm/helper-sme.h | 2 ++ target/arm/sme_helper.c | 52 ++++++++++++++++++++++++++++++++++++++ target/arm/translate-sme.c | 29 +++++++++++++++++++++ target/arm/sme.decode | 2 ++ 4 files changed, 85 insertions(+)
target/arm/helper-sme.h +2 -0
@@ -124,3 +124,5 @@ 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)
target/arm/sme_helper.c +52 -0
55 lines not on this page · raw message
target/arm/translate-sme.c +29 -0
@@ -274,6 +274,32 @@ TRANS_FEAT(ADDVA_s, aa64_sme, do_adda, a, MO_32, gen_helper_sme_addva_s) TRANS_FEAT(ADDHA_d, aa64_sme_i16i64, do_adda, a, MO_64, gen_helper_sme_addha_d) TRANS_FEAT(ADDVA_d, aa64_sme_i16i64, do_adda, a, MO_64, gen_helper_sme_addva_d) +static bool do_outprod (DisasContext *s,arg_op *a,MemOp esz, +gen_helper_gvec_5 *fn) +{ +uint32_t desc =simd_desc (s->svl, s->svl, a->sub); +TCGv_ptr za, zn, zm, pn, pm; + +if (!sme_smza_enabled_check (s)) { +return true; + } + +/* Sum XZR+zad to find ZAd. */ + za =get_tile_rowcol (s, esz,31 , a->zad, false); + zn =vec_full_reg_ptr (s, a->zn); + zm =vec_full_reg_ptr (s, a->zm); + pn =pred_full_reg_ptr (s, a->pn); + pm =pred_full_reg_ptr (s, a->pm); + +fn (za, zn, zm, pn, pm,tcg_constant_i32 (desc)); + +tcg_temp_free_ptr (za); +tcg_temp_free_ptr (zn); +tcg_temp_free_ptr (pn); +tcg_temp_free_ptr (pm); +return true; +} +static bool do_outprod_fpst (DisasContext *s,arg_op *a,MemOp esz,gen_helper_gvec_5_ptr *fn) {
@@ -306,3 +332,6 @@ TRANS_FEAT(FMOPA_s, aa64_sme, do_outprod_fpst, a, MO_32, gen_helper_sme_fmopa_s) TRANS_FEAT(FMOPA_d, aa64_sme_f64f64, do_outprod_fpst, a, MO_64, gen_helper_sme_fmopa_d) + +/* TODO: FEAT_EBF16 */ +TRANS_FEAT (BFMOPA , aa64_sme, do_outprod, a,MO_32 , gen_helper_sme_bfmopa)
target/arm/sme.decode +2 -0
@@ -73,3 +73,5 @@ ADDVA_d 11000000 11 01000 1 ... ... ..... 00 ... @adda_64 FMOPA_s 10000000 100 ..... ... ... ..... . 00 .. @op_32 FMOPA_d 10000000 110 ..... ... ... ..... . 0 ... @op_64 + +BFMOPA 10000001 100 ..... ... ... ..... . 00 .. @op_32
Signature · 1 line
2.34.1
PATCH v2 52/71 target/arm: Implement FMOPA, FMOPS (widening)
In reply to Richard Henderson--- target/arm/helper-sme.h | 2 ++ target/arm/sme_helper.c | 74 ++++++++++++++++++++++++++++++++++++++ target/arm/translate-sme.c | 2 ++ target/arm/sme.decode | 1 + 4 files changed, 79 insertions(+)
target/arm/helper-sme.h +2 -0
@@ -120,6 +120,8 @@ DEF_HELPER_FLAGS_5(sme_addva_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_5(sme_addha_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_5(sme_addva_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_7 (sme_fmopa_h,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, ptr, ptr, i32)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,
target/arm/sme_helper.c +74 -0
80 lines not on this page · raw message
target/arm/translate-sme.c +2 -0
@@ -328,6 +328,8 @@ static bool do_outprod_fpst(DisasContext *s, arg_op *a, MemOp esz,return true; } +TRANS_FEAT (FMOPA_h, aa64_sme, do_outprod_fpst, + a, MO_32, gen_helper_sme_fmopa_h)TRANS_FEAT (FMOPA_s, aa64_sme, do_outprod_fpst, a, MO_32, gen_helper_sme_fmopa_s) TRANS_FEAT(FMOPA_d, aa64_sme_f64f64, do_outprod_fpst,
target/arm/sme.decode +1 -0
@@ -75,3 +75,4 @@ FMOPA_s 10000000 100 ..... ... ... ..... . 00 .. @op_32 FMOPA_d 10000000 110 ..... ... ... ..... . 0 ... @op_64 BFMOPA 10000001 100 ..... ... ... ..... . 00 .. @op_32 +FMOPA_h 10000001 101 ..... ... ... ..... . 00 .. @op_32
Signature · 1 line
2.34.1
PATCH v2 53/71 target/arm: Implement SME integer outer product
In reply to Richard HendersonThis is SMOPA, SUMOPA, USMOPA_s, UMOPA, for both Int8 and Int16.
--- target/arm/helper-sme.h | 16 ++++++++ target/arm/sme_helper.c | 82 ++++++++++++++++++++++++++++++++++++++ target/arm/translate-sme.c | 14 +++++++ target/arm/sme.decode | 10 +++++ 4 files changed, 122 insertions(+)
target/arm/helper-sme.h +16 -0
@@ -128,3 +128,19 @@ 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_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, + void, ptr, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_6(sme_sumopa_s, TCG_CALL_NO_RWG, + void, ptr, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_6(sme_usmopa_s, TCG_CALL_NO_RWG, + void, ptr, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_6(sme_smopa_d, TCG_CALL_NO_RWG, + void, ptr, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_6(sme_umopa_d, TCG_CALL_NO_RWG, + void, ptr, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_6(sme_sumopa_d, TCG_CALL_NO_RWG, + void, ptr, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_6(sme_usmopa_d, TCG_CALL_NO_RWG, + void, ptr, ptr, ptr, ptr, ptr, i32)
target/arm/sme_helper.c +82 -0
85 lines not on this page · raw message
target/arm/translate-sme.c +14 -0
@@ -337,3 +337,17 @@ TRANS_FEAT(FMOPA_d, aa64_sme_f64f64, do_outprod_fpst,/* TODO: FEAT_EBF16 */ TRANS_FEAT(BFMOPA, aa64_sme, do_outprod, 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) +TRANS_FEAT(SUMOPA_s, aa64_sme, do_outprod, a, MO_32, gen_helper_sme_sumopa_s) +TRANS_FEAT(USMOPA_s, aa64_sme, do_outprod, a, MO_32, gen_helper_sme_usmopa_s) + +TRANS_FEAT (SMOPA_d, aa64_sme_i16i64, do_outprod, + a, MO_64, gen_helper_sme_smopa_d) +TRANS_FEAT (UMOPA_d, aa64_sme_i16i64, do_outprod, + a, MO_64, gen_helper_sme_umopa_d) +TRANS_FEAT (SUMOPA_d, aa64_sme_i16i64, do_outprod, + a, MO_64, gen_helper_sme_sumopa_d) +TRANS_FEAT (USMOPA_d, aa64_sme_i16i64, do_outprod, + a,MO_64 , gen_helper_sme_usmopa_d)
target/arm/sme.decode +10 -0
@@ -76,3 +76,13 @@ FMOPA_d 10000000 110 ..... ... ... ..... . 0 ... @op_64 BFMOPA 10000001 100 ..... ... ... ..... . 00 .. @op_32 FMOPA_h 10000001 101 ..... ... ... ..... . 00 .. @op_32 + +SMOPA_s 1010000 0 10 0 ..... ... ... ..... . 00 .. @op_32 +SUMOPA_s 1010000 0 10 1 ..... ... ... ..... . 00 .. @op_32 +USMOPA_s 1010000 1 10 0 ..... ... ... ..... . 00 .. @op_32 +UMOPA_s 1010000 1 10 1 ..... ... ... ..... . 00 .. @op_32 + +SMOPA_d 1010000 0 11 0 ..... ... ... ..... . 0 ... @op_64 +SUMOPA_d 1010000 0 11 1 ..... ... ... ..... . 0 ... @op_64 +USMOPA_d 1010000 1 11 0 ..... ... ... ..... . 0 ... @op_64 +UMOPA_d 1010000 1 11 1 ..... ... ... ..... . 0 ... @op_64
Signature · 1 line
2.34.1
PATCH v2 54/71 target/arm: Implement PSEL
In reply to Richard Henderson--- target/arm/translate-sve.c | 57 ++++++++++++++++++++++++++++++++++++++ target/arm/sve.decode | 20 +++++++++++++ 2 files changed, 77 insertions(+)
target/arm/translate-sve.c +57 -0
@@ -7379,3 +7379,60 @@ static bool do_BFMLAL_zzxw(DisasContext *s, arg_rrxr_esz *a, bool sel) TRANS_FEAT(BFMLALB_zzxw, aa64_sve_bf16, do_BFMLAL_zzxw, a, false) TRANS_FEAT(BFMLALT_zzxw, aa64_sve_bf16, do_BFMLAL_zzxw, a, true) + +static bool trans_PSEL (DisasContext *s,arg_psel *a) +{ +int vl =vec_full_reg_size (s); +int pl =pred_gvec_reg_size (s); +int elements = vl >> a->esz; +TCGv_i64 tmp, didx, dbit; +TCGv_ptr ptr; + +if (!dc_isar_feature (aa64_sme, s)) { +return false; + } +if (!sve_access_check (s)) { +return true; + } + + tmp =tcg_temp_new_i64 (); + dbit =tcg_temp_new_i64 (); + didx =tcg_temp_new_i64 (); + ptr =tcg_temp_new_ptr (); + +/* Compute the predicate element. */ +tcg_gen_addi_i64 (tmp,cpu_reg (s, a->rv), a->imm); +if (is_power_of_2 (elements)) { +tcg_gen_andi_i64 (tmp, tmp, elements -1 ); + }else { +tcg_gen_remu_i64 (tmp, tmp,tcg_constant_i64 (elements)); + } + +/* Extract the predicate byte and bit indices. */ +tcg_gen_shli_i64 (tmp, tmp, a->esz); +tcg_gen_andi_i64 (dbit, tmp,7 ); +tcg_gen_shri_i64 (didx, tmp,3 ); +if (HOST_BIG_ENDIAN ) { +tcg_gen_xori_i64 (didx, didx,7 ); + } + +/* Load the predicate word. */ +tcg_gen_trunc_i64_ptr (ptr, didx); +tcg_gen_add_ptr (ptr, ptr, cpu_env); +tcg_gen_ld8u_i64 (tmp, ptr,pred_full_reg_offset (s, a->pm)); + +/* Extract the predicate bit and replicate to MO_64. */ +tcg_gen_shr_i64 (tmp, tmp, dbit); +tcg_gen_andi_i64 (tmp, tmp,1 ); +tcg_gen_neg_i64 (tmp, tmp); + +/* Apply to either copy the source, or write zeros. */ +tcg_gen_gvec_ands (MO_64 ,pred_full_reg_offset (s, a->pd), +pred_full_reg_offset (s, a->pn), tmp, pl, pl); + +tcg_temp_free_i64 (tmp); +tcg_temp_free_i64 (dbit); +tcg_temp_free_i64 (didx); +tcg_temp_free_ptr (ptr); +return true; +}
target/arm/sve.decode +20 -0
@@ -1674,3 +1674,23 @@ BFMLALT_zzxw 01100100 11 1 ..... 0100.1 ..... ..... @rrxr_3a esz=2 ### SVE2 floating-point bfloat16 dot-product (indexed) BFDOT_zzxz 01100100 01 1 ..... 010000 ..... ..... @rrxr_2 esz=2 + +### SVE broadcast predicate element + +&psel esz pd pn pm rv imm +%psel_rv 16:2 !function=plus_12 +%psel_imm_b 22:2 19:2 +%psel_imm_h 22:2 20:1 +%psel_imm_s 22:2 +%psel_imm_d 23:1 +@psel ........ .. . ... .. .. pn:4 . pm:4 . pd:4 \ + &psel rv=%psel_rv + +PSEL 00100101 .. 1 ..1 .. 01 .... 0 .... 0 .... \ + @psel esz=0 imm=%psel_imm_b +PSEL 00100101 .. 1 .10 .. 01 .... 0 .... 0 .... \ + @psel esz=1 imm=%psel_imm_h +PSEL 00100101 .. 1 100 .. 01 .... 0 .... 0 .... \ + @psel esz=2 imm=%psel_imm_s +PSEL 00100101 .1 1 000 .. 01 .... 0 .... 0 .... \ + @psel esz=3 imm=%psel_imm_d
Signature · 1 line
2.34.1
PATCH v2 55/71 target/arm: Implement REVD
In reply to Richard Henderson--- target/arm/helper-sve.h | 2 ++ target/arm/sve_helper.c | 16 ++++++++++++++++ target/arm/translate-sve.c | 2 ++ target/arm/sve.decode | 1 + 4 files changed, 21 insertions(+)
target/arm/helper-sve.h +2 -0
@@ -719,6 +719,8 @@ DEF_HELPER_FLAGS_4(sve_revh_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_4(sve_revw_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(sme_revd_q, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) + DEF_HELPER_FLAGS_4(sve_rbit_b, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_4(sve_rbit_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)DEF_HELPER_FLAGS_4 (sve_rbit_s,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, i32)
target/arm/sve_helper.c +16 -0
@@ -931,6 +931,22 @@ DO_ZPZ_D(sve_revh_d, uint64_t, hswap64) DO_ZPZ_D(sve_revw_d, uint64_t, wswap64) +void HELPER (sme_revd_q )(void *vd,void *vn,void *vg,uint32_t desc) +{ +intptr_t i, opr_sz =simd_oprsz (desc) /8 ; +uint64_t *d = vd, *n = vn; +uint8_t *pg = vg; + +for (i =0 ; i < opr_sz; i +=2 ) { +if (pg[H1 (i)] &1 ) { +uint64_t n0 = n[i +0 ]; +uint64_t n1 = n[i +1 ]; + d[i +0 ] = n1; + d[i +1 ] = n0; + } + } +} + DO_ZPZ(sve_rbit_b, uint8_t, H1, revbit8) DO_ZPZ(sve_rbit_h, uint16_t, H1_2, revbit16)DO_ZPZ (sve_rbit_s, uint32_t,H1_4 , revbit32)
target/arm/translate-sve.c +2 -0
@@ -2896,6 +2896,8 @@ TRANS_FEAT(REVH, aa64_sve, gen_gvec_ool_arg_zpz, revh_fns[a->esz], a, 0)TRANS_FEAT (REVW , aa64_sve, gen_gvec_ool_arg_zpz, a->esz == 3 ? gen_helper_sve_revw_d : NULL, a, 0) +TRANS_FEAT(REVD, aa64_sme, gen_gvec_ool_arg_zpz, gen_helper_sme_revd_q, a, 0) +TRANS_FEAT (SPLICE , aa64_sve, gen_gvec_ool_arg_zpzz, gen_helper_sve_splice, a, a->esz)
target/arm/sve.decode +1 -0
@@ -652,6 +652,7 @@ REVB 00000101 .. 1001 00 100 ... ..... ..... @rd_pg_rn REVH 00000101 .. 1001 01 100 ... ..... ..... @rd_pg_rn REVW 00000101 .. 1001 10 100 ... ..... ..... @rd_pg_rn RBIT 00000101 .. 1001 11 100 ... ..... ..... @rd_pg_rn +REVD 00000101 00 1011 10 100 ... ..... ..... @rd_pg_rn_e0 # SVE vector splice (predicated, destructive) SPLICE 00000101 .. 101 100 100 ... ..... ..... @rdn_pg_rm
Signature · 1 line
2.34.1
PATCH v2 56/71 target/arm: Implement SCLAMP, UCLAMP
In reply to Richard Henderson--- target/arm/helper.h | 18 +++++++ target/arm/translate-sve.c | 102 +++++++++++++++++++++++++++++++++++++ target/arm/vec_helper.c | 24 +++++++++ target/arm/sve.decode | 5 ++ 4 files changed, 149 insertions(+)
target/arm/helper.h +18 -0
@@ -1017,6 +1017,24 @@ DEF_HELPER_FLAGS_6(gvec_bfmlal, TCG_CALL_NO_RWG,DEF_HELPER_FLAGS_6 (gvec_bfmlal_idx,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5 (gvec_sclamp_b,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5 (gvec_sclamp_h,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5 (gvec_sclamp_s,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5 (gvec_sclamp_d,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, i32) + +DEF_HELPER_FLAGS_5 (gvec_uclamp_b,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5 (gvec_uclamp_h,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5 (gvec_uclamp_s,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5 (gvec_uclamp_d,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, i32) +#ifdef TARGET_AARCH64 #include "helper-a64.h" #include "helper-sve.h"
target/arm/translate-sve.c +102 -0
105 lines not on this page · raw message
target/arm/vec_helper.c +24 -0
@@ -2690,3 +2690,27 @@ void HELPER(gvec_bfmlal_idx)(void *vd, void *vn, void *vm, }clear_tail (d, opr_sz,simd_maxsz (desc)); } + +#define DO_CLAMP (NAME ,TYPE ) \ +void HELPER(NAME)(void *d, void *n, void *m, void *a, uint32_t desc) \ +{ \ + intptr_t i, opr_sz = simd_oprsz(desc); \ + for (i = 0; i < opr_sz; i += sizeof(TYPE)) { \ + TYPE aa = *(TYPE *)(a + i); \ + TYPE nn = *(TYPE *)(n + i); \ + TYPE mm = *(TYPE *)(m + i); \ + TYPE dd = MIN(MAX(aa, nn), mm); \ + *(TYPE *)(d + i) = dd; \ + } \ + clear_tail(d, opr_sz, simd_maxsz(desc)); \ +} + +DO_CLAMP(gvec_sclamp_b, int8_t) +DO_CLAMP(gvec_sclamp_h, int16_t) +DO_CLAMP(gvec_sclamp_s, int32_t) +DO_CLAMP(gvec_sclamp_d, int64_t) + +DO_CLAMP(gvec_uclamp_b, uint8_t) +DO_CLAMP(gvec_uclamp_h, uint16_t) +DO_CLAMP(gvec_uclamp_s, uint32_t) +DO_CLAMP (gvec_uclamp_d, uint64_t)
target/arm/sve.decode +5 -0
@@ -1695,3 +1695,8 @@ PSEL 00100101 .. 1 100 .. 01 .... 0 .... 0 .... \ @psel esz=2 imm=%psel_imm_s PSEL 00100101 .1 1 000 .. 01 .... 0 .... 0 .... \ @psel esz=3 imm=%psel_imm_d + +### SVE clamp + +SCLAMP 01000100 .. 0 ..... 110000 ..... ..... @rda_rn_rm +UCLAMP 01000100 .. 0 ..... 110001 ..... ..... @rda_rn_rm
Signature · 1 line
2.34.1
PATCH v2 57/71 target/arm: Reset streaming sve state on exception boundaries
In reply to Richard HendersonWe can handle both exception entry and exception return by hooking into aarch64_sve_change_el.
--- target/arm/helper.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
target/arm/helper.c +13 -2
@@ -14276,6 +14276,19 @@ void aarch64_sve_change_el(CPUARMState *env, int old_el,return ; } + old_a64 = old_el ?arm_el_is_aa64 (env, old_el) : el0_a64; + new_a64 = new_el ?arm_el_is_aa64 (env, new_el) : el0_a64; + +/* +* Both AArch64.TakeException and AArch64.ExceptionReturn +* invoke ResetSVEState when taking an exception from, or +* returning to, AArch32 state when PSTATE.SM is enabled. +*/ +if (old_a64 != new_a64 &&FIELD_EX64 (env->svcr,SVCR ,SM )) { +arm_reset_sve_state (env); +return ; + } +/* * DDI0584A.d sec 3.2: "If SVE instructions are disabled or trapped * at ELx, or not available because the EL is in AArch32 state, then
@@ -14288,10 +14301,8 @@ void aarch64_sve_change_el(CPUARMState *env, int old_el,* we already have the correct register contents when encountering the * vq0->vq0 transition between EL0->EL1. */ - old_a64 = old_el ?arm_el_is_aa64 (env, old_el) : el0_a64; old_len = (old_a64 && !sve_exception_el (env, old_el) ?sve_vqm1_for_el (env, old_el) :0 ); - new_a64 = new_el ?arm_el_is_aa64 (env, new_el) : el0_a64; new_len = (new_a64 && !sve_exception_el (env, new_el) ?sve_vqm1_for_el (env, new_el) :0 );
Signature · 1 line
2.34.1
PATCH v2 58/71 target/arm: Enable SME for -cpu max
In reply to Richard HendersonNote that SME remains effectively disabled for user-only, because we do not yet set CPACR_EL1.SMEN. This needs to wait until the kernel ABI is implemented.
--- target/arm/cpu64.c | 11 +++++++++++ docs/system/arm/emulation.rst | 4 ++++ 2 files changed, 15 insertions(+)
target/arm/cpu64.c +11 -0
@@ -1017,6 +1017,7 @@ static void aarch64_max_initfn(Object *obj)* we do for EL2 with the virtualization=on property. */ t =FIELD_DP64 (t,ID_AA64PFR1 ,MTE ,3 );/* FEAT_MTE3 */ + t =FIELD_DP64 (t,ID_AA64PFR1 ,SME ,1 );/* FEAT_SME */ t =FIELD_DP64 (t,ID_AA64PFR1 ,CSV2_FRAC ,0 );/* FEAT_CSV2_2 */ cpu->isar.id_aa64pfr1 = t;
@@ -1067,6 +1068,16 @@ static void aarch64_max_initfn(Object *obj) t =FIELD_DP64 (t,ID_AA64DFR0 ,PMUVER ,5 );/* FEAT_PMUv3p4 */ cpu->isar.id_aa64dfr0 = t; + t = cpu->isar.id_aa64smfr0; + t =FIELD_DP64 (t,ID_AA64SMFR0 ,F32F32 ,1 );/* FEAT_SME */ + t =FIELD_DP64 (t,ID_AA64SMFR0 ,B16F32 ,1 );/* FEAT_SME */ + t =FIELD_DP64 (t,ID_AA64SMFR0 ,F16F32 ,1 );/* FEAT_SME */ + t =FIELD_DP64 (t,ID_AA64SMFR0 ,I8I32 ,0xf );/* FEAT_SME */ + t =FIELD_DP64 (t,ID_AA64SMFR0 ,F64F64 ,1 );/* FEAT_SME_F64F64 */ + t =FIELD_DP64 (t,ID_AA64SMFR0 ,I16I64 ,0xf );/* FEAT_SME_I16I64 */ + t =FIELD_DP64 (t,ID_AA64SMFR0 ,FA64 ,1 );/* FEAT_SME_FA64 */ + cpu->isar.id_aa64smfr0 = t; +/* Replicate the same data to the 32-bit id registers. */ aa32_max_features (cpu);
docs/system/arm/emulation.rst +4 -0
@@ -63,6 +63,10 @@ the following architecture extensions: - FEAT_SHA512 (Advanced SIMD SHA512 instructions) - FEAT_SM3 (Advanced SIMD SM3 instructions) - FEAT_SM4 (Advanced SIMD SM4 instructions) +- FEAT_SME (Scalable Matrix Extension) +- FEAT_SME_FA64 (Full A64 instruction set in Streaming SVE mode) +- FEAT_SME_F64F64 (Double-precision floating-point outer product instructions) +- FEAT_SME_I16I64 (16-bit to 64-bit integer widening outer product instructions) - FEAT_SPECRES (Speculation restriction instructions) - FEAT_SSBS (Speculative Store Bypass Safe) - FEAT_TLBIOS (TLB invalidate instructions in Outer Shareable domain)
Signature · 1 line
2.34.1
PATCH v2 59/71 linux-user/aarch64: Clear tpidr2_el0 if CLONE_SETTLS
In reply to Richard Henderson--- linux-user/aarch64/target_cpu.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
linux-user/aarch64/target_cpu.h +4 -1
@@ -34,10 +34,13 @@ static inline void cpu_clone_regs_parent(CPUARMState *env, unsigned flags)static inline void cpu_set_tls (CPUARMState *env,target_ulong newtls) { -/* Note that AArch64 Linux keeps the TLS pointer in TPIDR; this is +/* +* Note that AArch64 Linux keeps the TLS pointer in TPIDR; this is * different from AArch32 Linux, which uses TPIDRRO. */ env->cp15.tpidr_el[0 ] = newtls; +/* TPIDR2_EL0 is cleared with CLONE_SETTLS. */ + env->cp15.tpidr2_el0 =0 ; }static inline abi_ulong get_sp_from_cpustate (CPUARMState *state)
Signature · 1 line
2.34.1
PATCH v2 60/71 linux-user/aarch64: Reset PSTATE.SM on syscalls
In reply to Richard Henderson--- linux-user/aarch64/cpu_loop.c | 9 +++++++++ 1 file changed, 9 insertions(+)
linux-user/aarch64/cpu_loop.c +9 -0
@@ -89,6 +89,15 @@ void cpu_loop(CPUARMState *env)switch (trapnr) {case EXCP_SWI : +/* +* On syscall, PSTATE.ZA is preserved, along with the ZA matrix. +* PSTATE.SM is cleared, per SMSTOP, which does ResetSVEState. +*/ +if (FIELD_EX64 (env->svcr,SVCR ,SM )) { + env->svcr =FIELD_DP64 (env->svcr,SVCR ,SM ,0 ); +arm_rebuild_hflags (env); +arm_reset_sve_state (env); + } ret = do_syscall(env, env->xregs[8], env->xregs[0],
Signature · 1 line
2.34.1
PATCH v2 61/71 linux-user/aarch64: Add SM bit to SVE signal context
In reply to Richard HendersonMake sure to zero the currently reserved fields.
--- linux-user/aarch64/signal.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
linux-user/aarch64/signal.c +8 -1
@@ -78,7 +78,8 @@ struct target_extra_context {struct target_sve_context {struct target_aarch64_ctx head;uint16_t vl; -uint16_t reserved[3 ]; +uint16_t flags; +uint16_t reserved[2 ];/* The actual SVE data immediately follows. It is laid out * according to TARGET_SVE_SIG_{Z,P}REG_OFFSET, based off of * the original struct pointer.
@@ -101,6 +102,8 @@ struct target_sve_context {#define TARGET_SVE_SIG_CONTEXT_SIZE (VQ ) \ (TARGET_SVE_SIG_PREG_OFFSET(VQ, 17)) +#define TARGET_SVE_SIG_FLAG_SM 1 +struct target_rt_sigframe {struct target_siginfo info;struct target_ucontext uc;
@@ -177,9 +180,13 @@ static void target_setup_sve_record(struct target_sve_context *sve, {int i, j; +memset (sve,0 ,sizeof (*sve));__put_user (TARGET_SVE_MAGIC , &sve->head.magic);__put_user (size, &sve->head.size);__put_user (vq *TARGET_SVE_VQ_BYTES , &sve->vl); +if (FIELD_EX64 (env->svcr,SVCR ,SM )) { +__put_user (TARGET_SVE_SIG_FLAG_SM , &sve->flags); + }/* Note that SVE regs are stored as a byte stream, with each byte element * at a subsequent address. This corresponds to a little-endian store
Signature · 1 line
2.34.1
PATCH v2 62/71 linux-user/aarch64: Tidy target_restore_sigframe error return
In reply to Richard HendersonFold the return value setting into the goto, so each point of failure need not do both.
--- linux-user/aarch64/signal.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
linux-user/aarch64/signal.c +11 -15
@@ -287,7 +287,6 @@ static int target_restore_sigframe(CPUARMState *env,struct target_sve_context *sve =NULL ;uint64_t extra_datap =0 ;bool used_extra = false; -bool err = false;int vq =0 , sve_size =0 ;target_restore_general_frame (env, sf);
@@ -301,8 +300,7 @@ static int target_restore_sigframe(CPUARMState *env,switch (magic) {case 0 :if (size !=0 ) { - err = true; - goto exit; + goto err; }if (used_extra) { ctx =NULL ;
@@ -314,8 +312,7 @@ static int target_restore_sigframe(CPUARMState *env,case TARGET_FPSIMD_MAGIC :if (fpsimd || size !=sizeof (struct target_fpsimd_context )) { - err = true; - goto exit; + goto err; } fpsimd = (struct target_fpsimd_context *)ctx;break ;
@@ -329,13 +326,11 @@ static int target_restore_sigframe(CPUARMState *env,break ; } } - err = true; - goto exit; + goto err;case TARGET_EXTRA_MAGIC :if (extra || size !=sizeof (struct target_extra_context )) { - err = true; - goto exit; + goto err; }__get_user (extra_datap, &((struct target_extra_context *)ctx)->datap);
@@ -348,8 +343,7 @@ static int target_restore_sigframe(CPUARMState *env,/* Unknown record -- we certainly didn't generate it. * Did we in fact get out of sync? */ - err = true; - goto exit; + goto err; } ctx = (void *)ctx + size; }
@@ -358,17 +352,19 @@ static int target_restore_sigframe(CPUARMState *env,if (fpsimd) {target_restore_fpsimd_record (env, fpsimd); }else { - err = true; + goto err; }/* SVE data, if present, overwrites FPSIMD data. */ if (sve) {target_restore_sve_record (env, sve, vq); } - - exit:unlock_user (extra, extra_datap,0 ); -return err; +return 0 ; + + err: +unlock_user (extra, extra_datap,0 ); +return 1 ; } static abi_ulong get_sigframe(struct target_sigaction *ka,
Signature · 1 line
2.34.1
PATCH v2 63/71 linux-user/aarch64: Do not allow duplicate or short sve records
In reply to Richard HendersonIn parse_user_sigframe, the kernel rejects duplicate sve records, or records that are smaller than the header. We were silently allowing these cases to pass, dropping the record.
--- linux-user/aarch64/signal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
linux-user/aarch64/signal.c +4 -1
@@ -318,10 +318,13 @@ static int target_restore_sigframe(CPUARMState *env,break ;case TARGET_SVE_MAGIC : +if (sve || size <sizeof (struct target_sve_context )) { + goto err; + }if (cpu_isar_feature (aa64_sve,env_archcpu (env))) { vq =sve_vq (env); sve_size =QEMU_ALIGN_UP (TARGET_SVE_SIG_CONTEXT_SIZE (vq),16 ); -if (!sve && size == sve_size) { +if (size == sve_size) { sve = (struct target_sve_context *)ctx;break ; }
Signature · 1 line
2.34.1
PATCH v2 64/71 linux-user/aarch64: Verify extra record lock succeeded
In reply to Richard Henderson--- linux-user/aarch64/signal.c | 3 +++ 1 file changed, 3 insertions(+)
linux-user/aarch64/signal.c +3 -0
@@ -340,6 +340,9 @@ static int target_restore_sigframe(CPUARMState *env,__get_user (extra_size, &((struct target_extra_context *)ctx)->size); extra =lock_user (VERIFY_READ , extra_datap, extra_size,0 ); +if (!extra) { +return 1 ; + }break ;default :
Signature · 1 line
2.34.1
PATCH v2 65/71 linux-user/aarch64: Move sve record checks into restore
In reply to Richard HendersonMove the checks out of the parsing loop and into the restore function. This more closely mirrors the code structure in the kernel, and is slightly clearer.
Reject rather than silently skip incorrect VL and SVE record sizes.
--- linux-user/aarch64/signal.c | 51 +++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 16 deletions(-)
linux-user/aarch64/signal.c +35 -16
@@ -250,12 +250,36 @@ static void target_restore_fpsimd_record(CPUARMState *env, } } -static void target_restore_sve_record (CPUARMState *env, -struct target_sve_context *sve,int vq) +static bool target_restore_sve_record (CPUARMState *env, +struct target_sve_context *sve, +int size) { -int i, j; +int i, j, vl, vq; -/* Note that SVE regs are stored as a byte stream, with each byte element +if (!cpu_isar_feature (aa64_sve,env_archcpu (env))) { +return false; + } + +__get_user (vl, &sve->vl); + vq =sve_vq (env); + +/* Reject mismatched VL. */ +if (vl != vq *TARGET_SVE_VQ_BYTES ) { +return false; + } + +/* Accept empty record -- used to clear PSTATE.SM. */ +if (size <=sizeof (*sve)) { +return true; + } + +/* Reject non-empty but incomplete record. */ +if (size <TARGET_SVE_SIG_CONTEXT_SIZE (vq)) { +return false; + } + +/* +* Note that SVE regs are stored as a byte stream, with each byte element * at a subsequent address. This corresponds to a little-endian load * of our 64-bit hunks. */
@@ -277,6 +301,7 @@ static void target_restore_sve_record(CPUARMState *env, } } } +return true; } static int target_restore_sigframe(CPUARMState *env,
@@ -287,7 +312,7 @@ static int target_restore_sigframe(CPUARMState *env,struct target_sve_context *sve =NULL ;uint64_t extra_datap =0 ;bool used_extra = false; -int vq =0 , sve_size =0 ; +int sve_size =0 ;target_restore_general_frame (env, sf);
@@ -321,15 +346,9 @@ static int target_restore_sigframe(CPUARMState *env,if (sve || size <sizeof (struct target_sve_context )) { goto err; } -if (cpu_isar_feature (aa64_sve,env_archcpu (env))) { - vq =sve_vq (env); - sve_size =QEMU_ALIGN_UP (TARGET_SVE_SIG_CONTEXT_SIZE (vq),16 ); -if (size == sve_size) { - sve = (struct target_sve_context *)ctx; -break ; - } - } - goto err; + sve = (struct target_sve_context *)ctx; + sve_size = size; +break ;case TARGET_EXTRA_MAGIC :if (extra || size !=sizeof (struct target_extra_context )) {
@@ -362,8 +381,8 @@ static int target_restore_sigframe(CPUARMState *env, }/* SVE data, if present, overwrites FPSIMD data. */ -if (sve) { -target_restore_sve_record (env, sve, vq); +if (sve && !target_restore_sve_record (env, sve, sve_size)) { + goto err; }unlock_user (extra, extra_datap,0 );return 0 ;
Signature · 1 line
2.34.1
PATCH v2 66/71 linux-user/aarch64: Implement SME signal handling
In reply to Richard HendersonSet the SM bit in the SVE record on signal delivery, create the ZA record. Restore SM and ZA state according to the records present on return.
--- linux-user/aarch64/signal.c | 162 +++++++++++++++++++++++++++++++++--- 1 file changed, 151 insertions(+), 11 deletions(-)
linux-user/aarch64/signal.c +151 -11
@@ -104,6 +104,22 @@ struct target_sve_context {#define TARGET_SVE_SIG_FLAG_SM 1 +#define TARGET_ZA_MAGIC 0x54366345 + +struct target_za_context { +struct target_aarch64_ctx head; +uint16_t vl; +uint16_t reserved[3 ]; +/* The actual ZA data immediately follows. */ +}; + +#define TARGET_ZA_SIG_REGS_OFFSET \ + QEMU_ALIGN_UP(sizeof(struct target_za_context), TARGET_SVE_VQ_BYTES) +#define TARGET_ZA_SIG_ZAV_OFFSET (VQ ,N ) \ + (TARGET_ZA_SIG_REGS_OFFSET + (VQ) * TARGET_SVE_VQ_BYTES * (N)) +#define TARGET_ZA_SIG_CONTEXT_SIZE (VQ ) \ + TARGET_ZA_SIG_ZAV_OFFSET(VQ, VQ * TARGET_SVE_VQ_BYTES) +struct target_rt_sigframe {struct target_siginfo info;struct target_ucontext uc;
@@ -176,9 +192,9 @@ static void target_setup_end_record(struct target_aarch64_ctx *end) }static void target_setup_sve_record (struct target_sve_context *sve, -CPUARMState *env,int vq,int size) +CPUARMState *env,int size) { -int i, j; +int i, j, vq =sme_vq (env);memset (sve,0 ,sizeof (*sve));__put_user (TARGET_SVE_MAGIC , &sve->head.magic);
@@ -207,6 +223,34 @@ static void target_setup_sve_record(struct target_sve_context *sve, } } +static void target_setup_za_record (struct target_za_context *za, +CPUARMState *env,int size) +{ +int vq =sme_vq (env); +int vl = vq *TARGET_SVE_VQ_BYTES ; +int i, j; + +memset (za,0 ,sizeof (*za)); +__put_user (TARGET_ZA_MAGIC , &za->head.magic); +__put_user (size, &za->head.size); +__put_user (vl, &za->vl); + +if (size ==TARGET_ZA_SIG_CONTEXT_SIZE (0 )) { +return ; + } + +/* +* Note that ZA vectors are stored as a byte stream, +* with each byte element at a subsequent address. +*/ +for (i =0 ; i < vl; ++i) { +uint64_t *z = (void *)za +TARGET_ZA_SIG_ZAV_OFFSET (vq, i); +for (j =0 ; j < vq *2 ; ++j) { +__put_user_e (env->zarray[i].d[j], z + j, le); + } + } +} +static void target_restore_general_frame (CPUARMState *env,struct target_rt_sigframe *sf) {
@@ -252,16 +296,28 @@ static void target_restore_fpsimd_record(CPUARMState *env,static bool target_restore_sve_record (CPUARMState *env,struct target_sve_context *sve, -int size) +int size,int *svcr) { -int i, j, vl, vq; +int i, j, vl, vq, flags; +bool sm; +/* ??? Kernel tests SVE && (!sm || SME); suggest (sm ? SME : SVE). */ if (!cpu_isar_feature (aa64_sve,env_archcpu (env))) {return false; }__get_user (vl, &sve->vl); - vq =sve_vq (env); +__get_user (flags, &sve->flags); + + sm = flags &TARGET_SVE_SIG_FLAG_SM ; +if (sm) { +if (!cpu_isar_feature (aa64_sme,env_archcpu (env))) { +return false; + } + vq =sme_vq (env); + }else { + vq =sve_vq (env); + }/* Reject mismatched VL. */ if (vl != vq *TARGET_SVE_VQ_BYTES ) {
@@ -278,6 +334,8 @@ static bool target_restore_sve_record(CPUARMState *env,return false; } + *svcr =FIELD_DP64 (*svcr,SVCR ,SM , sm); +/* * Note that SVE regs are stored as a byte stream, with each byte element * at a subsequent address. This corresponds to a little-endian load
@@ -304,15 +362,57 @@ static bool target_restore_sve_record(CPUARMState *env,return true; } +static bool target_restore_za_record (CPUARMState *env, +struct target_za_context *za, +int size,int *svcr) +{ +int i, j, vl, vq; + +if (!cpu_isar_feature (aa64_sme,env_archcpu (env))) { +return false; + } + +__get_user (vl, &za->vl); + vq =sme_vq (env); + +/* Reject mismatched VL. */ +if (vl != vq *TARGET_SVE_VQ_BYTES ) { +return false; + } + +/* Accept empty record -- used to clear PSTATE.ZA. */ +if (size <=TARGET_ZA_SIG_CONTEXT_SIZE (0 )) { +return true; + } + +/* Reject non-empty but incomplete record. */ +if (size <TARGET_ZA_SIG_CONTEXT_SIZE (vq)) { +return false; + } + + *svcr =FIELD_DP64 (*svcr,SVCR ,ZA ,1 ); + +for (i =0 ; i < vl; ++i) { +uint64_t *z = (void *)za +TARGET_ZA_SIG_ZAV_OFFSET (vq, i); +for (j =0 ; j < vq *2 ; ++j) { +__get_user_e (env->zarray[i].d[j], z + j, le); + } + } +return true; +} +static int target_restore_sigframe (CPUARMState *env,struct target_rt_sigframe *sf) {struct target_aarch64_ctx *ctx, *extra =NULL ;struct target_fpsimd_context *fpsimd =NULL ;struct target_sve_context *sve =NULL ; +struct target_za_context *za =NULL ;uint64_t extra_datap =0 ;bool used_extra = false;int sve_size =0 ; +int za_size =0 ; +int svcr =0 ;target_restore_general_frame (env, sf);
@@ -350,6 +450,14 @@ static int target_restore_sigframe(CPUARMState *env, sve_size = size;break ; +case TARGET_ZA_MAGIC : +if (za || size <sizeof (struct target_za_context )) { + goto err; + } + za = (struct target_za_context *)ctx; + za_size = size; +break ; +case TARGET_EXTRA_MAGIC :if (extra || size !=sizeof (struct target_extra_context )) { goto err;
@@ -381,9 +489,16 @@ static int target_restore_sigframe(CPUARMState *env, }/* SVE data, if present, overwrites FPSIMD data. */ -if (sve && !target_restore_sve_record (env, sve, sve_size)) { +if (sve && !target_restore_sve_record (env, sve, sve_size, &svcr)) { goto err; } +if (za && !target_restore_za_record (env, za, za_size, &svcr)) { + goto err; + } +if (env->svcr != svcr) { + env->svcr = svcr; +arm_rebuild_hflags (env); + }unlock_user (extra, extra_datap,0 );return 0 ;
@@ -451,7 +566,8 @@ static void target_setup_frame(int usig, struct target_sigaction *ka, .total_size = offsetof(struct target_rt_sigframe, uc.tuc_mcontext.__reserved), }; -int fpsimd_ofs, fr_ofs, sve_ofs =0 , vq =0 , sve_size =0 ; +int fpsimd_ofs, fr_ofs, sve_ofs =0 , za_ofs =0 ; +int sve_size =0 , za_size =0 ;struct target_rt_sigframe *frame;struct target_rt_frame_record *fr;abi_ulong frame_addr, return_addr;
@@ -461,11 +577,20 @@ static void target_setup_frame(int usig, struct target_sigaction *ka, &layout);/* SVE state needs saving only if it exists. */ -if (cpu_isar_feature (aa64_sve,env_archcpu (env))) { - vq =sve_vq (env); - sve_size =QEMU_ALIGN_UP (TARGET_SVE_SIG_CONTEXT_SIZE (vq),16 ); +if (cpu_isar_feature (aa64_sve,env_archcpu (env)) || +cpu_isar_feature (aa64_sme,env_archcpu (env))) { + sve_size =QEMU_ALIGN_UP (TARGET_SVE_SIG_CONTEXT_SIZE (sve_vq (env)),16 ); sve_ofs =alloc_sigframe_space (sve_size, &layout); } +if (cpu_isar_feature (aa64_sme,env_archcpu (env))) { +/* ZA state needs saving only if it is enabled. */ +if (FIELD_EX64 (env->svcr,SVCR ,ZA )) { + za_size =TARGET_ZA_SIG_CONTEXT_SIZE (sme_vq (0 )); + }else { + za_size =TARGET_ZA_SIG_CONTEXT_SIZE (0 ); + } + za_ofs =alloc_sigframe_space (za_size, &layout); + }if (layout.extra_ofs) {/* Reserve space for the extra end marker. The standard end marker
@@ -512,7 +637,10 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,target_setup_end_record ((void *)frame + layout.extra_end_ofs); }if (sve_ofs) { -target_setup_sve_record ((void *)frame + sve_ofs, env, vq, sve_size); +target_setup_sve_record ((void *)frame + sve_ofs, env, sve_size); + } +if (za_ofs) { +target_setup_za_record ((void *)frame + za_ofs, env, za_size); }/* Set up the stack frame for unwinding. */
@@ -536,6 +664,18 @@ static void target_setup_frame(int usig, struct target_sigaction *ka, env->btype =2 ; } +/* +* Invoke the signal handler with both SM and ZA disabled. +* When clearing SM, ResetSVEState, per SMSTOP. +*/ +if (FIELD_EX64 (env->svcr,SVCR ,SM )) { +arm_reset_sve_state (env); + } +if (env->svcr) { + env->svcr =0 ; +arm_rebuild_hflags (env); + } +if (info) {tswap_siginfo (&frame->info, info); env->xregs[1 ] = frame_addr + offsetof(struct target_rt_sigframe , info);
Signature · 1 line
2.34.1
PATCH v2 67/71 linux-user: Rename sve prctls
In reply to Richard HendersonAdd "sve" to the sve prctl functions, to distinguish them from the coming "sme" prctls with similar names.
--- linux-user/aarch64/target_prctl.h | 8 ++++---- linux-user/syscall.c | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-)
linux-user/aarch64/target_prctl.h +4 -4
@@ -6,7 +6,7 @@#ifndef AARCH64_TARGET_PRCTL_H #define AARCH64_TARGET_PRCTL_H -static abi_long do_prctl_get_vl (CPUArchState *env) +static abi_long do_prctl_sve_get_vl (CPUArchState *env) {ARMCPU *cpu =env_archcpu (env);if (cpu_isar_feature (aa64_sve, cpu)) {
@@ -14,9 +14,9 @@ static abi_long do_prctl_get_vl(CPUArchState *env) }return -TARGET_EINVAL ; } -#define do_prctl_get_vl do_prctl_get_vl +#define do_prctl_sve_get_vl do_prctl_sve_get_vl -static abi_long do_prctl_set_vl (CPUArchState *env,abi_long arg2) +static abi_long do_prctl_sve_set_vl (CPUArchState *env,abi_long arg2) {/* * We cannot support either PR_SVE_SET_VL_ONEXEC or PR_SVE_VL_INHERIT.
@@ -47,7 +47,7 @@ static abi_long do_prctl_set_vl(CPUArchState *env, abi_long arg2) }return -TARGET_EINVAL ; } -#define do_prctl_set_vl do_prctl_set_vl +#define do_prctl_sve_set_vl do_prctl_sve_set_vlstatic abi_long do_prctl_reset_keys (CPUArchState *env,abi_long arg2) {
linux-user/syscall.c +6 -6
@@ -6365,11 +6365,11 @@ static abi_long do_prctl_inval1(CPUArchState *env, abi_long arg2)#ifndef do_prctl_set_fp_mode#define do_prctl_set_fp_mode do_prctl_inval1#endif -#ifndef do_prctl_get_vl -#define do_prctl_get_vl do_prctl_inval0 +#ifndef do_prctl_sve_get_vl +#define do_prctl_sve_get_vl do_prctl_inval0#endif -#ifndef do_prctl_set_vl -#define do_prctl_set_vl do_prctl_inval1 +#ifndef do_prctl_sve_set_vl +#define do_prctl_sve_set_vl do_prctl_inval1#endif #ifndef do_prctl_reset_keys#define do_prctl_reset_keys do_prctl_inval1
@@ -6434,9 +6434,9 @@ static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2,case PR_SET_FP_MODE :return do_prctl_set_fp_mode (env, arg2);case PR_SVE_GET_VL : -return do_prctl_get_vl (env); +return do_prctl_sve_get_vl (env);case PR_SVE_SET_VL : -return do_prctl_set_vl (env, arg2); +return do_prctl_sve_set_vl (env, arg2);case PR_PAC_RESET_KEYS :if (arg3 || arg4 || arg5) {return -TARGET_EINVAL ;
Signature · 1 line
2.34.1
PATCH v2 68/71 linux-user/aarch64: Implement PR_SME_GET_VL, PR_SME_SET_VL
In reply to Richard HendersonThese prctl set the Streaming SVE vector length, which may be completely different from the Normal SVE vector length.
--- linux-user/aarch64/target_prctl.h | 48 +++++++++++++++++++++++++++++++ linux-user/syscall.c | 16 +++++++++++ 2 files changed, 64 insertions(+)
linux-user/aarch64/target_prctl.h +48 -0
@@ -10,6 +10,7 @@ static abi_long do_prctl_sve_get_vl(CPUArchState *env) {ARMCPU *cpu =env_archcpu (env);if (cpu_isar_feature (aa64_sve, cpu)) { +/* PSTATE.SM is always unset on syscall entry. */ return sve_vq (env) *16 ; }return -TARGET_EINVAL ;
@@ -27,6 +28,7 @@ static abi_long do_prctl_sve_set_vl(CPUArchState *env, abi_long arg2) && arg2 >= 0 && arg2 <= 512 * 16 && !(arg2 & 15)) {uint32_t vq, old_vq; +/* PSTATE.SM is always unset on syscall entry. */ old_vq =sve_vq (env);/*
@@ -49,6 +51,52 @@ static abi_long do_prctl_sve_set_vl(CPUArchState *env, abi_long arg2) }#define do_prctl_sve_set_vl do_prctl_sve_set_vl +static abi_long do_prctl_sme_get_vl (CPUArchState *env) +{ +ARMCPU *cpu =env_archcpu (env); +if (cpu_isar_feature (aa64_sme, cpu)) { +return sme_vq (env) *16 ; + } +return -TARGET_EINVAL ; +} +#define do_prctl_sme_get_vl do_prctl_sme_get_vl + +static abi_long do_prctl_sme_set_vl (CPUArchState *env,abi_long arg2) +{ +/* +* We cannot support either PR_SME_SET_VL_ONEXEC or PR_SME_VL_INHERIT. +* Note the kernel definition of sve_vl_valid allows for VQ=512, +* i.e. VL=8192, even though the architectural maximum is VQ=16. +*/ +if (cpu_isar_feature (aa64_sme,env_archcpu (env)) + && arg2 >=0 && arg2 <=512 *16 && !(arg2 &15 )) { +int vq, old_vq; + + old_vq =sme_vq (env); + +/* +* Bound the value of vq, so that we know that it fits into +* the 4-bit field in SMCR_EL1. Because PSTATE.SM is cleared +* on syscall entry, we are not modifying the current SVE +* vector length. +*/ + vq =MAX (arg2 /16 ,1 ); + vq =MIN (vq,16 ); + env->vfp.smcr_el[1 ] = +FIELD_DP64 (env->vfp.smcr_el[1 ],SMCR ,LEN , vq -1 ); + vq =sme_vq (env); + +if (old_vq != vq) { +/* PSTATE.ZA state is cleared on any change to VQ. */ + env->svcr =FIELD_DP64 (env->svcr,SVCR ,ZA ,0 ); +arm_rebuild_hflags (env); + } +return vq *16 ; + } +return -TARGET_EINVAL ; +} +#define do_prctl_sme_set_vl do_prctl_sme_set_vl +static abi_long do_prctl_reset_keys (CPUArchState *env,abi_long arg2) {ARMCPU *cpu =env_archcpu (env);
linux-user/syscall.c +16 -0
@@ -6346,6 +6346,12 @@ abi_long do_arch_prctl(CPUX86State *env, int code, abi_ulong addr)#ifndef PR_SET_SYSCALL_USER_DISPATCH # define PR_SET_SYSCALL_USER_DISPATCH 59#endif +#ifndef PR_SME_SET_VL +# define PR_SME_SET_VL 63 +# define PR_SME_GET_VL 64 +# define PR_SME_VL_LEN_MASK 0xffff +# define PR_SME_VL_INHERIT (1 << 17) +#endif #include "target_prctl.h"
@@ -6386,6 +6392,12 @@ static abi_long do_prctl_inval1(CPUArchState *env, abi_long arg2)#ifndef do_prctl_set_unalign#define do_prctl_set_unalign do_prctl_inval1#endif +#ifndef do_prctl_sme_get_vl +#define do_prctl_sme_get_vl do_prctl_inval0 +#endif +#ifndef do_prctl_sme_set_vl +#define do_prctl_sme_set_vl do_prctl_inval1 +#endif static abi_long do_prctl (CPUArchState *env,abi_long option,abi_long arg2,abi_long arg3,abi_long arg4,abi_long arg5)
@@ -6437,6 +6449,10 @@ static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2,return do_prctl_sve_get_vl (env);case PR_SVE_SET_VL :return do_prctl_sve_set_vl (env, arg2); +case PR_SME_GET_VL : +return do_prctl_sme_get_vl (env); +case PR_SME_SET_VL : +return do_prctl_sme_set_vl (env, arg2);case PR_PAC_RESET_KEYS :if (arg3 || arg4 || arg5) {return -TARGET_EINVAL ;
Signature · 1 line
2.34.1
PATCH v2 69/71 target/arm: Only set ZEN in reset if SVE present
In reply to Richard HendersonThere's no reason to set CPACR_EL1.ZEN if SVE disabled.
--- target/arm/cpu.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
target/arm/cpu.c +3 -4
@@ -203,11 +203,10 @@ static void arm_cpu_reset(DeviceState *dev)/* and to the FP/Neon instructions */ env->cp15.cpacr_el1 =FIELD_DP64 (env->cp15.cpacr_el1,CPACR_EL1 ,FPEN ,3 ); -/* and to the SVE instructions */ - env->cp15.cpacr_el1 =FIELD_DP64 (env->cp15.cpacr_el1, -CPACR_EL1 ,ZEN ,3 ); -/* with reasonable vector length */ +/* and to the SVE instructions, with default vector length */ if (cpu_isar_feature (aa64_sve, cpu)) { + env->cp15.cpacr_el1 =FIELD_DP64 (env->cp15.cpacr_el1, +CPACR_EL1 ,ZEN ,3 ); env->vfp.zcr_el[1 ] = cpu->sve_default_vq -1 ; }/*
Signature · 1 line
2.34.1
PATCH v2 70/71 target/arm: Enable SME for user-only
In reply to Richard HendersonEnable SME, TPIDR2_EL0, and FA64 if supported by the cpu.
--- target/arm/cpu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
target/arm/cpu.c +11 -0
@@ -209,6 +209,17 @@ static void arm_cpu_reset(DeviceState *dev) CPACR_EL1, ZEN, 3); env->vfp.zcr_el[1 ] = cpu->sve_default_vq -1 ; } +/* and for SME instructions, with default vector length, and TPIDR2 */ +if (cpu_isar_feature (aa64_sme, cpu)) { + env->cp15.sctlr_el[1 ] |= SCTLR_EnTP2; + env->cp15.cpacr_el1 =FIELD_DP64 (env->cp15.cpacr_el1, +CPACR_EL1 ,SMEN ,3 ); + env->vfp.smcr_el[1 ] = cpu->sme_default_vq -1 ; +if (cpu_isar_feature (aa64_sme_fa64, cpu)) { + env->vfp.smcr_el[1 ] =FIELD_DP64 (env->vfp.smcr_el[1 ], +SMCR ,FA64 ,1 ); + } + }/* * Enable 48-bit address space (TODO: take reserved_va into account). * Enable TBI0 but not TBI1.
Signature · 1 line
2.34.1
PATCH v2 71/71 linux-user/aarch64: Add SME related hwcap entries
In reply to Richard Henderson--- linux-user/elfload.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
linux-user/elfload.c +20 -0
@@ -601,6 +601,18 @@ enum {ARM_HWCAP2_A64_RNG =1 <<16 ,ARM_HWCAP2_A64_BTI =1 <<17 ,ARM_HWCAP2_A64_MTE =1 <<18 , +ARM_HWCAP2_A64_ECV =1 <<19 , +ARM_HWCAP2_A64_AFP =1 <<20 , +ARM_HWCAP2_A64_RPRES =1 <<21 , +ARM_HWCAP2_A64_MTE3 =1 <<22 , +ARM_HWCAP2_A64_SME =1 <<23 , +ARM_HWCAP2_A64_SME_I16I64 =1 <<24 , +ARM_HWCAP2_A64_SME_F64F64 =1 <<25 , +ARM_HWCAP2_A64_SME_I8I32 =1 <<26 , +ARM_HWCAP2_A64_SME_F16F32 =1 <<27 , +ARM_HWCAP2_A64_SME_B16F32 =1 <<28 , +ARM_HWCAP2_A64_SME_F32F32 =1 <<29 , + ARM_HWCAP2_A64_SME_FA64 = 1 << 30, };#define ELF_HWCAP get_elf_hwcap()
@@ -670,6 +682,14 @@ static uint32_t get_elf_hwcap2(void)GET_FEATURE_ID (aa64_rndr,ARM_HWCAP2_A64_RNG );GET_FEATURE_ID (aa64_bti,ARM_HWCAP2_A64_BTI );GET_FEATURE_ID (aa64_mte,ARM_HWCAP2_A64_MTE ); +GET_FEATURE_ID (aa64_sme, (ARM_HWCAP2_A64_SME | +ARM_HWCAP2_A64_SME_F32F32 | +ARM_HWCAP2_A64_SME_B16F32 | +ARM_HWCAP2_A64_SME_F16F32 | +ARM_HWCAP2_A64_SME_I8I32 )); +GET_FEATURE_ID (aa64_sme_f64f64,ARM_HWCAP2_A64_SME_F64F64 ); +GET_FEATURE_ID (aa64_sme_i16i64,ARM_HWCAP2_A64_SME_I16I64 ); +GET_FEATURE_ID (aa64_sme_fa64,ARM_HWCAP2_A64_SME_FA64 );return hwcaps; }
Signature · 1 line
2.34.1
On Tue, 7 Jun 2022 at 21:33, Richard Henderson
<[email protected]> wrote:
I took the first 20 patches of this into target-arm.next to cut it down to size a bit, but will continue to review the other two-thirds.
-- PMM