Skip to contentSkip to conversation

Hexagon (target/hexagon) improve store handling

PATCH In review Taylor Simpson 2 participants 8 messages Sep 20, 2022 – Sep 28, 2022

lore
Share & tools
lore
#0 lore raw

cover Hexagon (target/hexagon) improve store handling

Make store handling faster and more robust

Taylor Simpson (3):
Hexagon (target/hexagon) add instruction attributes from archlib Hexagon (target/hexagon) move store size tracking to translation Hexagon (target/hexagon) Change decision to set pkt_has_store_s[01]

 target/hexagon/macros.h               |   8 +-
 target/hexagon/attribs_def.h.inc      |  38 +++++++-
 target/hexagon/decode.c               |  17 ++--
 target/hexagon/genptr.c               |  36 +++-----
 target/hexagon/translate.c            |  36 +++++++-
 target/hexagon/hex_common.py          |   3 +-
 target/hexagon/imported/ldst.idef     | 122 +++++++++++++-------------
 target/hexagon/imported/subinsns.idef |  72 +++++++--------
 8 files changed, 196 insertions(+), 136 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/3 Hexagon (target/hexagon) add instruction attributes from archlib

The imported files from the architecture library have added some instruction attributes. Some of these will be used in a subsequent patch for determing the size of a store.

---
 target/hexagon/attribs_def.h.inc      |  37 +++++++-
 target/hexagon/imported/ldst.idef     | 122 +++++++++++++-------------
 target/hexagon/imported/subinsns.idef |  72 +++++++--------
 3 files changed, 133 insertions(+), 98 deletions(-)
target/hexagon/attribs_def.h.inc +36 -1
index dc890a557f..222ad95fb0 100644
@@ -1,5 +1,5 @@
 /*
- *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *  Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -38,6 +38,16 @@ DEF_ATTRIB(SUBINSN, "sub-instruction", "", "")
 /* Load and Store attributes */
 DEF_ATTRIB(LOAD, "Loads from memory", "", "")
 DEF_ATTRIB(STORE, "Stores to memory", "", "")
+DEF_ATTRIB(STOREIMMED, "Stores immed to memory", "", "")
+DEF_ATTRIB(MEMSIZE_0B, "Memory width is 0 byte", "", "")
+DEF_ATTRIB(MEMSIZE_1B, "Memory width is 1 byte", "", "")
+DEF_ATTRIB(MEMSIZE_2B, "Memory width is 2 bytes", "", "")
+DEF_ATTRIB(MEMSIZE_4B, "Memory width is 4 bytes", "", "")
+DEF_ATTRIB(MEMSIZE_8B, "Memory width is 8 bytes", "", "")
+DEF_ATTRIB(REGWRSIZE_1B, "Memory width is 1 byte", "", "")
+DEF_ATTRIB(REGWRSIZE_2B, "Memory width is 2 bytes", "", "")
+DEF_ATTRIB(REGWRSIZE_4B, "Memory width is 4 bytes", "", "")
+DEF_ATTRIB(REGWRSIZE_8B, "Memory width is 8 bytes", "", "")
 DEF_ATTRIB(MEMLIKE, "Memory-like instruction", "", "")
 DEF_ATTRIB(MEMLIKE_PACKET_RULES, "follows Memory-like packet rules", "", "")
 
@@ -71,6 +81,11 @@ DEF_ATTRIB(COF, "Change-of-flow instruction", "", "")
 DEF_ATTRIB(CONDEXEC, "May be cancelled by a predicate", "", "")
 DEF_ATTRIB(DOTNEWVALUE, "Uses a register value generated in this pkt", "", "")
 DEF_ATTRIB(NEWCMPJUMP, "Compound compare and jump", "", "")
+DEF_ATTRIB(NVSTORE, "New-value store", "", "")
+DEF_ATTRIB(MEMOP, "memop", "", "")
+
+DEF_ATTRIB(ROPS_2, "Compound instruction worth 2 RISC-ops", "", "")
+DEF_ATTRIB(ROPS_3, "Compound instruction worth 3 RISC-ops", "", "")
 
 /* access to implicit registers */
 DEF_ATTRIB(IMPLICIT_WRITES_LR, "Writes the link register", "", "UREG.LR")
@@ -87,6 +102,9 @@ DEF_ATTRIB(IMPLICIT_WRITES_P3, "May write Predicate 3", "", "UREG.P3")
 DEF_ATTRIB(IMPLICIT_READS_PC, "Reads the PC register", "", "")
 DEF_ATTRIB(IMPLICIT_WRITES_USR, "May write USR", "", "")
 DEF_ATTRIB(WRITES_PRED_REG, "Writes a predicate register", "", "")
+DEF_ATTRIB(COMMUTES, "The operation is communitive", "", "")
+DEF_ATTRIB(DEALLOCRET, "dealloc_return", "", "")
+DEF_ATTRIB(DEALLOCFRAME, "deallocframe", "", "")
 
 DEF_ATTRIB(CRSLOT23, "Can execute in slot 2 or slot 3 (CR)", "", "")
 DEF_ATTRIB(IT_NOP, "nop instruction", "", "")
@@ -94,17 +112,21 @@ DEF_ATTRIB(IT_EXTENDER, "constant extender instruction", "", "")
 
 
 /* Restrictions to make note of */
+DEF_ATTRIB(RESTRICT_COF_MAX1, "One change-of-flow per packet", "", "")
+DEF_ATTRIB(RESTRICT_NOPACKET, "Not allowed in a packet", "", "")
 DEF_ATTRIB(RESTRICT_SLOT0ONLY, "Must execute on slot0", "", "")
 DEF_ATTRIB(RESTRICT_SLOT1ONLY, "Must execute on slot1", "", "")
 DEF_ATTRIB(RESTRICT_SLOT2ONLY, "Must execute on slot2", "", "")
 DEF_ATTRIB(RESTRICT_SLOT3ONLY, "Must execute on slot3", "", "")
 DEF_ATTRIB(RESTRICT_NOSLOT1, "No slot 1 instruction in parallel", "", "")
 DEF_ATTRIB(RESTRICT_PREFERSLOT0, "Try to encode into slot 0", "", "")
+DEF_ATTRIB(RESTRICT_PACKET_AXOK, "May exist with A-type or X-type", "", "")
 
 DEF_ATTRIB(ICOP, "Instruction cache op", "", "")
 
 DEF_ATTRIB(HWLOOP0_END, "Ends HW loop0", "", "")
 DEF_ATTRIB(HWLOOP1_END, "Ends HW loop1", "", "")
+DEF_ATTRIB(RET_TYPE, "return type", "", "")
 DEF_ATTRIB(DCZEROA, "dczeroa type", "", "")
 DEF_ATTRIB(ICFLUSHOP, "icflush op type", "", "")
 DEF_ATTRIB(DCFLUSHOP, "dcflush op type", "", "")
@@ -116,5 +138,18 @@ DEF_ATTRIB(L2FETCH, "Instruction is l2fetch type", "", "")
 DEF_ATTRIB(ICINVA, "icinva", "", "")
 DEF_ATTRIB(DCCLEANINVA, "dccleaninva", "", "")
 
+/* Documentation Notes */
+DEF_ATTRIB(NOTE_CONDITIONAL, "can be conditionally executed", "", "")
+DEF_ATTRIB(NOTE_NEWVAL_SLOT0, "New-value oprnd must execute on slot 0", "", "")
+DEF_ATTRIB(NOTE_PRIV, "Monitor-level feature", "", "")
+DEF_ATTRIB(NOTE_NOPACKET, "solo instruction", "", "")
+DEF_ATTRIB(NOTE_AXOK, "May only be grouped with ALU32 or non-FP XTYPE.", "", "")
+DEF_ATTRIB(NOTE_LATEPRED, "The predicate can not be used as a .new", "", "")
+DEF_ATTRIB(NOTE_NVSLOT0, "Can execute only in slot 0 (ST)", "", "")
+
+/* Restrictions to make note of */
+DEF_ATTRIB(RESTRICT_NOSLOT1_STORE, "Packet must not have slot 1 store", "", "")
+DEF_ATTRIB(RESTRICT_LATEPRED, "Predicate can not be used as a .new.", "", "")
+
 /* Keep this as the last attribute: */
 DEF_ATTRIB(ZZ_LASTATTRIB, "Last attribute in the file", "", "")
target/hexagon/imported/ldst.idef +61 -61

207 lines not on this page · raw message

target/hexagon/imported/subinsns.idef +36 -36

138 lines not on this page · raw message

Signature · 1 line
2.17.1
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] Hexagon (target/hexagon) add instruction attributes from archlib

Quoted 10 lines · Taylor Simpson

The imported files from the architecture library have added some instruction attributes. Some of these will be used in a subsequent patch for determing the size of a store.

---
  target/hexagon/attribs_def.h.inc      |  37 +++++++-
  target/hexagon/imported/ldst.idef     | 122 +++++++++++++-------------
  target/hexagon/imported/subinsns.idef |  72 +++++++--------
  3 files changed, 133 insertions(+), 98 deletions(-)

r~

#3 lore raw

PATCH 2/3 Hexagon (target/hexagon) move store size tracking to translation

In reply to Taylor Simpson

The store width is needed for packet commit, so it is stored in ctx->store_width. Currently, it is set when a store has a TCG override instead of a QEMU helper. In the QEMU helper case, the ctx->store_width is not set, we invoke a helper during packet commit that uses the runtime store width.

This patch ensures ctx->store_width is set for all store instructions, so performance is improved because packet commit can generate the proper TCG store rather than the generic helper.

We do this by
- Use the attributes from the instructions during translation to set ctx->store_width
- Remove setting of ctx->store_width from genptr.c

---
 target/hexagon/macros.h    |  8 ++++----
 target/hexagon/genptr.c    | 36 ++++++++++++------------------------
 target/hexagon/translate.c | 26 ++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 28 deletions(-)
target/hexagon/macros.h +4 -4
index 92eb8bbf05..c8805bdaeb 100644
@@ -156,7 +156,7 @@
         __builtin_choose_expr(TYPE_TCGV(X), \
             gen_store1, (void)0))
 #define MEM_STORE1(VA, DATA, SLOT) \
-    MEM_STORE1_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT)
+    MEM_STORE1_FUNC(DATA)(cpu_env, VA, DATA, SLOT)
 
 #define MEM_STORE2_FUNC(X) \
     __builtin_choose_expr(TYPE_INT(X), \
@@ -164,7 +164,7 @@
         __builtin_choose_expr(TYPE_TCGV(X), \
             gen_store2, (void)0))
 #define MEM_STORE2(VA, DATA, SLOT) \
-    MEM_STORE2_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT)
+    MEM_STORE2_FUNC(DATA)(cpu_env, VA, DATA, SLOT)
 
 #define MEM_STORE4_FUNC(X) \
     __builtin_choose_expr(TYPE_INT(X), \
@@ -172,7 +172,7 @@
         __builtin_choose_expr(TYPE_TCGV(X), \
             gen_store4, (void)0))
 #define MEM_STORE4(VA, DATA, SLOT) \
-    MEM_STORE4_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT)
+    MEM_STORE4_FUNC(DATA)(cpu_env, VA, DATA, SLOT)
 
 #define MEM_STORE8_FUNC(X) \
     __builtin_choose_expr(TYPE_INT(X), \
@@ -180,7 +180,7 @@
         __builtin_choose_expr(TYPE_TCGV_I64(X), \
             gen_store8, (void)0))
 #define MEM_STORE8(VA, DATA, SLOT) \
-    MEM_STORE8_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT)
+    MEM_STORE8_FUNC(DATA)(cpu_env, VA, DATA, SLOT)
 #else
 #define MEM_LOAD1s(VA) ((int8_t)mem_load1(env, slot, VA))
 #define MEM_LOAD1u(VA) ((uint8_t)mem_load1(env, slot, VA))
target/hexagon/genptr.c +12 -24
index 8a334ba07b..806d0974ff 100644
@@ -401,62 +401,50 @@ static inline void gen_store32(TCGv vaddr, TCGv src, int width, int slot)
     tcg_gen_mov_tl(hex_store_val32[slot], src);
 }
 
-static inline void gen_store1(TCGv_env cpu_env, TCGv vaddr, TCGv src,
-                              DisasContext *ctx, int slot)
+static inline void gen_store1(TCGv_env cpu_env, TCGv vaddr, TCGv src, int slot)
 {
     gen_store32(vaddr, src, 1, slot);
-    ctx->store_width[slot] = 1;
 }
 
-static inline void gen_store1i(TCGv_env cpu_env, TCGv vaddr, int32_t src,
-                               DisasContext *ctx, int slot)
+static inline void gen_store1i(TCGv_env cpu_env, TCGv vaddr, int32_t src, int slot)
 {
     TCGv tmp = tcg_constant_tl(src);
-    gen_store1(cpu_env, vaddr, tmp, ctx, slot);
+    gen_store1(cpu_env, vaddr, tmp, slot);
 }
 
-static inline void gen_store2(TCGv_env cpu_env, TCGv vaddr, TCGv src,
-                              DisasContext *ctx, int slot)
+static inline void gen_store2(TCGv_env cpu_env, TCGv vaddr, TCGv src, int slot)
 {
     gen_store32(vaddr, src, 2, slot);
-    ctx->store_width[slot] = 2;
 }
 
-static inline void gen_store2i(TCGv_env cpu_env, TCGv vaddr, int32_t src,
-                               DisasContext *ctx, int slot)
+static inline void gen_store2i(TCGv_env cpu_env, TCGv vaddr, int32_t src, int slot)
 {
     TCGv tmp = tcg_constant_tl(src);
-    gen_store2(cpu_env, vaddr, tmp, ctx, slot);
+    gen_store2(cpu_env, vaddr, tmp, slot);
 }
 
-static inline void gen_store4(TCGv_env cpu_env, TCGv vaddr, TCGv src,
-                              DisasContext *ctx, int slot)
+static inline void gen_store4(TCGv_env cpu_env, TCGv vaddr, TCGv src, int slot)
 {
     gen_store32(vaddr, src, 4, slot);
-    ctx->store_width[slot] = 4;
 }
 
-static inline void gen_store4i(TCGv_env cpu_env, TCGv vaddr, int32_t src,
-                               DisasContext *ctx, int slot)
+static inline void gen_store4i(TCGv_env cpu_env, TCGv vaddr, int32_t src, int slot)
 {
     TCGv tmp = tcg_constant_tl(src);
-    gen_store4(cpu_env, vaddr, tmp, ctx, slot);
+    gen_store4(cpu_env, vaddr, tmp, slot);
 }
 
-static inline void gen_store8(TCGv_env cpu_env, TCGv vaddr, TCGv_i64 src,
-                              DisasContext *ctx, int slot)
+static inline void gen_store8(TCGv_env cpu_env, TCGv vaddr, TCGv_i64 src, int slot)
 {
     tcg_gen_mov_tl(hex_store_addr[slot], vaddr);
     tcg_gen_movi_tl(hex_store_width[slot], 8);
     tcg_gen_mov_i64(hex_store_val64[slot], src);
-    ctx->store_width[slot] = 8;
 }
 
-static inline void gen_store8i(TCGv_env cpu_env, TCGv vaddr, int64_t src,
-                               DisasContext *ctx, int slot)
+static inline void gen_store8i(TCGv_env cpu_env, TCGv vaddr, int64_t src, int slot)
 {
     TCGv_i64 tmp = tcg_constant_i64(src);
-    gen_store8(cpu_env, vaddr, tmp, ctx, slot);
+    gen_store8(cpu_env, vaddr, tmp, slot);
 }
 
 static TCGv gen_8bitsof(TCGv result, TCGv value)
target/hexagon/translate.c +26 -0
index 0e8a0772f7..bc02870b9f 100644
@@ -327,6 +327,31 @@ static void mark_implicit_pred_writes(DisasContext *ctx, Insn *insn)
     mark_implicit_pred_write(ctx, insn, A_IMPLICIT_WRITES_P3, 3);
 }
 
+static void mark_store_width(DisasContext *ctx, Insn *insn)
+{
+    uint16_t opcode = insn->opcode;
+    uint32_t slot = insn->slot;
+
+    if (GET_ATTRIB(opcode, A_STORE)) {
+        if (GET_ATTRIB(opcode, A_MEMSIZE_1B)) {
+            ctx->store_width[slot] = 1;
+            return;
+        }
+        if (GET_ATTRIB(opcode, A_MEMSIZE_2B)) {
+            ctx->store_width[slot] = 2;
+            return;
+        }
+        if (GET_ATTRIB(opcode, A_MEMSIZE_4B)) {
+            ctx->store_width[slot] = 4;
+            return;
+        }
+        if (GET_ATTRIB(opcode, A_MEMSIZE_8B)) {
+            ctx->store_width[slot] = 8;
+            return;
+        }
+    }
+}
+
 static void gen_insn(CPUHexagonState *env, DisasContext *ctx,
                      Insn *insn, Packet *pkt)
 {
@@ -334,6 +359,7 @@ static void gen_insn(CPUHexagonState *env, DisasContext *ctx,
         mark_implicit_reg_writes(ctx, insn);
         insn->generate(env, ctx, insn, pkt);
         mark_implicit_pred_writes(ctx, insn);
+        mark_store_width(ctx, insn);
     } else {
         gen_exception_end_tb(ctx, HEX_EXCP_INVALID_OPCODE);
     }
Signature · 1 line
2.17.1
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] Hexagon (target/hexagon) move store size tracking to translation

Quoted 161 lines · Taylor Simpson

The store width is needed for packet commit, so it is stored in ctx->store_width. Currently, it is set when a store has a TCG override instead of a QEMU helper. In the QEMU helper case, the ctx->store_width is not set, we invoke a helper during packet commit that uses the runtime store width.

This patch ensures ctx->store_width is set for all store instructions, so performance is improved because packet commit can generate the proper TCG store rather than the generic helper.

We do this by
- Use the attributes from the instructions during translation to set ctx->store_width
- Remove setting of ctx->store_width from genptr.c

---
  target/hexagon/macros.h    |  8 ++++----
  target/hexagon/genptr.c    | 36 ++++++++++++------------------------
  target/hexagon/translate.c | 26 ++++++++++++++++++++++++++
  3 files changed, 42 insertions(+), 28 deletions(-)
target/hexagon/macros.h +4 -4
index 92eb8bbf05..c8805bdaeb 100644
@@ -156,7 +156,7 @@
          __builtin_choose_expr(TYPE_TCGV(X), \
              gen_store1, (void)0))
  #define MEM_STORE1(VA, DATA, SLOT) \
-    MEM_STORE1_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT)
+    MEM_STORE1_FUNC(DATA)(cpu_env, VA, DATA, SLOT)
 
  #define MEM_STORE2_FUNC(X) \
      __builtin_choose_expr(TYPE_INT(X), \
@@ -164,7 +164,7 @@
          __builtin_choose_expr(TYPE_TCGV(X), \
              gen_store2, (void)0))
  #define MEM_STORE2(VA, DATA, SLOT) \
-    MEM_STORE2_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT)
+    MEM_STORE2_FUNC(DATA)(cpu_env, VA, DATA, SLOT)
 
  #define MEM_STORE4_FUNC(X) \
      __builtin_choose_expr(TYPE_INT(X), \
@@ -172,7 +172,7 @@
          __builtin_choose_expr(TYPE_TCGV(X), \
              gen_store4, (void)0))
  #define MEM_STORE4(VA, DATA, SLOT) \
-    MEM_STORE4_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT)
+    MEM_STORE4_FUNC(DATA)(cpu_env, VA, DATA, SLOT)
 
  #define MEM_STORE8_FUNC(X) \
      __builtin_choose_expr(TYPE_INT(X), \
@@ -180,7 +180,7 @@
          __builtin_choose_expr(TYPE_TCGV_I64(X), \
              gen_store8, (void)0))
  #define MEM_STORE8(VA, DATA, SLOT) \
-    MEM_STORE8_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT)
+    MEM_STORE8_FUNC(DATA)(cpu_env, VA, DATA, SLOT)
  #else
  #define MEM_LOAD1s(VA) ((int8_t)mem_load1(env, slot, VA))
  #define MEM_LOAD1u(VA) ((uint8_t)mem_load1(env, slot, VA))
target/hexagon/genptr.c +12 -24
index 8a334ba07b..806d0974ff 100644
@@ -401,62 +401,50 @@ static inline void gen_store32(TCGv vaddr, TCGv src, int width, int slot)
      tcg_gen_mov_tl(hex_store_val32[slot], src);
  }
 
-static inline void gen_store1(TCGv_env cpu_env, TCGv vaddr, TCGv src,
-                              DisasContext *ctx, int slot)
+static inline void gen_store1(TCGv_env cpu_env, TCGv vaddr, TCGv src, int slot)
  {
      gen_store32(vaddr, src, 1, slot);
-    ctx->store_width[slot] = 1;
  }
 
-static inline void gen_store1i(TCGv_env cpu_env, TCGv vaddr, int32_t src,
-                               DisasContext *ctx, int slot)
+static inline void gen_store1i(TCGv_env cpu_env, TCGv vaddr, int32_t src, int slot)
  {
      TCGv tmp = tcg_constant_tl(src);
-    gen_store1(cpu_env, vaddr, tmp, ctx, slot);
+    gen_store1(cpu_env, vaddr, tmp, slot);
  }
 
-static inline void gen_store2(TCGv_env cpu_env, TCGv vaddr, TCGv src,
-                              DisasContext *ctx, int slot)
+static inline void gen_store2(TCGv_env cpu_env, TCGv vaddr, TCGv src, int slot)
  {
      gen_store32(vaddr, src, 2, slot);
-    ctx->store_width[slot] = 2;
  }
 
-static inline void gen_store2i(TCGv_env cpu_env, TCGv vaddr, int32_t src,
-                               DisasContext *ctx, int slot)
+static inline void gen_store2i(TCGv_env cpu_env, TCGv vaddr, int32_t src, int slot)
  {
      TCGv tmp = tcg_constant_tl(src);
-    gen_store2(cpu_env, vaddr, tmp, ctx, slot);
+    gen_store2(cpu_env, vaddr, tmp, slot);
  }
 
-static inline void gen_store4(TCGv_env cpu_env, TCGv vaddr, TCGv src,
-                              DisasContext *ctx, int slot)
+static inline void gen_store4(TCGv_env cpu_env, TCGv vaddr, TCGv src, int slot)
  {
      gen_store32(vaddr, src, 4, slot);
-    ctx->store_width[slot] = 4;
  }
 
-static inline void gen_store4i(TCGv_env cpu_env, TCGv vaddr, int32_t src,
-                               DisasContext *ctx, int slot)
+static inline void gen_store4i(TCGv_env cpu_env, TCGv vaddr, int32_t src, int slot)
  {
      TCGv tmp = tcg_constant_tl(src);
-    gen_store4(cpu_env, vaddr, tmp, ctx, slot);
+    gen_store4(cpu_env, vaddr, tmp, slot);
  }
 
-static inline void gen_store8(TCGv_env cpu_env, TCGv vaddr, TCGv_i64 src,
-                              DisasContext *ctx, int slot)
+static inline void gen_store8(TCGv_env cpu_env, TCGv vaddr, TCGv_i64 src, int slot)
  {
      tcg_gen_mov_tl(hex_store_addr[slot], vaddr);
      tcg_gen_movi_tl(hex_store_width[slot], 8);
      tcg_gen_mov_i64(hex_store_val64[slot], src);
-    ctx->store_width[slot] = 8;
  }
 
-static inline void gen_store8i(TCGv_env cpu_env, TCGv vaddr, int64_t src,
-                               DisasContext *ctx, int slot)
+static inline void gen_store8i(TCGv_env cpu_env, TCGv vaddr, int64_t src, int slot)
  {
      TCGv_i64 tmp = tcg_constant_i64(src);
-    gen_store8(cpu_env, vaddr, tmp, ctx, slot);
+    gen_store8(cpu_env, vaddr, tmp, slot);
  }
 
  static TCGv gen_8bitsof(TCGv result, TCGv value)
target/hexagon/translate.c +12 -0
index 0e8a0772f7..bc02870b9f 100644
@@ -327,6 +327,31 @@ static void mark_implicit_pred_writes(DisasContext *ctx, Insn *insn)
      mark_implicit_pred_write(ctx, insn, A_IMPLICIT_WRITES_P3, 3);
  }
 
+static void mark_store_width(DisasContext *ctx, Insn *insn)
+{
+    uint16_t opcode = insn->opcode;
+    uint32_t slot = insn->slot;
+
+    if (GET_ATTRIB(opcode, A_STORE)) {
+        if (GET_ATTRIB(opcode, A_MEMSIZE_1B)) {
+            ctx->store_width[slot] = 1;
+            return;
+        }
+        if (GET_ATTRIB(opcode, A_MEMSIZE_2B)) {
+            ctx->store_width[slot] = 2;

target/hexagon/translate.c static void mark_implicit_pred_writes(DisasContext *ctx, Insn *insn) · line 351

Quoted 10 lines
target/hexagon/translate.c +10 -0
+            return;
+        }
+        if (GET_ATTRIB(opcode, A_MEMSIZE_4B)) {
+            ctx->store_width[slot] = 4;
+            return;
+        }
+        if (GET_ATTRIB(opcode, A_MEMSIZE_8B)) {
+            ctx->store_width[slot] = 8;
+            return;
+        }

Hmm. Perhaps

    int size = 0;
    if (GET_ATTRIB(opcode, A_MEMSIZE_1B)) {
        size |= 1;
    }
    ...
    tcg_debug_assert(is_power_of_2(size));
    ctx->store_width[slot] = size;

just to make sure you get exactly one of the above cases.

Otherwise, LGTM,

r~

#5 lore raw

PATCH 3/3 Hexagon (target/hexagon) Change decision to set pkt_has_store_s[01]

In reply to Taylor Simpson

We have found cases where pkt_has_store_s[01] is set incorrectly. This leads to generating an unnecessary store that is left over from a previous packet.

Add an attribute to determine if an instruction is a scalar store The attribute is attached to the fSTORE macro (hex_common.py) Simplify the logic in decode.c that sets pkt_has_store_s[01]

---
 target/hexagon/attribs_def.h.inc |  1 +
 target/hexagon/decode.c          | 17 ++++++++++++-----
 target/hexagon/translate.c       | 10 ++++++----
 target/hexagon/hex_common.py     |  3 ++-
 4 files changed, 21 insertions(+), 10 deletions(-)
target/hexagon/attribs_def.h.inc +1 -0
index 222ad95fb0..5d2a102c18 100644
@@ -44,6 +44,7 @@ DEF_ATTRIB(MEMSIZE_1B, "Memory width is 1 byte", "", "")
 DEF_ATTRIB(MEMSIZE_2B, "Memory width is 2 bytes", "", "")
 DEF_ATTRIB(MEMSIZE_4B, "Memory width is 4 bytes", "", "")
 DEF_ATTRIB(MEMSIZE_8B, "Memory width is 8 bytes", "", "")
+DEF_ATTRIB(SCALAR_STORE, "Store is scalar", "", "")
 DEF_ATTRIB(REGWRSIZE_1B, "Memory width is 1 byte", "", "")
 DEF_ATTRIB(REGWRSIZE_2B, "Memory width is 2 bytes", "", "")
 DEF_ATTRIB(REGWRSIZE_4B, "Memory width is 4 bytes", "", "")
target/hexagon/decode.c +12 -5
index 6f0f27b4ba..2ba94a77de 100644
@@ -1,5 +1,5 @@
 /*
- *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *  Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -402,10 +402,17 @@ static void decode_set_insn_attr_fields(Packet *pkt)
         }
 
         if (GET_ATTRIB(opcode, A_STORE)) {
-            if (pkt->insn[i].slot == 0) {
-                pkt->pkt_has_store_s0 = true;
-            } else {
-                pkt->pkt_has_store_s1 = true;
+            if (GET_ATTRIB(opcode, A_SCALAR_STORE) &&
+                !GET_ATTRIB(opcode, A_MEMSIZE_0B)) {
+                g_assert(GET_ATTRIB(opcode, A_MEMSIZE_1B) ||
+                         GET_ATTRIB(opcode, A_MEMSIZE_2B) ||
+                         GET_ATTRIB(opcode, A_MEMSIZE_4B) ||
+                         GET_ATTRIB(opcode, A_MEMSIZE_8B));
+                if (pkt->insn[i].slot == 0) {
+                    pkt->pkt_has_store_s0 = true;
+                } else {
+                    pkt->pkt_has_store_s1 = true;
+                }
             }
         }
 
target/hexagon/translate.c +6 -4
index bc02870b9f..efe7d2264e 100644
@@ -1,5 +1,5 @@
 /*
- *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *  Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -525,10 +525,12 @@ static void process_store_log(DisasContext *ctx, Packet *pkt)
      *  slot 1 and then slot 0.  This will be important when
      *  the memory accesses overlap.
      */
-    if (pkt->pkt_has_store_s1 && !pkt->pkt_has_dczeroa) {
+    if (pkt->pkt_has_store_s1) {
+        g_assert(!pkt->pkt_has_dczeroa);
         process_store(ctx, pkt, 1);
     }
-    if (pkt->pkt_has_store_s0 && !pkt->pkt_has_dczeroa) {
+    if (pkt->pkt_has_store_s0) {
+        g_assert(!pkt->pkt_has_dczeroa);
         process_store(ctx, pkt, 0);
     }
 }
@@ -691,7 +693,7 @@ static void gen_commit_packet(CPUHexagonState *env, DisasContext *ctx,
          * The dczeroa will be the store in slot 0, check that we don't have
          * a store in slot 1 or an HVX store.
          */
-        g_assert(has_store_s0 && !has_store_s1 && !has_hvx_store);
+        g_assert(!has_store_s1 && !has_hvx_store);
         process_dczeroa(ctx, pkt);
     } else if (has_hvx_store) {
         TCGv mem_idx = tcg_constant_tl(ctx->mem_idx);
target/hexagon/hex_common.py +2 -1
index c81aca8d2a..d9ba7df786 100755
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 
 ##
-##  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
+##  Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
 ##
 ##  This program is free software; you can redistribute it and/or modify
 ##  it under the terms of the GNU General Public License as published by
@@ -75,6 +75,7 @@ def calculate_attribs():
     add_qemu_macro_attrib('fWRITE_P3', 'A_WRITES_PRED_REG')
     add_qemu_macro_attrib('fSET_OVERFLOW', 'A_IMPLICIT_WRITES_USR')
     add_qemu_macro_attrib('fSET_LPCFG', 'A_IMPLICIT_WRITES_USR')
+    add_qemu_macro_attrib('fSTORE', 'A_SCALAR_STORE')
 
     # Recurse down macros, find attributes from sub-macros
     macroValues = list(macros.values())
Signature · 1 line
2.17.1
Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] Hexagon (target/hexagon) Change decision to set pkt_has_store_s[01]

Quoted 43 lines · Taylor Simpson

We have found cases where pkt_has_store_s[01] is set incorrectly. This leads to generating an unnecessary store that is left over from a previous packet.

Add an attribute to determine if an instruction is a scalar store The attribute is attached to the fSTORE macro (hex_common.py) Simplify the logic in decode.c that sets pkt_has_store_s[01]

---
  target/hexagon/attribs_def.h.inc |  1 +
  target/hexagon/decode.c          | 17 ++++++++++++-----
  target/hexagon/translate.c       | 10 ++++++----
  target/hexagon/hex_common.py     |  3 ++-
  4 files changed, 21 insertions(+), 10 deletions(-)
target/hexagon/attribs_def.h.inc +1 -0
index 222ad95fb0..5d2a102c18 100644
@@ -44,6 +44,7 @@ DEF_ATTRIB(MEMSIZE_1B, "Memory width is 1 byte", "", "")
  DEF_ATTRIB(MEMSIZE_2B, "Memory width is 2 bytes", "", "")
  DEF_ATTRIB(MEMSIZE_4B, "Memory width is 4 bytes", "", "")
  DEF_ATTRIB(MEMSIZE_8B, "Memory width is 8 bytes", "", "")
+DEF_ATTRIB(SCALAR_STORE, "Store is scalar", "", "")
  DEF_ATTRIB(REGWRSIZE_1B, "Memory width is 1 byte", "", "")
  DEF_ATTRIB(REGWRSIZE_2B, "Memory width is 2 bytes", "", "")
  DEF_ATTRIB(REGWRSIZE_4B, "Memory width is 4 bytes", "", "")
target/hexagon/decode.c +1 -1
index 6f0f27b4ba..2ba94a77de 100644
@@ -1,5 +1,5 @@
  /*
- *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *  Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
   *
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
@@ -402,10 +402,17 @@ static void decode_set_insn_attr_fields(Packet *pkt)
          }
 
          if (GET_ATTRIB(opcode, A_STORE)) {

target/hexagon/decode.c static void decode_set_insn_attr_fields(Packet *pkt) · line 410

Quoted 10 lines
target/hexagon/decode.c +6 -4
-            if (pkt->insn[i].slot == 0) {
-                pkt->pkt_has_store_s0 = true;
-            } else {
-                pkt->pkt_has_store_s1 = true;
+            if (GET_ATTRIB(opcode, A_SCALAR_STORE) &&
+                !GET_ATTRIB(opcode, A_MEMSIZE_0B)) {
+                g_assert(GET_ATTRIB(opcode, A_MEMSIZE_1B) ||
+                         GET_ATTRIB(opcode, A_MEMSIZE_2B) ||
+                         GET_ATTRIB(opcode, A_MEMSIZE_4B) ||
+                         GET_ATTRIB(opcode, A_MEMSIZE_8B));

Would this assert be redundant with the one I suggested vs patch 2?

Otherwise,

r~

Quoted 64 lines
target/hexagon/decode.c +5 -0
+                if (pkt->insn[i].slot == 0) {
+                    pkt->pkt_has_store_s0 = true;
+                } else {
+                    pkt->pkt_has_store_s1 = true;
+                }
              }
          }
 
target/hexagon/translate.c +6 -4
index bc02870b9f..efe7d2264e 100644
@@ -1,5 +1,5 @@
  /*
- *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *  Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
   *
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
@@ -525,10 +525,12 @@ static void process_store_log(DisasContext *ctx, Packet *pkt)
       *  slot 1 and then slot 0.  This will be important when
       *  the memory accesses overlap.
       */
-    if (pkt->pkt_has_store_s1 && !pkt->pkt_has_dczeroa) {
+    if (pkt->pkt_has_store_s1) {
+        g_assert(!pkt->pkt_has_dczeroa);
          process_store(ctx, pkt, 1);
      }
-    if (pkt->pkt_has_store_s0 && !pkt->pkt_has_dczeroa) {
+    if (pkt->pkt_has_store_s0) {
+        g_assert(!pkt->pkt_has_dczeroa);
          process_store(ctx, pkt, 0);
      }
  }
@@ -691,7 +693,7 @@ static void gen_commit_packet(CPUHexagonState *env, DisasContext *ctx,
           * The dczeroa will be the store in slot 0, check that we don't have
           * a store in slot 1 or an HVX store.
           */
-        g_assert(has_store_s0 && !has_store_s1 && !has_hvx_store);
+        g_assert(!has_store_s1 && !has_hvx_store);
          process_dczeroa(ctx, pkt);
      } else if (has_hvx_store) {
          TCGv mem_idx = tcg_constant_tl(ctx->mem_idx);
target/hexagon/hex_common.py +2 -1
index c81aca8d2a..d9ba7df786 100755
@@ -1,7 +1,7 @@
  #!/usr/bin/env python3
 
  ##
-##  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
+##  Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
  ##
  ##  This program is free software; you can redistribute it and/or modify
  ##  it under the terms of the GNU General Public License as published by
@@ -75,6 +75,7 @@ def calculate_attribs():
      add_qemu_macro_attrib('fWRITE_P3', 'A_WRITES_PRED_REG')
      add_qemu_macro_attrib('fSET_OVERFLOW', 'A_IMPLICIT_WRITES_USR')
      add_qemu_macro_attrib('fSET_LPCFG', 'A_IMPLICIT_WRITES_USR')
+    add_qemu_macro_attrib('fSTORE', 'A_SCALAR_STORE')
 
      # Recurse down macros, find attributes from sub-macros
      macroValues = list(macros.values())
#7 lore raw

RE: [PATCH 3/3] Hexagon (target/hexagon) Change decision to set pkt_has_store_s[01]

Quoted 49 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, September 28, 2022 11:12 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>; Michael Lambert <[email protected]>
Subject: Re: [PATCH 3/3] Hexagon (target/hexagon) Change decision to set pkt_has_store_s[01]

Quoted 24 lines · Taylor Simpson

We have found cases where pkt_has_store_s[01] is set incorrectly. This leads to generating an unnecessary store that is left over from a previous packet.

Add an attribute to determine if an instruction is a scalar store The attribute is attached to the fSTORE macro (hex_common.py) Simplify the logic in decode.c that sets pkt_has_store_s[01]

---
  target/hexagon/attribs_def.h.inc |  1 +
  target/hexagon/decode.c          | 17 ++++++++++++-----
  target/hexagon/translate.c       | 10 ++++++----
  target/hexagon/hex_common.py     |  3 ++-
  4 files changed, 21 insertions(+), 10 deletions(-)

--git a/target/hexagon/decode.c b/target/hexagon/decode.c index 6f0f27b4ba..2ba94a77de 100644

target/hexagon/decode.c +0 -0
@@ -1,5 +1,5 @@
          }
 
          if (GET_ATTRIB(opcode, A_STORE)) {

target/hexagon/decode.c static void decode_set_insn_attr_fields(Packet *pkt) · line 410

Quoted 10 lines
target/hexagon/decode.c +6 -4
-            if (pkt->insn[i].slot == 0) {
-                pkt->pkt_has_store_s0 = true;
-            } else {
-                pkt->pkt_has_store_s1 = true;
+            if (GET_ATTRIB(opcode, A_SCALAR_STORE) &&
+                !GET_ATTRIB(opcode, A_MEMSIZE_0B)) {
+                g_assert(GET_ATTRIB(opcode, A_MEMSIZE_1B) ||
+                         GET_ATTRIB(opcode, A_MEMSIZE_2B) ||
+                         GET_ATTRIB(opcode, A_MEMSIZE_4B) ||
+                         GET_ATTRIB(opcode, A_MEMSIZE_8B));

Would this assert be redundant with the one I suggested vs patch 2?

Quoted 2 lines

Otherwise,

Yes, this would be redundant with the one you suggested. Further, the one you suggested is an improvement because it ensures that exactly one of the attributes is set.

Will make the changes and create a PR.

Thanks,
Taylor