Skip to contentSkip to conversation

target/hexagon: Misc HLX fixes

PATCH In review Anton Johansson via qemu development 3 participants 9 messages Nov 12 – Nov 17

lore
Share & tools
lore
#0 lore raw

v3 cover target/hexagon: Misc HLX fixes

Hi,

I was too slow on the review before the series got PRd, so I'll submit these preliminary fixes instead. Not included here is a fix for --disable-hexagon-idef-parser being broken with the new stub HMX helpers.

Changes in v2:
- Squashed tests into their respective fix patches (Marco)
- Added missing file (Marco)

Changes in v3:
- named-parameter substitution for inline assembly tests (Brian)
- Add Instruction::has_pair_dest to find all possible pair producers (Brian, Marco)
- Move new-regno patching to the non-HLX path of decode_fill_newvalue_regno() to avoid incorrectly overwriting consumer registers (Marco)

Anton Johansson (4):
target/hexagon: HLX, preserve scalar :mem_noshuf ordering target/hexagon: HLX, search for .new values in pair high register target/hexagon: Forward return address to HLX load/store helpers linux-user/hexagon: Reset hlx_ctx pointer on cpu clone

 linux-user/hexagon/target_cpu.h     |  1 +
 target/hexagon/hlx_helper.h         | 19 ++++++++++++++++
 target/hexagon/insn.h               |  1 +
 target/hexagon/macros.h             | 13 +++++++----
 target/hexagon/decode.c             | 29 +++++++++++++++++++-----
 target/hexagon/hlx_helper.c         | 31 +++++++++++++++++--------
 target/hexagon/translate.c          |  7 +++---
 tests/tcg/hexagon/hlx_assign_conv.c | 35 +++++++++++++++++++++++++++++
 tests/tcg/hexagon/hlx_mem.c         | 22 ++++++++++++++++++
 target/hexagon/gen_trans_funcs.py   |  5 +++++
 target/hexagon/hex_common.py        |  2 ++
 11 files changed, 143 insertions(+), 22 deletions(-)
 create mode 100644 target/hexagon/hlx_helper.h
Signature · 1 line
2.52.0
#1 lore raw

PATCH v3 1/4 target/hexagon: HLX, preserve scalar :mem_noshuf ordering

A packet containing HLX instructions currently defers all stores to the end of the packet, this breaks scalar :mem_noshuf ordering. Only reorder HLX stores.

Fixes a6fae6da070d66b9 ("target/hexagon: translate packets with HLX instructions")
---
 target/hexagon/translate.c  |  7 ++++---
 tests/tcg/hexagon/hlx_mem.c | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)
target/hexagon/translate.c +4 -3
index 8ab28d40d3..f9d4c3fb66 100644
@@ -1525,8 +1525,10 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)
             for (int pass = 0; pass < 3; pass++) {
                 for (i = 0; i < ctx->pkt.num_insns; i++) {
                     Insn *insn = &ctx->pkt.insn[i];
+                    bool hlx = GET_ATTRIB(insn->opcode, A_HLX);
                     bool tmp = GET_ATTRIB(insn->opcode, A_HLX_TMP);
-                    bool store = !tmp && GET_ATTRIB(insn->opcode, A_STORE);
+                    bool store = !tmp && hlx &&
+                                 GET_ATTRIB(insn->opcode, A_STORE);
                     if (pass != (tmp ? 0 : store ? 2 : 1)) {
                         continue;
                     }
@@ -1534,8 +1536,7 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)
                     if (insn->hlx_new_zero) {
                         gen_hlx_new_zero(insn);
                     }
-                    if (GET_ATTRIB(insn->opcode, A_HLX) &&
-                        trace_event_get_state_backends(
+                    if (hlx && trace_event_get_state_backends(
                             TRACE_HEXAGON_HLX_OP)) {
                         gen_helper_hlx_trace_op(tcg_env,
                             tcg_constant_i32(insn->opcode));
tests/tcg/hexagon/hlx_mem.c +22 -0
index 643b499fd9..c0844646a0 100644
@@ -229,6 +229,25 @@ static void test_store_fault(void)
     check_h("LX_S16b_new (fault)", buf_out, expected, HLX_HALF_ELEMS);
 }
 
+static void test_preserve_scalar_noshuf(void)
+{
+    uint32_t ret = 0;
+    uint32_t ptr = 0;
+    uint32_t val = 0x1234;
+    asm volatile("{\n"
+                 ".word 0xe5007822\n"
+                 "    memw(%[ptr]) = %[val]\n"
+                 "    %[ret] = memw(%[ptr])\n"
+                 "}:mem_noshuf\n"
+                 : [ret] "=r"(ret)
+                 : [ptr] "r"(&ptr), [val] "r"(val)
+                 : "memory");
+    if (ret != val) {
+        printf("FAIL broken scalar :mem_noshuf ordering\n");
+        err++;
+    }
+}
+
 int main(void)
 {
     init_vtcm();
@@ -253,6 +272,9 @@ int main(void)
     /* Store in a faulting packet */
     test_store_fault();
 
+    /* Make sure HLX packets preserve scalar :mem_noshuf ordering */
+    test_preserve_scalar_noshuf();
+
     puts(err ? "FAIL" : "PASS");
     return err;
 }
Signature · 1 line
2.52.0
#2 lore raw

PATCH v3 2/4 target/hexagon: HLX, search for .new values in pair high register

In reply to Anton Johansson via qemu development

Otherwise, the following packet

  {
      L7:6 = combine(L0, L2)
      mem(R7) = L7.new
  }

results in mem(R7) being zero-initialized, compared to L6.new which would correctly write the lower bytes of the pair.

Compared to scalar and HVX .new instructions, HLX encodes the register number rather than an offset to the producing instruction + an odd/even bit. In order to find possible producers which write to register pairs without the odd/even bit, a Instruction::has_pair_dest field is added for scalar, HVX, and HLX registers.

Lastly, we move the new-regno patching in decode_fill_newvalue_regno() to the non-HLX scalar path to avoid overwriting the consumer L7 with the base register L6 of the producer destination L7:6. This is safe as the patching is only required for replacing the scalar offset+odd/even bit with the actual producer.

Fixes ef81d1b047337e81 ("target/hexagon: decode HLX packets and add load and store")
---
 target/hexagon/insn.h               |  1 +
 target/hexagon/decode.c             | 29 +++++++++++++++++++-----
 tests/tcg/hexagon/hlx_assign_conv.c | 35 +++++++++++++++++++++++++++++
 target/hexagon/gen_trans_funcs.py   |  5 +++++
 target/hexagon/hex_common.py        |  2 ++
 5 files changed, 66 insertions(+), 6 deletions(-)
target/hexagon/insn.h +1 -0
index 0dd36d2931..37a3111374 100644
@@ -42,6 +42,7 @@ struct Instruction {
     int32_t new_read_idx;
     int32_t dest_idx;
     bool has_pred_dest;
+    bool has_pair_dest;
 
     bool part1;              /*
                               * cmp-jumps are split into two insns.
target/hexagon/decode.c +23 -6
index d48630da87..08fa9aee2a 100644
@@ -110,9 +110,25 @@ static int hlx_find_new_value_producer(Packet *packet, int consumer,
 {
     for (int i = 0; i < packet->num_insns; i++) {
         Insn *insn = &packet->insn[i];
+        uint8_t regno;
 
-        if (i != consumer && GET_ATTRIB(insn->opcode, A_HLX) &&
-            insn->dest_idx != -1 && insn->regno[insn->dest_idx] == lreg) {
+        /*
+         * Skip ourselves, instructions without return values, and
+         * any non-HLX instructions.
+         */
+        if (i == consumer || !GET_ATTRIB(insn->opcode, A_HLX) ||
+            insn->dest_idx == -1) {
+            continue;
+        }
+
+        regno = insn->regno[insn->dest_idx];
+
+        /*
+         * Compare against the base register number, and against the top
+         * register for instructions returning pairs.
+         */
+        if (regno == lreg ||
+            (insn->has_pair_dest && regno + 1 == lreg)) {
             return i;
         }
     }
@@ -172,12 +188,13 @@ decode_fill_newvalue_regno(Packet *packet)
                 if (def_idx < 0 || packet->insn[def_idx].dest_idx == -1) {
                     return false;
                 }
+
+                /* Now patch up the consumer with the register number */
+                dst_idx = packet->insn[def_idx].dest_idx;
+                packet->insn[i].regno[use_regidx] =
+                    packet->insn[def_idx].regno[dst_idx];
             }
 
-            /* Now patch up the consumer with the register number */
-            dst_idx = packet->insn[def_idx].dest_idx;
-            packet->insn[i].regno[use_regidx] =
-                packet->insn[def_idx].regno[dst_idx];
             /*
              * We need to remember who produces this value to later
              * check if it was dynamically cancelled
tests/tcg/hexagon/hlx_assign_conv.c +35 -0
index 8192882b8e..bca902a6e5 100644
@@ -120,6 +120,40 @@ static void test_assign_rw(void)
     check_wp("LX_assign_rw", pw_out_lo, pw_out_hi, expected_w, HLX_HALF_ELEMS);
 }
 
+static void test_combine_assign_hi(void)
+{
+    /*
+     * Tests that a combine operation acts as a producer of a .new value for
+     * the high vector in a pair.
+     */
+    HLX_Vector l_lo;
+    HLX_Vector l_hi;
+
+    fill_w(pw_a_lo, pw_a_hi, VAL_W);
+
+    l_lo = Q6_L_tmp_mem_A(pw_a_lo);
+    l_hi = Q6_L_tmp_mem_A(pw_a_hi);
+
+    hlx_put_v(0, l_lo);
+    hlx_put_v(2, l_hi);
+    /*
+     * {
+     *     L7:6 = combine(L0, L2)
+     *     mem(R7) = L7.new
+     * }
+     */
+    asm volatile(HLX_PTRS HLX_LD0 HLX_LD2
+                 ".word 0xef24602d\n"
+                 ".word 0xa487c007\n"
+                 : : [stage] "r"(hlx_stage) : HLX_CLOBBERS);
+    Q6_mem_Ku16_new_AL(buf_a, hlx_get_v(7));
+
+    for (int j = 0; j < HLX_HALF_ELEMS; j++) {
+        expected[j] = VAL_B;
+    }
+    check_h("LX_assign_w (hi only)", buf_a, expected, HLX_HALF_ELEMS);
+}
+
 
 static void test_combine_w(void)
 {
@@ -336,6 +370,7 @@ int main(void)
     test_assign_s();
     test_assign_u();
     test_assign_rw();
+    test_combine_assign_hi();
 
     /* Combine and mux */
     test_combine_w();
target/hexagon/gen_trans_funcs.py +5 -0
index 93125bdfe4..7e65438565 100755
@@ -74,6 +74,7 @@ def mark_which_imm_extended(f, tag):
 ##         insn->new_read_idx = -1;
 ##         insn->dest_idx = 0;
 ##         insn->has_pred_dest = false;
+##         insn->has_pair_dest = false;
 ##         return true;
 ##     }
 ##
@@ -94,6 +95,7 @@ def gen_trans_funcs(f):
         dest_idx = -1
         dest_idx_reg_id = None
         has_pred_dest = "false"
+        has_pair_dest = "false"
         for regno, (reg_type, reg_id, *_) in enumerate(regs):
             reg = hex_common.get_register(tag, reg_type, reg_id)
             f.write(code_fmt(f"""\
@@ -108,6 +110,8 @@ def gen_trans_funcs(f):
                     dest_idx_reg_id = reg_id
             if reg_type == "P" and reg.is_written() and not reg.is_read():
                 has_pred_dest = "true"
+            if reg.is_written() and reg.is_pair():
+                has_pair_dest = "true"
 
         if len(imms) != 0:
             mark_which_imm_extended(f, tag)
@@ -132,6 +136,7 @@ def gen_trans_funcs(f):
             insn->new_read_idx = {new_read_idx};
             insn->dest_idx = {dest_idx};
             insn->has_pred_dest = {has_pred_dest};
+            insn->has_pair_dest = {has_pair_dest};
         """))
         f.write(textwrap.dedent(f"""\
                 return true;
target/hexagon/hex_common.py +2 -0
index f85f063f52..8d68d8dad9 100755
@@ -805,6 +805,8 @@ def is_hvx_reg(self):
         return True
     def is_hlx_reg(self):
         return False
+    def is_pair(self):
+        return len(self.regid) == 2
     def hvx_off(self):
         return f"{self.reg_tcg()}_off"
     def hvx_base(self):
Signature · 1 line
2.52.0
Reviewed-by on v3 2/4
#3 lore raw

Re: [PATCH v3 2/4] target/hexagon: HLX, search for .new values in pair high register

Quoted 25 lines · Anton Johansson

Otherwise, the following packet

  {
      L7:6 = combine(L0, L2)
      mem(R7) = L7.new
  }

results in mem(R7) being zero-initialized, compared to L6.new which would correctly write the lower bytes of the pair.

Compared to scalar and HVX .new instructions, HLX encodes the register number rather than an offset to the producing instruction + an odd/even bit. In order to find possible producers which write to register pairs without the odd/even bit, a Instruction::has_pair_dest field is added for scalar, HVX, and HLX registers.

Lastly, we move the new-regno patching in decode_fill_newvalue_regno() to the non-HLX scalar path to avoid overwriting the consumer L7 with the base register L6 of the producer destination L7:6. This is safe as the patching is only required for replacing the scalar offset+odd/even bit with the actual producer.

Fixes ef81d1b047337e81 ("target/hexagon: decode HLX packets and add load and store")
Quoted 8 lines
---
 target/hexagon/insn.h               |  1 +
 target/hexagon/decode.c             | 29 +++++++++++++++++++-----
 tests/tcg/hexagon/hlx_assign_conv.c | 35 +++++++++++++++++++++++++++++
 target/hexagon/gen_trans_funcs.py   |  5 +++++
 target/hexagon/hex_common.py        |  2 ++
 5 files changed, 66 insertions(+), 6 deletions(-)
Reviewed-by on v3 2/4
#4 lore raw

Re: [PATCH v3 2/4] target/hexagon: HLX, search for .new values in pair high register

In reply to Anton Johansson via qemu development
Quoted 24 lines · Anton Johansson

Otherwise, the following packet

   {
       L7:6 = combine(L0, L2)
       mem(R7) = L7.new
   }

results in mem(R7) being zero-initialized, compared to L6.new which would correctly write the lower bytes of the pair.

Compared to scalar and HVX .new instructions, HLX encodes the register number rather than an offset to the producing instruction + an odd/even bit. In order to find possible producers which write to register pairs without the odd/even bit, a Instruction::has_pair_dest field is added for scalar, HVX, and HLX registers.

Lastly, we move the new-regno patching in decode_fill_newvalue_regno() to the non-HLX scalar path to avoid overwriting the consumer L7 with the base register L6 of the producer destination L7:6. This is safe as the patching is only required for replacing the scalar offset+odd/even bit with the actual producer.

Fixes ef81d1b047337e81 ("target/hexagon: decode HLX packets and add load and store")
Quoted 7 lines
---
  target/hexagon/insn.h               |  1 +
  target/hexagon/decode.c             | 29 +++++++++++++++++++-----
  tests/tcg/hexagon/hlx_assign_conv.c | 35 +++++++++++++++++++++++++++++
  target/hexagon/gen_trans_funcs.py   |  5 +++++
  target/hexagon/hex_common.py        |  2 ++
  5 files changed, 66 insertions(+), 6 deletions(-)
Quoted 166 lines
target/hexagon/insn.h +1 -0
index 0dd36d2931..37a3111374 100644
@@ -42,6 +42,7 @@ struct Instruction {
      int32_t new_read_idx;
      int32_t dest_idx;
      bool has_pred_dest;
+    bool has_pair_dest;
 
      bool part1;              /*
                                * cmp-jumps are split into two insns.
target/hexagon/decode.c +23 -6
index d48630da87..08fa9aee2a 100644
@@ -110,9 +110,25 @@ static int hlx_find_new_value_producer(Packet *packet, int consumer,
  {
      for (int i = 0; i < packet->num_insns; i++) {
          Insn *insn = &packet->insn[i];
+        uint8_t regno;
 
-        if (i != consumer && GET_ATTRIB(insn->opcode, A_HLX) &&
-            insn->dest_idx != -1 && insn->regno[insn->dest_idx] == lreg) {
+        /*
+         * Skip ourselves, instructions without return values, and
+         * any non-HLX instructions.
+         */
+        if (i == consumer || !GET_ATTRIB(insn->opcode, A_HLX) ||
+            insn->dest_idx == -1) {
+            continue;
+        }
+
+        regno = insn->regno[insn->dest_idx];
+
+        /*
+         * Compare against the base register number, and against the top
+         * register for instructions returning pairs.
+         */
+        if (regno == lreg ||
+            (insn->has_pair_dest && regno + 1 == lreg)) {
              return i;
          }
      }
@@ -172,12 +188,13 @@ decode_fill_newvalue_regno(Packet *packet)
                  if (def_idx < 0 || packet->insn[def_idx].dest_idx == -1) {
                      return false;
                  }
+
+                /* Now patch up the consumer with the register number */
+                dst_idx = packet->insn[def_idx].dest_idx;
+                packet->insn[i].regno[use_regidx] =
+                    packet->insn[def_idx].regno[dst_idx];
              }
 
-            /* Now patch up the consumer with the register number */
-            dst_idx = packet->insn[def_idx].dest_idx;
-            packet->insn[i].regno[use_regidx] =
-                packet->insn[def_idx].regno[dst_idx];
              /*
               * We need to remember who produces this value to later
               * check if it was dynamically cancelled
tests/tcg/hexagon/hlx_assign_conv.c +35 -0
index 8192882b8e..bca902a6e5 100644
@@ -120,6 +120,40 @@ static void test_assign_rw(void)
      check_wp("LX_assign_rw", pw_out_lo, pw_out_hi, expected_w, HLX_HALF_ELEMS);
  }
 
+static void test_combine_assign_hi(void)
+{
+    /*
+     * Tests that a combine operation acts as a producer of a .new value for
+     * the high vector in a pair.
+     */
+    HLX_Vector l_lo;
+    HLX_Vector l_hi;
+
+    fill_w(pw_a_lo, pw_a_hi, VAL_W);
+
+    l_lo = Q6_L_tmp_mem_A(pw_a_lo);
+    l_hi = Q6_L_tmp_mem_A(pw_a_hi);
+
+    hlx_put_v(0, l_lo);
+    hlx_put_v(2, l_hi);
+    /*
+     * {
+     *     L7:6 = combine(L0, L2)
+     *     mem(R7) = L7.new
+     * }
+     */
+    asm volatile(HLX_PTRS HLX_LD0 HLX_LD2
+                 ".word 0xef24602d\n"
+                 ".word 0xa487c007\n"
+                 : : [stage] "r"(hlx_stage) : HLX_CLOBBERS);
+    Q6_mem_Ku16_new_AL(buf_a, hlx_get_v(7));
+
+    for (int j = 0; j < HLX_HALF_ELEMS; j++) {
+        expected[j] = VAL_B;
+    }
+    check_h("LX_assign_w (hi only)", buf_a, expected, HLX_HALF_ELEMS);
+}
+
 
  static void test_combine_w(void)
  {
@@ -336,6 +370,7 @@ int main(void)
      test_assign_s();
      test_assign_u();
      test_assign_rw();
+    test_combine_assign_hi();
 
      /* Combine and mux */
      test_combine_w();
target/hexagon/gen_trans_funcs.py +5 -0
index 93125bdfe4..7e65438565 100755
@@ -74,6 +74,7 @@ def mark_which_imm_extended(f, tag):
  ##         insn->new_read_idx = -1;
  ##         insn->dest_idx = 0;
  ##         insn->has_pred_dest = false;
+##         insn->has_pair_dest = false;
  ##         return true;
  ##     }
  ##
@@ -94,6 +95,7 @@ def gen_trans_funcs(f):
          dest_idx = -1
          dest_idx_reg_id = None
          has_pred_dest = "false"
+        has_pair_dest = "false"
          for regno, (reg_type, reg_id, *_) in enumerate(regs):
              reg = hex_common.get_register(tag, reg_type, reg_id)
              f.write(code_fmt(f"""\
@@ -108,6 +110,8 @@ def gen_trans_funcs(f):
                      dest_idx_reg_id = reg_id
              if reg_type == "P" and reg.is_written() and not reg.is_read():
                  has_pred_dest = "true"
+            if reg.is_written() and reg.is_pair():
+                has_pair_dest = "true"
 
          if len(imms) != 0:
              mark_which_imm_extended(f, tag)
@@ -132,6 +136,7 @@ def gen_trans_funcs(f):
              insn->new_read_idx = {new_read_idx};
              insn->dest_idx = {dest_idx};
              insn->has_pred_dest = {has_pred_dest};
+            insn->has_pair_dest = {has_pair_dest};
          """))
          f.write(textwrap.dedent(f"""\
                  return true;
target/hexagon/hex_common.py +2 -0
index f85f063f52..8d68d8dad9 100755
@@ -805,6 +805,8 @@ def is_hvx_reg(self):
          return True
      def is_hlx_reg(self):
          return False
+    def is_pair(self):
+        return len(self.regid) == 2
      def hvx_off(self):
          return f"{self.reg_tcg()}_off"
      def hvx_base(self):
#5 lore raw

PATCH v3 3/4 target/hexagon: Forward return address to HLX load/store helpers

In reply to Anton Johansson via qemu development
Fixes 2db29a3615a5ad2a3 ("target/hexagon: add HLX helper support")
---
 target/hexagon/hlx_helper.h | 19 +++++++++++++++++++
 target/hexagon/macros.h     | 13 +++++++++----
 target/hexagon/hlx_helper.c | 31 ++++++++++++++++++++++---------
 3 files changed, 50 insertions(+), 13 deletions(-)
 create mode 100644 target/hexagon/hlx_helper.h
target/hexagon/hlx_helper.h new file +19 -0
new file mode 100644
index 0000000000..ab36cc1049
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HEXAGON_HLX_HELPER_H
+#define HEXAGON_HLX_HELPER_H
+
+#include "cpu.h"
+
+void hlx_load_vec_ra(CPUHexagonState *env, void *dst_void,
+                     target_ulong ea, uint32_t above, uint32_t below,
+                     uintptr_t ra);
+
+void hlx_store_vec_ra(CPUHexagonState *env, target_ulong ea,
+                      void *src_void, uint32_t above, uint32_t below,
+                      uintptr_t ra);
+
+#endif
target/hexagon/macros.h +9 -4
index 2748e26d6c..5799016ea4 100644
@@ -22,6 +22,7 @@
 #include "hex_regs.h"
 #include "reg_fields.h"
 #include "accel/tcg/getpc.h"
+#include "hlx_helper.h"
 
 #define GET_FIELD(FIELD, REGIN) \
     fEXTRACTU_BITS(REGIN, reg_field_info[FIELD].width, \
@@ -738,8 +739,10 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)
                             EA, tcg_constant_i32(ABOVE), \
                             tcg_constant_i32(BELOW))
 #else
-#define fLOADMML(EA, DST, ABOVE, BELOW) \
-    do { HELPER(hlx_load_vec)(env, &(DST), (EA), (ABOVE), (BELOW)); } while (0)
+#define fLOADMML(EA, DST, ABOVE, BELOW)                                \
+    do {                                                               \
+        hlx_load_vec_ra(env, &(DST), (EA), (ABOVE), (BELOW), GETPC()); \
+    } while (0)
 #endif
 
 /* The helper logs the store for packet commit. */
@@ -748,8 +751,10 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)
     gen_helper_hlx_store_vec(tcg_env, EA, tcg_constant_ptr((intptr_t)&(SRC)), \
                              tcg_constant_i32(ABOVE), tcg_constant_i32(BELOW))
 #else
-#define fSTOREMML(EA, SRC, ABOVE, BELOW) \
-    do { HELPER(hlx_store_vec)(env, (EA), &(SRC), (ABOVE), (BELOW)); } while (0)
+#define fSTOREMML(EA, SRC, ABOVE, BELOW)                                \
+    do {                                                                \
+        hlx_store_vec_ra(env, (EA), &(SRC), (ABOVE), (BELOW), GETPC()); \
+    } while (0)
 #endif
 
 /* Helpers receive .new registers in future_LRegs. */
target/hexagon/hlx_helper.c +22 -9
index c063706cfa..bc638f6403 100644
@@ -7,6 +7,7 @@
 #include "cpu.h"
 #include "accel/tcg/cpu-ldst.h"
 #include "exec/helper-proto.h"
+#include "hlx_helper.h"
 #include "hlx/hlx.h"
 #include "hw/hexagon/hexagon_hlx.h"
 #include "accel/tcg/probe.h"
@@ -15,40 +16,52 @@
 #define HLX_MEM_ALIGN_MASK (~(HLX_VEC_SIZE_BYTES - 1))
 
 /* Align down to 2KB. Above and below are unused in V85. */
-void HELPER(hlx_load_vec)(CPUHexagonState *env, void *dst_void,
-                          target_ulong ea, uint32_t above, uint32_t below)
+void hlx_load_vec_ra(CPUHexagonState *env, void *dst_void,
+                     target_ulong ea, uint32_t above, uint32_t below,
+                     uintptr_t ra)
 {
     HLXVector *dst = (HLXVector *)dst_void;
     target_ulong aligned_ea = ea & HLX_MEM_ALIGN_MASK;
-    uintptr_t raddr = GETPC();
     int mmu_idx = cpu_mmu_index(env_cpu(env), false);
 
     /* A 2KB-aligned access stays within one page. */
-    void *host = probe_read(env, aligned_ea, HLX_VEC_SIZE_BYTES, mmu_idx,
-                            raddr);
+    void *host = probe_read(env, aligned_ea, HLX_VEC_SIZE_BYTES, mmu_idx, ra);
 
     if (host) {
         memcpy(dst, host, HLX_VEC_SIZE_BYTES);
     } else {
         for (int i = 0; i < HLX_VEC_SIZE_BYTES; i += 8) {
-            uint64_t val = cpu_ldq_le_data_ra(env, aligned_ea + i, raddr);
+            uint64_t val = cpu_ldq_le_data_ra(env, aligned_ea + i, ra);
             memcpy(&dst->ub[i], &val, 8);
         }
     }
 }
 
-void HELPER(hlx_store_vec)(CPUHexagonState *env, target_ulong ea,
-                           void *src_void, uint32_t above, uint32_t below)
+void hlx_store_vec_ra(CPUHexagonState *env, target_ulong ea,
+                      void *src_void, uint32_t above, uint32_t below,
+                      uintptr_t ra)
 {
     target_ulong aligned_ea = ea & HLX_MEM_ALIGN_MASK;
     int mmu_idx = cpu_mmu_index(env_cpu(env), false);
 
-    probe_write(env, aligned_ea, HLX_VEC_SIZE_BYTES, mmu_idx, GETPC());
+    probe_write(env, aligned_ea, HLX_VEC_SIZE_BYTES, mmu_idx, ra);
     memcpy(&env->hlx_store_data, src_void, sizeof(HLXVector));
     env->hlx_store_va = aligned_ea;
     env->hlx_store_pending = true;
 }
 
+void HELPER(hlx_load_vec)(CPUHexagonState *env, void *dst_void,
+                          target_ulong ea, uint32_t above, uint32_t below)
+{
+    hlx_load_vec_ra(env, dst_void, ea, above, below, GETPC());
+}
+
+void HELPER(hlx_store_vec)(CPUHexagonState *env, target_ulong ea,
+                           void *src_void, uint32_t above, uint32_t below)
+{
+    hlx_store_vec_ra(env, ea, src_void, above, below, GETPC());
+}
+
 void HELPER(hlx_commit_store)(CPUHexagonState *env)
 {
     target_ulong va = env->hlx_store_va;
Signature · 1 line
2.52.0
Reviewed-by on v3 3/4
#6 lore raw

Re: [PATCH v3 3/4] target/hexagon: Forward return address to HLX load/store helpers

Quoted 9 lines · Anton Johansson
Fixes 2db29a3615a5ad2a3 ("target/hexagon: add HLX helper support")
---
  target/hexagon/hlx_helper.h | 19 +++++++++++++++++++
  target/hexagon/macros.h     | 13 +++++++++----
  target/hexagon/hlx_helper.c | 31 ++++++++++++++++++++++---------
  3 files changed, 50 insertions(+), 13 deletions(-)

create mode 100644 target/hexagon/hlx_helper.h

Quoted 137 lines
target/hexagon/hlx_helper.h new file +19 -0
new file mode 100644
index 0000000000..ab36cc1049
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HEXAGON_HLX_HELPER_H
+#define HEXAGON_HLX_HELPER_H
+
+#include "cpu.h"
+
+void hlx_load_vec_ra(CPUHexagonState *env, void *dst_void,
+                     target_ulong ea, uint32_t above, uint32_t below,
+                     uintptr_t ra);
+
+void hlx_store_vec_ra(CPUHexagonState *env, target_ulong ea,
+                      void *src_void, uint32_t above, uint32_t below,
+                      uintptr_t ra);
+
+#endif
target/hexagon/macros.h +9 -4
index 2748e26d6c..5799016ea4 100644
@@ -22,6 +22,7 @@
  #include "hex_regs.h"
  #include "reg_fields.h"
  #include "accel/tcg/getpc.h"
+#include "hlx_helper.h"
 
  #define GET_FIELD(FIELD, REGIN) \
      fEXTRACTU_BITS(REGIN, reg_field_info[FIELD].width, \
@@ -738,8 +739,10 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)
                              EA, tcg_constant_i32(ABOVE), \
                              tcg_constant_i32(BELOW))
  #else
-#define fLOADMML(EA, DST, ABOVE, BELOW) \
-    do { HELPER(hlx_load_vec)(env, &(DST), (EA), (ABOVE), (BELOW)); } while (0)
+#define fLOADMML(EA, DST, ABOVE, BELOW)                                \
+    do {                                                               \
+        hlx_load_vec_ra(env, &(DST), (EA), (ABOVE), (BELOW), GETPC()); \
+    } while (0)
  #endif
 
  /* The helper logs the store for packet commit. */
@@ -748,8 +751,10 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)
      gen_helper_hlx_store_vec(tcg_env, EA, tcg_constant_ptr((intptr_t)&(SRC)), \
                               tcg_constant_i32(ABOVE), tcg_constant_i32(BELOW))
  #else
-#define fSTOREMML(EA, SRC, ABOVE, BELOW) \
-    do { HELPER(hlx_store_vec)(env, (EA), &(SRC), (ABOVE), (BELOW)); } while (0)
+#define fSTOREMML(EA, SRC, ABOVE, BELOW)                                \
+    do {                                                                \
+        hlx_store_vec_ra(env, (EA), &(SRC), (ABOVE), (BELOW), GETPC()); \
+    } while (0)
  #endif
 
  /* Helpers receive .new registers in future_LRegs. */
target/hexagon/hlx_helper.c +22 -9
index c063706cfa..bc638f6403 100644
@@ -7,6 +7,7 @@
  #include "cpu.h"
  #include "accel/tcg/cpu-ldst.h"
  #include "exec/helper-proto.h"
+#include "hlx_helper.h"
  #include "hlx/hlx.h"
  #include "hw/hexagon/hexagon_hlx.h"
  #include "accel/tcg/probe.h"
@@ -15,40 +16,52 @@
  #define HLX_MEM_ALIGN_MASK (~(HLX_VEC_SIZE_BYTES - 1))
 
  /* Align down to 2KB. Above and below are unused in V85. */
-void HELPER(hlx_load_vec)(CPUHexagonState *env, void *dst_void,
-                          target_ulong ea, uint32_t above, uint32_t below)
+void hlx_load_vec_ra(CPUHexagonState *env, void *dst_void,
+                     target_ulong ea, uint32_t above, uint32_t below,
+                     uintptr_t ra)
  {
      HLXVector *dst = (HLXVector *)dst_void;
      target_ulong aligned_ea = ea & HLX_MEM_ALIGN_MASK;
-    uintptr_t raddr = GETPC();
      int mmu_idx = cpu_mmu_index(env_cpu(env), false);
 
      /* A 2KB-aligned access stays within one page. */
-    void *host = probe_read(env, aligned_ea, HLX_VEC_SIZE_BYTES, mmu_idx,
-                            raddr);
+    void *host = probe_read(env, aligned_ea, HLX_VEC_SIZE_BYTES, mmu_idx, ra);
 
      if (host) {
          memcpy(dst, host, HLX_VEC_SIZE_BYTES);
      } else {
          for (int i = 0; i < HLX_VEC_SIZE_BYTES; i += 8) {
-            uint64_t val = cpu_ldq_le_data_ra(env, aligned_ea + i, raddr);
+            uint64_t val = cpu_ldq_le_data_ra(env, aligned_ea + i, ra);
              memcpy(&dst->ub[i], &val, 8);
          }
      }
  }
 
-void HELPER(hlx_store_vec)(CPUHexagonState *env, target_ulong ea,
-                           void *src_void, uint32_t above, uint32_t below)
+void hlx_store_vec_ra(CPUHexagonState *env, target_ulong ea,
+                      void *src_void, uint32_t above, uint32_t below,
+                      uintptr_t ra)
  {
      target_ulong aligned_ea = ea & HLX_MEM_ALIGN_MASK;
      int mmu_idx = cpu_mmu_index(env_cpu(env), false);
 
-    probe_write(env, aligned_ea, HLX_VEC_SIZE_BYTES, mmu_idx, GETPC());
+    probe_write(env, aligned_ea, HLX_VEC_SIZE_BYTES, mmu_idx, ra);
      memcpy(&env->hlx_store_data, src_void, sizeof(HLXVector));
      env->hlx_store_va = aligned_ea;
      env->hlx_store_pending = true;
  }
 
+void HELPER(hlx_load_vec)(CPUHexagonState *env, void *dst_void,
+                          target_ulong ea, uint32_t above, uint32_t below)
+{
+    hlx_load_vec_ra(env, dst_void, ea, above, below, GETPC());
+}
+
+void HELPER(hlx_store_vec)(CPUHexagonState *env, target_ulong ea,
+                           void *src_void, uint32_t above, uint32_t below)
+{
+    hlx_store_vec_ra(env, ea, src_void, above, below, GETPC());
+}
+
  void HELPER(hlx_commit_store)(CPUHexagonState *env)
  {
      target_ulong va = env->hlx_store_va;
#7 lore raw

PATCH v3 4/4 linux-user/hexagon: Reset hlx_ctx pointer on cpu clone

In reply to Anton Johansson via qemu development

Currently hlx_ctx retains the pointer to the hlx_user_ctx of its parent. Another way to go is similar to hvx_ctx, which in user-mode, is just the struct itself rather than a pointer to the struct.

Fixes cf0bfbc338eaeef2b ("target/hexagon: manage HLX contexts through CCR")
---
 linux-user/hexagon/target_cpu.h | 1 +
 1 file changed, 1 insertion(+)
linux-user/hexagon/target_cpu.h +1 -0
index ecb76e9268..6c36b7166f 100644
@@ -25,6 +25,7 @@ static inline void cpu_clone_regs_child(CPUHexagonState *env,
         env->gpr[HEX_REG_SP] = newsp;
     }
     env->gpr[0] = 0;
+    env->hlx_ctx = &env->hlx_user_ctx;
 }
 
 static inline void cpu_clone_regs_parent(CPUHexagonState *env, unsigned flags)
Signature · 1 line
2.52.0
Reviewed-by on v3 4/4
#8 lore raw

Re: [PATCH v3 4/4] linux-user/hexagon: Reset hlx_ctx pointer on cpu clone

Quoted 8 lines · Anton Johansson

Currently hlx_ctx retains the pointer to the hlx_user_ctx of its parent. Another way to go is similar to hvx_ctx, which in user-mode, is just the struct itself rather than a pointer to the struct.

Fixes cf0bfbc338eaeef2b ("target/hexagon: manage HLX contexts through CCR")

---

Quoted 15 lines
  linux-user/hexagon/target_cpu.h | 1 +
  1 file changed, 1 insertion(+)
linux-user/hexagon/target_cpu.h +1 -0
index ecb76e9268..6c36b7166f 100644
@@ -25,6 +25,7 @@ static inline void cpu_clone_regs_child(CPUHexagonState *env,
          env->gpr[HEX_REG_SP] = newsp;
      }
      env->gpr[0] = 0;
+    env->hlx_ctx = &env->hlx_user_ctx;
  }
 
  static inline void cpu_clone_regs_parent(CPUHexagonState *env, unsigned flags)