Skip to contentSkip to conversation

Hexagon (target/hexagon) Check for multiwrites in analyze_packet

PATCH Superseded Taylor Simpson 3 participants 31 messages Sep 11 – Sep 14 Arm/Amlogic Meson SoC support

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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 write per 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.

Changes in v2
- Rebase against latest sources, including Hexagon system mode
- Add checks for multiple writes to system registers

Taylor Simpson (10):
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) Check for greg multiwrite in analyze_packet Hexagon (target/hexagon) Check for sreg multiwrite in analyze_packet Hexagon (target/hexagon) Remove old way of detecting register
multiwrites

 target/hexagon/insn.h               |   4 -
 target/hexagon/translate.h          |  47 ++++++++--
 target/hexagon/decode.c             |  54 ------------
 target/hexagon/translate.c          |  88 ++++++++++++++-----
 tests/tcg/hexagon/multiple-writes.c | 129 ++++++++++++++++++++++++++++
 target/hexagon/gen_trans_funcs.py   |  10 ---
 tests/tcg/hexagon/meson.build       |   2 +-
 7 files changed, 239 insertions(+), 95 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/10 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 | 45 ++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 19 deletions(-)
target/hexagon/translate.c +26 -19
index 5d3d67e5d3..52dd1f0266 100644
@@ -562,28 +562,13 @@ static void mark_implicit_writes(DisasContext *ctx)
     mark_implicit_pred_writes(ctx);
 }
 
-static void analyze_packet(DisasContext *ctx)
-{
-    ctx->read_after_write = false;
-    ctx->has_hvx_overlap = false;
-    for (int i = 0; i < ctx->pkt.num_insns; i++) {
-        Insn *insn = &ctx->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)
+/* Clear out the disassembly context */
+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);
@@ -616,8 +601,26 @@ 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)
+{
+    ctx->read_after_write = false;
+    ctx->has_hvx_overlap = false;
+    for (int i = 0; i < ctx->pkt.num_insns; i++) {
+        Insn *insn = &ctx->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)
+{
+    int i;
 
     /*
      * pregs_written is used both in the analyze phase as well as the code
@@ -659,7 +662,7 @@ static void gen_start_packet(DisasContext *ctx)
     ctx->pkt_ends_tb = pkt_ends_tb(&ctx->pkt);
     ctx->need_next_pc = need_next_PC(ctx);
     if (ctx->need_next_pc) {
-        tcg_gen_movi_tl(hex_next_PC, next_PC);
+        tcg_gen_movi_tl(hex_next_PC, ctx->next_PC);
     }
 
     /* Preload the predicated registers into get_result_gpr(ctx, i) */
@@ -1199,6 +1202,10 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)
     words_read = decode_packet(ctx, nwords, words, &ctx->pkt, false);
     if (words_read > 0) {
         ctx->pkt.pc = ctx->base.pc_next;
+
+        clear_pkt_ctx(ctx);
+        analyze_packet(ctx);
+
         if (ctx->pkt.pkt_has_write_conflict) {
             gen_exception_decode_fail(ctx, words_read,
                                       HEX_CAUSE_REG_WRITE_CONFLICT);
Signature · 1 line
2.43.0
Reviewed-by on v2 1/10
#2 lore raw

Re: [PATCH v2 01/10] Hexagon (target/hexagon) Move code out of gen_start_packet

Quoted 5 lines · Taylor Simpson

Move clear_pkt_ctx and analyze_packet out of gen_start_packet Precursor to adding packet validity checks to analyze_packet

---

Aside: I notice that you are touching "next_PC" here and it occurs to me that I have local follow-up patches from your previous suggestion on how to remove it.  I'm prioritizing closing functionality gaps over translation performance/codegen improvements for the time being, so it's somewhat deep in the queue.  I suppose I should bump it up a notch.

Quoted 86 lines
  target/hexagon/translate.c | 45 ++++++++++++++++++++++----------------
  1 file changed, 26 insertions(+), 19 deletions(-)
target/hexagon/translate.c +26 -19
index 5d3d67e5d3..52dd1f0266 100644
@@ -562,28 +562,13 @@ static void mark_implicit_writes(DisasContext *ctx)
      mark_implicit_pred_writes(ctx);
  }
 
-static void analyze_packet(DisasContext *ctx)
-{
-    ctx->read_after_write = false;
-    ctx->has_hvx_overlap = false;
-    for (int i = 0; i < ctx->pkt.num_insns; i++) {
-        Insn *insn = &ctx->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)
+/* Clear out the disassembly context */
+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);
@@ -616,8 +601,26 @@ 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)
+{
+    ctx->read_after_write = false;
+    ctx->has_hvx_overlap = false;
+    for (int i = 0; i < ctx->pkt.num_insns; i++) {
+        Insn *insn = &ctx->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)
+{
+    int i;
 
      /*
       * pregs_written is used both in the analyze phase as well as the code
@@ -659,7 +662,7 @@ static void gen_start_packet(DisasContext *ctx)
      ctx->pkt_ends_tb = pkt_ends_tb(&ctx->pkt);
      ctx->need_next_pc = need_next_PC(ctx);
      if (ctx->need_next_pc) {
-        tcg_gen_movi_tl(hex_next_PC, next_PC);
+        tcg_gen_movi_tl(hex_next_PC, ctx->next_PC);
      }
 
      /* Preload the predicated registers into get_result_gpr(ctx, i) */
@@ -1199,6 +1202,10 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)
      words_read = decode_packet(ctx, nwords, words, &ctx->pkt, false);
      if (words_read > 0) {
          ctx->pkt.pc = ctx->base.pc_next;
+
+        clear_pkt_ctx(ctx);
+        analyze_packet(ctx);
+
          if (ctx->pkt.pkt_has_write_conflict) {
              gen_exception_decode_fail(ctx, words_read,
                                        HEX_CAUSE_REG_WRITE_CONFLICT);
#3 lore raw

Re: [PATCH v2 01/10] Hexagon (target/hexagon) Move code out of gen_start_packet

Quoted 8 lines · Brian Cain
Quoted 5 lines · Taylor Simpson

Move clear_pkt_ctx and analyze_packet out of gen_start_packet Precursor to adding packet validity checks to analyze_packet

---

Quoted 9 lines

Aside: I notice that you are touching "next_PC" here and it occurs to me that I have local follow-up patches from your previous suggestion on how to remove it. I'm prioritizing closing functionality gaps over translation performance/codegen improvements for the time being, so it's somewhat deep in the queue. I suppose I should bump it up a notch.

FWIW, the changes to next_PC are de minimis.

The original gen_start_packet had

    target_ulong next_PC = ...
    ...
    ctx->next_PC = next_PC;
    ...
    if (...) {
        tcg_gen_movi_tl(hex_next_PC, next_PC);
    }

When I split that function in two, the local variable and assignment to ctx->next_PC ended up in clear_pkt_ctx. So, I changed the third snippet to

    if (...) {
        tcg_gen_movi_tl(hex_next_PC, ctx->next_PC);
    }

Thanks,
Taylor

Reviewed-by
#4 lore raw

Re: [PATCH v2 01/10] Hexagon (target/hexagon) Move code out of gen_start_packet

Quoted 8 lines · Taylor Simpson

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 | 45 ++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 19 deletions(-)
#5 lore raw

PATCH v2 2/10 Hexagon (target/hexagon) Check for GPR multiwrite in analyze_packet

In reply to Taylor Simpson

For now, assert the new method is a superset of the old method We'll remove the old method in a subsequent patch

---
 target/hexagon/translate.h |  6 ++++++
 target/hexagon/translate.c | 23 ++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)
target/hexagon/translate.h +6 -0
index d8628383f1..964e6ce0b7 100644
@@ -41,6 +41,8 @@ typedef struct DisasContext {
     DECLARE_BITMAP(regs_written, TOTAL_PER_THREAD_REGS);
     DECLARE_BITMAP(predicated_regs, TOTAL_PER_THREAD_REGS);
     bool pkt_ends_tb;
+    DECLARE_BITMAP(gpr_multi_write, TOTAL_PER_THREAD_REGS);
+    DECLARE_BITMAP(gpr_uncond, TOTAL_PER_THREAD_REGS);
     bool implicit_usr_write;
 #ifndef CONFIG_USER_ONLY
     int greg_log[GREG_WRITES_MAX];
@@ -157,9 +159,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 +22 -1
index 52dd1f0266..60441dc309 100644
@@ -577,6 +577,8 @@ static void clear_pkt_ctx(DisasContext *ctx)
     ctx->greg_log_idx = 0;
     ctx->sreg_log_idx = 0;
 #endif
+    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;
@@ -603,6 +605,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)
 {
     ctx->read_after_write = false;
@@ -1206,7 +1221,13 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)
         clear_pkt_ctx(ctx);
         analyze_packet(ctx);
 
-        if (ctx->pkt.pkt_has_write_conflict) {
+        /*
+         * Check that the new method is a superset of the old methond
+         * Remove in a later patch
+         */
+        g_assert(!ctx->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
Reviewed-by on v2 2/10
#6 lore raw

Re: [PATCH v2 02/10] Hexagon (target/hexagon) Check for GPR multiwrite in analyze_packet

Quoted 9 lines · Taylor Simpson

For now, assert the new method is a superset of the old method We'll remove the old method in a subsequent patch

---
 target/hexagon/translate.h |  6 ++++++
 target/hexagon/translate.c | 23 ++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)
#7 lore raw

PATCH v2 3/10 Hexagon (tests/tcg/hexagon) Add tests for multi-destination instructions

In reply to Taylor Simpson

Instructions 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
index 8686317fdc..4305903547 100644
@@ -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;
+
+    asm volatile(
+        "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;
+
+    asm volatile(
+        "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;
+
+    asm volatile(
+        "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
Reviewed-by on v2 3/10
#8 lore raw

Re: [PATCH v2 03/10] Hexagon (tests/tcg/hexagon) Add tests for multi-destination instructions

Quoted 5 lines · Taylor Simpson

Instructions such as post-increment loads define multiple destinations These make it harder to detect multi-write conflicts

---

Quoted 81 lines
  tests/tcg/hexagon/multiple-writes.c | 60 +++++++++++++++++++++++++++++
  1 file changed, 60 insertions(+)
tests/tcg/hexagon/multiple-writes.c +60 -0
index 8686317fdc..4305903547 100644
@@ -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;
+
+    asm volatile(
+        "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;
+
+    asm volatile(
+        "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;
+
+    asm volatile(
+        "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;
  }
Reviewed-by
#9 lore raw

Re: [PATCH v2 03/10] Hexagon (tests/tcg/hexagon) Add tests for multi-destination instructions

Quoted 8 lines · Taylor Simpson

Instructions 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(+)
#10 lore raw

PATCH v2 4/10 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
index 964e6ce0b7..9ee5f25365 100644
@@ -70,6 +70,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;
@@ -218,7 +220,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;
@@ -229,6 +235,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) {
@@ -238,6 +246,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
index 60441dc309..ca22bae28f 100644
@@ -589,6 +589,8 @@ static void clear_pkt_ctx(DisasContext *ctx)
     bitmap_zero(ctx->vregs_updated, NUM_VREGS);
     bitmap_zero(ctx->vregs_select, NUM_VREGS);
     bitmap_zero(ctx->predicated_future_vregs, NUM_VREGS);
+    bitmap_zero(ctx->vregs_multi_write, NUM_VREGS);
+    bitmap_zero(ctx->vregs_uncond, NUM_VREGS);
     bitmap_zero(ctx->predicated_tmp_vregs, NUM_VREGS);
     bitmap_zero(ctx->qregs_written, NUM_QREGS);
     ctx->qreg_log_idx = 0;
@@ -608,6 +610,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);
@@ -615,6 +618,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
#12 lore raw

PATCH v2 5/10 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/meson.build       |  2 +-
 2 files changed, 47 insertions(+), 1 deletion(-)
tests/tcg/hexagon/multiple-writes.c +46 -0
index 4305903547..b93f2ab32e 100644
@@ -199,6 +199,49 @@ static int test_post_increment3(void)
     return sig;
 }
 
+static int test_vreg_legal_predicated(void)
+{
+    int sig;
+
+    asm volatile(
+        "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;
+
+    asm volatile(
+        "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/meson.build +1 -1
index 4a2826c427..08c6e34c20 100644
@@ -54,7 +54,7 @@ tests += {
   'load_unpack.c': {'cflags': cflags},
   # Build this test with -mv71 to exercise the CABAC instruction
   'misc.c': {'cflags': [cflags, '-mv71', '-O2']},
-  'multiple-writes.c': {'cflags': cflags},
+  'multiple-writes.c': {'cflags': [cflags, '-mhvx']},
   'overflow.c': {'cflags': cflags, 'exe_name': 'hex-overflow'},
   'preg_alias.c': {'cflags': cflags},
   'dual_stores.c': {'cflags': cflags},
Signature · 1 line
2.43.0
#13 lore raw

Re: [PATCH v2 05/10] Hexagon (tests/tcg/hexagon) Add tests for vreg multiple writes

Quoted 48 lines · Taylor Simpson
---
 tests/tcg/hexagon/multiple-writes.c | 46 +++++++++++++++++++++++++++++
 tests/tcg/hexagon/meson.build       |  2 +-
 2 files changed, 47 insertions(+), 1 deletion(-)
tests/tcg/hexagon/multiple-writes.c +33 -0
index 4305903547..b93f2ab32e 100644
@@ -199,6 +199,49 @@ static int test_post_increment3(void)
     return sig;
 }
 
+static int test_vreg_legal_predicated(void)
+{
+    int sig;
+
+    asm volatile(
+        "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;
+
+    asm volatile(
+        "r0 = #0\n"
+        "r1 = ##1f\n"
+        "memw(%1) = r1\n"
+        ".word 0x1e0361e0    /* { v0 = v1 */\n"

tests/tcg/hexagon/multiple-writes.c static int test_post_increment3(void) · line 244

Quoted 10 lines
tests/tcg/hexagon/multiple-writes.c +10 -0
+        ".word 0x1e03e2e0    /*   v0 = v2  } */\n"
+        "1:\n"
+        "%0 = r0\n"
+        : "=r"(sig)
+        : "r"(&resume_pc)
+        : "r0", "r1", "memory");
+
+    return sig;
+}
+

Would it be useful to add a mixed predicated/unconditional test as well?

Such as:
if (p0) v0 = v1
v0 = v2

#14 lore raw

Re: [PATCH v2 05/10] Hexagon (tests/tcg/hexagon) Add tests for vreg multiple writes

Quoted 64 lines · Marco Liebel

Review

Quoted 8 lines · Taylor Simpson
---
 tests/tcg/hexagon/multiple-writes.c | 46 +++++++++++++++++++++++++++++
 tests/tcg/hexagon/meson.build       |  2 +-
 2 files changed, 47 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/tests/tcg/hexagon/multiple-writes.c

Quoted 40 lines

index 4305903547 <(430)%20590-3547>..b93f2ab32e 100644

tests/tcg/hexagon/multiple-writes.c +33 -0
@@ -199,6 +199,49 @@ static int test_post_increment3(void)
     return sig;
 }
 
+static int test_vreg_legal_predicated(void)
+{
+    int sig;
+
+    asm volatile(
+        "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;
+
+    asm volatile(
+        "r0 = #0\n"
+        "r1 = ##1f\n"
+        "memw(%1) = r1\n"
+        ".word 0x1e0361e0    /* { v0 = v1 */\n"

tests/tcg/hexagon/multiple-writes.c static int test_post_increment3(void) · line 244

Quoted 10 lines
tests/tcg/hexagon/multiple-writes.c +10 -0
+        ".word 0x1e03e2e0    /*   v0 = v2  } */\n"
+        "1:\n"
+        "%0 = r0\n"
+        : "=r"(sig)
+        : "r"(&resume_pc)
+        : "r0", "r1", "memory");
+
+    return sig;
+}
+

Would it be useful to add a mixed predicated/unconditional test as well?

Quoted 4 lines

Such as:
if (p0) v0 = v1
v0 = v2

Yes, will do.

Taylor

#15 lore raw

PATCH v2 6/10 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
index 9ee5f25365..b6cdf51c20 100644
@@ -76,6 +76,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;
@@ -308,7 +309,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
index ca22bae28f..815eecb60a 100644
@@ -593,6 +593,7 @@ static void clear_pkt_ctx(DisasContext *ctx)
     bitmap_zero(ctx->vregs_uncond, NUM_VREGS);
     bitmap_zero(ctx->predicated_tmp_vregs, 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;
@@ -624,6 +625,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
#17 lore raw

PATCH v2 7/10 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
index b93f2ab32e..86adc1331f 100644
@@ -242,6 +242,27 @@ static int test_vreg_illegal(void)
     return sig;
 }
 
+static int test_qreg_illegal(void)
+{
+    int sig;
+
+    asm volatile(
+        "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
#19 lore raw

PATCH v2 8/10 Hexagon (target/hexagon) Check for greg multiwrite in analyze_packet

In reply to Taylor Simpson
---
 target/hexagon/translate.h | 11 +++++++++--
 target/hexagon/translate.c |  8 ++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
target/hexagon/translate.h +9 -2
index b6cdf51c20..eb0d10d686 100644
@@ -47,6 +47,8 @@ typedef struct DisasContext {
 #ifndef CONFIG_USER_ONLY
     int greg_log[GREG_WRITES_MAX];
     int greg_log_idx;
+    DECLARE_BITMAP(gregs_written, NUM_GREGS);
+    DECLARE_BITMAP(gregs_multi_write, NUM_GREGS);
     int sreg_log[SREG_WRITES_MAX];
     int sreg_log_idx;
     TCGv_i32 t_sreg_new_value[HEX_SREG_GLB_START];
@@ -105,8 +107,13 @@ static inline void ctx_log_greg_write(DisasContext *ctx, int rnum)
     if (rnum > HEX_GREG_G3) {
         return;
     }
-    ctx->greg_log[ctx->greg_log_idx] = rnum;
-    ctx->greg_log_idx++;
+    if (!test_bit(rnum, ctx->gregs_written)) {
+        set_bit(rnum, ctx->gregs_written);
+        ctx->greg_log[ctx->greg_log_idx] = rnum;
+        ctx->greg_log_idx++;
+    } else {
+        set_bit(rnum, ctx->gregs_multi_write);
+    }
 }
 
 static inline void ctx_log_greg_write_pair(DisasContext *ctx, int rnum)
target/hexagon/translate.c +8 -0
index 815eecb60a..f469452daa 100644
@@ -575,6 +575,8 @@ static void clear_pkt_ctx(DisasContext *ctx)
     bitmap_zero(ctx->predicated_regs, TOTAL_PER_THREAD_REGS);
 #ifndef CONFIG_USER_ONLY
     ctx->greg_log_idx = 0;
+    bitmap_zero(ctx->gregs_written, NUM_GREGS);
+    bitmap_zero(ctx->qregs_multi_write, NUM_GREGS);
     ctx->sreg_log_idx = 0;
 #endif
     bitmap_zero(ctx->gpr_multi_write, TOTAL_PER_THREAD_REGS);
@@ -629,6 +631,12 @@ static bool pkt_has_write_conflict(DisasContext *ctx)
         return true;
     }
 
+#ifndef CONFIG_USER_ONLY
+    if (!bitmap_empty(ctx->gregs_multi_write, NUM_GREGS)) {
+        return true;
+    }
+#endif
+
     return false;
 }
 
Signature · 1 line
2.43.0
#20 lore raw

Re: [PATCH v2 08/10] Hexagon (target/hexagon) Check for greg multiwrite in analyze_packet

Quoted 12 lines · Taylor Simpson
---
 target/hexagon/translate.h | 11 +++++++++--
 target/hexagon/translate.c |  8 ++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
target/hexagon/translate.c +0 -0
index 815eecb60a..f469452daa 100644

target/hexagon/translate.c static void clear_pkt_ctx(DisasContext *ctx) · line 579

Quoted 5 lines
target/hexagon/translate.c +2 -0
@@ -575,6 +575,8 @@ static void clear_pkt_ctx(DisasContext *ctx)
     bitmap_zero(ctx->predicated_regs, TOTAL_PER_THREAD_REGS);
 #ifndef CONFIG_USER_ONLY
     ctx->greg_log_idx = 0;
+    bitmap_zero(ctx->gregs_written, NUM_GREGS);
+    bitmap_zero(ctx->qregs_multi_write, NUM_GREGS);

Should this be *g*regs_multi_write and not *q*regs_multi_write?

#21 lore raw

Re: [PATCH v2 08/10] Hexagon (target/hexagon) Check for greg multiwrite in analyze_packet

Quoted 9 lines · Marco Liebel
Quoted 7 lines · Taylor Simpson
---
 target/hexagon/translate.h | 11 +++++++++--
 target/hexagon/translate.c |  8 ++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
Quoted 13 lines

target/hexagon/translate.c static void clear_pkt_ctx(DisasContext *ctx) · line 579

Quoted 10 lines
target/hexagon/translate.c +2 -0
index 815eecb60a..f469452daa 100644
@@ -575,6 +575,8 @@ static void clear_pkt_ctx(DisasContext *ctx)
     bitmap_zero(ctx->predicated_regs, TOTAL_PER_THREAD_REGS);
 #ifndef CONFIG_USER_ONLY
     ctx->greg_log_idx = 0;
+    bitmap_zero(ctx->gregs_written, NUM_GREGS);
+    bitmap_zero(ctx->qregs_multi_write, NUM_GREGS);

Should this be *g*regs_multi_write and not *q*regs_multi_write?

Yes, I caught this when fixing the test-functional failures Brian pointed out.

Taylor

#22 lore raw

PATCH v2 9/10 Hexagon (target/hexagon) Check for sreg multiwrite in analyze_packet

In reply to Taylor Simpson
---
 target/hexagon/translate.h | 11 +++++++++--
 target/hexagon/translate.c |  4 ++++
 2 files changed, 13 insertions(+), 2 deletions(-)
target/hexagon/translate.h +9 -2
index eb0d10d686..b90f7fff1c 100644
@@ -51,6 +51,8 @@ typedef struct DisasContext {
     DECLARE_BITMAP(gregs_multi_write, NUM_GREGS);
     int sreg_log[SREG_WRITES_MAX];
     int sreg_log_idx;
+    DECLARE_BITMAP(sregs_written, NUM_SREGS);
+    DECLARE_BITMAP(sregs_multi_write, NUM_SREGS);
     TCGv_i32 t_sreg_new_value[HEX_SREG_GLB_START];
     TCGv_i32 greg_new_value[NUM_GREGS];
 #endif
@@ -125,8 +127,13 @@ static inline void ctx_log_greg_write_pair(DisasContext *ctx, int rnum)
 
 static inline void ctx_log_sreg_write(DisasContext *ctx, int rnum)
 {
-    ctx->sreg_log[ctx->sreg_log_idx] = rnum;
-    ctx->sreg_log_idx++;
+    if (!test_bit(rnum, ctx->sregs_written)) {
+        set_bit(rnum, ctx->sregs_written);
+        ctx->sreg_log[ctx->sreg_log_idx] = rnum;
+        ctx->sreg_log_idx++;
+    } else {
+        set_bit(rnum, ctx->sregs_multi_write);
+    }
 }
 
 static inline void ctx_log_sreg_write_pair(DisasContext *ctx, int rnum)
target/hexagon/translate.c +4 -0
index f469452daa..c40ca86810 100644
@@ -635,6 +635,10 @@ static bool pkt_has_write_conflict(DisasContext *ctx)
     if (!bitmap_empty(ctx->gregs_multi_write, NUM_GREGS)) {
         return true;
     }
+
+    if (!bitmap_empty(ctx->sregs_multi_write, NUM_SREGS)) {
+        return true;
+    }
 #endif
 
     return false;
Signature · 1 line
2.43.0
#23 lore raw

Re: [PATCH v2 09/10] Hexagon (target/hexagon) Check for sreg multiwrite in analyze_packet

Quoted 12 lines · Taylor Simpson
---
 target/hexagon/translate.h | 11 +++++++++--
 target/hexagon/translate.c |  4 ++++
 2 files changed, 13 insertions(+), 2 deletions(-)
target/hexagon/translate.h +0 -0
index eb0d10d686..b90f7fff1c 100644

target/hexagon/translate.h typedef struct DisasContext { · line 55

Quoted 5 lines
target/hexagon/translate.h +2 -0
@@ -51,6 +51,8 @@ typedef struct DisasContext {
     DECLARE_BITMAP(gregs_multi_write, NUM_GREGS);
     int sreg_log[SREG_WRITES_MAX];
     int sreg_log_idx;
+    DECLARE_BITMAP(sregs_written, NUM_SREGS);
+    DECLARE_BITMAP(sregs_multi_write, NUM_SREGS);

Do sregs_written and sregs_multi_write need to be cleared in clear_pkt_ctx like the other bitmaps?

#24 lore raw

Re: [PATCH v2 09/10] Hexagon (target/hexagon) Check for sreg multiwrite in analyze_packet

Quoted 9 lines · Marco Liebel
Quoted 7 lines · Taylor Simpson
---
 target/hexagon/translate.h | 11 +++++++++--
 target/hexagon/translate.c |  4 ++++
 2 files changed, 13 insertions(+), 2 deletions(-)
Quoted 14 lines

target/hexagon/translate.h typedef struct DisasContext { · line 55

Quoted 10 lines
target/hexagon/translate.h +2 -0
index eb0d10d686..b90f7fff1c 100644
@@ -51,6 +51,8 @@ typedef struct DisasContext {
     DECLARE_BITMAP(gregs_multi_write, NUM_GREGS);
     int sreg_log[SREG_WRITES_MAX];
     int sreg_log_idx;
+    DECLARE_BITMAP(sregs_written, NUM_SREGS);
+    DECLARE_BITMAP(sregs_multi_write, NUM_SREGS);

Do sregs_written and sregs_multi_write need to be cleared in clear_pkt_ctx like the other bitmaps?

Yes, I caught this when fixing the test-functional failures Brian pointed out.

Taylor

#25 lore raw

PATCH v2 10/10 Hexagon (target/hexagon) Remove old way of detecting register multiwrites

In reply to Taylor Simpson

We 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        |  6 ----
 target/hexagon/gen_trans_funcs.py | 10 ------
 4 files changed, 74 deletions(-)
target/hexagon/insn.h +0 -4
index 835b1c954e..5d59430da9 100644
@@ -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 -6
index c40ca86810..ca23cc6d9e 100644
@@ -1247,12 +1247,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(!ctx->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
index 19c1f9fdea..45da1b7b5d 100755
@@ -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
Reviewed-by on v2 10/10
#26 lore raw

Re: [PATCH v2 10/10] Hexagon (target/hexagon) Remove old way of detecting register multiwrites

Quoted 2 lines · Taylor Simpson

We now detect register multiwrites in packet analyzis instead of packet decoding

typo "analysis"

Quoted 3 lines

---

Quoted 159 lines
  target/hexagon/insn.h             |  4 ---
  target/hexagon/decode.c           | 54 -------------------------------
  target/hexagon/translate.c        |  6 ----
  target/hexagon/gen_trans_funcs.py | 10 ------
  4 files changed, 74 deletions(-)
target/hexagon/insn.h +0 -4
index 835b1c954e..5d59430da9 100644
@@ -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
index b12e91fe6a..89e961331f 100644
@@ -691,55 +691,6 @@ bool opcode_supported(uint16_t opcode, const HexagonCPUDef *hex_def)
      return true;
  }
 
-/*
- * Check for GPR write conflicts in the packet.
- * A conflict exists when a register is written by more than one instruction
- * and at least one of those writes is unconditional.
- *
- * TODO: handle the more general case of any
- * packet w/multiple-register-write operands.
- */
-static bool pkt_has_write_conflict(Packet *pkt)
-{
-    DECLARE_BITMAP(all_dest_gprs, 32) = { 0 };
-    DECLARE_BITMAP(wreg_mult_gprs, 32) = { 0 };
-    DECLARE_BITMAP(uncond_wreg_gprs, 32) = { 0 };
-    DECLARE_BITMAP(conflict, 32);
-
-    for (int i = 0; i < pkt->num_insns; i++) {
-        Insn *insn = &pkt->insn[i];
-        int dest = insn->dest_idx;
-
-        if (dest < 0 || !insn->dest_is_gpr) {
-            continue;
-        }
-
-        int rnum = insn->regno[dest];
-        bool is_uncond = !GET_ATTRIB(insn->opcode, A_CONDEXEC);
-
-        if (test_bit(rnum, all_dest_gprs)) {
-            set_bit(rnum, wreg_mult_gprs);
-        }
-        set_bit(rnum, all_dest_gprs);
-        if (is_uncond) {
-            set_bit(rnum, uncond_wreg_gprs);
-        }
-
-        if (insn->dest_is_pair) {
-            if (test_bit(rnum + 1, all_dest_gprs)) {
-                set_bit(rnum + 1, wreg_mult_gprs);
-            }
-            set_bit(rnum + 1, all_dest_gprs);
-            if (is_uncond) {
-                set_bit(rnum + 1, uncond_wreg_gprs);
-            }
-        }
-    }
-
-    bitmap_and(conflict, wreg_mult_gprs, uncond_wreg_gprs, 32);
-    return !bitmap_empty(conflict, 32);
-}
-
  /*
   * decode_packet
   * Decodes packet with given words
@@ -759,10 +710,6 @@ int decode_packet(DisasContext *ctx, int max_words, const uint32_t *words,
 
      /* Initialize */
      memset(pkt, 0, sizeof(*pkt));
-    for (i = 0; i < INSTRUCTIONS_MAX; i++) {
-        pkt->insn[i].dest_idx = -1;
-        pkt->insn[i].new_read_idx = -1;
-    }
      /* Try to build packet */
      while (!end_of_packet && (words_read < max_words)) {
          Insn *insn = &pkt->insn[num_insns];
@@ -837,7 +784,6 @@ int decode_packet(DisasContext *ctx, int max_words, const uint32_t *words,
              /* Invalid packet */
              return 0;
          }
-        pkt->pkt_has_write_conflict = pkt_has_write_conflict(pkt);
      }
      decode_fill_newvalue_regno(pkt);
 
target/hexagon/translate.c +0 -6
index c40ca86810..ca23cc6d9e 100644
@@ -1247,12 +1247,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(!ctx->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
index 19c1f9fdea..45da1b7b5d 100755
@@ -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"""\
Reviewed-by
#27 lore raw

Re: [PATCH v2 10/10] Hexagon (target/hexagon) Remove old way of detecting register multiwrites

Quoted 11 lines · Taylor Simpson

We 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        |  6 ----
 target/hexagon/gen_trans_funcs.py | 10 ------
 4 files changed, 74 deletions(-)
#28 lore raw
In reply to Taylor Simpson
Quoted 13 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 write per 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.

Changes in v2
- Rebase against latest sources, including Hexagon system mode
- Add checks for multiple writes to system registers

Quoted 13 lines

Taylor Simpson (10):
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) Check for greg multiwrite in analyze_packet Hexagon (target/hexagon) Check for sreg multiwrite in analyze_packet Hexagon (target/hexagon) Remove old way of detecting register
multiwrites

The greg multiwrite change seems to have an issue here. clear_pkt_ctx() needs to clear gregs_multi_write?

You can reproduce the test failures locally with make check-functional.

Quoted 10 lines
  target/hexagon/insn.h               |   4 -
  target/hexagon/translate.h          |  47 ++++++++--
  target/hexagon/decode.c             |  54 ------------
  target/hexagon/translate.c          |  88 ++++++++++++++-----
  tests/tcg/hexagon/multiple-writes.c | 129 ++++++++++++++++++++++++++++
  target/hexagon/gen_trans_funcs.py   |  10 ---
  tests/tcg/hexagon/meson.build       |   2 +-
  7 files changed, 239 insertions(+), 95 deletions(-)
#29 lore raw
Quoted 29 lines · Brian Cain
Quoted 13 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 write per 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.

Changes in v2
- Rebase against latest sources, including Hexagon system mode
- Add checks for multiple writes to system registers

Quoted 13 lines

Taylor Simpson (10):
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) Check for greg multiwrite in analyze_packet Hexagon (target/hexagon) Check for sreg multiwrite in analyze_packet Hexagon (target/hexagon) Remove old way of detecting register
multiwrites

Quoted 5 lines

The greg multiwrite change seems to have an issue here. clear_pkt_ctx() needs to clear gregs_multi_write?

You can reproduce the test failures locally with make check-functional.

Correct. There are problems with both gregs and sregs. I'll make the fixes in V3

Should I add a multi-write test to check-functional? If so, please advise on the easiest way to do this.

Thanks,
Taylor

#30 lore raw
Quoted 45 lines · Taylor Simpson

On Fri, Sep 11, 2026 at 8:34 PM Brian Cain <[email protected]> wrote:

On 9/11/2026 5:08 PM, Taylor Simpson wrote:
> 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 write per 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.
>
> Changes in v2
> - Rebase against latest sources, including Hexagon system mode > - Add checks for multiple writes to system registers
>
> Taylor Simpson (10):
>    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) Check for greg multiwrite in analyze_packet
>    Hexagon (target/hexagon) Check for sreg multiwrite in analyze_packet
>    Hexagon (target/hexagon) Remove old way of detecting register >      multiwrites

The greg multiwrite change seems to have an issue here. clear_pkt_ctx()
needs to clear gregs_multi_write?

Quoted 8 lines

You can reproduce the test failures locally with make check-functional.

Correct.  There are problems with both gregs and sregs. I'll make the fixes in V3

Should I add a multi-write test to check-functional?  If so, please advise on the easiest way to do this.

If you like, that's fine.  Thankfully the existing tests were able to catch it.  IMO tests that are able to build and run with little or no dependence on hw device models are suitable/appropriate for check-tcg tests.  In system mode, we can write baremetal tests that fit this description, and the sreg/guest reg tests seem like they could work well.  But it's a bit inconvenient to write the baremetal tests, so I'll leave it up to you.  If you prefer to have the multiwrite tests come from downloaded-binary cases that run in check-functional, you can contribute a PR to https://github.com/qualcomm/qemu-hexagon-testing/ to add test case(s), we can tag that change once it lands and then we can refer to them in tests/functional/hexagon/ (probably test_systests.py).

But neither of those options needs to gate this commit series.

BTW here is an example sysemu check-tcg test that focuses on translation and manages to avoid a hardware dependency - https://lore.kernel.org/qemu-devel/[email protected]/ -- it's not landed yet, unfortunately.

-Brian