target: Use TCG generic gen_hswap_i32/i64()
cover target: Use TCG generic gen_hswap_i32/i64()
Some targets open-code gen_hswap();
replace by the generic helper.
Philippe Mathieu-Daudé (6):
target/arm: Use hswap_i32() in VREV/SMLAD opcodes target/cris: Use hswap_i32() in SWAPW opcode target/microblaze: Use hswap_i32() in SWAPH opcode target/sh4: Use hswap_i32() in SWAP.W opcode target/mips: Use hswap_i64() in DSHD opcode target/loongarch: Use hswap_i64() in REVH.D opcode
target/arm/tcg/translate-a32.h | 6 ------ target/arm/tcg/translate-neon.c | 4 ++-- target/arm/tcg/translate.c | 4 ++-- target/cris/translate.c | 14 +------------- target/microblaze/translate.c | 7 +------ target/mips/tcg/translate.c | 14 +------------- target/sh4/translate.c | 2 +- target/cris/translate_v10.c.inc | 2 +- target/loongarch/insn_trans/trans_bit.c.inc | 16 +--------------- 9 files changed, 10 insertions(+), 59 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/6 target/arm: Use hswap_i32() in VREV/SMLAD opcodes
Commit 46be8425ff ("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generic hswap_i32(). Use it instead of open-coding it as gen_swap_half().
--- target/arm/tcg/translate-a32.h | 6 ------ target/arm/tcg/translate-neon.c | 4 ++-- target/arm/tcg/translate.c | 4 ++-- 3 files changed, 4 insertions(+), 10 deletions(-)
target/arm/tcg/translate-a32.h +0 -6
@@ -158,10 +158,4 @@ DO_GEN_ST(32, MO_UL)/* Set NZCV flags from the high 4 bits of var. */ #define gen_set_nzcv (var) gen_set_cpsr(var, CPSR_NZCV) -/* Swap low and high halfwords. */ -static inline void gen_swap_half (TCGv_i32 dest,TCGv_i32 var) -{ -tcg_gen_rotri_i32 (dest, var,16 ); -} -#endif
target/arm/tcg/translate-neon.c +2 -2
@@ -2906,7 +2906,7 @@ static bool trans_VREV64(DisasContext *s, arg_VREV64 *a)tcg_gen_bswap32_i32 (tmp[half], tmp[half]);break ;case 1 : -gen_swap_half (tmp[half], tmp[half]); +tcg_gen_hswap_i32 (tmp[half], tmp[half]);break ;case 2 :break ;
@@ -3516,7 +3516,7 @@ static bool trans_VREV32(DisasContext *s, arg_2misc *a) {static NeonGenOneOpFn *const fn[] = { tcg_gen_bswap32_i32, - gen_swap_half, + tcg_gen_hswap_i32,NULL ,NULL , };
target/arm/tcg/translate.c +2 -2
@@ -7612,7 +7612,7 @@ static bool op_smlad(DisasContext *s, arg_rrrr *a, bool m_swap, bool sub) t1 =load_reg (s, a->rn); t2 =load_reg (s, a->rm);if (m_swap) { -gen_swap_half (t2, t2); +tcg_gen_hswap_i32 (t2, t2); }gen_smul_dual (t1, t2);
@@ -7700,7 +7700,7 @@ static bool op_smlald(DisasContext *s, arg_rrrr *a, bool m_swap, bool sub) t1 =load_reg (s, a->rn); t2 =load_reg (s, a->rm);if (m_swap) { -gen_swap_half (t2, t2); +tcg_gen_hswap_i32 (t2, t2); }gen_smul_dual (t1, t2);
Signature · 1 line
2.41.0
Re: [PATCH 1/6] target/arm: Use hswap_i32() in VREV/SMLAD opcodes
Quoted 10 lines · Philippe Mathieu-Daudé
Commit
46be8425ff("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generichswap_i32(). Use it instead of open-coding it asgen_swap_half().Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/arm/tcg/translate-a32.h | 6 ------ target/arm/tcg/translate-neon.c | 4 ++-- target/arm/tcg/translate.c | 4 ++-- 3 files changed, 4 insertions(+), 10 deletions(-)
r~
PATCH 2/6 target/cris: Use hswap_i32() in SWAPW opcode
In reply to Philippe Mathieu-DaudéCommit 46be8425ff ("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generic hswap_i32(). Use it instead of open-coding it as t_gen_swapw().
--- target/cris/translate.c | 14 +------------- target/cris/translate_v10.c.inc | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-)
target/cris/translate.c +1 -13
@@ -399,18 +399,6 @@ static inline void t_gen_swapb(TCGv d, TCGv s)tcg_gen_or_tl (d, d, t); } -/* Swap the halfwords of the s operand. */ -static inline void t_gen_swapw (TCGv d,TCGv s) -{ -TCGv t; -/* d and s refer the same object. */ - t =tcg_temp_new (); -tcg_gen_mov_tl (t, s); -tcg_gen_shli_tl (d, t,16 ); -tcg_gen_shri_tl (t, t,16 ); -tcg_gen_or_tl (d, d, t); -} -/* * Reverse the bits within each byte. *
@@ -1675,7 +1663,7 @@ static int dec_swap_r(CPUCRISState *env, DisasContext *dc)tcg_gen_not_tl (t0, t0); }if (dc->op2 &4 ) { -t_gen_swapw (t0, t0); +tcg_gen_hswap_i32 (t0, t0); }if (dc->op2 &2 ) {t_gen_swapb (t0, t0);
target/cris/translate_v10.c.inc +1 -1
@@ -506,7 +506,7 @@ static void dec10_reg_swap(DisasContext *dc) if (dc->dst & 8) tcg_gen_not_tl(t0, t0); if (dc->dst & 4) - t_gen_swapw(t0, t0); + tcg_gen_hswap_i32(t0, t0); if (dc->dst & 2) t_gen_swapb(t0, t0); if (dc->dst & 1)
Signature · 1 line
2.41.0
Re: [PATCH 2/6] target/cris: Use hswap_i32() in SWAPW opcode
Quoted 48 lines · Philippe Mathieu-Daudé
Commit
46be8425ff("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generichswap_i32(). Use it instead of open-coding it ast_gen_swapw().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/cris/translate.c | 14 +------------- target/cris/translate_v10.c.inc | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-)target/cris/translate.c +1
-13@@ -399,18 +399,6 @@ static inline void t_gen_swapb(TCGv d, TCGv s)tcg_gen_or_tl (d, d, t); } -/* Swap the halfwords of the s operand. */ -static inline void t_gen_swapw (TCGv d,TCGv s) -{ -TCGv t; -/* d and s refer the same object. */ - t =tcg_temp_new (); -tcg_gen_mov_tl (t, s); -tcg_gen_shli_tl (d, t,16 ); -tcg_gen_shri_tl (t, t,16 ); -tcg_gen_or_tl (d, d, t); -} -/* * Reverse the bits within each byte. * @@ -1675,7 +1663,7 @@ static int dec_swap_r(CPUCRISState *env, DisasContext *dc)tcg_gen_not_tl (t0, t0); }if (dc->op2 &4 ) { -t_gen_swapw (t0, t0); +tcg_gen_hswap_i32 (t0, t0); }if (dc->op2 &2 ) {t_gen_swapb (t0, t0);target/cris/translate_v10.c.inc +0
-0
target/cris/translate_v10.c.inc static void dec10_reg_swap(DisasContext *dc) · line 509
Quoted 5 lines
target/cris/translate_v10.c.inc +1
-1@@ -506,7 +506,7 @@ static void dec10_reg_swap(DisasContext *dc) if (dc->dst & 8) tcg_gen_not_tl(t0, t0); if (dc->dst & 4) - t_gen_swapw(t0, t0); + tcg_gen_hswap_i32(t0, t0);
Both these are operating on TCGv, not TCGv_i32, so I think this should be tcg_gen_hswap_tl(). (Compare the tcg_gen_not_tl() calls.)
target/cris/translate_v10.c.inc static void dec10_reg_swap(DisasContext *dc) · line 512
Quoted 3 lines
target/cris/translate_v10.c.inc +0
-0if (dc->dst & 2) t_gen_swapb(t0, t0); if (dc->dst & 1)
thanks
-- PMM
Re: [PATCH 2/6] target/cris: Use hswap_i32() in SWAPW opcode
Quoted 13 lines · Peter Maydell
Quoted 10 lines · Philippe Mathieu-Daudé
Commit
46be8425ff("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generichswap_i32(). Use it instead of open-coding it ast_gen_swapw().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/cris/translate.c | 14 +------------- target/cris/translate_v10.c.inc | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-)
Quoted 14 lines
target/cris/translate_v10.c.inc static void dec10_reg_swap(DisasContext *dc) · line 509
Quoted 10 lines
target/cris/translate_v10.c.inc +1
-1@@ -506,7 +506,7 @@ static void dec10_reg_swap(DisasContext *dc) if (dc->dst & 8) tcg_gen_not_tl(t0, t0); if (dc->dst & 4) - t_gen_swapw(t0, t0); + tcg_gen_hswap_i32(t0, t0);Both these are operating on TCGv, not
TCGv_i32, so I think this should betcg_gen_hswap_tl(). (Compare thetcg_gen_not_tl()calls.)
You are correct, if someone copies part of this code to a new function compiled for a 64-bit target, this won't build.
We know cris is a 32-bit only target.
When implementing tcg_gen_foo_tl(), should we implement both corresponding tcg_gen_foo_i32/i64() even if one is never used (thus not tested)?
I like completeness, but I'm a bit reluctant to commit unused code (mostly for maintenance burden).
Maybe I can go mid-way and only add tcg_gen_hswap_tl() -> tcg_gen_hswap_i32() here. If tcg_gen_hswap_tl() were used on a 64-bit target then we'd get a build failure. Does that sound reasonable?
Thanks,
Phil.
Re: [PATCH 2/6] target/cris: Use hswap_i32() in SWAPW opcode
Quoted 39 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Peter Maydell
Quoted 10 lines · Philippe Mathieu-Daudé
Commit
46be8425ff("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generichswap_i32(). Use it instead of open-coding it ast_gen_swapw().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/cris/translate.c | 14 +------------- target/cris/translate_v10.c.inc | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-)Quoted 14 lines
target/cris/translate_v10.c.inc static void dec10_reg_swap(DisasContext *dc) · line 509
Quoted 10 lines
target/cris/translate_v10.c.inc +1
-1@@ -506,7 +506,7 @@ static void dec10_reg_swap(DisasContext *dc) if (dc->dst & 8) tcg_gen_not_tl(t0, t0); if (dc->dst & 4) - t_gen_swapw(t0, t0); + tcg_gen_hswap_i32(t0, t0);Both these are operating on TCGv, not
TCGv_i32, so I think this should betcg_gen_hswap_tl(). (Compare thetcg_gen_not_tl()calls.)You are correct, if someone copies part of this code to a new function compiled for a 64-bit target, this won't build.
We know cris is a 32-bit only target.
When implementing
tcg_gen_foo_tl(), should we implement both corresponding tcg_gen_foo_i32/i64() even if one is never used (thus not tested)?
Quoted 7 lines
I like completeness, but I'm a bit reluctant to commit unused code (mostly for maintenance burden).
Maybe I can go mid-way and only add
tcg_gen_hswap_tl()->tcg_gen_hswap_i32()here. Iftcg_gen_hswap_tl()were used on a 64-bit target then we'd get a build failure. Does that sound reasonable?
We already have tcg_gen_hswap_tl (it's a #define like all the _tl symbols), so I'm just asking that you use it rather than the _i32 version. If we were writing the cris target code from scratch these days we'd probably write it to use _i32 throughout, but since it's not written that way I think it's better to continue the pattern rather than deviate from it.
thanks
-- PMM
Re: [PATCH 2/6] target/cris: Use hswap_i32() in SWAPW opcode
Quoted 48 lines · Peter Maydell
Quoted 39 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Peter Maydell
Quoted 10 lines · Philippe Mathieu-Daudé
Commit
46be8425ff("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generichswap_i32(). Use it instead of open-coding it ast_gen_swapw().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/cris/translate.c | 14 +------------- target/cris/translate_v10.c.inc | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-)Quoted 14 lines
target/cris/translate_v10.c.inc static void dec10_reg_swap(DisasContext *dc) · line 509
Quoted 10 lines
target/cris/translate_v10.c.inc +1
-1@@ -506,7 +506,7 @@ static void dec10_reg_swap(DisasContext *dc) if (dc->dst & 8) tcg_gen_not_tl(t0, t0); if (dc->dst & 4) - t_gen_swapw(t0, t0); + tcg_gen_hswap_i32(t0, t0);Both these are operating on TCGv, not
TCGv_i32, so I think this should betcg_gen_hswap_tl(). (Compare thetcg_gen_not_tl()calls.)You are correct, if someone copies part of this code to a new function compiled for a 64-bit target, this won't build.
We know cris is a 32-bit only target.
When implementing
tcg_gen_foo_tl(), should we implement both corresponding tcg_gen_foo_i32/i64() even if one is never used (thus not tested)?Quoted 7 lines
I like completeness, but I'm a bit reluctant to commit unused code (mostly for maintenance burden).
Maybe I can go mid-way and only add
tcg_gen_hswap_tl()->tcg_gen_hswap_i32()here. Iftcg_gen_hswap_tl()were used on a 64-bit target then we'd get a build failure. Does that sound reasonable?
Quoted 7 lines
We already have
tcg_gen_hswap_tl(it's a #define like all the_tlsymbols), so I'm just asking that you use it rather than the_i32version. If we were writing the cris target code from scratch these days we'd probably write it to use_i32throughout, but since it's not written that way I think it's better to continue the pattern rather than deviate from it.
Doh I missed commit 46be8425ff also added tcg_gen_hswap_tl()...
Thanks!
Phil.
PATCH 3/6 target/microblaze: Use hswap_i32() in SWAPH opcode
In reply to Philippe Mathieu-DaudéCommit 46be8425ff ("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generic hswap_i32(). Use it instead of open-coding it as gen_swaph().
--- target/microblaze/translate.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
target/microblaze/translate.c +1 -6
@@ -608,13 +608,8 @@ DO_TYPEA0(sra, false, gen_sra) DO_TYPEA0(src, false, gen_src) DO_TYPEA0(srl, false, gen_srl) -static void gen_swaph (TCGv_i32 out,TCGv_i32 ina) -{ -tcg_gen_rotri_i32 (out, ina,16 ); -} - DO_TYPEA0(swapb, false, tcg_gen_bswap32_i32) -DO_TYPEA0(swaph, false, gen_swaph) +DO_TYPEA0(swaph, false, tcg_gen_hswap_i32)static bool trans_wdic (DisasContext *dc,arg_wdic *a) {
Signature · 1 line
2.41.0
Re: [PATCH 3/6] target/microblaze: Use hswap_i32() in SWAPH opcode
Quoted 8 lines · Philippe Mathieu-Daudé
Commit
46be8425ff("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generichswap_i32(). Use it instead of open-coding it asgen_swaph().Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/microblaze/translate.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
r~
PATCH 4/6 target/sh4: Use hswap_i32() in SWAP.W opcode
In reply to Philippe Mathieu-DaudéCommit 46be8425ff ("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generic hswap_i32(). Use it.
--- target/sh4/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/sh4/translate.c +1 -1
@@ -678,7 +678,7 @@ static void _decode_opc(DisasContext * ctx) }return ;case 0x6009 :/* swap.w Rm,Rn */ -tcg_gen_rotli_i32 (REG (B11_8 ),REG (B7_4 ),16 ); +tcg_gen_hswap_i32 (REG (B11_8 ),REG (B7_4 ));return ;case 0x200d :/* xtrct Rm,Rn */ {
Signature · 1 line
2.41.0
Re: [PATCH 4/6] target/sh4: Use hswap_i32() in SWAP.W opcode
Quoted 7 lines · Philippe Mathieu-Daudé
Commit
46be8425ff("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generichswap_i32(). Use it.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/sh4/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
PATCH 5/6 target/mips: Use hswap_i64() in DSHD opcode
In reply to Philippe Mathieu-DaudéCommit 46be8425ff ("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generic hswap_i32(). Use it instead of open-coding it in gen_bshfl().
--- target/mips/tcg/translate.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
target/mips/tcg/translate.c +1 -13
@@ -4948,19 +4948,7 @@ static void gen_bshfl(DisasContext *ctx, uint32_t op2, int rt, int rd) }break ;case OPC_DSHD : - { -TCGv t1 =tcg_temp_new (); -TCGv t2 =tcg_constant_tl (0x0000FFFF0000FFFFULL ); - -tcg_gen_shri_tl (t1, t0,16 ); -tcg_gen_and_tl (t1, t1, t2); -tcg_gen_and_tl (t0, t0, t2); -tcg_gen_shli_tl (t0, t0,16 ); -tcg_gen_or_tl (t0, t0, t1); -tcg_gen_shri_tl (t1, t0,32 ); -tcg_gen_shli_tl (t0, t0,32 ); -tcg_gen_or_tl (cpu_gpr[rd], t0, t1); - } +tcg_gen_hswap_i64 (cpu_gpr[rd], t0);break ;#endif default :
Signature · 1 line
2.41.0
Re: [PATCH 5/6] target/mips: Use hswap_i64() in DSHD opcode
Quoted 22 lines · Philippe Mathieu-Daudé
Commit
46be8425ff("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generichswap_i32(). Use it instead of open-coding it ingen_bshfl().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/translate.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)target/mips/tcg/translate.c +0
-4@@ -4948,19 +4948,7 @@ static void gen_bshfl(DisasContext *ctx, uint32_t op2, int rt, int rd) }break ;case OPC_DSHD : - { -TCGv t1 =tcg_temp_new (); -TCGv t2 =tcg_constant_tl (0x0000FFFF0000FFFFULL ); -
target/mips/tcg/translate.c static void gen_bshfl(DisasContext *ctx, uint32_t op2, int rt, int rd) · line 4951
Quoted 10 lines
target/mips/tcg/translate.c +1
-9-tcg_gen_shri_tl (t1, t0,16 ); -tcg_gen_and_tl (t1, t1, t2); -tcg_gen_and_tl (t0, t0, t2); -tcg_gen_shli_tl (t0, t0,16 ); -tcg_gen_or_tl (t0, t0, t1); -tcg_gen_shri_tl (t1, t0,32 ); -tcg_gen_shli_tl (t0, t0,32 ); -tcg_gen_or_tl (cpu_gpr[rd], t0, t1); - } +tcg_gen_hswap_i64 (cpu_gpr[rd], t0);
We know that target_long here is 64 bits, but for consistency with the rest of the function maybe tcg_gen_hswap_tl() is better? I'm not sure...
thanks
-- PMM
PATCH 6/6 target/loongarch: Use hswap_i64() in REVH.D opcode
In reply to Philippe Mathieu-DaudéCommit 46be8425ff ("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generic hswap_i32(). Use it instead of open-coding it as gen_revh_d().
--- target/loongarch/insn_trans/trans_bit.c.inc | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
target/loongarch/insn_trans/trans_bit.c.inc +1 -15
@@ -150,20 +150,6 @@ static void gen_revh_2w(TCGv dest, TCGv src1) tcg_gen_or_i64(dest, t1, t0); } -static void gen_revh_d(TCGv dest, TCGv src1) -{ - TCGv t0 = tcg_temp_new(); - TCGv t1 = tcg_temp_new(); - TCGv mask = tcg_constant_tl(0x0000FFFF0000FFFFULL); - - tcg_gen_shri_tl(t1, src1, 16); - tcg_gen_and_tl(t1, t1, mask); - tcg_gen_and_tl(t0, src1, mask); - tcg_gen_shli_tl(t0, t0, 16); - tcg_gen_or_tl(t0, t0, t1); - tcg_gen_rotri_tl(dest, t0, 32); -} - static void gen_maskeqz(TCGv dest, TCGv src1, TCGv src2) { TCGv zero = tcg_constant_tl(0);
@@ -193,7 +179,7 @@ TRANS(revb_4h, gen_rr, EXT_NONE, EXT_NONE, gen_revb_4h) TRANS(revb_2w, gen_rr, EXT_NONE, EXT_NONE, gen_revb_2w) TRANS(revb_d, gen_rr, EXT_NONE, EXT_NONE, tcg_gen_bswap64_i64) TRANS(revh_2w, gen_rr, EXT_NONE, EXT_NONE, gen_revh_2w) -TRANS(revh_d, gen_rr, EXT_NONE, EXT_NONE, gen_revh_d) +TRANS(revh_d, gen_rr, EXT_NONE, EXT_NONE, tcg_gen_hswap_i64) TRANS(bitrev_4b, gen_rr, EXT_ZERO, EXT_SIGN, gen_helper_bitswap) TRANS(bitrev_8b, gen_rr, EXT_NONE, EXT_NONE, gen_helper_bitswap) TRANS(bitrev_w, gen_rr, EXT_NONE, EXT_SIGN, gen_helper_bitrev_w)
Signature · 1 line
2.41.0
Re: [PATCH 6/6] target/loongarch: Use hswap_i64() in REVH.D opcode
Quoted 8 lines · Philippe Mathieu-Daudé
Commit
46be8425ff("tcg: Implement tcg_gen_{h,w}swap_{i32,i64}") introduced the generichswap_i32(). Use it instead of open-coding it asgen_revh_d().Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/loongarch/insn_trans/trans_bit.c.inc | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
r~