target/arm: enforce alignment
v2 cover target/arm: enforce alignment
As reported in https://bugs.launchpad.net/bugs/1905356
For version 2, I've rearranged things a bit, which has made it easy to support SCTLR.A/CCR.UNALIGN_TRAP. At least for non-sve code, where we issue tcg load/store operations. Predicated sve load/stores will require more work within the helpers.
I've not explicitly tested the SCTLR.A support, since I don't have any code that tries to enable it. Though it seems obvious enough. I will look into writing a small semihosting test case using our existing test infrastructure shortly.
r~
Supercedes: <[email protected]>
Richard Henderson (24):
target/arm: Fix decode of align in VLDST_single target/arm: Add ALIGN_MEM to TBFLAG_ANY
target/arm: Adjust gen_aa32_{ld,st}_i32 for align+endianness target/arm: Merge gen_aa32_frob64 into gen_aa32_ld_i64 target/arm: Fix SCTLR_B test for TCGv_i64 load/store target/arm: Adjust gen_aa32_{ld,st}_i64 for align+endianness target/arm: Enforce word alignment for LDRD/STRD target/arm: Enforce alignment for LDA/LDAH/STL/STLH target/arm: Enforce alignment for LDM/STM
target/arm: Enforce alignment for RFE
target/arm: Enforce alignment for SRS
target/arm: Enforce alignment for VLDM/VSTM target/arm: Enforce alignment for VLDR/VSTR target/arm: Enforce alignment for VLD1 (all lanes) target/arm: Enforce alignment for VLDn/VSTn (multiple) target/arm: Enforce alignment for VLDn/VSTn (single) target/arm: Use finalize_memop for aa64 gpr load/store target/arm: Use finalize_memop for aa64 fpr load/store target/arm: Enforce alignment for aa64 load-acq/store-rel target/arm: Use MemOp for size + endian in aa64 vector ld/st target/arm: Enforce alignment for aa64 vector LDn/STn (multiple) target/arm: Enforce alignment for aa64 vector LDn/STn (single) target/arm: Enforce alignment for sve LD1R target/arm: Enforce alignment for sve unpredicated LDR/STR
target/arm/cpu.h | 20 +-- target/arm/translate.h | 27 +++++ target/arm/neon-ls.decode | 4 +- target/arm/helper.c | 19 ++- target/arm/translate-a64.c | 175 ++++++++++++++------------- target/arm/translate-sve.c | 60 ++++++--- target/arm/translate.c | 207 ++++++++++++++++++-------------- target/arm/translate-neon.c.inc | 85 ++++++++++--- target/arm/translate-vfp.c.inc | 20 +-- 9 files changed, 391 insertions(+), 226 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/24 target/arm: Fix decode of align in VLDST_single
The encoding of size = 2 and size = 3 had the incorrect decode for align, overlapping the stride field. This error was hidden by what should have been unnecessary masking in translate.
--- target/arm/neon-ls.decode | 4 ++-- target/arm/translate-neon.c.inc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
target/arm/neon-ls.decode +2 -2
@@ -46,7 +46,7 @@ VLD_all_lanes 1111 0100 1 . 1 0 rn:4 .... 11 n:2 size:2 t:1 a:1 rm:4 \ VLDST_single 1111 0100 1 . l:1 0 rn:4 .... 00 n:2 reg_idx:3 align:1 rm:4 \ vd=%vd_dp size=0 stride=1 -VLDST_single 1111 0100 1 . l:1 0 rn:4 .... 01 n:2 reg_idx:2 align:2 rm:4 \ +VLDST_single 1111 0100 1 . l:1 0 rn:4 .... 01 n:2 reg_idx:2 . align:1 rm:4 \ vd=%vd_dp size=1 stride=%imm1_5_p1 -VLDST_single 1111 0100 1 . l:1 0 rn:4 .... 10 n:2 reg_idx:1 align:3 rm:4 \ +VLDST_single 1111 0100 1 . l:1 0 rn:4 .... 10 n:2 reg_idx:1 . align:2 rm:4 \ vd=%vd_dp size=2 stride=%imm1_6_p1
target/arm/translate-neon.c.inc +2 -2
@@ -606,7 +606,7 @@ static bool trans_VLDST_single(DisasContext *s, arg_VLDST_single *a) switch (nregs) { case 1: if (((a->align & (1 << a->size)) != 0) || - (a->size == 2 && ((a->align & 3) == 1 || (a->align & 3) == 2))) { + (a->size == 2 && (a->align == 1 || a->align == 2))) { return false; } break;
@@ -621,7 +621,7 @@ static bool trans_VLDST_single(DisasContext *s, arg_VLDST_single *a) } break; case 4: - if ((a->size == 2) && ((a->align & 3) == 3)) { + if (a->size == 2 && a->align == 3) { return false; } break;
Signature · 1 line
2.25.1
PATCH v2 2/24 target/arm: Add ALIGN_MEM to TBFLAG_ANY
In reply to Richard HendersonUse this to signal when memory access alignment is required. This value comes from the CCR register for M-profile, and from the SCTLR register for A-profile.
--- target/arm/cpu.h | 20 +++++++++++--------- target/arm/translate.h | 2 ++ target/arm/helper.c | 19 +++++++++++++++++-- target/arm/translate.c | 7 +++---- 4 files changed, 33 insertions(+), 15 deletions(-)
target/arm/cpu.h +11 -9
@@ -3220,15 +3220,15 @@ typedef ARMCPU ArchCPU;* We put flags which are shared between 32 and 64 bit mode at the top * of the word, and flags which apply to only one mode at the bottom. * -* 31 20 18 14 9 0 -* +--------------+-----+-----+----------+--------------+ -* | | | TBFLAG_A32 | | -* | | +-----+----------+ TBFLAG_AM32 | -* | TBFLAG_ANY | |TBFLAG_M32| | -* | +-----------+----------+--------------| -* | | TBFLAG_A64 | -* +--------------+-------------------------------------+ -* 31 20 0 +* 31 19 18 14 9 0 +* +--------------+---+-----+----------+--------------+ +* | | | TBFLAG_A32 | | +* | | +-----+----------+ TBFLAG_AM32 | +* | TBFLAG_ANY | |TBFLAG_M32| | +* | +---------+----------+--------------| +* | | TBFLAG_A64 | +* +--------------+-----------------------------------+ +* 31 19 0 * * Unless otherwise noted, these bits are cached in env->hflags. */
@@ -3241,6 +3241,8 @@ FIELD(TBFLAG_ANY, MMUIDX, 24, 4)FIELD (TBFLAG_ANY ,FPEXC_EL ,22 ,2 ) /* For A-profile only, target EL for debug exceptions. */FIELD (TBFLAG_ANY ,DEBUG_TARGET_EL ,20 ,2 ) +/* Memory operations require alignment: SCTLR_ELx.A or CCR.UNALIGN_TRP */ +FIELD (TBFLAG_ANY ,ALIGN_MEM ,19 ,1 )/* * Bit usage when in AArch32 state, both A- and M-profile.
target/arm/translate.h +2 -0
@@ -87,6 +87,8 @@ typedef struct DisasContext {bool bt;/* True if any CP15 access is trapped by HSTR_EL2 */ bool hstr_active; +/* True if memory operations require alignment */ +bool align_mem;/* * >= 0, a copy of PSTATE.BTYPE, which will be 0 without v8.5-BTI. * < 0, set by the current instruction.
target/arm/helper.c +17 -2
@@ -12775,6 +12775,12 @@ static uint32_t rebuild_hflags_m32(CPUARMState *env, int fp_el, ARMMMUIdx mmu_idx) {uint32_t flags =0 ; +uint32_t ccr = env->v7m.ccr[env->v7m.secure]; + +/* Without HaveMainExt, CCR.UNALIGN_TRP is RES1. */ +if (ccr &R_V7M_CCR_UNALIGN_TRP_MASK ) { + flags =FIELD_DP32 (flags,TBFLAG_ANY ,ALIGN_MEM ,1 ); + }if (arm_v7m_is_handler_mode (env)) { flags =FIELD_DP32 (flags,TBFLAG_M32 ,HANDLER ,1 );
@@ -12787,7 +12793,7 @@ static uint32_t rebuild_hflags_m32(CPUARMState *env, int fp_el,*/ if (arm_feature (env,ARM_FEATURE_V8 ) && !((mmu_idx &ARM_MMU_IDX_M_NEGPRI ) && - (env->v7m.ccr[env->v7m.secure] &R_V7M_CCR_STKOFHFNMIGN_MASK ))) { + (ccr &R_V7M_CCR_STKOFHFNMIGN_MASK ))) { flags =FIELD_DP32 (flags,TBFLAG_M32 ,STACKCHECK ,1 ); }
@@ -12807,12 +12813,17 @@ static uint32_t rebuild_hflags_a32(CPUARMState *env, int fp_el, ARMMMUIdx mmu_idx) {uint32_t flags =rebuild_hflags_aprofile (env); +int el =arm_current_el (env); + +if (arm_sctlr (env, el) &SCTLR_A ) { + flags =FIELD_DP32 (flags,TBFLAG_ANY ,ALIGN_MEM ,1 ); + }if (arm_el_is_aa64 (env,1 )) { flags =FIELD_DP32 (flags,TBFLAG_A32 ,VFPEN ,1 ); } -if (arm_current_el (env) <2 && env->cp15.hstr_el2 && +if (el <2 && env->cp15.hstr_el2 && (arm_hcr_el2_eff (env) & (HCR_E2H |HCR_TGE )) != (HCR_E2H |HCR_TGE )) { flags =FIELD_DP32 (flags,TBFLAG_A32 ,HSTR_ACTIVE ,1 ); }
@@ -12857,6 +12868,10 @@ static uint32_t rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, sctlr =regime_sctlr (env, stage1); +if (sctlr &SCTLR_A ) { + flags =FIELD_DP32 (flags,TBFLAG_ANY ,ALIGN_MEM ,1 ); + } +if (arm_cpu_data_is_big_endian_a64 (el, sctlr)) { flags =FIELD_DP32 (flags,TBFLAG_ANY ,BE_DATA ,1 ); }
target/arm/translate.c +3 -4
@@ -900,8 +900,7 @@ static void gen_aa32_ld_i32(DisasContext *s, TCGv_i32 val, TCGv_i32 a32, {TCGv addr; -if (arm_dc_feature (s,ARM_FEATURE_M ) && - !arm_dc_feature (s,ARM_FEATURE_M_MAIN )) { +if (s->align_mem) { opc |=MO_ALIGN ; }
@@ -915,8 +914,7 @@ static void gen_aa32_st_i32(DisasContext *s, TCGv_i32 val, TCGv_i32 a32, {TCGv addr; -if (arm_dc_feature (s,ARM_FEATURE_M ) && - !arm_dc_feature (s,ARM_FEATURE_M_MAIN )) { +if (s->align_mem) { opc |=MO_ALIGN ; }
@@ -8779,6 +8777,7 @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) dc->user = (dc->current_el ==0 );#endif dc->fp_excp_el =FIELD_EX32 (tb_flags,TBFLAG_ANY ,FPEXC_EL ); + dc->align_mem =FIELD_EX32 (tb_flags,TBFLAG_ANY ,ALIGN_MEM );if (arm_feature (env,ARM_FEATURE_M )) { dc->vfp_enabled =1 ;
Signature · 1 line
2.25.1
Re: [PATCH v2 02/24] target/arm: Add ALIGN_MEM to TBFLAG_ANY
Quoted 43 lines · Richard Henderson
Use this to signal when memory access alignment is required. This value comes from the CCR register for M-profile, and from the SCTLR register for A-profile.
Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu.h | 20 +++++++++++--------- target/arm/translate.h | 2 ++ target/arm/helper.c | 19 +++++++++++++++++-- target/arm/translate.c | 7 +++---- 4 files changed, 33 insertions(+), 15 deletions(-)target/arm/cpu.h +9
-9@@ -3220,15 +3220,15 @@ typedef ARMCPU ArchCPU;* We put flags which are shared between 32 and 64 bit mode at the top * of the word, and flags which apply to only one mode at the bottom. * -* 31 20 18 14 9 0 -* +--------------+-----+-----+----------+--------------+ -* | | | TBFLAG_A32 | | -* | | +-----+----------+ TBFLAG_AM32 | -* | TBFLAG_ANY | |TBFLAG_M32| | -* | +-----------+----------+--------------| -* | | TBFLAG_A64 | -* +--------------+-------------------------------------+ -* 31 20 0 +* 31 19 18 14 9 0 +* +--------------+---+-----+----------+--------------+ +* | | | TBFLAG_A32 | | +* | | +-----+----------+ TBFLAG_AM32 | +* | TBFLAG_ANY | |TBFLAG_M32| | +* | +---------+----------+--------------| +* | | TBFLAG_A64 | +* +--------------+-----------------------------------+ +* 31 19 0 * * Unless otherwise noted, these bits are cached in env->hflags. */
target/arm/cpu.h FIELD(TBFLAG_ANY, MMUIDX, 24, 4) · line 3245
Quoted 5 lines
target/arm/cpu.h +2
-0@@ -3241,6 +3241,8 @@ FIELD(TBFLAG_ANY, MMUIDX, 24, 4)FIELD (TBFLAG_ANY ,FPEXC_EL ,22 ,2 ) /* For A-profile only, target EL for debug exceptions. */FIELD (TBFLAG_ANY ,DEBUG_TARGET_EL ,20 ,2 ) +/* Memory operations require alignment: SCTLR_ELx.A or CCR.UNALIGN_TRP */ +FIELD (TBFLAG_ANY ,ALIGN_MEM ,19 ,1 )
This is trying to use the same bit as TBFLAG_A64 MTE0_ACTIVE... We might have to finally start in on using bits in cs_base.
thanks
-- PMM
Re: [PATCH v2 02/24] target/arm: Add ALIGN_MEM to TBFLAG_ANY
Quoted 5 lines · Peter Maydell
target/arm/cpu.h FIELD(TBFLAG_ANY, MMUIDX, 24, 4) · line 3245
Quoted 2 lines
target/arm/cpu.h +2
-0+/* Memory operations require alignment: SCTLR_ELx.A or CCR.UNALIGN_TRP */ +FIELD (TBFLAG_ANY ,ALIGN_MEM ,19 ,1 )This is trying to use the same bit as
TBFLAG_A64MTE0_ACTIVE... We might have to finally start in on using bits incs_base.
Oops. Didn't notice this as I extended from a32 to a64. And then of course didn't enable mte while testing alignment...
I'll use cs_base in the next version, moving all of the target-specific bits there, leaving only TBFLAG_ANY_* in tb->flags.
r~
PATCH v2 3/24 target/arm: Adjust gen_aa32_{ld, st}_i32 for align+endianness
In reply to Richard HendersonCreate a finalize_memop function that computes alignment and endianness and returns the final MemOp for the operation.
Split out gen_aa32_{ld,st}_internal_i32 which bypasses any special handling of endianness or alignment. Adjust gen_aa32_{ld,st}_i32 so that s->be_data is not added by the callers.
--- target/arm/translate.h | 24 ++++++++ target/arm/translate.c | 100 +++++++++++++++++--------------- target/arm/translate-neon.c.inc | 9 +-- 3 files changed, 79 insertions(+), 54 deletions(-)
target/arm/translate.h +24 -0
@@ -448,4 +448,28 @@ static inline TCGv_ptr fpstatus_ptr(ARMFPStatusFlavour flavour) return statusptr; } +/** +* finalize_memop: +* @s: DisasContext +* @opc: size+sign+align of the memory operation +* +* Build the complete MemOp for a memory operation, including alignment +* and endianness. +* +* If (op & MO_AMASK) then the operation already contains the required +* alignment, e.g. for AccType_ATOMIC. Otherwise, this an optionally +* unaligned operation, e.g. for AccType_NORMAL. +* +* In the later case, there are configuration bits that require alignment, +* and this is applied here. Note that there is no way to indicate that +* no alignment should ever be enforced; this must be handled manually. +*/ +static inline MemOp finalize_memop (DisasContext *s,MemOp opc) +{ +if (s->align_mem && !(opc &MO_AMASK )) { + opc |=MO_ALIGN ; + } +return opc | s->be_data; +} +#endif /* TARGET_ARM_TRANSLATE_H */
target/arm/translate.c +52 -48
215 lines not on this page · raw message
target/arm/translate-neon.c.inc +3 -6
@@ -559,8 +559,7 @@ static bool trans_VLD_all_lanes(DisasContext *s, arg_VLD_all_lanes *a) addr = tcg_temp_new_i32(); load_reg_var(s, addr, a->rn); for (reg = 0; reg < nregs; reg++) { - gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), - s->be_data | size); + gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), size); if ((vd & 1) && vec_size == 16) { /* * We cannot write 16 bytes at once because the
@@ -650,13 +649,11 @@ static bool trans_VLDST_single(DisasContext *s, arg_VLDST_single *a) */ for (reg = 0; reg < nregs; reg++) { if (a->l) { - gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), - s->be_data | a->size); + gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), a->size); neon_store_element(vd, a->reg_idx, a->size, tmp); } else { /* Store */ neon_load_element(tmp, vd, a->reg_idx, a->size); - gen_aa32_st_i32(s, tmp, addr, get_mem_index(s), - s->be_data | a->size); + gen_aa32_st_i32(s, tmp, addr, get_mem_index(s), a->size); } vd += a->stride; tcg_gen_addi_i32(addr, addr, 1 << a->size);
Signature · 1 line
2.25.1
Re: [PATCH v2 03/24] target/arm: Adjust gen_aa32_{ld, st}_i32 for align+endianness
Quoted 26 lines · Richard Henderson
Create a
finalize_memopfunction that computes alignment and endianness and returns the final MemOp for the operation.Split out gen_aa32_{ld,st}_internal_i32 which bypasses any special handling of endianness or alignment. Adjust gen_aa32_{ld,st}_i32 so that
s->be_datais not added by the callers.Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate.h | 24 ++++++++ target/arm/translate.c | 100 +++++++++++++++++--------------- target/arm/translate-neon.c.inc | 9 +-- 3 files changed, 79 insertions(+), 54 deletions(-)target/arm/translate.h +3
-0@@ -448,4 +448,28 @@ static inline TCGv_ptr fpstatus_ptr(ARMFPStatusFlavour flavour)return statusptr; } +/** +* finalize_memop: +* @s: DisasContext
target/arm/translate.h static inline TCGv_ptr fpstatus_ptr(ARMFPStatusFlavour flavour) · line 463
Quoted 10 lines
target/arm/translate.h +10
-0+* @opc: size+sign+align of the memory operation +* +* Build the complete MemOp for a memory operation, including alignment +* and endianness. +* +* If (op & MO_AMASK) then the operation already contains the required +* alignment, e.g. for AccType_ATOMIC. Otherwise, this an optionally +* unaligned operation, e.g. for AccType_NORMAL. +* +* In the later case, there are configuration bits that require alignment,
"latter case".
Quoted 15 lines
target/arm/translate.h +14
-0+* and this is applied here. Note that there is no way to indicate that +* no alignment should ever be enforced; this must be handled manually. +*/ +static inline MemOp finalize_memop (DisasContext *s,MemOp opc) +{ +if (s->align_mem && !(opc &MO_AMASK )) { + opc |=MO_ALIGN ; + } +return opc | s->be_data; +} + +#define DO_GEN_LD (SUFF ,OPC ) \ + static inline void gen_aa32_ld##SUFF(DisasContext *s, TCGv_i32 val, \ + TCGv_i32 a32, int index) \
target/arm/translate.h static inline TCGv_ptr fpstatus_ptr(ARMFPStatusFlavour flavour)
Quoted 10 lines
target/arm/translate.h +8
-0+ { \ +gen_aa32_ld_i32 (s, val, a32, index,OPC ); \ } +#define DO_GEN_ST (SUFF ,OPC ) \ + static inline void gen_aa32_st##SUFF(DisasContext *s, TCGv_i32 val, \ + TCGv_i32 a32, int index) \ + { \ + gen_aa32_st_i32(s, val, a32, index, OPC); \ + }
Since these generated functions no longer do anything extra that the gen_aa32_{ld,st}_i32() that the call don't do, we could reasonably have a follow-on patch that makes all the callsites directly call those functions and remove the extra layer of indirection, I think. The main reason we had them before was so that we had somewhere to add the handling of s->be_data.
For this patch, other than the typo above,
thanks
-- PMM
PATCH v2 4/24 target/arm: Merge gen_aa32_frob64 into gen_aa32_ld_i64
In reply to Richard HendersonThis is the only caller. Adjust some commentary to talk about SCTLR_B instead of the vanishing function.
--- target/arm/translate.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-)
target/arm/translate.c +16 -21
@@ -942,20 +942,17 @@ static void gen_aa32_st_i32(DisasContext *s, TCGv_i32 val, TCGv_i32 a32,gen_aa32_st_i32 (s, val, a32, index,OPC ); \ } -static inline void gen_aa32_frob64 (DisasContext *s,TCGv_i64 val) -{ -/* Not needed for user-mode BE32, where we use MO_BE instead. */ -if (!IS_USER_ONLY && s->sctlr_b) { -tcg_gen_rotri_i64 (val, val,32 ); - } -} -static void gen_aa32_ld_i64 (DisasContext *s,TCGv_i64 val,TCGv_i32 a32,int index,MemOp opc) {TCGv addr =gen_aa32_addr (s, a32, opc);tcg_gen_qemu_ld_i64 (val, addr, index, opc); -gen_aa32_frob64 (s, val); + +/* Not needed for user-mode BE32, where we use MO_BE instead. */ +if (!IS_USER_ONLY && s->sctlr_b) { +tcg_gen_rotri_i64 (val, val,32 ); + } +tcg_temp_free (addr); }
@@ -4921,16 +4918,13 @@ static void gen_load_exclusive(DisasContext *s, int rt, int rt2,TCGv_i32 tmp2 =tcg_temp_new_i32 ();TCGv_i64 t64 =tcg_temp_new_i64 (); -/* For AArch32, architecturally the 32-bit word at the lowest +/* +* For AArch32, architecturally the 32-bit word at the lowest * address is always Rt and the one at addr+4 is Rt2, even if * the CPU is big-endian. That means we don't want to do a -* gen_aa32_ld_i64(), which invokes gen_aa32_frob64() as if -* for an architecturally 64-bit access, but instead do a -* 64-bit access using MO_BE if appropriate and then split -* the two halves. -* This only makes a difference for BE32 user-mode, where -* frob64() must not flip the two halves of the 64-bit data -* but this code must treat BE32 user-mode like BE32 system. +* gen_aa32_ld_i64(), which checks SCTLR_B as if for an +* architecturally 64-bit access, but instead do a 64-bit access +* using MO_BE if appropriate and then split the two halves. */ TCGv taddr =gen_aa32_addr (s, addr, opc);
@@ -4990,14 +4984,15 @@ static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,TCGv_i64 n64 =tcg_temp_new_i64 (); t2 =load_reg (s, rt2); -/* For AArch32, architecturally the 32-bit word at the lowest + +/* +* For AArch32, architecturally the 32-bit word at the lowest * address is always Rt and the one at addr+4 is Rt2, even if * the CPU is big-endian. Since we're going to treat this as a * single 64-bit BE store, we need to put the two halves in the * opposite order for BE to LE, so that they end up in the right -* places. -* We don't want gen_aa32_frob64() because that does the wrong -* thing for BE32 usermode. +* places. We don't want gen_aa32_st_i64, because that checks +* SCTLR_B as if for an architectural 64-bit access. */ if (s->be_data ==MO_BE ) {tcg_gen_concat_i32_i64 (n64, t2, t1);
Signature · 1 line
2.25.1
Re: [PATCH v2 04/24] target/arm: Merge gen_aa32_frob64 into gen_aa32_ld_i64
Quoted 8 lines · Richard Henderson
This is the only caller. Adjust some commentary to talk about
SCTLR_Binstead of the vanishing function.Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-)
thanks
-- PMM
PATCH v2 5/24 target/arm: Fix SCTLR_B test for TCGv_i64 load/store
In reply to Richard HendersonJust because operating on a TCGv_i64 temporary does not mean that we're performing a 64-bit operation. Restrict the frobbing to actual 64-bit operations.
--- target/arm/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/translate.c +2 -2
@@ -949,7 +949,7 @@ static void gen_aa32_ld_i64(DisasContext *s, TCGv_i64 val, TCGv_i32 a32,tcg_gen_qemu_ld_i64 (val, addr, index, opc);/* Not needed for user-mode BE32, where we use MO_BE instead. */ -if (!IS_USER_ONLY && s->sctlr_b) { +if (!IS_USER_ONLY && s->sctlr_b && (opc &MO_SIZE ) ==MO_64 ) {tcg_gen_rotri_i64 (val, val,32 ); }
@@ -968,7 +968,7 @@ static void gen_aa32_st_i64(DisasContext *s, TCGv_i64 val, TCGv_i32 a32,TCGv addr =gen_aa32_addr (s, a32, opc);/* Not needed for user-mode BE32, where we use MO_BE instead. */ -if (!IS_USER_ONLY && s->sctlr_b) { +if (!IS_USER_ONLY && s->sctlr_b && (opc &MO_SIZE ) ==MO_64 ) {TCGv_i64 tmp =tcg_temp_new_i64 ();tcg_gen_rotri_i64 (tmp, val,32 );tcg_gen_qemu_st_i64 (tmp, addr, index, opc);
Signature · 1 line
2.25.1
Re: [PATCH v2 05/24] target/arm: Fix SCTLR_B test for TCGv_i64 load/store
Quoted 4 lines · Richard Henderson
Just because operating on a
TCGv_i64temporary does not mean that we're performing a 64-bit operation. Restrict the frobbing to actual 64-bit operations.
If I understand correctly, this patch isn't actually a behaviour change because at this point the only users of gen_aa32_ld_i64() and gen_aa32_st_i64() are in fact performing 64-bit operations so the (opc & MO_SIZE) == MO_64 test is always true. (Presumably subsequent patches are going to add uses of these functions that want to load smaller sizes?) If that's right, worth mentioning explicitly in the commit message, I think.
Quoted 19 lines
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/arm/translate.c +1
-1@@ -949,7 +949,7 @@ static void gen_aa32_ld_i64(DisasContext *s, TCGv_i64 val, TCGv_i32 a32,tcg_gen_qemu_ld_i64 (val, addr, index, opc);/* Not needed for user-mode BE32, where we use MO_BE instead. */ -if (!IS_USER_ONLY && s->sctlr_b) { +if (!IS_USER_ONLY && s->sctlr_b && (opc &MO_SIZE ) ==MO_64 ) {tcg_gen_rotri_i64 (val, val,32 ); }
target/arm/translate.c static void gen_aa32_st_i64(DisasContext *s, TCGv_i64 val, TCGv_i32 a32, · line 974
Quoted 8 lines
target/arm/translate.c +1
-1@@ -968,7 +968,7 @@ static void gen_aa32_st_i64(DisasContext *s, TCGv_i64 val, TCGv_i32 a32,TCGv addr =gen_aa32_addr (s, a32, opc);/* Not needed for user-mode BE32, where we use MO_BE instead. */ -if (!IS_USER_ONLY && s->sctlr_b) { +if (!IS_USER_ONLY && s->sctlr_b && (opc &MO_SIZE ) ==MO_64 ) {TCGv_i64 tmp =tcg_temp_new_i64 ();tcg_gen_rotri_i64 (tmp, val,32 );tcg_gen_qemu_st_i64 (tmp, addr, index, opc);
Otherwise
thanks
-- PMM
Re: [PATCH v2 05/24] target/arm: Fix SCTLR_B test for TCGv_i64 load/store
Quoted 11 lines · Peter Maydell
Quoted 4 lines · Richard Henderson
Just because operating on a
TCGv_i64temporary does not mean that we're performing a 64-bit operation. Restrict the frobbing to actual 64-bit operations.If I understand correctly, this patch isn't actually a behaviour change because at this point the only users of
gen_aa32_ld_i64()andgen_aa32_st_i64()are in fact performing 64-bit operations so the (opc &MO_SIZE) ==MO_64test is always true.
Correct.
Quoted 3 lines
(Presumably
subsequent patches are going to add uses of these functions that want to load smaller sizes?)
Correct.
Quoted 2 lines
If that's right, worth mentioning
explicitly in the commit message, I think.
Will do.
r~
PATCH v2 6/24 target/arm: Adjust gen_aa32_{ld, st}_i64 for align+endianness
In reply to Richard HendersonAdjust the interface to match what has been done to the TCGv_i32 load/store functions.
This is less obvious, because at present the only user of these functions, trans_VLDST_multiple, also wants to manipulate the endianness to speed up loading multiple bytes. Thus we retain an "internal" interface which is identical to the current gen_aa32_{ld,st}_i64 interface.
The "new" interface will gain users as we remove the legacy interfaces, gen_aa32_ld64 and gen_aa32_st64.
--- target/arm/translate.c | 78 +++++++++++++++++++-------------- target/arm/translate-neon.c.inc | 6 ++- 2 files changed, 49 insertions(+), 35 deletions(-)
target/arm/translate.c +45 -33
@@ -916,6 +916,37 @@ static void gen_aa32_st_internal_i32(DisasContext *s, TCGv_i32 val,tcg_temp_free (addr); } +static void gen_aa32_ld_internal_i64 (DisasContext *s,TCGv_i64 val, +TCGv_i32 a32,int index,MemOp opc) +{ +TCGv addr =gen_aa32_addr (s, a32, opc); + +tcg_gen_qemu_ld_i64 (val, addr, index, opc); + +/* Not needed for user-mode BE32, where we use MO_BE instead. */ +if (!IS_USER_ONLY && s->sctlr_b && (opc &MO_SIZE ) ==MO_64 ) { +tcg_gen_rotri_i64 (val, val,32 ); + } +tcg_temp_free (addr); +} + +static void gen_aa32_st_internal_i64 (DisasContext *s,TCGv_i64 val, +TCGv_i32 a32,int index,MemOp opc) +{ +TCGv addr =gen_aa32_addr (s, a32, opc); + +/* Not needed for user-mode BE32, where we use MO_BE instead. */ +if (!IS_USER_ONLY && s->sctlr_b && (opc &MO_SIZE ) ==MO_64 ) { +TCGv_i64 tmp =tcg_temp_new_i64 (); +tcg_gen_rotri_i64 (tmp, val,32 ); +tcg_gen_qemu_st_i64 (tmp, addr, index, opc); +tcg_temp_free_i64 (tmp); + }else { +tcg_gen_qemu_st_i64 (val, addr, index, opc); + } +tcg_temp_free (addr); +} +static void gen_aa32_ld_i32 (DisasContext *s,TCGv_i32 val,TCGv_i32 a32,int index,MemOp opc) {
@@ -928,6 +959,18 @@ static void gen_aa32_st_i32(DisasContext *s, TCGv_i32 val, TCGv_i32 a32,gen_aa32_st_internal_i32 (s, val, a32, index,finalize_memop (s, opc)); } +static void gen_aa32_ld_i64 (DisasContext *s,TCGv_i64 val,TCGv_i32 a32, +int index,MemOp opc) +{ +gen_aa32_ld_internal_i64 (s, val, a32, index,finalize_memop (s, opc)); +} + +static void gen_aa32_st_i64 (DisasContext *s,TCGv_i64 val,TCGv_i32 a32, +int index,MemOp opc) +{ +gen_aa32_st_internal_i64 (s, val, a32, index,finalize_memop (s, opc)); +} +#define DO_GEN_LD (SUFF ,OPC ) \ static inline void gen_aa32_ld##SUFF(DisasContext *s, TCGv_i32 val, \ TCGv_i32 a32, int index) \
@@ -942,47 +985,16 @@ static void gen_aa32_st_i32(DisasContext *s, TCGv_i32 val, TCGv_i32 a32,gen_aa32_st_i32 (s, val, a32, index,OPC ); \ } -static void gen_aa32_ld_i64 (DisasContext *s,TCGv_i64 val,TCGv_i32 a32, -int index,MemOp opc) -{ -TCGv addr =gen_aa32_addr (s, a32, opc); -tcg_gen_qemu_ld_i64 (val, addr, index, opc); - -/* Not needed for user-mode BE32, where we use MO_BE instead. */ -if (!IS_USER_ONLY && s->sctlr_b && (opc &MO_SIZE ) ==MO_64 ) { -tcg_gen_rotri_i64 (val, val,32 ); - } - -tcg_temp_free (addr); -} -static inline void gen_aa32_ld64 (DisasContext *s,TCGv_i64 val,TCGv_i32 a32,int index) { -gen_aa32_ld_i64 (s, val, a32, index,MO_Q | s->be_data); -} - -static void gen_aa32_st_i64 (DisasContext *s,TCGv_i64 val,TCGv_i32 a32, -int index,MemOp opc) -{ -TCGv addr =gen_aa32_addr (s, a32, opc); - -/* Not needed for user-mode BE32, where we use MO_BE instead. */ -if (!IS_USER_ONLY && s->sctlr_b && (opc &MO_SIZE ) ==MO_64 ) { -TCGv_i64 tmp =tcg_temp_new_i64 (); -tcg_gen_rotri_i64 (tmp, val,32 ); -tcg_gen_qemu_st_i64 (tmp, addr, index, opc); -tcg_temp_free_i64 (tmp); - }else { -tcg_gen_qemu_st_i64 (val, addr, index, opc); - } -tcg_temp_free (addr); +gen_aa32_ld_i64 (s, val, a32, index,MO_Q ); }static inline void gen_aa32_st64 (DisasContext *s,TCGv_i64 val,TCGv_i32 a32,int index) { -gen_aa32_st_i64 (s, val, a32, index,MO_Q | s->be_data); +gen_aa32_st_i64 (s, val, a32, index,MO_Q ); }DO_GEN_LD (8u ,MO_UB )
target/arm/translate-neon.c.inc +4 -2
@@ -494,11 +494,13 @@ static bool trans_VLDST_multiple(DisasContext *s, arg_VLDST_multiple *a) int tt = a->vd + reg + spacing * xs; if (a->l) { - gen_aa32_ld_i64(s, tmp64, addr, mmu_idx, endian | size); + gen_aa32_ld_internal_i64(s, tmp64, addr, mmu_idx, + endian | size); neon_store_element64(tt, n, size, tmp64); } else { neon_load_element64(tmp64, tt, n, size); - gen_aa32_st_i64(s, tmp64, addr, mmu_idx, endian | size); + gen_aa32_st_internal_i64(s, tmp64, addr, mmu_idx, + endian | size); } tcg_gen_add_i32(addr, addr, tmp); }
Signature · 1 line
2.25.1
Re: [PATCH v2 06/24] target/arm: Adjust gen_aa32_{ld, st}_i64 for align+endianness
Quoted 10 lines · Richard Henderson
Adjust the interface to match what has been done to the
TCGv_i32load/store functions.This is less obvious, because at present the only user of these functions,
trans_VLDST_multiple, also wants to manipulate the endianness to speed up loading multiple bytes. Thus we retain an "internal" interface which is identical to the current gen_aa32_{ld,st}_i64 interface.
Quoted 4 lines
The "new" interface will gain users as we remove the legacy interfaces,
gen_aa32_ld64andgen_aa32_st64.Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v2 7/24 target/arm: Enforce word alignment for LDRD/STRD
In reply to Richard Henderson--- target/arm/translate.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
target/arm/translate.c +8 -8
@@ -6468,13 +6468,13 @@ static bool trans_LDRD_rr(DisasContext *s, arg_ldst_rr *a) addr =op_addr_rr_pre (s, a); tmp =tcg_temp_new_i32 (); -gen_aa32_ld_i32 (s, tmp, addr, mem_idx,MO_UL ); +gen_aa32_ld_i32 (s, tmp, addr, mem_idx,MO_UL |MO_ALIGN );store_reg (s, a->rt, tmp);tcg_gen_addi_i32 (addr, addr,4 ); tmp =tcg_temp_new_i32 (); -gen_aa32_ld_i32 (s, tmp, addr, mem_idx,MO_UL ); +gen_aa32_ld_i32 (s, tmp, addr, mem_idx,MO_UL |MO_ALIGN );store_reg (s, a->rt +1 , tmp);/* LDRD w/ base writeback is undefined if the registers overlap. */
@@ -6497,13 +6497,13 @@ static bool trans_STRD_rr(DisasContext *s, arg_ldst_rr *a) addr =op_addr_rr_pre (s, a); tmp =load_reg (s, a->rt); -gen_aa32_st_i32 (s, tmp, addr, mem_idx,MO_UL ); +gen_aa32_st_i32 (s, tmp, addr, mem_idx,MO_UL |MO_ALIGN );tcg_temp_free_i32 (tmp);tcg_gen_addi_i32 (addr, addr,4 ); tmp =load_reg (s, a->rt +1 ); -gen_aa32_st_i32 (s, tmp, addr, mem_idx,MO_UL ); +gen_aa32_st_i32 (s, tmp, addr, mem_idx,MO_UL |MO_ALIGN );tcg_temp_free_i32 (tmp);op_addr_rr_post (s, a, addr,-4 );
@@ -6605,13 +6605,13 @@ static bool op_ldrd_ri(DisasContext *s, arg_ldst_ri *a, int rt2) addr =op_addr_ri_pre (s, a); tmp =tcg_temp_new_i32 (); -gen_aa32_ld_i32 (s, tmp, addr, mem_idx,MO_UL ); +gen_aa32_ld_i32 (s, tmp, addr, mem_idx,MO_UL |MO_ALIGN );store_reg (s, a->rt, tmp);tcg_gen_addi_i32 (addr, addr,4 ); tmp =tcg_temp_new_i32 (); -gen_aa32_ld_i32 (s, tmp, addr, mem_idx,MO_UL ); +gen_aa32_ld_i32 (s, tmp, addr, mem_idx,MO_UL |MO_ALIGN );store_reg (s, rt2, tmp);/* LDRD w/ base writeback is undefined if the registers overlap. */
@@ -6644,13 +6644,13 @@ static bool op_strd_ri(DisasContext *s, arg_ldst_ri *a, int rt2) addr =op_addr_ri_pre (s, a); tmp =load_reg (s, a->rt); -gen_aa32_st_i32 (s, tmp, addr, mem_idx,MO_UL ); +gen_aa32_st_i32 (s, tmp, addr, mem_idx,MO_UL |MO_ALIGN );tcg_temp_free_i32 (tmp);tcg_gen_addi_i32 (addr, addr,4 ); tmp =load_reg (s, rt2); -gen_aa32_st_i32 (s, tmp, addr, mem_idx,MO_UL ); +gen_aa32_st_i32 (s, tmp, addr, mem_idx,MO_UL |MO_ALIGN );tcg_temp_free_i32 (tmp);op_addr_ri_post (s, a, addr,-4 );
Signature · 1 line
2.25.1
Re: [PATCH v2 07/24] target/arm: Enforce word alignment for LDRD/STRD
Quoted 6 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
thanks
-- PMM
PATCH v2 8/24 target/arm: Enforce alignment for LDA/LDAH/STL/STLH
In reply to Richard Henderson--- target/arm/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/translate.c +2 -2
@@ -6876,7 +6876,7 @@ static bool op_stl(DisasContext *s, arg_STL *a, MemOp mop) addr =load_reg (s, a->rn); tmp =load_reg (s, a->rt);tcg_gen_mb (TCG_MO_ALL |TCG_BAR_STRL ); -gen_aa32_st_i32 (s, tmp, addr,get_mem_index (s), mop); +gen_aa32_st_i32 (s, tmp, addr,get_mem_index (s), mop |MO_ALIGN );disas_set_da_iss (s, mop, a->rt | ISSIsAcqRel | ISSIsWrite);tcg_temp_free_i32 (tmp);
@@ -7032,7 +7032,7 @@ static bool op_lda(DisasContext *s, arg_LDA *a, MemOp mop) addr =load_reg (s, a->rn); tmp =tcg_temp_new_i32 (); -gen_aa32_ld_i32 (s, tmp, addr,get_mem_index (s), mop); +gen_aa32_ld_i32 (s, tmp, addr,get_mem_index (s), mop |MO_ALIGN );disas_set_da_iss (s, mop, a->rt | ISSIsAcqRel);tcg_temp_free_i32 (addr);
Signature · 1 line
2.25.1
Re: [PATCH v2 08/24] target/arm: Enforce alignment for LDA/LDAH/STL/STLH
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
thanks
-- PMM
PATCH v2 9/24 target/arm: Enforce alignment for LDM/STM
In reply to Richard Henderson--- target/arm/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/translate.c +2 -2
@@ -7824,7 +7824,7 @@ static bool op_stm(DisasContext *s, arg_ldst_block *a, int min_n) }else { tmp =load_reg (s, i); } -gen_aa32_st32 (s, tmp, addr, mem_idx); +gen_aa32_st_i32 (s, tmp, addr, mem_idx,MO_UL |MO_ALIGN );tcg_temp_free_i32 (tmp);/* No need to add after the last transfer. */
@@ -7899,7 +7899,7 @@ static bool do_ldm(DisasContext *s, arg_ldst_block *a, int min_n) } tmp =tcg_temp_new_i32 (); -gen_aa32_ld32u (s, tmp, addr, mem_idx); +gen_aa32_ld_i32 (s, tmp, addr, mem_idx,MO_UL |MO_ALIGN );if (user) { tmp2 =tcg_const_i32 (i);gen_helper_set_user_reg (cpu_env, tmp2, tmp);
Signature · 1 line
2.25.1
Re: [PATCH v2 09/24] target/arm: Enforce alignment for LDM/STM
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
thanks
-- PMM
PATCH v2 10/24 target/arm: Enforce alignment for RFE
In reply to Richard Henderson--- target/arm/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/translate.c +2 -2
@@ -8259,10 +8259,10 @@ static bool trans_RFE(DisasContext *s, arg_RFE *a)/* Load PC into tmp and CPSR into tmp2. */ t1 =tcg_temp_new_i32 (); -gen_aa32_ld32u (s, t1, addr,get_mem_index (s)); +gen_aa32_ld_i32 (s, t1, addr,get_mem_index (s),MO_UL |MO_ALIGN );tcg_gen_addi_i32 (addr, addr,4 ); t2 =tcg_temp_new_i32 (); -gen_aa32_ld32u (s, t2, addr,get_mem_index (s)); +gen_aa32_ld_i32 (s, t2, addr,get_mem_index (s),MO_UL |MO_ALIGN );if (a->w) {/* Base writeback. */
Signature · 1 line
2.25.1
Re: [PATCH v2 10/24] target/arm: Enforce alignment for RFE
Quoted 6 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
thanks
-- PMM
PATCH v2 11/24 target/arm: Enforce alignment for SRS
In reply to Richard Henderson--- target/arm/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/translate.c +2 -2
@@ -5134,11 +5134,11 @@ static void gen_srs(DisasContext *s, }tcg_gen_addi_i32 (addr, addr, offset); tmp =load_reg (s,14 ); -gen_aa32_st32 (s, tmp, addr,get_mem_index (s)); +gen_aa32_st_i32 (s, tmp, addr,get_mem_index (s),MO_UL |MO_ALIGN );tcg_temp_free_i32 (tmp); tmp =load_cpu_field (spsr);tcg_gen_addi_i32 (addr, addr,4 ); -gen_aa32_st32 (s, tmp, addr,get_mem_index (s)); +gen_aa32_st_i32 (s, tmp, addr,get_mem_index (s),MO_UL |MO_ALIGN );tcg_temp_free_i32 (tmp);if (writeback) {switch (amode) {
Signature · 1 line
2.25.1
Re: [PATCH v2 11/24] target/arm: Enforce alignment for SRS
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
thanks
-- PMM
PATCH v2 12/24 target/arm: Enforce alignment for VLDM/VSTM
In reply to Richard Henderson--- target/arm/translate-vfp.c.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/arm/translate-vfp.c.inc +4 -4
@@ -1065,12 +1065,12 @@ static bool trans_VLDM_VSTM_sp(DisasContext *s, arg_VLDM_VSTM_sp *a) for (i = 0; i < n; i++) { if (a->l) { /* load */ - gen_aa32_ld32u(s, tmp, addr, get_mem_index(s)); + gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), MO_UL | MO_ALIGN); vfp_store_reg32(tmp, a->vd + i); } else { /* store */ vfp_load_reg32(tmp, a->vd + i); - gen_aa32_st32(s, tmp, addr, get_mem_index(s)); + gen_aa32_st_i32(s, tmp, addr, get_mem_index(s), MO_UL | MO_ALIGN); } tcg_gen_addi_i32(addr, addr, offset); }
@@ -1148,12 +1148,12 @@ static bool trans_VLDM_VSTM_dp(DisasContext *s, arg_VLDM_VSTM_dp *a) for (i = 0; i < n; i++) { if (a->l) { /* load */ - gen_aa32_ld64(s, tmp, addr, get_mem_index(s)); + gen_aa32_ld_i64(s, tmp, addr, get_mem_index(s), MO_Q | MO_ALIGN_4); vfp_store_reg64(tmp, a->vd + i); } else { /* store */ vfp_load_reg64(tmp, a->vd + i); - gen_aa32_st64(s, tmp, addr, get_mem_index(s)); + gen_aa32_st_i64(s, tmp, addr, get_mem_index(s), MO_Q | MO_ALIGN_4); } tcg_gen_addi_i32(addr, addr, offset); }
Signature · 1 line
2.25.1
Re: [PATCH v2 12/24] target/arm: Enforce alignment for VLDM/VSTM
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate-vfp.c.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
thanks
-- PMM
PATCH v2 13/24 target/arm: Enforce alignment for VLDR/VSTR
In reply to Richard Henderson--- target/arm/translate-vfp.c.inc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
target/arm/translate-vfp.c.inc +6 -6
@@ -926,11 +926,11 @@ static bool trans_VLDR_VSTR_hp(DisasContext *s, arg_VLDR_VSTR_sp *a) addr = add_reg_for_lit(s, a->rn, offset); tmp = tcg_temp_new_i32(); if (a->l) { - gen_aa32_ld16u(s, tmp, addr, get_mem_index(s)); + gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), MO_UW | MO_ALIGN); vfp_store_reg32(tmp, a->vd); } else { vfp_load_reg32(tmp, a->vd); - gen_aa32_st16(s, tmp, addr, get_mem_index(s)); + gen_aa32_st_i32(s, tmp, addr, get_mem_index(s), MO_UW | MO_ALIGN); } tcg_temp_free_i32(tmp); tcg_temp_free_i32(addr);
@@ -960,11 +960,11 @@ static bool trans_VLDR_VSTR_sp(DisasContext *s, arg_VLDR_VSTR_sp *a) addr = add_reg_for_lit(s, a->rn, offset); tmp = tcg_temp_new_i32(); if (a->l) { - gen_aa32_ld32u(s, tmp, addr, get_mem_index(s)); + gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), MO_UL | MO_ALIGN); vfp_store_reg32(tmp, a->vd); } else { vfp_load_reg32(tmp, a->vd); - gen_aa32_st32(s, tmp, addr, get_mem_index(s)); + gen_aa32_st_i32(s, tmp, addr, get_mem_index(s), MO_UL | MO_ALIGN); } tcg_temp_free_i32(tmp); tcg_temp_free_i32(addr);
@@ -1001,11 +1001,11 @@ static bool trans_VLDR_VSTR_dp(DisasContext *s, arg_VLDR_VSTR_dp *a) addr = add_reg_for_lit(s, a->rn, offset); tmp = tcg_temp_new_i64(); if (a->l) { - gen_aa32_ld64(s, tmp, addr, get_mem_index(s)); + gen_aa32_ld_i64(s, tmp, addr, get_mem_index(s), MO_Q | MO_ALIGN_4); vfp_store_reg64(tmp, a->vd); } else { vfp_load_reg64(tmp, a->vd); - gen_aa32_st64(s, tmp, addr, get_mem_index(s)); + gen_aa32_st_i64(s, tmp, addr, get_mem_index(s), MO_Q | MO_ALIGN_4); } tcg_temp_free_i64(tmp); tcg_temp_free_i32(addr);
Signature · 1 line
2.25.1
Re: [PATCH v2 13/24] target/arm: Enforce alignment for VLDR/VSTR
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate-vfp.c.inc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
thanks
-- PMM
PATCH v2 14/24 target/arm: Enforce alignment for VLD1 (all lanes)
In reply to Richard Henderson--- target/arm/translate-neon.c.inc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/arm/translate-neon.c.inc +3 -2
@@ -522,6 +522,7 @@ static bool trans_VLD_all_lanes(DisasContext *s, arg_VLD_all_lanes *a) int size = a->size; int nregs = a->n + 1; TCGv_i32 addr, tmp; + MemOp mop; if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { return false;
@@ -556,12 +557,12 @@ static bool trans_VLD_all_lanes(DisasContext *s, arg_VLD_all_lanes *a) */ stride = a->t ? 2 : 1; vec_size = nregs == 1 ? stride * 8 : 8; - + mop = size | (a->a ? MO_ALIGN : 0); tmp = tcg_temp_new_i32(); addr = tcg_temp_new_i32(); load_reg_var(s, addr, a->rn); for (reg = 0; reg < nregs; reg++) { - gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), size); + gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), mop); if ((vd & 1) && vec_size == 16) { /* * We cannot write 16 bytes at once because the
Signature · 1 line
2.25.1
Re: [PATCH v2 14/24] target/arm: Enforce alignment for VLD1 (all lanes)
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate-neon.c.inc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Patch subject says "VLD1", but trans_VLD_all_lanes handles all of the "VLDn to all lanes" insns.
Quoted 17 lines
target/arm/translate-neon.c.inc +1
-1@@ -522,6 +522,7 @@ static bool trans_VLD_all_lanes(DisasContext *s, arg_VLD_all_lanes *a) int size = a->size; int nregs = a->n + 1; TCGv_i32 addr, tmp; + MemOp mop; if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { return false;@@ -556,12 +557,12 @@ static bool trans_VLD_all_lanes(DisasContext *s, arg_VLD_all_lanes *a) */ stride = a->t ? 2 : 1; vec_size = nregs == 1 ? stride * 8 : 8; -
target/arm/translate-neon.c.inc static bool trans_VLD_all_lanes(DisasContext *s, arg_VLD_all_lanes *a) · line 568
Quoted 10 lines
target/arm/translate-neon.c.inc +2
-1+ mop = size | (a->a ? MO_ALIGN : 0); tmp = tcg_temp_new_i32(); addr = tcg_temp_new_i32(); load_reg_var(s, addr, a->rn); for (reg = 0; reg < nregs; reg++) { - gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), size); + gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), mop); if ((vd & 1) && vec_size == 16) { /* * We cannot write 16 bytes at once because the
I think this code is correct for VLD1 (A bit means "address must be aligned to the size of the element") and VLD3 (A bit is always 0), but not for VLD2 (A bit means "address must be aligned to 2* size of element") or VLD4 (A bit means "address must be aligned to 4* size", and there is a special case for size==3 meaning "32 bits at 16-byte alignment").
thanks
-- PMM
PATCH v2 15/24 target/arm: Enforce alignment for VLDn/VSTn (multiple)
In reply to Richard Henderson--- target/arm/translate.h | 1 + target/arm/translate.c | 15 +++++++++++++++ target/arm/translate-neon.c.inc | 27 ++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 5 deletions(-)
target/arm/translate.h +1 -0
@@ -204,6 +204,7 @@ void arm_test_cc(DisasCompare *cmp, int cc);void arm_free_cc (DisasCompare *cmp);void arm_jump_cc (DisasCompare *cmp,TCGLabel *label);void arm_gen_test_cc (int cc,TCGLabel *label); +MemOp pow2_align (unsigned i);/* Return state of Alternate Half-precision flag, caller frees result */ static inline TCGv_i32 get_ahp_flag (void )
target/arm/translate.c +15 -0
@@ -875,6 +875,21 @@ static inline void store_reg_from_load(DisasContext *s, int reg, TCGv_i32 var)#define IS_USER_ONLY 0#endif +MemOp pow2_align (unsigned i) +{ +static const MemOp mop_align[] = { +0 ,MO_ALIGN_2 ,MO_ALIGN_4 ,MO_ALIGN_8 ,MO_ALIGN_16 , +/* +* FIXME: TARGET_PAGE_BITS_MIN affects TLB_FLAGS_MASK such +* that 256-bit alignment (MO_ALIGN_32) cannot be supported: +* see get_alignment_bits(). Enforce only 128-bit alignment for now. +*/ +MO_ALIGN_16 + }; +g_assert (i <ARRAY_SIZE (mop_align)); +return mop_align[i]; +} +/* * Abstractions of "generate code to do a guest load/store for * AArch32", where a vaddr is always 32 bits (and is zero
target/arm/translate-neon.c.inc +22 -5
@@ -429,7 +429,7 @@ static bool trans_VLDST_multiple(DisasContext *s, arg_VLDST_multiple *a) { /* Neon load/store multiple structures */ int nregs, interleave, spacing, reg, n; - MemOp endian = s->be_data; + MemOp mop, align, endian; int mmu_idx = get_mem_index(s); int size = a->size; TCGv_i64 tmp64;
@@ -473,20 +473,36 @@ static bool trans_VLDST_multiple(DisasContext *s, arg_VLDST_multiple *a) } /* For our purposes, bytes are always little-endian. */ + endian = s->be_data; if (size == 0) { endian = MO_LE; } + + /* Enforce alignment requested by the instruction */ + if (a->align) { + align = pow2_align(a->align + 2); /* 4 ** a->align */ + } else { + align = s->align_mem ? MO_ALIGN : 0; + } + /* * Consecutive little-endian elements from a single register * can be promoted to a larger little-endian operation. */ if (interleave == 1 && endian == MO_LE) { + /* Retain any natural alignment. */ + if (align == MO_ALIGN) { + align = pow2_align(size); + } size = 3; } + tmp64 = tcg_temp_new_i64(); addr = tcg_temp_new_i32(); tmp = tcg_const_i32(1 << size); load_reg_var(s, addr, a->rn); + + mop = endian | size | align; for (reg = 0; reg < nregs; reg++) { for (n = 0; n < 8 >> size; n++) { int xs;
@@ -494,15 +510,16 @@ static bool trans_VLDST_multiple(DisasContext *s, arg_VLDST_multiple *a) int tt = a->vd + reg + spacing * xs; if (a->l) { - gen_aa32_ld_internal_i64(s, tmp64, addr, mmu_idx, - endian | size); + gen_aa32_ld_internal_i64(s, tmp64, addr, mmu_idx, mop); neon_store_element64(tt, n, size, tmp64); } else { neon_load_element64(tmp64, tt, n, size); - gen_aa32_st_internal_i64(s, tmp64, addr, mmu_idx, - endian | size); + gen_aa32_st_internal_i64(s, tmp64, addr, mmu_idx, mop); } tcg_gen_add_i32(addr, addr, tmp); + + /* Subsequent memory operations inherit alignment */ + mop &= ~MO_AMASK; } } }
Signature · 1 line
2.25.1
Re: [PATCH v2 15/24] target/arm: Enforce alignment for VLDn/VSTn (multiple)
Quoted 7 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate.h | 1 + target/arm/translate.c | 15 +++++++++++++++ target/arm/translate-neon.c.inc | 27 ++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 5 deletions(-)
thanks
-- PMM
PATCH v2 16/24 target/arm: Enforce alignment for VLDn/VSTn (single)
In reply to Richard Henderson--- target/arm/translate-neon.c.inc | 48 ++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-)
target/arm/translate-neon.c.inc +42 -6
@@ -611,6 +611,7 @@ static bool trans_VLDST_single(DisasContext *s, arg_VLDST_single *a) int nregs = a->n + 1; int vd = a->vd; TCGv_i32 addr, tmp; + MemOp mop; if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { return false;
@@ -660,23 +661,58 @@ static bool trans_VLDST_single(DisasContext *s, arg_VLDST_single *a) return true; } + /* Pick up SCTLR settings */ + mop = finalize_memop(s, a->size); + + if (a->align) { + MemOp align_op; + + switch (nregs) { + case 1: + /* For VLD1, use natural alignment. */ + align_op = MO_ALIGN; + break; + case 2: + /* For VLD2, use double alignment. */ + align_op = pow2_align(a->size + 1); + break; + case 4: + if (a->size == MO_32) { + /* + * For VLD4.32, align = 1 is double alignment, align = 2 is + * quad alignment; align = 3 is rejected above. + */ + align_op = pow2_align(a->size + a->align); + } else { + /* For VLD4.8 and VLD.16, we want quad alignment. */ + align_op = pow2_align(a->size + 2); + } + break; + default: + /* For VLD3, the alignment field is zero and rejected above. */ + g_assert_not_reached(); + } + + mop = (mop & ~MO_AMASK) | align_op; + } + tmp = tcg_temp_new_i32(); addr = tcg_temp_new_i32(); load_reg_var(s, addr, a->rn); - /* - * TODO: if we implemented alignment exceptions, we should check - * addr against the alignment encoded in a->align here. - */ + for (reg = 0; reg < nregs; reg++) { if (a->l) { - gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), a->size); + gen_aa32_ld_internal_i32(s, tmp, addr, get_mem_index(s), mop); neon_store_element(vd, a->reg_idx, a->size, tmp); } else { /* Store */ neon_load_element(tmp, vd, a->reg_idx, a->size); - gen_aa32_st_i32(s, tmp, addr, get_mem_index(s), a->size); + gen_aa32_st_internal_i32(s, tmp, addr, get_mem_index(s), mop); } vd += a->stride; tcg_gen_addi_i32(addr, addr, 1 << a->size); + + /* Subsequent memory operations inherit alignment */ + mop &= ~MO_AMASK; } tcg_temp_free_i32(addr); tcg_temp_free_i32(tmp);
Signature · 1 line
2.25.1
Re: [PATCH v2 16/24] target/arm: Enforce alignment for VLDn/VSTn (single)
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate-neon.c.inc | 48 ++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-)
thanks
-- PMM
PATCH v2 17/24 target/arm: Use finalize_memop for aa64 gpr load/store
In reply to Richard HendersonIn the case of gpr load, merge the size and is_signed arguments; otherwise, simply convert size to memop.
--- target/arm/translate-a64.c | 78 ++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 45 deletions(-)
target/arm/translate-a64.c +33 -45
@@ -880,19 +880,19 @@ static void gen_adc_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)* Store from GPR register to memory. */ static void do_gpr_st_memidx (DisasContext *s,TCGv_i64 source, -TCGv_i64 tcg_addr,int size,int memidx, +TCGv_i64 tcg_addr,MemOp memop,int memidx,bool iss_valid,unsigned int iss_srt,bool iss_sf,bool iss_ar) { -g_assert (size <=3 ); -tcg_gen_qemu_st_i64 (source, tcg_addr, memidx, s->be_data + size); + memop =finalize_memop (s, memop); +tcg_gen_qemu_st_i64 (source, tcg_addr, memidx, memop);if (iss_valid) {uint32_t syn; syn = syn_data_abort_with_iss(0, - size, + (memop & MO_SIZE), false, iss_srt, iss_sf,
@@ -903,37 +903,28 @@ static void do_gpr_st_memidx(DisasContext *s, TCGv_i64 source, }static void do_gpr_st (DisasContext *s,TCGv_i64 source, -TCGv_i64 tcg_addr,int size, +TCGv_i64 tcg_addr,MemOp memop,bool iss_valid,unsigned int iss_srt,bool iss_sf,bool iss_ar) { -do_gpr_st_memidx (s, source, tcg_addr, size,get_mem_index (s), +do_gpr_st_memidx (s, source, tcg_addr, memop,get_mem_index (s), iss_valid, iss_srt, iss_sf, iss_ar); }/* * Load from memory to GPR register */ -static void do_gpr_ld_memidx (DisasContext *s, -TCGv_i64 dest,TCGv_i64 tcg_addr, -int size,bool is_signed, -bool extend,int memidx, +static void do_gpr_ld_memidx (DisasContext *s,TCGv_i64 dest,TCGv_i64 tcg_addr, +MemOp memop,bool extend,int memidx,bool iss_valid,unsigned int iss_srt,bool iss_sf,bool iss_ar) { -MemOp memop = s->be_data + size; - -g_assert (size <=3 ); - -if (is_signed) { - memop +=MO_SIGN ; - } - + memop =finalize_memop (s, memop);tcg_gen_qemu_ld_i64 (dest, tcg_addr, memidx, memop); -if (extend && is_signed) { -g_assert (size <3 ); +if (extend && (memop &MO_SIGN )) { +g_assert ((memop &MO_SIZE ) <=MO_32 );tcg_gen_ext32u_i64 (dest, dest); }
@@ -941,8 +932,8 @@ static void do_gpr_ld_memidx(DisasContext *s,uint32_t syn; syn = syn_data_abort_with_iss(0, - size, - is_signed, + (memop & MO_SIZE), + (memop & MO_SIGN) != 0, iss_srt, iss_sf, iss_ar,
@@ -951,14 +942,12 @@ static void do_gpr_ld_memidx(DisasContext *s, } } -static void do_gpr_ld (DisasContext *s, -TCGv_i64 dest,TCGv_i64 tcg_addr, -int size,bool is_signed,bool extend, +static void do_gpr_ld (DisasContext *s,TCGv_i64 dest,TCGv_i64 tcg_addr, +MemOp memop,bool extend,bool iss_valid,unsigned int iss_srt,bool iss_sf,bool iss_ar) { -do_gpr_ld_memidx (s, dest, tcg_addr, size, is_signed, extend, -get_mem_index (s), +do_gpr_ld_memidx (s, dest, tcg_addr, memop, extend,get_mem_index (s), iss_valid, iss_srt, iss_sf, iss_ar); }
@@ -2687,7 +2676,7 @@ static void disas_ldst_excl(DisasContext *s, uint32_t insn) } clean_addr =gen_mte_check1 (s,cpu_reg_sp (s, rn), false, rn !=31 , size); -do_gpr_ld (s,cpu_reg (s, rt), clean_addr, size, false, false, true, rt, +do_gpr_ld (s,cpu_reg (s, rt), clean_addr, size, false, true, rt,disas_ldst_compute_iss_sf (size, false,0 ), is_lasr);tcg_gen_mb (TCG_MO_ALL |TCG_BAR_LDAQ );return ;
@@ -2800,8 +2789,8 @@ static void disas_ld_lit(DisasContext *s, uint32_t insn)/* Only unsigned 32bit loads target 32bit registers. */ bool iss_sf = opc !=0 ; -do_gpr_ld (s, tcg_rt, clean_addr, size, is_signed, false, - true, rt, iss_sf, false); +do_gpr_ld (s, tcg_rt, clean_addr, size + is_signed *MO_SIGN , + false, true, rt, iss_sf, false); }tcg_temp_free_i64 (clean_addr); }
@@ -2960,11 +2949,11 @@ static void disas_ldst_pair(DisasContext *s, uint32_t insn)/* Do not modify tcg_rt before recognizing any exception * from the second load. */ -do_gpr_ld (s, tmp, clean_addr, size, is_signed, false, - false,0 , false, false); +do_gpr_ld (s, tmp, clean_addr, size + is_signed *MO_SIGN , + false, false,0 , false, false);tcg_gen_addi_i64 (clean_addr, clean_addr,1 << size); -do_gpr_ld (s, tcg_rt2, clean_addr, size, is_signed, false, - false,0 , false, false); +do_gpr_ld (s, tcg_rt2, clean_addr, size + is_signed *MO_SIGN , + false, false,0 , false, false);tcg_gen_mov_i64 (tcg_rt, tmp);tcg_temp_free_i64 (tmp);
@@ -3095,8 +3084,8 @@ static void disas_ldst_reg_imm9(DisasContext *s, uint32_t insn,do_gpr_st_memidx (s, tcg_rt, clean_addr, size, memidx, iss_valid, rt, iss_sf, false); }else { -do_gpr_ld_memidx (s, tcg_rt, clean_addr, size, - is_signed, is_extended, memidx, +do_gpr_ld_memidx (s, tcg_rt, clean_addr, size + is_signed *MO_SIGN , + is_extended, memidx, iss_valid, rt, iss_sf, false); } }
@@ -3200,9 +3189,8 @@ static void disas_ldst_reg_roffset(DisasContext *s, uint32_t insn,do_gpr_st (s, tcg_rt, clean_addr, size, true, rt, iss_sf, false); }else { -do_gpr_ld (s, tcg_rt, clean_addr, size, - is_signed, is_extended, - true, rt, iss_sf, false); +do_gpr_ld (s, tcg_rt, clean_addr, size + is_signed *MO_SIGN , + is_extended, true, rt, iss_sf, false); } } }
@@ -3285,8 +3273,8 @@ static void disas_ldst_reg_unsigned_imm(DisasContext *s, uint32_t insn,do_gpr_st (s, tcg_rt, clean_addr, size, true, rt, iss_sf, false); }else { -do_gpr_ld (s, tcg_rt, clean_addr, size, is_signed, is_extended, - true, rt, iss_sf, false); +do_gpr_ld (s, tcg_rt, clean_addr, size + is_signed *MO_SIGN , + is_extended, true, rt, iss_sf, false); } } }
@@ -3373,7 +3361,7 @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn,* full load-acquire (we only need "load-acquire processor consistent"), * but we choose to implement them as full LDAQ. */ -do_gpr_ld (s,cpu_reg (s, rt), clean_addr, size, false, false, +do_gpr_ld (s,cpu_reg (s, rt), clean_addr, size, false, true, rt,disas_ldst_compute_iss_sf (size, false,0 ), true);tcg_gen_mb (TCG_MO_ALL |TCG_BAR_LDAQ );return ;
@@ -3446,7 +3434,7 @@ static void disas_ldst_pac(DisasContext *s, uint32_t insn, is_wback || rn != 31, size); tcg_rt =cpu_reg (s, rt); -do_gpr_ld (s, tcg_rt, clean_addr, size,/* is_signed */ false, +do_gpr_ld (s, tcg_rt, clean_addr, size,/* extend */ false,/* iss_valid */ !is_wback,/* iss_srt */ rt,/* iss_sf */ true,/* iss_ar */ false);
@@ -3531,8 +3519,8 @@ static void disas_ldst_ldapr_stlr(DisasContext *s, uint32_t insn)* Load-AcquirePC semantics; we implement as the slightly more * restrictive Load-Acquire. */ -do_gpr_ld (s,cpu_reg (s, rt), clean_addr, size, is_signed, extend, - true, rt, iss_sf, true); +do_gpr_ld (s,cpu_reg (s, rt), clean_addr, size + is_signed *MO_SIGN , + extend, true, rt, iss_sf, true);tcg_gen_mb (TCG_MO_ALL |TCG_BAR_LDAQ ); } }
Signature · 1 line
2.25.1
Re: [PATCH v2 17/24] target/arm: Use finalize_memop for aa64 gpr load/store
Quoted 5 lines · Richard Henderson
In the case of gpr load, merge the size and
is_signedarguments; otherwise, simply convert size to memop.Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v2 18/24 target/arm: Use finalize_memop for aa64 fpr load/store
In reply to Richard HendersonFor 128-bit load/store, use 16-byte alignment. This requires that we perform the two operations in the correct order so that we generate the alignment fault before modifying memory.
--- target/arm/translate-a64.c | 42 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-)
target/arm/translate-a64.c +26 -16
@@ -957,25 +957,33 @@ static void do_gpr_ld(DisasContext *s, TCGv_i64 dest, TCGv_i64 tcg_addr,static void do_fp_st (DisasContext *s,int srcidx,TCGv_i64 tcg_addr,int size) {/* This writes the bottom N bits of a 128 bit wide vector to memory */ -TCGv_i64 tmp =tcg_temp_new_i64 (); -tcg_gen_ld_i64 (tmp, cpu_env,fp_reg_offset (s, srcidx,MO_64 )); +TCGv_i64 tmplo =tcg_temp_new_i64 (); +MemOp mop; + +tcg_gen_ld_i64 (tmplo, cpu_env,fp_reg_offset (s, srcidx,MO_64 )); +if (size <4 ) { -tcg_gen_qemu_st_i64 (tmp, tcg_addr,get_mem_index (s), - s->be_data + size); + mop =finalize_memop (s, size); +tcg_gen_qemu_st_i64 (tmplo, tcg_addr,get_mem_index (s), mop); }else {bool be = s->be_data ==MO_BE ;TCGv_i64 tcg_hiaddr =tcg_temp_new_i64 (); +TCGv_i64 tmphi =tcg_temp_new_i64 (); +tcg_gen_ld_i64 (tmphi, cpu_env,fp_reg_hi_offset (s, srcidx)); + + mop = s->be_data |MO_Q ; +tcg_gen_qemu_st_i64 (be ? tmphi : tmplo, tcg_addr,get_mem_index (s), + mop | (s->align_mem ?MO_ALIGN_16 :0 ));tcg_gen_addi_i64 (tcg_hiaddr, tcg_addr,8 ); -tcg_gen_qemu_st_i64 (tmp, be ? tcg_hiaddr : tcg_addr,get_mem_index (s), - s->be_data |MO_Q ); -tcg_gen_ld_i64 (tmp, cpu_env,fp_reg_hi_offset (s, srcidx)); -tcg_gen_qemu_st_i64 (tmp, be ? tcg_addr : tcg_hiaddr,get_mem_index (s), - s->be_data |MO_Q ); +tcg_gen_qemu_st_i64 (be ? tmplo : tmphi, tcg_hiaddr, +get_mem_index (s), mop); +tcg_temp_free_i64 (tcg_hiaddr); +tcg_temp_free_i64 (tmphi); } -tcg_temp_free_i64 (tmp); +tcg_temp_free_i64 (tmplo); }/*
@@ -986,10 +994,11 @@ static void do_fp_ld(DisasContext *s, int destidx, TCGv_i64 tcg_addr, int size)/* This always zero-extends and writes to a full 128 bit wide vector */ TCGv_i64 tmplo =tcg_temp_new_i64 ();TCGv_i64 tmphi =NULL ; +MemOp mop;if (size <4 ) { -MemOp memop = s->be_data + size; -tcg_gen_qemu_ld_i64 (tmplo, tcg_addr,get_mem_index (s), memop); + mop =finalize_memop (s, size); +tcg_gen_qemu_ld_i64 (tmplo, tcg_addr,get_mem_index (s), mop); }else {bool be = s->be_data ==MO_BE ;TCGv_i64 tcg_hiaddr;
@@ -997,11 +1006,12 @@ static void do_fp_ld(DisasContext *s, int destidx, TCGv_i64 tcg_addr, int size) tmphi =tcg_temp_new_i64 (); tcg_hiaddr =tcg_temp_new_i64 (); + mop = s->be_data |MO_Q ; +tcg_gen_qemu_ld_i64 (be ? tmphi : tmplo, tcg_addr,get_mem_index (s), + mop | (s->align_mem ?MO_ALIGN_16 :0 ));tcg_gen_addi_i64 (tcg_hiaddr, tcg_addr,8 ); -tcg_gen_qemu_ld_i64 (tmplo, be ? tcg_hiaddr : tcg_addr,get_mem_index (s), - s->be_data |MO_Q ); -tcg_gen_qemu_ld_i64 (tmphi, be ? tcg_addr : tcg_hiaddr,get_mem_index (s), - s->be_data |MO_Q ); +tcg_gen_qemu_ld_i64 (be ? tmplo : tmphi, tcg_hiaddr, +get_mem_index (s), mop);tcg_temp_free_i64 (tcg_hiaddr); }
Signature · 1 line
2.25.1
Re: [PATCH v2 18/24] target/arm: Use finalize_memop for aa64 fpr load/store
Quoted 7 lines · Richard Henderson
For 128-bit load/store, use 16-byte alignment. This requires that we perform the two operations in the correct order so that we generate the alignment fault before modifying memory.
Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v2 19/24 target/arm: Enforce alignment for aa64 load-acq/store-rel
In reply to Richard Henderson--- target/arm/translate-a64.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
target/arm/translate-a64.c +14 -9
@@ -2669,7 +2669,8 @@ static void disas_ldst_excl(DisasContext *s, uint32_t insn)tcg_gen_mb (TCG_MO_ALL |TCG_BAR_STRL ); clean_addr =gen_mte_check1 (s,cpu_reg_sp (s, rn), true, rn !=31 , size); -do_gpr_st (s,cpu_reg (s, rt), clean_addr, size, true, rt, +/* TODO: ARMv8.4-LSE SCTLR.nAA */ +do_gpr_st (s,cpu_reg (s, rt), clean_addr, size |MO_ALIGN , true, rt,disas_ldst_compute_iss_sf (size, false,0 ), is_lasr);return ;
@@ -2686,8 +2687,9 @@ static void disas_ldst_excl(DisasContext *s, uint32_t insn) } clean_addr =gen_mte_check1 (s,cpu_reg_sp (s, rn), false, rn !=31 , size); -do_gpr_ld (s,cpu_reg (s, rt), clean_addr, size, false, true, rt, -disas_ldst_compute_iss_sf (size, false,0 ), is_lasr); +/* TODO: ARMv8.4-LSE SCTLR.nAA */ +do_gpr_ld (s,cpu_reg (s, rt), clean_addr, size |MO_ALIGN , false, true, + rt,disas_ldst_compute_iss_sf (size, false,0 ), is_lasr);tcg_gen_mb (TCG_MO_ALL |TCG_BAR_LDAQ );return ;
@@ -3476,15 +3478,18 @@ static void disas_ldst_ldapr_stlr(DisasContext *s, uint32_t insn)int size =extract32 (insn,30 ,2 );TCGv_i64 clean_addr, dirty_addr;bool is_store = false; -bool is_signed = false;bool extend = false;bool iss_sf; +MemOp mop;if (!dc_isar_feature (aa64_rcpc_8_4, s)) {unallocated_encoding (s);return ; } +/* TODO: ARMv8.4-LSE SCTLR.nAA */ + mop = size |MO_ALIGN ; +switch (opc) {case 0 :/* STLURB */ is_store = true;
@@ -3496,21 +3501,21 @@ static void disas_ldst_ldapr_stlr(DisasContext *s, uint32_t insn)unallocated_encoding (s);return ; } - is_signed = true; + mop |=MO_SIGN ;break ;case 3 :/* LDAPURS* 32-bit variant */ if (size >1 ) {unallocated_encoding (s);return ; } - is_signed = true; + mop |=MO_SIGN ; extend = true;/* zero-extend 32->64 after signed load */ break ;default :g_assert_not_reached (); } - iss_sf =disas_ldst_compute_iss_sf (size, is_signed, opc); + iss_sf =disas_ldst_compute_iss_sf (size, (mop &MO_SIGN ) !=0 , opc);if (rn ==31 ) {gen_check_sp_alignment (s);
@@ -3523,13 +3528,13 @@ static void disas_ldst_ldapr_stlr(DisasContext *s, uint32_t insn)if (is_store) {/* Store-Release semantics */ tcg_gen_mb (TCG_MO_ALL |TCG_BAR_STRL ); -do_gpr_st (s,cpu_reg (s, rt), clean_addr, size, true, rt, iss_sf, true); +do_gpr_st (s,cpu_reg (s, rt), clean_addr, mop, true, rt, iss_sf, true); }else {/* * Load-AcquirePC semantics; we implement as the slightly more * restrictive Load-Acquire. */ -do_gpr_ld (s,cpu_reg (s, rt), clean_addr, size + is_signed *MO_SIGN , +do_gpr_ld (s,cpu_reg (s, rt), clean_addr, mop, extend, true, rt, iss_sf, true);tcg_gen_mb (TCG_MO_ALL |TCG_BAR_LDAQ ); }
Signature · 1 line
2.25.1
Re: [PATCH v2 19/24] target/arm: Enforce alignment for aa64 load-acq/store-rel
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate-a64.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
thanks
-- PMM
PATCH v2 20/24 target/arm: Use MemOp for size + endian in aa64 vector ld/st
In reply to Richard Henderson--- target/arm/translate-a64.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
target/arm/translate-a64.c +10 -10
@@ -1140,24 +1140,24 @@ static void write_vec_element_i32(DisasContext *s, TCGv_i32 tcg_src,/* Store from vector register to memory */ static void do_vec_st (DisasContext *s,int srcidx,int element, -TCGv_i64 tcg_addr,int size,MemOp endian) +TCGv_i64 tcg_addr,MemOp mop) {TCGv_i64 tcg_tmp =tcg_temp_new_i64 (); -read_vec_element (s, tcg_tmp, srcidx, element, size); -tcg_gen_qemu_st_i64 (tcg_tmp, tcg_addr,get_mem_index (s), endian | size); +read_vec_element (s, tcg_tmp, srcidx, element, mop &MO_SIZE ); +tcg_gen_qemu_st_i64 (tcg_tmp, tcg_addr,get_mem_index (s), mop);tcg_temp_free_i64 (tcg_tmp); }/* Load from memory to vector register */ static void do_vec_ld (DisasContext *s,int destidx,int element, -TCGv_i64 tcg_addr,int size,MemOp endian) +TCGv_i64 tcg_addr,MemOp mop) {TCGv_i64 tcg_tmp =tcg_temp_new_i64 (); -tcg_gen_qemu_ld_i64 (tcg_tmp, tcg_addr,get_mem_index (s), endian | size); -write_vec_element (s, tcg_tmp, destidx, element, size); +tcg_gen_qemu_ld_i64 (tcg_tmp, tcg_addr,get_mem_index (s), mop); +write_vec_element (s, tcg_tmp, destidx, element, mop &MO_SIZE );tcg_temp_free_i64 (tcg_tmp); }
@@ -3705,9 +3705,9 @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)for (xs =0 ; xs < selem; xs++) {int tt = (rt + r + xs) %32 ;if (is_store) { -do_vec_st (s, tt, e, clean_addr, size, endian); +do_vec_st (s, tt, e, clean_addr, size | endian); }else { -do_vec_ld (s, tt, e, clean_addr, size, endian); +do_vec_ld (s, tt, e, clean_addr, size | endian); }tcg_gen_add_i64 (clean_addr, clean_addr, tcg_ebytes); }
@@ -3856,9 +3856,9 @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn) }else {/* Load/store one element per register */ if (is_load) { -do_vec_ld (s, rt, index, clean_addr, scale, s->be_data); +do_vec_ld (s, rt, index, clean_addr, scale | s->be_data); }else { -do_vec_st (s, rt, index, clean_addr, scale, s->be_data); +do_vec_st (s, rt, index, clean_addr, scale | s->be_data); } }tcg_gen_add_i64 (clean_addr, clean_addr, tcg_ebytes);
Signature · 1 line
2.25.1
Re: [PATCH v2 20/24] target/arm: Use MemOp for size + endian in aa64 vector ld/st
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate-a64.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
thanks
-- PMM
PATCH v2 21/24 target/arm: Enforce alignment for aa64 vector LDn/STn (multiple)
In reply to Richard Henderson--- target/arm/translate-a64.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
target/arm/translate-a64.c +11 -4
@@ -3606,7 +3606,7 @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)bool is_postidx =extract32 (insn,23 ,1 );bool is_q =extract32 (insn,30 ,1 );TCGv_i64 clean_addr, tcg_rn, tcg_ebytes; -MemOp endian = s->be_data; +MemOp endian, align, mop;int total;/* total bytes */ int elements;/* elements per vector */
@@ -3674,6 +3674,7 @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn) }/* For our purposes, bytes are always little-endian. */ + endian = s->be_data;if (size ==0 ) { endian =MO_LE ; }
@@ -3692,11 +3693,17 @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)* Consecutive little-endian elements from a single register * can be promoted to a larger little-endian operation. */ + align =MO_ALIGN ;if (selem ==1 && endian ==MO_LE ) { + align =pow2_align (size); size =3 ; } - elements = (is_q ?16 :8 ) >> size; +if (!s->align_mem) { + align =0 ; + } + mop = endian | size | align; + elements = (is_q ?16 :8 ) >> size; tcg_ebytes =tcg_const_i64 (1 << size);for (r =0 ; r < rpt; r++) {int e;
@@ -3705,9 +3712,9 @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)for (xs =0 ; xs < selem; xs++) {int tt = (rt + r + xs) %32 ;if (is_store) { -do_vec_st (s, tt, e, clean_addr, size | endian); +do_vec_st (s, tt, e, clean_addr, mop); }else { -do_vec_ld (s, tt, e, clean_addr, size | endian); +do_vec_ld (s, tt, e, clean_addr, mop); }tcg_gen_add_i64 (clean_addr, clean_addr, tcg_ebytes); }
Signature · 1 line
2.25.1
Re: [PATCH v2 21/24] target/arm: Enforce alignment for aa64 vector LDn/STn (multiple)
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate-a64.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
thanks
-- PMM
PATCH v2 22/24 target/arm: Enforce alignment for aa64 vector LDn/STn (single)
In reply to Richard Henderson--- target/arm/translate-a64.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
target/arm/translate-a64.c +5 -4
@@ -3786,6 +3786,7 @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn)int index = is_q <<3 |S <<2 | size;int xs, total;TCGv_i64 clean_addr, tcg_rn, tcg_ebytes; +MemOp mop;if (extract32 (insn,31 ,1 )) {unallocated_encoding (s);
@@ -3847,6 +3848,7 @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn) clean_addr =gen_mte_checkN (s, tcg_rn, !is_load, is_postidx || rn !=31 , scale, total); + mop =finalize_memop (s, scale); tcg_ebytes =tcg_const_i64 (1 << scale);for (xs =0 ; xs < selem; xs++) {
@@ -3854,8 +3856,7 @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn)/* Load and replicate to all elements */ TCGv_i64 tcg_tmp =tcg_temp_new_i64 (); -tcg_gen_qemu_ld_i64 (tcg_tmp, clean_addr, -get_mem_index (s), s->be_data + scale); +tcg_gen_qemu_ld_i64 (tcg_tmp, clean_addr,get_mem_index (s), mop);tcg_gen_gvec_dup_i64 (scale,vec_full_reg_offset (s, rt), (is_q +1 ) *8 ,vec_full_reg_size (s), tcg_tmp);
@@ -3863,9 +3864,9 @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn) }else {/* Load/store one element per register */ if (is_load) { -do_vec_ld (s, rt, index, clean_addr, scale | s->be_data); +do_vec_ld (s, rt, index, clean_addr, mop); }else { -do_vec_st (s, rt, index, clean_addr, scale | s->be_data); +do_vec_st (s, rt, index, clean_addr, mop); } }tcg_gen_add_i64 (clean_addr, clean_addr, tcg_ebytes);
Signature · 1 line
2.25.1
Re: [PATCH v2 22/24] target/arm: Enforce alignment for aa64 vector LDn/STn (single)
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate-a64.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
thanks
-- PMM
PATCH v2 23/24 target/arm: Enforce alignment for sve LD1R
In reply to Richard Henderson--- target/arm/translate-sve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/translate-sve.c +1 -1
@@ -5011,7 +5011,7 @@ static bool trans_LD1R_zpri(DisasContext *s, arg_rpri_load *a) clean_addr =gen_mte_check1 (s, temp, false, true, msz);tcg_gen_qemu_ld_i64 (temp, clean_addr,get_mem_index (s), - s->be_data | dtype_mop[a->dtype]); +finalize_memop (s, dtype_mop[a->dtype]));/* Broadcast to *all* elements. */ tcg_gen_gvec_dup_i64(esz, vec_full_reg_offset(s, a->rd),
Signature · 1 line
2.25.1
Re: [PATCH v2 23/24] target/arm: Enforce alignment for sve LD1R
Quoted 11 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate-sve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/arm/translate-sve.c +0
-0
target/arm/translate-sve.c static bool trans_LD1R_zpri(DisasContext *s, arg_rpri_load *a)
Quoted 9 lines
target/arm/translate-sve.c +1
-2@@ -5011,7 +5011,7 @@ static bool trans_LD1R_zpri(DisasContext *s, arg_rpri_load *a) clean_addr =gen_mte_check1 (s, temp, false, true, msz);tcg_gen_qemu_ld_i64 (temp, clean_addr,get_mem_index (s), - s->be_data | dtype_mop[a->dtype]); +finalize_memop (s, dtype_mop[a->dtype]));/* Broadcast to *all* elements. */ tcg_gen_gvec_dup_i64(esz, vec_full_reg_offset(s, a->rd), --
thanks
-- PMM
PATCH v2 24/24 target/arm: Enforce alignment for sve unpredicated LDR/STR
In reply to Richard Henderson--- target/arm/translate-sve.c | 58 +++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 13 deletions(-)
target/arm/translate-sve.c +45 -13
@@ -4263,7 +4263,8 @@ static bool trans_UCVTF_dd(DisasContext *s, arg_rpr_esz *a)* The load should begin at the address Rn + IMM. */ -static void do_ldr (DisasContext *s,uint32_t vofs,int len,int rn,int imm) +static void do_ldr (DisasContext *s,uint32_t vofs,int len, +MemOp align,int rn,int imm) {int len_align =QEMU_ALIGN_DOWN (len,8 );int len_remain = len %8 ;
@@ -4276,6 +4277,10 @@ static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm) clean_addr =gen_mte_checkN (s, dirty_addr, false, rn !=31 , len,MO_8 );tcg_temp_free_i64 (dirty_addr); +if (!s->align_mem) { + align =0 ; + } +/* * Note that unpredicated load/store of vector/predicate registers * are defined as a stream of bytes, which equates to little-endian
@@ -4288,7 +4293,8 @@ static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm) t0 =tcg_temp_new_i64 ();for (i =0 ; i < len_align; i +=8 ) { -tcg_gen_qemu_ld_i64 (t0, clean_addr, midx,MO_LEQ ); +tcg_gen_qemu_ld_i64 (t0, clean_addr, midx,MO_LEQ | align); + align =0 ;tcg_gen_st_i64 (t0, cpu_env, vofs + i);tcg_gen_addi_i64 (clean_addr, clean_addr,8 ); }
@@ -4302,6 +4308,16 @@ static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm) clean_addr =new_tmp_a64_local (s);tcg_gen_mov_i64 (clean_addr, t0); +if (align >MO_ALIGN_8 ) { + t0 =tcg_temp_new_i64 (); +tcg_gen_qemu_ld_i64 (t0, clean_addr, midx,MO_LEQ | align); +tcg_gen_addi_i64 (clean_addr, clean_addr,8 ); +tcg_gen_addi_ptr (i, i,8 ); +tcg_gen_st_i64 (t0, cpu_env, vofs); +tcg_temp_free_i64 (t0); + align =0 ; + } +gen_set_label (loop); t0 =tcg_temp_new_i64 ();
@@ -4330,12 +4346,12 @@ static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm)case 4 :case 8 :tcg_gen_qemu_ld_i64 (t0, clean_addr, midx, -MO_LE |ctz32 (len_remain)); +MO_LE |ctz32 (len_remain) | align);break ;case 6 : t1 =tcg_temp_new_i64 (); -tcg_gen_qemu_ld_i64 (t0, clean_addr, midx,MO_LEUL ); +tcg_gen_qemu_ld_i64 (t0, clean_addr, midx,MO_LEUL | align);tcg_gen_addi_i64 (clean_addr, clean_addr,4 );tcg_gen_qemu_ld_i64 (t1, clean_addr, midx,MO_LEUW );tcg_gen_deposit_i64 (t0, t0, t1,32 ,32 );
@@ -4351,7 +4367,8 @@ static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm) }/* Similarly for stores. */ -static void do_str (DisasContext *s,uint32_t vofs,int len,int rn,int imm) +static void do_str (DisasContext *s,uint32_t vofs,int len,MemOp align, +int rn,int imm) {int len_align =QEMU_ALIGN_DOWN (len,8 );int len_remain = len %8 ;
@@ -4364,6 +4381,10 @@ static void do_str(DisasContext *s, uint32_t vofs, int len, int rn, int imm) clean_addr =gen_mte_checkN (s, dirty_addr, false, rn !=31 , len,MO_8 );tcg_temp_free_i64 (dirty_addr); +if (!s->align_mem) { + align =0 ; + } +/* Note that unpredicated load/store of vector/predicate registers * are defined as a stream of bytes, which equates to little-endian * operations on larger quantities. There is no nice way to force
@@ -4378,7 +4399,8 @@ static void do_str(DisasContext *s, uint32_t vofs, int len, int rn, int imm) t0 =tcg_temp_new_i64 ();for (i =0 ; i < len_align; i +=8 ) {tcg_gen_ld_i64 (t0, cpu_env, vofs + i); -tcg_gen_qemu_st_i64 (t0, clean_addr, midx,MO_LEQ ); +tcg_gen_qemu_st_i64 (t0, clean_addr, midx,MO_LEQ | align); + align =0 ;tcg_gen_addi_i64 (clean_addr, clean_addr,8 ); }tcg_temp_free_i64 (t0);
@@ -4391,6 +4413,16 @@ static void do_str(DisasContext *s, uint32_t vofs, int len, int rn, int imm) clean_addr =new_tmp_a64_local (s);tcg_gen_mov_i64 (clean_addr, t0); +if (align >MO_ALIGN_8 ) { + t0 =tcg_temp_new_i64 (); +tcg_gen_ld_i64 (t0, cpu_env, vofs); +tcg_gen_qemu_st_i64 (t0, clean_addr, midx,MO_LEQ | align); +tcg_gen_addi_i64 (clean_addr, clean_addr,8 ); +tcg_gen_addi_ptr (i, i,8 ); +tcg_temp_free_i64 (t0); + align =0 ; + } +gen_set_label (loop); t0 =tcg_temp_new_i64 ();
@@ -4400,7 +4432,7 @@ static void do_str(DisasContext *s, uint32_t vofs, int len, int rn, int imm)tcg_gen_addi_ptr (i, i,8 );tcg_temp_free_ptr (tp); -tcg_gen_qemu_st_i64 (t0, clean_addr, midx,MO_LEQ ); +tcg_gen_qemu_st_i64 (t0, clean_addr, midx,MO_LEQ | align);tcg_gen_addi_i64 (clean_addr, clean_addr,8 );tcg_temp_free_i64 (t0);
@@ -4418,11 +4450,11 @@ static void do_str(DisasContext *s, uint32_t vofs, int len, int rn, int imm)case 4 :case 8 :tcg_gen_qemu_st_i64 (t0, clean_addr, midx, -MO_LE |ctz32 (len_remain)); +MO_LE |ctz32 (len_remain) | align);break ;case 6 : -tcg_gen_qemu_st_i64 (t0, clean_addr, midx,MO_LEUL ); +tcg_gen_qemu_st_i64 (t0, clean_addr, midx,MO_LEUL | align);tcg_gen_addi_i64 (clean_addr, clean_addr,4 );tcg_gen_shri_i64 (t0, t0,32 );tcg_gen_qemu_st_i64 (t0, clean_addr, midx,MO_LEUW );
@@ -4440,7 +4472,7 @@ static bool trans_LDR_zri(DisasContext *s, arg_rri *a)if (sve_access_check (s)) {int size =vec_full_reg_size (s);int off =vec_full_reg_offset (s, a->rd); -do_ldr (s, off, size, a->rn, a->imm * size); +do_ldr (s, off, size,MO_ALIGN_16 , a->rn, a->imm * size); }return true; }
@@ -4450,7 +4482,7 @@ static bool trans_LDR_pri(DisasContext *s, arg_rri *a)if (sve_access_check (s)) {int size =pred_full_reg_size (s);int off =pred_full_reg_offset (s, a->rd); -do_ldr (s, off, size, a->rn, a->imm * size); +do_ldr (s, off, size,MO_ALIGN_2 , a->rn, a->imm * size); }return true; }
@@ -4460,7 +4492,7 @@ static bool trans_STR_zri(DisasContext *s, arg_rri *a)if (sve_access_check (s)) {int size =vec_full_reg_size (s);int off =vec_full_reg_offset (s, a->rd); -do_str (s, off, size, a->rn, a->imm * size); +do_str (s, off, size,MO_ALIGN_16 , a->rn, a->imm * size); }return true; }
@@ -4470,7 +4502,7 @@ static bool trans_STR_pri(DisasContext *s, arg_rri *a)if (sve_access_check (s)) {int size =pred_full_reg_size (s);int off =pred_full_reg_offset (s, a->rd); -do_str (s, off, size, a->rn, a->imm * size); +do_str (s, off, size,MO_ALIGN_2 , a->rn, a->imm * size); }return true; }
Signature · 1 line
2.25.1
Re: [PATCH v2 24/24] target/arm: Enforce alignment for sve unpredicated LDR/STR
Quoted 45 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/translate-sve.c | 58 +++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 13 deletions(-)target/arm/translate-sve.c +8
-2@@ -4263,7 +4263,8 @@ static bool trans_UCVTF_dd(DisasContext *s, arg_rpr_esz *a)* The load should begin at the address Rn + IMM. */ -static void do_ldr (DisasContext *s,uint32_t vofs,int len,int rn,int imm) +static void do_ldr (DisasContext *s,uint32_t vofs,int len, +MemOp align,int rn,int imm) {int len_align =QEMU_ALIGN_DOWN (len,8 );int len_remain = len %8 ;@@ -4276,6 +4277,10 @@ static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm) clean_addr =gen_mte_checkN (s, dirty_addr, false, rn !=31 , len,MO_8 );tcg_temp_free_i64 (dirty_addr); +if (!s->align_mem) { + align =0 ; + } +/* * Note that unpredicated load/store of vector/predicate registers * are defined as a stream of bytes, which equates to little-endian @@ -4288,7 +4293,8 @@ static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm) t0 =tcg_temp_new_i64 ();for (i =0 ; i < len_align; i +=8 ) { -tcg_gen_qemu_ld_i64 (t0, clean_addr, midx,MO_LEQ ); +tcg_gen_qemu_ld_i64 (t0, clean_addr, midx,MO_LEQ | align); + align =0 ;tcg_gen_st_i64 (t0, cpu_env, vofs + i);tcg_gen_addi_i64 (clean_addr, clean_addr,8 ); }@@ -4302,6 +4308,16 @@ static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm) clean_addr =new_tmp_a64_local (s);tcg_gen_mov_i64 (clean_addr, t0);
target/arm/translate-sve.c static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm) · line 4320
Quoted 10 lines
target/arm/translate-sve.c +10
-0+if (align >MO_ALIGN_8 ) { + t0 =tcg_temp_new_i64 (); +tcg_gen_qemu_ld_i64 (t0, clean_addr, midx,MO_LEQ | align); +tcg_gen_addi_i64 (clean_addr, clean_addr,8 ); +tcg_gen_addi_ptr (i, i,8 ); +tcg_gen_st_i64 (t0, cpu_env, vofs); +tcg_temp_free_i64 (t0); + align =0 ; + } +
Why do we need to do this (and the similar thing in do_str()) ? Most of the rest of the patch is fairly clear in that it is just passing the alignment requirement through to the load/store fns, but this is a bit more opaque to me...
thanks
-- PMM
Re: [PATCH v2 24/24] target/arm: Enforce alignment for sve unpredicated LDR/STR
Quoted 11 lines · Peter Maydell
target/arm/translate-sve.c static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm) · line 4320
Quoted 10 lines
target/arm/translate-sve.c +10
-0+if (align >MO_ALIGN_8 ) { + t0 =tcg_temp_new_i64 (); +tcg_gen_qemu_ld_i64 (t0, clean_addr, midx,MO_LEQ | align); +tcg_gen_addi_i64 (clean_addr, clean_addr,8 ); +tcg_gen_addi_ptr (i, i,8 ); +tcg_gen_st_i64 (t0, cpu_env, vofs); +tcg_temp_free_i64 (t0); + align =0 ; + } +
Quoted 4 lines
Why do we need to do this (and the similar thing in
do_str()) ? Most of the rest of the patch is fairly clear in that it is just passing the alignment requirement through to the load/store fns, but this is a bit more opaque to me...
What follows this context is a single memory access within a tcg loop.
When align is <= the size of the access, every access can use the same alignment mop. But for MO_ALIGN_16, since we're emitting 8-byte accesses, the second access will not be 16-byte aligned. So I peel off one loop iteration at the beginning to perform the alignment check.
r~
Peter Maydell
Reviewed-byRe: [PATCH v2 24/24] target/arm: Enforce alignment for sve unpredicated LDR/STR
Quoted 18 lines · Richard Henderson
Quoted 11 lines · Peter Maydell
target/arm/translate-sve.c static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm) · line 4320
Quoted 10 lines
target/arm/translate-sve.c +10
-0+if (align >MO_ALIGN_8 ) { + t0 =tcg_temp_new_i64 (); +tcg_gen_qemu_ld_i64 (t0, clean_addr, midx,MO_LEQ | align); +tcg_gen_addi_i64 (clean_addr, clean_addr,8 ); +tcg_gen_addi_ptr (i, i,8 ); +tcg_gen_st_i64 (t0, cpu_env, vofs); +tcg_temp_free_i64 (t0); + align =0 ; + } +Quoted 4 lines
Why do we need to do this (and the similar thing in
do_str()) ? Most of the rest of the patch is fairly clear in that it is just passing the alignment requirement through to the load/store fns, but this is a bit more opaque to me...
Quoted 6 lines
What follows this context is a single memory access within a tcg loop.
When align is <= the size of the access, every access can use the same alignment mop. But for
MO_ALIGN_16, since we're emitting 8-byte accesses, the second access will not be 16-byte aligned. So I peel off one loop iteration at the beginning to perform the alignment check.
OK. Could you add comments to that effect, please?
Otherwise
thanks
-- PMM