target/hexagon: fix J2_jumptnew/pt predicate check to use LSB
PATCH 1/3 target/hexagon: fix J2_jumptnew/pt predicate check to use LSB
J2_jumptnew and J2_jumptnewpt passed the raw predicate value to gen_cond_jump(), checking if the full 8-bit value was non-zero. Refer to PRM Section 6.1.2 "predicate-consuming instructions examine only the least-significant bit".
This inconsistency caused if (p0.new) jumps and if (p0.new) loads within the same packet to disagree when the predicate had values other than the ones generated by predicate-generating instructions (e.g. 0x80 or 0xAA where bit 0 is clear but the value is non-zero): the jump would be taken while the loads were skipped.
Fix by routing both macros through fGEN_TCG_cond_jumpt(fLSBNEW(PuN)), matching the pattern used by every other predicated jump.
--- target/hexagon/gen_tcg.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/hexagon/gen_tcg.h +2 -2
@@ -951,9 +951,9 @@#define fGEN_TCG_J2_jumpfpt (SHORTCODE ) \ fGEN_TCG_cond_jumpf(fLSBOLD(PuV))#define fGEN_TCG_J2_jumptnew (SHORTCODE ) \ - gen_cond_jump(ctx, TCG_COND_EQ, PuN, riV) + fGEN_TCG_cond_jumpt(fLSBNEW(PuN))#define fGEN_TCG_J2_jumptnewpt (SHORTCODE ) \ - gen_cond_jump(ctx, TCG_COND_EQ, PuN, riV) + fGEN_TCG_cond_jumpt(fLSBNEW(PuN))#define fGEN_TCG_J2_jumpfnewpt (SHORTCODE ) \ fGEN_TCG_cond_jumpf(fLSBNEW(PuN))#define fGEN_TCG_J2_jumpfnew (SHORTCODE ) \
Signature · 1 line
2.34.1
PATCH 2/3 target/hexagon: use TCG_COND_TSTEQ/TSTNE for predicate branches
Replace TCG_COND_EQ/NE comparisons against 0 with TCG_COND_TSTEQ/TSTNE comparisons against 1 for all predicate-conditional branches. This tests bit 0 of the predicate register directly, eliminating redundant andi operations that previously extracted the LSB before the comparison.
For predicate-conditional jumps (jumpt, jumpf, jumptnew, etc.) and jump-register variants (jumprt, jumprf, etc.), pass the raw predicate value directly instead of going through fLSBOLD/fLSBNEW extraction. For callers that produce a 0/1 result via setcond (compare-and-jump, jumprz, etc.), the TSTEQ/TSTNE test on bit 0 is equivalent to the previous EQ/NE test against 0.
--- target/hexagon/gen_tcg.h | 80 +++++++++++++++++++------------------- target/hexagon/genptr.c | 32 ++++++--------- target/hexagon/translate.c | 2 +- 3 files changed, 53 insertions(+), 61 deletions(-)
target/hexagon/gen_tcg.h +40 -40
@@ -696,13 +696,13 @@ gen_callr(ctx, RsV)#define fGEN_TCG_J2_callt (SHORTCODE ) \ - gen_cond_call(ctx, PuV, TCG_COND_EQ, riV) + gen_cond_call(ctx, PuV, TCG_COND_TSTEQ, riV)#define fGEN_TCG_J2_callf (SHORTCODE ) \ - gen_cond_call(ctx, PuV, TCG_COND_NE, riV) + gen_cond_call(ctx, PuV, TCG_COND_TSTNE, riV)#define fGEN_TCG_J2_callrt (SHORTCODE ) \ - gen_cond_callr(ctx, TCG_COND_EQ, PuV, RsV) + gen_cond_callr(ctx, TCG_COND_TSTEQ, PuV, RsV)#define fGEN_TCG_J2_callrf (SHORTCODE ) \ - gen_cond_callr(ctx, TCG_COND_NE, PuV, RsV) + gen_cond_callr(ctx, TCG_COND_TSTNE, PuV, RsV)#define fGEN_TCG_J2_loop0r (SHORTCODE ) \ gen_loop0r(ctx, RsV, riV)
@@ -893,21 +893,21 @@ gen_cmpnd_cmp_n1_jmp_f(ctx, 1, TCG_COND_GT, RsV, riV)#define fGEN_TCG_J4_tstbit0_tp0_jump_nt (SHORTCODE ) \ - gen_cmpnd_tstbit0_jmp(ctx, 0, RsV, TCG_COND_EQ, riV) + gen_cmpnd_tstbit0_jmp(ctx, 0, RsV, TCG_COND_TSTEQ, riV)#define fGEN_TCG_J4_tstbit0_tp0_jump_t (SHORTCODE ) \ - gen_cmpnd_tstbit0_jmp(ctx, 0, RsV, TCG_COND_EQ, riV) + gen_cmpnd_tstbit0_jmp(ctx, 0, RsV, TCG_COND_TSTEQ, riV)#define fGEN_TCG_J4_tstbit0_fp0_jump_nt (SHORTCODE ) \ - gen_cmpnd_tstbit0_jmp(ctx, 0, RsV, TCG_COND_NE, riV) + gen_cmpnd_tstbit0_jmp(ctx, 0, RsV, TCG_COND_TSTNE, riV)#define fGEN_TCG_J4_tstbit0_fp0_jump_t (SHORTCODE ) \ - gen_cmpnd_tstbit0_jmp(ctx, 0, RsV, TCG_COND_NE, riV) + gen_cmpnd_tstbit0_jmp(ctx, 0, RsV, TCG_COND_TSTNE, riV)#define fGEN_TCG_J4_tstbit0_tp1_jump_nt (SHORTCODE ) \ - gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_EQ, riV) + gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_TSTEQ, riV)#define fGEN_TCG_J4_tstbit0_tp1_jump_t (SHORTCODE ) \ - gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_EQ, riV) + gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_TSTEQ, riV)#define fGEN_TCG_J4_tstbit0_fp1_jump_nt (SHORTCODE ) \ - gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_NE, riV) + gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_TSTNE, riV)#define fGEN_TCG_J4_tstbit0_fp1_jump_t (SHORTCODE ) \ - gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_NE, riV) + gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_TSTNE, riV)/* p0 = cmp.eq(r0, #7) */ #define fGEN_TCG_SA1_cmpeqi (SHORTCODE ) \
@@ -933,31 +933,31 @@do { \TCGv LSB =tcg_temp_new (); \COND ; \ -gen_cond_jump (ctx,TCG_COND_EQ ,LSB , riV); \ +gen_cond_jump (ctx,TCG_COND_TSTEQ ,LSB , riV); \ } while (0)#define fGEN_TCG_cond_jumpf (COND ) \ do { \ TCGv LSB = tcg_temp_new(); \ COND; \ - gen_cond_jump(ctx, TCG_COND_NE, LSB, riV); \ + gen_cond_jump(ctx, TCG_COND_TSTNE, LSB, riV); \ } while (0)#define fGEN_TCG_J2_jumpt (SHORTCODE ) \ - fGEN_TCG_cond_jumpt(fLSBOLD(PuV)) + gen_cond_jump(ctx, TCG_COND_TSTEQ, PuV, riV)#define fGEN_TCG_J2_jumptpt (SHORTCODE ) \ - fGEN_TCG_cond_jumpt(fLSBOLD(PuV)) + gen_cond_jump(ctx, TCG_COND_TSTEQ, PuV, riV)#define fGEN_TCG_J2_jumpf (SHORTCODE ) \ - fGEN_TCG_cond_jumpf(fLSBOLD(PuV)) + gen_cond_jump(ctx, TCG_COND_TSTNE, PuV, riV)#define fGEN_TCG_J2_jumpfpt (SHORTCODE ) \ - fGEN_TCG_cond_jumpf(fLSBOLD(PuV)) + gen_cond_jump(ctx, TCG_COND_TSTNE, PuV, riV)#define fGEN_TCG_J2_jumptnew (SHORTCODE ) \ - fGEN_TCG_cond_jumpt(fLSBNEW(PuN)) + gen_cond_jump(ctx, TCG_COND_TSTEQ, PuN, riV)#define fGEN_TCG_J2_jumptnewpt (SHORTCODE ) \ - fGEN_TCG_cond_jumpt(fLSBNEW(PuN)) + gen_cond_jump(ctx, TCG_COND_TSTEQ, PuN, riV)#define fGEN_TCG_J2_jumpfnewpt (SHORTCODE ) \ - fGEN_TCG_cond_jumpf(fLSBNEW(PuN)) + gen_cond_jump(ctx, TCG_COND_TSTNE, PuN, riV)#define fGEN_TCG_J2_jumpfnew (SHORTCODE ) \ - fGEN_TCG_cond_jumpf(fLSBNEW(PuN)) + gen_cond_jump(ctx, TCG_COND_TSTNE, PuN, riV)#define fGEN_TCG_J2_jumprz (SHORTCODE ) \ fGEN_TCG_cond_jumpt(tcg_gen_setcondi_tl(TCG_COND_NE, LSB, RsV, 0))#define fGEN_TCG_J2_jumprzpt (SHORTCODE ) \
@@ -979,31 +979,31 @@do { \TCGv LSB =tcg_temp_new (); \COND ; \ -gen_cond_jumpr (ctx, RsV,TCG_COND_EQ ,LSB ); \ +gen_cond_jumpr (ctx, RsV,TCG_COND_TSTEQ ,LSB ); \ } while (0)#define fGEN_TCG_cond_jumprf (COND ) \ do { \ TCGv LSB = tcg_temp_new(); \ COND; \ - gen_cond_jumpr(ctx, RsV, TCG_COND_NE, LSB); \ + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTNE, LSB); \ } while (0)#define fGEN_TCG_J2_jumprt (SHORTCODE ) \ - fGEN_TCG_cond_jumprt(fLSBOLD(PuV)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTEQ, PuV)#define fGEN_TCG_J2_jumprtpt (SHORTCODE ) \ - fGEN_TCG_cond_jumprt(fLSBOLD(PuV)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTEQ, PuV)#define fGEN_TCG_J2_jumprf (SHORTCODE ) \ - fGEN_TCG_cond_jumprf(fLSBOLD(PuV)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTNE, PuV)#define fGEN_TCG_J2_jumprfpt (SHORTCODE ) \ - fGEN_TCG_cond_jumprf(fLSBOLD(PuV)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTNE, PuV)#define fGEN_TCG_J2_jumprtnew (SHORTCODE ) \ - fGEN_TCG_cond_jumprt(fLSBNEW(PuN)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTEQ, PuN)#define fGEN_TCG_J2_jumprtnewpt (SHORTCODE ) \ - fGEN_TCG_cond_jumprt(fLSBNEW(PuN)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTEQ, PuN)#define fGEN_TCG_J2_jumprfnew (SHORTCODE ) \ - fGEN_TCG_cond_jumprf(fLSBNEW(PuN)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTNE, PuN)#define fGEN_TCG_J2_jumprfnewpt (SHORTCODE ) \ - fGEN_TCG_cond_jumprf(fLSBNEW(PuN)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTNE, PuN)/* * New value compare & jump instructions
@@ -1101,13 +1101,13 @@ gen_cmpi_jumpnv(ctx, TCG_COND_LE, NsN, -1, riV)#define fGEN_TCG_J4_tstbit0_t_jumpnv_t (SHORTCODE ) \ - gen_testbit0_jumpnv(ctx, NsN, TCG_COND_EQ, riV) + gen_testbit0_jumpnv(ctx, NsN, TCG_COND_TSTEQ, riV)#define fGEN_TCG_J4_tstbit0_t_jumpnv_nt (SHORTCODE ) \ - gen_testbit0_jumpnv(ctx, NsN, TCG_COND_EQ, riV) + gen_testbit0_jumpnv(ctx, NsN, TCG_COND_TSTEQ, riV)#define fGEN_TCG_J4_tstbit0_f_jumpnv_t (SHORTCODE ) \ - gen_testbit0_jumpnv(ctx, NsN, TCG_COND_NE, riV) + gen_testbit0_jumpnv(ctx, NsN, TCG_COND_TSTNE, riV)#define fGEN_TCG_J4_tstbit0_f_jumpnv_nt (SHORTCODE ) \ - gen_testbit0_jumpnv(ctx, NsN, TCG_COND_NE, riV) + gen_testbit0_jumpnv(ctx, NsN, TCG_COND_TSTNE, riV)/* r0 = r1 ; jump address */ #define fGEN_TCG_J4_jumpsetr (SHORTCODE ) \
@@ -1150,14 +1150,14 @@ gen_jumpr(ctx, hex_gpr[HEX_REG_LR])#define fGEN_TCG_SL2_jumpr31_t (SHORTCODE ) \ - gen_cond_jumpr31(ctx, TCG_COND_EQ, hex_pred[0]) + gen_cond_jumpr31(ctx, TCG_COND_TSTEQ, hex_pred[0])#define fGEN_TCG_SL2_jumpr31_f (SHORTCODE ) \ - gen_cond_jumpr31(ctx, TCG_COND_NE, hex_pred[0]) + gen_cond_jumpr31(ctx, TCG_COND_TSTNE, hex_pred[0])#define fGEN_TCG_SL2_jumpr31_tnew (SHORTCODE ) \ - gen_cond_jumpr31(ctx, TCG_COND_EQ, ctx->new_pred_value[0]) + gen_cond_jumpr31(ctx, TCG_COND_TSTEQ, ctx->new_pred_value[0])#define fGEN_TCG_SL2_jumpr31_fnew (SHORTCODE ) \ - gen_cond_jumpr31(ctx, TCG_COND_NE, ctx->new_pred_value[0]) + gen_cond_jumpr31(ctx, TCG_COND_TSTNE, ctx->new_pred_value[0])/* Count trailing zeros/ones */ #define fGEN_TCG_S2_ct0 (SHORTCODE ) \
target/hexagon/genptr.c +12 -20
@@ -455,7 +455,7 @@ static void gen_write_new_pc_addr(DisasContext *ctx, TCGv addr,TCGLabel *pred_false =NULL ;if (cond !=TCG_COND_ALWAYS ) { pred_false =gen_new_label (); -tcg_gen_brcondi_tl (cond, pred,0 , pred_false); +tcg_gen_brcondi_tl (cond, pred,1 , pred_false); }if (ctx->pkt->pkt_has_multi_cof) {
@@ -579,9 +579,7 @@ static void gen_cond_jumpr(DisasContext *ctx, TCGv dst_pc,static void gen_cond_jumpr31 (DisasContext *ctx,TCGCond cond,TCGv pred) { -TCGv LSB =tcg_temp_new (); -tcg_gen_andi_tl (LSB , pred,1 ); -gen_cond_jumpr (ctx, hex_gpr[HEX_REG_LR ], cond,LSB ); +gen_cond_jumpr (ctx, hex_gpr[HEX_REG_LR ], cond, pred); } static void gen_cond_jump(DisasContext *ctx, TCGCond cond, TCGv pred,
@@ -609,14 +607,14 @@ static void gen_cmpnd_cmp_jmp_t(DisasContext *ctx, int pnum, TCGCond cond, TCGv arg1, TCGv arg2, int pc_off) { -gen_cmpnd_cmp_jmp (ctx ,pnum ,cond ,arg1 ,arg2 ,TCG_COND_EQ ,pc_off ); +gen_cmpnd_cmp_jmp (ctx ,pnum ,cond ,arg1 ,arg2 ,TCG_COND_TSTEQ ,pc_off ); }static void gen_cmpnd_cmp_jmp_f (DisasContext *ctx,int pnum,TCGCond cond,TCGv arg1,TCGv arg2,int pc_off) { -gen_cmpnd_cmp_jmp (ctx, pnum, cond, arg1, arg2,TCG_COND_NE , pc_off); +gen_cmpnd_cmp_jmp (ctx, pnum, cond, arg1, arg2,TCG_COND_TSTNE , pc_off); } static void gen_cmpnd_cmpi_jmp_t(DisasContext *ctx,
@@ -624,7 +622,7 @@ static void gen_cmpnd_cmpi_jmp_t(DisasContext *ctx, int pc_off) {TCGv tmp =tcg_constant_tl (arg2); -gen_cmpnd_cmp_jmp (ctx, pnum, cond, arg1, tmp,TCG_COND_EQ , pc_off); +gen_cmpnd_cmp_jmp (ctx, pnum, cond, arg1, tmp,TCG_COND_TSTEQ , pc_off); } static void gen_cmpnd_cmpi_jmp_f(DisasContext *ctx,
@@ -632,7 +630,7 @@ static void gen_cmpnd_cmpi_jmp_f(DisasContext *ctx, int pc_off) {TCGv tmp =tcg_constant_tl (arg2); -gen_cmpnd_cmp_jmp (ctx, pnum, cond, arg1, tmp,TCG_COND_NE , pc_off); +gen_cmpnd_cmp_jmp (ctx, pnum, cond, arg1, tmp,TCG_COND_TSTNE , pc_off); } static void gen_cmpnd_cmp_n1_jmp_t(DisasContext *ctx, int pnum, TCGCond cond,
@@ -665,9 +663,7 @@ static void gen_cmpnd_tstbit0_jmp(DisasContext *ctx,static void gen_testbit0_jumpnv (DisasContext *ctx,TCGv arg,TCGCond cond,int pc_off) { -TCGv pred =tcg_temp_new (); -tcg_gen_andi_tl (pred, arg,1 ); -gen_cond_jump (ctx, cond, pred, pc_off); +gen_cond_jump (ctx, cond, arg, pc_off); }static void gen_jump (DisasContext *ctx,int pc_off)
@@ -698,11 +694,9 @@ static void gen_cond_call(DisasContext *ctx, TCGv pred, TCGCond cond, int pc_off) {TCGv lr =get_result_gpr (ctx,HEX_REG_LR ); -TCGv lsb =tcg_temp_new ();TCGLabel *skip =gen_new_label (); -tcg_gen_andi_tl (lsb, pred,1 ); -gen_write_new_pc_pcrel (ctx, pc_off, cond, lsb); -tcg_gen_brcondi_tl (cond, lsb,0 , skip); +gen_write_new_pc_pcrel (ctx, pc_off, cond, pred); +tcg_gen_brcondi_tl (cond, pred,1 , skip);tcg_gen_movi_tl (lr, ctx->next_PC);gen_set_label (skip); }
@@ -710,10 +704,8 @@ static void gen_cond_call(DisasContext *ctx, TCGv pred,static void gen_cond_callr (DisasContext *ctx,TCGCond cond,TCGv pred,TCGv new_pc) { -TCGv lsb =tcg_temp_new ();TCGLabel *skip =gen_new_label (); -tcg_gen_andi_tl (lsb, pred,1 ); -tcg_gen_brcondi_tl (cond, lsb,0 , skip); +tcg_gen_brcondi_tl (cond, pred,1 , skip);gen_callr (ctx, new_pc);gen_set_label (skip); }
@@ -955,7 +947,7 @@ static void gen_cmp_jumpnv(DisasContext *ctx, {TCGv pred =tcg_temp_new ();tcg_gen_setcond_tl (cond, pred, val, src); -gen_cond_jump (ctx,TCG_COND_EQ , pred, pc_off); +gen_cond_jump (ctx,TCG_COND_TSTEQ , pred, pc_off); } static void gen_cmpi_jumpnv(DisasContext *ctx,
@@ -963,7 +955,7 @@ static void gen_cmpi_jumpnv(DisasContext *ctx, {TCGv pred =tcg_temp_new ();tcg_gen_setcondi_tl (cond, pred, val, src); -gen_cond_jump (ctx,TCG_COND_EQ , pred, pc_off); +gen_cond_jump (ctx,TCG_COND_TSTEQ , pred, pc_off); }/* Shift left with saturation */
target/hexagon/translate.c +1 -1
@@ -163,7 +163,7 @@ static void gen_end_tb(DisasContext *ctx)if (ctx->branch_cond !=TCG_COND_NEVER ) {if (ctx->branch_cond !=TCG_COND_ALWAYS ) {TCGLabel *skip =gen_new_label (); -tcg_gen_brcondi_tl (ctx->branch_cond, ctx->branch_taken,0 , skip); +tcg_gen_brcondi_tl (ctx->branch_cond, ctx->branch_taken,1 , skip);gen_goto_tb (ctx,0 , ctx->branch_dest, true);gen_set_label (skip);gen_goto_tb (ctx,1 , ctx->next_PC, false);
Signature · 1 line
2.34.1
Re: [PATCH 2/3] target/hexagon: use TCG_COND_TSTEQ/TSTNE for predicate branches
Quoted 55 lines · Brian Cain
Replace TCG_COND_EQ/NE comparisons against 0 with TCG_COND_TSTEQ/TSTNE comparisons against 1 for all predicate-conditional branches. This tests bit 0 of the predicate register directly, eliminating redundant andi operations that previously extracted the LSB before the comparison.
For predicate-conditional jumps (jumpt, jumpf, jumptnew, etc.) and jump-register variants (jumprt, jumprf, etc.), pass the raw predicate value directly instead of going through fLSBOLD/fLSBNEW extraction. For callers that produce a 0/1 result via setcond (compare-and-jump, jumprz, etc.), the TSTEQ/TSTNE test on bit 0 is equivalent to the previous EQ/NE test against 0.
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/gen_tcg.h | 80 +++++++++++++++++++------------------- target/hexagon/genptr.c | 32 ++++++--------- target/hexagon/translate.c | 2 +- 3 files changed, 53 insertions(+), 61 deletions(-)target/hexagon/gen_tcg.h +7
-7@@ -933,31 +933,31 @@do { \TCGv LSB =tcg_temp_new (); \COND ; \ -gen_cond_jump (ctx,TCG_COND_EQ ,LSB , riV); \ +gen_cond_jump (ctx,TCG_COND_TSTEQ ,LSB , riV); \ } while (0)#define fGEN_TCG_cond_jumpf (COND ) \ do { \ TCGv LSB = tcg_temp_new(); \ COND; \ - gen_cond_jump(ctx, TCG_COND_NE, LSB, riV); \ + gen_cond_jump(ctx, TCG_COND_TSTNE, LSB, riV); \ } while (0)#define fGEN_TCG_J2_jumpt (SHORTCODE ) \ - fGEN_TCG_cond_jumpt(fLSBOLD(PuV)) + gen_cond_jump(ctx, TCG_COND_TSTEQ, PuV, riV)#define fGEN_TCG_J2_jumptpt (SHORTCODE ) \ - fGEN_TCG_cond_jumpt(fLSBOLD(PuV)) + gen_cond_jump(ctx, TCG_COND_TSTEQ, PuV, riV)#define fGEN_TCG_J2_jumpf (SHORTCODE ) \ - fGEN_TCG_cond_jumpf(fLSBOLD(PuV)) + gen_cond_jump(ctx, TCG_COND_TSTNE, PuV, riV)#define fGEN_TCG_J2_jumpfpt (SHORTCODE ) \ - fGEN_TCG_cond_jumpf(fLSBOLD(PuV)) + gen_cond_jump(ctx, TCG_COND_TSTNE, PuV, riV)#define fGEN_TCG_J2_jumptnew (SHORTCODE ) \ - fGEN_TCG_cond_jumpt(fLSBNEW(PuN)) + gen_cond_jump(ctx, TCG_COND_TSTEQ, PuN, riV)#define fGEN_TCG_J2_jumptnewpt (SHORTCODE ) \
target/hexagon/gen_tcg.h line 962
Quoted 10 lines
target/hexagon/gen_tcg.h +3
-3- fGEN_TCG_cond_jumpt(fLSBNEW(PuN)) + gen_cond_jump(ctx, TCG_COND_TSTEQ, PuN, riV)#define fGEN_TCG_J2_jumpfnewpt (SHORTCODE ) \ - fGEN_TCG_cond_jumpf(fLSBNEW(PuN)) + gen_cond_jump(ctx, TCG_COND_TSTNE, PuN, riV)#define fGEN_TCG_J2_jumpfnew (SHORTCODE ) \ - fGEN_TCG_cond_jumpf(fLSBNEW(PuN)) + gen_cond_jump(ctx, TCG_COND_TSTNE, PuN, riV)
There are no more uses of fGET_TCG_cond_jumpf, so that macro can be removed.
There are some additional uses of fGEN_TCG_cond_jumpt just below these changes (e.g., fGEN_TCG_J2_jumprz). So that macro needs to stay.
Quoted 30 lines
target/hexagon/gen_tcg.h +7
-7@@ -979,31 +979,31 @@do { \TCGv LSB =tcg_temp_new (); \COND ; \ -gen_cond_jumpr (ctx, RsV,TCG_COND_EQ ,LSB ); \ +gen_cond_jumpr (ctx, RsV,TCG_COND_TSTEQ ,LSB ); \ } while (0)#define fGEN_TCG_cond_jumprf (COND ) \ do { \ TCGv LSB = tcg_temp_new(); \ COND; \ - gen_cond_jumpr(ctx, RsV, TCG_COND_NE, LSB); \ + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTNE, LSB); \ } while (0)#define fGEN_TCG_J2_jumprt (SHORTCODE ) \ - fGEN_TCG_cond_jumprt(fLSBOLD(PuV)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTEQ, PuV)#define fGEN_TCG_J2_jumprtpt (SHORTCODE ) \ - fGEN_TCG_cond_jumprt(fLSBOLD(PuV)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTEQ, PuV)#define fGEN_TCG_J2_jumprf (SHORTCODE ) \ - fGEN_TCG_cond_jumprf(fLSBOLD(PuV)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTNE, PuV)#define fGEN_TCG_J2_jumprfpt (SHORTCODE ) \ - fGEN_TCG_cond_jumprf(fLSBOLD(PuV)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTNE, PuV)#define fGEN_TCG_J2_jumprtnew (SHORTCODE ) \ - fGEN_TCG_cond_jumprt(fLSBNEW(PuN)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTEQ, PuN)
target/hexagon/gen_tcg.h line 1007
Quoted 10 lines
target/hexagon/gen_tcg.h +3
-3#define fGEN_TCG_J2_jumprtnewpt (SHORTCODE ) \ - fGEN_TCG_cond_jumprt(fLSBNEW(PuN)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTEQ, PuN)#define fGEN_TCG_J2_jumprfnew (SHORTCODE ) \ - fGEN_TCG_cond_jumprf(fLSBNEW(PuN)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTNE, PuN)#define fGEN_TCG_J2_jumprfnewpt (SHORTCODE ) \ - fGEN_TCG_cond_jumprf(fLSBNEW(PuN)) + gen_cond_jumpr(ctx, RsV, TCG_COND_TSTNE, PuN)
There are no more uses of fGEN_TCG_cond_jumpr[tf], so those macros can be removed.
Otherwise
PATCH 3/3 tests/tcg/hexagon: add test for predicated .new branch LSB evaluation
In reply to Brian CainTest for predicated .new branches with non-standard predicate values (non-all-0, non-all-1). Hexagon predicates are 8 bits wide but conditional branches evaluate only the LSB.
--- tests/tcg/hexagon/Makefile.target | 3 + tests/tcg/hexagon/test_pnew_jump_loads.c | 339 +++++++++++++++++++++++ 2 files changed, 342 insertions(+) create mode 100644 tests/tcg/hexagon/test_pnew_jump_loads.c
tests/tcg/hexagon/Makefile.target +3 -0
@@ -81,6 +81,8 @@ HEX_TESTS += test_vminh HEX_TESTS += test_vpmpyh HEX_TESTS += test_vspliceb +HEX_TESTS += test_pnew_jump_loads + HEX_TESTS += v68_scalar HEX_TESTS += v68_hvx HEX_TESTS += v69_hvx
@@ -104,6 +106,7 @@ overflow: overflow.c hex_test.h preg_alias: preg_alias.c hex_test.h read_write_overlap: read_write_overlap.c hex_test.h reg_mut: reg_mut.c hex_test.h +test_pnew_jump_loads: test_pnew_jump_loads.c hex_test.h unaligned_pc: unaligned_pc.c # This test has to be compiled for the -mv67t target
tests/tcg/hexagon/test_pnew_jump_loads.c new file +339 -0
339 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 3/3] tests/tcg/hexagon: add test for predicated .new branch LSB evaluation
Quoted 83 lines · Brian Cain
Test for predicated .new branches with non-standard predicate values (non-all-0, non-all-1). Hexagon predicates are 8 bits wide but conditional branches evaluate only the LSB.
Signed-off-by Brian Cain <[email protected]>--- tests/tcg/hexagon/Makefile.target | 3 + tests/tcg/hexagon/test_pnew_jump_loads.c | 339 +++++++++++++++++++++++ 2 files changed, 342 insertions(+) create mode 100644 tests/tcg/hexagon/test_pnew_jump_loads.ctests/tcg/hexagon/Makefile.target +3
-0@@ -81,6 +81,8 @@ HEX_TESTS += test_vminh HEX_TESTS += test_vpmpyh HEX_TESTS += test_vspliceb +HEX_TESTS += test_pnew_jump_loads + HEX_TESTS += v68_scalar HEX_TESTS += v68_hvx HEX_TESTS += v69_hvx@@ -104,6 +106,7 @@ overflow: overflow.c hex_test.h preg_alias: preg_alias.c hex_test.h read_write_overlap: read_write_overlap.c hex_test.h reg_mut: reg_mut.c hex_test.h +test_pnew_jump_loads: test_pnew_jump_loads.c hex_test.h unaligned_pc: unaligned_pc.c # This test has to be compiled for the -mv67t targettests/tcg/hexagon/test_pnew_jump_loads.c new file +5
-0@@ -0,0 +1,339 @@ +/* +* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +* SPDX-License-Identifier: GPL-2.0-or-later +* +* Exhaustive test for predicated .new branches with non-standard predicate
+ * values (non-all-0, non-all-1).
+ *
+ * Hexagon predicates are 8 bits wide but conditional branches evaluate only
+ * bit 0 (the LSB). A predicate value like0xFEis non-zero yet has bit 0
+ * clear, so it must evaluate as "false".
+ *
+ * This test covers the distinct TCG code paths for predicated .new ops:
+ *+ * 1. gen_cond_jump - J2_jumptnewpt / J2_jumpfnewpt (p0..p3) + * 2. gen_cond_jumpr - J2_jumprtnewpt / J2_jumprfnewpt + * 3. gen_cond_jumpr31 - SL2_jumpr31_tnew / SL2_jumpr31_fnew (duplex) + * 4. gen_testbit0_jumpnv - J4_tstbit0_t/f_jumpnv_t + * 5. Conditional .new loads and stores+ */
tests/tcg/hexagon/test_pnew_jump_loads.c new file +11
-0+ +#include <stdio.h> +#include <stdint.h> + +int err; + +#include "hex_test.h" + +/* +* Non-standard predicate: non-zero (0xFE) but bit 0 clear => false. +* This distinguishes correct LSB evaluation from incorrect non-zero checks.
+ */tests/tcg/hexagon/test_pnew_jump_loads.c new file +8
-0+#define PRED_VAL 0xFEu +#define SENTINEL 0xDEADBEEFu +#define LOAD_VAL 0xAAAABBBBu + +/* gen_cond_jump (J2_jumptnewpt) */ + +/* +* Macro to test jumptnew across predicate registers p0..p3.
tests/tcg/hexagon/test_pnew_jump_loads.c line 49
Quoted 10 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+* { Pn = and(Pn, Pn); if (Pn.new) jump:t TARGET } +* +* Pn.new = PRED_VAL & PRED_VAL = 0xFE => bit0=0 => not taken. +* Different predicate registers produce different instruction encodings. +*/ +#define TEST_JUMPTNEW (PREG ) \ +static void test_jumptnew_##PREG(void) \ +{ \ + uint32_t jumped; \ + asm volatile( \
Don't need volatile here.
tests/tcg/hexagon/test_pnew_jump_loads.c line 58
Quoted 10 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +9
-0+#PREG " = %[pred]\n" \ + "{ " #PREG " = and(" #PREG ", " #PREG ")\n" \ + " if (" #PREG ".new) jump:t 1f }\n" \ + "%[jumped] = #0\n" \ + "jump 2f\n" \ + "1:\n" \ + "%[jumped] = #1\n" \ + "2:\n" \ + : [jumped] "=&r"(jumped) \
You don't need the & here. Jumped is written after all the inputs are read.
Quoted 8 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +7
-0+ : [pred] "r"(PRED_VAL) \ + : #PREG \ + ); \ + check32(jumped, 0); \ +} + +TEST_JUMPTNEW (p0)
tests/tcg/hexagon/test_pnew_jump_loads.c line 75
Quoted 10 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+TEST_JUMPTNEW (p1) +TEST_JUMPTNEW (p2 ) +TEST_JUMPTNEW (p3) + +/* jumpfnew: bit0=0 => condition "false" => negated => jump IS taken */ +static voidtest_jumpfnew_p0 (void) +{ +uint32_t jumped; + + asm volatile(
Don't need volatile
tests/tcg/hexagon/test_pnew_jump_loads.c line 84
Quoted 10 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +9
-0+"p0 = %[pred]\n" +"{ p0 = and(p0, p0)\n" +" if (!p0.new) jump:t 1f }\n" +"%[jumped] = #0\n" +"jump 2f\n" +"1:\n" +"%[jumped] = #1\n" +"2:\n" + : [jumped] "=&r"(jumped)
Don't need &.
Quoted 4 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +3
-0+ : [pred] "r"(PRED_VAL) + : "p0" + );
tests/tcg/hexagon/test_pnew_jump_loads.c line 97
Quoted 10 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+check32 (jumped,1 ); +} + +/* gen_cond_jumpr (J2_jumprtnewpt) */ + +static void test_jumprtnew_p0 (void ) +{ +uint32_t jumped; + + asm volatile(
Don't need volatile
tests/tcg/hexagon/test_pnew_jump_loads.c line 107
Quoted 11 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+"p0 = %[pred]\n" +"r0 = ##1f\n" +"{ p0 = and(p0, p0)\n" +" if (p0.new) jumpr:t r0 }\n" +"%[jumped] = #0\n" +"jump 2f\n" +"1:\n" +"%[jumped] = #1\n" +"2:\n" + : [jumped] "=&r"(jumped)
Don't need &
tests/tcg/hexagon/test_pnew_jump_loads.c line 118
Quoted 12 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +11
-0+ : [pred] "r"(PRED_VAL) + : "p0", "r0" + ); +check32 (jumped,0 ); +} + +static void test_jumprfnew_p0 (void ) +{ +uint32_t jumped; + + asm volatile(
Don't need volatile
tests/tcg/hexagon/test_pnew_jump_loads.c line 128
Quoted 11 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+"p0 = %[pred]\n" +"r0 = ##1f\n" +"{ p0 = and(p0, p0)\n" +" if (!p0.new) jumpr:t r0 }\n" +"%[jumped] = #0\n" +"jump 2f\n" +"1:\n" +"%[jumped] = #1\n" +"2:\n" + : [jumped] "=&r"(jumped)
Don't need &
Quoted 12 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +11
-0+ : [pred] "r"(PRED_VAL) + : "p0", "r0" + ); +check32 (jumped,1 ); +} + +/* gen_cond_jumpr31 (SL2_jumpr31_tnew) */ + +/* +* Duplex sub-instructions: only SA1_cmpeqi and similar can produce .new +* predicates in a duplex packet, and those only yield 0x00/0xFF.
tests/tcg/hexagon/test_pnew_jump_loads.c line 149
Quoted 10 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+* We test with standard values to exercise the duplex decode path. +* +* { p0 = cmp.eq(r0, #0); if (p0.new) jumpr:nt r31 } +* With r0=0: p0.new = 0xFF => bit0=1 => taken. +*/ +static void test_jumpr31_tnew (void ) +{ +uint32_t jumped; + + asm volatile(
Don't need volatile
tests/tcg/hexagon/test_pnew_jump_loads.c line 159
Quoted 11 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+"r0 = #0\n" +"r31 = ##1f\n" +"{ p0 = cmp.eq(r0, #0)\n" +" if (p0.new) jumpr:nt r31 }\n" +"%[jumped] = #0\n" +"jump 2f\n" +"1:\n" +"%[jumped] = #1\n" +"2:\n" + : [jumped] "=&r"(jumped)
Don't need &
tests/tcg/hexagon/test_pnew_jump_loads.c line 171
Quoted 13 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +12
-0+ : + : "r0", "r31", "p0" + ); +check32 (jumped,1 ); +} + +/* p0.new = 0xFF => bit0=1 => !true => not taken */ +static void test_jumpr31_fnew (void ) +{ +uint32_t jumped; + + asm volatile(
Don't need volatile
tests/tcg/hexagon/test_pnew_jump_loads.c line 181
Quoted 11 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+"r0 = #0\n" +"r31 = ##1f\n" +"{ p0 = cmp.eq(r0, #0)\n" +" if (!p0.new) jumpr:nt r31 }\n" +"%[jumped] = #0\n" +"jump 2f\n" +"1:\n" +"%[jumped] = #1\n" +"2:\n" + : [jumped] "=&r"(jumped)
Don't need &
Quoted 8 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +7
-0+ : + : "r0", "r31", "p0" + ); +check32 (jumped,0 ); +} + +/* gen_testbit0_jumpnv (J4_tstbit0) */
tests/tcg/hexagon/test_pnew_jump_loads.c line 198
Quoted 10 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+ +/* +* { r0 = #0xFE; if (tstbit(r0.new, #0)) jump:t TARGET } +* r0.new = 0xFE => bit0=0 => tstbit false => not taken. +*/ +static void test_tstbit0_t_jumpnv (void ) +{ +uint32_t jumped; + + asm volatile(
Don't need volatile
tests/tcg/hexagon/test_pnew_jump_loads.c line 206
Quoted 9 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +8
-0+"{ r0 = #0xFE\n" +" if (tstbit(r0.new, #0)) jump:t 1f }\n" +"%[jumped] = #0\n" +"jump 2f\n" +"1:\n" +"%[jumped] = #1\n" +"2:\n" + : [jumped] "=&r"(jumped)
Don't need &
tests/tcg/hexagon/test_pnew_jump_loads.c line 218
Quoted 13 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +12
-0+ : + : "r0" + ); +check32 (jumped,0 ); +} + +/* bit0=0 => tstbit false => negated => taken */ +static void test_tstbit0_f_jumpnv (void ) +{ +uint32_t jumped; + + asm volatile(
Don't need volatile
tests/tcg/hexagon/test_pnew_jump_loads.c line 226
Quoted 9 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +8
-0+"{ r0 = #0xFE\n" +" if (!tstbit(r0.new, #0)) jump:t 1f }\n" +"%[jumped] = #0\n" +"jump 2f\n" +"1:\n" +"%[jumped] = #1\n" +"2:\n" + : [jumped] "=&r"(jumped)
Don't need &
Quoted 9 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +8
-0+ : + : "r0" + ); +check32 (jumped,1 ); +} + +/* conditional .new loads and stores */ +
tests/tcg/hexagon/test_pnew_jump_loads.c line 244
Quoted 10 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+static uint32_t load_val; +static uint32_t store_dst; + +/* bit0=0 => condition false => load skipped => sentinel remains */ +static void test_cond_load_tnew (void ) +{ +uint32_t result; + + load_val =LOAD_VAL ; + asm volatile(
Don't need volatile
tests/tcg/hexagon/test_pnew_jump_loads.c
Quoted 3 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +2
-0+"p0 = %[pred]\n" +"%[res] = ##0xDEADBEEF\n"
Use SENTINEL instead of 0xDEADBEEF
tests/tcg/hexagon/test_pnew_jump_loads.c line 249
Quoted 4 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +3
-0+"{ p0 = and(p0, p0)\n" +" if (p0.new) %[res] = memw(%[addr]+#0) }\n" + : [res] "=&r"(result)
Note that & *is* needed here.
Quoted 5 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +4
-0+ : [pred] "r"(PRED_VAL), + [addr] "r"(&load_val) + : "p0", "memory" + );
tests/tcg/hexagon/test_pnew_jump_loads.c line 263
Quoted 10 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+check32 (result,SENTINEL ); +} + +/* bit0=0 => condition false => negated => load executed */ +static void test_cond_load_fnew (void ) +{ +uint32_t result; + + load_val =LOAD_VAL ; + asm volatile(
Don't need volatile
tests/tcg/hexagon/test_pnew_jump_loads.c
Quoted 3 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +2
-0+"p0 = %[pred]\n" +"%[res] = ##0xDEADBEEF\n"
SENTINEL
Quoted 6 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +5
-0+"{ p0 = and(p0, p0)\n" +" if (!p0.new) %[res] = memw(%[addr]+#0) }\n" + : [res] "=&r"(result) + : [pred] "r"(PRED_VAL), + [addr] "r"(&load_val)
tests/tcg/hexagon/test_pnew_jump_loads.c line 280
Quoted 10 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+ : "p0", "memory" + ); +check32 (result,LOAD_VAL ); +} + +/* bit0=0 => condition false => store skipped => sentinel remains */ +static void test_cond_store_tnew (void ) +{ + store_dst =SENTINEL ; + asm volatile(
+ "p0 = %[pred]\n"
Quoted 49 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +48
-0+"{ p0 = and(p0, p0)\n" +" if (p0.new) memw(%[addr]+#0) = %[val] }\n" + : + : [pred] "r"(PRED_VAL), + [addr] "r"(&store_dst), + [val] "r"(LOAD_VAL) + : "p0", "memory" + ); +check32 (store_dst,SENTINEL ); +} + +/* bit0=0 => condition false => negated => store executed */ +static void test_cond_store_fnew (void ) +{ + store_dst =SENTINEL ; + asmvolatile ( +"p0 = %[pred]\n" +"{ p0 = and(p0, p0)\n" +" if (!p0.new) memw(%[addr]+#0) = %[val] }\n" + : + : [pred]"r" (PRED_VAL ), + [addr]"r" (&store_dst), + [val]"r" (LOAD_VAL ) + :"p0" ,"memory" + ); +check32 (store_dst,LOAD_VAL ); +} + +int main (void ) +{ +/* gen_cond_jump with all predicate registers */ +test_jumptnew_p0 (); +test_jumptnew_p1 (); +test_jumptnew_p2 (); +test_jumptnew_p3 (); +test_jumpfnew_p0 (); + +/* gen_cond_jumpr */ +test_jumprtnew_p0 (); +test_jumprfnew_p0 (); + +/* gen_cond_jumpr31 (duplex, standard values) */ +test_jumpr31_tnew (); +test_jumpr31_fnew (); + +/* gen_testbit0_jumpnv */ +test_tstbit0_t_jumpnv (); +test_tstbit0_f_jumpnv ();
tests/tcg/hexagon/test_pnew_jump_loads.c line 339
Quoted 10 lines
tests/tcg/hexagon/test_pnew_jump_loads.c new file +10
-0+ +/* conditional .new loads and stores */ +test_cond_load_tnew (); +test_cond_load_fnew (); +test_cond_store_tnew (); +test_cond_store_fnew (); + +puts (err ?"FAIL" :"PASS" ); +return err ?1 :0 ; +}
Otherwise
Quoted 27 lines · Brian Cain
J2_jumptnewandJ2_jumptnewptpassed the raw predicate value togen_cond_jump(), checking if the full 8-bit value was non-zero. Refer to PRM Section 6.1.2 "predicate-consuming instructions examine only the least-significant bit".This inconsistency caused if (p0.new) jumps and if (p0.new) loads within the same packet to disagree when the predicate had values other than the ones generated by predicate-generating instructions (e.g.
0x80or0xAAwhere bit 0 is clear but the value is non-zero): the jump would be taken while the loads were skipped.Fix by routing both macros through fGEN_TCG_cond_jumpt(fLSBNEW(PuN)), matching the pattern used by every other predicated jump.
Discovered-by Alexey Karyakin <[email protected]>Signed-off-by Brian Cain <[email protected]>--- target/hexagon/gen_tcg.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/hexagon/gen_tcg.h +0
-0@@ -951,9 +951,9 @@#define fGEN_TCG_J2_jumpfpt (SHORTCODE ) \
target/hexagon/gen_tcg.h line 959
Quoted 10 lines
target/hexagon/gen_tcg.h +2
-2fGEN_TCG_cond_jumpf(fLSBOLD(PuV))#define fGEN_TCG_J2_jumptnew (SHORTCODE ) \ - gen_cond_jump(ctx, TCG_COND_EQ, PuN, riV) + fGEN_TCG_cond_jumpt(fLSBNEW(PuN))#define fGEN_TCG_J2_jumptnewpt (SHORTCODE ) \ - gen_cond_jump(ctx, TCG_COND_EQ, PuN, riV) + fGEN_TCG_cond_jumpt(fLSBNEW(PuN))#define fGEN_TCG_J2_jumpfnewpt (SHORTCODE ) \ fGEN_TCG_cond_jumpf(fLSBNEW(PuN))#define fGEN_TCG_J2_jumpfnew (SHORTCODE ) \