Hexagon (target/hexagon) Check for multiwrites in analyze_packet
cover Hexagon (target/hexagon) Check for multiwrites in analyze_packet
Currently, we check for register multiwrites during packet decode. The downside of this approach is that it only checks a single destination register for each instruction. During analyze_packet, we can check for more than one instruction. Further, we can check for different types of registers. This series adds checks for HVX v-registers and q-registers.
Note that multiple writes to a predicate register are allowed on Hexagon.
Taylor Simpson (8):
Hexagon (target/hexagon) Move code out of gen_start_packet Hexagon (target/hexagon) Check for GPR multiwrite in analyze_packet Hexagon (tests/tcg/hexagon) Add tests for multi-destination
instructions
Hexagon (target/hexagon) Check for vreg multiwrite in analyze_packet Hexagon (tests/tcg/hexagon) Add tests for vreg multiple writes Hexagon (target/hexagon) Check for qreg multiwrite in analyze_packet Hexagon (tests/tcg/hexagon) Add tests for qreg multiple writes Hexagon (target/hexagon) Remove old way of detecting register
multiwrites
target/hexagon/insn.h | 4 - target/hexagon/translate.h | 25 +++++- target/hexagon/decode.c | 54 ------------ target/hexagon/translate.c | 77 ++++++++++++----- tests/tcg/hexagon/multiple-writes.c | 129 ++++++++++++++++++++++++++++ target/hexagon/gen_trans_funcs.py | 10 --- tests/tcg/hexagon/Makefile.target | 1 + 7 files changed, 210 insertions(+), 90 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/8 Hexagon (target/hexagon) Move code out of gen_start_packet
Move clear_pkt_ctx and analyze_packet out of gen_start_packet Precursor to adding packet validity checks to analyze_packet
--- target/hexagon/translate.c | 46 ++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 19 deletions(-)
target/hexagon/translate.c +27 -19
@@ -407,29 +407,12 @@ static void mark_implicit_writes(DisasContext *ctx)mark_implicit_pred_writes (ctx); } -static void analyze_packet (DisasContext *ctx) -{ -Packet *pkt = ctx->pkt; - ctx->read_after_write = false; - ctx->has_hvx_overlap = false; -for (int i =0 ; i < pkt->num_insns; i++) { -Insn *insn = &pkt->insn[i]; - ctx->insn = insn; -if (opcode_analyze[insn->opcode]) { - opcode_analyze[insn->opcode](ctx); - } - } - - ctx->need_commit =need_commit (ctx); -} - -static void gen_start_packet (DisasContext *ctx) +static void clear_pkt_ctx (DisasContext *ctx) {Packet *pkt = ctx->pkt;target_ulong next_PC = ctx->base.pc_next + pkt->encod_pkt_size_in_bytes;int i; -/* Clear out the disassembly context */ ctx->next_PC = next_PC; ctx->reg_log_idx =0 ;bitmap_zero (ctx->regs_written,TOTAL_PER_THREAD_REGS );
@@ -458,8 +441,29 @@ static void gen_start_packet(DisasContext *ctx)for (i =0 ; i <NUM_PREGS ; i++) { ctx->new_pred_value[i] =NULL ; } +} -analyze_packet (ctx); +static void analyze_packet (DisasContext *ctx) +{ +Packet *pkt = ctx->pkt; + ctx->read_after_write = false; + ctx->has_hvx_overlap = false; +for (int i =0 ; i < pkt->num_insns; i++) { +Insn *insn = &pkt->insn[i]; + ctx->insn = insn; +if (opcode_analyze[insn->opcode]) { + opcode_analyze[insn->opcode](ctx); + } + } + + ctx->need_commit =need_commit (ctx); +} + +static void gen_start_packet (DisasContext *ctx) +{ +Packet *pkt = ctx->pkt; +target_ulong next_PC = ctx->base.pc_next + pkt->encod_pkt_size_in_bytes; +int i;/* * pregs_written is used both in the analyze phase as well as the code
@@ -957,6 +961,10 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx) words_read =decode_packet (ctx, nwords, words, &pkt, false);if (words_read >0 ) { pkt.pc = ctx->base.pc_next; + +clear_pkt_ctx (ctx); +analyze_packet (ctx); +if (pkt.pkt_has_write_conflict) {gen_exception_decode_fail (ctx, words_read,HEX_CAUSE_REG_WRITE_CONFLICT );
Signature · 1 line
2.43.0
PATCH 2/8 Hexagon (target/hexagon) Check for GPR multiwrite in analyze_packet
In reply to Taylor SimpsonFor now, assert the new method is a subset of the old method We'll remove the old method in a subsequent patch
--- target/hexagon/translate.h | 6 ++++++ target/hexagon/translate.c | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-)
target/hexagon/translate.h +6 -0
@@ -39,6 +39,8 @@ typedef struct DisasContext {int reg_log_idx;DECLARE_BITMAP (regs_written,TOTAL_PER_THREAD_REGS );DECLARE_BITMAP (predicated_regs,TOTAL_PER_THREAD_REGS ); +DECLARE_BITMAP (gpr_multi_write,TOTAL_PER_THREAD_REGS ); +DECLARE_BITMAP (gpr_uncond,TOTAL_PER_THREAD_REGS );bool implicit_usr_write;int preg_log[PRED_WRITES_MAX ];int preg_log_idx;
@@ -113,9 +115,13 @@ static inline void ctx_log_reg_write(DisasContext *ctx, int rnum, ctx->reg_log[ctx->reg_log_idx] = rnum; ctx->reg_log_idx++;set_bit (rnum, ctx->regs_written); + }else { +set_bit (rnum, ctx->gpr_multi_write); }if (is_predicated) {set_bit (rnum, ctx->predicated_regs); + }else { +set_bit (rnum, ctx->gpr_uncond); } } }
target/hexagon/translate.c +21 -1
@@ -417,6 +417,8 @@ static void clear_pkt_ctx(DisasContext *ctx) ctx->reg_log_idx =0 ;bitmap_zero (ctx->regs_written,TOTAL_PER_THREAD_REGS );bitmap_zero (ctx->predicated_regs,TOTAL_PER_THREAD_REGS ); +bitmap_zero (ctx->gpr_multi_write,TOTAL_PER_THREAD_REGS ); +bitmap_zero (ctx->gpr_uncond,TOTAL_PER_THREAD_REGS ); ctx->preg_log_idx =0 ;bitmap_zero (ctx->pregs_written,NUM_PREGS ); ctx->future_vregs_idx =0 ;
@@ -443,6 +445,19 @@ static void clear_pkt_ctx(DisasContext *ctx) } } +static bool pkt_has_write_conflict (DisasContext *ctx) +{ +DECLARE_BITMAP (gpr_conflict,TOTAL_PER_THREAD_REGS ); + +bitmap_and (gpr_conflict, ctx->gpr_multi_write, ctx->gpr_uncond, +TOTAL_PER_THREAD_REGS ); +if (!bitmap_empty (gpr_conflict,TOTAL_PER_THREAD_REGS )) { +return true; + } + +return false; +} +static void analyze_packet (DisasContext *ctx) {Packet *pkt = ctx->pkt;
@@ -965,7 +980,12 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)clear_pkt_ctx (ctx);analyze_packet (ctx); -if (pkt.pkt_has_write_conflict) { +/* +* Check that the new method is a superset of the old methond +* Remove in a later patch +*/ +g_assert (!pkt.pkt_has_write_conflict ||pkt_has_write_conflict (ctx)); +if (pkt_has_write_conflict (ctx)) {gen_exception_decode_fail (ctx, words_read,HEX_CAUSE_REG_WRITE_CONFLICT );return ;
Signature · 1 line
2.43.0
PATCH 3/8 Hexagon (tests/tcg/hexagon) Add tests for multi-destination instructions
In reply to Taylor SimpsonInstructions such as post-increment loads define multiple destinations These make it harder to detect multi-write conflicts
--- tests/tcg/hexagon/multiple-writes.c | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
tests/tcg/hexagon/multiple-writes.c +60 -0
@@ -143,6 +143,62 @@ static int test_zero(void)return sig; } +/* Test multiple post-increment writes to the same GPR */ +static int test_post_increment1 (void ) +{ +int sig; + + asmvolatile ( +"r0 = #0\n" +"r1 = ##1f\n" +"memw(%1) = r1\n" +".word 0x9b004021 /* { r1 = memb(r0++#1) */\n" +".word 0x9b00c022 /* r2 = memb(r0++#1) } */\n" +"1:\n" +"%0 = r0\n" + :"=r" (sig) + :"r" (&resume_pc) + :"r0" ,"r1" ,"memory" ); + +return sig; +} + +static int test_post_increment2 (void ) +{ +int sig; + + asmvolatile ( +"r0 = #0\n" +"r1 = ##1f\n" +"memw(%1) = r1\n" +".word 0x9b00c020 /* r0 = memb(r0++#1) */\n" +"1:\n" +"%0 = r0\n" + :"=r" (sig) + :"r" (&resume_pc) + :"r0" ,"r1" ,"memory" ); + +return sig; +} + +static int test_post_increment3 (void ) +{ +int sig; + + asmvolatile ( +"r0 = #0\n" +"r1 = ##1f\n" +"memw(%1) = r1\n" +".word 0x9bc1c020 /* r1:0 = memd(r1++#8) */\n" +"1:\n" +"%0 = r0\n" + :"=r" (sig) + :"r" (&resume_pc) + :"r0" ,"r1" ,"memory" ); + +return sig; +} +int main () {struct sigaction act;
@@ -164,6 +220,10 @@ int main()/* Illegal: zero encoding = duplex with duplicate dest R0 */ assert (test_zero () ==SIGILL ); +assert (test_post_increment1 () ==SIGILL ); +assert (test_post_increment2 () ==SIGILL ); +assert (test_post_increment3 () ==SIGILL ); +puts ("PASS" );return EXIT_SUCCESS ; }
Signature · 1 line
2.43.0
PATCH 4/8 Hexagon (target/hexagon) Check for vreg multiwrite in analyze_packet
In reply to Taylor Simpson--- target/hexagon/translate.h | 12 +++++++++++- target/hexagon/translate.c | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-)
target/hexagon/translate.h +11 -1
@@ -60,6 +60,8 @@ typedef struct DisasContext {DECLARE_BITMAP (vregs_select,NUM_VREGS );DECLARE_BITMAP (predicated_future_vregs,NUM_VREGS );DECLARE_BITMAP (predicated_tmp_vregs,NUM_VREGS ); +DECLARE_BITMAP (vregs_multi_write,NUM_VREGS ); +DECLARE_BITMAP (vregs_uncond,NUM_VREGS );DECLARE_BITMAP (insn_vregs_read,NUM_VREGS );int qreg_log[NUM_QREGS ];int qreg_log_idx;
@@ -174,7 +176,11 @@ static inline void ctx_log_vreg_write(DisasContext *ctx, ctx->has_hvx_overlap = true; } } -set_bit (rnum, ctx->vregs_written); +if (!test_bit (rnum, ctx->vregs_written)) { +set_bit (rnum, ctx->vregs_written); + }else { +set_bit (rnum, ctx->vregs_multi_write); + }if (type !=EXT_TMP ) {if (!test_bit (rnum, ctx->vregs_updated)) { ctx->vreg_log[ctx->vreg_log_idx] = rnum;
@@ -185,6 +191,8 @@ static inline void ctx_log_vreg_write(DisasContext *ctx,set_bit (rnum, ctx->vregs_updated);if (is_predicated) {set_bit (rnum, ctx->predicated_future_vregs); + }else { +set_bit (rnum, ctx->vregs_uncond); } }if (type ==EXT_NEW ) {
@@ -194,6 +202,8 @@ static inline void ctx_log_vreg_write(DisasContext *ctx,set_bit (rnum, ctx->vregs_updated_tmp);if (is_predicated) {set_bit (rnum, ctx->predicated_tmp_vregs); + }else { +set_bit (rnum, ctx->vregs_uncond); } } }
target/hexagon/translate.c +9 -0
@@ -430,6 +430,8 @@ static void clear_pkt_ctx(DisasContext *ctx)bitmap_zero (ctx->vregs_select,NUM_VREGS );bitmap_zero (ctx->predicated_future_vregs,NUM_VREGS );bitmap_zero (ctx->predicated_tmp_vregs,NUM_VREGS ); +bitmap_zero (ctx->vregs_multi_write,NUM_VREGS ); +bitmap_zero (ctx->vregs_uncond,NUM_VREGS );bitmap_zero (ctx->qregs_written,NUM_QREGS ); ctx->qreg_log_idx =0 ;for (i =0 ; i <STORES_MAX ; i++) {
@@ -448,6 +450,7 @@ static void clear_pkt_ctx(DisasContext *ctx)static bool pkt_has_write_conflict (DisasContext *ctx) {DECLARE_BITMAP (gpr_conflict,TOTAL_PER_THREAD_REGS ); +DECLARE_BITMAP (vregs_conflict,NUM_VREGS );bitmap_and (gpr_conflict, ctx->gpr_multi_write, ctx->gpr_uncond,TOTAL_PER_THREAD_REGS );
@@ -455,6 +458,12 @@ static bool pkt_has_write_conflict(DisasContext *ctx)return true; } +bitmap_and (vregs_conflict, ctx->vregs_multi_write, ctx->vregs_uncond, +NUM_VREGS ); +if (!bitmap_empty (vregs_conflict,NUM_VREGS )) { +return true; + } +return false; }
Signature · 1 line
2.43.0
PATCH 5/8 Hexagon (tests/tcg/hexagon) Add tests for vreg multiple writes
In reply to Taylor Simpson--- tests/tcg/hexagon/multiple-writes.c | 46 +++++++++++++++++++++++++++++ tests/tcg/hexagon/Makefile.target | 1 + 2 files changed, 47 insertions(+)
tests/tcg/hexagon/multiple-writes.c +46 -0
@@ -199,6 +199,49 @@ static int test_post_increment3(void)return sig; } +static int test_vreg_legal_predicated (void ) +{ +int sig; + + asmvolatile ( +"r0 = #0\n" +"r1 = ##1f\n" +"memw(%1) = r1\n" +"r2 = #7\n" +"r3 = #13\n" +"p0 = cmp.eq(r2, r3)\n" +"{\n" +" if (p0) v0 = v1\n" +" if (!p0) v0 = v2\n" +"}\n" +"1:\n" +"%0 = #23\n" + :"=r" (sig) + :"r" (&resume_pc) + :"r0" ,"r1" ,"r2" ,"r3" ,"p0" ,"v0" ,"v1" ,"memory" ); + +return sig; +} + +static int test_vreg_illegal (void ) +{ +int sig; + + asmvolatile ( +"r0 = #0\n" +"r1 = ##1f\n" +"memw(%1) = r1\n" +".word 0x1e0361e0 /* { v0 = v1 */\n" +".word 0x1e03e2e0 /* v0 = v2 } */\n" +"1:\n" +"%0 = r0\n" + :"=r" (sig) + :"r" (&resume_pc) + :"r0" ,"r1" ,"memory" ); + +return sig; +} +int main () {struct sigaction act;
@@ -224,6 +267,9 @@ int main()assert (test_post_increment2 () ==SIGILL );assert (test_post_increment3 () ==SIGILL ); +assert (test_vreg_legal_predicated () ==23 ); +assert (test_vreg_illegal () ==SIGILL ); +puts ("PASS" );return EXIT_SUCCESS ; }
tests/tcg/hexagon/Makefile.target +1 -0
@@ -118,6 +118,7 @@ vector_add_int: CFLAGS += -mhvx -fvectorize hvx_misc: hvx_misc.c hvx_misc.h hvx_misc: CFLAGS += -mhvx hvx_histogram: CFLAGS += -mhvx -Wno-gnu-folding-constant +multiple-writes: CFLAGS += -mhvx v68_hvx: v68_hvx.c hvx_misc.h v6mpy_ref.c.inc v68_hvx: CFLAGS += -mhvx -Wno-unused-function v69_hvx: v69_hvx.c hvx_misc.h
Signature · 1 line
2.43.0
PATCH 6/8 Hexagon (target/hexagon) Check for qreg multiwrite in analyze_packet
In reply to Taylor Simpson--- target/hexagon/translate.h | 7 ++++++- target/hexagon/translate.c | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-)
target/hexagon/translate.h +6 -1
@@ -66,6 +66,7 @@ typedef struct DisasContext {int qreg_log[NUM_QREGS ];int qreg_log_idx;DECLARE_BITMAP (qregs_written,NUM_QREGS ); +DECLARE_BITMAP (qregs_multi_write,NUM_QREGS );DECLARE_BITMAP (insn_qregs_written,NUM_QREGS );DECLARE_BITMAP (insn_qregs_read,NUM_QREGS );bool pre_commit;
@@ -264,7 +265,11 @@ static inline void ctx_log_qreg_write(DisasContext *ctx, ctx->has_hvx_overlap = true; } } -set_bit (rnum, ctx->qregs_written); +if (!test_bit (rnum, ctx->qregs_written)) { +set_bit (rnum, ctx->qregs_written); + }else { +set_bit (rnum, ctx->qregs_multi_write); + } ctx->qreg_log[ctx->qreg_log_idx] = rnum; ctx->qreg_log_idx++; }
target/hexagon/translate.c +5 -0
@@ -433,6 +433,7 @@ static void clear_pkt_ctx(DisasContext *ctx)bitmap_zero (ctx->vregs_multi_write,NUM_VREGS );bitmap_zero (ctx->vregs_uncond,NUM_VREGS );bitmap_zero (ctx->qregs_written,NUM_QREGS ); +bitmap_zero (ctx->qregs_multi_write,NUM_QREGS ); ctx->qreg_log_idx =0 ;for (i =0 ; i <STORES_MAX ; i++) { ctx->store_width[i] =0 ;
@@ -464,6 +465,10 @@ static bool pkt_has_write_conflict(DisasContext *ctx)return true; } +if (!bitmap_empty (ctx->qregs_multi_write,NUM_QREGS )) { +return true; + } +return false; }
Signature · 1 line
2.43.0
PATCH 7/8 Hexagon (tests/tcg/hexagon) Add tests for qreg multiple writes
In reply to Taylor Simpson--- tests/tcg/hexagon/multiple-writes.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
tests/tcg/hexagon/multiple-writes.c +23 -0
@@ -242,6 +242,27 @@ static int test_vreg_illegal(void)return sig; } +static int test_qreg_illegal (void ) +{ +int sig; + + asmvolatile ( +"r0 = #0\n" +"r1 = ##1f\n" +"memw(%1) = r1\n" +"{\n" +".word 0x19a14048 /* { q0 = vand(v0, r1) */\n" +".word 0x19a0c044 /* q0 = vsetq(r0) } */\n" +"}\n" +"1:\n" +"%0 = r0\n" + :"=r" (sig) + :"r" (&resume_pc) + :"r0" ,"r1" ,"memory" ); + +return sig; +} +int main () {struct sigaction act;
@@ -270,6 +291,8 @@ int main()assert (test_vreg_legal_predicated () ==23 );assert (test_vreg_illegal () ==SIGILL ); +assert (test_qreg_illegal () ==SIGILL ); +puts ("PASS" );return EXIT_SUCCESS ; }
Signature · 1 line
2.43.0
PATCH 8/8 Hexagon (target/hexagon) Remove old way of detecting register multiwrites
In reply to Taylor SimpsonWe now detect register multiwrites in packet analyzis instead of packet decoding
--- target/hexagon/insn.h | 4 --- target/hexagon/decode.c | 54 ------------------------------- target/hexagon/translate.c | 5 --- target/hexagon/gen_trans_funcs.py | 10 ------ 4 files changed, 73 deletions(-)
target/hexagon/insn.h +0 -4
@@ -41,8 +41,6 @@ struct Instruction { uint32_t new_value_producer_slot:4;int32_t new_read_idx;int32_t dest_idx; -bool dest_is_pair; -bool dest_is_gpr;bool has_pred_dest;bool part1;/*
@@ -74,8 +72,6 @@ struct Packet {bool pkt_has_hvx;Insn *vhist_insn; -bool pkt_has_write_conflict; -Insn insn[INSTRUCTIONS_MAX ]; };
target/hexagon/decode.c +0 -54
72 lines not on this page · raw message
target/hexagon/translate.c +0 -5
@@ -994,11 +994,6 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)clear_pkt_ctx (ctx);analyze_packet (ctx); -/* -* Check that the new method is a superset of the old methond -* Remove in a later patch -*/ -g_assert (!pkt.pkt_has_write_conflict ||pkt_has_write_conflict (ctx));if (pkt_has_write_conflict (ctx)) {gen_exception_decode_fail (ctx, words_read,HEX_CAUSE_REG_WRITE_CONFLICT );
target/hexagon/gen_trans_funcs.py +0 -10
@@ -91,8 +91,6 @@ def gen_trans_funcs(f): new_read_idx = -1 dest_idx = -1 dest_idx_reg_id = None - dest_is_pair = "false" - dest_is_gpr = "false" has_pred_dest = "false" for regno, (reg_type, reg_id, *_) in enumerate(regs): reg = hex_common.get_register(tag, reg_type, reg_id)
@@ -106,12 +104,6 @@ def gen_trans_funcs(f): if dest_idx_reg_id is None or reg_id < dest_idx_reg_id: dest_idx = regno dest_idx_reg_id = reg_id - dest_is_pair = ("true" - if isinstance(reg, hex_common.Pair) - else "false") - dest_is_gpr = ("true" - if reg_type == "R" - else "false") if reg_type == "P" and reg.is_written() and not reg.is_read(): has_pred_dest = "true"
@@ -137,8 +129,6 @@ def gen_trans_funcs(f): f.write(code_fmt(f"""\ insn->new_read_idx = {new_read_idx}; insn->dest_idx = {dest_idx}; - insn->dest_is_pair = {dest_is_pair}; - insn->dest_is_gpr = {dest_is_gpr}; insn->has_pred_dest = {has_pred_dest}; """)) f.write(textwrap.dedent(f"""\
Signature · 1 line
2.43.0
Quoted 21 lines · Taylor Simpson
Currently, we check for register multiwrites during packet decode. The downside of this approach is that it only checks a single destination register for each instruction. During
analyze_packet, we can check for more than one instruction. Further, we can check for different types of registers. This series adds checks for HVX v-registers and q-registers.Note that multiple writes to a predicate register are allowed on Hexagon.
Taylor Simpson (8):
Hexagon (target/hexagon) Move code out ofgen_start_packetHexagon (target/hexagon) Check for GPR multiwrite inanalyze_packetHexagon (tests/tcg/hexagon) Add tests for multi-destination
instructions
Hexagon (target/hexagon) Check for vreg multiwrite inanalyze_packetHexagon (tests/tcg/hexagon) Add tests for vreg multiple writes Hexagon (target/hexagon) Check for qreg multiwrite inanalyze_packetHexagon (tests/tcg/hexagon) Add tests for qreg multiple writes Hexagon (target/hexagon) Remove old way of detecting register
multiwrites
Quoted 10 lines
target/hexagon/insn.h | 4 - target/hexagon/translate.h | 25 +++++- target/hexagon/decode.c | 54 ------------ target/hexagon/translate.c | 77 ++++++++++++----- tests/tcg/hexagon/multiple-writes.c | 129 ++++++++++++++++++++++++++++ target/hexagon/gen_trans_funcs.py | 10 --- tests/tcg/hexagon/Makefile.target | 1 + 7 files changed, 210 insertions(+), 90 deletions(-)
For this entire series:
Quoted 4 lines
--
2.43.0