hex queue
The following changes since commit 667e1fff878326c35c7f5146072e60a63a9a41c8:
Merge tag 'hw-misc-20251230' of https://github.com/philmd/qemu into staging (2025-12-31 16:44:17 +1100)
are available in the Git repository at:
https://github.com/quic/qemu tags/pull-hex-20260102
for you to fetch changes up to 15722c774ab2fa6904464cd531bc1120d9553896:
Hexagon (target/hexagon) s/log_write/gen_write (2025-12-31 22:57:44 -0600)
----------------------------------------------------------------
Bypass packet commit for implicit usr write; cleanup
----------------------------------------------------------------
Taylor Simpson (9):
Hexagon (target/hexagon) Remove gen_tcg_func_table.py Hexagon (target/hexagon) Add pkt_need_commit argument to arch_fpop_end Hexagon (target/hexagon) Implicit writes to USR don't force packet commit Hexagon (tests/tcg/hexagon) Add test for USR changes in packet Hexagon (target/hexagon) analyze all reads before writes Hexagon (target/hexagon) Remove gen_log_reg_write
Hexagon (target/hexagon) s/gen_log_pred_write/gen_pred_write Hexagon (target/hexagon) s/gen_log_vreg_write/gen_vreg_write Hexagon (target/hexagon) s/log_write/gen_write
target/hexagon/arch.h | 2 +- target/hexagon/gen_tcg.h | 125 ++++++------ target/hexagon/genptr.h | 3 +- target/hexagon/helper.h | 114 +++++------ target/hexagon/translate.h | 1 + target/hexagon/arch.c | 3 +- target/hexagon/genptr.c | 92 ++++----- target/hexagon/idef-parser/parser-helpers.c | 4 +- target/hexagon/op_helper.c | 287 +++++++++++++++++----------- target/hexagon/translate.c | 53 +++-- tests/tcg/hexagon/usr.c | 54 ++++++ target/hexagon/README | 11 +- target/hexagon/gen_analyze_funcs.py | 4 + target/hexagon/gen_helper_funcs.py | 8 +- target/hexagon/gen_tcg_func_table.py | 66 ------- target/hexagon/gen_tcg_funcs.py | 7 +- target/hexagon/hex_common.py | 56 +++--- target/hexagon/meson.build | 10 - 18 files changed, 472 insertions(+), 428 deletions(-) delete mode 100755 target/hexagon/gen_tcg_func_table.py
[PULL 9/9] Hexagon (target/hexagon) s/log_write/gen_write
From: Taylor Simpson <[email protected]>
These functions don't "log" anything, they just generate the write
--- target/hexagon/gen_tcg_funcs.py | 2 +- target/hexagon/hex_common.py | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-)
target/hexagon/gen_tcg_funcs.py +1 -1
@@ -98,7 +98,7 @@ def gen_tcg_func(f, tag, regs, imms): for regtype, regid in regs: reg = hex_common.get_register(tag, regtype, regid) if reg.is_written(): - reg.log_write(f, tag) + reg.gen_write(f, tag) f.write("}\n\n")
target/hexagon/hex_common.py +15 -15
@@ -451,7 +451,7 @@ def decl_tcg(self, f, tag, regno): f.write(code_fmt(f"""\ TCGv {self.reg_tcg()} = get_result_gpr(ctx, {self.reg_num}); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): ## No write needed return def analyze_write(self, f, tag, regno):
@@ -494,7 +494,7 @@ def decl_tcg(self, f, tag, regno): f.write(code_fmt(f"""\ tcg_gen_mov_tl({self.reg_tcg()}, hex_gpr[{self.reg_num}]); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): ## No write needed return def analyze_read(self, f, regno):
@@ -517,7 +517,7 @@ def decl_tcg(self, f, tag, regno): f.write(code_fmt(f"""\ TCGv {self.reg_tcg()} = get_result_gpr(ctx, {self.reg_num}); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): f.write(code_fmt(f"""\ gen_write_ctrl_reg(ctx, {self.reg_num}, {self.reg_tcg()}); """))
@@ -569,7 +569,7 @@ def decl_tcg(self, f, tag, regno): f.write(code_fmt(f"""\ TCGv {self.reg_tcg()} = tcg_temp_new(); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): f.write(code_fmt(f"""\ gen_pred_write(ctx, {self.reg_num}, {self.reg_tcg()}); """))
@@ -606,7 +606,7 @@ def decl_tcg(self, f, tag, regno): TCGv {self.reg_tcg()} = tcg_temp_new(); tcg_gen_mov_tl({self.reg_tcg()}, hex_pred[{self.reg_num}]); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): f.write(code_fmt(f"""\ gen_pred_write(ctx, {self.reg_num}, {self.reg_tcg()}); """))
@@ -626,7 +626,7 @@ def decl_tcg(self, f, tag, regno): TCGv_i64 {self.reg_tcg()} = get_result_gpr_pair(ctx, {self.reg_num}); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): f.write(code_fmt(f"""\ gen_write_reg_pair(ctx, {self.reg_num}, {self.reg_tcg()}); """))
@@ -660,7 +660,7 @@ def decl_tcg(self, f, tag, regno): hex_gpr[{self.reg_num}], hex_gpr[{self.reg_num} + 1]); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): f.write(code_fmt(f"""\ gen_write_reg_pair(ctx, {self.reg_num}, {self.reg_tcg()}); """))
@@ -685,7 +685,7 @@ def decl_tcg(self, f, tag, regno): TCGv_i64 {self.reg_tcg()} = get_result_gpr_pair(ctx, {self.reg_num}); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): f.write(code_fmt(f"""\ gen_write_ctrl_reg_pair(ctx, {self.reg_num}, {self.reg_tcg()}); """))
@@ -723,7 +723,7 @@ def decl_tcg(self, f, tag, regno): TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr(); tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()}); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): pass def helper_hvx_desc(self, f): f.write(code_fmt(f"""\
@@ -789,7 +789,7 @@ def decl_tcg(self, f, tag, regno): TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr(); tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()}); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): pass def helper_hvx_desc(self, f): f.write(code_fmt(f"""\
@@ -821,7 +821,7 @@ def decl_tcg(self, f, tag, regno): vreg_src_off(ctx, {self.reg_num}), sizeof(MMVector), sizeof(MMVector)); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): f.write(code_fmt(f"""\ gen_vreg_write(ctx, {self.hvx_off()}, {self.reg_num}, {hvx_newv(tag)});
@@ -854,7 +854,7 @@ def decl_tcg(self, f, tag, regno): TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr(); tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()}); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): pass def helper_hvx_desc(self, f): f.write(code_fmt(f"""\
@@ -913,7 +913,7 @@ def decl_tcg(self, f, tag, regno): TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr(); tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()}); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): f.write(code_fmt(f"""\ gen_vreg_write_pair(ctx, {self.hvx_off()}, {self.reg_num}, {hvx_newv(tag)});
@@ -946,7 +946,7 @@ def decl_tcg(self, f, tag, regno): TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr(); tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()}); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): pass def helper_hvx_desc(self, f): f.write(code_fmt(f"""\
@@ -993,7 +993,7 @@ def decl_tcg(self, f, tag, regno): TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr(); tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()}); """)) - def log_write(self, f, tag): + def gen_write(self, f, tag): pass def helper_hvx_desc(self, f): f.write(code_fmt(f"""\
Signature · 1 line
2.34.1
[PULL 1/9] Hexagon (target/hexagon) Remove gen_tcg_func_table.py
In reply to Brian CainFrom: Taylor Simpson <[email protected]>
This can easily be done in C with opcodes_def_generated.h.inc
Note that gen_tcg_func_table.py has some logic to skip instructions. However, there aren't any instructions currently in the code that would be skipped by this logic. So, it is safe to base the table on the complete opcodes table.
--- target/hexagon/genptr.c | 6 ++- target/hexagon/README | 1 - target/hexagon/gen_tcg_func_table.py | 66 ---------------------------- target/hexagon/meson.build | 10 ----- 4 files changed, 5 insertions(+), 78 deletions(-) delete mode 100755 target/hexagon/gen_tcg_func_table.py
target/hexagon/genptr.c +5 -1
@@ -1454,4 +1454,8 @@ void gen_add_sat_i64(DisasContext *ctx, TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b) }#include "tcg_funcs_generated.c.inc" -#include "tcg_func_table_generated.c.inc" +const SemanticInsn opcode_genptr[XX_LAST_OPCODE ] = { +#define OPCODE(X) [X] = generate_##X +#include "opcodes_def_generated.h.inc" +#undef OPCODE +};
target/hexagon/README +0 -1
@@ -47,7 +47,6 @@ header files in <BUILD_DIR>/target/hexagon gen_op_attribs.py -> op_attribs_generated.h.inc gen_helper_protos.py -> helper_protos_generated.h.inc gen_tcg_funcs.py -> tcg_funcs_generated.c.inc - 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
target/hexagon/gen_tcg_func_table.py deleted +0 -66
66 lines not on this page · raw message
target/hexagon/meson.build +0 -10
@@ -41,20 +41,10 @@ hexagon_ss.add(semantics_generated) # # Step 2 # We use Python scripts to generate the following files -# tcg_func_table_generated.c.inc # printinsn_generated.h.inc # op_attribs_generated.h.inc # opcodes_def_generated.h.inc # -tcg_func_table_generated = custom_target( - 'tcg_func_table_generated.c.inc', - output: 'tcg_func_table_generated.c.inc', - depends: [semantics_generated], - depend_files: [hex_common_py], - command: [python, files('gen_tcg_func_table.py'), semantics_generated, '@OUTPUT@'], -) -hexagon_ss.add(tcg_func_table_generated) - printinsn_generated = custom_target( 'printinsn_generated.h.inc', output: 'printinsn_generated.h.inc',
Signature · 1 line
2.34.1
[PULL 8/9] Hexagon (target/hexagon) s/gen_log_vreg_write/gen_vreg_write
In reply to Brian CainFrom: Taylor Simpson <[email protected]>
Note there are two functions impacted
gen_log_vreg_write -> gen_vreg_write
gen_log_vreg_write_pair -> gen_vreg_write_pairThese functions don't "log" anything, they just generate the write
--- target/hexagon/genptr.c | 8 ++++---- target/hexagon/hex_common.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-)
target/hexagon/genptr.c +4 -4
@@ -1174,7 +1174,7 @@ static intptr_t vreg_src_off(DisasContext *ctx, int num)return offset; } -static void gen_log_vreg_write (DisasContext *ctx,intptr_t srcoff,int num, +static void gen_vreg_write (DisasContext *ctx,intptr_t srcoff,int num,VRegWriteType type) {intptr_t dstoff;
@@ -1190,12 +1190,12 @@ static void gen_log_vreg_write(DisasContext *ctx, intptr_t srcoff, int num, } } -static void gen_log_vreg_write_pair (DisasContext *ctx,intptr_t srcoff,int num, +static void gen_vreg_write_pair (DisasContext *ctx,intptr_t srcoff,int num,VRegWriteType type) { -gen_log_vreg_write (ctx, srcoff, num ^0 , type); +gen_vreg_write (ctx, srcoff, num ^0 , type); srcoff +=sizeof (MMVector); -gen_log_vreg_write (ctx, srcoff, num ^1 , type); +gen_vreg_write (ctx, srcoff, num ^1 , type); }static intptr_t get_result_qreg (DisasContext *ctx,int qnum)
target/hexagon/hex_common.py +4 -4
@@ -823,8 +823,8 @@ def decl_tcg(self, f, tag, regno): """)) def log_write(self, f, tag): f.write(code_fmt(f"""\ - gen_log_vreg_write(ctx, {self.hvx_off()}, {self.reg_num}, - {hvx_newv(tag)}); + gen_vreg_write(ctx, {self.hvx_off()}, {self.reg_num}, + {hvx_newv(tag)}); """)) def helper_hvx_desc(self, f): f.write(code_fmt(f"""\
@@ -915,8 +915,8 @@ def decl_tcg(self, f, tag, regno): """)) def log_write(self, f, tag): f.write(code_fmt(f"""\ - gen_log_vreg_write_pair(ctx, {self.hvx_off()}, {self.reg_num}, - {hvx_newv(tag)}); + gen_vreg_write_pair(ctx, {self.hvx_off()}, {self.reg_num}, + {hvx_newv(tag)}); """)) def helper_hvx_desc(self, f): f.write(code_fmt(f"""\
Signature · 1 line
2.34.1
[PULL 3/9] Hexagon (target/hexagon) Implicit writes to USR don't force packet commit
In reply to Brian CainFrom: Taylor Simpson <[email protected]>
Implicit writes to USR are only to specific fields of USR to indicate side effects (e.g., saturation overflow, floating point status). In these cases, we don't force a packet commit. This will allow more packets to be short-circuited (avoid writing the results to temporaries).
When there is a packet commit with an implicit write to USR, we initialize new_value_usr during gen_start_packet and write to USR in gen_reg_writes.
--- target/hexagon/translate.h | 1 + target/hexagon/translate.c | 35 ++++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 13 deletions(-)
target/hexagon/translate.h +1 -0
@@ -39,6 +39,7 @@ typedef struct DisasContext {int reg_log_idx;DECLARE_BITMAP (regs_written,TOTAL_PER_THREAD_REGS );DECLARE_BITMAP (predicated_regs,TOTAL_PER_THREAD_REGS ); +bool implicit_usr_write;int preg_log[PRED_WRITES_MAX ];int preg_log_idx;DECLARE_BITMAP (pregs_written,NUM_PREGS );
target/hexagon/translate.c +22 -13
@@ -272,12 +272,7 @@ static void mark_implicit_reg_write(DisasContext *ctx, int attrib, int rnum) {uint16_t opcode = ctx->insn->opcode;if (GET_ATTRIB (opcode, attrib)) { -/* -* USR is used to set overflow and FP exceptions, -* so treat it as conditional -*/ -bool is_predicated =GET_ATTRIB (opcode,A_CONDEXEC ) || - rnum ==HEX_REG_USR ; +bool is_predicated =GET_ATTRIB (opcode,A_CONDEXEC );/* LC0/LC1 is conditionally written by endloop instructions */ if ((rnum == HEX_REG_LC0 || rnum == HEX_REG_LC1) &&
@@ -291,6 +286,14 @@ static void mark_implicit_reg_write(DisasContext *ctx, int attrib, int rnum) } } +static void mark_implicit_usr_write (DisasContext *ctx,int attrib) +{ +uint16_t opcode = ctx->insn->opcode; +if (GET_ATTRIB (opcode, attrib)) { + ctx->implicit_usr_write = true; + } +} +static void mark_implicit_reg_writes (DisasContext *ctx) {mark_implicit_reg_write (ctx,A_IMPLICIT_WRITES_FP ,HEX_REG_FP );
@@ -300,8 +303,9 @@ static void mark_implicit_reg_writes(DisasContext *ctx)mark_implicit_reg_write (ctx,A_IMPLICIT_WRITES_SA0 ,HEX_REG_SA0 );mark_implicit_reg_write (ctx,A_IMPLICIT_WRITES_LC1 ,HEX_REG_LC1 );mark_implicit_reg_write (ctx,A_IMPLICIT_WRITES_SA1 ,HEX_REG_SA1 ); -mark_implicit_reg_write (ctx,A_IMPLICIT_WRITES_USR ,HEX_REG_USR ); -mark_implicit_reg_write (ctx,A_FPOP ,HEX_REG_USR ); + +mark_implicit_usr_write (ctx,A_IMPLICIT_WRITES_USR ); +mark_implicit_usr_write (ctx,A_FPOP ); }static void mark_implicit_pred_write (DisasContext *ctx,int attrib,int pnum)
@@ -351,11 +355,6 @@ static bool need_commit(DisasContext *ctx) } } -/* Floating point instructions are hard-coded to use new_value */ -if (check_for_attrib (pkt,A_FPOP )) { -return true; - } -if (ctx->read_after_write || ctx->has_hvx_overlap) {return true; }
@@ -467,6 +466,12 @@ static void gen_start_packet(DisasContext *ctx) } } +/* Preload usr to new_value_usr */ +if (ctx->need_commit && ctx->implicit_usr_write && + !test_bit (HEX_REG_USR , ctx->regs_written)) { +tcg_gen_mov_tl (hex_new_value_usr, hex_gpr[HEX_REG_USR ]); + } +/* * Preload the predicated pred registers into ctx->new_pred_value[pred_num] * Only endloop instructions conditionally write to pred registers
@@ -587,6 +592,10 @@ static void gen_reg_writes(DisasContext *ctx) ctx->is_tight_loop = false; } } + +if (ctx->implicit_usr_write && !test_bit (HEX_REG_USR , ctx->regs_written)) { +tcg_gen_mov_tl (hex_gpr[HEX_REG_USR ], hex_new_value_usr); + } }static void gen_pred_writes (DisasContext *ctx)
Signature · 1 line
2.34.1
[PULL 2/9] Hexagon (target/hexagon) Add pkt_need_commit argument to arch_fpop_end
In reply to Brian CainFrom: Taylor Simpson <[email protected]>
The arch_fpop_end function converts the softfloat fp_status flags to bits set in Hexagon USR. It is hard-coded that the packet must need a commit. We add an argument to the function and update all the helper call sites.
In a subsequent commit, we will change the code that forces a commit when the packet contains an floating point instruction.
--- target/hexagon/arch.h | 2 +- target/hexagon/gen_tcg.h | 114 ++++++------ target/hexagon/helper.h | 114 ++++++------ target/hexagon/arch.c | 3 +- target/hexagon/op_helper.c | 287 +++++++++++++++++------------ target/hexagon/gen_helper_funcs.py | 8 +- target/hexagon/gen_tcg_funcs.py | 4 + 7 files changed, 294 insertions(+), 238 deletions(-)
target/hexagon/arch.h +1 -1
@@ -28,7 +28,7 @@ uint64_t interleave(uint32_t odd, uint32_t even);uint64_t deinterleave (uint64_t src);int32_t conv_round (int32_t a,int n);void arch_fpop_start (CPUHexagonState *env); -void arch_fpop_end (CPUHexagonState *env); +void arch_fpop_end (CPUHexagonState *env,bool pkt_need_commit);int arch_sf_recip_common (float32 *Rs,float32 *Rt,float32 *Rd,int *adjust,float_status *fp_status); int arch_sf_invsqrt_common(float32 *Rs, float32 *Rd, int *adjust,
target/hexagon/gen_tcg.h +57 -57
193 lines not on this page · raw message
target/hexagon/helper.h +57 -57
129 lines not on this page · raw message
target/hexagon/arch.c +1 -2
@@ -222,9 +222,8 @@ void arch_fpop_start(CPUHexagonState *env) } \ }while (0 ) -void arch_fpop_end(CPUHexagonState *env) +void arch_fpop_end(CPUHexagonState *env, bool pkt_need_commit) { -const bool pkt_need_commit = true;int flags =get_float_exception_flags (&env->fp_status);if (flags !=0 ) {SOFTFLOAT_TEST_FLAG (float_flag_inexact,FPINPF ,FPINPE );
target/hexagon/op_helper.c +171 -116
755 lines not on this page · raw message
target/hexagon/gen_helper_funcs.py +3 -5
@@ -84,11 +84,6 @@ def gen_helper_function(f, tag, tagregs, tagimms): {hex_common.semdict[tag]} """)) - if "A_FPOP" in hex_common.attribdict[tag]: - f.write(hex_common.code_fmt(f"""\ - arch_fpop_end(env); - """)) - ## Return the scalar result for regtype, regid in regs: reg = hex_common.get_register(tag, regtype, regid)
@@ -116,6 +111,9 @@ def main(): ## Skip the guest instructions if "A_GUEST" in hex_common.attribdict[tag]: continue + ## Skip the floating point instructions + if "A_FPOP" in hex_common.attribdict[tag]: + continue ## Skip the diag instructions if tag == "Y6_diag": continue
target/hexagon/gen_tcg_funcs.py +4 -0
@@ -77,6 +77,10 @@ def gen_tcg_func(f, tag, regs, imms): f.write(f" emit_{tag}({arguments});\n") elif hex_common.skip_qemu_helper(tag): + if "A_FPOP" in hex_common.attribdict[tag]: + f.write(" TCGv pkt_need_commit = ") + f.write("tcg_constant_tl(ctx->need_commit);\n") + f.write(f" fGEN_TCG_{tag}({hex_common.semdict[tag]});\n") else: ## Generate the call to the helper
Signature · 1 line
2.34.1
[PULL 6/9] Hexagon (target/hexagon) Remove gen_log_reg_write
In reply to Brian CainFrom: Taylor Simpson <[email protected]>
The gen_log_reg_write function is a memnant of the original Hexagon target design. With the addition of gen_analyze_funcs.py and the ability to short-circuit a packet commit, this function can be removed.
Note that the implementation of gen_log_reg_write contains a check of the register mutability mask. This is only needed for control registers, so we move it to gen_write_ctrl_reg.
We do need the gen_log_reg_write_pair function, but the name is now misleading, so we change the name go gen_write_reg_pair.
--- target/hexagon/gen_tcg.h | 7 +-- target/hexagon/genptr.h | 1 - target/hexagon/genptr.c | 64 ++++++++------------- target/hexagon/idef-parser/parser-helpers.c | 2 +- target/hexagon/README | 10 ++-- target/hexagon/gen_tcg_funcs.py | 1 - target/hexagon/hex_common.py | 14 ++--- 7 files changed, 40 insertions(+), 59 deletions(-)
target/hexagon/gen_tcg.h +3 -4
@@ -509,10 +509,9 @@/* sub-instruction version (no RxV, so handle it manually) */ #define fGEN_TCG_SS2_allocframe (SHORTCODE ) \ do { \ - TCGv r29 = tcg_temp_new(); \ + TCGv r29 = get_result_gpr(ctx, HEX_REG_SP); \ tcg_gen_mov_tl(r29, hex_gpr[HEX_REG_SP]); \ gen_allocframe(ctx, r29, uiV); \ - gen_log_reg_write(ctx, HEX_REG_SP, r29); \ } while (0)/*
@@ -528,7 +527,7 @@do { \TCGv_i64 r31_30 =tcg_temp_new_i64 (); \gen_deallocframe (ctx, r31_30, hex_gpr[HEX_REG_FP ]); \ -gen_log_reg_write_pair (ctx,HEX_REG_FP , r31_30); \ +gen_write_reg_pair (ctx,HEX_REG_FP , r31_30); \ }while (0 )/*
@@ -546,7 +545,7 @@do { \TCGv_i64 RddV =get_result_gpr_pair (ctx,HEX_REG_FP ); \gen_return (ctx, RddV, hex_gpr[HEX_REG_FP ]); \ -gen_log_reg_write_pair (ctx,HEX_REG_FP , RddV); \ +gen_write_reg_pair (ctx,HEX_REG_FP , RddV); \ }while (0 )/*
target/hexagon/genptr.h +0 -1
@@ -37,7 +37,6 @@ TCGv gen_read_reg(TCGv result, int num);TCGv gen_read_preg (TCGv pred,uint8_t num);TCGv get_result_gpr (DisasContext *ctx,int rnum);TCGv get_result_pred (DisasContext *ctx,int pnum); -void gen_log_reg_write (DisasContext *ctx,int rnum,TCGv val);void gen_log_pred_write (DisasContext *ctx,int pnum,TCGv val);void gen_set_usr_field (DisasContext *ctx,int field,TCGv val);void gen_set_usr_fieldi (DisasContext *ctx,int field,int x);
target/hexagon/genptr.c +24 -40
135 lines not on this page · raw message
target/hexagon/idef-parser/parser-helpers.c +1 -1
@@ -1315,7 +1315,7 @@ void gen_write_reg(Context *c, YYLTYPE *locp, HexValue *reg, HexValue *value) value_m =rvalue_materialize (c, locp, &value_m);OUT (c, locp, -"gen_log_reg_write(ctx, " , ®->reg.id,", " , +"tcg_gen_mov_tl(get_result_gpr(ctx, " , ®->reg.id,"), " , &value_m,");\n" ); }
target/hexagon/README +6 -4
@@ -79,12 +79,14 @@ tcg_funcs_generated.c.inc Insn *insn, Packet *pkt) { - TCGv RdV = tcg_temp_new(); + Insn *insn G_GNUC_UNUSED = ctx->insn; const int RdN = insn->regno[0]; - TCGv RsV = hex_gpr[insn->regno[1]]; - TCGv RtV = hex_gpr[insn->regno[2]]; + TCGv RdV = get_result_gpr(ctx, RdN); + const int RsN = insn->regno[1]; + TCGv RsV = hex_gpr[RsN]; + const int RtN = insn->regno[2]; + TCGv RtV = hex_gpr[RtN]; gen_helper_A2_add(RdV, tcg_env, RsV, RtV); - gen_log_reg_write(ctx, RdN, RdV); } helper_funcs_generated.c.inc
target/hexagon/gen_tcg_funcs.py +0 -1
@@ -35,7 +35,6 @@ ## TCGv RsV = hex_gpr[insn->regno[1]]; ## TCGv RtV = hex_gpr[insn->regno[2]]; ## <GEN> -## gen_log_reg_write(ctx, RdN, RdV); ## } ## ## where <GEN> depends on hex_common.skip_qemu_helper(tag)
target/hexagon/hex_common.py +6 -8
@@ -452,9 +452,8 @@ def decl_tcg(self, f, tag, regno): TCGv {self.reg_tcg()} = get_result_gpr(ctx, {self.reg_num}); """)) def log_write(self, f, tag): - f.write(code_fmt(f"""\ - gen_log_reg_write(ctx, {self.reg_num}, {self.reg_tcg()}); - """)) + ## No write needed + return def analyze_write(self, f, tag, regno): predicated = "true" if is_predicated(tag) else "false" f.write(code_fmt(f"""\
@@ -496,9 +495,8 @@ def decl_tcg(self, f, tag, regno): tcg_gen_mov_tl({self.reg_tcg()}, hex_gpr[{self.reg_num}]); """)) def log_write(self, f, tag): - f.write(code_fmt(f"""\ - gen_log_reg_write(ctx, {self.reg_num}, {self.reg_tcg()}); - """)) + ## No write needed + return def analyze_read(self, f, regno): f.write(code_fmt(f"""\ ctx_log_reg_read(ctx, {self.reg_num});
@@ -630,7 +628,7 @@ def decl_tcg(self, f, tag, regno): """)) def log_write(self, f, tag): f.write(code_fmt(f"""\ - gen_log_reg_write_pair(ctx, {self.reg_num}, {self.reg_tcg()}); + gen_write_reg_pair(ctx, {self.reg_num}, {self.reg_tcg()}); """)) def analyze_write(self, f, tag, regno): predicated = "true" if is_predicated(tag) else "false"
@@ -664,7 +662,7 @@ def decl_tcg(self, f, tag, regno): """)) def log_write(self, f, tag): f.write(code_fmt(f"""\ - gen_log_reg_write_pair(ctx, {self.reg_num}, {self.reg_tcg()}); + gen_write_reg_pair(ctx, {self.reg_num}, {self.reg_tcg()}); """)) def analyze_read(self, f, regno): f.write(code_fmt(f"""\
Signature · 1 line
2.34.1
[PULL 5/9] Hexagon (target/hexagon) analyze all reads before writes
In reply to Brian CainFrom: Taylor Simpson <[email protected]>
I noticed that analyze_packet is marking the implicit pred reads after marking all the writes. However, the semantics of the instrucion and packet are to do all the reads, then do the operation, then do all the writes.
Here is the old code
static void analyze_packet(DisasContext *ctx)
{
Packet *pkt = ctx->pkt;
ctx->read_after_write = false;
ctx->has_hvx_overlap = false;
for (int i = 0; i < pkt->num_insns; i++) {
Insn *insn = &pkt->insn[i];
ctx->insn = insn;
if (opcode_analyze[insn->opcode]) {
opcode_analyze[insn->opcode](ctx);
}
mark_implicit_reg_writes(ctx);
mark_implicit_pred_writes(ctx);
mark_implicit_pred_reads(ctx);
}
ctx->need_commit = need_commit(ctx);
}Recall that opcode_analyze[insn->opcode](ctx) will mark all the explicit reads then all the explicit writes.
To properly handle the semantics, we'll create two new functions
mark_implicit_reads
mark_implicit_writes
Then we change gen_analyze_funcs.py to add a call to the former after all the explicit reads and a call to the latter after all the explicit_writes.
The reason this is an RFC patch is I can't find any instructions where this distinction makes a difference in ctx->need_commit which determines if the packet commit can be short-circuited. However, this could change in the future if the architecture introduces an instruction with an implicit read of a register that is also written (either implicit or explicit). Then, anlayze_packet would detect a read-after-write, and the packet would not short-circuit. The execution would be correct, but the performance would not be optimal.
Message-Id: <[email protected]>
--- target/hexagon/translate.c | 18 +++++++++++++++--- target/hexagon/gen_analyze_funcs.py | 4 ++++ 2 files changed, 19 insertions(+), 3 deletions(-)
target/hexagon/translate.c +15 -3
@@ -37,6 +37,10 @@#include "exec/helper-info.c.inc" #undef HELPER_H +/* Forward declarations referenced in analyze_funcs_generated.c.inc */ +static void mark_implicit_reads (DisasContext *ctx); +static void mark_implicit_writes (DisasContext *ctx); +#include "analyze_funcs_generated.c.inc" typedef void (*AnalyzeInsn )(DisasContext *ctx);
@@ -377,6 +381,17 @@ static void mark_implicit_pred_reads(DisasContext *ctx)mark_implicit_pred_read (ctx,A_IMPLICIT_READS_P3 ,3 ); } +static void mark_implicit_reads (DisasContext *ctx) +{ +mark_implicit_pred_reads (ctx); +} + +static void mark_implicit_writes (DisasContext *ctx) +{ +mark_implicit_reg_writes (ctx); +mark_implicit_pred_writes (ctx); +} +static void analyze_packet (DisasContext *ctx) {Packet *pkt = ctx->pkt;
@@ -388,9 +403,6 @@ static void analyze_packet(DisasContext *ctx)if (opcode_analyze[insn->opcode]) { opcode_analyze[insn->opcode](ctx); } -mark_implicit_reg_writes (ctx); -mark_implicit_pred_writes (ctx); -mark_implicit_pred_reads (ctx); } ctx->need_commit =need_commit (ctx);
target/hexagon/gen_analyze_funcs.py +4 -0
@@ -67,6 +67,8 @@ def gen_analyze_func(f, tag, regs, imms): if reg.is_read(): reg.analyze_read(f, regno) + f.write(" mark_implicit_reads(ctx);\n") + ## Analyze the register writes for regno, register in enumerate(regs): reg_type, reg_id = register
@@ -74,6 +76,8 @@ def gen_analyze_func(f, tag, regs, imms): if reg.is_written(): reg.analyze_write(f, tag, regno) + f.write(" mark_implicit_writes(ctx);\n") + f.write("}\n\n")
Signature · 1 line
2.34.1
[PULL 7/9] Hexagon (target/hexagon) s/gen_log_pred_write/gen_pred_write
In reply to Brian CainFrom: Taylor Simpson <[email protected]>
The function doesn't "log" anything, it just generates the write
--- target/hexagon/gen_tcg.h | 4 ++-- target/hexagon/genptr.h | 2 +- target/hexagon/genptr.c | 14 +++++++------- target/hexagon/idef-parser/parser-helpers.c | 2 +- target/hexagon/hex_common.py | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-)
target/hexagon/gen_tcg.h +2 -2
@@ -599,7 +599,7 @@TCGv p0 =tcg_temp_new (); \gen_helper_cabacdecbin_pred (p0, RssV, RttV); \gen_helper_cabacdecbin_val (RddV, RssV, RttV); \ -gen_log_pred_write (ctx,0 , p0); \ +gen_pred_write (ctx,0 , p0); \ }while (0 )/*
@@ -914,7 +914,7 @@do { \TCGv p0 =tcg_temp_new (); \gen_comparei (TCG_COND_EQ , p0, RsV, uiV); \ -gen_log_pred_write (ctx,0 , p0); \ +gen_pred_write (ctx,0 , p0); \ } while (0)#define fGEN_TCG_J2_jump (SHORTCODE ) \
target/hexagon/genptr.h +1 -1
@@ -37,7 +37,7 @@ TCGv gen_read_reg(TCGv result, int num);TCGv gen_read_preg (TCGv pred,uint8_t num);TCGv get_result_gpr (DisasContext *ctx,int rnum);TCGv get_result_pred (DisasContext *ctx,int pnum); -void gen_log_pred_write (DisasContext *ctx,int pnum,TCGv val); +void gen_pred_write (DisasContext *ctx,int pnum,TCGv val);void gen_set_usr_field (DisasContext *ctx,int field,TCGv val);void gen_set_usr_fieldi (DisasContext *ctx,int field,int x);void gen_set_usr_field_if (DisasContext *ctx,int field,TCGv val);
target/hexagon/genptr.c +7 -7
@@ -120,7 +120,7 @@ TCGv get_result_pred(DisasContext *ctx, int pnum) } } -void gen_log_pred_write (DisasContext *ctx,int pnum,TCGv val) +void gen_pred_write (DisasContext *ctx,int pnum,TCGv val) {TCGv pred =get_result_pred (ctx, pnum);TCGv base_val =tcg_temp_new ();
@@ -215,7 +215,7 @@ static void gen_write_p3_0(DisasContext *ctx, TCGv control_reg)TCGv hex_p8 =tcg_temp_new ();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); +gen_pred_write (ctx, i, hex_p8); } }
@@ -557,7 +557,7 @@ static void gen_ploopNsr(DisasContext *ctx, int N, TCGv RsV, int riV)tcg_gen_mov_tl (get_result_gpr (ctx,HEX_REG_LC0 ), RsV);tcg_gen_movi_tl (get_result_gpr (ctx,HEX_REG_SA0 ), ctx->pkt->pc + riV);gen_set_usr_fieldi (ctx,USR_LPCFG ,N ); -gen_log_pred_write (ctx,3 ,tcg_constant_tl (0 )); +gen_pred_write (ctx,3 ,tcg_constant_tl (0 )); }static void gen_ploopNsi (DisasContext *ctx,int N ,int count,int riV)
@@ -597,7 +597,7 @@ static void gen_cmpnd_cmp_jmp(DisasContext *ctx,if (ctx->insn->part1) {TCGv pred =tcg_temp_new ();gen_compare (cond1, pred, arg1, arg2); -gen_log_pred_write (ctx, pnum, pred); +gen_pred_write (ctx, pnum, pred); }else {TCGv pred =tcg_temp_new ();tcg_gen_mov_tl (pred, ctx->new_pred_value[pnum]);
@@ -654,7 +654,7 @@ static void gen_cmpnd_tstbit0_jmp(DisasContext *ctx,TCGv pred =tcg_temp_new ();tcg_gen_andi_tl (pred, arg,1 );gen_8bitsof (pred, pred); -gen_log_pred_write (ctx, pnum, pred); +gen_pred_write (ctx, pnum, pred); }else {TCGv pred =tcg_temp_new ();tcg_gen_mov_tl (pred, ctx->new_pred_value[pnum]);
@@ -834,7 +834,7 @@ static void gen_endloop0(DisasContext *ctx)TCGLabel *label1 =gen_new_label ();tcg_gen_brcondi_tl (TCG_COND_NE , lpcfg,1 , label1); { -gen_log_pred_write (ctx,3 ,tcg_constant_tl (0xff )); +gen_pred_write (ctx,3 ,tcg_constant_tl (0xff )); }gen_set_label (label1);
@@ -908,7 +908,7 @@ static void gen_endloop01(DisasContext *ctx)*/ tcg_gen_brcondi_tl (TCG_COND_NE , lpcfg,1 , label1); { -gen_log_pred_write (ctx,3 ,tcg_constant_tl (0xff )); +gen_pred_write (ctx,3 ,tcg_constant_tl (0xff )); }gen_set_label (label1);
target/hexagon/idef-parser/parser-helpers.c +1 -1
@@ -1713,7 +1713,7 @@ void gen_pred_assign(Context *c, YYLTYPE *locp, HexValue *left_pred,/* Extract first 8 bits, and store new predicate value */ OUT (c, locp,"tcg_gen_andi_i32(" , left_pred,", " , &r,", 0xff);\n" );if (is_direct) { -OUT (c, locp,"gen_log_pred_write(ctx, " , pred_id,", " , left_pred, +OUT (c, locp,"gen_pred_write(ctx, " , pred_id,", " , left_pred,");\n" ); } }
target/hexagon/hex_common.py +2 -2
@@ -571,7 +571,7 @@ def decl_tcg(self, f, tag, regno): """)) def log_write(self, f, tag): f.write(code_fmt(f"""\ - gen_log_pred_write(ctx, {self.reg_num}, {self.reg_tcg()}); + gen_pred_write(ctx, {self.reg_num}, {self.reg_tcg()}); """)) def analyze_write(self, f, tag, regno): f.write(code_fmt(f"""\
@@ -608,7 +608,7 @@ def decl_tcg(self, f, tag, regno): """)) def log_write(self, f, tag): f.write(code_fmt(f"""\ - gen_log_pred_write(ctx, {self.reg_num}, {self.reg_tcg()}); + gen_pred_write(ctx, {self.reg_num}, {self.reg_tcg()}); """)) def analyze_read(self, f, regno): f.write(code_fmt(f"""\
Signature · 1 line
2.34.1
[PULL 4/9] Hexagon (tests/tcg/hexagon) Add test for USR changes in packet
In reply to Brian CainFrom: Taylor Simpson <[email protected]>
--- tests/tcg/hexagon/usr.c | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
tests/tcg/hexagon/usr.c +54 -0
@@ -608,6 +608,58 @@ TEST_CMP_xx(uint32_t, uint32_t, FUNC, SRC1, SRC2, RES, USR_RES)#define TEST_CMP_PP (FUNC ,SRC1 ,SRC2 ,RES ,USR_RES ) \ TEST_CMP_xx(uint64_t, uint64_t, FUNC, SRC1, SRC2, RES, USR_RES) +static void test_usr_packets (void ) +{ +uint32_t usr_out; +/* Test setting USR bits inside and outside packets */ + asm(CLEAR_USRBITS \ +"r10 = satub(%[val_0xfff]) /* Set usr.OVF */\n\t" +"{\n\t" +" r11 = convert_uw2sf(%[val_0x010020a5]) /* Set usr.FPINPF */\n\t" +" r10 = memw(%[err]) /* Force pkt commit */\n\t" +"}\n\t" +"{\n\t" +" r11 = sfadd(%[SF_one], %[SF_SNaN]) /* Set usr.FPINVF */\n\t" +" r10 = add(r10, #1) /* No pkt commit */\n\t" +"}\n\t" +"%[usr_out] = usr\n\t" + : [usr_out]"=r" (usr_out) + : [val_0xfff]"r" (0xfff ), + [SF_one]"r" (SF_one), [SF_SNaN]"r" (SF_SNaN), + [val_0x010020a5]"r" (0x010020a5 ), + [err]"m" (err) + :"r2" ,"r10" ,"r11" ,"usr" ); +check32 (usr_out &0x3f ,USR_OVF |USR_FPINVF |USR_FPINPF ); + +/* Test setting several USR bits in the same packet (no pkt commit) */ + asm(CLEAR_USRBITS \ +"{\n\t" +" r10 = satub(%[val_0xfff]) /* Set usr.OVF */\n\t" +" r12 = sfadd(%[SF_one], %[SF_SNaN]) /* Set usr.FPINVF */\n\t" +"}\n\t" +"%[usr_out] = usr\n\t" + : [usr_out]"=r" (usr_out) + : [val_0xfff]"r" (0xfff ), + [SF_one]"r" (SF_one), [SF_SNaN]"r" (SF_SNaN) + :"r2" ,"r10" ,"r11" ,"r12" ,"usr" ); +check32 (usr_out &0x3f ,USR_OVF |USR_FPINVF ); + +/* Test setting several USR bits in the same packet (with pkt commit) */ + asm(CLEAR_USRBITS \ +"{\n\t" +" r10 = satub(%[val_0xfff]) /* Set usr.OVF */\n\t" +" r11 = convert_uw2sf(%[val_0x010020a5]) /* Set usr.FPINPF */\n\t" +" r12 = memw(%[err]) /* Force pkt commit */\n\t" +"}\n\t" +"%[usr_out] = usr\n\t" + : [usr_out]"=r" (usr_out) + : [val_0xfff]"r" (0xfff ), + [val_0x010020a5]"r" (0x010020a5 ), + [err]"m" (err) + :"r2" ,"r10" ,"r11" ,"r12" ,"usr" ); +check32 (usr_out &0x3f ,USR_OVF |USR_FPINPF ); +} +int main () {TEST_R_OP_R (satub,0 ,0 ,USR_CLEAR );
@@ -1097,6 +1149,8 @@ int main()TEST_Rp_OP_R (sfinvsqrta, SF_small_neg, SF_HEX_NaN,0x00 ,USR_FPINVF );TEST_Rp_OP_R (sfinvsqrta, SF_SNaN, SF_HEX_NaN,0x00 ,USR_FPINVF ); +test_usr_packets (); +puts (err ?"FAIL" :"PASS" );return err; }
Signature · 1 line
2.34.1
Richard Henderson
AppliedQuoted 6 lines · Brian Cain
The following changes since commit
667e1fff878326c35c7f5146072e60a63a9a41c8:Merge tag 'hw-misc-20251230' ofhttps://github.com/philmd/qemu into staging (2025-12-31 16:44:17 +1100)are available in the Git repository at:
Quoted 8 lines
https://github.com/quic/qemu tags/pull-hex-20260102for you to fetch changes up to
15722c774ab2fa6904464cd531bc1120d9553896:Hexagon (target/hexagon) s/log_write/gen_write (2025-12-31 22:57:44 -0600)----------------------------------------------------------------
Bypass packet commit for implicit usr write; cleanup
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/11.0 as appropriate.
r~