target: Use tcg_constant_tl() instead of tcg_gen_movi_tl()
cover target: Use tcg_constant_tl() instead of tcg_gen_movi_tl()
Directly use tcg_constant_tl() for constant integer, this save a call to tcg_gen_movi_tl(), often saving a temp register.
(Only build-tested)
Philippe Mathieu-Daudé (3):
target/mips: Use tcg_constant_tl() instead of tcg_gen_movi_tl() target/tricore: Use tcg_constant_tl() instead of tcg_gen_movi_tl() target/ppc: Use tcg_constant_tl() instead of tcg_gen_movi_tl()
target/mips/tcg/translate.c | 56 ++++------- target/ppc/translate.c | 13 +-- target/tricore/translate.c | 3 +- target/mips/tcg/micromips_translate.c.inc | 12 +-- target/mips/tcg/mips16e_translate.c.inc | 15 +-- target/mips/tcg/nanomips_translate.c.inc | 114 ++++++++-------------- 6 files changed, 74 insertions(+), 139 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/3 target/mips: Use tcg_constant_tl() instead of tcg_gen_movi_tl()
Directly use tcg_constant_tl() for constant integer, this save a call to tcg_gen_movi_tl(), often saving a temp register.
Most of the places found using the following Coccinelle spatch script:
@@
identifier tmp;
constant val;
@@
* TCGv tmp = tcg_temp_new();
... * tcg_gen_movi_tl(tmp, val);
@@
identifier tmp;
int val;
@@
* TCGv tmp = tcg_temp_new();
... * tcg_gen_movi_i64(tmp, val);
---
Based-on: <[email protected]>
--- target/mips/tcg/translate.c | 56 ++++------- target/mips/tcg/micromips_translate.c.inc | 12 +-- target/mips/tcg/mips16e_translate.c.inc | 15 +-- target/mips/tcg/nanomips_translate.c.inc | 114 ++++++++-------------- 4 files changed, 68 insertions(+), 129 deletions(-)
target/mips/tcg/translate.c +19 -37
@@ -2253,8 +2253,7 @@ static void gen_st_cond(DisasContext *ctx, int rt, int base, int offset,/* compare the address against that of the preceding LL */ gen_base_offset_addr (ctx, addr, base, offset);tcg_gen_brcond_tl (TCG_COND_EQ , addr, cpu_lladdr, l1); -tcg_gen_movi_tl (t0,0 ); -gen_store_gpr (t0, rt); +gen_store_gpr (tcg_constant_tl (0 ), rt);tcg_gen_br (done);gen_set_label (l1);
@@ -3060,8 +3059,7 @@ static void gen_r6_muldiv(DisasContext *ctx, int opc, int rd, int rs, int rt)tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );tcg_gen_or_tl (t2, t2, t3); -tcg_gen_movi_tl (t3,0 ); -tcg_gen_movcond_tl (TCG_COND_NE , t1, t2, t3, t2, t1); +tcg_gen_movcond_tl (TCG_COND_NE , t1, t2,tcg_constant_tl (0 ), t2, t1);tcg_gen_div_tl (cpu_gpr[rd], t0, t1);tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]); }
@@ -3077,30 +3075,27 @@ static void gen_r6_muldiv(DisasContext *ctx, int opc, int rd, int rs, int rt)tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );tcg_gen_or_tl (t2, t2, t3); -tcg_gen_movi_tl (t3,0 ); -tcg_gen_movcond_tl (TCG_COND_NE , t1, t2, t3, t2, t1); +tcg_gen_movcond_tl (TCG_COND_NE , t1, t2,tcg_constant_tl (0 ), t2, t1);tcg_gen_rem_tl (cpu_gpr[rd], t0, t1);tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]); }break ;case R6_OPC_DIVU : { -TCGv t2 =tcg_constant_tl (0 ); -TCGv t3 =tcg_constant_tl (1 );tcg_gen_ext32u_tl (t0, t0);tcg_gen_ext32u_tl (t1, t1); -tcg_gen_movcond_tl (TCG_COND_EQ , t1, t1, t2, t3, t1); +tcg_gen_movcond_tl (TCG_COND_EQ , t1, t1, +tcg_constant_tl (0 ),tcg_constant_tl (1 ), t1);tcg_gen_divu_tl (cpu_gpr[rd], t0, t1);tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]); }break ;case R6_OPC_MODU : { -TCGv t2 =tcg_constant_tl (0 ); -TCGv t3 =tcg_constant_tl (1 );tcg_gen_ext32u_tl (t0, t0);tcg_gen_ext32u_tl (t1, t1); -tcg_gen_movcond_tl (TCG_COND_EQ , t1, t1, t2, t3, t1); +tcg_gen_movcond_tl (TCG_COND_EQ , t1, t1, +tcg_constant_tl (0 ),tcg_constant_tl (1 ), t1);tcg_gen_remu_tl (cpu_gpr[rd], t0, t1);tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]); }
@@ -3155,8 +3150,7 @@ static void gen_r6_muldiv(DisasContext *ctx, int opc, int rd, int rs, int rt)tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );tcg_gen_or_tl (t2, t2, t3); -tcg_gen_movi_tl (t3,0 ); -tcg_gen_movcond_tl (TCG_COND_NE , t1, t2, t3, t2, t1); +tcg_gen_movcond_tl (TCG_COND_NE , t1, t2,tcg_constant_tl (0 ), t2, t1);tcg_gen_div_tl (cpu_gpr[rd], t0, t1); }break ;
@@ -3169,24 +3163,21 @@ static void gen_r6_muldiv(DisasContext *ctx, int opc, int rd, int rs, int rt)tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );tcg_gen_or_tl (t2, t2, t3); -tcg_gen_movi_tl (t3,0 ); -tcg_gen_movcond_tl (TCG_COND_NE , t1, t2, t3, t2, t1); +tcg_gen_movcond_tl (TCG_COND_NE , t1, t2,tcg_constant_tl (0 ), t2, t1);tcg_gen_rem_tl (cpu_gpr[rd], t0, t1); }break ;case R6_OPC_DDIVU : { -TCGv t2 =tcg_constant_tl (0 ); -TCGv t3 =tcg_constant_tl (1 ); -tcg_gen_movcond_tl (TCG_COND_EQ , t1, t1, t2, t3, t1); +tcg_gen_movcond_tl (TCG_COND_EQ , t1, t1, +tcg_constant_tl (0 ),tcg_constant_tl (1 ), t1);tcg_gen_divu_i64 (cpu_gpr[rd], t0, t1); }break ;case R6_OPC_DMODU : { -TCGv t2 =tcg_constant_tl (0 ); -TCGv t3 =tcg_constant_tl (1 ); -tcg_gen_movcond_tl (TCG_COND_EQ , t1, t1, t2, t3, t1); +tcg_gen_movcond_tl (TCG_COND_EQ , t1, t1, +tcg_constant_tl (0 ),tcg_constant_tl (1 ), t1);tcg_gen_remu_i64 (cpu_gpr[rd], t0, t1); }break ;
@@ -3239,8 +3230,7 @@ static void gen_div1_tx79(DisasContext *ctx, uint32_t opc, int rs, int rt)tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );tcg_gen_or_tl (t2, t2, t3); -tcg_gen_movi_tl (t3,0 ); -tcg_gen_movcond_tl (TCG_COND_NE , t1, t2, t3, t2, t1); +tcg_gen_movcond_tl (TCG_COND_NE , t1, t2,tcg_constant_tl (0 ), t2, t1);tcg_gen_div_tl (cpu_LO[1 ], t0, t1);tcg_gen_rem_tl (cpu_HI[1 ], t0, t1);tcg_gen_ext32s_tl (cpu_LO[1 ], cpu_LO[1 ]);
@@ -3295,8 +3285,7 @@ static void gen_muldiv(DisasContext *ctx, uint32_t opc,tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );tcg_gen_or_tl (t2, t2, t3); -tcg_gen_movi_tl (t3,0 ); -tcg_gen_movcond_tl (TCG_COND_NE , t1, t2, t3, t2, t1); +tcg_gen_movcond_tl (TCG_COND_NE , t1, t2,tcg_constant_tl (0 ), t2, t1);tcg_gen_div_tl (cpu_LO[acc], t0, t1);tcg_gen_rem_tl (cpu_HI[acc], t0, t1);tcg_gen_ext32s_tl (cpu_LO[acc], cpu_LO[acc]);
@@ -3348,17 +3337,15 @@ static void gen_muldiv(DisasContext *ctx, uint32_t opc,tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );tcg_gen_or_tl (t2, t2, t3); -tcg_gen_movi_tl (t3,0 ); -tcg_gen_movcond_tl (TCG_COND_NE , t1, t2, t3, t2, t1); +tcg_gen_movcond_tl (TCG_COND_NE , t1, t2,tcg_constant_tl (0 ), t2, t1);tcg_gen_div_tl (cpu_LO[acc], t0, t1);tcg_gen_rem_tl (cpu_HI[acc], t0, t1); }break ;case OPC_DDIVU : { -TCGv t2 =tcg_constant_tl (0 ); -TCGv t3 =tcg_constant_tl (1 ); -tcg_gen_movcond_tl (TCG_COND_EQ , t1, t1, t2, t3, t1); +tcg_gen_movcond_tl (TCG_COND_EQ , t1, t1, +tcg_constant_tl (0 ),tcg_constant_tl (1 ), t1);tcg_gen_divu_i64 (cpu_LO[acc], t0, t1);tcg_gen_remu_i64 (cpu_HI[acc], t0, t1); }
@@ -11428,17 +11415,12 @@ static void gen_compute_compact_branch(DisasContext *ctx, uint32_t opc,void gen_addiupc (DisasContext *ctx,int rx,int imm,int is_64_bit,int extended) { -TCGv t0; -if (extended && (ctx->hflags &MIPS_HFLAG_BMASK )) {gen_reserved_instruction (ctx);return ; } - t0 =tcg_temp_new (); - -tcg_gen_movi_tl (t0,pc_relative_pc (ctx)); -tcg_gen_addi_tl (cpu_gpr[rx], t0, imm); +tcg_gen_addi_tl (cpu_gpr[rx],tcg_constant_tl (pc_relative_pc (ctx)), imm);if (!is_64_bit) {tcg_gen_ext32s_tl (cpu_gpr[rx], cpu_gpr[rx]); }
target/mips/tcg/micromips_translate.c.inc +4 -8
@@ -980,8 +980,7 @@ static void gen_ldst_pair(DisasContext *ctx, uint32_t opc, int rd, tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, mo_endian(ctx) | MO_SL | ctx->default_tcg_memop_mask); gen_store_gpr(t1, rd); - tcg_gen_movi_tl(t1, 4); - gen_op_addr_add(ctx, t0, t0, t1); + gen_op_addr_add(ctx, t0, t0, tcg_constant_tl(4)); tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, mo_endian(ctx) | MO_SL | ctx->default_tcg_memop_mask); gen_store_gpr(t1, rd + 1);
@@ -990,8 +989,7 @@ static void gen_ldst_pair(DisasContext *ctx, uint32_t opc, int rd, gen_load_gpr(t1, rd); tcg_gen_qemu_st_tl(t1, t0, ctx->mem_idx, mo_endian(ctx) | MO_UL | ctx->default_tcg_memop_mask); - tcg_gen_movi_tl(t1, 4); - gen_op_addr_add(ctx, t0, t0, t1); + gen_op_addr_add(ctx, t0, t0, tcg_constant_tl(4)); gen_load_gpr(t1, rd + 1); tcg_gen_qemu_st_tl(t1, t0, ctx->mem_idx, mo_endian(ctx) | MO_UL | ctx->default_tcg_memop_mask);
@@ -1005,8 +1003,7 @@ static void gen_ldst_pair(DisasContext *ctx, uint32_t opc, int rd, tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, mo_endian(ctx) | MO_UQ | ctx->default_tcg_memop_mask); gen_store_gpr(t1, rd); - tcg_gen_movi_tl(t1, 8); - gen_op_addr_add(ctx, t0, t0, t1); + gen_op_addr_add(ctx, t0, t0, tcg_constant_tl(8)); tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, mo_endian(ctx) | MO_UQ | ctx->default_tcg_memop_mask); gen_store_gpr(t1, rd + 1);
@@ -1015,8 +1012,7 @@ static void gen_ldst_pair(DisasContext *ctx, uint32_t opc, int rd, gen_load_gpr(t1, rd); tcg_gen_qemu_st_tl(t1, t0, ctx->mem_idx, mo_endian(ctx) | MO_UQ | ctx->default_tcg_memop_mask); - tcg_gen_movi_tl(t1, 8); - gen_op_addr_add(ctx, t0, t0, t1); + gen_op_addr_add(ctx, t0, t0, tcg_constant_tl(8)); gen_load_gpr(t1, rd + 1); tcg_gen_qemu_st_tl(t1, t0, ctx->mem_idx, mo_endian(ctx) | MO_UQ | ctx->default_tcg_memop_mask);
target/mips/tcg/mips16e_translate.c.inc +4 -11
@@ -130,10 +130,8 @@ static int xlat(int r) static void decr_and_store(DisasContext *ctx, unsigned regidx, TCGv t0) { TCGv t1 = tcg_temp_new(); - TCGv t2 = tcg_temp_new(); - tcg_gen_movi_tl(t2, -4); - gen_op_addr_add(ctx, t0, t0, t2); + gen_op_addr_add(ctx, t0, t0, tcg_constant_tl(-4)); gen_load_gpr(t1, regidx); tcg_gen_qemu_st_tl(t1, t0, ctx->mem_idx, mo_endian(ctx) | MO_UL | ctx->default_tcg_memop_mask);
@@ -146,7 +144,6 @@ static void gen_mips16_save(DisasContext *ctx, { TCGv t0 = tcg_temp_new(); TCGv t1 = tcg_temp_new(); - TCGv t2 = tcg_temp_new(); int args, astatic; switch (aregs) {
@@ -286,8 +283,7 @@ static void gen_mips16_save(DisasContext *ctx, } } - tcg_gen_movi_tl(t2, -framesize); - gen_op_addr_add(ctx, cpu_gpr[29], cpu_gpr[29], t2); + gen_op_addr_add(ctx, cpu_gpr[29], cpu_gpr[29], tcg_constant_tl(-framesize)); } static void decr_and_load(DisasContext *ctx, unsigned regidx, TCGv t0)
@@ -307,10 +303,8 @@ static void gen_mips16_restore(DisasContext *ctx, { int astatic; TCGv t0 = tcg_temp_new(); - TCGv t2 = tcg_temp_new(); - tcg_gen_movi_tl(t2, framesize); - gen_op_addr_add(ctx, t0, cpu_gpr[29], t2); + gen_op_addr_add(ctx, t0, cpu_gpr[29], tcg_constant_tl(-framesize)); if (do_ra) { decr_and_load(ctx, 31, t0);
@@ -390,8 +384,7 @@ static void gen_mips16_restore(DisasContext *ctx, } } - tcg_gen_movi_tl(t2, framesize); - gen_op_addr_add(ctx, cpu_gpr[29], cpu_gpr[29], t2); + gen_op_addr_add(ctx, cpu_gpr[29], cpu_gpr[29], tcg_constant_tl(-framesize)); } #if defined(TARGET_MIPS64)
target/mips/tcg/nanomips_translate.c.inc +41 -73
320 lines not on this page · raw message
Signature · 1 line
2.45.2
Re: [PATCH 1/3] target/mips: Use tcg_constant_tl() instead of tcg_gen_movi_tl()
Quoted 9 lines · Philippe Mathieu-Daudé
target/mips/tcg/translate.c +0
-2@@ -11428,17 +11415,12 @@ static void gen_compute_compact_branch(DisasContext *ctx, uint32_t opc,void gen_addiupc (DisasContext *ctx,int rx,int imm,int is_64_bit,int extended) { -TCGv t0; -if (extended && (ctx->hflags &MIPS_HFLAG_BMASK )) {gen_reserved_instruction (ctx);return ;
target/mips/tcg/translate.c static void gen_compute_compact_branch(DisasContext *ctx, uint32_t opc, · line 11426
Quoted 10 lines
target/mips/tcg/translate.c +1
-4} - t0 =tcg_temp_new (); - -tcg_gen_movi_tl (t0,pc_relative_pc (ctx)); -tcg_gen_addi_tl (cpu_gpr[rx], t0, imm); +tcg_gen_addi_tl (cpu_gpr[rx],tcg_constant_tl (pc_relative_pc (ctx)), imm);if (!is_64_bit) {tcg_gen_ext32s_tl (cpu_gpr[rx], cpu_gpr[rx]); }
Oh dear. All of this can be computed during translate.
target_ulong val = pc_relative_pc(ctx) + imm;
if (!is_64_bit) {
val = (int32_t)val;
}
tcg_gen_movi_tl(cpu_gpr[rx], val);target/mips/tcg/micromips_translate.c.inc static void gen_ldst_pair(DisasContext *ctx, uint32_t opc, int rd, · line 983
Quoted 11 lines
target/mips/tcg/micromips_translate.c.inc +1
-2@@ -980,8 +980,7 @@ static void gen_ldst_pair(DisasContext *ctx, uint32_t opc, int rd, tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, mo_endian(ctx) | MO_SL | ctx->default_tcg_memop_mask); gen_store_gpr(t1, rd); - tcg_gen_movi_tl(t1, 4); - gen_op_addr_add(ctx, t0, t0, t1); + gen_op_addr_add(ctx, t0, t0, tcg_constant_tl(4));
It might be useful to add a gen_op_addr_addi() helper.
Anyway, it's all an incremental improvement so,
r~
PATCH 2/3 target/tricore: Use tcg_constant_tl() instead of tcg_gen_movi_tl()
In reply to Philippe Mathieu-DaudéDirectly use tcg_constant_tl() for constant integer, this save a call to tcg_gen_movi_tl().
--- target/tricore/translate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target/tricore/translate.c +1 -2
@@ -2732,8 +2732,7 @@ static inline void gen_insert(TCGv ret, TCGv r1, TCGv r2, TCGv width, TCGv pos)TCGv temp =tcg_temp_new ();TCGv temp2 =tcg_temp_new (); -tcg_gen_movi_tl (mask,1 ); -tcg_gen_shl_tl (mask, mask, width); +tcg_gen_shl_tl (mask,tcg_constant_tl (1 ), width);tcg_gen_subi_tl (mask, mask,1 );tcg_gen_shl_tl (mask, mask, pos);
Signature · 1 line
2.45.2
Re: [PATCH 2/3] target/tricore: Use tcg_constant_tl() instead of tcg_gen_movi_tl()
Quoted 8 lines · Philippe Mathieu-Daudé
Directly use
tcg_constant_tl()for constant integer, this save a call totcg_gen_movi_tl().Inspired-by Richard Henderson<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/tricore/translate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
r~
PATCH 3/3 target/ppc: Use tcg_constant_tl() instead of tcg_gen_movi_tl()
In reply to Philippe Mathieu-DaudéDirectly use tcg_constant_tl() for constant integer, this save a call to tcg_gen_movi_tl() and a temp register.
--- target/ppc/translate.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
target/ppc/translate.c +5 -8
@@ -1588,16 +1588,13 @@ static opc_handler_t invalid_handler = {static inline void gen_op_cmp (TCGv arg0,TCGv arg1,int s,int crf) {TCGv t0 =tcg_temp_new (); -TCGv t1 =tcg_temp_new ();TCGv_i32 t =tcg_temp_new_i32 (); -tcg_gen_movi_tl (t0,CRF_EQ ); -tcg_gen_movi_tl (t1,CRF_LT );tcg_gen_movcond_tl ((s ?TCG_COND_LT :TCG_COND_LTU ), - t0, arg0, arg1, t1, t0); -tcg_gen_movi_tl (t1,CRF_GT ); + t0, arg0, arg1, +tcg_constant_tl (CRF_LT ),tcg_constant_tl (CRF_EQ ));tcg_gen_movcond_tl ((s ?TCG_COND_GT :TCG_COND_GTU ), - t0, arg0, arg1, t1, t0); + t0, arg0, arg1,tcg_constant_tl (CRF_GT ), t0);tcg_gen_trunc_tl_i32 (t, t0);tcg_gen_trunc_tl_i32 (cpu_crf[crf], cpu_so);
@@ -2974,8 +2971,8 @@ static void gen_fetch_inc_conditional(DisasContext *ctx, MemOp memop,tcg_gen_qemu_st_tl (u,EA , ctx->mem_idx, memop);/* RT = (t != t2 ? t : u = 1<<(s*8-1)) */ -tcg_gen_movi_tl (u,1 << (memop_size (memop) *8 -1 )); -tcg_gen_movcond_tl (cond, cpu_gpr[rD (ctx->opcode)], t, t2, t, u); +tcg_gen_movcond_tl (cond, cpu_gpr[rD (ctx->opcode)], t, t2, t, +tcg_constant_tl (1 << (memop_size (memop) *8 -1 ))); }static void gen_ld_atomic (DisasContext *ctx,MemOp memop)
Signature · 1 line
2.45.2
Re: [PATCH 3/3] target/ppc: Use tcg_constant_tl() instead of tcg_gen_movi_tl()
Quoted 8 lines · Philippe Mathieu-Daudé
Directly use
tcg_constant_tl()for constant integer, this save a call totcg_gen_movi_tl()and a temp register.Inspired-by Richard Henderson<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/ppc/translate.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
r~
Quoted 4 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (3):
target/mips: Usetcg_constant_tl()instead oftcg_gen_movi_tl()target/tricore: Usetcg_constant_tl()instead oftcg_gen_movi_tl()target/ppc: Usetcg_constant_tl()instead oftcg_gen_movi_tl()
Series queued, thanks.