Skip to contentSkip to conversation

hexagon: Add HVX context

PATCH Superseded Brian Cain 2 participants 11 messages Sep 15 – Sep 23 Arm/Amlogic Meson SoC support

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Brian Cain

author
#0 lore raw

v5 cover hexagon: Add HVX context

Add HVX contexts to Hexagon translation, necessary for system emulation. Change the HVX instruction translation to access the context via a base pointer.

Modeling the HVX context mapping while avoiding the need to copy the context when the OS scheduler decides to remap them required some general TCG gvec changes to enable some more _var forms.

In v5:
- added a GUEST_ERROR when SSR:XA value is out-of-range for ext_contexts.

In v4:
- moved the linux-user hvx_ctx from ArchCPU to CPUArchState, eliminating linux-user/main.c change.

In v3:
- fixed HVX context alignment declarations
- created hex_hvx_ptr global for sysemu, abstraction hex_hvx() to refer to the context.
- added some test cases (reset Marco's R-b)

In v2:
- Removed unused default hvx context from target/hexagon/cpu.[ch], add a hexagon_hvx_select_context() to the reset instead.
- combined the HVX pointer, QOM context, and SSR:XA selection work commits into share HVX contexts among CPUs.

v4: https://lore.kernel.org/qemu-devel/[email protected]/
v3: https://lore.kernel.org/qemu-devel/[email protected]/
v2: https://lore.kernel.org/qemu-devel/[email protected]/
v1: https://lore.kernel.org/qemu-devel/[email protected]/

Brian Cain (6):
tcg: split out _var forms of gvec logical, abs and min/max ops
tcg: add base arguments to the gvec 2s, dup_i32 and cmp expanders
tcg: split out _var forms of gvec saturating/mul/shift-immediate ops target/hexagon: raise an exception for HVX with SSR:XE clear target/hexagon: share HVX contexts among CPUs tests/functional/hexagon: add HVX tests

 include/hw/hexagon/hexagon.h                |   1 +
 include/hw/hexagon/hexagon_hvx_context.h    |  27 +
 include/tcg/tcg-op-gvec-common.h            |  97 +++
 target/hexagon/cpu.h                        |  26 +-
 target/hexagon/cpu_helper.h                 |   1 +
 target/hexagon/gen_tcg_hvx.h                | 608 ++++++++++---------
 target/hexagon/genptr.h                     |   8 +
 target/hexagon/mmvec/macros.h               |  14 +-
 target/hexagon/translate.h                  |  13 +-
 hw/hexagon/hex-subsys.c                     |  36 ++
 hw/hexagon/hexagon_hvx_context.c            |  84 +++
 target/hexagon/cpu.c                        |  32 +-
 target/hexagon/cpu_helper.c                 |  82 +++
 target/hexagon/gdbstub.c                    |  16 +-
 target/hexagon/genptr.c                     | 102 ++--
 target/hexagon/machine.c                    |  12 +
 target/hexagon/op_helper.c                  |  37 +-
 target/hexagon/translate.c                  |  71 ++-
 tcg/tcg-op-gvec.c                           | 617 ++++++++++++++------
 hw/hexagon/meson.build                      |   1 +
 target/hexagon/hex_common.py                | 179 +++---
 tests/functional/hexagon/test_arch_tests.py |   7 +
 tests/functional/hexagon/test_systests.py   |   6 +
 23 files changed, 1456 insertions(+), 621 deletions(-)
 create mode 100644 include/hw/hexagon/hexagon_hvx_context.h
 create mode 100644 hw/hexagon/hexagon_hvx_context.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v5 1/6 tcg: split out _var forms of gvec logical, abs and min/max ops

target/hexagon is about to address its HVX register file through a runtime base pointer rather than a constant offset from env, in order to share one register file between several vCPUs. The gvec ops it needs have no base-parameterized form yet.

Split tcg_gen_gvec_{and,or,xor,andc,orc,not,abs,smin,umin,smax,umax} the same way tcg_gen_gvec_{add,sub,mov,dup_imm} already are: the work moves to a _var function taking a TCGv_ptr base per operand, and the existing entry point becomes a wrapper passing tcg_env.

The aofs == bofs shortcuts also have to compare the bases, since equal offsets into different objects are not the same operand.

---
 include/tcg/tcg-op-gvec-common.h |  45 ++++++++
 tcg/tcg-op-gvec.c                | 184 ++++++++++++++++++++++++-------
 2 files changed, 189 insertions(+), 40 deletions(-)
include/tcg/tcg-op-gvec-common.h +45 -0
index ea0c87f4db6..99a6685e8a5 100644
@@ -287,6 +287,13 @@ void tcg_gen_gvec_mov_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
                           TCGv_ptr abase, uint32_t aofs,
                           uint32_t oprsz, uint32_t maxsz);
 
+void tcg_gen_gvec_not_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                          TCGv_ptr abase, uint32_t aofs,
+                          uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_abs_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                          TCGv_ptr abase, uint32_t aofs,
+                          uint32_t oprsz, uint32_t maxsz);
+
 void tcg_gen_gvec_mov(unsigned vece, uint32_t dofs, uint32_t aofs,
                       uint32_t oprsz, uint32_t maxsz);
 void tcg_gen_gvec_not(unsigned vece, uint32_t dofs, uint32_t aofs,
@@ -335,6 +342,23 @@ void tcg_gen_gvec_ussub(unsigned vece, uint32_t dofs, uint32_t aofs,
                         uint32_t bofs, uint32_t oprsz, uint32_t maxsz);
 
 /* Min/max.  */
+void tcg_gen_gvec_smin_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                           TCGv_ptr abase, uint32_t aofs,
+                           TCGv_ptr bbase, uint32_t bofs,
+                           uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_umin_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                           TCGv_ptr abase, uint32_t aofs,
+                           TCGv_ptr bbase, uint32_t bofs,
+                           uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_smax_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                           TCGv_ptr abase, uint32_t aofs,
+                           TCGv_ptr bbase, uint32_t bofs,
+                           uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_umax_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                           TCGv_ptr abase, uint32_t aofs,
+                           TCGv_ptr bbase, uint32_t bofs,
+                           uint32_t oprsz, uint32_t maxsz);
+
 void tcg_gen_gvec_smin(unsigned vece, uint32_t dofs, uint32_t aofs,
                        uint32_t bofs, uint32_t oprsz, uint32_t maxsz);
 void tcg_gen_gvec_umin(unsigned vece, uint32_t dofs, uint32_t aofs,
@@ -344,6 +368,27 @@ void tcg_gen_gvec_smax(unsigned vece, uint32_t dofs, uint32_t aofs,
 void tcg_gen_gvec_umax(unsigned vece, uint32_t dofs, uint32_t aofs,
                        uint32_t bofs, uint32_t oprsz, uint32_t maxsz);
 
+void tcg_gen_gvec_and_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                          TCGv_ptr abase, uint32_t aofs,
+                          TCGv_ptr bbase, uint32_t bofs,
+                          uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_or_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                         TCGv_ptr abase, uint32_t aofs,
+                         TCGv_ptr bbase, uint32_t bofs,
+                         uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_xor_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                          TCGv_ptr abase, uint32_t aofs,
+                          TCGv_ptr bbase, uint32_t bofs,
+                          uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_andc_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                           TCGv_ptr abase, uint32_t aofs,
+                           TCGv_ptr bbase, uint32_t bofs,
+                           uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_orc_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                          TCGv_ptr abase, uint32_t aofs,
+                          TCGv_ptr bbase, uint32_t bofs,
+                          uint32_t oprsz, uint32_t maxsz);
+
 void tcg_gen_gvec_and(unsigned vece, uint32_t dofs, uint32_t aofs,
                       uint32_t bofs, uint32_t oprsz, uint32_t maxsz);
 void tcg_gen_gvec_or(unsigned vece, uint32_t dofs, uint32_t aofs,
tcg/tcg-op-gvec.c +144 -40

299 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v5 2/6 tcg: add base arguments to the gvec 2s, dup_i32 and cmp expanders

In reply to Brian Cain

These three families still name tcg_env directly, so they cannot be reached from a _var entry point. Thread a TCGv_ptr base per operand through expand_2s_{i32,i64,vec}, expand_2sh_vec, expand_cmp_{i32,i64,vec} and do_gvec_shifts, and split expand_2i_ool out of tcg_gen_gvec_2i_ool the way expand_2_ool already is, so the out-of-line fallback is reachable too.

Add tcg_gen_gvec_{2s,shls,shrs,sars,dup_i32,cmp}_var; the existing entry points become wrappers passing tcg_env and generate identical code.

Note that the operand swap in tcg_gen_gvec_cmp_var, used when a condition has no helper, now has to swap the bases along with the offsets.

---
 include/tcg/tcg-op-gvec-common.h |  21 +++
 tcg/tcg-op-gvec.c                | 256 +++++++++++++++++++++----------
 2 files changed, 192 insertions(+), 85 deletions(-)
include/tcg/tcg-op-gvec-common.h +21 -0
index 99a6685e8a5..fa28ebdde0f 100644
@@ -237,6 +237,10 @@ void tcg_gen_gvec_2(uint32_t dofs, uint32_t aofs,
 /* Similarly, expand (env+dofs) = op(env+aofs, c). */
 void tcg_gen_gvec_2i(uint32_t dofs, uint32_t aofs, uint32_t oprsz,
                      uint32_t maxsz, int64_t c, const GVecGen2i *op);
+/* Expand (dbase+dofs) = op(abase+aofs, s), length @oprsz. */
+void tcg_gen_gvec_2s_var(TCGv_ptr dbase, uint32_t dofs,
+                         TCGv_ptr abase, uint32_t aofs, uint32_t oprsz,
+                         uint32_t maxsz, TCGv_i64 c, const GVecGen2s *op);
 /* Similarly, expand (env+dofs) = op(env+aofs, s). */
 void tcg_gen_gvec_2s(uint32_t dofs, uint32_t aofs, uint32_t oprsz,
                      uint32_t maxsz, TCGv_i64 c, const GVecGen2s *op);
@@ -433,6 +437,8 @@ void tcg_gen_gvec_dup_i64(unsigned vece, uint32_t dofs, uint32_t s,
 
 void tcg_gen_gvec_dup_imm_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
                               uint32_t oprsz, uint32_t maxsz, uint64_t imm);
+void tcg_gen_gvec_dup_i32_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                              uint32_t oprsz, uint32_t maxsz, TCGv_i32 in);
 
 void tcg_gen_gvec_shli(unsigned vece, uint32_t dofs, uint32_t aofs,
                        int64_t shift, uint32_t oprsz, uint32_t maxsz);
@@ -445,6 +451,16 @@ void tcg_gen_gvec_rotli(unsigned vece, uint32_t dofs, uint32_t aofs,
 void tcg_gen_gvec_rotri(unsigned vece, uint32_t dofs, uint32_t aofs,
                         int64_t shift, uint32_t oprsz, uint32_t maxsz);
 
+void tcg_gen_gvec_shls_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                           TCGv_ptr abase, uint32_t aofs,
+                           TCGv_i32 shift, uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_shrs_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                           TCGv_ptr abase, uint32_t aofs,
+                           TCGv_i32 shift, uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_sars_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                           TCGv_ptr abase, uint32_t aofs,
+                           TCGv_i32 shift, uint32_t oprsz, uint32_t maxsz);
+
 void tcg_gen_gvec_shls(unsigned vece, uint32_t dofs, uint32_t aofs,
                        TCGv_i32 shift, uint32_t oprsz, uint32_t maxsz);
 void tcg_gen_gvec_shrs(unsigned vece, uint32_t dofs, uint32_t aofs,
@@ -471,6 +487,11 @@ void tcg_gen_gvec_rotlv(unsigned vece, uint32_t dofs, uint32_t aofs,
 void tcg_gen_gvec_rotrv(unsigned vece, uint32_t dofs, uint32_t aofs,
                         uint32_t bofs, uint32_t oprsz, uint32_t maxsz);
 
+void tcg_gen_gvec_cmp_var(TCGCond cond, unsigned vece,
+                          TCGv_ptr dbase, uint32_t dofs,
+                          TCGv_ptr abase, uint32_t aofs,
+                          TCGv_ptr bbase, uint32_t bofs,
+                          uint32_t oprsz, uint32_t maxsz);
 void tcg_gen_gvec_cmp(TCGCond cond, unsigned vece, uint32_t dofs,
                       uint32_t aofs, uint32_t bofs,
                       uint32_t oprsz, uint32_t maxsz);
tcg/tcg-op-gvec.c +171 -85

566 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v5 3/6 tcg: split out _var forms of gvec saturating/mul/shift-immediate ops

In reply to Brian Cain

target/hexagon is about to address its HVX register file through a runtime base pointer rather than a constant offset from env, in order to share one register file between several vCPUs. Split the other gvec op families it needs like tcg_gen_gvec_{add,sub,mov,and,etc}.

Add tcg_gen_gvec_{ssadd,sssub,usadd,ussub,mul}_var and tcg_gen_gvec_{shri,sari}_var, plus the tcg_gen_gvec_2i_var plumbing the immediate-shift forms are built on.

---
 include/tcg/tcg-op-gvec-common.h |  31 ++++++
 tcg/tcg-op-gvec.c                | 177 ++++++++++++++++++++++---------
 2 files changed, 160 insertions(+), 48 deletions(-)
include/tcg/tcg-op-gvec-common.h +31 -0
index fa28ebdde0f..6d3c2bae57a 100644
@@ -234,6 +234,10 @@ void tcg_gen_gvec_2_var(TCGv_ptr dbase, uint32_t dofs,
 /* Similarly, expand (env+dofs) = op(env+aofs). */
 void tcg_gen_gvec_2(uint32_t dofs, uint32_t aofs,
                     uint32_t oprsz, uint32_t maxsz, const GVecGen2 *op);
+/* Expand (dbase+dofs) = op(abase+aofs, c), clearing @oprsz..@maxsz. */
+void tcg_gen_gvec_2i_var(TCGv_ptr dbase, uint32_t dofs,
+                         TCGv_ptr abase, uint32_t aofs, uint32_t oprsz,
+                         uint32_t maxsz, int64_t c, const GVecGen2i *op);
 /* Similarly, expand (env+dofs) = op(env+aofs, c). */
 void tcg_gen_gvec_2i(uint32_t dofs, uint32_t aofs, uint32_t oprsz,
                      uint32_t maxsz, int64_t c, const GVecGen2i *op);
@@ -315,6 +319,10 @@ void tcg_gen_gvec_sub_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
                           TCGv_ptr abase, uint32_t aofs,
                           TCGv_ptr bbase, uint32_t bofs,
                           uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_mul_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                          TCGv_ptr abase, uint32_t aofs,
+                          TCGv_ptr bbase, uint32_t bofs,
+                          uint32_t oprsz, uint32_t maxsz);
 
 void tcg_gen_gvec_add(unsigned vece, uint32_t dofs, uint32_t aofs,
                       uint32_t bofs, uint32_t oprsz, uint32_t maxsz);
@@ -336,6 +344,23 @@ void tcg_gen_gvec_muls(unsigned vece, uint32_t dofs, uint32_t aofs,
                        TCGv_i64 c, uint32_t oprsz, uint32_t maxsz);
 
 /* Saturated arithmetic.  */
+void tcg_gen_gvec_ssadd_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                            TCGv_ptr abase, uint32_t aofs,
+                            TCGv_ptr bbase, uint32_t bofs,
+                            uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_sssub_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                            TCGv_ptr abase, uint32_t aofs,
+                            TCGv_ptr bbase, uint32_t bofs,
+                            uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_usadd_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                            TCGv_ptr abase, uint32_t aofs,
+                            TCGv_ptr bbase, uint32_t bofs,
+                            uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_ussub_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                            TCGv_ptr abase, uint32_t aofs,
+                            TCGv_ptr bbase, uint32_t bofs,
+                            uint32_t oprsz, uint32_t maxsz);
+
 void tcg_gen_gvec_ssadd(unsigned vece, uint32_t dofs, uint32_t aofs,
                         uint32_t bofs, uint32_t oprsz, uint32_t maxsz);
 void tcg_gen_gvec_sssub(unsigned vece, uint32_t dofs, uint32_t aofs,
@@ -442,8 +467,14 @@ void tcg_gen_gvec_dup_i32_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
 
 void tcg_gen_gvec_shli(unsigned vece, uint32_t dofs, uint32_t aofs,
                        int64_t shift, uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_shri_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                           TCGv_ptr abase, uint32_t aofs,
+                           int64_t shift, uint32_t oprsz, uint32_t maxsz);
 void tcg_gen_gvec_shri(unsigned vece, uint32_t dofs, uint32_t aofs,
                        int64_t shift, uint32_t oprsz, uint32_t maxsz);
+void tcg_gen_gvec_sari_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                           TCGv_ptr abase, uint32_t aofs,
+                           int64_t shift, uint32_t oprsz, uint32_t maxsz);
 void tcg_gen_gvec_sari(unsigned vece, uint32_t dofs, uint32_t aofs,
                        int64_t shift, uint32_t oprsz, uint32_t maxsz);
 void tcg_gen_gvec_rotli(unsigned vece, uint32_t dofs, uint32_t aofs,
tcg/tcg-op-gvec.c +129 -48

352 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#4 lore raw

PATCH v5 4/6 target/hexagon: raise an exception for HVX with SSR:XE clear

In reply to Brian Cain

SSR:XE gates access to the HVX coprocessor: executing an HVX instruction while it is clear must raise a precise exception with cause 0x16, NO_COPROC_ENABLE.

Carry SSR:XE in a TB flag and emit the exception for the first HVX packet of a TB when the coprocessor is disabled.

---
 target/hexagon/cpu.h       |  1 +
 target/hexagon/translate.h |  2 ++
 target/hexagon/cpu.c       |  2 ++
 target/hexagon/translate.c | 11 +++++++++++
 4 files changed, 16 insertions(+)
target/hexagon/cpu.h +1 -0
index b1533680bd7..97f689fda22 100644
@@ -207,6 +207,7 @@ struct ArchCPU {
 FIELD(TB_FLAGS, IS_TIGHT_LOOP, 0, 1)
 FIELD(TB_FLAGS, MMU_INDEX, 1, 3)
 FIELD(TB_FLAGS, PCYCLE_ENABLED, 4, 1)
+FIELD(TB_FLAGS, HVX_COPROC_ENABLED, 5, 1)
 
 G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env,
                                             uint32_t exception,
target/hexagon/translate.h +2 -0
index d8628383f1d..b87a2b20e2f 100644
@@ -89,6 +89,8 @@ typedef struct DisasContext {
     TCGv branch_taken;
     TCGv dczero_addr;
     bool pcycle_enabled;
+    bool hvx_coproc_enabled;
+    bool hvx_check_emitted;
     uint32_t num_cycles;
 } DisasContext;
 
target/hexagon/cpu.c +2 -0
index fad526ccfb5..19486e0f741 100644
@@ -340,6 +340,8 @@ static TCGTBCPUState hexagon_get_tb_cpu_state(CPUState *cs)
     hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, MMU_INDEX,
                            cpu_mmu_index(env_cpu(env), false));
     hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, PCYCLE_ENABLED, 1);
+    hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, HVX_COPROC_ENABLED,
+                           GET_SSR_FIELD(SSR_XE, env->t_sreg[HEX_SREG_SSR]));
 #else
     hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, MMU_INDEX, MMU_USER_IDX);
 #endif
target/hexagon/translate.c +11 -0
index fd1de87405c..0cb3dbe5420 100644
@@ -720,6 +720,14 @@ static void gen_start_packet(DisasContext *ctx)
             i = find_next_bit(ctx->predicated_tmp_vregs, NUM_VREGS, i + 1);
         }
     }
+
+#ifndef CONFIG_USER_ONLY
+    if (ctx->pkt.pkt_has_hvx && !ctx->hvx_coproc_enabled &&
+        !ctx->hvx_check_emitted) {
+        gen_precise_exception(HEX_CAUSE_NO_COPROC_ENABLE, ctx->pkt.pc);
+        ctx->hvx_check_emitted = true;
+    }
+#endif
 }
 
 bool is_gather_store_insn(DisasContext *ctx)
@@ -1239,6 +1247,9 @@ static void hexagon_tr_init_disas_context(DisasContextBase *dcbase,
 #ifndef CONFIG_USER_ONLY
     ctx->num_cycles = 0;
     ctx->pcycle_enabled = FIELD_EX32(hex_flags, TB_FLAGS, PCYCLE_ENABLED);
+    ctx->hvx_coproc_enabled =
+        FIELD_EX32(hex_flags, TB_FLAGS, HVX_COPROC_ENABLED);
+    ctx->hvx_check_emitted = false;
 #endif
 }
 
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH v5 5/6 target/hexagon: share HVX contexts among CPUs

In reply to Brian Cain

The HVX register file belongs to an extension context, not a hardware thread. Model each system-emulation context as a QOM device, link the contexts to each vCPU, and use SSR:XA to select the active context.

Keep one embedded context per linux-user CPU. Carry the selected register-file base with HVX operands so translated code can address the selected context at run time.

---
 include/hw/hexagon/hexagon.h             |   1 +
 include/hw/hexagon/hexagon_hvx_context.h |  27 +
 target/hexagon/cpu.h                     |  25 +-
 target/hexagon/cpu_helper.h              |   1 +
 target/hexagon/gen_tcg_hvx.h             | 608 +++++++++++++----------
 target/hexagon/genptr.h                  |   8 +
 target/hexagon/mmvec/macros.h            |  14 +-
 target/hexagon/translate.h               |  11 +-
 hw/hexagon/hex-subsys.c                  |  36 ++
 hw/hexagon/hexagon_hvx_context.c         |  84 ++++
 target/hexagon/cpu.c                     |  30 +-
 target/hexagon/cpu_helper.c              |  82 +++
 target/hexagon/gdbstub.c                 |  16 +-
 target/hexagon/genptr.c                  | 102 ++--
 target/hexagon/machine.c                 |  12 +
 target/hexagon/op_helper.c               |  37 +-
 target/hexagon/translate.c               |  60 ++-
 hw/hexagon/meson.build                   |   1 +
 target/hexagon/hex_common.py             | 179 ++++---
 19 files changed, 886 insertions(+), 448 deletions(-)
 create mode 100644 include/hw/hexagon/hexagon_hvx_context.h
 create mode 100644 hw/hexagon/hexagon_hvx_context.c
include/hw/hexagon/hexagon.h +1 -0
index 62398eeb359..9b5d33ffc3b 100644
@@ -173,6 +173,7 @@ struct HexagonCommonMachineState {
     DeviceState *qtimer;
     DeviceState *glob_regs;
     DeviceState *tlb;
+    unsigned num_hvx_ctx;
 };
 
 #endif
include/hw/hexagon/hexagon_hvx_context.h new file +27 -0
new file mode 100644
index 00000000000..ab85816a7ff
@@ -0,0 +1,27 @@
+/*
+ * Hexagon HVX Extension Context QOM Object
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HEXAGON_HVX_CONTEXT_H
+#define HEXAGON_HVX_CONTEXT_H
+
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+#include "target/hexagon/cpu.h"
+
+#define TYPE_HEXAGON_HVX_CONTEXT "hexagon-hvx-context"
+OBJECT_DECLARE_SIMPLE_TYPE(HexagonHVXContextState, HEXAGON_HVX_CONTEXT)
+
+struct HexagonHVXContextState {
+    SysBusDevice parent_obj;
+
+    /* Physical context number, as SSR:XA maps to it. */
+    uint32_t index;
+
+    HexagonHVXContext regs;
+};
+
+#endif /* HEXAGON_HVX_CONTEXT_H */
target/hexagon/cpu.h +23 -2
index 97f689fda22..df4c0182247 100644
@@ -29,6 +29,7 @@
 
 typedef struct HexagonTLBState HexagonTLBState;
 typedef struct HexagonGlobalRegState HexagonGlobalRegState;
+typedef struct HexagonHVXContextState HexagonHVXContextState;
 
 #include "cpu-qom.h"
 #include "exec/cpu-common.h"
@@ -49,6 +50,7 @@ typedef struct HexagonGlobalRegState HexagonGlobalRegState;
 #define REG_WRITES_MAX 32
 #define PRED_WRITES_MAX 5                   /* 4 insns + endloop */
 #define VSTORES_MAX 2
+#define HVX_CONTEXTS_MAX 8
 #define MAX_TLB_ENTRIES 1024
 #define THREADS_MAX 16
 
@@ -120,6 +122,11 @@ typedef struct {
 /* Maximum number of vector temps in a packet */
 #define VECTOR_TEMPS_MAX            4
 
+typedef struct HexagonHVXContext {
+    MMVector VRegs[NUM_VREGS];
+    MMQReg QRegs[NUM_QREGS];
+} QEMU_ALIGNED(16) HexagonHVXContext;
+
 typedef struct CPUArchState {
     target_ulong gpr[TOTAL_PER_THREAD_REGS];
     target_ulong pred[NUM_PREGS];
@@ -159,11 +166,15 @@ typedef struct CPUArchState {
     target_ulong llsc_val;
     uint64_t     llsc_val_i64;
 
-    MMVector VRegs[NUM_VREGS] QEMU_ALIGNED(16);
+#ifdef CONFIG_USER_ONLY
+    HexagonHVXContext hvx_ctx;
+#else
+    HexagonHVXContext *hvx;
+#endif
+
     MMVector future_VRegs[VECTOR_TEMPS_MAX] QEMU_ALIGNED(16);
     MMVector tmp_VRegs[VECTOR_TEMPS_MAX] QEMU_ALIGNED(16);
 
-    MMQReg QRegs[NUM_QREGS] QEMU_ALIGNED(16);
     MMQReg future_QRegs[NUM_QREGS] QEMU_ALIGNED(16);
 
     /* Temporaries used within instructions */
@@ -196,6 +207,7 @@ struct ArchCPU {
     CPUHexagonState env;
     HexagonCPUConfig cfg;
 #ifndef CONFIG_USER_ONLY
+    HexagonHVXContextState *hvx_ctx[HVX_CONTEXTS_MAX];
     HexagonTLBState *tlb;
     uint32_t boot_addr;
     HexagonGlobalRegState *globalregs;
@@ -204,6 +216,15 @@ struct ArchCPU {
 #endif
 };
 
+static inline HexagonHVXContext *hex_hvx(CPUHexagonState *env)
+{
+#ifdef CONFIG_USER_ONLY
+    return &env->hvx_ctx;
+#else
+    return env->hvx;
+#endif
+}
+
 FIELD(TB_FLAGS, IS_TIGHT_LOOP, 0, 1)
 FIELD(TB_FLAGS, MMU_INDEX, 1, 3)
 FIELD(TB_FLAGS, PCYCLE_ENABLED, 4, 1)
target/hexagon/cpu_helper.h +1 -0
index 12512efd74f..afb4df59f80 100644
@@ -15,6 +15,7 @@ void hexagon_peek_memory_range(CPUHexagonState *env, uint32_t start_addr,
                                uint32_t length, uintptr_t retaddr);
 uint32_t hexagon_get_pmu_counter(CPUHexagonState *cur_env, int index);
 void hexagon_modify_ssr(CPUHexagonState *env, uint32_t new, uint32_t old);
+unsigned hexagon_hvx_select_context(CPUHexagonState *env, uint32_t ssr);
 int get_cpu_mode(const CPUHexagonState *env);
 int get_exe_mode(const CPUHexagonState *env);
 void clear_wait_mode(CPUHexagonState *env);
target/hexagon/gen_tcg_hvx.h +338 -270

1,072 lines not on this page · raw message

target/hexagon/genptr.h +8 -0
index f498398367c..238ee089cba 100644
@@ -59,6 +59,14 @@ TCGv gen_get_half(TCGv result, int N, TCGv src, bool sign);
 void gen_set_half(int N, TCGv result, TCGv src);
 void gen_set_half_i64(int N, TCGv_i64 result, TCGv src);
 void probe_noshuf_load(TCGv va, int s, int mi);
+void gen_gvec_sabsdiff_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                           TCGv_ptr abase, uint32_t aofs,
+                           TCGv_ptr bbase, uint32_t bofs,
+                           uint32_t oprsz, uint32_t maxsz);
+void gen_gvec_uabsdiff_var(unsigned vece, TCGv_ptr dbase, uint32_t dofs,
+                           TCGv_ptr abase, uint32_t aofs,
+                           TCGv_ptr bbase, uint32_t bofs,
+                           uint32_t oprsz, uint32_t maxsz);
 void gen_gvec_sabsdiff(unsigned vece, uint32_t dofs, uint32_t aofs,
                        uint32_t bofs, uint32_t oprsz, uint32_t maxsz);
 void gen_gvec_uabsdiff(unsigned vece, uint32_t dofs, uint32_t aofs,
target/hexagon/mmvec/macros.h +8 -6
index b36f833b1de..df695d0731c 100644
@@ -286,26 +286,28 @@
         fV_AL_CHECK(EA, fVECSIZE() - 1); \
     } while (0)
 #ifdef QEMU_GENERATE
-#define fLOADMMV(EA, DST) gen_vreg_load(ctx, DST##_off, EA, true)
+#define fLOADMMV(EA, DST) gen_vreg_load(ctx, DST##_base, DST##_off, EA, true)
 #endif
 #ifdef QEMU_GENERATE
-#define fLOADMMVU(EA, DST) gen_vreg_load(ctx, DST##_off, EA, false)
+#define fLOADMMVU(EA, DST) gen_vreg_load(ctx, DST##_base, DST##_off, EA, false)
 #endif
 #ifdef QEMU_GENERATE
 #define fSTOREMMV(EA, SRC) \
-    gen_vreg_store(ctx, EA, SRC##_off, insn->slot, true)
+    gen_vreg_store(ctx, EA, SRC##_base, SRC##_off, insn->slot, true)
 #endif
 #ifdef QEMU_GENERATE
 #define fSTOREMMVQ(EA, SRC, MASK) \
-    gen_vreg_masked_store(ctx, EA, SRC##_off, MASK##_off, insn->slot, false)
+    gen_vreg_masked_store(ctx, EA, SRC##_base, SRC##_off, \
+                          MASK##_base, MASK##_off, insn->slot, false)
 #endif
 #ifdef QEMU_GENERATE
 #define fSTOREMMVNQ(EA, SRC, MASK) \
-    gen_vreg_masked_store(ctx, EA, SRC##_off, MASK##_off, insn->slot, true)
+    gen_vreg_masked_store(ctx, EA, SRC##_base, SRC##_off, \
+                          MASK##_base, MASK##_off, insn->slot, true)
 #endif
 #ifdef QEMU_GENERATE
 #define fSTOREMMVU(EA, SRC) \
-    gen_vreg_store(ctx, EA, SRC##_off, insn->slot, false)
+    gen_vreg_store(ctx, EA, SRC##_base, SRC##_off, insn->slot, false)
 #endif
 #define fVFOREACH(WIDTH, VAR) for (VAR = 0; VAR < fVELEM(WIDTH); VAR++)
 #define fVARRAY_ELEMENT_ACCESS(ARRAY, TYPE, INDEX) \
target/hexagon/translate.h +9 -2
index b87a2b20e2f..78c1951b70e 100644
@@ -192,9 +192,9 @@ static inline void ctx_log_reg_read_pair(DisasContext *ctx, int rnum)
 }
 
 intptr_t ctx_future_vreg_off(DisasContext *ctx, int regnum,
-                             int num, bool alloc_ok);
+                             int num, bool alloc_ok, TCGv_ptr *base);
 intptr_t ctx_tmp_vreg_off(DisasContext *ctx, int regnum,
-                          int num, bool alloc_ok);
+                          int num, bool alloc_ok, TCGv_ptr *base);
 
 static inline void ctx_start_hvx_insn(DisasContext *ctx)
 {
@@ -328,6 +328,13 @@ extern TCGv_i64 hex_llsc_val_i64;
 extern TCGv hex_vstore_addr[VSTORES_MAX];
 extern TCGv hex_vstore_size[VSTORES_MAX];
 extern TCGv hex_vstore_pending[VSTORES_MAX];
+#ifdef CONFIG_USER_ONLY
+#define hex_hvx_ptr tcg_env
+#define HEX_HVX_OFFSET(member) offsetof(CPUHexagonState, hvx_ctx.member)
+#else
+extern TCGv_ptr hex_hvx_ptr;
+#define HEX_HVX_OFFSET(member) offsetof(HexagonHVXContext, member)
+#endif
 #ifndef CONFIG_USER_ONLY
 extern TCGv_i32 hex_greg[NUM_GREGS];
 extern TCGv_i32 hex_t_sreg[NUM_SREGS];
hw/hexagon/hex-subsys.c +36 -0
index 4e3a418340e..0efcb40d8a3 100644
@@ -7,8 +7,10 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qemu/error-report.h"
 #include "hw/hexagon/hex-subsys.h"
 #include "hw/hexagon/hexagon_globalreg.h"
+#include "hw/hexagon/hexagon_hvx_context.h"
 #include "hw/hexagon/hexagon_tlb.h"
 #include "hw/intc/hex-l2vic.h"
 #include "hw/timer/qct-qtimer.h"
@@ -98,6 +100,33 @@ static DeviceState *tlb_create(HexagonCommonMachineState *hms,
     return tlb;
 }
 
+/*
+ * Create the core's HVX extension contexts.  There are fewer of them than
+ * there are hardware threads, and SSR:XA picks which one a thread uses, so
+ * they belong to the subsystem rather than to any one CPU.
+ */
+static void hvx_contexts_create(HexagonCommonMachineState *hms,
+                                const struct hexagon_machine_config *m_cfg)
+{
+    unsigned n = m_cfg->cfgtable.ext_contexts;
+    unsigned i;
+
+    if (n > HVX_CONTEXTS_MAX) {
+        error_report("machine declares %u HVX contexts, only %u are usable",
+                     n, HVX_CONTEXTS_MAX);
+        exit(1);
+    }
+    for (i = 0; i < n; i++) {
+        DeviceState *ctx = qdev_new(TYPE_HEXAGON_HVX_CONTEXT);
+        g_autofree char *name = g_strdup_printf("hvx-context[%u]", i);
+
+        object_property_add_child(OBJECT(hms), name, OBJECT(ctx));
+        qdev_prop_set_uint32(ctx, "index", i);
+        sysbus_realize_and_unref(SYS_BUS_DEVICE(ctx), &error_fatal);
+    }
+    hms->num_hvx_ctx = n;
+}
+
 static DeviceState *cluster_create(HexagonCommonMachineState *hms)
 {
     DeviceState *cluster = qdev_new(TYPE_CPU_CLUSTER);
@@ -140,6 +169,7 @@ void hex_subsys_create(HexagonCommonMachineState *hms,
     hms->qtimer = qtimer_create(hms, m_cfg);
     hms->glob_regs = globalreg_create(hms, m_cfg, rev);
     hms->tlb = tlb_create(hms, m_cfg);
+    hvx_contexts_create(hms, m_cfg);
 }
 
 void hex_subsys_add_cpu(HexagonCommonMachineState *hms, DeviceState *cpu)
@@ -151,6 +181,12 @@ void hex_subsys_add_cpu(HexagonCommonMachineState *hms, DeviceState *cpu)
                              &error_fatal);
     object_property_set_link(OBJECT(cpu), "l2vic", OBJECT(hms->l2vic),
                              &error_fatal);
+    for (unsigned i = 0; i < hms->num_hvx_ctx; i++) {
+        g_autofree char *name = g_strdup_printf("hvx-context[%u]", i);
+        Object *ctx = object_resolve_path_component(OBJECT(hms), name);
+
+        object_property_set_link(OBJECT(cpu), name, ctx, &error_fatal);
+    }
 }
 
 void hex_subsys_realize_cluster(HexagonCommonMachineState *hms)
hw/hexagon/hexagon_hvx_context.c new file +84 -0

84 lines not on this page · raw message

target/hexagon/cpu.c +24 -6
index 19486e0f741..6acd472cd88 100644
@@ -43,6 +43,7 @@
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
 #include "hw/hexagon/hexagon_globalreg.h"
+#include "hw/hexagon/hexagon_hvx_context.h"
 #endif
 
 static ObjectClass *hexagon_cpu_class_by_name(const char *cpu_model)
@@ -191,7 +192,7 @@ static void print_vreg(FILE *f, CPUHexagonState *env, int regnum,
     if (skip_if_zero) {
         bool nonzero_found = false;
         for (int i = 0; i < MAX_VEC_SIZE_BYTES; i++) {
-            if (env->VRegs[regnum].ub[i] != 0) {
+            if (hex_hvx(env)->VRegs[regnum].ub[i] != 0) {
                 nonzero_found = true;
                 break;
             }
@@ -202,9 +203,10 @@ static void print_vreg(FILE *f, CPUHexagonState *env, int regnum,
     }
 
     qemu_fprintf(f, "  v%d = ( ", regnum);
-    qemu_fprintf(f, "0x%02x", env->VRegs[regnum].ub[MAX_VEC_SIZE_BYTES - 1]);
+    qemu_fprintf(f, "0x%02x",
+                 hex_hvx(env)->VRegs[regnum].ub[MAX_VEC_SIZE_BYTES - 1]);
     for (int i = MAX_VEC_SIZE_BYTES - 2; i >= 0; i--) {
-        qemu_fprintf(f, ", 0x%02x", env->VRegs[regnum].ub[i]);
+        qemu_fprintf(f, ", 0x%02x", hex_hvx(env)->VRegs[regnum].ub[i]);
     }
     qemu_fprintf(f, " )\n");
 }
@@ -220,7 +222,7 @@ static void print_qreg(FILE *f, CPUHexagonState *env, int regnum,
     if (skip_if_zero) {
         bool nonzero_found = false;
         for (int i = 0; i < MAX_VEC_SIZE_BYTES / 8; i++) {
-            if (env->QRegs[regnum].ub[i] != 0) {
+            if (hex_hvx(env)->QRegs[regnum].ub[i] != 0) {
                 nonzero_found = true;
                 break;
             }
@@ -232,9 +234,9 @@ static void print_qreg(FILE *f, CPUHexagonState *env, int regnum,
 
     qemu_fprintf(f, "  q%d = ( ", regnum);
     qemu_fprintf(f, "0x%02x",
-                 env->QRegs[regnum].ub[MAX_VEC_SIZE_BYTES / 8 - 1]);
+                 hex_hvx(env)->QRegs[regnum].ub[MAX_VEC_SIZE_BYTES / 8 - 1]);
     for (int i = MAX_VEC_SIZE_BYTES / 8 - 2; i >= 0; i--) {
-        qemu_fprintf(f, ", 0x%02x", env->QRegs[regnum].ub[i]);
+        qemu_fprintf(f, ", 0x%02x", hex_hvx(env)->QRegs[regnum].ub[i]);
     }
     qemu_fprintf(f, " )\n");
 }
@@ -327,6 +329,9 @@ static TCGTBCPUState hexagon_get_tb_cpu_state(CPUState *cs)
     CPUHexagonState *env = cpu_env(cs);
     vaddr pc = env->gpr[HEX_REG_PC];
     uint32_t hex_flags = 0;
+#ifndef CONFIG_USER_ONLY
+    HexagonCPU *cpu;
+#endif
 
     if (pc == env->gpr[HEX_REG_SA0]) {
         hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, IS_TIGHT_LOOP, 1);
@@ -337,10 +342,12 @@ static TCGTBCPUState hexagon_get_tb_cpu_state(CPUState *cs)
     }
 
 #ifndef CONFIG_USER_ONLY
+    cpu = env_archcpu(env);
     hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, MMU_INDEX,
                            cpu_mmu_index(env_cpu(env), false));
     hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, PCYCLE_ENABLED, 1);
     hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, HVX_COPROC_ENABLED,
+                           cpu->hvx_ctx[0] &&
                            GET_SSR_FIELD(SSR_XE, env->t_sreg[HEX_SREG_SSR]));
 #else
     hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, MMU_INDEX, MMU_USER_IDX);
@@ -448,6 +455,7 @@ static void hexagon_cpu_reset_hold(Object *obj, ResetType type)
     env->t_sreg[HEX_SREG_HTID] = cpu->htid;
     env->threadId = cpu->htid;
     hexagon_cpu_soft_reset(env);
+    hexagon_hvx_select_context(env, env->t_sreg[HEX_SREG_SSR]);
     env->cause_code = HEX_EVENT_NONE;
     env->gpr[HEX_REG_PC] = cpu->boot_addr;
 #endif
@@ -553,7 +561,17 @@ static void hexagon_cpu_init(Object *obj)
 {
 #ifndef CONFIG_USER_ONLY
     HexagonCPU *cpu = HEXAGON_CPU(obj);
+    int i;
+
     qdev_init_gpio_in(DEVICE(cpu), hexagon_cpu_set_irq, 8);
+
+    for (i = 0; i < HVX_CONTEXTS_MAX; i++) {
+        object_property_add_link(obj, "hvx-context[*]",
+                                 TYPE_HEXAGON_HVX_CONTEXT,
+                                 (Object **)&cpu->hvx_ctx[i],
+                                 qdev_prop_allow_set_link_before_realize,
+                                 OBJ_PROP_LINK_STRONG);
+    }
 #endif
 }
 
target/hexagon/cpu_helper.c +82 -0

100 lines not on this page · raw message

target/hexagon/gdbstub.c +8 -8
index b9856cfc978..76ab5235f6e 100644
@@ -80,8 +80,8 @@ static int gdb_get_vreg(CPUHexagonState *env, GByteArray *mem_buf, int n)
 {
     int total = 0;
     int i;
-    for (i = 0; i < ARRAY_SIZE(env->VRegs[n].uw); i++) {
-        total += gdb_get_reg32(mem_buf, env->VRegs[n].uw[i]);
+    for (i = 0; i < ARRAY_SIZE(hex_hvx(env)->VRegs[n].uw); i++) {
+        total += gdb_get_reg32(mem_buf, hex_hvx(env)->VRegs[n].uw[i]);
     }
     return total;
 }
@@ -90,8 +90,8 @@ static int gdb_get_qreg(CPUHexagonState *env, GByteArray *mem_buf, int n)
 {
     int total = 0;
     int i;
-    for (i = 0; i < ARRAY_SIZE(env->QRegs[n].uw); i++) {
-        total += gdb_get_reg32(mem_buf, env->QRegs[n].uw[i]);
+    for (i = 0; i < ARRAY_SIZE(hex_hvx(env)->QRegs[n].uw); i++) {
+        total += gdb_get_reg32(mem_buf, hex_hvx(env)->QRegs[n].uw[i]);
     }
     return total;
 }
@@ -116,8 +116,8 @@ int hexagon_hvx_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
 static int gdb_put_vreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
 {
     int i;
-    for (i = 0; i < ARRAY_SIZE(env->VRegs[n].uw); i++) {
-        env->VRegs[n].uw[i] = ldl_le_p(mem_buf);
+    for (i = 0; i < ARRAY_SIZE(hex_hvx(env)->VRegs[n].uw); i++) {
+        hex_hvx(env)->VRegs[n].uw[i] = ldl_le_p(mem_buf);
         mem_buf += 4;
     }
     return MAX_VEC_SIZE_BYTES;
@@ -126,8 +126,8 @@ static int gdb_put_vreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
 static int gdb_put_qreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
 {
     int i;
-    for (i = 0; i < ARRAY_SIZE(env->QRegs[n].uw); i++) {
-        env->QRegs[n].uw[i] = ldl_le_p(mem_buf);
+    for (i = 0; i < ARRAY_SIZE(hex_hvx(env)->QRegs[n].uw); i++) {
+        hex_hvx(env)->QRegs[n].uw[i] = ldl_le_p(mem_buf);
         mem_buf += 4;
     }
     return MAX_VEC_SIZE_BYTES / 8;
target/hexagon/genptr.c +65 -37

204 lines not on this page · raw message

target/hexagon/machine.c +12 -0
index bf4646f4a8b..179b6f53a2a 100644
@@ -7,11 +7,23 @@
 #include "qemu/osdep.h"
 #include "migration/vmstate.h"
 #include "cpu.h"
+#include "cpu_helper.h"
+
+static int hexagon_cpu_post_load(void *opaque, int version_id)
+{
+    HexagonCPU *cpu = opaque;
+    CPUHexagonState *env = &cpu->env;
+
+    hexagon_hvx_select_context(env, env->t_sreg[HEX_SREG_SSR]);
+
+    return 0;
+}
 
 const VMStateDescription vmstate_hexagon_cpu = {
     .name = "cpu",
     .version_id = 2,
     .minimum_version_id = 2,
+    .post_load = hexagon_cpu_post_load,
     .fields = (const VMStateField[]) {
         VMSTATE_UINT32_ARRAY(env.gpr, HexagonCPU, TOTAL_PER_THREAD_REGS),
         VMSTATE_UINT32_ARRAY(env.pred, HexagonCPU, NUM_PREGS),
target/hexagon/op_helper.c +19 -18
index 0d08ac77361..47c7953b92e 100644
@@ -1408,7 +1408,8 @@ void HELPER(vhist)(CPUHexagonState *env)
             unsigned char regno = value >> 3;
             unsigned char element = value & 7;
 
-            env->VRegs[regno].uh[(sizeof(MMVector) / 16) * lane + element]++;
+            hex_hvx(env)->VRegs[regno]
+                .uh[(sizeof(MMVector) / 16) * lane + element]++;
         }
     }
 }
@@ -1424,7 +1425,7 @@ void HELPER(vhistq)(CPUHexagonState *env)
             unsigned char element = value & 7;
 
             if (fGETQBIT(env->qtmp, sizeof(MMVector) / 8 * lane + i)) {
-                env->VRegs[regno].uh[
+                hex_hvx(env)->VRegs[regno].uh[
                     (sizeof(MMVector) / 16) * lane + element]++;
             }
         }
@@ -1441,8 +1442,8 @@ void HELPER(vwhist256)(CPUHexagonState *env)
         unsigned int vindex = (bucket >> 3) & 0x1F;
         unsigned int elindex = ((i >> 0) & (~7)) | ((bucket >> 0) & 7);
 
-        env->VRegs[vindex].uh[elindex] =
-            env->VRegs[vindex].uh[elindex] + weight;
+        hex_hvx(env)->VRegs[vindex].uh[elindex] =
+            hex_hvx(env)->VRegs[vindex].uh[elindex] + weight;
     }
 }
 
@@ -1457,8 +1458,8 @@ void HELPER(vwhist256q)(CPUHexagonState *env)
         unsigned int elindex = ((i >> 0) & (~7)) | ((bucket >> 0) & 7);
 
         if (fGETQBIT(env->qtmp, 2 * i)) {
-            env->VRegs[vindex].uh[elindex] =
-                env->VRegs[vindex].uh[elindex] + weight;
+            hex_hvx(env)->VRegs[vindex].uh[elindex] =
+                hex_hvx(env)->VRegs[vindex].uh[elindex] + weight;
         }
     }
 }
@@ -1473,8 +1474,8 @@ void HELPER(vwhist256_sat)(CPUHexagonState *env)
         unsigned int vindex = (bucket >> 3) & 0x1F;
         unsigned int elindex = ((i >> 0) & (~7)) | ((bucket >> 0) & 7);
 
-        env->VRegs[vindex].uh[elindex] =
-            fVSATUH(env->VRegs[vindex].uh[elindex] + weight);
+        hex_hvx(env)->VRegs[vindex].uh[elindex] =
+            fVSATUH(hex_hvx(env)->VRegs[vindex].uh[elindex] + weight);
     }
 }
 
@@ -1489,8 +1490,8 @@ void HELPER(vwhist256q_sat)(CPUHexagonState *env)
         unsigned int elindex = ((i >> 0) & (~7)) | ((bucket >> 0) & 7);
 
         if (fGETQBIT(env->qtmp, 2 * i)) {
-            env->VRegs[vindex].uh[elindex] =
-                fVSATUH(env->VRegs[vindex].uh[elindex] + weight);
+            hex_hvx(env)->VRegs[vindex].uh[elindex] =
+                fVSATUH(hex_hvx(env)->VRegs[vindex].uh[elindex] + weight);
         }
     }
 }
@@ -1505,8 +1506,8 @@ void HELPER(vwhist128)(CPUHexagonState *env)
         unsigned int vindex = (bucket >> 3) & 0x1F;
         unsigned int elindex = ((i >> 1) & (~3)) | ((bucket >> 1) & 3);
 
-        env->VRegs[vindex].uw[elindex] =
-            env->VRegs[vindex].uw[elindex] + weight;
+        hex_hvx(env)->VRegs[vindex].uw[elindex] =
+            hex_hvx(env)->VRegs[vindex].uw[elindex] + weight;
     }
 }
 
@@ -1521,8 +1522,8 @@ void HELPER(vwhist128q)(CPUHexagonState *env)
         unsigned int elindex = ((i >> 1) & (~3)) | ((bucket >> 1) & 3);
 
         if (fGETQBIT(env->qtmp, 2 * i)) {
-            env->VRegs[vindex].uw[elindex] =
-                env->VRegs[vindex].uw[elindex] + weight;
+            hex_hvx(env)->VRegs[vindex].uw[elindex] =
+                hex_hvx(env)->VRegs[vindex].uw[elindex] + weight;
         }
     }
 }
@@ -1538,8 +1539,8 @@ void HELPER(vwhist128m)(CPUHexagonState *env, int32_t uiV)
         unsigned int elindex = ((i >> 1) & (~3)) | ((bucket >> 1) & 3);
 
         if ((bucket & 1) == uiV) {
-            env->VRegs[vindex].uw[elindex] =
-                env->VRegs[vindex].uw[elindex] + weight;
+            hex_hvx(env)->VRegs[vindex].uw[elindex] =
+                hex_hvx(env)->VRegs[vindex].uw[elindex] + weight;
         }
     }
 }
@@ -1555,8 +1556,8 @@ void HELPER(vwhist128qm)(CPUHexagonState *env, int32_t uiV)
         unsigned int elindex = ((i >> 1) & (~3)) | ((bucket >> 1) & 3);
 
         if (((bucket & 1) == uiV) && fGETQBIT(env->qtmp, 2 * i)) {
-            env->VRegs[vindex].uw[elindex] =
-                env->VRegs[vindex].uw[elindex] + weight;
+            hex_hvx(env)->VRegs[vindex].uw[elindex] =
+                hex_hvx(env)->VRegs[vindex].uw[elindex] + weight;
         }
     }
 }
target/hexagon/translate.c +38 -22

131 lines not on this page · raw message

hw/hexagon/meson.build +1 -0
index 720a5d54dcc..c4b257dfa28 100644
@@ -1,6 +1,7 @@
 hexagon_ss = ss.source_set()
 hexagon_ss.add(files('hexagon_tlb.c'))
 hexagon_ss.add(files('hexagon_globalreg.c'))
+hexagon_ss.add(files('hexagon_hvx_context.c'))
 hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hex-subsys.c'))
 hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hexagon_dsp.c'))
 hexagon_ss.add(when: 'CONFIG_HEX_VIRT', if_true: files('virt.c'))
target/hexagon/hex_common.py +102 -77

302 lines not on this page · raw message

Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH v5 5/6] target/hexagon: share HVX contexts among CPUs

Hi,

Quoted 48 lines · Brian Cain

The HVX register file belongs to an extension context, not a hardware thread. Model each system-emulation context as a QOM device, link the contexts to each vCPU, and use SSR:XA to select the active context.

Keep one embedded context per linux-user CPU. Carry the selected register-file base with HVX operands so translated code can address the selected context at run time.

---
  include/hw/hexagon/hexagon.h             |   1 +
  include/hw/hexagon/hexagon_hvx_context.h |  27 +
  target/hexagon/cpu.h                     |  25 +-
  target/hexagon/cpu_helper.h              |   1 +
  target/hexagon/gen_tcg_hvx.h             | 608 +++++++++++++----------
  target/hexagon/genptr.h                  |   8 +
  target/hexagon/mmvec/macros.h            |  14 +-
  target/hexagon/translate.h               |  11 +-
  hw/hexagon/hex-subsys.c                  |  36 ++
  hw/hexagon/hexagon_hvx_context.c         |  84 ++++
  target/hexagon/cpu.c                     |  30 +-
  target/hexagon/cpu_helper.c              |  82 +++
  target/hexagon/gdbstub.c                 |  16 +-
  target/hexagon/genptr.c                  | 102 ++--
  target/hexagon/machine.c                 |  12 +
  target/hexagon/op_helper.c               |  37 +-
  target/hexagon/translate.c               |  60 ++-
  hw/hexagon/meson.build                   |   1 +
  target/hexagon/hex_common.py             | 179 ++++---
  19 files changed, 886 insertions(+), 448 deletions(-)

create mode 100644 include/hw/hexagon/hexagon_hvx_context.h create mode 100644 hw/hexagon/hexagon_hvx_context.c

target/hexagon/cpu.h +1 -0
index 97f689fda22..df4c0182247 100644
@@ -29,6 +29,7 @@
 
  typedef struct HexagonTLBState HexagonTLBState;
  typedef struct HexagonGlobalRegState HexagonGlobalRegState;
+typedef struct HexagonHVXContextState HexagonHVXContextState;
 
  #include "cpu-qom.h"
  #include "exec/cpu-common.h"

target/hexagon/cpu.h typedef struct HexagonGlobalRegState HexagonGlobalRegState; · line 52

Quoted 3 lines
target/hexagon/cpu.h +0 -0
@@ -49,6 +50,7 @@ typedef struct HexagonGlobalRegState HexagonGlobalRegState;
  #define REG_WRITES_MAX 32
  #define PRED_WRITES_MAX 5                   /* 4 insns + endloop */
  #define VSTORES_MAX 2

Could this simplify #ifdef'ry maintenance in source?

  #ifdef CONFIG_USER_ONLY
  #define HVX_CONTEXTS_MAX 1
  #else

target/hexagon/cpu.h typedef struct HexagonGlobalRegState HexagonGlobalRegState; · line 53

Quoted 1 line
target/hexagon/cpu.h +1 -0
+#define HVX_CONTEXTS_MAX 8
  #endif
Quoted 53 lines
target/hexagon/cpu.h +20 -2
  #define MAX_TLB_ENTRIES 1024
  #define THREADS_MAX 16
 
@@ -120,6 +122,11 @@ typedef struct {
  /* Maximum number of vector temps in a packet */
  #define VECTOR_TEMPS_MAX            4
 
+typedef struct HexagonHVXContext {
+    MMVector VRegs[NUM_VREGS];
+    MMQReg QRegs[NUM_QREGS];
+} QEMU_ALIGNED(16) HexagonHVXContext;
+
  typedef struct CPUArchState {
      target_ulong gpr[TOTAL_PER_THREAD_REGS];
      target_ulong pred[NUM_PREGS];
@@ -159,11 +166,15 @@ typedef struct CPUArchState {
      target_ulong llsc_val;
      uint64_t     llsc_val_i64;
 
-    MMVector VRegs[NUM_VREGS] QEMU_ALIGNED(16);
+#ifdef CONFIG_USER_ONLY
+    HexagonHVXContext hvx_ctx;
+#else
+    HexagonHVXContext *hvx;
+#endif
+
      MMVector future_VRegs[VECTOR_TEMPS_MAX] QEMU_ALIGNED(16);
      MMVector tmp_VRegs[VECTOR_TEMPS_MAX] QEMU_ALIGNED(16);
 
-    MMQReg QRegs[NUM_QREGS] QEMU_ALIGNED(16);
      MMQReg future_QRegs[NUM_QREGS] QEMU_ALIGNED(16);
 
      /* Temporaries used within instructions */
@@ -196,6 +207,7 @@ struct ArchCPU {
      CPUHexagonState env;
      HexagonCPUConfig cfg;
  #ifndef CONFIG_USER_ONLY
+    HexagonHVXContextState *hvx_ctx[HVX_CONTEXTS_MAX];
      HexagonTLBState *tlb;
      uint32_t boot_addr;
      HexagonGlobalRegState *globalregs;
@@ -204,6 +216,15 @@ struct ArchCPU {
  #endif
  };
 
+static inline HexagonHVXContext *hex_hvx(CPUHexagonState *env)
+{
+#ifdef CONFIG_USER_ONLY
+    return &env->hvx_ctx;
+#else
+    return env->hvx;
+#endif
+}
author
#7 lore raw

Re: [PATCH v5 5/6] target/hexagon: share HVX contexts among CPUs

Quoted 56 lines · Philippe Mathieu-Daudé

Hi,

Quoted 46 lines · Brian Cain

The HVX register file belongs to an extension context, not a hardware thread. Model each system-emulation context as a QOM device, link the contexts to each vCPU, and use SSR:XA to select the active context.

Keep one embedded context per linux-user CPU.  Carry the selected register-file base with HVX operands so translated code can address the selected context at run time.

---
  include/hw/hexagon/hexagon.h             |   1 + include/hw/hexagon/hexagon_hvx_context.h |  27 + target/hexagon/cpu.h                     |  25 +- target/hexagon/cpu_helper.h              |   1 + target/hexagon/gen_tcg_hvx.h             | 608 +++++++++++++---------- target/hexagon/genptr.h                  |   8 + target/hexagon/mmvec/macros.h            |  14 +- target/hexagon/translate.h               |  11 +- hw/hexagon/hex-subsys.c                  |  36 ++ hw/hexagon/hexagon_hvx_context.c         |  84 ++++ target/hexagon/cpu.c                     |  30 +- target/hexagon/cpu_helper.c              |  82 +++ target/hexagon/gdbstub.c                 |  16 +- target/hexagon/genptr.c                  | 102 ++-- target/hexagon/machine.c                 |  12 + target/hexagon/op_helper.c               |  37 +- target/hexagon/translate.c               |  60 ++- hw/hexagon/meson.build                   |   1 + target/hexagon/hex_common.py             | 179 ++++---

  19 files changed, 886 insertions(+), 448 deletions(-)

  create mode 100644 include/hw/hexagon/hexagon_hvx_context.h create mode 100644 hw/hexagon/hexagon_hvx_context.c

target/hexagon/cpu.h +1 -0
index 97f689fda22..df4c0182247 100644
@@ -29,6 +29,7 @@
     typedef struct HexagonTLBState HexagonTLBState;
   typedef struct HexagonGlobalRegState HexagonGlobalRegState;
+typedef struct HexagonHVXContextState HexagonHVXContextState;
     #include "cpu-qom.h"
   #include "exec/cpu-common.h"

target/hexagon/cpu.h typedef struct HexagonGlobalRegState · line 53

Quoted 4 lines
target/hexagon/cpu.h +0 -0
@@ -49,6 +50,7 @@ typedef struct HexagonGlobalRegState 
 HexagonGlobalRegState;
   #define REG_WRITES_MAX 32
   #define PRED_WRITES_MAX 5                   /* 4 insns + endloop */
   #define VSTORES_MAX 2

Could this simplify #ifdef'ry maintenance in source?

Quoted 8 lines

  #ifdef CONFIG_USER_ONLY
  #define HVX_CONTEXTS_MAX 1
  #else

target/hexagon/cpu.h typedef struct HexagonGlobalRegState HexagonGlobalRegState; · line 53

Quoted 1 line
target/hexagon/cpu.h +1 -0
+#define HVX_CONTEXTS_MAX 8

  #endif

Okay, good idea - I'll give it a go.

Quoted 48 lines
Quoted 47 lines
target/hexagon/cpu.h +0 -0
   #define MAX_TLB_ENTRIES 1024
   #define THREADS_MAX 16

  @@ -120,6 +122,11 @@ typedef struct {
  /* Maximum number of vector temps in a packet */ #define VECTOR_TEMPS_MAX            4 +typedef struct HexagonHVXContext {
+    MMVector VRegs[NUM_VREGS];
+    MMQReg QRegs[NUM_QREGS];

target/hexagon/cpu.h +2 -0
+} QEMU_ALIGNED(16) HexagonHVXContext;
+

  typedef struct CPUArchState {
      target_ulong gpr[TOTAL_PER_THREAD_REGS];
      target_ulong pred[NUM_PREGS];

target/hexagon/cpu.h +14 -0
@@ -159,11 +166,15 @@ typedef struct CPUArchState {
       target_ulong llsc_val;
       uint64_t     llsc_val_i64;
   -    MMVector VRegs[NUM_VREGS] QEMU_ALIGNED(16);
+#ifdef CONFIG_USER_ONLY
+    HexagonHVXContext hvx_ctx;
+#else
+    HexagonHVXContext *hvx;
+#endif
+
       MMVector future_VRegs[VECTOR_TEMPS_MAX] QEMU_ALIGNED(16);
       MMVector tmp_VRegs[VECTOR_TEMPS_MAX] QEMU_ALIGNED(16);
   -    MMQReg QRegs[NUM_QREGS] QEMU_ALIGNED(16);
       MMQReg future_QRegs[NUM_QREGS] QEMU_ALIGNED(16);
         /* Temporaries used within instructions */
@@ -196,6 +207,7 @@ struct ArchCPU {
       CPUHexagonState env;
       HexagonCPUConfig cfg;
   #ifndef CONFIG_USER_ONLY
+    HexagonHVXContextState *hvx_ctx[HVX_CONTEXTS_MAX];
       HexagonTLBState *tlb;
       uint32_t boot_addr;
       HexagonGlobalRegState *globalregs;
@@ -204,6 +216,15 @@ struct ArchCPU {
   #endif
   };
   +static inline HexagonHVXContext *hex_hvx(CPUHexagonState *env)
+{
+#ifdef CONFIG_USER_ONLY
+    return &env->hvx_ctx;
+#else
+    return env->hvx;
+#endif
+}
author
#8 lore raw

Re: [PATCH v5 5/6] target/hexagon: share HVX contexts among CPUs

Quoted 63 lines · Brian Cain
Quoted 61 lines · Philippe Mathieu-Daudé

Hi,

Quoted 47 lines · Brian Cain

The HVX register file belongs to an extension context, not a hardware thread. Model each system-emulation context as a QOM device, link the contexts to each vCPU, and use SSR:XA to select the active context.

Keep one embedded context per linux-user CPU.  Carry the selected register-file base with HVX operands so translated code can address the selected context at run time.

---
  include/hw/hexagon/hexagon.h             |   1 + include/hw/hexagon/hexagon_hvx_context.h |  27 + target/hexagon/cpu.h                     |  25 +- target/hexagon/cpu_helper.h              |   1 + target/hexagon/gen_tcg_hvx.h             | 608
+++++++++++++----------
  target/hexagon/genptr.h                  |   8 + target/hexagon/mmvec/macros.h            |  14 +- target/hexagon/translate.h               |  11 +- hw/hexagon/hex-subsys.c                  |  36 ++ hw/hexagon/hexagon_hvx_context.c         |  84 ++++ target/hexagon/cpu.c                     |  30 +- target/hexagon/cpu_helper.c              |  82 +++ target/hexagon/gdbstub.c                 |  16 +- target/hexagon/genptr.c                  | 102 ++-- target/hexagon/machine.c                 |  12 + target/hexagon/op_helper.c               |  37 +- target/hexagon/translate.c               |  60 ++- hw/hexagon/meson.build                   |   1 + target/hexagon/hex_common.py             | 179 ++++---

  19 files changed, 886 insertions(+), 448 deletions(-)

  create mode 100644 include/hw/hexagon/hexagon_hvx_context.h create mode 100644 hw/hexagon/hexagon_hvx_context.c

target/hexagon/cpu.h +1 -0
index 97f689fda22..df4c0182247 100644
@@ -29,6 +29,7 @@
     typedef struct HexagonTLBState HexagonTLBState;
   typedef struct HexagonGlobalRegState HexagonGlobalRegState;
+typedef struct HexagonHVXContextState HexagonHVXContextState;
     #include "cpu-qom.h"
   #include "exec/cpu-common.h"

target/hexagon/cpu.h typedef struct HexagonGlobalRegState · line 53

Quoted 4 lines
target/hexagon/cpu.h +0 -0
@@ -49,6 +50,7 @@ typedef struct HexagonGlobalRegState 
 HexagonGlobalRegState;
   #define REG_WRITES_MAX 32
   #define PRED_WRITES_MAX 5                   /* 4 insns + endloop */
   #define VSTORES_MAX 2

Could this simplify #ifdef'ry maintenance in source?

  #ifdef CONFIG_USER_ONLY
  #define HVX_CONTEXTS_MAX 1
  #else

Quoted 5 lines
Quoted 4 lines

target/hexagon/cpu.h typedef struct HexagonGlobalRegState HexagonGlobalRegState; · line 53

Quoted 1 line
target/hexagon/cpu.h +1 -0
+#define HVX_CONTEXTS_MAX 8

  #endif

Okay, good idea - I'll give it a go.

Hmmm - making that change and making both modes have a "HexagonHVXContext *hvx" would work but then we'd need to add some ifdef'd magic to cpu_copy() so that we get one context bound to each thread.  That sounds like it's not a net win.

Quoted 49 lines
Quoted 49 lines
Quoted 48 lines
target/hexagon/cpu.h +0 -0
   #define MAX_TLB_ENTRIES 1024
   #define THREADS_MAX 16

  @@ -120,6 +122,11 @@ typedef struct {
  /* Maximum number of vector temps in a packet */ #define VECTOR_TEMPS_MAX            4 +typedef struct HexagonHVXContext {
+    MMVector VRegs[NUM_VREGS];
+    MMQReg QRegs[NUM_QREGS];

target/hexagon/cpu.h +2 -0
+} QEMU_ALIGNED(16) HexagonHVXContext;
+

  typedef struct CPUArchState {
      target_ulong gpr[TOTAL_PER_THREAD_REGS];
      target_ulong pred[NUM_PREGS];

target/hexagon/cpu.h +14 -0
@@ -159,11 +166,15 @@ typedef struct CPUArchState {
       target_ulong llsc_val;
       uint64_t     llsc_val_i64;
   -    MMVector VRegs[NUM_VREGS] QEMU_ALIGNED(16);
+#ifdef CONFIG_USER_ONLY
+    HexagonHVXContext hvx_ctx;
+#else
+    HexagonHVXContext *hvx;
+#endif
+
       MMVector future_VRegs[VECTOR_TEMPS_MAX] QEMU_ALIGNED(16);
       MMVector tmp_VRegs[VECTOR_TEMPS_MAX] QEMU_ALIGNED(16);
   -    MMQReg QRegs[NUM_QREGS] QEMU_ALIGNED(16);
       MMQReg future_QRegs[NUM_QREGS] QEMU_ALIGNED(16);
         /* Temporaries used within instructions */
@@ -196,6 +207,7 @@ struct ArchCPU {
       CPUHexagonState env;
       HexagonCPUConfig cfg;
   #ifndef CONFIG_USER_ONLY
+    HexagonHVXContextState *hvx_ctx[HVX_CONTEXTS_MAX];
       HexagonTLBState *tlb;
       uint32_t boot_addr;
       HexagonGlobalRegState *globalregs;
@@ -204,6 +216,15 @@ struct ArchCPU {
   #endif
   };
   +static inline HexagonHVXContext *hex_hvx(CPUHexagonState *env)
+{
+#ifdef CONFIG_USER_ONLY
+    return &env->hvx_ctx;
+#else
+    return env->hvx;
+#endif
+}
#9 lore raw

Re: [PATCH v5 5/6] target/hexagon: share HVX contexts among CPUs

Quoted 65 lines · Brian Cain
Quoted 63 lines · Brian Cain
Quoted 61 lines · Philippe Mathieu-Daudé

Hi,

Quoted 47 lines · Brian Cain

The HVX register file belongs to an extension context, not a hardware thread. Model each system-emulation context as a QOM device, link the contexts to each vCPU, and use SSR:XA to select the active context.

Keep one embedded context per linux-user CPU.  Carry the selected register-file base with HVX operands so translated code can address the selected context at run time.

---
  include/hw/hexagon/hexagon.h             |   1 + include/hw/hexagon/hexagon_hvx_context.h |  27 + target/hexagon/cpu.h                     |  25 +- target/hexagon/cpu_helper.h              |   1 + target/hexagon/gen_tcg_hvx.h             | 608 ++++++++++++

+----------
  target/hexagon/genptr.h                  |   8 +
  target/hexagon/mmvec/macros.h            |  14 +-
  target/hexagon/translate.h               |  11 +-
  hw/hexagon/hex-subsys.c                  |  36 ++
  hw/hexagon/hexagon_hvx_context.c         |  84 ++++
  target/hexagon/cpu.c                     |  30 +-
  target/hexagon/cpu_helper.c              |  82 +++
  target/hexagon/gdbstub.c                 |  16 +-
  target/hexagon/genptr.c                  | 102 ++--
  target/hexagon/machine.c                 |  12 +
  target/hexagon/op_helper.c               |  37 +-
  target/hexagon/translate.c               |  60 ++-
  hw/hexagon/meson.build                   |   1 +
  target/hexagon/hex_common.py             | 179 ++++---
  19 files changed, 886 insertions(+), 448 deletions(-)

  create mode 100644 include/hw/hexagon/hexagon_hvx_context.h create mode 100644 hw/hexagon/hexagon_hvx_context.c

target/hexagon/cpu.h +1 -0
index 97f689fda22..df4c0182247 100644
@@ -29,6 +29,7 @@
     typedef struct HexagonTLBState HexagonTLBState;
   typedef struct HexagonGlobalRegState HexagonGlobalRegState;
+typedef struct HexagonHVXContextState HexagonHVXContextState;
     #include "cpu-qom.h"
   #include "exec/cpu-common.h"

target/hexagon/cpu.h typedef struct HexagonGlobalRegState · line 53

Quoted 4 lines
target/hexagon/cpu.h +0 -0
@@ -49,6 +50,7 @@ typedef struct HexagonGlobalRegState 
 HexagonGlobalRegState;
   #define REG_WRITES_MAX 32
   #define PRED_WRITES_MAX 5                   /* 4 insns + endloop */
   #define VSTORES_MAX 2

Could this simplify #ifdef'ry maintenance in source?

  #ifdef CONFIG_USER_ONLY
  #define HVX_CONTEXTS_MAX 1
  #else

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

target/hexagon/cpu.h typedef struct HexagonGlobalRegState HexagonGlobalRegState; · line 53

Quoted 1 line
target/hexagon/cpu.h +1 -0
+#define HVX_CONTEXTS_MAX 8

  #endif

Okay, good idea - I'll give it a go.

Hmmm - making that change and making both modes have a "HexagonHVXContext *hvx" would work but then we'd need to add some ifdef'd magic to cpu_copy() so that we get one context bound to each thread.  That sounds like it's not a net win.

Unfortunate. Something bugs me in this patch but it is too big to review and Richard already reviewed it, so no objection.

To reduce the changes size we can introduce hex_hvx() and HEX_HVX_OFFSET() as a NO-OP first step with most of the code churn:

  static inline CPUHexagonState *hex_hvx(CPUHexagonState *env)
  {
      return env;
  }

  #define HEX_HVX_OFFSET(member) offsetof(CPUHexagonState, member)

See for example 4a5d2c649da ("target/loongarch: Add macro CSR_OFFSET and CPU_CSR_OFFSET") and around commits.

This will help us to review the more complex rest of the changes when looking back at the commit in the future ;) Normally if you do the split you can keep Richard R-b tag.

Quoted 51 lines
Quoted 50 lines
Quoted 50 lines
Quoted 49 lines
target/hexagon/cpu.h +0 -0
   #define MAX_TLB_ENTRIES 1024
   #define THREADS_MAX 16

  @@ -120,6 +122,11 @@ typedef struct {
  /* Maximum number of vector temps in a packet */ #define VECTOR_TEMPS_MAX            4 +typedef struct HexagonHVXContext {
+    MMVector VRegs[NUM_VREGS];
+    MMQReg QRegs[NUM_QREGS];

target/hexagon/cpu.h +2 -0
+} QEMU_ALIGNED(16) HexagonHVXContext;
+

  typedef struct CPUArchState {
      target_ulong gpr[TOTAL_PER_THREAD_REGS];
      target_ulong pred[NUM_PREGS];

target/hexagon/cpu.h +14 -0
@@ -159,11 +166,15 @@ typedef struct CPUArchState {
       target_ulong llsc_val;
       uint64_t     llsc_val_i64;
   -    MMVector VRegs[NUM_VREGS] QEMU_ALIGNED(16);
+#ifdef CONFIG_USER_ONLY
+    HexagonHVXContext hvx_ctx;
+#else
+    HexagonHVXContext *hvx;
+#endif
+
       MMVector future_VRegs[VECTOR_TEMPS_MAX] QEMU_ALIGNED(16);
       MMVector tmp_VRegs[VECTOR_TEMPS_MAX] QEMU_ALIGNED(16);
   -    MMQReg QRegs[NUM_QREGS] QEMU_ALIGNED(16);
       MMQReg future_QRegs[NUM_QREGS] QEMU_ALIGNED(16);
         /* Temporaries used within instructions */
@@ -196,6 +207,7 @@ struct ArchCPU {
       CPUHexagonState env;
       HexagonCPUConfig cfg;
   #ifndef CONFIG_USER_ONLY
+    HexagonHVXContextState *hvx_ctx[HVX_CONTEXTS_MAX];
       HexagonTLBState *tlb;
       uint32_t boot_addr;
       HexagonGlobalRegState *globalregs;
@@ -204,6 +216,15 @@ struct ArchCPU {
   #endif
   };
   +static inline HexagonHVXContext *hex_hvx(CPUHexagonState *env)
+{
+#ifdef CONFIG_USER_ONLY
+    return &env->hvx_ctx;
+#else
+    return env->hvx;
+#endif
+}
author
#10 lore raw

PATCH v5 6/6 tests/functional/hexagon: add HVX tests

In reply to Brian Cain

These tests pass now that HVX is modeled for system emulation.

---
 tests/functional/hexagon/test_arch_tests.py | 7 +++++++
 tests/functional/hexagon/test_systests.py   | 6 ++++++
 2 files changed, 13 insertions(+)
tests/functional/hexagon/test_arch_tests.py +7 -0
index 40f76e25ae6..28bf2f02d39 100755
@@ -119,6 +119,13 @@ def test_user_mode(self) -> None:
         """
         self.run_uart_test("test_user_mode")
 
+    def test_hvx_context(self) -> None:
+        """Tests the HVX coprocessor context: SSR XA context selection
+        and isolation, vsplat/store, and the NO_COPROC_ENABLE exception
+        raised when SSR:XE is clear.
+        """
+        self.run_uart_test("test_hvx_context")
+
 
 if __name__ == "__main__":
     QemuSystemTest.main()
tests/functional/hexagon/test_systests.py +6 -0
index 2779efa9172..c8137a71713 100755
@@ -99,5 +99,11 @@ def test_mmu_multi_tlb(self):
     def test_timer_reg(self):
         self.run_exit_zero("timer_reg")
 
+    def test_hvx_multi(self):
+        self.run_exit_zero("hvx-multi")
+
+    def test_standalone_vec(self):
+        self.run_exit_zero("standalone_vec")
+
 if __name__ == "__main__":
     QemuSystemTest.main()
Signature · 1 line
2.34.1