target/arm: Use tcg_constant_*
cover target/arm: Use tcg_constant_*
Introduce store_cpu_field_constant() helper to avoid using temporary when the value is constant (and read-only).
Philippe Mathieu-Daudé (3):
target/arm: Use tcg_constant_i32() in op_smlad() target/arm: Introduce store_cpu_field_constant() helper target/arm: Use the constant variant of store_cpu_field() when
possible
target/arm/translate-a32.h | 11 ++++++++--- target/arm/translate.c | 24 +++++++----------------- 2 files changed, 15 insertions(+), 20 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/3 target/arm: Use tcg_constant_i32() in op_smlad()
Avoid using a TCG temporary for a read-only constant.
--- target/arm/translate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target/arm/translate.c +1 -2
@@ -7873,10 +7873,9 @@ static bool op_smlad(DisasContext *s, arg_rrrr *a, bool m_swap, bool sub) t3 =tcg_temp_new_i32 ();tcg_gen_sari_i32 (t3, t1,31 ); qf =load_cpu_field (QF ); - one =tcg_const_i32 (1 ); + one =tcg_constant_i32 (1 );tcg_gen_movcond_i32 (TCG_COND_NE , qf, t2, t3, one, qf);store_cpu_field (qf,QF ); -tcg_temp_free_i32 (one);tcg_temp_free_i32 (t3);tcg_temp_free_i32 (t2); }
Signature · 1 line
2.31.1
Re: [PATCH 1/3] target/arm: Use tcg_constant_i32() in op_smlad()
Quoted 6 lines · Philippe Mathieu-Daudé
Avoid using a TCG temporary for a read-only constant.
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/arm/translate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
r~
PATCH 2/3 target/arm: Introduce store_cpu_field_constant() helper
In reply to Philippe Mathieu-DaudéSimilarly to the store_cpu_field() helper which takes a TCG temporary, store its value to the CPUState, introduce the store_cpu_field_constant() helper which store a constant to CPUState (without using any TCG temporary).
--- target/arm/translate-a32.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
target/arm/translate-a32.h +8 -3
@@ -61,14 +61,19 @@ static inline TCGv_i32 load_cpu_offset(int offset)#define load_cpu_field (name) load_cpu_offset(offsetof(CPUARMState, name)) -static inline void store_cpu_offset (TCGv_i32 var,int offset) +static inline void store_cpu_offset (TCGv_i32 var,int offset,bool is_temp) {tcg_gen_st_i32 (var, cpu_env, offset); -tcg_temp_free_i32 (var); +if (is_temp) { +tcg_temp_free_i32 (var); + } }#define store_cpu_field (var, name) \ - store_cpu_offset(var, offsetof(CPUARMState, name)) + store_cpu_offset(var, offsetof(CPUARMState, name), true) + +#define store_cpu_field_constant (val, name) \ + store_cpu_offset(tcg_const_i32(val), offsetof(CPUARMState, name), false)/* Create a new temporary and set it to the value of a CPU register. */ static inline TCGv_i32 load_reg (DisasContext *s,int reg)
Signature · 1 line
2.31.1
Re: [PATCH 2/3] target/arm: Introduce store_cpu_field_constant() helper
Quoted 7 lines · Philippe Mathieu-Daudé
target/arm/translate-a32.h +2
-2-static inline void store_cpu_offset (TCGv_i32 var,int offset) +static inline void store_cpu_offset (TCGv_i32 var,int offset,bool is_temp) {tcg_gen_st_i32 (var, cpu_env, offset); -tcg_temp_free_i32 (var); +if (is_temp) {
target/arm/translate-a32.h static inline TCGv_i32 load_cpu_offset(int offset) · line 76
Quoted 10 lines
target/arm/translate-a32.h +6
-1+tcg_temp_free_i32 (var); + } }#define store_cpu_field (var, name) \ - store_cpu_offset(var, offsetof(CPUARMState, name)) + store_cpu_offset(var, offsetof(CPUARMState, name), true) + +#define store_cpu_field_constant (val, name) \ + store_cpu_offset(tcg_const_i32(val), offsetof(CPUARMState, name), false)
You missed out on using tcg_constant_i32 in the end.
r~
Re: [PATCH 2/3] target/arm: Introduce store_cpu_field_constant() helper
Quoted 13 lines · Richard Henderson
Quoted 12 lines · Philippe Mathieu-Daudé
(quoted diff) +1
-1-static inline void store_cpu_offset(TCGv_i32 var, int offset) +static inline void store_cpu_offset(TCGv_i32 var, int offset, bool
is_temp)
{
tcg_gen_st_i32(var, cpu_env, offset);
-tcg_temp_free_i32(var);
+ if (is_temp) {
+tcg_temp_free_i32(var);
+ }
}
#definestore_cpu_field(var, name)\
-store_cpu_offset(var, offsetof(CPUARMState, name))
Quoted 8 lines
Quoted 6 lines
+
store_cpu_offset(var, offsetof(CPUARMState, name), true)target/arm/translate-a32.h +3
-0+ +#define store_cpu_field_constant (val, name) \ + store_cpu_offset(tcg_const_i32(val), offsetof(CPUARMState, name),false)
You missed out on using
tcg_constant_i32in the end.
Oops... thanks :)
PATCH 3/3 target/arm: Use the constant variant of store_cpu_field() when possible
In reply to Philippe Mathieu-DaudéWhen using a constant variable, we can replace the store_cpu_field() call by store_cpu_field_constant() which avoid using TCG temporaries.
--- target/arm/translate.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
target/arm/translate.c +6 -15
@@ -388,8 +388,7 @@ void clear_eci_state(DisasContext *s)* multiple insn executes. */ if (s->eci) { -TCGv_i32 tmp =tcg_const_i32 (0 ); -store_cpu_field (tmp, condexec_bits); +store_cpu_field_constant (0 , condexec_bits); s->eci =0 ; } }
@@ -764,9 +763,8 @@ void gen_set_condexec(DisasContext *s) {if (s->condexec_mask) {uint32_t val = (s->condexec_cond <<4 ) | (s->condexec_mask >>1 ); -TCGv_i32 tmp =tcg_temp_new_i32 (); -tcg_gen_movi_i32 (tmp, val); -store_cpu_field (tmp, condexec_bits); + +store_cpu_field_constant (val, condexec_bits); } }
@@ -8386,8 +8384,6 @@ static bool trans_BL(DisasContext *s, arg_i *a)static bool trans_BLX_i (DisasContext *s,arg_BLX_i *a) { -TCGv_i32 tmp; -/* * BLX <imm> would be useless on M-profile; the encoding space * is used for other insns from v8.1M onward, and UNDEFs before that.
@@ -8401,8 +8397,7 @@ static bool trans_BLX_i(DisasContext *s, arg_BLX_i *a)return false; }tcg_gen_movi_i32 (cpu_R[14 ], s->base.pc_next | s->thumb); - tmp =tcg_const_i32 (!s->thumb); -store_cpu_field (tmp, thumb); +store_cpu_field_constant (!s->thumb, thumb);gen_jmp (s, (read_pc (s) & ~3 ) + a->imm);return true; }
@@ -8701,7 +8696,6 @@ static bool trans_LCTP(DisasContext *s, arg_LCTP *a)* doesn't cache branch information, all we need to do is reset * FPSCR.LTPSIZE to 4. */ -TCGv_i32 ltpsize;if (!dc_isar_feature (aa32_lob, s) || !dc_isar_feature (aa32_mve, s)) {
@@ -8712,8 +8706,7 @@ static bool trans_LCTP(DisasContext *s, arg_LCTP *a)return true; } - ltpsize =tcg_const_i32 (4 ); -store_cpu_field (ltpsize, v7m.ltpsize); +store_cpu_field_constant (4 , v7m.ltpsize);return true; }
@@ -9511,9 +9504,7 @@ static void arm_tr_tb_start(DisasContextBase *dcbase, CPUState *cpu)/* Reset the conditional execution bits immediately. This avoids complications trying to do it at the end of the block. */ if (dc->condexec_mask || dc->condexec_cond) { -TCGv_i32 tmp =tcg_temp_new_i32 (); -tcg_gen_movi_i32 (tmp,0 ); -store_cpu_field (tmp, condexec_bits); +store_cpu_field_constant (0 , condexec_bits); } }
Signature · 1 line
2.31.1
Re: [PATCH 3/3] target/arm: Use the constant variant of store_cpu_field() when possible
Quoted 7 lines · Philippe Mathieu-Daudé
When using a constant variable, we can replace the
store_cpu_field()call bystore_cpu_field_constant()which avoid using TCG temporaries.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/arm/translate.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
r~