Hexagon (target/hexagon) COF overrides and new generator
v2 cover Hexagon (target/hexagon) COF overrides and new generator
The idef-parser skips the change-of-flow (COF) instructions, so add overrides
**** Changes in v2 ****
Add a new generator for analyze_<tag> instructions. Pouplate the DisasContext ahead of generating code.
Taylor Simpson (6):
Hexagon (target/hexagon) Add overrides for jumpr31 instructions Hexagon (target/hexagon) Add overrides for callr
Hexagon (target/hexagon) Add overrides for endloop1/endloop01 Hexagon (target/hexagon) Add overrides for dealloc-return instructions Hexagon (target/hexagon) Analyze packet before generating TCG Hexagon (target/hexagon) Analyze packet step 2
target/hexagon/gen_tcg.h | 77 ++++++ target/hexagon/insn.h | 3 + target/hexagon/macros.h | 10 - target/hexagon/translate.h | 51 ++-- target/hexagon/genptr.c | 198 +++++++++++++++- target/hexagon/idef-parser/parser-helpers.c | 5 - target/hexagon/op_helper.c | 24 -- target/hexagon/translate.c | 173 +++++++++----- target/hexagon/README | 11 +- target/hexagon/gen_analyze_func_table.py | 52 ++++ target/hexagon/gen_analyze_funcs.py | 250 ++++++++++++++++++++ target/hexagon/gen_tcg_funcs.py | 39 --- target/hexagon/meson.build | 18 ++ 13 files changed, 742 insertions(+), 169 deletions(-) create mode 100755 target/hexagon/gen_analyze_func_table.py create mode 100755 target/hexagon/gen_analyze_funcs.py
Signature · 1 line
2.17.1
PATCH v2 1/6 Hexagon (target/hexagon) Add overrides for jumpr31 instructions
Add overrides for
SL2_jumpr31 Unconditional
SL2_jumpr31_t Predicated true (old value)
SL2_jumpr31_f Predicated false (old value)
SL2_jumpr31_tnew Predicated true (new value)
SL2_jumpr31_fnew Predicated false (new value)--- target/hexagon/gen_tcg.h | 13 +++++++++++++ target/hexagon/genptr.c | 8 ++++++++ 2 files changed, 21 insertions(+)
target/hexagon/gen_tcg.h +13 -0
@@ -1015,6 +1015,19 @@#define fGEN_TCG_S2_asl_r_r_sat (SHORTCODE ) \ gen_asl_r_r_sat(RdV, RsV, RtV) +#define fGEN_TCG_SL2_jumpr31 (SHORTCODE ) \ + gen_jumpr(ctx, hex_gpr[HEX_REG_LR]) + +#define fGEN_TCG_SL2_jumpr31_t (SHORTCODE ) \ + gen_cond_jumpr31(ctx, TCG_COND_EQ, hex_pred[0]) +#define fGEN_TCG_SL2_jumpr31_f (SHORTCODE ) \ + gen_cond_jumpr31(ctx, TCG_COND_NE, hex_pred[0]) + +#define fGEN_TCG_SL2_jumpr31_tnew (SHORTCODE ) \ + gen_cond_jumpr31(ctx, TCG_COND_EQ, hex_new_pred_value[0]) +#define fGEN_TCG_SL2_jumpr31_fnew (SHORTCODE ) \ + gen_cond_jumpr31(ctx, TCG_COND_NE, hex_new_pred_value[0]) +/* Floating point */ #define fGEN_TCG_F2_conv_sf2df (SHORTCODE ) \ gen_helper_conv_sf2df(RddV, cpu_env, RsV)
target/hexagon/genptr.c +8 -0
@@ -553,6 +553,14 @@ static void gen_cond_jumpr(DisasContext *ctx, TCGv dst_pc,gen_write_new_pc_addr (ctx, dst_pc, cond, pred); } +static void gen_cond_jumpr31 (DisasContext *ctx,TCGCond cond,TCGv pred) +{ +TCGv LSB =tcg_temp_new (); +tcg_gen_andi_tl (LSB , pred,1 ); +gen_cond_jumpr (ctx, hex_gpr[HEX_REG_LR ], cond,LSB ); +tcg_temp_free (LSB ); +} +static void gen_cond_jump (DisasContext *ctx,TCGCond cond,TCGv pred,int pc_off) {
Signature · 1 line
2.17.1
PATCH v2 2/6 Hexagon (target/hexagon) Add overrides for callr
In reply to Taylor SimpsonAdd overrides for
J2_callr
J2_callrt
J2_callrf
--- target/hexagon/gen_tcg.h | 6 ++++++ target/hexagon/macros.h | 10 ---------- target/hexagon/genptr.c | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-)
target/hexagon/gen_tcg.h +6 -0
@@ -614,11 +614,17 @@#define fGEN_TCG_J2_call (SHORTCODE ) \ gen_call(ctx, riV) +#define fGEN_TCG_J2_callr (SHORTCODE ) \ + gen_callr(ctx, RsV)#define fGEN_TCG_J2_callt (SHORTCODE ) \ gen_cond_call(ctx, PuV, TCG_COND_EQ, riV)#define fGEN_TCG_J2_callf (SHORTCODE ) \ gen_cond_call(ctx, PuV, TCG_COND_NE, riV) +#define fGEN_TCG_J2_callrt (SHORTCODE ) \ + gen_cond_callr(ctx, TCG_COND_EQ, PuV, RsV) +#define fGEN_TCG_J2_callrf (SHORTCODE ) \ + gen_cond_callr(ctx, TCG_COND_NE, PuV, RsV)#define fGEN_TCG_J2_endloop0 (SHORTCODE ) \ gen_endloop0(ctx)
target/hexagon/macros.h +0 -10
@@ -421,16 +421,6 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)#define fBRANCH (LOC ,TYPE ) fWRITE_NPC(LOC)#define fJUMPR (REGNO ,TARGET ,TYPE ) fBRANCH(TARGET, COF_TYPE_JUMPR)#define fHINTJR (TARGET ) {/* Not modelled in qemu */ } -#define fCALL (A ) \ - do { \ - fWRITE_LR(fREAD_NPC()); \ - fBRANCH(A, COF_TYPE_CALL); \ - } while (0) -#define fCALLR (A ) \ - do { \ - fWRITE_LR(fREAD_NPC()); \ - fBRANCH(A, COF_TYPE_CALLR); \ - } while (0)#define fWRITE_LOOP_REGS0 (START ,COUNT ) \ do { \ WRITE_RREG(HEX_REG_LC0, COUNT); \
target/hexagon/genptr.c +20 -0
@@ -670,6 +670,14 @@ static void gen_call(DisasContext *ctx, int pc_off)gen_write_new_pc_pcrel (ctx, pc_off,TCG_COND_ALWAYS ,NULL ); } +static void gen_callr (DisasContext *ctx,TCGv new_pc) +{ +TCGv next_PC = +tcg_constant_tl (ctx->pkt->pc + ctx->pkt->encod_pkt_size_in_bytes); +gen_log_reg_write (HEX_REG_LR , next_PC); +gen_write_new_pc_addr (ctx, new_pc,TCG_COND_ALWAYS ,NULL ); +} +static void gen_cond_call (DisasContext *ctx,TCGv pred,TCGCond cond,int pc_off) {
@@ -686,6 +694,18 @@ static void gen_cond_call(DisasContext *ctx, TCGv pred,gen_set_label (skip); } +static void gen_cond_callr (DisasContext *ctx, +TCGCond cond,TCGv pred,TCGv new_pc) +{ +TCGv lsb =tcg_temp_new (); +TCGLabel *skip =gen_new_label (); +tcg_gen_andi_tl (lsb, pred,1 ); +tcg_gen_brcondi_tl (cond, lsb,0 , skip); +tcg_temp_free (lsb); +gen_callr (ctx, new_pc); +gen_set_label (skip); +} +static void gen_endloop0 (DisasContext *ctx) {TCGv lpcfg =tcg_temp_local_new ();
Signature · 1 line
2.17.1
PATCH v2 3/6 Hexagon (target/hexagon) Add overrides for endloop1/endloop01
In reply to Taylor Simpson--- target/hexagon/gen_tcg.h | 4 ++ target/hexagon/genptr.c | 79 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+)
target/hexagon/gen_tcg.h +4 -0
@@ -628,6 +628,10 @@#define fGEN_TCG_J2_endloop0 (SHORTCODE ) \ gen_endloop0(ctx) +#define fGEN_TCG_J2_endloop1 (SHORTCODE ) \ + gen_endloop1(ctx) +#define fGEN_TCG_J2_endloop01 (SHORTCODE ) \ + gen_endloop01(ctx)/* * Compound compare and jump instructions
target/hexagon/genptr.c +79 -0
85 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 4/6 Hexagon (target/hexagon) Add overrides for dealloc-return instructions
In reply to Taylor SimpsonThese instructions perform a deallocframe+return (jumpr r31)
Add overrides for
L4_return
SL2_return
L4_return_t
L4_return_f
L4_return_tnew_pt
L4_return_fnew_pt
L4_return_tnew_pnt
L4_return_fnew_pnt
SL2_return_t
SL2_return_f
SL2_return_tnew
SL2_return_fnewThis patch eliminates the last helper that uses write_new_pc, so we remove it from op_helper.c
--- target/hexagon/gen_tcg.h | 54 ++++++++++++++++++++++++ target/hexagon/genptr.c | 86 ++++++++++++++++++++++++++++++++++++++ target/hexagon/op_helper.c | 24 ----------- 3 files changed, 140 insertions(+), 24 deletions(-)
target/hexagon/gen_tcg.h +54 -0
@@ -508,6 +508,60 @@#define fGEN_TCG_S2_storerinew_pcr (SHORTCODE ) \ fGEN_TCG_STORE_pcr(2, fSTORE(1, 4, EA, NtN)) +/* +* dealloc_return +* Assembler mapped to +* r31:30 = dealloc_return(r30):raw +*/ +#define fGEN_TCG_L4_return (SHORTCODE ) \ + gen_return(ctx, RddV, RsV) + +/* +* sub-instruction version (no RddV, so handle it manually) +*/ +#define fGEN_TCG_SL2_return (SHORTCODE ) \ + do { \ + TCGv_i64 RddV = tcg_temp_new_i64(); \ + gen_return(ctx, RddV, hex_gpr[HEX_REG_FP]); \ + gen_log_reg_write_pair(HEX_REG_FP, RddV); \ + tcg_temp_free_i64(RddV); \ + } while (0) + +/* +* Conditional returns follow this naming convention +* _t predicate true +* _f predicate false +* _tnew_pt predicate.new true predict taken +* _fnew_pt predicate.new false predict taken +* _tnew_pnt predicate.new true predict not taken +* _fnew_pnt predicate.new false predict not taken +* Predictions are not modelled in QEMU +* +* Example: +* if (p1) r31:30 = dealloc_return(r30):raw +*/ +#define fGEN_TCG_L4_return_t (SHORTCODE ) \ + gen_cond_return(ctx, RddV, RsV, PvV, TCG_COND_EQ); +#define fGEN_TCG_L4_return_f (SHORTCODE ) \ + gen_cond_return(ctx, RddV, RsV, PvV, TCG_COND_NE) +#define fGEN_TCG_L4_return_tnew_pt (SHORTCODE ) \ + gen_cond_return(ctx, RddV, RsV, PvN, TCG_COND_EQ) +#define fGEN_TCG_L4_return_fnew_pt (SHORTCODE ) \ + gen_cond_return(ctx, RddV, RsV, PvN, TCG_COND_NE) +#define fGEN_TCG_L4_return_tnew_pnt (SHORTCODE ) \ + gen_cond_return(ctx, RddV, RsV, PvN, TCG_COND_EQ) +#define fGEN_TCG_L4_return_fnew_pnt (SHORTCODE ) \ + gen_cond_return(ctx, RddV, RsV, PvN, TCG_COND_NE) + +#define fGEN_TCG_SL2_return_t (SHORTCODE ) \ + gen_cond_return_subinsn(ctx, TCG_COND_EQ, hex_pred[0]) +#define fGEN_TCG_SL2_return_f (SHORTCODE ) \ + gen_cond_return_subinsn(ctx, TCG_COND_NE, hex_pred[0]) +#define fGEN_TCG_SL2_return_tnew (SHORTCODE ) \ + gen_cond_return_subinsn(ctx, TCG_COND_EQ, hex_new_pred_value[0]) +#define fGEN_TCG_SL2_return_fnew (SHORTCODE ) \ + gen_cond_return_subinsn(ctx, TCG_COND_NE, hex_new_pred_value[0]) +/* * Mathematical operations with more than one definition require * special handling
target/hexagon/genptr.c +86 -0
92 lines not on this page · raw message
target/hexagon/op_helper.c +0 -24
@@ -105,30 +105,6 @@ void log_store64(CPUHexagonState *env, target_ulong addr, env->mem_log_stores[slot].data64 = val; } -void write_new_pc (CPUHexagonState *env,bool pkt_has_multi_cof, -target_ulong addr) -{ -HEX_DEBUG_LOG ("write_new_pc(0x" TARGET_FMT_lx")\n" , addr); - -if (pkt_has_multi_cof) { -/* -* If more than one branch is taken in a packet, only the first one -* is actually done. -*/ -if (env->branch_taken) { -HEX_DEBUG_LOG ("INFO: multiple branches taken in same packet, " -"ignoring the second one\n" ); - }else { -fCHECK_PCALIGN (addr); - env->gpr[HEX_REG_PC ] = addr; - env->branch_taken =1 ; - } - }else { -fCHECK_PCALIGN (addr); - env->gpr[HEX_REG_PC ] = addr; - } -} -/* Handy place to set a breakpoint */ void HELPER (debug_start_packet )(CPUHexagonState *env) {
Signature · 1 line
2.17.1
PATCH v2 5/6 Hexagon (target/hexagon) Analyze packet before generating TCG
In reply to Taylor SimpsonWe create a new generator that creates an analyze_<tag> function for each instruction. Currently, these functions record the writes to R, P, and C registers by calling ctx_log_reg_write[_pair] or ctx_log_pred_write.
During gen_start_packet, we invoke the analyze_<tag> function for each instruction in the packet, and we mark the implicit register and predicate writes.
Doing the analysis up front has several advantages
- We remove calls to ctx_log_* from gen_tcg_funcs.py and genptr.c
- After the analysis is performed, we can initialize hex_new_value for each of the predicated assignments rather than during TCG generation for the instructions
- This is a stepping stone for future work where the analysis will include the set of registers that are written. In cases where the packet doesn't have an overlap between the registers that are written and registers that are read, we can avoid the intermediate step of writing to hex_new_value. Note that other checks will also be needed (e.g., no instructions can raise an exception).
--- target/hexagon/insn.h | 3 + target/hexagon/translate.h | 43 ++-- target/hexagon/genptr.c | 5 +- target/hexagon/idef-parser/parser-helpers.c | 5 - target/hexagon/translate.c | 145 +++++++----- target/hexagon/README | 11 +- target/hexagon/gen_analyze_func_table.py | 52 +++++ target/hexagon/gen_analyze_funcs.py | 239 ++++++++++++++++++++ target/hexagon/gen_tcg_funcs.py | 21 -- target/hexagon/meson.build | 18 ++ 10 files changed, 428 insertions(+), 114 deletions(-) create mode 100755 target/hexagon/gen_analyze_func_table.py create mode 100755 target/hexagon/gen_analyze_funcs.py
target/hexagon/insn.h +3 -0
@@ -29,6 +29,7 @@ struct Packet;struct DisasContext ;typedef void (*SemanticInsn )(struct DisasContext *ctx); +typedef void (*AnalyzeInsn )(struct DisasContext *ctx);struct Instruction {SemanticInsn generate;/* pointer to genptr routine */
@@ -74,4 +75,6 @@ struct Packet {typedef struct Packet Packet ; +extern const AnalyzeInsn opcode_analyze[]; +#endif
target/hexagon/translate.h +24 -19
62 lines not on this page · raw message
target/hexagon/genptr.c +1 -4
@@ -149,6 +149,7 @@ void gen_log_pred_write(DisasContext *ctx, int pnum, TCGv val) hex_new_pred_value[pnum], base_val); }tcg_gen_ori_tl (hex_pred_written, hex_pred_written,1 << pnum); +set_bit (pnum, ctx->pregs_written);tcg_temp_free (base_val); }
@@ -231,7 +232,6 @@ static void gen_write_p3_0(DisasContext *ctx, TCGv control_reg)for (int i =0 ; i <NUM_PREGS ; i++) {tcg_gen_extract_tl (hex_p8, control_reg, i *8 ,8 );gen_log_pred_write (ctx, i, hex_p8); -ctx_log_pred_write (ctx, i); }tcg_temp_free (hex_p8); }
@@ -250,7 +250,6 @@ static inline void gen_write_ctrl_reg(DisasContext *ctx, int reg_num,gen_write_p3_0 (ctx, val); }else {gen_log_reg_write (reg_num, val); -ctx_log_reg_write (ctx, reg_num);if (reg_num ==HEX_REG_QEMU_PKT_CNT ) { ctx->num_packets =0 ; }
@@ -273,10 +272,8 @@ static inline void gen_write_ctrl_reg_pair(DisasContext *ctx, int reg_num,tcg_gen_extrh_i64_i32 (val32, val);gen_log_reg_write (reg_num +1 , val32);tcg_temp_free (val32); -ctx_log_reg_write (ctx, reg_num +1 ); }else {gen_log_reg_write_pair (reg_num, val); -ctx_log_reg_write_pair (ctx, reg_num);if (reg_num ==HEX_REG_QEMU_PKT_CNT ) { ctx->num_packets =0 ; ctx->num_insns =0 ;
target/hexagon/idef-parser/parser-helpers.c +0 -5
@@ -1438,10 +1438,6 @@ void gen_write_reg(Context *c, YYLTYPE *locp, HexValue *reg, HexValue *value) locp,"gen_log_reg_write(" , ®->reg.id,", " , &value_m, ");\n"); -OUT (c, - locp, -"ctx_log_reg_write(ctx, " , ®->reg.id, -");\n" );gen_rvalue_free (c, locp, reg);gen_rvalue_free (c, locp, &value_m); }
@@ -1894,7 +1890,6 @@ void gen_pred_assign(Context *c, YYLTYPE *locp, HexValue *left_pred,if (is_direct) {OUT (c, locp,"gen_log_pred_write(ctx, " , pred_id,", " , left_pred,");\n" ); -OUT (c, locp,"ctx_log_pred_write(ctx, " , pred_id,");\n" );gen_rvalue_free (c, locp, left_pred); }/* Free temporary value */
target/hexagon/translate.c +83 -62
188 lines not on this page · raw message
target/hexagon/README +8 -3
@@ -52,6 +52,8 @@ header files in <BUILD_DIR>/target/hexagon gen_tcg_func_table.py -> tcg_func_table_generated.c.inc gen_helper_funcs.py -> helper_funcs_generated.c.inc gen_idef_parser_funcs.py -> idef_parser_input.h + gen_analyze_funcs.py -> analyze_funcs_generated.c.inc + gen_analyze_func_table.py -> analyze_func_table.c.inc Qemu helper functions have 3 parts DEF_HELPER declaration indicates the signature of the helper
@@ -87,7 +89,6 @@ tcg_funcs_generated.c.inc TCGv RtV = hex_gpr[insn->regno[2]]; gen_helper_A2_add(RdV, cpu_env, RsV, RtV); gen_log_reg_write(RdN, RdV); - ctx_log_reg_write(ctx, RdN); tcg_temp_free(RdV); }
@@ -162,7 +163,6 @@ istruction. gen_helper_V6_vaddw(cpu_env, VdV, VuV, VvV, slot); tcg_temp_free(slot); gen_log_vreg_write(ctx, VdV_off, VdN, EXT_DFL, insn->slot, false); - ctx_log_vreg_write(ctx, VdN, EXT_DFL, false); tcg_temp_free_ptr(VdV); tcg_temp_free_ptr(VuV); tcg_temp_free_ptr(VvV);
@@ -195,9 +195,14 @@ when the override is present. vreg_src_off(ctx, VvN); fGEN_TCG_V6_vaddw({ fHIDE(int i;) fVFOREACH(32, i) { VdV.w[i] = VuV.w[i] + VvV.w[i] ; } }); gen_log_vreg_write(ctx, VdV_off, VdN, EXT_DFL, insn->slot, false); - ctx_log_vreg_write(ctx, VdN, EXT_DFL, false); } +We also generate an analyze_<tag> function for each instruction. Currently, +these functions record the writes to registers by calling ctx_log_*. During +gen_start_packet, we invoke the analyze_<tag> function for each instruction in +the packet, and we mark the implicit writes. After the analysis is performed, +we initialize hex_new_value for each of the predicated assignments. + In addition to instruction semantics, we use a generator to create the decode tree. This generation is also a two step process. The first step is to run target/hexagon/gen_dectree_import.c to produce
target/hexagon/gen_analyze_func_table.py new file +52 -0
52 lines not on this page · raw message
target/hexagon/gen_analyze_funcs.py new file +239 -0
239 lines not on this page · raw message
target/hexagon/gen_tcg_funcs.py +0 -21
@@ -44,15 +44,6 @@ def genptr_decl_pair_writable(f, tag, regtype, regid, regno): (regN, regno)) else: f.write(" const int %s = insn->regno[%d];\n" % (regN, regno)) - if ('A_CONDEXEC' in hex_common.attribdict[tag]): - f.write(" if (!is_preloaded(ctx, %s)) {\n" % regN) - f.write(" tcg_gen_mov_tl(hex_new_value[%s], hex_gpr[%s]);\n" % \ - (regN, regN)) - f.write(" }\n") - f.write(" if (!is_preloaded(ctx, %s + 1)) {\n" % regN) - f.write(" tcg_gen_mov_tl(hex_new_value[%s + 1], hex_gpr[%s + 1]);\n" % \ - (regN, regN)) - f.write(" }\n") def genptr_decl_writable(f, tag, regtype, regid, regno): regN="%s%sN" % (regtype,regid)
@@ -63,11 +54,6 @@ def genptr_decl_writable(f, tag, regtype, regid, regno): (regN, regno)) else: f.write(" const int %s = insn->regno[%d];\n" % (regN, regno)) - if ('A_CONDEXEC' in hex_common.attribdict[tag]): - f.write(" if (!is_preloaded(ctx, %s)) {\n" % regN) - f.write(" tcg_gen_mov_tl(hex_new_value[%s], hex_gpr[%s]);\n" % \ - (regN, regN)) - f.write(" }\n") def genptr_decl(f, tag, regtype, regid, regno): regN="%s%sN" % (regtype,regid)
@@ -465,8 +451,6 @@ def genptr_dst_write_pair(f, tag, regtype, regid): else: f.write(" gen_log_reg_write_pair(%s%sN, %s%sV);\n" % \ (regtype, regid, regtype, regid)) - f.write(" ctx_log_reg_write_pair(ctx, %s%sN);\n" % \ - (regtype, regid)) def genptr_dst_write(f, tag, regtype, regid): if (regtype == "R"):
@@ -480,16 +464,12 @@ def genptr_dst_write(f, tag, regtype, regid): else: f.write(" gen_log_reg_write(%s%sN, %s%sV);\n" % \ (regtype, regid, regtype, regid)) - f.write(" ctx_log_reg_write(ctx, %s%sN);\n" % \ - (regtype, regid)) else: print("Bad register parse: ", regtype, regid) elif (regtype == "P"): if (regid in {"d", "e", "x"}): f.write(" gen_log_pred_write(ctx, %s%sN, %s%sV);\n" % \ (regtype, regid, regtype, regid)) - f.write(" ctx_log_pred_write(ctx, %s%sN);\n" % \ - (regtype, regid)) else: print("Bad register parse: ", regtype, regid) elif (regtype == "C"):
@@ -581,7 +561,6 @@ def genptr_dst_write_opn(f,regtype, regid, tag): ## TCGv RtV = hex_gpr[insn->regno[2]]; ## <GEN> ## gen_log_reg_write(RdN, RdV); -## ctx_log_reg_write(ctx, RdN); ## tcg_temp_free(RdV); ## } ##
target/hexagon/meson.build +18 -0
@@ -67,6 +67,24 @@ tcg_func_table_generated = custom_target( ) hexagon_ss.add(tcg_func_table_generated) +analyze_funcs_generated = custom_target( + 'analyze_funcs_generated.c.inc', + output: 'analyze_funcs_generated.c.inc', + depends: [semantics_generated], + depend_files: [hex_common_py, attribs_def, gen_tcg_h, gen_tcg_hvx_h], + command: [python, files('gen_analyze_funcs.py'), semantics_generated, attribs_def, gen_tcg_h, gen_tcg_hvx_h, '@OUTPUT@'], +) +hexagon_ss.add(analyze_funcs_generated) + +analyze_func_table_generated = custom_target( + 'analyze_func_table_generated.c.inc', + output: 'analyze_func_table_generated.c.inc', + depends: [semantics_generated], + depend_files: [hex_common_py, attribs_def], + command: [python, files('gen_analyze_func_table.py'), semantics_generated, attribs_def, '@OUTPUT@'], +) +hexagon_ss.add(analyze_func_table_generated) + printinsn_generated = custom_target( 'printinsn_generated.h.inc', output: 'printinsn_generated.h.inc',
Signature · 1 line
2.17.1
PATCH v2 6/6 Hexagon (target/hexagon) Analyze packet step 2
In reply to Taylor SimpsonAnalyze HVX vector and predicate registers
--- target/hexagon/translate.h | 14 ++++++++------ target/hexagon/translate.c | 28 ++++++++++++++++++++++++++++ target/hexagon/gen_analyze_funcs.py | 17 ++++++++++++++--- target/hexagon/gen_tcg_funcs.py | 18 ------------------ 4 files changed, 50 insertions(+), 27 deletions(-)
target/hexagon/translate.h +8 -6
@@ -54,6 +54,8 @@ typedef struct DisasContext {DECLARE_BITMAP (vregs_updated_tmp,NUM_VREGS );DECLARE_BITMAP (vregs_updated,NUM_VREGS );DECLARE_BITMAP (vregs_select,NUM_VREGS ); +DECLARE_BITMAP (predicated_future_vregs,NUM_VREGS ); +DECLARE_BITMAP (predicated_tmp_vregs,NUM_VREGS );int qreg_log[NUM_QREGS ];bool qreg_is_predicated[NUM_QREGS ];int qreg_log_idx;
@@ -95,12 +97,6 @@ static inline void ctx_log_reg_write_pair(DisasContext *ctx, int rnum,ctx_log_reg_write (ctx, rnum +1 , is_predicated); } -static inline bool is_vreg_preloaded (DisasContext *ctx,int num) -{ -return test_bit (num, ctx->vregs_updated) || -test_bit (num, ctx->vregs_updated_tmp); -} -intptr_t ctx_future_vreg_off (DisasContext *ctx,int regnum,int num,bool alloc_ok); intptr_t ctx_tmp_vreg_off(DisasContext *ctx, int regnum,
@@ -116,12 +112,18 @@ static inline void ctx_log_vreg_write(DisasContext *ctx, ctx->vreg_log_idx++;set_bit (rnum, ctx->vregs_updated); +if (is_predicated) { +set_bit (rnum, ctx->predicated_future_vregs); + } }if (type ==EXT_NEW ) {set_bit (rnum, ctx->vregs_select); }if (type ==EXT_TMP ) {set_bit (rnum, ctx->vregs_updated_tmp); +if (is_predicated) { +set_bit (rnum, ctx->predicated_tmp_vregs); + } } }
target/hexagon/translate.c +28 -0
@@ -356,6 +356,8 @@ static void gen_start_packet(DisasContext *ctx)bitmap_zero (ctx->vregs_updated_tmp,NUM_VREGS );bitmap_zero (ctx->vregs_updated,NUM_VREGS );bitmap_zero (ctx->vregs_select,NUM_VREGS ); +bitmap_zero (ctx->predicated_future_vregs,NUM_VREGS ); +bitmap_zero (ctx->predicated_tmp_vregs,NUM_VREGS ); ctx->qreg_log_idx =0 ;for (i =0 ; i <STORES_MAX ; i++) { ctx->store_width[i] =0 ;
@@ -395,6 +397,32 @@ static void gen_start_packet(DisasContext *ctx) i + 1); } } +if (!bitmap_empty (ctx->predicated_future_vregs,NUM_VREGS )) { +int i =find_first_bit (ctx->predicated_future_vregs,NUM_VREGS ); +while (i <NUM_VREGS ) { +const intptr_t VdV_off = +ctx_future_vreg_off (ctx, i,1 , true); + intptr_t src_off = offsetof(CPUHexagonState, VRegs[i]); +tcg_gen_gvec_mov (MO_64 , VdV_off, + src_off, +sizeof (MMVector), +sizeof (MMVector)); + i =find_next_bit (ctx->predicated_future_vregs,NUM_VREGS , i +1 ); + } + } +if (!bitmap_empty (ctx->predicated_tmp_vregs,NUM_VREGS )) { +int i =find_first_bit (ctx->predicated_tmp_vregs,NUM_VREGS ); +while (i <NUM_VREGS ) { +const intptr_t VdV_off = +ctx_tmp_vreg_off (ctx, i,1 , true); + intptr_t src_off = offsetof(CPUHexagonState, VRegs[i]); +tcg_gen_gvec_mov (MO_64 , VdV_off, + src_off, +sizeof (MMVector), +sizeof (MMVector)); + i =find_next_bit (ctx->predicated_tmp_vregs,NUM_VREGS , i +1 ); + } + }if (pkt->pkt_has_hvx) {tcg_gen_movi_tl (hex_VRegs_updated,0 );
target/hexagon/gen_analyze_funcs.py +14 -3
@@ -83,9 +83,16 @@ def analyze_opn_old(f, tag, regtype, regid, regno): else: print("Bad register parse: ", regtype, regid) elif (regtype == "V"): + newv = "EXT_DFL" + if (hex_common.is_new_result(tag)): + newv = "EXT_NEW" + elif (hex_common.is_tmp_result(tag)): + newv = "EXT_TMP" if (regid in {"dd", "xx"}): - f.write("// const int %s = insn->regno[%d];\n" %\ + f.write(" const int %s = insn->regno[%d];\n" %\ (regN, regno)) + f.write(" ctx_log_vreg_write_pair(ctx, %s, %s, %s);\n" % \ + (regN, newv, predicated)) elif (regid in {"uu", "vv"}): f.write("// const int %s = insn->regno[%d];\n" % \ (regN, regno))
@@ -93,14 +100,18 @@ def analyze_opn_old(f, tag, regtype, regid, regno): f.write("// const int %s = insn->regno[%d];\n" % \ (regN, regno)) elif (regid in {"d", "x", "y"}): - f.write("// const int %s = insn->regno[%d];\n" % \ + f.write(" const int %s = insn->regno[%d];\n" % \ (regN, regno)) + f.write(" ctx_log_vreg_write(ctx, %s, %s, %s);\n" % \ + (regN, newv, predicated)) else: print("Bad register parse: ", regtype, regid) elif (regtype == "Q"): if (regid in {"d", "e", "x"}): - f.write("// const int %s = insn->regno[%d];\n" % \ + f.write(" const int %s = insn->regno[%d];\n" % \ (regN, regno)) + f.write(" ctx_log_qreg_write(ctx, %s, %s);\n" % \ + (regN, predicated)) elif (regid in {"s", "t", "u", "v"}): f.write("// const int %s = insn->regno[%d];\n" % \ (regN, regno))
target/hexagon/gen_tcg_funcs.py +0 -18
@@ -159,17 +159,6 @@ def genptr_decl(f, tag, regtype, regid, regno): f.write(" ctx_future_vreg_off(ctx, %s%sN," % \ (regtype, regid)) f.write(" 1, true);\n"); - if 'A_CONDEXEC' in hex_common.attribdict[tag]: - f.write(" if (!is_vreg_preloaded(ctx, %s)) {\n" % (regN)) - f.write(" intptr_t src_off =") - f.write(" offsetof(CPUHexagonState, VRegs[%s%sN]);\n"% \ - (regtype, regid)) - f.write(" tcg_gen_gvec_mov(MO_64, %s%sV_off,\n" % \ - (regtype, regid)) - f.write(" src_off,\n") - f.write(" sizeof(MMVector),\n") - f.write(" sizeof(MMVector));\n") - f.write(" }\n") if (not hex_common.skip_qemu_helper(tag)): f.write(" TCGv_ptr %s%sV = tcg_temp_new_ptr();\n" % \
@@ -495,9 +484,6 @@ def genptr_dst_write_ext(f, tag, regtype, regid, newv="EXT_DFL"): (regtype, regid, regtype, regid)) f.write("%s, insn->slot, %s);\n" % \ (newv, is_predicated)) - f.write(" ctx_log_vreg_write_pair(ctx, %s%sN, %s,\n" % \ - (regtype, regid, newv)) - f.write(" %s);\n" % (is_predicated)) elif (regid in {"d", "x", "y"}): if ('A_CONDEXEC' in hex_common.attribdict[tag]): is_predicated = "true"
@@ -507,8 +493,6 @@ def genptr_dst_write_ext(f, tag, regtype, regid, newv="EXT_DFL"): (regtype, regid, regtype, regid, newv)) f.write("insn->slot, %s);\n" % \ (is_predicated)) - f.write(" ctx_log_vreg_write(ctx, %s%sN, %s, %s);\n" % \ - (regtype, regid, newv, is_predicated)) else: print("Bad register parse: ", regtype, regid) elif (regtype == "Q"):
@@ -520,8 +504,6 @@ def genptr_dst_write_ext(f, tag, regtype, regid, newv="EXT_DFL"): f.write(" gen_log_qreg_write(%s%sV_off, %s%sN, %s, " % \ (regtype, regid, regtype, regid, newv)) f.write("insn->slot, %s);\n" % (is_predicated)) - f.write(" ctx_log_qreg_write(ctx, %s%sN, %s);\n" % \ - (regtype, regid, is_predicated)) else: print("Bad register parse: ", regtype, regid) else:
Signature · 1 line
2.17.1