Hexagon (target/hexagon) performance and bug fixes
v3 cover Hexagon (target/hexagon) performance and bug fixes
1)
Performance improvement
Add pkt and insn to DisasContext
Many functions need information from all 3 structures, so merge them together.
2)
Bug fix
Fix predicated assignment to .tmp and .cur
3)
Performance improvement
Add overrides for S2_asr_r_r_sat/S2_asl_r_r_sat These functions will not be handled by idef-parser
4-11)
The final 8 patches improve change-of-flow handling.
Currently, we set the PC to a new address before exiting a TB. The ultimate goal is to use direct block chaining. However, several steps are needed along the way.
4)
When a packet has more than one change-of-flow (COF) instruction, only the first one taken is considered. The runtime bookkeeping is only needed when there is more than one COF instruction in a packet.
5, 6)
Remove PC and next_PC from the runtime state and always use a translation-time constant. Note that next_PC is used by call instructions to set LR and by conditional COF instructions to set the fall-through address.
7, 8, 9)
Add helper overrides for COF instructions. In particular, we must distinguish those that use a PC-relative address for the destination. These are candidates for direct block chaining later.
10)
Use direct block chaining for packets that have a single PC-relative COF instruction. Instead of generating the code while processing the instruction, we record the effect in DisasContext and generate the code during gen_end_tb.
11)
Use direct block chaining for tight loops. We look for TBs that end with an endloop0 that will branch back to the TB start address.
**** Changes in V3 ****
Merge previously emailed patches into single series Merge functions that check if vreg is preloaded
**** Changes in V2 ****
Update test case to use both true and false predicates
Add fix for .cur
Simplify test in need_pkt_has_multi_cof
Address feedback from Matheus Tavares Bernardino <[email protected]>
Rearrange new-value-jump overrides
Simplify gen_write_new_pc_addr
Taylor Simpson (11):
Hexagon (target/hexagon) Add pkt and insn to DisasContext Hexagon (target/hexagon) Fix predicated assignment to .tmp and .cur Hexagon (target/hexagon) Add overrides for
S2_asr_r_r_sat/S2_asl_r_r_sat
Hexagon (target/hexagon) Only use branch_taken when packet has multi
cof
Hexagon (target/hexagon) Remove PC from the runtime state Hexagon (target/hexagon) Remove next_PC from runtime state Hexagon (target/hexagon) Add overrides for direct call instructions Hexagon (target/hexagon) Add overrides for compound compare and jump Hexagon (target/hexagon) Add overrides for various forms of jump Hexagon (target/hexagon) Use direct block chaining for direct
jump/branch
Hexagon (target/hexagon) Use direct block chaining for tight loops
target/hexagon/cpu.h | 18 +- target/hexagon/gen_tcg.h | 400 +++++++++++++++++++++++++- target/hexagon/gen_tcg_hvx.h | 6 +- target/hexagon/insn.h | 9 +- target/hexagon/macros.h | 16 +- target/hexagon/mmvec/macros.h | 4 +- target/hexagon/translate.h | 21 +- target/hexagon/decode.c | 15 +- target/hexagon/genptr.c | 419 +++++++++++++++++++++++++++- target/hexagon/op_helper.c | 28 +- target/hexagon/translate.c | 235 +++++++++++----- tests/tcg/hexagon/hvx_misc.c | 72 +++++ tests/tcg/hexagon/usr.c | 30 +- target/hexagon/gen_helper_funcs.py | 13 +- target/hexagon/gen_helper_protos.py | 14 +- target/hexagon/gen_tcg_funcs.py | 38 ++- target/hexagon/hex_common.py | 29 +- 17 files changed, 1229 insertions(+), 138 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/11 Hexagon (target/hexagon) Add pkt and insn to DisasContext
This enables us to reduce the number of parameters to many functions In particular, the generated functions previously took all 3 as arguments
Not only does this simplify the code, it improves the translation time
--- target/hexagon/gen_tcg_hvx.h | 6 +- target/hexagon/insn.h | 7 +- target/hexagon/macros.h | 10 +-- target/hexagon/mmvec/macros.h | 4 +- target/hexagon/translate.h | 9 ++- target/hexagon/genptr.c | 6 +- target/hexagon/translate.c | 120 +++++++++++++++++--------------- target/hexagon/gen_tcg_funcs.py | 15 ++-- 8 files changed, 89 insertions(+), 88 deletions(-)
target/hexagon/gen_tcg_hvx.h +3 -3
@@ -1,5 +1,5 @@/* -* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +* Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -697,7 +697,7 @@ static inline void assert_vhist_tmp(DisasContext *ctx)#define fGEN_TCG_NEWVAL_VEC_STORE (GET_EA ,INC ) \ do { \ GET_EA; \ - gen_vreg_store(ctx, insn, pkt, EA, OsN_off, insn->slot, true); \ + gen_vreg_store(ctx, EA, OsN_off, insn->slot, true); \ INC; \ } while (0)
@@ -736,7 +736,7 @@ static inline void assert_vhist_tmp(DisasContext *ctx)PRED ; \tcg_gen_brcondi_tl (TCG_COND_EQ ,LSB ,0 , false_label); \tcg_temp_free (LSB ); \ -gen_vreg_store (ctx, insn, pkt,EA ,SRCOFF , insn->slot,ALIGN ); \ +gen_vreg_store (ctx,EA ,SRCOFF , insn->slot,ALIGN ); \INC ; \tcg_gen_br (end_label); \gen_set_label (false_label); \
target/hexagon/insn.h +2 -5
@@ -1,5 +1,5 @@/* -* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +* Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -28,10 +28,7 @@ struct Instruction;struct Packet ;struct DisasContext ; -typedef void (*SemanticInsn )(CPUHexagonState *env, -struct DisasContext *ctx, -struct Instruction *insn, -struct Packet *pkt); +typedef void (*SemanticInsn )(struct DisasContext *ctx);struct Instruction {SemanticInsn generate;/* pointer to genptr routine */
target/hexagon/macros.h +5 -5
@@ -94,9 +94,9 @@*/ #define CHECK_NOSHUF (VA ,SIZE ) \ do { \ - if (insn->slot == 0 && pkt->pkt_has_store_s1) { \ + if (insn->slot == 0 && ctx->pkt->pkt_has_store_s1) { \ probe_noshuf_load(VA, SIZE, ctx->mem_idx); \ - process_store(ctx, pkt, 1); \ + process_store(ctx, 1); \ } \ } while (0)
@@ -105,12 +105,12 @@TCGLabel *label =gen_new_label (); \tcg_gen_brcondi_tl (TCG_COND_EQ ,PRED ,0 , label); \GET_EA ; \ -if (insn->slot ==0 && pkt->pkt_has_store_s1) { \ +if (insn->slot ==0 && ctx->pkt->pkt_has_store_s1) { \probe_noshuf_load (EA ,SIZE , ctx->mem_idx); \ } \gen_set_label (label); \ -if (insn->slot ==0 && pkt->pkt_has_store_s1) { \ -process_store (ctx, pkt,1 ); \ +if (insn->slot ==0 && ctx->pkt->pkt_has_store_s1) { \ +process_store (ctx,1 ); \ } \ }while (0 )
target/hexagon/mmvec/macros.h +2 -2
@@ -288,7 +288,7 @@#endif #ifdef QEMU_GENERATE #define fSTOREMMV (EA ,SRC ) \ - gen_vreg_store(ctx, insn, pkt, EA, SRC##_off, insn->slot, true) + gen_vreg_store(ctx, EA, SRC##_off, insn->slot, true)#endif #ifdef QEMU_GENERATE #define fSTOREMMVQ (EA ,SRC ,MASK ) \
@@ -300,7 +300,7 @@#endif #ifdef QEMU_GENERATE #define fSTOREMMVU (EA ,SRC ) \ - gen_vreg_store(ctx, insn, pkt, EA, SRC##_off, insn->slot, false) + gen_vreg_store(ctx, EA, 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 +6 -3
@@ -1,5 +1,5 @@/* -* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +* Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -23,10 +23,13 @@#include "cpu.h" #include "exec/translator.h" #include "tcg/tcg-op.h" +#include "insn.h" #include "internal.h" typedef struct DisasContext { DisasContextBase base; + Packet *pkt; + Insn *insn; uint32_t mem_idx; uint32_t num_packets; uint32_t num_insns;
@@ -147,6 +150,6 @@ extern TCGv hex_vstore_addr[VSTORES_MAX];extern TCGv hex_vstore_size[VSTORES_MAX ];extern TCGv hex_vstore_pending[VSTORES_MAX ]; -bool is_gather_store_insn (Insn *insn,Packet *pkt); -void process_store (DisasContext *ctx,Packet *pkt,int slot_num); +bool is_gather_store_insn (DisasContext *ctx); +void process_store (DisasContext *ctx,int slot_num);#endif
target/hexagon/genptr.c +3 -3
@@ -551,13 +551,13 @@ static void gen_vreg_load(DisasContext *ctx, intptr_t dstoff, TCGv src,tcg_temp_free_i64 (tmp); } -static void gen_vreg_store (DisasContext *ctx,Insn *insn,Packet *pkt, -TCGv EA ,intptr_t srcoff,int slot,bool aligned) +static void gen_vreg_store (DisasContext *ctx,TCGv EA ,intptr_t srcoff, +int slot,bool aligned) { intptr_t dstoff = offsetof(CPUHexagonState, vstore[slot].data); intptr_t maskoff = offsetof(CPUHexagonState, vstore[slot].mask); -if (is_gather_store_insn (insn, pkt)) { +if (is_gather_store_insn (ctx)) {TCGv sl =tcg_constant_tl (slot);gen_helper_gather_store (cpu_env,EA , sl);return ;
target/hexagon/translate.c +63 -57
270 lines not on this page · raw message
target/hexagon/gen_tcg_funcs.py +5 -10
@@ -561,11 +561,7 @@ def genptr_dst_write_opn(f,regtype, regid, tag): ## Generate the TCG code to call the helper ## For A2_add: Rd32=add(Rs32,Rt32), { RdV=RsV+RtV;} ## We produce: -## static void generate_A2_add() -## CPUHexagonState *env -## DisasContext *ctx, -## Insn *insn, -## Packet *pkt) +## static void generate_A2_add(DisasContext *ctx) ## { ## TCGv RdV = tcg_temp_local_new(); ## const int RdN = insn->regno[0];
@@ -584,12 +580,11 @@ def genptr_dst_write_opn(f,regtype, regid, tag): ## <GEN> is gen_helper_A2_add(RdV, cpu_env, RsV, RtV); ## def gen_tcg_func(f, tag, regs, imms): - f.write("static void generate_%s(\n" %tag) - f.write(" CPUHexagonState *env,\n") - f.write(" DisasContext *ctx,\n") - f.write(" Insn *insn,\n") - f.write(" Packet *pkt)\n") + f.write("static void generate_%s(DisasContext *ctx)\n" %tag) f.write('{\n') + + f.write(" Insn *insn __attribute__((unused)) = ctx->insn;\n") + if hex_common.need_ea(tag): gen_decl_ea_tcg(f, tag) i=0 ## Declare all the operands (regs and immediates)
Signature · 1 line
2.17.1
Re: [PATCH v3 01/11] Hexagon (target/hexagon) Add pkt and insn to DisasContext
Quoted 6 lines · Taylor Simpson
This enables us to reduce the number of parameters to many functions In particular, the generated functions previously took all 3 as arguments
Not only does this simplify the code, it improves the translation time
Signed-off-by Taylor Simpson<[email protected]>
Quoted 10 lines
--- target/hexagon/gen_tcg_hvx.h | 6 +- target/hexagon/insn.h | 7 +- target/hexagon/macros.h | 10 +-- target/hexagon/mmvec/macros.h | 4 +- target/hexagon/translate.h | 9 ++- target/hexagon/genptr.c | 6 +- target/hexagon/translate.c | 120 +++++++++++++++++--------------- target/hexagon/gen_tcg_funcs.py | 15 ++-- 8 files changed, 89 insertions(+), 88 deletions(-)
r~
PATCH v3 2/11 Hexagon (target/hexagon) Fix predicated assignment to .tmp and .cur
In reply to Taylor SimpsonHere are example instructions with a predicated .tmp/.cur assignment
if (p1) v12.tmp = vmem(r7 + #0)
if (p0) v12.cur = vmem(r9 + #0)The .tmp/.cur indicates that references to v12 in the same packet take the result of the load. However, when the predicate is false, the value at the start of the packet should be used. After the packet commits, the .tmp value is dropped, but the .cur value is maintained.
To fix this bug, we preload the original value from the HVX register into the temporary used for the result.
Test cases added to tests/tcg/hexagon/hvx_misc.c
--- target/hexagon/translate.h | 6 +++ tests/tcg/hexagon/hvx_misc.c | 72 +++++++++++++++++++++++++++++++++ target/hexagon/gen_tcg_funcs.py | 12 ++++++ 3 files changed, 90 insertions(+)
target/hexagon/translate.h +6 -0
@@ -86,6 +86,12 @@ static inline bool is_preloaded(DisasContext *ctx, int num)return test_bit (num, ctx->regs_written); } +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,
tests/tcg/hexagon/hvx_misc.c +72 -0
84 lines not on this page · raw message
target/hexagon/gen_tcg_funcs.py +12 -0
@@ -173,6 +173,18 @@ 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" % \ (regtype, regid))
Signature · 1 line
2.17.1
Re: [PATCH v3 02/11] Hexagon (target/hexagon) Fix predicated assignment to .tmp and .cur
Quoted 13 lines · Taylor Simpson
Here are example instructions with a predicated .tmp/.cur assignment
if (p1) v12.tmp = vmem(r7 + #0) if (p0) v12.cur = vmem(r9 + #0)The .tmp/.cur indicates that references to v12 in the same packet take the result of the load. However, when the predicate is false, the value at the start of the packet should be used. After the packet commits, the .tmp value is dropped, but the .cur value is maintained.
To fix this bug, we preload the original value from the HVX register into the temporary used for the result.
Test cases added to
tests/tcg/hexagon/hvx_misc.c
Quoted 8 lines
Co-authored-by Matheus Tavares Bernardino<[email protected]>Signed-off-by Matheus Tavares Bernardino<[email protected]>Signed-off-by Taylor Simpson<[email protected]>--- target/hexagon/translate.h | 6 +++ tests/tcg/hexagon/hvx_misc.c | 72 +++++++++++++++++++++++++++++++++ target/hexagon/gen_tcg_funcs.py | 12 ++++++ 3 files changed, 90 insertions(+)
r~
PATCH v3 3/11 Hexagon (target/hexagon) Add overrides for S2_asr_r_r_sat/S2_asl_r_r_sat
In reply to Taylor SimpsonThese instructions will not be generated by idef-parser, so we override them manually.
Test cases added to tests/tcg/hexagon/usr.c
--- target/hexagon/gen_tcg.h | 10 ++- target/hexagon/genptr.c | 173 +++++++++++++++++++++++++++++++++++++++ tests/tcg/hexagon/usr.c | 30 +++++-- 3 files changed, 206 insertions(+), 7 deletions(-)
target/hexagon/gen_tcg.h +9 -1
@@ -1,5 +1,5 @@/* -* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +* Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -612,6 +612,14 @@tcg_temp_free (tmp); \ }while (0 ) +/* r0 = asr(r1, r2):sat */ +#define fGEN_TCG_S2_asr_r_r_sat (SHORTCODE ) \ + gen_asr_r_r_sat(RdV, RsV, RtV) + +/* r0 = asl(r1, r2):sat */ +#define fGEN_TCG_S2_asl_r_r_sat (SHORTCODE ) \ + gen_asl_r_r_sat(RdV, RsV, RtV) +/* Floating point */ #define fGEN_TCG_F2_conv_sf2df (SHORTCODE ) \ gen_helper_conv_sf2df(RddV, cpu_env, RsV)
target/hexagon/genptr.c +173 -0
179 lines not on this page · raw message
tests/tcg/hexagon/usr.c +24 -6
@@ -429,6 +429,7 @@ FUNC_P_OP_P(vabshsat, "%0 = vabsh(%2):sat") FUNC_P_OP_PP(vnavgwr, "%0 = vnavgw(%2, %3):rnd:sat") FUNC_R_OP_RI(round_ri_sat, "%0 = round(%2, #%3):sat") FUNC_R_OP_RR(asr_r_r_sat, "%0 = asr(%2, %3):sat") +FUNC_R_OP_RR(asl_r_r_sat, "%0 = asl(%2, %3):sat")FUNC_XPp_OP_PP (ACS ,"%0, p2 = vacsh(%3, %4)" )
@@ -907,12 +908,29 @@ int main()TEST_R_OP_RI (round_ri_sat,0x0000ffff ,2 ,0x00004000 ,USR_CLEAR );TEST_R_OP_RI (round_ri_sat,0x7fffffff ,2 ,0x1fffffff ,USR_OVF ); -TEST_R_OP_RR (asr_r_r_sat,0x0000ffff ,0x00000002 ,0x00003fff , -USR_CLEAR ); -TEST_R_OP_RR (asr_r_r_sat,0x00ffffff ,0xfffffff5 ,0x7fffffff , -USR_OVF ); -TEST_R_OP_RR (asr_r_r_sat,0x80000000 ,0xfffffff5 ,0x80000000 , -USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,0x0000ffff ,0x02 ,0x00003fff ,USR_CLEAR ); +TEST_R_OP_RR (asr_r_r_sat,0x80000000 ,0x01 ,0xc0000000 ,USR_CLEAR ); +TEST_R_OP_RR (asr_r_r_sat,0xffffffff ,0x01 ,0xffffffff ,USR_CLEAR ); +TEST_R_OP_RR (asr_r_r_sat,0x00ffffff ,0xf5 ,0x7fffffff ,USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,0x80000000 ,0xf5 ,0x80000000 ,USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,0x7fff0000 ,0x42 ,0x7fffffff ,USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,0xff000000 ,0x42 ,0x80000000 ,USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,4096 ,32 ,0x00000000 ,USR_CLEAR ); +TEST_R_OP_RR (asr_r_r_sat,4096 ,-32 ,0x7fffffff ,USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,-4096 ,32 ,0xffffffff ,USR_CLEAR ); +TEST_R_OP_RR (asr_r_r_sat,-4096 ,-32 ,0x80000000 ,USR_OVF ); + +TEST_R_OP_RR (asl_r_r_sat,0x00000000 ,0x40 ,0x00000000 ,USR_CLEAR ); +TEST_R_OP_RR (asl_r_r_sat,0x80000000 ,0xff ,0xc0000000 ,USR_CLEAR ); +TEST_R_OP_RR (asl_r_r_sat,0xffffffff ,0xff ,0xffffffff ,USR_CLEAR ); +TEST_R_OP_RR (asl_r_r_sat,0x00ffffff ,0x0b ,0x7fffffff ,USR_OVF ); +TEST_R_OP_RR (asl_r_r_sat,0x80000000 ,0x0b ,0x80000000 ,USR_OVF ); +TEST_R_OP_RR (asl_r_r_sat,0x7fff0000 ,0xbe ,0x7fffffff ,USR_OVF ); +TEST_R_OP_RR (asl_r_r_sat,0xff000000 ,0xbe ,0x80000000 ,USR_OVF ); +TEST_R_OP_RR (asl_r_r_sat,4096 ,32 ,0x7fffffff ,USR_OVF ); +TEST_R_OP_RR (asl_r_r_sat,4096 ,-32 ,0x00000000 ,USR_CLEAR ); +TEST_R_OP_RR (asl_r_r_sat,-4096 ,32 ,0x80000000 ,USR_OVF ); +TEST_R_OP_RR (asl_r_r_sat,-4096 ,-32 ,0xffffffff ,USR_CLEAR ); TEST_XPp_OP_PP(ACS, 0x0004000300020001ULL, 0x0001000200030004ULL, 0x0000000000000000ULL, 0x0004000300030004ULL, 0xf0,
Signature · 1 line
2.17.1
Re: [PATCH v3 03/11] Hexagon (target/hexagon) Add overrides for S2_asr_r_r_sat/S2_asl_r_r_sat
target/hexagon/genptr.c static TCGv gen_8bitsof(TCGv result, TCGv value) · line 465
Quoted 7 lines · Taylor Simpson
target/hexagon/genptr.c +7
-0+static void gen_set_usr_field (int field,TCGv val) +{ +tcg_gen_deposit_tl (hex_new_value[HEX_REG_USR ], hex_new_value[HEX_REG_USR ], + val, + reg_field_info[field].offset, + reg_field_info[field].width); +}
If you plan to use this for something else, fine, but since you're never clearing USR_OVF, it would be better to use tcg_gen_ori_tl.
Quoted 5 lines
target/hexagon/genptr.c +5
-0+static void gen_sat_i64 (TCGv_i64 dst,TCGv_i64 src,uint32_t bits) +{ +TCGLabel *label =gen_new_label (); + +tcg_gen_sextract_i64 (dst, src,0 , bits);
target/hexagon/genptr.c static TCGv gen_8bitsof(TCGv result, TCGv value) · line 487
Quoted 10 lines
target/hexagon/genptr.c +10
-0+tcg_gen_brcond_i64 (TCG_COND_EQ , dst, src, label); + { +TCGv_i64 min =tcg_constant_i64 (-(1LL << (bits -1 ))); +TCGv_i64 max =tcg_constant_i64 ((1LL << (bits -1 )) -1 ); +tcg_gen_movcond_i64 (TCG_COND_LT , dst, src,tcg_constant_i64 (0 ), + min, max); +gen_set_usr_fieldi (USR_OVF ,1 ); + } +gen_set_label (label); +}
This could be done branchless:
tcg_gen_smax_i64(dst, src, min); tcg_gen_smin_i64(dst, dst, max); tcg_gen_setcond_i64(TCG_COND_NE, o_64, dst, src); tcg_gen_trunc_i64_tl(o_tl, o_64); tcg_gen_shli_tl(o_tl, reg_field_info[USE_OVF].offset); tcg_gen_or_tl(hex_new_value[HEX_REG_USR], hex_new_value[HEX_REG_USR], o_tl);
target/hexagon/genptr.c static TCGv gen_8bitsof(TCGv result, TCGv value) · line 497
Quoted 9 lines
target/hexagon/genptr.c +9
-0+static void gen_satval (TCGv_i64 dest,TCGv_i64 source,uint32_t bits) +{ +TCGv_i64 min =tcg_constant_i64 (-(1LL << (bits -1 ))); +TCGv_i64 max =tcg_constant_i64 ((1LL << (bits -1 )) -1 ); + +gen_set_usr_fieldi (USR_OVF ,1 ); +tcg_gen_movcond_i64 (TCG_COND_LT , dest, source,tcg_constant_i64 (0 ), + min, max); +}
Likewise.
target/hexagon/genptr.c static TCGv gen_8bitsof(TCGv result, TCGv value) · line 511
Quoted 13 lines
target/hexagon/genptr.c +13
-0+/* Shift left with saturation */ +static void gen_shl_sat (TCGv RdV,TCGv RsV,TCGv shift_amt) +{ +/* +* int64_t A = (fCAST4_8s(RsV) << shift_amt; +* if (((int32_t)((fSAT(A)) ^ ((int32_t)(RsV)))) < 0) { +* RdV = fSATVALN(32, ((int32_t)(RsV))) +* } else if (((RsV) > 0) && ((A) == 0)) { +* RdV = fSATVALN(32, (RsV)); +* } else { +* RdV = fSAT(A); +* } +*/
A little bit tricky to follow, but is this overflow condition to be the same as
x_32 = rsv << shift_amt;
y_32 = x_32 >> shift_amt;
overflow = x_32 != y_32;i.e. overflow if we've lost bits that are not copies of the sign bit (and thus restored by the arithmetic right shift)?
target/hexagon/genptr.c static TCGv gen_8bitsof(TCGv result, TCGv value) · line 528
Quoted 6 lines
target/hexagon/genptr.c +6
-0+tcg_gen_ext_i32_i64 (RsV_i64, RsV); +tcg_gen_ext_i32_i64 (shift_amt_i64, shift_amt); +tcg_gen_shl_i64 (A , RsV_i64, shift_amt_i64); + +/* Check for saturation */ +gen_sat_i64 (A_sat_i64,A ,32 );
Setting USR_OVF here...
target/hexagon/genptr.c static TCGv gen_8bitsof(TCGv result, TCGv value) · line 532
Quoted 4 lines
target/hexagon/genptr.c +4
-0+tcg_gen_extrl_i64_i32 (A_sat, A_sat_i64); +tcg_gen_xor_tl (tmp, A_sat, RsV); +tcg_gen_brcondi_tl (TCG_COND_GE , tmp,0 , label1); +gen_satval (RdV_i64, RsV_i64,32 );
... and also here. Is this also computing the same saturation value that you did above?
target/hexagon/genptr.c static TCGv gen_8bitsof(TCGv result, TCGv value) · line 539
Quoted 7 lines
target/hexagon/genptr.c +7
-0+tcg_gen_extrl_i64_i32 (RdV, RdV_i64); +tcg_gen_br (done); + +gen_set_label (label1); +tcg_gen_brcondi_tl (TCG_COND_LE , RsV,0 , label2); +tcg_gen_brcondi_i64 (TCG_COND_NE ,A ,0 , label2); +gen_satval (RdV_i64, RsV_i64,32 );
and again?
Quoted 30 lines
target/hexagon/genptr.c +30
-0+tcg_gen_extrl_i64_i32 (RdV, RdV_i64); +tcg_gen_br (done); + +gen_set_label (label2); +tcg_gen_mov_tl (RdV, A_sat); + +gen_set_label (done); + +tcg_temp_free_i64 (RsV_i64); +tcg_temp_free_i64 (shift_amt_i64); +tcg_temp_free_i64 (A ); +tcg_temp_free_i64 (A_sat_i64); +tcg_temp_free (A_sat); +tcg_temp_free_i64 (RdV_i64); +tcg_temp_free (tmp); +} + +static void gen_sar (TCGv RdV,TCGv RsV,TCGv shift_amt) +{ +/* +* if (shift_amt < 32) { +* RdV = sar(RsV, shift_amt); +* } else { +* if (RsV > 0) { +* RdV = 0; +* } else { +* RdV = ~0; +* } +* } +*/
target/hexagon/genptr.c static TCGv gen_8bitsof(TCGv result, TCGv value) · line 579
Quoted 10 lines
target/hexagon/genptr.c +10
-0+TCGLabel *shift_ge_32 =gen_new_label (); +TCGLabel *done =gen_new_label (); + +tcg_gen_brcondi_tl (TCG_COND_GE , shift_amt,32 , shift_ge_32); +tcg_gen_sar_tl (RdV, RsV, shift_amt); +tcg_gen_br (done); + +gen_set_label (shift_ge_32); +tcg_gen_movcond_tl (TCG_COND_LT , RdV, RsV,tcg_constant_tl (0 ), +tcg_constant_tl (~0 ),tcg_constant_tl (0 ));
This is better done as
shift = min(shift, 31);
rdv = rsv >> shift;without branches.
r~
PATCH v3 4/11 Hexagon (target/hexagon) Only use branch_taken when packet has multi cof
In reply to Taylor SimpsonWhen a packet has more than one change-of-flow instruction, only the first one to branch is considered. We use the branch_taken variable to keep track of this.
However, when there is a single cof instruction, we don't need the same amount of bookkeeping.
We add the pkt_has_multi_cof member to the Packet structure, and pass this information to the needed functions.
When there is a generated helper function with cof, the generator will pass this pkt_has_multi_cof as a runtime value.
--- target/hexagon/insn.h | 1 + target/hexagon/macros.h | 2 +- target/hexagon/decode.c | 15 +++++++++++++-- target/hexagon/op_helper.c | 24 +++++++++++++++--------- target/hexagon/translate.c | 4 +++- target/hexagon/gen_helper_funcs.py | 5 ++++- target/hexagon/gen_helper_protos.py | 8 ++++++-- target/hexagon/gen_tcg_funcs.py | 5 +++++ target/hexagon/hex_common.py | 3 +++ 9 files changed, 51 insertions(+), 16 deletions(-)
target/hexagon/insn.h +1 -0
@@ -57,6 +57,7 @@ struct Packet {/* Pre-decodes about COF */ bool pkt_has_cof;/* Has any change-of-flow */ +bool pkt_has_multi_cof;/* Has more than one change-of-flow */ bool pkt_has_endloop;bool pkt_has_dczeroa;
target/hexagon/macros.h +1 -1
@@ -407,7 +407,7 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)#define fCHECK_PCALIGN (A ) -#define fWRITE_NPC (A ) write_new_pc(env, A) +#define fWRITE_NPC (A ) write_new_pc(env, pkt_has_multi_cof != 0, A)#define fBRANCH (LOC ,TYPE ) fWRITE_NPC(LOC)#define fJUMPR (REGNO ,TARGET ,TYPE ) fBRANCH(TARGET, COF_TYPE_JUMPR)
target/hexagon/decode.c +13 -2
@@ -388,6 +388,7 @@ static void decode_set_insn_attr_fields(Packet *pkt)uint16_t opcode; pkt->pkt_has_cof = false; + pkt->pkt_has_multi_cof = false; pkt->pkt_has_endloop = false; pkt->pkt_has_dczeroa = false;
@@ -412,13 +413,23 @@ static void decode_set_insn_attr_fields(Packet *pkt) } } - pkt->pkt_has_cof |=decode_opcode_can_jump (opcode); +if (decode_opcode_can_jump (opcode)) { +if (pkt->pkt_has_cof) { + pkt->pkt_has_multi_cof = true; + } + pkt->pkt_has_cof = true; + } pkt->insn[i].is_endloop =decode_opcode_ends_loop (opcode); pkt->pkt_has_endloop |= pkt->insn[i].is_endloop; - pkt->pkt_has_cof |= pkt->pkt_has_endloop; +if (pkt->pkt_has_endloop) { +if (pkt->pkt_has_cof) { + pkt->pkt_has_multi_cof = true; + } + pkt->pkt_has_cof = true; + } } }
target/hexagon/op_helper.c +15 -9
@@ -104,20 +104,26 @@ static void log_store64(CPUHexagonState *env, target_ulong addr, env->mem_log_stores[slot].data64 = val; } -static void write_new_pc (CPUHexagonState *env,target_ulong addr) +static 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 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" ); +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->next_PC = addr; + env->branch_taken =1 ; + } }else {fCHECK_PCALIGN (addr); - env->branch_taken =1 ; env->next_PC = addr; } }
target/hexagon/translate.c +3 -1
@@ -248,7 +248,9 @@ static void gen_start_packet(DisasContext *ctx)tcg_gen_movi_tl (hex_slot_cancelled,0 ); }if (pkt->pkt_has_cof) { -tcg_gen_movi_tl (hex_branch_taken,0 ); +if (pkt->pkt_has_multi_cof) { +tcg_gen_movi_tl (hex_branch_taken,0 ); + }tcg_gen_movi_tl (hex_next_PC, next_PC); }if (need_pred_written (pkt)) {
target/hexagon/gen_helper_funcs.py +4 -1
@@ -1,7 +1,7 @@ #!/usr/bin/env python3 ## -## Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +## Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved. ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by
@@ -238,6 +238,9 @@ def gen_helper_function(f, tag, tagregs, tagimms): gen_helper_arg_imm(f,immlett) i += 1 + if (hex_common.need_pkt_has_multi_cof(tag)): + f.write(", uint32_t pkt_has_multi_cof") + if hex_common.need_slot(tag): if i > 0: f.write(", ") f.write("uint32_t slot")
target/hexagon/gen_helper_protos.py +6 -2
@@ -1,7 +1,7 @@ #!/usr/bin/env python3 ## -## Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +## Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved. ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by
@@ -82,6 +82,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): ## Figure out how many arguments the helper will take if (numscalarresults == 0): def_helper_size = len(regs)+len(imms)+numscalarreadwrite+1 + if hex_common.need_pkt_has_multi_cof(tag): def_helper_size += 1 if hex_common.need_part1(tag): def_helper_size += 1 if hex_common.need_slot(tag): def_helper_size += 1 f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag))
@@ -89,6 +90,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): f.write(', void' ) else: def_helper_size = len(regs)+len(imms)+numscalarreadwrite + if hex_common.need_pkt_has_multi_cof(tag): def_helper_size += 1 if hex_common.need_part1(tag): def_helper_size += 1 if hex_common.need_slot(tag): def_helper_size += 1 f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag))
@@ -126,7 +128,9 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): for immlett,bits,immshift in imms: f.write(", s32") - ## Add the arguments for the instruction slot and part1 (if needed) + ## Add the arguments for the instruction pkt_has_multi_cof, slot and + ## part1 (if needed) + if hex_common.need_pkt_has_multi_cof(tag): f.write(', i32') if hex_common.need_slot(tag): f.write(', i32' ) if hex_common.need_part1(tag): f.write(' , i32' ) f.write(')\n')
target/hexagon/gen_tcg_funcs.py +5 -0
@@ -622,6 +622,9 @@ def gen_tcg_func(f, tag, regs, imms): ## Generate the call to the helper for immlett,bits,immshift in imms: gen_helper_decl_imm(f,immlett) + if hex_common.need_pkt_has_multi_cof(tag): + f.write(" TCGv pkt_has_multi_cof = ") + f.write("tcg_constant_tl(ctx->pkt->pkt_has_multi_cof);\n") if hex_common.need_part1(tag): f.write(" TCGv part1 = tcg_constant_tl(insn->part1);\n") if hex_common.need_slot(tag):
@@ -654,6 +657,8 @@ def gen_tcg_func(f, tag, regs, imms): for immlett,bits,immshift in imms: gen_helper_call_imm(f,immlett) + if hex_common.need_pkt_has_multi_cof(tag): + f.write(", pkt_has_multi_cof") if hex_common.need_slot(tag): f.write(", slot") if hex_common.need_part1(tag): f.write(", part1" ) f.write(");\n")
target/hexagon/hex_common.py +3 -0
@@ -207,6 +207,9 @@ def need_part1(tag): def need_ea(tag): return re.compile(r"\bEA\b").search(semdict[tag]) +def need_pkt_has_multi_cof(tag): + return 'A_COF' in attribdict[tag] + def skip_qemu_helper(tag): return tag in overrides.keys()
Signature · 1 line
2.17.1
Re: [PATCH v3 04/11] Hexagon (target/hexagon) Only use branch_taken when packet has multi cof
Quoted 14 lines · Taylor Simpson
When a packet has more than one change-of-flow instruction, only the first one to branch is considered. We use the
branch_takenvariable to keep track of this.However, when there is a single cof instruction, we don't need the same amount of bookkeeping.
We add the
pkt_has_multi_cofmember to the Packet structure, and pass this information to the needed functions.When there is a generated helper function with cof, the generator will pass this
pkt_has_multi_cofas a runtime value.Signed-off-by Taylor Simpson<[email protected]>
Quoted 11 lines
--- target/hexagon/insn.h | 1 + target/hexagon/macros.h | 2 +- target/hexagon/decode.c | 15 +++++++++++++-- target/hexagon/op_helper.c | 24 +++++++++++++++--------- target/hexagon/translate.c | 4 +++- target/hexagon/gen_helper_funcs.py | 5 ++++- target/hexagon/gen_helper_protos.py | 8 ++++++-- target/hexagon/gen_tcg_funcs.py | 5 +++++ target/hexagon/hex_common.py | 3 +++ 9 files changed, 51 insertions(+), 16 deletions(-)
r~
PATCH v3 5/11 Hexagon (target/hexagon) Remove PC from the runtime state
In reply to Taylor SimpsonAdd pc field to Packet structure
For helpers that need PC, pass an extra argument Remove slot arg from conditional jump helpers On a trap0, copy pkt->pc into hex_gpr[HEX_REG_PC]
--- target/hexagon/gen_tcg.h | 7 +++++++ target/hexagon/insn.h | 1 + target/hexagon/macros.h | 2 +- target/hexagon/translate.c | 9 +-------- target/hexagon/gen_helper_funcs.py | 4 ++++ target/hexagon/gen_helper_protos.py | 3 +++ target/hexagon/gen_tcg_funcs.py | 3 +++ target/hexagon/hex_common.py | 6 +++++- 8 files changed, 25 insertions(+), 10 deletions(-)
target/hexagon/gen_tcg.h +7 -0
@@ -750,4 +750,11 @@ RsV = RsV; \ } while (0) +#define fGEN_TCG_J2_trap0 (SHORTCODE ) \ + do { \ + uiV = uiV; \ + tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->pkt->pc); \ + TCGv excp = tcg_constant_tl(HEX_EXCP_TRAP0); \ + gen_helper_raise_exception(cpu_env, excp); \ + } while (0)#endif
target/hexagon/insn.h +1 -0
@@ -54,6 +54,7 @@ typedef struct Instruction Insn;struct Packet {uint16_t num_insns;uint16_t encod_pkt_size_in_bytes; +uint32_t pc;/* Pre-decodes about COF */ bool pkt_has_cof;/* Has any change-of-flow */
target/hexagon/macros.h +1 -1
@@ -398,7 +398,7 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)#else #define fREAD_GP () READ_REG(HEX_REG_GP)#endif -#define fREAD_PC () (READ_REG(HEX_REG_PC)) +#define fREAD_PC () (PC)#define fREAD_NPC () (env->next_PC & (0xfffffffe))
target/hexagon/translate.c +1 -8
@@ -194,11 +194,6 @@ static bool check_for_attrib(Packet *pkt, int attrib)return false; } -static bool need_pc (Packet *pkt) -{ -return check_for_attrib (pkt,A_IMPLICIT_READS_PC ); -} -static bool need_slot_cancelled (Packet *pkt) {return check_for_attrib (pkt,A_CONDEXEC );
@@ -241,9 +236,6 @@ static void gen_start_packet(DisasContext *ctx) }/* Initialize the runtime state for packet semantics */ -if (need_pc (pkt)) { -tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], ctx->base.pc_next); - }if (need_slot_cancelled (pkt)) {tcg_gen_movi_tl (hex_slot_cancelled,0 ); }
@@ -772,6 +764,7 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx) }if (decode_packet (nwords, words, &pkt, false) >0 ) { + pkt.pc = ctx->base.pc_next;HEX_DEBUG_PRINT_PKT (&pkt); ctx->pkt = &pkt;gen_start_packet (ctx);
target/hexagon/gen_helper_funcs.py +4 -0
@@ -241,6 +241,10 @@ def gen_helper_function(f, tag, tagregs, tagimms): if (hex_common.need_pkt_has_multi_cof(tag)): f.write(", uint32_t pkt_has_multi_cof") + if hex_common.need_PC(tag): + if i > 0: f.write(", ") + f.write("target_ulong PC") + i += 1 if hex_common.need_slot(tag): if i > 0: f.write(", ") f.write("uint32_t slot")
target/hexagon/gen_helper_protos.py +3 -0
@@ -85,6 +85,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): if hex_common.need_pkt_has_multi_cof(tag): def_helper_size += 1 if hex_common.need_part1(tag): def_helper_size += 1 if hex_common.need_slot(tag): def_helper_size += 1 + if hex_common.need_PC(tag): def_helper_size += 1 f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag)) ## The return type is void f.write(', void' )
@@ -93,6 +94,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): if hex_common.need_pkt_has_multi_cof(tag): def_helper_size += 1 if hex_common.need_part1(tag): def_helper_size += 1 if hex_common.need_slot(tag): def_helper_size += 1 + if hex_common.need_PC(tag): def_helper_size += 1 f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag)) ## Generate the qemu DEF_HELPER type for each result
@@ -131,6 +133,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): ## Add the arguments for the instruction pkt_has_multi_cof, slot and ## part1 (if needed) if hex_common.need_pkt_has_multi_cof(tag): f.write(', i32') + if hex_common.need_PC(tag): f.write(', i32') if hex_common.need_slot(tag): f.write(', i32' ) if hex_common.need_part1(tag): f.write(' , i32' ) f.write(')\n')
target/hexagon/gen_tcg_funcs.py +3 -0
@@ -629,6 +629,8 @@ def gen_tcg_func(f, tag, regs, imms): f.write(" TCGv part1 = tcg_constant_tl(insn->part1);\n") if hex_common.need_slot(tag): f.write(" TCGv slot = tcg_constant_tl(insn->slot);\n") + if hex_common.need_PC(tag): + f.write(" TCGv PC = tcg_constant_tl(ctx->pkt->pc);\n") f.write(" gen_helper_%s(" % (tag)) i=0 ## If there is a scalar result, it is the return type
@@ -659,6 +661,7 @@ def gen_tcg_func(f, tag, regs, imms): if hex_common.need_pkt_has_multi_cof(tag): f.write(", pkt_has_multi_cof") + if hex_common.need_PC(tag): f.write(", PC") if hex_common.need_slot(tag): f.write(", slot") if hex_common.need_part1(tag): f.write(", part1" ) f.write(");\n")
target/hexagon/hex_common.py +5 -1
@@ -194,7 +194,8 @@ def is_new_val(regtype, regid, tag): return regtype+regid+'N' in semdict[tag] def need_slot(tag): - if ('A_CONDEXEC' in attribdict[tag] or + if (('A_CONDEXEC' in attribdict[tag] and + 'A_JUMP' not in attribdict[tag]) or 'A_STORE' in attribdict[tag] or 'A_LOAD' in attribdict[tag]): return 1
@@ -207,6 +208,9 @@ def need_part1(tag): def need_ea(tag): return re.compile(r"\bEA\b").search(semdict[tag]) +def need_PC(tag): + return 'A_IMPLICIT_READS_PC' in attribdict[tag] + def need_pkt_has_multi_cof(tag): return 'A_COF' in attribdict[tag]
Signature · 1 line
2.17.1
Re: [PATCH v3 05/11] Hexagon (target/hexagon) Remove PC from the runtime state
Quoted 6 lines · Taylor Simpson
Add pc field to Packet structure
For helpers that need PC, pass an extra argument Remove slot arg from conditional jump helpers On a trap0, copypkt->pcinto hex_gpr[HEX_REG_PC]Signed-off-by Taylor Simpson<[email protected]>
Quoted 10 lines
--- target/hexagon/gen_tcg.h | 7 +++++++ target/hexagon/insn.h | 1 + target/hexagon/macros.h | 2 +- target/hexagon/translate.c | 9 +-------- target/hexagon/gen_helper_funcs.py | 4 ++++ target/hexagon/gen_helper_protos.py | 3 +++ target/hexagon/gen_tcg_funcs.py | 3 +++ target/hexagon/hex_common.py | 6 +++++- 8 files changed, 25 insertions(+), 10 deletions(-)
r~
PATCH v3 6/11 Hexagon (target/hexagon) Remove next_PC from runtime state
In reply to Taylor SimpsonThe imported files don't properly mark all CONDEXEC instructions, so we add some logic to hex_common.py to add the attribute.
--- target/hexagon/cpu.h | 1 - target/hexagon/gen_tcg.h | 6 ++++++ target/hexagon/macros.h | 2 +- target/hexagon/translate.h | 2 +- target/hexagon/op_helper.c | 6 +++--- target/hexagon/translate.c | 29 +++++++++++++++++++++++------ target/hexagon/gen_helper_funcs.py | 4 ++++ target/hexagon/gen_helper_protos.py | 3 +++ target/hexagon/gen_tcg_funcs.py | 3 +++ target/hexagon/hex_common.py | 20 ++++++++++++++++++++ 10 files changed, 64 insertions(+), 12 deletions(-)
target/hexagon/cpu.h +0 -1
@@ -78,7 +78,6 @@ typedef struct CPUArchState {target_ulong gpr[TOTAL_PER_THREAD_REGS ];target_ulong pred[NUM_PREGS ];target_ulong branch_taken; -target_ulong next_PC;/* For comparing with LLDB on target - see adjust_stack_ptrs function */ target_ulong last_pc_dumped;
target/hexagon/gen_tcg.h +6 -0
@@ -612,6 +612,12 @@tcg_temp_free (tmp); \ } while (0) +#define fGEN_TCG_J2_pause (SHORTCODE ) \ + do { \ + uiV = uiV; \ + tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->next_PC); \ + } while (0) +/* r0 = asr(r1, r2):sat */ #define fGEN_TCG_S2_asr_r_r_sat (SHORTCODE ) \ gen_asr_r_r_sat(RdV, RsV, RtV)
target/hexagon/macros.h +1 -1
@@ -400,7 +400,7 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)#endif #define fREAD_PC () (PC) -#define fREAD_NPC () (env->next_PC & (0xfffffffe)) +#define fREAD_NPC () (next_PC & (0xfffffffe))#define fREAD_P0 () (READ_PREG(0))#define fREAD_P3 () (READ_PREG(3))
target/hexagon/translate.h +1 -1
@@ -30,6 +30,7 @@ typedef struct DisasContext {DisasContextBase base;Packet *pkt;Insn *insn; +uint32_t next_PC;uint32_t mem_idx;uint32_t num_packets;uint32_t num_insns;
@@ -134,7 +135,6 @@ static inline void ctx_log_qreg_write(DisasContext *ctx,extern TCGv hex_gpr[TOTAL_PER_THREAD_REGS ];extern TCGv hex_pred[NUM_PREGS ]; -extern TCGv hex_next_PC;extern TCGv hex_this_PC;extern TCGv hex_slot_cancelled;extern TCGv hex_branch_taken;
target/hexagon/op_helper.c +3 -3
@@ -119,12 +119,12 @@ static void write_new_pc(CPUHexagonState *env, bool pkt_has_multi_cof, "ignoring the second one\n"); }else {fCHECK_PCALIGN (addr); - env->next_PC = addr; + env->gpr[HEX_REG_PC ] = addr; env->branch_taken =1 ; } }else {fCHECK_PCALIGN (addr); - env->next_PC = addr; + env->gpr[HEX_REG_PC ] = addr; } }
@@ -299,7 +299,7 @@ void HELPER(debug_commit_end)(CPUHexagonState *env, int has_st0, int has_st1) } } -HEX_DEBUG_LOG ("Next PC = " TARGET_FMT_lx"\n" , env->next_PC); +HEX_DEBUG_LOG ("Next PC = " TARGET_FMT_lx"\n" , env->gpr[HEX_REG_PC ]); HEX_DEBUG_LOG("Exec counters: pkt = " TARGET_FMT_lx ", insn = " TARGET_FMT_lx ", hvx = " TARGET_FMT_lx "\n",
target/hexagon/translate.c +23 -6
@@ -31,7 +31,6 @@TCGv hex_gpr[TOTAL_PER_THREAD_REGS ];TCGv hex_pred[NUM_PREGS ]; -TCGv hex_next_PC;TCGv hex_this_PC;TCGv hex_slot_cancelled;TCGv hex_branch_taken;
@@ -120,7 +119,6 @@ static void gen_exec_counters(DisasContext *ctx)static void gen_end_tb (DisasContext *ctx) {gen_exec_counters (ctx); -tcg_gen_mov_tl (hex_gpr[HEX_REG_PC ], hex_next_PC);tcg_gen_exit_tb (NULL ,0 ); ctx->base.is_jmp =DISAS_NORETURN ; }
@@ -128,7 +126,7 @@ static void gen_end_tb(DisasContext *ctx)static void gen_exception_end_tb (DisasContext *ctx,int excp) {gen_exec_counters (ctx); -tcg_gen_mov_tl (hex_gpr[HEX_REG_PC ], hex_next_PC); +tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], ctx->next_PC);gen_exception_raw (excp); ctx->base.is_jmp =DISAS_NORETURN ;
@@ -204,6 +202,24 @@ static bool need_pred_written(Packet *pkt)return check_for_attrib (pkt,A_WRITES_PRED_REG ); } +static bool need_next_PC (DisasContext *ctx) +{ +Packet *pkt = ctx->pkt; + +/* Check for conditional control flow or HW loop end */ +for (int i =0 ; i < pkt->num_insns; i++) { +uint16_t opcode = pkt->insn[i].opcode; +if (GET_ATTRIB (opcode,A_CONDEXEC ) &&GET_ATTRIB (opcode,A_COF )) { +return true; + } +if (GET_ATTRIB (opcode,A_HWLOOP0_END ) || +GET_ATTRIB (opcode,A_HWLOOP1_END )) { +return true; + } + } +return false; +} +static void gen_start_packet (DisasContext *ctx) {Packet *pkt = ctx->pkt;
@@ -211,6 +227,7 @@ static void gen_start_packet(DisasContext *ctx)int i;/* Clear out the disassembly context */ + ctx->next_PC = next_PC; ctx->reg_log_idx =0 ;bitmap_zero (ctx->regs_written,TOTAL_PER_THREAD_REGS ); ctx->preg_log_idx =0 ;
@@ -243,7 +260,9 @@ static void gen_start_packet(DisasContext *ctx)if (pkt->pkt_has_multi_cof) {tcg_gen_movi_tl (hex_branch_taken,0 ); } -tcg_gen_movi_tl (hex_next_PC, next_PC); +if (need_next_PC (ctx)) { +tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], next_PC); + } }if (need_pred_written (pkt)) {tcg_gen_movi_tl (hex_pred_written,0 );
@@ -936,8 +955,6 @@ void hexagon_translate_init(void) } hex_pred_written =tcg_global_mem_new (cpu_env, offsetof(CPUHexagonState , pred_written),"pred_written" ); - hex_next_PC =tcg_global_mem_new (cpu_env, - offsetof(CPUHexagonState , next_PC),"next_PC" ); hex_this_PC =tcg_global_mem_new (cpu_env, offsetof(CPUHexagonState , this_PC),"this_PC" ); hex_slot_cancelled = tcg_global_mem_new(cpu_env,
target/hexagon/gen_helper_funcs.py +4 -0
@@ -245,6 +245,10 @@ def gen_helper_function(f, tag, tagregs, tagimms): if i > 0: f.write(", ") f.write("target_ulong PC") i += 1 + if hex_common.helper_needs_next_PC(tag): + if i > 0: f.write(", ") + f.write("target_ulong next_PC") + i += 1 if hex_common.need_slot(tag): if i > 0: f.write(", ") f.write("uint32_t slot")
target/hexagon/gen_helper_protos.py +3 -0
@@ -86,6 +86,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): if hex_common.need_part1(tag): def_helper_size += 1 if hex_common.need_slot(tag): def_helper_size += 1 if hex_common.need_PC(tag): def_helper_size += 1 + if hex_common.helper_needs_next_PC(tag): def_helper_size += 1 f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag)) ## The return type is void f.write(', void' )
@@ -95,6 +96,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): if hex_common.need_part1(tag): def_helper_size += 1 if hex_common.need_slot(tag): def_helper_size += 1 if hex_common.need_PC(tag): def_helper_size += 1 + if hex_common.helper_needs_next_PC(tag): def_helper_size += 1 f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag)) ## Generate the qemu DEF_HELPER type for each result
@@ -134,6 +136,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): ## part1 (if needed) if hex_common.need_pkt_has_multi_cof(tag): f.write(', i32') if hex_common.need_PC(tag): f.write(', i32') + if hex_common.helper_needs_next_PC(tag): f.write(', i32') if hex_common.need_slot(tag): f.write(', i32' ) if hex_common.need_part1(tag): f.write(' , i32' ) f.write(')\n')
target/hexagon/gen_tcg_funcs.py +3 -0
@@ -631,6 +631,8 @@ def gen_tcg_func(f, tag, regs, imms): f.write(" TCGv slot = tcg_constant_tl(insn->slot);\n") if hex_common.need_PC(tag): f.write(" TCGv PC = tcg_constant_tl(ctx->pkt->pc);\n") + if hex_common.helper_needs_next_PC(tag): + f.write(" TCGv next_PC = tcg_constant_tl(ctx->next_PC);\n") f.write(" gen_helper_%s(" % (tag)) i=0 ## If there is a scalar result, it is the return type
@@ -662,6 +664,7 @@ def gen_tcg_func(f, tag, regs, imms): if hex_common.need_pkt_has_multi_cof(tag): f.write(", pkt_has_multi_cof") if hex_common.need_PC(tag): f.write(", PC") + if hex_common.helper_needs_next_PC(tag): f.write(", next_PC") if hex_common.need_slot(tag): f.write(", slot") if hex_common.need_part1(tag): f.write(", part1" ) f.write(");\n")
target/hexagon/hex_common.py +20 -0
@@ -66,6 +66,18 @@ def add_qemu_macro_attrib(name, attrib): macros[name].attribs.add(attrib) immextre = re.compile(r'f(MUST_)?IMMEXT[(]([UuSsRr])') + +def is_cond_jump(tag): + if tag == 'J2_rte': + return False + if ('A_HWLOOP0_END' in attribdict[tag] or + 'A_HWLOOP1_END' in attribdict[tag]): + return False + return re.compile(r"(if.*fBRANCH)|(if.*fJUMPR)").search(semdict[tag]) + +def is_cond_call(tag): + return re.compile(r"(if.*fCALL)").search(semdict[tag]) + def calculate_attribs(): add_qemu_macro_attrib('fREAD_PC', 'A_IMPLICIT_READS_PC') add_qemu_macro_attrib('fTRAP', 'A_IMPLICIT_READS_PC')
@@ -96,6 +108,11 @@ def calculate_attribs(): for regtype, regid, toss, numregs in regs: if regtype == "P" and is_written(regid): attribdict[tag].add('A_WRITES_PRED_REG') + # Mark conditional jumps and calls + # Not all instructions are properly marked with A_CONDEXEC + for tag in tags: + if is_cond_jump(tag) or is_cond_call(tag): + attribdict[tag].add('A_CONDEXEC') def SEMANTICS(tag, beh, sem): #print tag,beh,sem
@@ -211,6 +228,9 @@ def need_ea(tag): def need_PC(tag): return 'A_IMPLICIT_READS_PC' in attribdict[tag] +def helper_needs_next_PC(tag): + return 'A_CALL' in attribdict[tag] + def need_pkt_has_multi_cof(tag): return 'A_COF' in attribdict[tag]
Signature · 1 line
2.17.1
Re: [PATCH v3 06/11] Hexagon (target/hexagon) Remove next_PC from runtime state
Quoted 4 lines · Taylor Simpson
The imported files don't properly mark all CONDEXEC instructions, so we add some logic to
hex_common.pyto add the attribute.Signed-off-by Taylor Simpson<[email protected]>
Quoted 12 lines
--- target/hexagon/cpu.h | 1 - target/hexagon/gen_tcg.h | 6 ++++++ target/hexagon/macros.h | 2 +- target/hexagon/translate.h | 2 +- target/hexagon/op_helper.c | 6 +++--- target/hexagon/translate.c | 29 +++++++++++++++++++++++------ target/hexagon/gen_helper_funcs.py | 4 ++++ target/hexagon/gen_helper_protos.py | 3 +++ target/hexagon/gen_tcg_funcs.py | 3 +++ target/hexagon/hex_common.py | 20 ++++++++++++++++++++ 10 files changed, 64 insertions(+), 12 deletions(-)
r~
PATCH v3 7/11 Hexagon (target/hexagon) Add overrides for direct call instructions
In reply to Taylor SimpsonAdd overrides for
J2_call
J2_callt
J2_callf--- target/hexagon/gen_tcg.h | 8 ++++++ target/hexagon/genptr.c | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+)
target/hexagon/gen_tcg.h +8 -0
@@ -612,6 +612,14 @@tcg_temp_free (tmp); \ } while (0) +#define fGEN_TCG_J2_call (SHORTCODE ) \ + gen_call(ctx, riV) + +#define fGEN_TCG_J2_callt (SHORTCODE ) \ + gen_cond_call(ctx, PuV, true, riV) +#define fGEN_TCG_J2_callf (SHORTCODE ) \ + gen_cond_call(ctx, PuV, false, riV) +#define fGEN_TCG_J2_pause (SHORTCODE ) \ do { \ uiV = uiV; \
target/hexagon/genptr.c +55 -0
67 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 07/11] Hexagon (target/hexagon) Add overrides for direct call instructions
Quoted 10 lines · Taylor Simpson
Add overrides for
J2_call J2_callt J2_callfSigned-off-by Taylor Simpson<[email protected]>--- target/hexagon/gen_tcg.h | 8 ++++++ target/hexagon/genptr.c | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+)
r~
Re: [PATCH v3 07/11] Hexagon (target/hexagon) Add overrides for direct call instructions
In reply to Taylor Simpsontarget/hexagon/genptr.c static void gen_set_usr_fieldi(int field, int x) · line 520
Quoted 6 lines · Taylor Simpson
target/hexagon/genptr.c +6
-0+tcg_gen_andi_tl (lsb, pred,1 ); +if (!sense) { +tcg_gen_xori_tl (lsb, lsb,1 ); + } +gen_write_new_pc_pcrel (ctx, pc_off, lsb); +tcg_gen_brcondi_tl (TCG_COND_EQ , lsb,0 , skip);
Better to change the branch condition than invert the lsb.
r~
Re: [PATCH v3 07/11] Hexagon (target/hexagon) Add overrides for direct call instructions
In reply to Taylor Simpsontarget/hexagon/genptr.c static TCGv gen_8bitsof(TCGv result, TCGv value) · line 465
Quoted 7 lines · Taylor Simpson
target/hexagon/genptr.c +7
-0+static void gen_write_new_pc_addr (DisasContext *ctx,TCGv addr,TCGv pred) +{ +TCGLabel *pred_false =NULL ; +if (pred !=NULL ) { + pred_false =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_EQ , pred,0 , pred_false); + }
It would be nice to pass down the entire branch condition. Trivial for usage within this patch, but more complex for others.
r~
PATCH v3 8/11 Hexagon (target/hexagon) Add overrides for compound compare and jump
In reply to Taylor Simpson--- target/hexagon/gen_tcg.h | 177 +++++++++++++++++++++++++++++++++++++++ target/hexagon/genptr.c | 72 ++++++++++++++++ 2 files changed, 249 insertions(+)
target/hexagon/gen_tcg.h +177 -0
@@ -620,6 +620,183 @@#define fGEN_TCG_J2_callf (SHORTCODE ) \ gen_cond_call(ctx, PuV, false, riV) +/* +* Compound compare and jump instructions +* Here is a primer to understand the tag names +* +* Comparison +* cmpeqi compare equal to an immediate +* cmpgti compare greater than an immediate +* cmpgtiu compare greater than an unsigned immediate +* cmpeqn1 compare equal to negative 1 +* cmpgtn1 compare greater than negative 1 +* cmpeq compare equal (two registers) +* cmpgtu compare greater than unsigned (two registers) +* tstbit0 test bit zero +* +* Condition +* tp0 p0 is true p0 = cmp.eq(r0,#5); if (p0.new) jump:nt address +* fp0 p0 is false p0 = cmp.eq(r0,#5); if (!p0.new) jump:nt address +* tp1 p1 is true p1 = cmp.eq(r0,#5); if (p1.new) jump:nt address +* fp1 p1 is false p1 = cmp.eq(r0,#5); if (!p1.new) jump:nt address +* +* Prediction (not modelled in qemu) +* _nt not taken +* _t taken +*/ +#define fGEN_TCG_J4_cmpeq_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 0, TCG_COND_EQ, true, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 0, TCG_COND_EQ, true, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 0, TCG_COND_EQ, false, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 0, TCG_COND_EQ, false, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 1, TCG_COND_EQ, true, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 1, TCG_COND_EQ, true, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 1, TCG_COND_EQ, false, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 1, TCG_COND_EQ, false, RsV, RtV, riV) + +#define fGEN_TCG_J4_cmpgt_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 0, TCG_COND_GT, true, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 0, TCG_COND_GT, true, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 0, TCG_COND_GT, false, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 0, TCG_COND_GT, false, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 1, TCG_COND_GT, true, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 1, TCG_COND_GT, true, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 1, TCG_COND_GT, false, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 1, TCG_COND_GT, false, RsV, RtV, riV) + +#define fGEN_TCG_J4_cmpgtu_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 0, TCG_COND_GTU, true, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 0, TCG_COND_GTU, true, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 0, TCG_COND_GTU, false, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 0, TCG_COND_GTU, false, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 1, TCG_COND_GTU, true, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 1, TCG_COND_GTU, true, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 1, TCG_COND_GTU, false, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp(ctx, 1, TCG_COND_GTU, false, RsV, RtV, riV) + +#define fGEN_TCG_J4_cmpeqi_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 0, TCG_COND_EQ, true, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 0, TCG_COND_EQ, true, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 0, TCG_COND_EQ, false, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 0, TCG_COND_EQ, false, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 1, TCG_COND_EQ, true, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 1, TCG_COND_EQ, true, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 1, TCG_COND_EQ, false, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 1, TCG_COND_EQ, false, RsV, UiV, riV) + +#define fGEN_TCG_J4_cmpgti_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 0, TCG_COND_GT, true, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 0, TCG_COND_GT, true, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 0, TCG_COND_GT, false, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 0, TCG_COND_GT, false, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 1, TCG_COND_GT, true, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 1, TCG_COND_GT, true, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 1, TCG_COND_GT, false, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 1, TCG_COND_GT, false, RsV, UiV, riV) + +#define fGEN_TCG_J4_cmpgtui_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 0, TCG_COND_GTU, true, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 0, TCG_COND_GTU, true, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 0, TCG_COND_GTU, false, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 0, TCG_COND_GTU, false, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 1, TCG_COND_GTU, true, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 1, TCG_COND_GTU, true, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 1, TCG_COND_GTU, false, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp(ctx, 1, TCG_COND_GTU, false, RsV, UiV, riV) + +#define fGEN_TCG_J4_cmpeqn1_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 0, TCG_COND_EQ, true, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 0, TCG_COND_EQ, true, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 0, TCG_COND_EQ, false, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 0, TCG_COND_EQ, false, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 1, TCG_COND_EQ, true, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 1, TCG_COND_EQ, true, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 1, TCG_COND_EQ, false, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 1, TCG_COND_EQ, false, RsV, riV) + +#define fGEN_TCG_J4_cmpgtn1_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 0, TCG_COND_GT, true, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 0, TCG_COND_GT, true, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 0, TCG_COND_GT, false, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 0, TCG_COND_GT, false, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 1, TCG_COND_GT, true, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 1, TCG_COND_GT, true, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 1, TCG_COND_GT, false, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp(ctx, 1, TCG_COND_GT, false, RsV, riV) + +#define fGEN_TCG_J4_tstbit0_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 0, true, RsV, riV) +#define fGEN_TCG_J4_tstbit0_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 0, true, RsV, riV) +#define fGEN_TCG_J4_tstbit0_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 0, false, RsV, riV) +#define fGEN_TCG_J4_tstbit0_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 0, false, RsV, riV) +#define fGEN_TCG_J4_tstbit0_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 1, true, RsV, riV) +#define fGEN_TCG_J4_tstbit0_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 1, true, RsV, riV) +#define fGEN_TCG_J4_tstbit0_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 1, false, RsV, riV) +#define fGEN_TCG_J4_tstbit0_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 1, false, RsV, riV) +#define fGEN_TCG_J2_pause (SHORTCODE ) \ do { \ uiV = uiV; \
target/hexagon/genptr.c +72 -0
78 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 08/11] Hexagon (target/hexagon) Add overrides for compound compare and jump
Quoted 5 lines · Taylor Simpson
Signed-off-by Taylor Simpson<[email protected]>--- target/hexagon/gen_tcg.h | 177 +++++++++++++++++++++++++++++++++++++++ target/hexagon/genptr.c | 72 ++++++++++++++++ 2 files changed, 249 insertions(+)
r~
PATCH v3 9/11 Hexagon (target/hexagon) Add overrides for various forms of jump
In reply to Taylor Simpson--- target/hexagon/gen_tcg.h | 189 +++++++++++++++++++++++++++++++++++++++ target/hexagon/genptr.c | 45 ++++++++++ 2 files changed, 234 insertions(+)
target/hexagon/gen_tcg.h +189 -0
@@ -797,6 +797,195 @@#define fGEN_TCG_J4_tstbit0_fp1_jump_t (SHORTCODE ) \ gen_cmpnd_tstbit0_jmp(ctx, 1, false, RsV, riV) +#define fGEN_TCG_J2_jump (SHORTCODE ) \ + gen_jump(ctx, riV) +#define fGEN_TCG_J2_jumpr (SHORTCODE ) \ + gen_jumpr(ctx, RsV) +#define fGEN_TCG_J4_jumpseti (SHORTCODE ) \ + do { \ + tcg_gen_movi_tl(RdV, UiV); \ + gen_jump(ctx, riV); \ + } while (0) + +#define fGEN_TCG_cond_jump (COND ) \ + do { \ + TCGv LSB = tcg_temp_new(); \ + COND; \ + gen_cond_jump(ctx, LSB, riV); \ + tcg_temp_free(LSB); \ + } while (0) + +#define fGEN_TCG_J2_jumpt (SHORTCODE ) \ + fGEN_TCG_cond_jump(fLSBOLD(PuV)) +#define fGEN_TCG_J2_jumptpt (SHORTCODE ) \ + fGEN_TCG_cond_jump(fLSBOLD(PuV)) +#define fGEN_TCG_J2_jumpf (SHORTCODE ) \ + fGEN_TCG_cond_jump(fLSBOLDNOT(PuV)) +#define fGEN_TCG_J2_jumpfpt (SHORTCODE ) \ + fGEN_TCG_cond_jump(fLSBOLDNOT(PuV)) +#define fGEN_TCG_J2_jumptnew (SHORTCODE ) \ + gen_cond_jump(ctx, PuN, riV) +#define fGEN_TCG_J2_jumptnewpt (SHORTCODE ) \ + gen_cond_jump(ctx, PuN, riV) +#define fGEN_TCG_J2_jumpfnewpt (SHORTCODE ) \ + fGEN_TCG_cond_jump(fLSBNEWNOT(PuN)) +#define fGEN_TCG_J2_jumpfnew (SHORTCODE ) \ + fGEN_TCG_cond_jump(fLSBNEWNOT(PuN)) +#define fGEN_TCG_J2_jumprz (SHORTCODE ) \ + fGEN_TCG_cond_jump(tcg_gen_setcondi_tl(TCG_COND_NE, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprzpt (SHORTCODE ) \ + fGEN_TCG_cond_jump(tcg_gen_setcondi_tl(TCG_COND_NE, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprnz (SHORTCODE ) \ + fGEN_TCG_cond_jump(tcg_gen_setcondi_tl(TCG_COND_EQ, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprnzpt (SHORTCODE ) \ + fGEN_TCG_cond_jump(tcg_gen_setcondi_tl(TCG_COND_EQ, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprgtez (SHORTCODE ) \ + fGEN_TCG_cond_jump(tcg_gen_setcondi_tl(TCG_COND_GE, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprgtezpt (SHORTCODE ) \ + fGEN_TCG_cond_jump(tcg_gen_setcondi_tl(TCG_COND_GE, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprltez (SHORTCODE ) \ + fGEN_TCG_cond_jump(tcg_gen_setcondi_tl(TCG_COND_LE, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprltezpt (SHORTCODE ) \ + fGEN_TCG_cond_jump(tcg_gen_setcondi_tl(TCG_COND_LE, LSB, RsV, 0)) + +#define fGEN_TCG_cond_jumpr (COND ) \ + do { \ + TCGv LSB = tcg_temp_new(); \ + COND; \ + gen_cond_jumpr(ctx, LSB, RsV); \ + tcg_temp_free(LSB); \ + } while (0) + +#define fGEN_TCG_J2_jumprt (SHORTCODE ) \ + fGEN_TCG_cond_jumpr(fLSBOLD(PuV)) +#define fGEN_TCG_J2_jumprtpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpr(fLSBOLD(PuV)) +#define fGEN_TCG_J2_jumprf (SHORTCODE ) \ + fGEN_TCG_cond_jumpr(fLSBOLDNOT(PuV)) +#define fGEN_TCG_J2_jumprfpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpr(fLSBOLDNOT(PuV)) +#define fGEN_TCG_J2_jumprtnew (SHORTCODE ) \ + fGEN_TCG_cond_jumpr(fLSBNEW(PuN)) +#define fGEN_TCG_J2_jumprtnewpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpr(fLSBNEW(PuN)) +#define fGEN_TCG_J2_jumprfnew (SHORTCODE ) \ + fGEN_TCG_cond_jumpr(fLSBNEWNOT(PuN)) +#define fGEN_TCG_J2_jumprfnewpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpr(fLSBNEWNOT(PuN)) +#define fGEN_TCG_J2_jumprfnewpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpr(fLSBNEWNOT(PuN)) + +/* +* New value compare & jump instructions +* if ([!]COND(r0.new, r1) jump:t address +* if ([!]COND(r0.new, #7) jump:t address +*/ +#define fGEN_TCG_J4_cmpgt_t_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GT, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpgt_t_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GT, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpgt_f_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LE, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpgt_f_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LE, NsN, RtV, riV) + +#define fGEN_TCG_J4_cmpeq_t_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_EQ, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpeq_t_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_EQ, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpeq_f_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_NE, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpeq_f_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_NE, NsN, RtV, riV) + +#define fGEN_TCG_J4_cmplt_t_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LT, NsN, RtV, riV) +#define fGEN_TCG_J4_cmplt_t_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LT, NsN, RtV, riV) +#define fGEN_TCG_J4_cmplt_f_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GE, NsN, RtV, riV) +#define fGEN_TCG_J4_cmplt_f_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GE, NsN, RtV, riV) + +#define fGEN_TCG_J4_cmpeqi_t_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_EQ, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_t_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_EQ, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_f_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_NE, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_f_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_NE, NsN, UiV, riV) + +#define fGEN_TCG_J4_cmpgti_t_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_GT, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpgti_t_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_GT, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpgti_f_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_LE, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpgti_f_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_LE, NsN, UiV, riV) + +#define fGEN_TCG_J4_cmpltu_t_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LTU, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpltu_t_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LTU, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpltu_f_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GEU, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpltu_f_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GEU, NsN, RtV, riV) + +#define fGEN_TCG_J4_cmpgtui_t_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_GTU, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_t_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_GTU, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_f_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_LEU, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_f_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_LEU, NsN, UiV, riV) + +#define fGEN_TCG_J4_cmpgtu_t_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GTU, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_t_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GTU, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_f_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LEU, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_f_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LEU, NsN, RtV, riV) + +#define fGEN_TCG_J4_cmpeqn1_t_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_EQ, NsN, -1, riV) +#define fGEN_TCG_J4_cmpeqn1_t_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_EQ, NsN, -1, riV) +#define fGEN_TCG_J4_cmpeqn1_f_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_NE, NsN, -1, riV) +#define fGEN_TCG_J4_cmpeqn1_f_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_NE, NsN, -1, riV) + +#define fGEN_TCG_J4_cmpgtn1_t_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_GT, NsN, -1, riV) +#define fGEN_TCG_J4_cmpgtn1_t_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_GT, NsN, -1, riV) +#define fGEN_TCG_J4_cmpgtn1_f_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_LE, NsN, -1, riV) +#define fGEN_TCG_J4_cmpgtn1_f_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_LE, NsN, -1, riV) + +#define fGEN_TCG_J4_tstbit0_t_jumpnv_t (SHORTCODE ) \ + gen_testbit0_jumpnv(ctx, true, NsN, riV) +#define fGEN_TCG_J4_tstbit0_t_jumpnv_nt (SHORTCODE ) \ + gen_testbit0_jumpnv(ctx, true, NsN, riV) +#define fGEN_TCG_J4_tstbit0_f_jumpnv_t (SHORTCODE ) \ + gen_testbit0_jumpnv(ctx, false, NsN, riV) +#define fGEN_TCG_J4_tstbit0_f_jumpnv_nt (SHORTCODE ) \ + gen_testbit0_jumpnv(ctx, false, NsN, riV) + +/* r0 = r1 ; jump address */ +#define fGEN_TCG_J4_jumpsetr (SHORTCODE ) \ + do { \ + tcg_gen_mov_tl(RdV, RsV); \ + gen_jump(ctx, riV); \ + } while (0) +#define fGEN_TCG_J2_pause (SHORTCODE ) \ do { \ uiV = uiV; \
target/hexagon/genptr.c +45 -0
63 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 09/11] Hexagon (target/hexagon) Add overrides for various forms of jump
target/hexagon/genptr.c static void gen_cond_call(DisasContext *ctx, TCGv pred, bool sense, int pc_off) · line 632
Quoted 6 lines · Taylor Simpson
target/hexagon/genptr.c +6
-0+static void gen_cmp_jumpnv (DisasContext *ctx, +TCGCond cond,TCGv val,TCGv src,int pc_off) +{ +TCGv pred =tcg_temp_new (); +tcg_gen_setcond_tl (cond, pred, val, src); +gen_cond_jump (ctx, pred, pc_off);
This, in particular could benefit from the complete branch condition being passed down, rather than setcond here then brcond based on the result.
But it's still an improvement, so,
r~
PATCH v3 10/11 Hexagon (target/hexagon) Use direct block chaining for direct jump/branch
In reply to Taylor SimpsonDirect block chaining is documented here
https://qemu.readthedocs.io/en/latest/devel/tcg.html#direct-block-chaining
Recall that Hexagon allows packets with multiple jumps where only the first one with a true predicate will actually jump. So, we can only use direct block chaining when the packet contains a single PC-relative jump. We add the following to DisasContext in order to perform direct block chaining at the end of packet commit (in gen_end_tb)
has_single_direct_branch
Indicates that we can use direct block chaining
branch_cond
The condition under which the branch is taken
branch_dest
The destination of the branch
--- target/hexagon/translate.h | 3 +++ target/hexagon/genptr.c | 13 ++++++++++++- target/hexagon/translate.c | 39 +++++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 2 deletions(-)
target/hexagon/translate.h +3 -0
@@ -57,6 +57,9 @@ typedef struct DisasContext {bool qreg_is_predicated[NUM_QREGS ];int qreg_log_idx;bool pre_commit; +bool has_single_direct_branch; +TCGv branch_cond; +target_ulong branch_dest; } DisasContext;static inline void ctx_log_reg_write (DisasContext *ctx,int rnum)
target/hexagon/genptr.c +12 -1
@@ -482,7 +482,18 @@ static void gen_write_new_pc_addr(DisasContext *ctx, TCGv addr, TCGv pred)static void gen_write_new_pc_pcrel (DisasContext *ctx,int pc_off,TCGv pred) {target_ulong dest = ctx->pkt->pc + pc_off; -gen_write_new_pc_addr (ctx,tcg_constant_tl (dest), pred); +if (ctx->pkt->pkt_has_multi_cof) { +gen_write_new_pc_addr (ctx,tcg_constant_tl (dest), pred); + }else { +/* Defer this jump to the end of the TB */ +g_assert (ctx->branch_cond ==NULL ); + ctx->has_single_direct_branch = true; +if (pred !=NULL ) { + ctx->branch_cond =tcg_temp_local_new (); +tcg_gen_mov_tl (ctx->branch_cond, pred); + } + ctx->branch_dest = dest; + } }static void gen_set_usr_field (int field,TCGv val)
target/hexagon/translate.c +38 -1
@@ -116,10 +116,44 @@ static void gen_exec_counters(DisasContext *ctx) hex_gpr[HEX_REG_QEMU_HVX_CNT], ctx->num_hvx_insns); } +static bool use_goto_tb (DisasContext *ctx,target_ulong dest) +{ +return translator_use_goto_tb (&ctx->base, dest); +} + +static void gen_goto_tb (DisasContext *ctx,int idx,target_ulong dest) +{ +if (use_goto_tb (ctx, dest)) { +tcg_gen_goto_tb (idx); +tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], dest); +tcg_gen_exit_tb (ctx->base.tb, idx); + }else { +tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], dest); +tcg_gen_lookup_and_goto_ptr (); + } +} +static void gen_end_tb (DisasContext *ctx) {gen_exec_counters (ctx); -tcg_gen_exit_tb (NULL ,0 ); + +if (ctx->has_single_direct_branch) { +if (ctx->branch_cond !=NULL ) { +TCGLabel *skip =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_EQ , ctx->branch_cond,0 , skip); +gen_goto_tb (ctx,0 , ctx->branch_dest); +gen_set_label (skip); +gen_goto_tb (ctx,1 , ctx->next_PC); +tcg_temp_free (ctx->branch_cond); + ctx->branch_cond =NULL ; + }else { +gen_goto_tb (ctx,0 , ctx->branch_dest); + } + }else { +tcg_gen_lookup_and_goto_ptr (); + } + +g_assert (ctx->branch_cond ==NULL ); ctx->base.is_jmp =DISAS_NORETURN ; }
@@ -811,6 +845,9 @@ static void hexagon_tr_init_disas_context(DisasContextBase *dcbase,static void hexagon_tr_tb_start (DisasContextBase *db,CPUState *cpu) { +DisasContext *ctx =container_of (db, DisasContext, base); + ctx->has_single_direct_branch = false; + ctx->branch_cond =NULL ; }static void hexagon_tr_insn_start (DisasContextBase *dcbase,CPUState *cpu)
Signature · 1 line
2.17.1
Re: [PATCH v3 10/11] Hexagon (target/hexagon) Use direct block chaining for direct jump/branch
Quoted 6 lines · Taylor Simpson
Direct block chaining is documented here
https://qemu.readthedocs.io/en/latest/devel/tcg.html#direct-block-chainingRecall that Hexagon allows packets with multiple jumps where only the first one with a true predicate will actually jump. So, we can only use direct block chaining when the packet contains a single PC-relative jump.
Not quite accurate.
Only the first two direct branches can use direct block chaining. Other exits from the translation block could use indirect block chaining (tcg_gen_lookup_and_goto_ptr). You just have to remember which is taken.
That said, this is certainly an improvement.
target/hexagon/genptr.c static void gen_write_new_pc_addr(DisasContext *ctx, TCGv addr, TCGv pred) · line 495
Quoted 11 lines
target/hexagon/genptr.c +11
-0+if (ctx->pkt->pkt_has_multi_cof) { +gen_write_new_pc_addr (ctx,tcg_constant_tl (dest), pred); + }else { +/* Defer this jump to the end of the TB */ +g_assert (ctx->branch_cond ==NULL ); + ctx->has_single_direct_branch = true; +if (pred !=NULL ) { + ctx->branch_cond =tcg_temp_local_new (); +tcg_gen_mov_tl (ctx->branch_cond, pred); + } + ctx->branch_dest = dest;
Perhaps re-use hex_branch_taken as branch_cond?
Anyway,
r~
RE: [PATCH v3 10/11] Hexagon (target/hexagon) Use direct block chaining for direct jump/branch
Quoted 20 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, November 4, 2022 8:33 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>; Matheus Bernardino (QUIC) <[email protected]>
Subject: Re: [PATCH v3 10/11] Hexagon (target/hexagon) Use direct block chaining for direct jump/branchQuoted 7 lines · Taylor Simpson
Direct block chaining is documented here
https://qemu.readthedocs.io/en/latest/devel/tcg.html#direct-block-chai
ningRecall that Hexagon allows packets with multiple jumps where only the first one with a true predicate will actually jump. So, we can only use direct block chaining when the packet contains a single PC-relative
Quoted 9 lines
jump.
Not quite accurate.
Only the first two direct branches can use direct block chaining. Other exits from the translation block could use indirect block chaining (
tcg_gen_lookup_and_goto_ptr). You just have to remember which is taken.
I'll work on the wording in the commit message. When there is a single PC-relative branch or jump in the packet, we use tcg_gen_goto_tb/tcg_gen_exit_tb. Otherwise, we use tcg_gen_lookup_and_goto_ptr.
Quoted 14 lines
That said, this is certainly an improvement.
target/hexagon/genptr.c static void gen_write_new_pc_addr(DisasContext *ctx, TCGv addr, TCGv pred) · line 495
Quoted 11 lines
target/hexagon/genptr.c +11
-0+if (ctx->pkt->pkt_has_multi_cof) { +gen_write_new_pc_addr (ctx,tcg_constant_tl (dest), pred); + }else { +/* Defer this jump to the end of the TB */ +g_assert (ctx->branch_cond ==NULL ); + ctx->has_single_direct_branch = true; +if (pred !=NULL ) { + ctx->branch_cond =tcg_temp_local_new (); +tcg_gen_mov_tl (ctx->branch_cond, pred); + } + ctx->branch_dest = dest;
Quoted 1 line
Perhaps re-use
hex_branch_takenasbranch_cond?
Good idea. That will save the allocation/deallocation of the TCGv. I'll change it to a TCGCond to indicate the comparison to be done (if any). It will work nicely with your other suggestion to pass the branch condition along.
Quoted 6 lines
Anyway,
Reviewed-by Richard Henderson <[email protected]>r~
PATCH v3 11/11 Hexagon (target/hexagon) Use direct block chaining for tight loops
In reply to Taylor SimpsonDirect block chaining is documented here
https://qemu.readthedocs.io/en/latest/devel/tcg.html#direct-block-chaining
Hexagon inner loops end with the endloop0 instruction
To go back to the beginning of the loop, this instructions writes to PC from register SA0 (start address 0). To use direct block chaining, we have to assign PC with a constant value. So, we specialize the code generation when the start of the translation block is equal to SA0.
When this is the case, we defer the compare/branch from endloop0 to gen_end_tb. When this is done, we can assign the start address of the TB to PC.
--- target/hexagon/cpu.h | 17 ++++++++---- target/hexagon/gen_tcg.h | 3 ++ target/hexagon/translate.h | 1 + target/hexagon/genptr.c | 57 ++++++++++++++++++++++++++++++++++++++ target/hexagon/translate.c | 34 +++++++++++++++++++++++ 5 files changed, 107 insertions(+), 5 deletions(-)
target/hexagon/cpu.h +12 -5
@@ -152,16 +152,23 @@ struct ArchCPU {#include "cpu_bits.h" +typedef union { +uint32_t i; +struct { +bool is_tight_loop:1 ; + }; +}HexStateFlags ; +static inline void cpu_get_tb_cpu_state (CPUHexagonState *env,target_ulong *pc,target_ulong *cs_base,uint32_t *flags) { +HexStateFlags hex_flags = {0 }; *pc = env->gpr[HEX_REG_PC ]; *cs_base =0 ; -#ifdef CONFIG_USER_ONLY - *flags =0 ; -#else -#error System mode not supported on Hexagon yet -#endif +if (*pc == env->gpr[HEX_REG_SA0 ]) { + hex_flags.is_tight_loop = true; + } + *flags = hex_flags.i; }static inline int cpu_mmu_index (CPUHexagonState *env,bool ifetch)
target/hexagon/gen_tcg.h +3 -0
@@ -620,6 +620,9 @@#define fGEN_TCG_J2_callf (SHORTCODE ) \ gen_cond_call(ctx, PuV, false, riV) +#define fGEN_TCG_J2_endloop0 (SHORTCODE ) \ + gen_endloop0(ctx) +/* * Compound compare and jump instructions * Here is a primer to understand the tag names
target/hexagon/translate.h +1 -0
@@ -60,6 +60,7 @@ typedef struct DisasContext {bool has_single_direct_branch;TCGv branch_cond;target_ulong branch_dest; +bool is_tight_loop; } DisasContext;static inline void ctx_log_reg_write (DisasContext *ctx,int rnum)
target/hexagon/genptr.c +57 -0
63 lines not on this page · raw message
target/hexagon/translate.c +34 -0
@@ -135,6 +135,8 @@ static void gen_goto_tb(DisasContext *ctx, int idx, target_ulong dest)static void gen_end_tb (DisasContext *ctx) { +Packet *pkt = ctx->pkt; +gen_exec_counters (ctx);if (ctx->has_single_direct_branch) {
@@ -149,6 +151,18 @@ static void gen_end_tb(DisasContext *ctx) }else {gen_goto_tb (ctx,0 , ctx->branch_dest); } + }else if (ctx->is_tight_loop && + pkt->insn[pkt->num_insns -1 ].opcode == J2_endloop0) { +/* +* When we're in a tight loop, we defer the endloop0 processing +* to take advantage of direct block chaining +*/ +TCGLabel *skip =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_LEU , hex_gpr[HEX_REG_LC0 ],1 , skip); +tcg_gen_subi_tl (hex_gpr[HEX_REG_LC0 ], hex_gpr[HEX_REG_LC0 ],1 ); +gen_goto_tb (ctx,0 , ctx->base.tb->pc); +gen_set_label (skip); +gen_goto_tb (ctx,1 , ctx->next_PC); }else {tcg_gen_lookup_and_goto_ptr (); }
@@ -340,6 +354,15 @@ static void mark_implicit_reg_write(DisasContext *ctx, int attrib, int rnum)*/ bool is_predicated =GET_ATTRIB (opcode,A_CONDEXEC ) || rnum ==HEX_REG_USR ; + +/* LC0/LC1 is conditionally written by endloop instructions */ +if ((rnum ==HEX_REG_LC0 || rnum ==HEX_REG_LC1 ) && + (opcode == J2_endloop0 || + opcode == J2_endloop1 || + opcode == J2_endloop01)) { + is_predicated = true; + } +if (is_predicated && !is_preloaded (ctx, rnum)) {tcg_gen_mov_tl (hex_new_value[rnum], hex_gpr[rnum]); }
@@ -423,6 +446,14 @@ static void gen_reg_writes(DisasContext *ctx)int reg_num = ctx->reg_log[i];tcg_gen_mov_tl (hex_gpr[reg_num], hex_new_value[reg_num]); + +/* +* ctx->is_tight_loop is set when SA0 points to the beginning of the TB. +* If we write to SA0, we have to turn off tight loop handling. +*/ +if (reg_num ==HEX_REG_SA0 ) { + ctx->is_tight_loop = false; + } } }
@@ -846,8 +877,11 @@ static void hexagon_tr_init_disas_context(DisasContextBase *dcbase,static void hexagon_tr_tb_start (DisasContextBase *db,CPUState *cpu) {DisasContext *ctx =container_of (db, DisasContext, base); +HexStateFlags hex_flags = { db->tb->flags }; + ctx->has_single_direct_branch = false; ctx->branch_cond =NULL ; + ctx->is_tight_loop = hex_flags.is_tight_loop; }static void hexagon_tr_insn_start (DisasContextBase *dcbase,CPUState *cpu)
Signature · 1 line
2.17.1
Re: [PATCH v3 11/11] Hexagon (target/hexagon) Use direct block chaining for tight loops
Quoted 27 lines · Taylor Simpson
Direct block chaining is documented here
https://qemu.readthedocs.io/en/latest/devel/tcg.html#direct-block-chainingHexagon inner loops end with the endloop0 instruction
To go back to the beginning of the loop, this instructions writes to PC from register SA0 (start address 0). To use direct block chaining, we have to assign PC with a constant value. So, we specialize the code generation when the start of the translation block is equal to SA0.When this is the case, we defer the compare/branch from endloop0 to
gen_end_tb. When this is done, we can assign the start address of the TB to PC.Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/cpu.h | 17 ++++++++---- target/hexagon/gen_tcg.h | 3 ++ target/hexagon/translate.h | 1 + target/hexagon/genptr.c | 57 ++++++++++++++++++++++++++++++++++++++ target/hexagon/translate.c | 34 +++++++++++++++++++++++ 5 files changed, 107 insertions(+), 5 deletions(-)target/hexagon/cpu.h +0
-0
target/hexagon/cpu.h struct ArchCPU { · line 160
Quoted 9 lines
target/hexagon/cpu.h +6
-0@@ -152,16 +152,23 @@ struct ArchCPU {#include "cpu_bits.h" +typedef union { +uint32_t i; +struct { +bool is_tight_loop:1 ; + }; +}HexStateFlags ;
I don't see this as an improvement on manual flags handling, as it makes the flags value be dependent on host bit-field ordering. This makes it more difficult to compare traces across hosts.
Otherwise,
r~
RE: [PATCH v3 11/11] Hexagon (target/hexagon) Use direct block chaining for tight loops
Quoted 45 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, November 4, 2022 8:44 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>; Matheus Bernardino (QUIC) <[email protected]>
Subject: Re: [PATCH v3 11/11] Hexagon (target/hexagon) Use direct block chaining for tight loopsQuoted 14 lines · Taylor Simpson
Direct block chaining is documented here
https://qemu.readthedocs.io/en/latest/devel/tcg.html#direct-block-chai
ningHexagon inner loops end with the endloop0 instruction To go back to the beginning of the loop, this instructions writes to PC from register SA0 (start address 0). To use direct block chaining, we have to assign PC with a constant value. So, we specialize the code generation when the start of the translation block is equal to SA0.
When this is the case, we defer the compare/branch from endloop0 to
gen_end_tb. When this is done, we can assign the start address of the TB to PC.Quoted 6 lines
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/cpu.h | 17 ++++++++---- target/hexagon/gen_tcg.h | 3 ++ target/hexagon/translate.h | 1 + target/hexagon/genptr.c | 57++++++++++++++++++++++++++++++++++++++
Quoted 11 lines
target/hexagon/translate.c | 34 +++++++++++++++++++++++ 5 files changed, 107 insertions(+), 5 deletions(-)target/hexagon/cpu.h index renamed from target/hexagon/cpu.h +0
-0
ff8c26272d..5260e0f127100644target/hexagon/cpu.h +0
-0@@ -152,16 +152,23 @@ struct ArchCPU {#include "cpu_bits.h"
Quoted 10 lines
target/hexagon/cpu.h struct ArchCPU { · line 160
Quoted 6 lines
target/hexagon/cpu.h +6
-0+typedef union { +uint32_t i; +struct { +bool is_tight_loop:1 ; + }; +}HexStateFlags ;I don't see this as an improvement on manual flags handling, as it makes the flags value be dependent on host bit-field ordering. This makes it more difficult to compare traces across hosts.
I coded this originally with manual handling but decided this would be easier to read/understand/maintain - especially as we add more flags and some have more than 1 bit.
I haven't noticed the flags in any of the logs. Where are they printed?
Quoted 6 lines
Otherwise,
Reviewed-by Richard Henderson <[email protected]>r~
Re: [PATCH v3 11/11] Hexagon (target/hexagon) Use direct block chaining for tight loops
Quoted 3 lines · Taylor Simpson
I coded this originally with manual handling but decided this would be easier to read/understand/maintain - especially as we add more flags and some have more than 1 bit.
I haven't noticed the flags in any of the logs. Where are they printed?
Third field of -d exec, e.g.
Trace 0: 0x7f09a40004c0 [0000000000000000/fffffc0000000044/01000001/ff000000] __start
^^^^^^^^
r~