hexagon: Add HVX context
v6 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 v6:
- added a nop "prepare for separate HVX contexts" to introduce hex_hvx(), (preserving Richard's R-b across this and "share HVX contexts among CPUs").
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.
v5: https://lore.kernel.org/qemu-devel/[email protected]/
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 (7):
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: prepare for separate HVX contexts 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
PATCH v6 1/7 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
@@ -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
PATCH v6 2/7 tcg: add base arguments to the gvec 2s, dup_i32 and cmp expanders
In reply to Brian CainThese 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
@@ -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
PATCH v6 3/7 tcg: split out _var forms of gvec saturating/mul/shift-immediate ops
In reply to Brian Caintarget/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
@@ -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
PATCH v6 4/7 target/hexagon: raise an exception for HVX with SSR:XE clear
In reply to Brian CainSSR: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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v6 5/7 target/hexagon: prepare for separate HVX contexts
In reply to Brian CainPrepare for system emulation modeling of HVX contexts, which are remapped at runtime. No functional change is intended, this is just refactoring.
--- target/hexagon/cpu.h | 5 + target/hexagon/gen_tcg_hvx.h | 608 +++++++++++++++++++--------------- target/hexagon/genptr.h | 8 + target/hexagon/mmvec/macros.h | 14 +- target/hexagon/translate.h | 6 +- target/hexagon/cpu.c | 13 +- target/hexagon/gdbstub.c | 16 +- target/hexagon/genptr.c | 102 +++--- target/hexagon/op_helper.c | 37 ++- target/hexagon/translate.c | 55 +-- target/hexagon/hex_common.py | 179 +++++----- 11 files changed, 597 insertions(+), 446 deletions(-)
target/hexagon/cpu.h +5 -0
@@ -204,6 +204,11 @@ struct ArchCPU {#endif }; +static inline CPUHexagonState *hex_hvx (CPUHexagonState *env) +{ +return env; +} + FIELD(TB_FLAGS, IS_TIGHT_LOOP, 0, 1) FIELD(TB_FLAGS, MMU_INDEX, 1, 3)FIELD (TB_FLAGS ,PCYCLE_ENABLED ,4 ,1 )
target/hexagon/gen_tcg_hvx.h +338 -270
1,072 lines not on this page · raw message
target/hexagon/genptr.h +8 -0
@@ -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
@@ -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 +4 -2
@@ -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,8 @@ 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 ]; +#define hex_hvx_ptr tcg_env +#define HEX_HVX_OFFSET (member) offsetof(CPUHexagonState, member)#ifndef CONFIG_USER_ONLY extern TCGv_i32 hex_greg[NUM_GREGS ];extern TCGv_i32 hex_t_sreg[NUM_SREGS ];
target/hexagon/cpu.c +7 -6
@@ -191,7 +191,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 +202,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 +221,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 +233,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" ); }
target/hexagon/gdbstub.c +8 -8
@@ -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/op_helper.c +19 -18
@@ -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 +33 -22
114 lines not on this page · raw message
target/hexagon/hex_common.py +102 -77
302 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v6 5/7] target/hexagon: prepare for separate HVX contexts
Quoted 5 lines · Brian Cain
Prepare for system emulation modeling of HVX contexts, which are remapped at runtime. No functional change is intended, this is just refactoring.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by Brian Cain <[email protected]>
Quoted 13 lines
--- target/hexagon/cpu.h | 5 + target/hexagon/gen_tcg_hvx.h | 608 +++++++++++++++++++--------------- target/hexagon/genptr.h | 8 + target/hexagon/mmvec/macros.h | 14 +- target/hexagon/translate.h | 6 +- target/hexagon/cpu.c | 13 +- target/hexagon/gdbstub.c | 16 +- target/hexagon/genptr.c | 102 +++--- target/hexagon/op_helper.c | 37 ++- target/hexagon/translate.c | 55 +-- target/hexagon/hex_common.py | 179 +++++----- 11 files changed, 597 insertions(+), 446 deletions(-)
PATCH v6 6/7 target/hexagon: share HVX contexts among CPUs
In reply to Brian CainThe 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 | 24 +++++-- target/hexagon/cpu_helper.h | 1 + target/hexagon/translate.h | 7 +- hw/hexagon/hex-subsys.c | 36 ++++++++++ hw/hexagon/hexagon_hvx_context.c | 84 ++++++++++++++++++++++++ target/hexagon/cpu.c | 17 +++++ target/hexagon/cpu_helper.c | 82 +++++++++++++++++++++++ target/hexagon/machine.c | 12 ++++ target/hexagon/translate.c | 9 ++- hw/hexagon/meson.build | 1 + 12 files changed, 294 insertions(+), 7 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
@@ -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
@@ -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 +20 -4
@@ -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,9 +216,13 @@ struct ArchCPU {#endif }; -static inline CPUHexagonState *hex_hvx (CPUHexagonState *env) +static inline HexagonHVXContext *hex_hvx (CPUHexagonState *env) { -return env; +#ifdef CONFIG_USER_ONLY +return &env->hvx_ctx; +#else +return env->hvx; +#endif }FIELD (TB_FLAGS ,IS_TIGHT_LOOP ,0 ,1 )
target/hexagon/cpu_helper.h +1 -0
@@ -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/translate.h +6 -1
@@ -328,8 +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, member) +#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
@@ -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 +17 -0
@@ -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)
@@ -328,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 );
@@ -338,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 );
@@ -449,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
@@ -554,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/machine.c +12 -0
@@ -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/translate.c +7 -2
@@ -70,6 +70,9 @@ TCGv hex_imprecise_exception;TCGv hex_vstore_addr[VSTORES_MAX ];TCGv hex_vstore_size[VSTORES_MAX ];TCGv hex_vstore_pending[VSTORES_MAX ]; +#ifndef CONFIG_USER_ONLY +TCGv_ptr hex_hvx_ptr; +#endif #ifndef CONFIG_USER_ONLY TCGv_i32 hex_greg[NUM_GREGS ];
@@ -1024,7 +1027,7 @@ static void gen_commit_hvx(DisasContext *ctx)/* * for (i = 0; i < ctx->vreg_log_idx; i++) { * int rnum = ctx->vreg_log[i]; -* hex_hvx(env)->VRegs[rnum] = env->future_VRegs[rnum]; +* env->hvx->VRegs[rnum] = env->future_VRegs[rnum]; * } */ for (i =0 ; i < ctx->vreg_log_idx; i++) {
@@ -1041,7 +1044,7 @@ static void gen_commit_hvx(DisasContext *ctx)/* * for (i = 0; i < ctx->qreg_log_idx; i++) { * int rnum = ctx->qreg_log[i]; -* hex_hvx(env)->QRegs[rnum] = env->future_QRegs[rnum]; +* env->hvx->QRegs[rnum] = env->future_QRegs[rnum]; * } */ for (i =0 ; i < ctx->qreg_log_idx; i++) {
@@ -1371,6 +1374,8 @@ void hexagon_translate_init(void)opcode_init ();#ifndef CONFIG_USER_ONLY + hex_hvx_ptr =tcg_global_mem_new_ptr (tcg_env, + offsetof(CPUHexagonState , hvx),"hvx" );for (i =0 ; i <NUM_GREGS ; i++) { hex_greg[i] =tcg_global_mem_new_i32 (tcg_env, offsetof(CPUHexagonState, greg[i]),
hw/hexagon/meson.build +1 -0
@@ -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'))
Signature · 1 line
2.34.1
Re: [PATCH v6 6/7] target/hexagon: share HVX contexts among CPUs
Quoted 10 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.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by Brian Cain <[email protected]>
Quoted 14 lines
--- include/hw/hexagon/hexagon.h | 1 + include/hw/hexagon/hexagon_hvx_context.h | 27 ++++++++ target/hexagon/cpu.h | 24 +++++-- target/hexagon/cpu_helper.h | 1 + target/hexagon/translate.h | 7 +- hw/hexagon/hex-subsys.c | 36 ++++++++++ hw/hexagon/hexagon_hvx_context.c | 84 ++++++++++++++++++++++++ target/hexagon/cpu.c | 17 +++++ target/hexagon/cpu_helper.c | 82 +++++++++++++++++++++++ target/hexagon/machine.c | 12 ++++ target/hexagon/translate.c | 9 ++- hw/hexagon/meson.build | 1 + 12 files changed, 294 insertions(+), 7 deletions(-)
Now much easier to review :)
Quoted 6 lines
create mode 100644
include/hw/hexagon/hexagon_hvx_context.hcreate mode 100644hw/hexagon/hexagon_hvx_context.chw/hexagon/hex-subsys.c +2
-0+/* +* Create the core's HVX extension contexts. There are fewer of them than
hw/hexagon/hex-subsys.c static DeviceState *tlb_create(HexagonCommonMachineState *hms, · line 114
Quoted 10 lines
hw/hexagon/hex-subsys.c +10
-0+* 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 ) {
That would be 'if (n >= HVX_CONTEXTS_MAX) {' but since it is a programming error when creating a machine, simply assert:
assert(n < HVX_CONTEXTS_MAX);
Can be updated locally before sending the PR, no need to repost.
Quoted 27 lines
hw/hexagon/hex-subsys.c +16
-0+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)
hw/hexagon/hex-subsys.c void hex_subsys_add_cpu(HexagonCommonMachineState *hms, DeviceState *cpu) · line 184
Quoted 4 lines
hw/hexagon/hex-subsys.c +1
-0@@ -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++) {
Good style with reduced variable scope, ...
Quoted 9 lines
hw/hexagon/hex-subsys.c +5
-0+ 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); + } }
hw/hexagon/hex-subsys.c static void hexagon_cpu_init(Object *obj) · line 568
Quoted 8 lines
hw/hexagon/hex-subsys.c +4
-0@@ -554,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++) {
... but sometimes the style differ, better to keep the same.
(also easy enough to fix locally before PR).
Quoted 8 lines
target/hexagon/cpu.c +6
-0+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 }
Re: [PATCH v6 6/7] target/hexagon: share HVX contexts among CPUs
Quoted 51 lines · Philippe Mathieu-Daudé
Quoted 23 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.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by Brian Cain <[email protected]>---
include/hw/hexagon/hexagon.h | 1 +include/hw/hexagon/hexagon_hvx_context.h| 27 ++++++++ target/hexagon/cpu.h | 24 +++++-- target/hexagon/cpu_helper.h | 1 + target/hexagon/translate.h | 7 +- hw/hexagon/hex-subsys.c | 36 ++++++++++ hw/hexagon/hexagon_hvx_context.c | 84 ++++++++++++++++++++++++ target/hexagon/cpu.c | 17 +++++ target/hexagon/cpu_helper.c | 82 +++++++++++++++++++++++ target/hexagon/machine.c | 12 ++++ target/hexagon/translate.c | 9 ++- hw/hexagon/meson.build | 1 +Quoted 1 line
12 files changed, 294 insertions(+), 7 deletions(-)Now much easier to review :)
Quoted 14 lines
create mode 100644
include/hw/hexagon/hexagon_hvx_context.hcreate mode 100644hw/hexagon/hexagon_hvx_context.c+/*
+ * 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 structhexagon_machine_config*m_cfg)hw/hexagon/hex-subsys.c static DeviceState *tlb_create(HexagonCommonMachineState *hms, · line 114
Quoted 5 lines
hw/hexagon/hex-subsys.c +5
-0+{ + unsigned n = m_cfg->cfgtable.ext_contexts; + unsigned i; + + if (n > HVX_CONTEXTS_MAX) {That would be 'if (n >=
HVX_CONTEXTS_MAX) {' but since it is a programming error when creating a machine, simply assert:
Quoted 1 line
assert(n < HVX_CONTEXTS_MAX);
n here is the count of contexts to be allocated, so n == MAX is legal/expected (indeed used by one of the v81 machines). I'll make it assert(n <= HVX_CONTEXTS_MAX).
Quoted 2 lines
Can be updated locally before sending the PR, no need to repost.
Ok, ty, will do.
Quoted 67 lines
Quoted 29 lines
+ 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_autofreechar *name =g_strdup_printf("hvx-context[%u]", i);hw/hexagon/hex-subsys.c +8
-0+ + 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);hw/hexagon/hex-subsys.c +1
-0@@ -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)hw/hexagon/hex-subsys.c void · line 185
Quoted 5 lines
hw/hexagon/hex-subsys.c +1
-0@@ -151,6 +181,12 @@ voidhex_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++) {Good style with reduced variable scope, ...
Quoted 9 lines
hw/hexagon/hex-subsys.c +5
-0+ 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); + } }hw/hexagon/hex-subsys.c static void hexagon_cpu_init(Object *obj) · line 568
Quoted 8 lines
hw/hexagon/hex-subsys.c +4
-0@@ -554,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++) {... but sometimes the style differ, better to keep the same.
(also easy enough to fix locally before PR).
Quoted 8 lines
target/hexagon/cpu.c +6
-0+ 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 }
PATCH v6 7/7 tests/functional/hexagon: add HVX tests
In reply to Brian CainThese 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
@@ -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
@@ -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