target/hexagon: Misc HLX fixes
cover target/hexagon: Misc HLX fixes
Hi,
I was too slow on the review before the series got PRd, so I'll submit these preliminary fixes instead. Not included here is a fix for --disable-hexagon-idef-parser being broken with the new stub HMX helpers.
Anton Johansson (6):
target/hexagon: HLX, preserve scalar :mem_noshuf ordering target/hexagon: HLX, search for .new values in pair high register target/hexagon: Forward return address to HLX load/store helpers linux-user/hexagon: Reset hlx_ctx pointer on cpu clone tests/tcg/hexagon: test HLX scalar :mem_noshuf ordering tests/tcg/hexagon: HLX, test .new on pair high register
linux-user/hexagon/target_cpu.h | 1 + target/hexagon/macros.h | 13 +++++++---- target/hexagon/decode.c | 20 +++++++++++++++-- target/hexagon/hlx_helper.c | 31 +++++++++++++++++-------- target/hexagon/translate.c | 7 +++--- tests/tcg/hexagon/hlx_assign_conv.c | 35 +++++++++++++++++++++++++++++ tests/tcg/hexagon/hlx_mem.c | 22 ++++++++++++++++++ 7 files changed, 111 insertions(+), 18 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/6 target/hexagon: HLX, preserve scalar :mem_noshuf ordering
A packet containing HLX instructions currently defers all stores to the end of the packet, this breaks scalar :mem_noshuf ordering. Only reorder HLX stores.
--- target/hexagon/translate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
target/hexagon/translate.c +4 -3
@@ -1525,8 +1525,10 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)for (int pass =0 ; pass <3 ; pass++) {for (i =0 ; i < ctx->pkt.num_insns; i++) {Insn *insn = &ctx->pkt.insn[i]; +bool hlx =GET_ATTRIB (insn->opcode,A_HLX );bool tmp =GET_ATTRIB (insn->opcode,A_HLX_TMP ); -bool store = !tmp &&GET_ATTRIB (insn->opcode,A_STORE ); +bool store = !tmp && hlx && +GET_ATTRIB (insn->opcode,A_STORE );if (pass != (tmp ?0 : store ?2 :1 )) {continue ; }
@@ -1534,8 +1536,7 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)if (insn->hlx_new_zero) {gen_hlx_new_zero (insn); } -if (GET_ATTRIB (insn->opcode,A_HLX ) && -trace_event_get_state_backends ( +if (hlx &&trace_event_get_state_backends (TRACE_HEXAGON_HLX_OP )) {gen_helper_hlx_trace_op (tcg_env,tcg_constant_i32 (insn->opcode));
Signature · 1 line
2.52.0
Re: [PATCH v1 1/6] target/hexagon: HLX, preserve scalar :mem_noshuf ordering
Quoted 11 lines · Anton Johansson
A packet containing HLX instructions currently defers all stores to the end of the packet, this breaks scalar :mem_noshuf ordering. Only reorder HLX stores.
Fixes a6fae6da070d66b9 ("target/hexagon: translate packets with HLX instructions")Signed-off-by Anton Johansson <[email protected]>--- target/hexagon/translate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
PATCH 2/6 target/hexagon: HLX, search for .new values in pair high register
In reply to Anton Johansson via qemu developmentOtherwise, the following packet
{
L7:6 = combine(L0, L1)
memw(R7) = L7.new
}results in memw(R7) being zero-intialized, compared to L6.new which would correctly write the lower bytes of the pair.
--- target/hexagon/decode.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
target/hexagon/decode.c +18 -2
@@ -110,9 +110,25 @@ static int hlx_find_new_value_producer(Packet *packet, int consumer, {for (int i =0 ; i < packet->num_insns; i++) {Insn *insn = &packet->insn[i]; +uint8_t regno; -if (i != consumer &&GET_ATTRIB (insn->opcode,A_HLX ) && - insn->dest_idx !=-1 && insn->regno[insn->dest_idx] == lreg) { +/* +* Skip ourselves, instructions without return values, and +* any non-HLX instructions. +*/ +if (i == consumer || !GET_ATTRIB (insn->opcode,A_HLX ) || + insn->dest_idx ==-1 ) { +continue ; + } + + regno = insn->regno[insn->dest_idx]; + +/* +* Compare against the base register number, and against the top +* register for instructions returning pairs. +*/ +if (regno == lreg || + (GET_ATTRIB (insn->opcode,A_HLX_PAIRED_ALU ) && regno +1 == lreg)) {return i; } }
Signature · 1 line
2.52.0
PATCH 3/6 target/hexagon: Forward return address to HLX load/store helpers
In reply to Anton Johansson via qemu development--- target/hexagon/macros.h | 13 +++++++++---- target/hexagon/hlx_helper.c | 31 ++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 13 deletions(-)
target/hexagon/macros.h +9 -4
@@ -22,6 +22,7 @@#include "hex_regs.h" #include "reg_fields.h" #include "accel/tcg/getpc.h" +#include "hlx_helper.h" #define GET_FIELD (FIELD ,REGIN ) \ fEXTRACTU_BITS(REGIN, reg_field_info[FIELD].width, \
@@ -738,8 +739,10 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift) EA, tcg_constant_i32(ABOVE), \ tcg_constant_i32(BELOW))#else -#define fLOADMML (EA ,DST ,ABOVE ,BELOW ) \ - do { HELPER(hlx_load_vec)(env, &(DST), (EA), (ABOVE), (BELOW)); } while (0) +#define fLOADMML (EA ,DST ,ABOVE ,BELOW ) \ + do { \ + hlx_load_vec_ra(env, &(DST), (EA), (ABOVE), (BELOW), GETPC()); \ + } while (0)#endif /* The helper logs the store for packet commit. */
@@ -748,8 +751,10 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)gen_helper_hlx_store_vec (tcg_env,EA ,tcg_constant_ptr ((intptr_t )&(SRC )), \ tcg_constant_i32(ABOVE), tcg_constant_i32(BELOW))#else -#define fSTOREMML (EA ,SRC ,ABOVE ,BELOW ) \ - do { HELPER(hlx_store_vec)(env, (EA), &(SRC), (ABOVE), (BELOW)); } while (0) +#define fSTOREMML (EA ,SRC ,ABOVE ,BELOW ) \ + do { \ + hlx_store_vec_ra(env, (EA), &(SRC), (ABOVE), (BELOW), GETPC()); \ + } while (0)#endif /* Helpers receive .new registers in future_LRegs. */
target/hexagon/hlx_helper.c +22 -9
@@ -7,6 +7,7 @@#include "cpu.h" #include "accel/tcg/cpu-ldst.h" #include "exec/helper-proto.h" +#include "hlx_helper.h" #include "hlx/hlx.h" #include "hw/hexagon/hexagon_hlx.h" #include "accel/tcg/probe.h"
@@ -15,40 +16,52 @@#define HLX_MEM_ALIGN_MASK (~(HLX_VEC_SIZE_BYTES - 1))/* Align down to 2KB. Above and below are unused in V85. */ -void HELPER (hlx_load_vec )(CPUHexagonState *env,void *dst_void, -target_ulong ea,uint32_t above,uint32_t below) +void hlx_load_vec_ra (CPUHexagonState *env,void *dst_void, +target_ulong ea,uint32_t above,uint32_t below, +uintptr_t ra) {HLXVector *dst = (HLXVector *)dst_void;target_ulong aligned_ea = ea &HLX_MEM_ALIGN_MASK ; -uintptr_t raddr =GETPC ();int mmu_idx =cpu_mmu_index (env_cpu (env), false);/* A 2KB-aligned access stays within one page. */ -void *host =probe_read (env, aligned_ea,HLX_VEC_SIZE_BYTES , mmu_idx, - raddr); +void *host =probe_read (env, aligned_ea,HLX_VEC_SIZE_BYTES , mmu_idx, ra);if (host) {memcpy (dst, host,HLX_VEC_SIZE_BYTES ); }else {for (int i =0 ; i <HLX_VEC_SIZE_BYTES ; i +=8 ) { -uint64_t val =cpu_ldq_le_data_ra (env, aligned_ea + i, raddr); +uint64_t val =cpu_ldq_le_data_ra (env, aligned_ea + i, ra);memcpy (&dst->ub[i], &val,8 ); } } } -void HELPER (hlx_store_vec )(CPUHexagonState *env,target_ulong ea, -void *src_void,uint32_t above,uint32_t below) +void hlx_store_vec_ra (CPUHexagonState *env,target_ulong ea, +void *src_void,uint32_t above,uint32_t below, +uintptr_t ra) {target_ulong aligned_ea = ea &HLX_MEM_ALIGN_MASK ;int mmu_idx =cpu_mmu_index (env_cpu (env), false); -probe_write (env, aligned_ea,HLX_VEC_SIZE_BYTES , mmu_idx,GETPC ()); +probe_write (env, aligned_ea,HLX_VEC_SIZE_BYTES , mmu_idx, ra);memcpy (&env->hlx_store_data, src_void,sizeof (HLXVector)); env->hlx_store_va = aligned_ea; env->hlx_store_pending = true; } +void HELPER (hlx_load_vec )(CPUHexagonState *env,void *dst_void, +target_ulong ea,uint32_t above,uint32_t below) +{ +hlx_load_vec_ra (env, dst_void, ea, above, below,GETPC ()); +} + +void HELPER (hlx_store_vec )(CPUHexagonState *env,target_ulong ea, +void *src_void,uint32_t above,uint32_t below) +{ +hlx_store_vec_ra (env, ea, src_void, above, below,GETPC ()); +} +void HELPER (hlx_commit_store )(CPUHexagonState *env) {target_ulong va = env->hlx_store_va;
Signature · 1 line
2.52.0
Re: [PATCH v1 3/6] target/hexagon: Forward return address to HLX load/store helpers
Quoted 1 line · Anton Johansson
Could you add a commit message body which explains what this fix is for?
Quoted 12 lines
Fixes 2db29a3615a5ad2a3 ("target/hexagon: add HLX helper support")Signed-off-by Anton Johansson <[email protected]>--- target/hexagon/macros.h | 13 +++++++++---- target/hexagon/hlx_helper.c | 31 ++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 13 deletions(-)target/hexagon/macros.h +0
-0
target/hexagon/macros.h line 25
Quoted 4 lines
target/hexagon/macros.h +1
-0@@ -22,6 +22,7 @@#include "hex_regs.h" #include "reg_fields.h" #include "accel/tcg/getpc.h" +#include "hlx_helper.h"
hlx_helper.h is missing, so this commit (/series) doesn't build.
[...]
Does it make sense to write a test for this? How did you find it?
Re: [PATCH v1 3/6] target/hexagon: Forward return address to HLX load/store helpers
Quoted 24 lines · Marco Liebel
Quoted 1 line · Anton Johansson
Could you add a commit message body which explains what this fix is for?
Quoted 12 lines
Fixes 2db29a3615a5ad2a3 ("target/hexagon: add HLX helper support")Signed-off-by Anton Johansson <[email protected]>--- target/hexagon/macros.h | 13 +++++++++---- target/hexagon/hlx_helper.c | 31 ++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 13 deletions(-)target/hexagon/macros.h +0
-0target/hexagon/macros.h line 25
Quoted 4 lines
target/hexagon/macros.h +1
-0@@ -22,6 +22,7 @@#include "hex_regs.h" #include "reg_fields.h" #include "accel/tcg/getpc.h" +#include "hlx_helper.h"
hlx_helper.his missing, so this commit (/series) doesn't build.
Quoted 4 lines
[...]
Does it make sense to write a test for this? How did you find it?
Ah ofc I forgot to add it, my bad! It's a fairly common mistake when dealing with faulting helpers, and a mistake I've made plenty of times myself.
Signature · 2 lines
Anton Johansson rev.ng Labs Srl.
Re: [PATCH v1 3/6] target/hexagon: Forward return address to HLX load/store helpers
Quoted 25 lines · Anton Johansson
Quoted 24 lines · Marco Liebel
Quoted 1 line · Anton Johansson
Could you add a commit message body which explains what this fix is for?
Quoted 12 lines
Fixes 2db29a3615a5ad2a3 ("target/hexagon: add HLX helper support")Signed-off-by Anton Johansson <[email protected]>--- target/hexagon/macros.h | 13 +++++++++---- target/hexagon/hlx_helper.c | 31 ++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 13 deletions(-)target/hexagon/macros.h +0
-0target/hexagon/macros.h line 25
Quoted 4 lines
target/hexagon/macros.h +1
-0@@ -22,6 +22,7 @@#include "hex_regs.h" #include "reg_fields.h" #include "accel/tcg/getpc.h" +#include "hlx_helper.h"
hlx_helper.his missing, so this commit (/series) doesn't build.
Quoted 8 lines
Quoted 4 lines
[...]
Does it make sense to write a test for this? How did you find it?
Ah ofc I forgot to add it, my bad! It's a fairly common mistake when dealing with faulting helpers, and a mistake I've made plenty of times myself.
Forgot the other part of your question. No I don't think this makes sense to test for a single target, maybe if it could be tested or verified project-wide somehow since it's such a common issue with faulting helpers?
Signature · 2 lines
Anton Johansson rev.ng Labs Srl.
PATCH 4/6 linux-user/hexagon: Reset hlx_ctx pointer on cpu clone
In reply to Anton Johansson via qemu developmentCurrently hlx_ctx retains the pointer to the hlx_user_ctx of its parent. Another way to go is similar to hvx_ctx, which in user-mode, is just the struct itself rather than a pointer to the struct.
--- linux-user/hexagon/target_cpu.h | 1 + 1 file changed, 1 insertion(+)
linux-user/hexagon/target_cpu.h +1 -0
@@ -25,6 +25,7 @@ static inline void cpu_clone_regs_child(CPUHexagonState *env, env->gpr[HEX_REG_SP ] = newsp; } env->gpr[0 ] =0 ; + env->hlx_ctx = &env->hlx_user_ctx; }static inline void cpu_clone_regs_parent (CPUHexagonState *env,unsigned flags)
Signature · 1 line
2.52.0
Re: [PATCH v1 4/6] linux-user/hexagon: Reset hlx_ctx pointer on cpu clone
Quoted 11 lines · Anton Johansson
Currently
hlx_ctxretains the pointer to thehlx_user_ctxof its parent. Another way to go is similar tohvx_ctx, which in user-mode, is just the struct itself rather than a pointer to the struct.Fixes cf0bfbc338eaeef2b ("target/hexagon: manage HLX contexts through CCR")Signed-off-by Anton Johansson <[email protected]>--- linux-user/hexagon/target_cpu.h | 1 + 1 file changed, 1 insertion(+)
PATCH 5/6 tests/tcg/hexagon: test HLX scalar :mem_noshuf ordering
In reply to Anton Johansson via qemu developmentA packet containing HLX operations defer stores to the end of the packet, make sure this doesn't interfere with scalar :mem_noshuf ordering.
--- tests/tcg/hexagon/hlx_mem.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
tests/tcg/hexagon/hlx_mem.c +22 -0
@@ -229,6 +229,25 @@ static void test_store_fault(void)check_h ("LX_S16b_new (fault)" , buf_out, expected,HLX_HALF_ELEMS ); } +static void test_preserve_scalar_noshuf (void ) +{ +uint32_t ret =0 ; +uint32_t ptr =0 ; +uint32_t val =0x1234 ; + asmvolatile ("{\n" +".word 0xe5007822\n" +" memw(%1) = %2\n" +" %0 = memw(%1)\n" +"}:mem_noshuf\n" + :"=r" (ret) + :"r" (&ptr),"r" (val) + :"memory" ); +if (ret != val) { +printf ("FAIL broken scalar :mem_noshuf ordering\n" ); + err++; + } +} +int main (void ) {init_vtcm ();
@@ -253,6 +272,9 @@ int main(void)/* Store in a faulting packet */ test_store_fault (); +/* Make sure HLX packets preserve scalar :mem_noshuf ordering */ +test_preserve_scalar_noshuf (); +puts (err ?"FAIL" :"PASS" );return err; }
Signature · 1 line
2.52.0
PATCH 6/6 tests/tcg/hexagon: HLX, test .new on pair high register
In reply to Anton Johansson via qemu developmentMakes sure a pair operation is recognized as a producer of a .new value when only the high part is accessed.
--- tests/tcg/hexagon/hlx_assign_conv.c | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
tests/tcg/hexagon/hlx_assign_conv.c +35 -0
@@ -120,6 +120,40 @@ static void test_assign_rw(void)check_wp ("LX_assign_rw" , pw_out_lo, pw_out_hi, expected_w,HLX_HALF_ELEMS ); } +static void test_combine_assign_hi (void ) +{ +/* +* Tests that a combine operation acts as a producer of a .new value for +* the high vector in a pair. +*/ +HLX_Vector l_lo; +HLX_Vector l_hi; + +fill_w (pw_a_lo, pw_a_hi,VAL_W ); + + l_lo =Q6_L_tmp_mem_A (pw_a_lo); + l_hi =Q6_L_tmp_mem_A (pw_a_hi); + +hlx_put_v (0 , l_lo); +hlx_put_v (2 , l_hi); +/* +* { +* L7:6 = combine(L0, L1) +* memw(R7) = L7.new +* } +*/ + asm volatile(HLX_PTRS HLX_LD0 HLX_LD2 +".word 0xef24602d\n" +".word 0xa487c007\n" + : : [stage] "r"(hlx_stage) : HLX_CLOBBERS); +Q6_mem_Ku16_new_AL (buf_a,hlx_get_v (7 )); + +for (int j =0 ; j <HLX_HALF_ELEMS ; j++) { + expected[j] =VAL_A ; + } +check_h ("LX_assign_w (hi only)" , buf_a, expected,HLX_HALF_ELEMS ); +} +static void test_combine_w (void ) {
@@ -336,6 +370,7 @@ int main(void)test_assign_s ();test_assign_u ();test_assign_rw (); +test_combine_assign_hi ();/* Combine and mux */ test_combine_w ();
Signature · 1 line
2.52.0
Quoted 6 lines · Anton Johansson via qemu development
Hi,
I was too slow on the review before the series got PRd, so I'll submit these preliminary fixes instead. Not included here is a fix for --disable-hexagon-idef-parser being broken with the new stub HMX helpers.
Thanks for the fixes! Traveling part of this week, I will take a look at it soon.
Quoted 18 lines
Anton Johansson (6):
target/hexagon: HLX, preserve scalar :mem_noshuf ordering target/hexagon: HLX, search for .new values in pair high register target/hexagon: Forward return address to HLX load/store helpers linux-user/hexagon: Resethlx_ctxpointer on cpu clone tests/tcg/hexagon: test HLX scalar :mem_noshuf ordering tests/tcg/hexagon: HLX, test .new on pair high registerlinux-user/hexagon/target_cpu.h | 1 + target/hexagon/macros.h | 13 +++++++---- target/hexagon/decode.c | 20 +++++++++++++++-- target/hexagon/hlx_helper.c | 31 +++++++++++++++++-------- target/hexagon/translate.c | 7 +++--- tests/tcg/hexagon/hlx_assign_conv.c | 35 +++++++++++++++++++++++++++++ tests/tcg/hexagon/hlx_mem.c | 22 ++++++++++++++++++ 7 files changed, 111 insertions(+), 18 deletions(-)
Quoted 26 lines · Anton Johansson
Hi,
I was too slow on the review before the series got PRd, so I'll submit these preliminary fixes instead. Not included here is a fix for --disable-hexagon-idef-parser being broken with the new stub HMX helpers.
Anton Johansson (6):
target/hexagon: HLX, preserve scalar :mem_noshuf ordering target/hexagon: HLX, search for .new values in pair high register target/hexagon: Forward return address to HLX load/store helpers linux-user/hexagon: Resethlx_ctxpointer on cpu clone tests/tcg/hexagon: test HLX scalar :mem_noshuf ordering tests/tcg/hexagon: HLX, test .new on pair high registerlinux-user/hexagon/target_cpu.h | 1 + target/hexagon/macros.h | 13 +++++++---- target/hexagon/decode.c | 20 +++++++++++++++-- target/hexagon/hlx_helper.c | 31 +++++++++++++++++-------- target/hexagon/translate.c | 7 +++--- tests/tcg/hexagon/hlx_assign_conv.c | 35 +++++++++++++++++++++++++++++ tests/tcg/hexagon/hlx_mem.c | 22 ++++++++++++++++++ 7 files changed, 111 insertions(+), 18 deletions(-)
Quoted 3 lines
--
2.52.0
General note: I think combining patch 1+5 and 2+6 would make sense, because then it's easier to reason about them and give feedback, since they belong together.
Quoted 27 lines · Marco Liebel
Quoted 26 lines · Anton Johansson
Hi,
I was too slow on the review before the series got PRd, so I'll submit these preliminary fixes instead. Not included here is a fix for --disable-hexagon-idef-parser being broken with the new stub HMX helpers.
Anton Johansson (6):
target/hexagon: HLX, preserve scalar :mem_noshuf ordering target/hexagon: HLX, search for .new values in pair high register target/hexagon: Forward return address to HLX load/store helpers linux-user/hexagon: Resethlx_ctxpointer on cpu clone tests/tcg/hexagon: test HLX scalar :mem_noshuf ordering tests/tcg/hexagon: HLX, test .new on pair high registerlinux-user/hexagon/target_cpu.h | 1 + target/hexagon/macros.h | 13 +++++++---- target/hexagon/decode.c | 20 +++++++++++++++-- target/hexagon/hlx_helper.c | 31 +++++++++++++++++-------- target/hexagon/translate.c | 7 +++--- tests/tcg/hexagon/hlx_assign_conv.c | 35 +++++++++++++++++++++++++++++ tests/tcg/hexagon/hlx_mem.c | 22 ++++++++++++++++++ 7 files changed, 111 insertions(+), 18 deletions(-)
Quoted 8 lines
Quoted 3 lines
--
2.52.0General note: I think combining patch 1+5 and 2+6 would make sense, because then it's easier to reason about them and give feedback, since they belong together.
Right, will do! :)
Signature · 2 lines
Anton Johansson rev.ng Labs Srl.