All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] target/arm: Use tcg_constant_*
@ 2021-10-03 14:38 Philippe Mathieu-Daudé
  2021-10-03 14:38 ` [PATCH 1/3] target/arm: Use tcg_constant_i32() in op_smlad() Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-10-03 14:38 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, qemu-arm, Richard Henderson, Philippe Mathieu-Daudé

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(-)

-- 
2.31.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] target/arm: Use tcg_constant_i32() in op_smlad()
  2021-10-03 14:38 [PATCH 0/3] target/arm: Use tcg_constant_* Philippe Mathieu-Daudé
@ 2021-10-03 14:38 ` Philippe Mathieu-Daudé
  2021-10-03 15:33   ` Richard Henderson
  2021-10-03 14:39 ` [PATCH 2/3] target/arm: Introduce store_cpu_field_constant() helper Philippe Mathieu-Daudé
  2021-10-03 14:39 ` [PATCH 3/3] target/arm: Use the constant variant of store_cpu_field() when possible Philippe Mathieu-Daudé
  2 siblings, 1 reply; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-10-03 14:38 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, qemu-arm, Richard Henderson, Philippe Mathieu-Daudé

Avoid using a TCG temporary for a read-only constant.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 target/arm/translate.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/target/arm/translate.c b/target/arm/translate.c
index f7086c66a59..b41e0f50dfe 100644
--- a/target/arm/translate.c
+++ b/target/arm/translate.c
@@ -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);
     }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] target/arm: Introduce store_cpu_field_constant() helper
  2021-10-03 14:38 [PATCH 0/3] target/arm: Use tcg_constant_* Philippe Mathieu-Daudé
  2021-10-03 14:38 ` [PATCH 1/3] target/arm: Use tcg_constant_i32() in op_smlad() Philippe Mathieu-Daudé
@ 2021-10-03 14:39 ` Philippe Mathieu-Daudé
  2021-10-03 15:35   ` Richard Henderson
  2021-10-03 14:39 ` [PATCH 3/3] target/arm: Use the constant variant of store_cpu_field() when possible Philippe Mathieu-Daudé
  2 siblings, 1 reply; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-10-03 14:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, qemu-arm, Richard Henderson, 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).

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 target/arm/translate-a32.h | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/target/arm/translate-a32.h b/target/arm/translate-a32.h
index 88f15df60e8..b0abaac6f99 100644
--- a/target/arm/translate-a32.h
+++ b/target/arm/translate-a32.h
@@ -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)
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] target/arm: Use the constant variant of store_cpu_field() when possible
  2021-10-03 14:38 [PATCH 0/3] target/arm: Use tcg_constant_* Philippe Mathieu-Daudé
  2021-10-03 14:38 ` [PATCH 1/3] target/arm: Use tcg_constant_i32() in op_smlad() Philippe Mathieu-Daudé
  2021-10-03 14:39 ` [PATCH 2/3] target/arm: Introduce store_cpu_field_constant() helper Philippe Mathieu-Daudé
@ 2021-10-03 14:39 ` Philippe Mathieu-Daudé
  2021-10-03 15:40   ` Richard Henderson
  2 siblings, 1 reply; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-10-03 14:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, qemu-arm, Richard Henderson, 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.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 target/arm/translate.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/target/arm/translate.c b/target/arm/translate.c
index b41e0f50dfe..77c7a3ab2ec 100644
--- a/target/arm/translate.c
+++ b/target/arm/translate.c
@@ -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);
     }
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] target/arm: Use tcg_constant_i32() in op_smlad()
  2021-10-03 14:38 ` [PATCH 1/3] target/arm: Use tcg_constant_i32() in op_smlad() Philippe Mathieu-Daudé
@ 2021-10-03 15:33   ` Richard Henderson
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2021-10-03 15:33 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Peter Maydell, qemu-arm

On 10/3/21 10:38 AM, Philippe Mathieu-Daudé wrote:
> Avoid using a TCG temporary for a read-only constant.
> 
> Signed-off-by: Philippe Mathieu-Daudé<f4bug@amsat.org>
> ---
>   target/arm/translate.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] target/arm: Introduce store_cpu_field_constant() helper
  2021-10-03 14:39 ` [PATCH 2/3] target/arm: Introduce store_cpu_field_constant() helper Philippe Mathieu-Daudé
@ 2021-10-03 15:35   ` Richard Henderson
  2021-10-03 15:52     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2021-10-03 15:35 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Peter Maydell, qemu-arm

On 10/3/21 10:39 AM, Philippe Mathieu-Daudé wrote:
> -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)
>   

You missed out on using tcg_constant_i32 in the end.

r~


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] target/arm: Use the constant variant of store_cpu_field() when possible
  2021-10-03 14:39 ` [PATCH 3/3] target/arm: Use the constant variant of store_cpu_field() when possible Philippe Mathieu-Daudé
@ 2021-10-03 15:40   ` Richard Henderson
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2021-10-03 15:40 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Peter Maydell, qemu-arm

On 10/3/21 10:39 AM, Philippe Mathieu-Daudé wrote:
> When using a constant variable, we can replace the store_cpu_field()
> call by store_cpu_field_constant() which avoid using TCG temporaries.
> 
> Signed-off-by: Philippe Mathieu-Daudé<f4bug@amsat.org>
> ---
>   target/arm/translate.c | 21 ++++++---------------
>   1 file changed, 6 insertions(+), 15 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] target/arm: Introduce store_cpu_field_constant() helper
  2021-10-03 15:35   ` Richard Henderson
@ 2021-10-03 15:52     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-10-03 15:52 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: Peter Maydell, qemu-arm

On 10/3/21 17:35, Richard Henderson wrote:
> On 10/3/21 10:39 AM, Philippe Mathieu-Daudé wrote:
>> -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)
>>   
> 
> You missed out on using tcg_constant_i32 in the end.

Oops... thanks :)


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-10-03 15:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-03 14:38 [PATCH 0/3] target/arm: Use tcg_constant_* Philippe Mathieu-Daudé
2021-10-03 14:38 ` [PATCH 1/3] target/arm: Use tcg_constant_i32() in op_smlad() Philippe Mathieu-Daudé
2021-10-03 15:33   ` Richard Henderson
2021-10-03 14:39 ` [PATCH 2/3] target/arm: Introduce store_cpu_field_constant() helper Philippe Mathieu-Daudé
2021-10-03 15:35   ` Richard Henderson
2021-10-03 15:52     ` Philippe Mathieu-Daudé
2021-10-03 14:39 ` [PATCH 3/3] target/arm: Use the constant variant of store_cpu_field() when possible Philippe Mathieu-Daudé
2021-10-03 15:40   ` Richard Henderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.