Skip to contentSkip to conversation

hexagon: Add HVX context

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

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Brian Cain

author
#0 lore raw

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

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 test_hvx_context arch test

 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                        |  17 +-
 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                  |   7 +-
 hw/hexagon/hex-subsys.c                     |  36 ++
 hw/hexagon/hexagon_hvx_context.c            |  83 +++
 linux-user/hexagon/cpu_loop.c               |   2 +
 linux-user/main.c                           |   3 +
 target/hexagon/cpu.c                        |  32 +-
 target/hexagon/cpu_helper.c                 |  72 +++
 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                  |  73 ++-
 tcg/tcg-op-gvec.c                           | 617 ++++++++++++++------
 hw/hexagon/meson.build                      |   1 +
 target/hexagon/hex_common.py                | 180 +++---
 tests/functional/hexagon/test_arch_tests.py |   7 +
 24 files changed, 1431 insertions(+), 622 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 v2 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
Reviewed-by on v2 1/6
#2 lore raw

Re: [PATCH v2 1/6] tcg: split out _var forms of gvec logical, abs and min/max ops

Quoted 13 lines · 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. 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.

Quoted 6 lines
---
  include/tcg/tcg-op-gvec-common.h |  45 ++++++++
  tcg/tcg-op-gvec.c                | 184 ++++++++++++++++++++++++-------
  2 files changed, 189 insertions(+), 40 deletions(-)

r~

author
#3 lore raw

PATCH v2 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
Reviewed-by on v2 2/6
#4 lore raw

Re: [PATCH v2 2/6] tcg: add base arguments to the gvec 2s, dup_i32 and cmp expanders

Quoted 13 lines · 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.

Quoted 6 lines
---
  include/tcg/tcg-op-gvec-common.h |  21 +++
  tcg/tcg-op-gvec.c                | 256 +++++++++++++++++++++----------
  2 files changed, 192 insertions(+), 85 deletions(-)

r~

author
#5 lore raw

PATCH v2 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
Reviewed-by on v2 3/6
#6 lore raw

Re: [PATCH v2 3/6] tcg: split out _var forms of gvec saturating/mul/shift-immediate ops

Quoted 9 lines · 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.

Quoted 6 lines
---
  include/tcg/tcg-op-gvec-common.h |  31 ++++++
  tcg/tcg-op-gvec.c                | 177 ++++++++++++++++++++++---------
  2 files changed, 160 insertions(+), 48 deletions(-)

r~

author
#7 lore raw

PATCH v2 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 8a4a81dc26c..32cdcfe8529 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 4a7b76e3bcc..1109a8d914c 100644
@@ -331,6 +331,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 5d3d67e5d3e..b44cf48d757 100644
@@ -718,6 +718,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)
@@ -1235,6 +1243,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
#8 lore raw

PATCH v2 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                     |  16 +-
 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               |   5 +-
 hw/hexagon/hex-subsys.c                  |  36 ++
 hw/hexagon/hexagon_hvx_context.c         |  83 ++++
 linux-user/hexagon/cpu_loop.c            |   2 +
 linux-user/main.c                        |   3 +
 target/hexagon/cpu.c                     |  30 +-
 target/hexagon/cpu_helper.c              |  72 +++
 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               |  62 ++-
 hw/hexagon/meson.build                   |   1 +
 target/hexagon/hex_common.py             | 180 ++++---
 21 files changed, 867 insertions(+), 449 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 3d7b3cb12dc..0ee6fd8d033 100644
@@ -162,6 +162,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 +13 -3
index 32cdcfe8529..3d75e90579b 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 8
 
@@ -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] QEMU_ALIGNED(16);
+    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,11 @@ typedef struct CPUArchState {
     target_ulong llsc_val;
     uint64_t     llsc_val_i64;
 
-    MMVector VRegs[NUM_VREGS] QEMU_ALIGNED(16);
+    HexagonHVXContext *hvx;
+
     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 */
@@ -195,7 +202,10 @@ struct ArchCPU {
 
     CPUHexagonState env;
     HexagonCPUConfig cfg;
-#ifndef CONFIG_USER_ONLY
+#ifdef CONFIG_USER_ONLY
+    HexagonHVXContext hvx_ctx QEMU_ALIGNED(16);
+#else
+    HexagonHVXContextState *hvx_ctx[HVX_CONTEXTS_MAX];
     HexagonTLBState *tlb;
     uint32_t boot_addr;
     HexagonGlobalRegState *globalregs;
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 +3 -2
index b87a2b20e2f..a65be7b2e04 100644
@@ -91,6 +91,7 @@ typedef struct DisasContext {
     bool pcycle_enabled;
     bool hvx_coproc_enabled;
     bool hvx_check_emitted;
+    TCGv_ptr hvx_base;
     uint32_t num_cycles;
 } DisasContext;
 
@@ -192,9 +193,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)
 {
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 +83 -0

83 lines not on this page · raw message

linux-user/hexagon/cpu_loop.c +2 -0
index e4ef97a1184..c8fa6080a4e 100644
@@ -33,6 +33,8 @@ void cpu_loop(CPUHexagonState *env)
     target_ulong syscallnum;
     target_ulong ret;
 
+    env->hvx = &HEXAGON_CPU(cs)->hvx_ctx;
+
     for (;;) {
         cpu_exec_start(cs);
         trapnr = cpu_exec(cs);
linux-user/main.c +3 -0
index 60a695b7ca3..918b4930b07 100644
@@ -244,6 +244,9 @@ CPUArchState *cpu_copy(CPUArchState *env)
 
     new_cpu->tcg_cflags = cpu->tcg_cflags;
     memcpy(new_env, env, sizeof(CPUArchState));
+#if defined(TARGET_HEXAGON)
+    HEXAGON_CPU(new_cpu)->hvx_ctx = HEXAGON_CPU(cpu)->hvx_ctx;
+#endif
 #if defined(TARGET_I386) || defined(TARGET_X86_64)
     new_env->gdt.base = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES,
                                     PROT_READ | PROT_WRITE,
target/hexagon/cpu.c +24 -6
index 1109a8d914c..9b74ea38994 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)
@@ -182,7 +183,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 (env->hvx->VRegs[regnum].ub[i] != 0) {
                 nonzero_found = true;
                 break;
             }
@@ -193,9 +194,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",
+                 env->hvx->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", env->hvx->VRegs[regnum].ub[i]);
     }
     qemu_fprintf(f, " )\n");
 }
@@ -211,7 +213,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 (env->hvx->QRegs[regnum].ub[i] != 0) {
                 nonzero_found = true;
                 break;
             }
@@ -223,9 +225,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]);
+                 env->hvx->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", env->hvx->QRegs[regnum].ub[i]);
     }
     qemu_fprintf(f, " )\n");
 }
@@ -318,6 +320,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);
@@ -328,10 +333,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);
@@ -439,6 +446,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
@@ -544,7 +552,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 +72 -0

90 lines not on this page · raw message

target/hexagon/gdbstub.c +8 -8
index b9856cfc978..5e480726b03 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(env->hvx->VRegs[n].uw); i++) {
+        total += gdb_get_reg32(mem_buf, env->hvx->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(env->hvx->QRegs[n].uw); i++) {
+        total += gdb_get_reg32(mem_buf, env->hvx->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(env->hvx->VRegs[n].uw); i++) {
+        env->hvx->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(env->hvx->QRegs[n].uw); i++) {
+        env->hvx->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 7ad99ced7ab..cb9bc7e4317 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]++;
+            env->hvx->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[
+                env->hvx->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;
+        env->hvx->VRegs[vindex].uh[elindex] =
+            env->hvx->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;
+            env->hvx->VRegs[vindex].uh[elindex] =
+                env->hvx->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);
+        env->hvx->VRegs[vindex].uh[elindex] =
+            fVSATUH(env->hvx->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);
+            env->hvx->VRegs[vindex].uh[elindex] =
+                fVSATUH(env->hvx->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;
+        env->hvx->VRegs[vindex].uw[elindex] =
+            env->hvx->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;
+            env->hvx->VRegs[vindex].uw[elindex] =
+                env->hvx->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;
+            env->hvx->VRegs[vindex].uw[elindex] =
+                env->hvx->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;
+            env->hvx->VRegs[vindex].uw[elindex] =
+                env->hvx->VRegs[vindex].uw[elindex] + weight;
         }
     }
 }
target/hexagon/translate.c +40 -22

125 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 +103 -77

303 lines not on this page · raw message

Signature · 1 line
2.34.1
#9 lore raw

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

target/hexagon/cpu.h typedef struct { · line 128

Quoted 4 lines · Brian Cain
target/hexagon/cpu.h +4 -0
+typedef struct HexagonHVXContext {
+    MMVector VRegs[NUM_VREGS] QEMU_ALIGNED(16);
+    MMQReg QRegs[NUM_QREGS] QEMU_ALIGNED(16);
+} HexagonHVXContext;

Alignment is a property of the structure, here.

target/hexagon/cpu.h struct ArchCPU { · line 207

Quoted 3 lines
target/hexagon/cpu.h +3 -0
+#ifdef CONFIG_USER_ONLY
+    HexagonHVXContext hvx_ctx QEMU_ALIGNED(16);
+#else

No need to duplicate that here.

hw/hexagon/hexagon_hvx_context.c line 76

Quoted 6 lines
hw/hexagon/hexagon_hvx_context.c new file +6 -0
+static const TypeInfo hexagon_hvx_context_info = {
+    .name = TYPE_HEXAGON_HVX_CONTEXT,
+    .parent = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(HexagonHVXContextState),
+    .class_init = hexagon_hvx_context_class_init,
+};

Missing .instance_align.

linux-user/hexagon/cpu_loop.c void cpu_loop(CPUHexagonState *env) · line 36

Quoted 9 lines
linux-user/hexagon/cpu_loop.c +1 -0
index e4ef97a1184..c8fa6080a4e 100644
@@ -33,6 +33,8 @@ void cpu_loop(CPUHexagonState *env)
      target_ulong syscallnum;
      target_ulong ret;
 
+    env->hvx = &HEXAGON_CPU(cs)->hvx_ctx;

How complex would it be to not have this pointer for user-only?

I think all that would be needed is to define the base as tcg_env and adjust the offsetof used.

linux-user/hexagon/cpu_loop.c void cpu_loop(CPUHexagonState *env)

Quoted 6 lines
linux-user/hexagon/cpu_loop.c +6 -0
+    ctx->hvx_base = NULL;
+    if (ctx->pkt.pkt_has_hvx) {
+        ctx->hvx_base = tcg_temp_new_ptr();
+        tcg_gen_ld_ptr(ctx->hvx_base, tcg_env,
+                       offsetof(CPUHexagonState, hvx));
+    }

I think you should use a TCG global for the env->hvx_ctx slot. That will let the register allocator load the slot on demand.

Also, this could become

#ifdef CONFIG_USER_ONLY
#define hex_hvx_ptr tcg_env
#else
TCGv_ptr hex_hvx_ptr;
#endif

with a slight change in the offsetof computation.

r~

author
#10 lore raw

PATCH v2 6/6 tests/functional/hexagon: add test_hvx_context arch test

In reply to Brian Cain

Passes now that HVX raises NO_COPROC_ENABLE when SSR:XE is clear.

---
 tests/functional/hexagon/test_arch_tests.py | 7 +++++++
 1 file changed, 7 insertions(+)
tests/functional/hexagon/test_arch_tests.py +7 -0
index 5d7ce487436..f73c1f42bf0 100755
@@ -98,6 +98,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()
Signature · 1 line
2.34.1