target/hexagon: don't let an idef-parser dest clobber its own source
PATCH 1/1 target/hexagon: don't let an idef-parser dest clobber its own source
The idef-parser emitters write the destination in place, so when a packet is short-circuited and get_result_gpr() returns hex_gpr[] itself, an instruction naming one register as both source and destination reads back a value it already overwrote.
Rd32=cmpy(Rs32,Rt32):<<1:rnd:sat with Rs == Rd is an example.
Give a source reg that aliases a destination its own copy of the register value.
--- target/hexagon/genptr.h | 1 + target/hexagon/genptr.c | 11 ++++++ tests/tcg/hexagon/read_write_overlap.c | 47 ++++++++++++++++++++++++++ target/hexagon/gen_tcg_funcs.py | 15 ++++++++ target/hexagon/hex_common.py | 12 +++++++ 5 files changed, 86 insertions(+)
target/hexagon/genptr.h +1 -0
@@ -36,6 +36,7 @@ void gen_store8i(TCGv_env cpu_env, TCGv vaddr, int64_t src, uint32_t slot);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 gen_unalias_gpr_src (TCGv src,TCGv dst);TCGv get_result_pred (DisasContext *ctx,int pnum);void gen_pred_write (DisasContext *ctx,int pnum,TCGv val);void gen_set_usr_field (DisasContext *ctx,int field,TCGv val);
target/hexagon/genptr.c +11 -0
@@ -91,6 +91,17 @@ TCGv get_result_gpr(DisasContext *ctx, int rnum) } } +TCGv gen_unalias_gpr_src (TCGv src,TCGv dst) +{ +if (src != dst) { +return src; + } + +TCGv tmp =tcg_temp_new (); +tcg_gen_mov_tl (tmp, src); +return tmp; +} +static TCGv_i64 get_result_gpr_pair (DisasContext *ctx,int rnum) {TCGv_i64 result =tcg_temp_new_i64 ();
tests/tcg/hexagon/read_write_overlap.c +47 -0
59 lines not on this page · raw message
target/hexagon/gen_tcg_funcs.py +15 -0
@@ -75,6 +75,21 @@ def gen_tcg_func(f, tag, regs, imms): f.write(f" int {hex_common.imm_name(immlett)} = insn->immed[{i}];\n") if hex_common.is_idef_parser_enabled(tag): + gpr_operands = [ + hex_common.get_register(tag, regtype, regid) + for regtype, regid in regs + if hex_common.get_register(tag, regtype, regid).may_alias_gpr() + ] + dests = [reg for reg in gpr_operands if reg.is_written()] + for reg in gpr_operands: + if reg.is_written() or not reg.is_read(): + continue + src = reg.reg_tcg() + for dest in dests: + f.write(hex_common.code_fmt(f"""\ + {src} = gen_unalias_gpr_src({src}, {dest.reg_tcg()}); + """)) + declared = [] ## Handle registers for regtype, regid in regs:
target/hexagon/hex_common.py +12 -0
@@ -388,6 +388,8 @@ def decl_reg_num(self, f, regno): """)) def idef_arg(self, declared): declared.append(self.reg_tcg()) + def may_alias_gpr(self): + return False def helper_arg(self): return HelperArg( self.helper_proto_type(),
@@ -495,6 +497,8 @@ def is_new(self): return False class GprDest(Register, Single, Dest): + def may_alias_gpr(self): + return True def decl_tcg(self, f, tag, regno): self.decl_reg_num(f, regno) f.write(code_fmt(f"""\
@@ -510,6 +514,8 @@ def analyze_write(self, f, tag, regno): """)) class GprSource(Register, Single, OldSource): + def may_alias_gpr(self): + return True def decl_tcg(self, f, tag, regno): self.decl_reg_num(f, regno) f.write(code_fmt(f"""\
@@ -531,6 +537,8 @@ def analyze_read(self, f, regno): """)) class GprReadWrite(Register, Single, ReadWrite): + def may_alias_gpr(self): + return True def decl_tcg(self, f, tag, regno): self.decl_reg_num(f, regno) f.write(code_fmt(f"""\
@@ -557,6 +565,8 @@ def analyze_write(self, f, tag, regno): """)) class ControlDest(Register, Single, Dest): + def may_alias_gpr(self): + return True def decl_reg_num(self, f, regno): f.write(code_fmt(f"""\ const int {self.reg_num} = insn->regno[{regno}] + HEX_REG_SA0;
@@ -593,6 +603,8 @@ def analyze_read(self, f, regno): """)) class ModifierSource(Register, Single, OldSource): + def may_alias_gpr(self): + return True def decl_reg_num(self, f, regno): f.write(code_fmt(f"""\ const int {self.reg_num} = insn->regno[{regno}] + HEX_REG_M0;
Signature · 1 line
2.34.1
Quoted 10 lines · Brian Cain
The idef-parser emitters write the destination in place, so when a packet is short-circuited and
get_result_gpr()returns hex_gpr[] itself, an instruction naming one register as both source and destination reads back a value it already overwrote.
Rd32=cmpy(Rs32,Rt32):<<1:rnd:satwith Rs == Rd is an example.Give a source reg that aliases a destination its own copy of the register value.
Quoted 9 lines
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/genptr.h | 1 + target/hexagon/genptr.c | 11 ++++++ tests/tcg/hexagon/read_write_overlap.c | 47 ++++++++++++++++++++++++++ target/hexagon/gen_tcg_funcs.py | 15 ++++++++ target/hexagon/hex_common.py | 12 +++++++ 5 files changed, 86 insertions(+)