Skip to contentSkip to conversation

target/hexagon: Misc HLX fixes

PATCH Superseded Anton Johansson via qemu development 3 participants 11 messages Nov 5 – Nov 6

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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)

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/macros.h             | 13 +++++++----
 target/hexagon/decode.c             | 20 +++++++++++++++--
 target/hexagon/hlx_helper.c         | 31 +++++++++++++++++--------
 target/hexagon/translate.c          |  7 +++---
 tests/tcg/hexagon/hlx_assign_conv.c | 35 +++++++++++++++++++++++++++++
 tests/tcg/hexagon/hlx_mem.c         | 22 ++++++++++++++++++
 8 files changed, 130 insertions(+), 18 deletions(-)
 create mode 100644 target/hexagon/hlx_helper.h
Signature · 1 line
2.52.0
#1 lore raw

PATCH v2 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..f5af95115a 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(%1) = %2\n"
+                 "    %0 = memw(%1)\n"
+                 "}:mem_noshuf\n"
+                 : "=r"(ret)
+                 : "r"(&ptr), "r"(val)
+                 : "memory");
+    if (ret != val) {
+        printf("FAIL broken scalar :mem_noshuf ordering\n");
+        err++;
+    }
+}
+
 int main(void)
 {
     init_vtcm();
@@ -253,6 +272,9 @@ int main(void)
     /* Store in a faulting packet */
     test_store_fault();
 
+    /* Make sure HLX packets preserve scalar :mem_noshuf ordering */
+    test_preserve_scalar_noshuf();
+
     puts(err ? "FAIL" : "PASS");
     return err;
 }
Signature · 1 line
2.52.0
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] target/hexagon: HLX, preserve scalar :mem_noshuf ordering

Quoted 5 lines · Anton Johansson

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

Quoted 7 lines
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(-)
Reviewed-by on v2 1/4
#3 lore raw

Re: [PATCH v2 1/4] target/hexagon: HLX, preserve scalar :mem_noshuf ordering

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

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

Fixes a6fae6da070d66b9 ("target/hexagon: translate packets with HLX instructions")
---
  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 +2 -0
index 643b499fd9..f5af95115a 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)
+{

tests/tcg/hexagon/hlx_mem.c static void test_store_fault(void) · line 243

Quoted 10 lines
tests/tcg/hexagon/hlx_mem.c +10 -0
+    uint32_t ret = 0;
+    uint32_t ptr = 0;
+    uint32_t val = 0x1234;
+    asm volatile("{\n"
+                 ".word 0xe5007822\n"
+                 "    memw(%1) = %2\n"
+                 "    %0 = memw(%1)\n"
+                 "}:mem_noshuf\n"
+                 : "=r"(ret)
+                 : "r"(&ptr), "r"(val)

IMO it's a nice-to-have to use named-parameter substitution for inline asm instead of enumerated parameters.

If you decide to make that change: great.

Regardless,

Quoted 20 lines
tests/tcg/hexagon/hlx_mem.c +10 -0
+                 : "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;
  }
#4 lore raw

PATCH v2 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, L1)
      memw(R7) = L7.new
  }

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

Fixes ef81d1b047337e81 ("target/hexagon: decode HLX packets and add load and store")
---
 target/hexagon/decode.c             | 20 +++++++++++++++--
 tests/tcg/hexagon/hlx_assign_conv.c | 35 +++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 2 deletions(-)
target/hexagon/decode.c +18 -2
index d48630da87..8921ff765d 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 ||
+            (GET_ATTRIB(insn->opcode, A_HLX_PAIRED_ALU) && regno + 1 == lreg)) {
             return i;
         }
     }
tests/tcg/hexagon/hlx_assign_conv.c +35 -0
index 8192882b8e..aef82dd63b 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, L1)
+     *     memw(R7) = L7.new
+     * }
+     */
+    asm volatile(HLX_PTRS HLX_LD0 HLX_LD2
+                 ".word 0xef24602d\n"
+                 ".word 0xa487c007\n"
+                 : : [stage] "r"(hlx_stage) : HLX_CLOBBERS);
+    Q6_mem_Ku16_new_AL(buf_a, hlx_get_v(7));
+
+    for (int j = 0; j < HLX_HALF_ELEMS; j++) {
+        expected[j] = VAL_A;
+    }
+    check_h("LX_assign_w (hi only)", buf_a, expected, HLX_HALF_ELEMS);
+}
+
 
 static void test_combine_w(void)
 {
@@ -336,6 +370,7 @@ int main(void)
     test_assign_s();
     test_assign_u();
     test_assign_rw();
+    test_combine_assign_hi();
 
     /* Combine and mux */
     test_combine_w();
Signature · 1 line
2.52.0
#5 lore raw

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

Quoted 10 lines · Anton Johansson

Otherwise, the following packet

  {
      L7:6 = combine(L0, L1)
      memw(R7) = L7.new
  }

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

The packet in the test is combine(L0, L2), and the store is mem(R7) = L7.new.

Also s/intialized/initialized/.

[...]

target/hexagon/decode.c static int hlx_find_new_value_producer(Packet *packet, int consumer, · line 133

Quoted 4 lines
target/hexagon/decode.c +2 -0
+        if (regno == lreg ||
+            (GET_ATTRIB(insn->opcode, A_HLX_PAIRED_ALU) && regno + 1 == lreg)) {
             return i;
         }

This finds the producer now, but decode_fill_newvalue_regno() then overwrites the consumer's register with the producer's dest register:

packet->insn[i].regno[use_regidx] = packet->insn[def_idx].regno[dst_idx];

For a pair, that is the base register, so L7.new becomes L6.new and the store writes the low half of the pair instead of the high half.

Also, not all instructions that write a pair have A_HLX_PAIRED_ALU, e.g. LX_assign_rw (Ldd16.w=Rt32.w). A high .new store from those still writes zeros.

[...]

Quoted 2 lines
tests/tcg/hexagon/hlx_assign_conv.c +2 -0
+    hlx_put_v(0, l_lo);
+    hlx_put_v(2, l_hi);

[...]

tests/tcg/hexagon/hlx_assign_conv.c static void test_assign_rw(void) · line 155

Quoted 5 lines
tests/tcg/hexagon/hlx_assign_conv.c +5 -0
+    for (int j = 0; j < HLX_HALF_ELEMS; j++) {
+        expected[j] = VAL_A;
+    }
+    check_h("LX_assign_w (hi only)", buf_a, expected, HLX_HALF_ELEMS);
+}

L0 holds the low halves of VAL_W (0x5678), and combine(L0, L2) puts L0 into L7. So L7.new must store 0x5678, but the test expects VAL_A (0x1234), which is the L6 value.

The test passes because L6.new is used instead of L7.new.

IMHO: Maybe we should have a mechanism that creates an error
if a .new value is used, but that .new value isn't even in the packet. Like it is happening here. L6.new is computed, but it isn't even used in the packet. Maybe poisoning it somehow. But that's just me thinking out loud, doesn't need to go into this patch series.

#6 lore raw

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

Quoted 44 lines · Marco Liebel
Quoted 9 lines · Anton Johansson

Otherwise, the following packet

   {
       L7:6 = combine(L0, L1)
       memw(R7) = L7.new
   }

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

The packet in the test is combine(L0, L2), and the store is mem(R7) = L7.new.

Also s/intialized/initialized/.

[...]

target/hexagon/decode.c static int hlx_find_new_value_producer(Packet *packet, int consumer, · line 133

Quoted 4 lines
target/hexagon/decode.c +2 -0
+        if (regno == lreg ||
+            (GET_ATTRIB(insn->opcode, A_HLX_PAIRED_ALU) && regno + 1 == lreg)) {
              return i;
          }

This finds the producer now, but decode_fill_newvalue_regno() then overwrites the consumer's register with the producer's dest register:

packet->insn[i].regno[use_regidx] = packet->insn[def_idx].regno[dst_idx];

For a pair, that is the base register, so L7.new becomes L6.new and the store writes the low half of the pair instead of the high half.

Also, not all instructions that write a pair have A_HLX_PAIRED_ALU, e.g. LX_assign_rw (Ldd16.w=Rt32.w). A high .new store from those still writes zeros.

[...]

Quoted 2 lines
tests/tcg/hexagon/hlx_assign_conv.c +2 -0
+    hlx_put_v(0, l_lo);
+    hlx_put_v(2, l_hi);

[...]

tests/tcg/hexagon/hlx_assign_conv.c static void test_assign_rw(void) · line 155

Quoted 5 lines
tests/tcg/hexagon/hlx_assign_conv.c +5 -0
+    for (int j = 0; j < HLX_HALF_ELEMS; j++) {
+        expected[j] = VAL_A;
+    }
+    check_h("LX_assign_w (hi only)", buf_a, expected, HLX_HALF_ELEMS);
+}
Quoted 8 lines

L0 holds the low halves of VAL_W (0x5678), and combine(L0, L2) puts L0 into L7. So L7.new must store 0x5678, but the test expects VAL_A (0x1234), which is the L6 value.

The test passes because L6.new is used instead of L7.new.

IMHO: Maybe we should have a mechanism that creates an error
if a .new value is used, but that .new value isn't even in the packet. Like it

This sounds like it's either well-defined behavior that raises an invalid packet exception or implicitly/explicitly undefined behavior for which we can log a guest error.  If this condition represents a problem with the decoder it can just be an assertion, but it sounds like that's not the case.

For HVX many ill-formed packets are considered to be undefined and do not raise exceptions.  HLX may be similar, we'll have to check.

Quoted 3 lines

is happening here. L6.new is computed, but it isn't even used in the packet. Maybe poisoning it somehow. But that's just me thinking out loud, doesn't need to go into this patch series.

#7 lore raw

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

Quoted 51 lines · Brian Cain
Quoted 49 lines · Marco Liebel
Quoted 9 lines · Anton Johansson

Otherwise, the following packet

   {
       L7:6 = combine(L0, L1)
       memw(R7) = L7.new
   }

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

The packet in the test is combine(L0, L2), and the store is mem(R7) = L7.new.

Also s/intialized/initialized/.

[...]

Quoted 5 lines

+        if (regno == lreg ||
+            (GET_ATTRIB(insn->opcode, A_HLX_PAIRED_ALU) && regno + 1 == lreg)) {
              return i;
          }

This finds the producer now, but decode_fill_newvalue_regno() then overwrites the consumer's register with the producer's dest register:

packet->insn[i].regno[use_regidx] = packet->insn[def_idx].regno[dst_idx];

For a pair, that is the base register, so L7.new becomes L6.new and the store writes the low half of the pair instead of the high half.

Also, not all instructions that write a pair have A_HLX_PAIRED_ALU, e.g. LX_assign_rw (Ldd16.w=Rt32.w). A high .new store from those still writes zeros.

[...]

Quoted 2 lines

+    hlx_put_v(0, l_lo);
+    hlx_put_v(2, l_hi);

[...]

Quoted 5 lines

+    for (int j = 0; j < HLX_HALF_ELEMS; j++) {
+        expected[j] = VAL_A;
+    }
+    check_h("LX_assign_w (hi only)", buf_a, expected, HLX_HALF_ELEMS); +}

L0 holds the low halves of VAL_W (0x5678), and combine(L0, L2) puts L0 into L7. So L7.new must store 0x5678, but the test expects VAL_A (0x1234), which is the L6 value.

Quoted 7 lines
Quoted 4 lines

The test passes because L6.new is used instead of L7.new.

IMHO: Maybe we should have a mechanism that creates an error
if a .new value is used, but that .new value isn't even in the packet. Like it

This sounds like it's either well-defined behavior that raises an invalid packet exception or implicitly/explicitly undefined behavior for which we can log a guest error.  If this condition represents a problem with the decoder it can just be an assertion, but it sounds like that's not the case.

It was a little unclear to me whether ".new value is used ... isn't even in the packet" represented an encoding problem or a design error/decoding problem in QEMU.  Marco and I talked in person and it's clear to me now that it's the latter.

"maybe poisoning it somehow" - yes, if there's an easy way for us to make such an assertion we should definitely do that.  That sounds like it may be worth a look (by someone, at some time - agreed not necessarily in scope for this patch review).

Quoted 5 lines

For HVX many ill-formed packets are considered to be undefined and do not raise exceptions.  HLX may be similar, we'll have to check.

Quoted 3 lines

is happening here. L6.new is computed, but it isn't even used in the packet. Maybe poisoning it somehow. But that's just me thinking out loud, doesn't need to go into this patch series.

#8 lore raw

PATCH v2 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 v2 3/4
#9 lore raw

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

Quoted 10 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
#10 lore raw

PATCH v2 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