Skip to contentSkip to conversation

target/avr: Optimize various functions using extract opcode

PATCH In review Philippe Mathieu-Daudé 3 participants 4 messages Oct 3, 2021 – Oct 27, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/avr: Optimize various functions using extract opcode

When running the scripts/coccinelle/tcg_gen_extract.cocci Coccinelle semantic patch on target/avr/, we get:

[DBG] candidate at target/avr/translate.c:228
[DBG] candidate at target/avr/translate.c:266
[DBG] candidate at target/avr/translate.c:885
[DBG] candidate at target/avr/translate.c:924
[DBG] candidate at target/avr/translate.c:962

Manually inspect and replace combinations of (shri, andi) opcodes by the extract opcode.

---
 target/avr/translate.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
target/avr/translate.c +5 -11
index 438e7b13c18..246cbfba1cd 100644
@@ -225,8 +225,7 @@ static void gen_add_CHf(TCGv R, TCGv Rd, TCGv Rr)
     tcg_gen_or_tl(t1, t1, t3);
 
     tcg_gen_shri_tl(cpu_Cf, t1, 7); /* Cf = t1(7) */
-    tcg_gen_shri_tl(cpu_Hf, t1, 3); /* Hf = t1(3) */
-    tcg_gen_andi_tl(cpu_Hf, cpu_Hf, 1);
+    tcg_gen_extract_tl(cpu_Hf, t1, 3, 1); /* Hf = t1(3) */
 
     tcg_temp_free_i32(t3);
     tcg_temp_free_i32(t2);
@@ -263,8 +262,7 @@ static void gen_sub_CHf(TCGv R, TCGv Rd, TCGv Rr)
     tcg_gen_or_tl(t2, t2, t3); /* t2 = ~Rd & Rr | ~Rd & R | R & Rr */
 
     tcg_gen_shri_tl(cpu_Cf, t2, 7); /* Cf = t2(7) */
-    tcg_gen_shri_tl(cpu_Hf, t2, 3); /* Hf = t2(3) */
-    tcg_gen_andi_tl(cpu_Hf, cpu_Hf, 1);
+    tcg_gen_extract_tl(cpu_Hf, t2, 3, 1); /* Hf = t2(3) */
 
     tcg_temp_free_i32(t3);
     tcg_temp_free_i32(t2);
@@ -882,9 +880,7 @@ static bool trans_FMUL(DisasContext *ctx, arg_FMUL *a)
     /* update output registers */
     tcg_gen_shli_tl(R, R, 1);
     tcg_gen_andi_tl(R0, R, 0xff);
-    tcg_gen_shri_tl(R1, R, 8);
-    tcg_gen_andi_tl(R1, R1, 0xff);
-
+    tcg_gen_extract_tl(R1, R, 8, 8);
 
     tcg_temp_free_i32(R);
 
@@ -921,8 +917,7 @@ static bool trans_FMULS(DisasContext *ctx, arg_FMULS *a)
     /* update output registers */
     tcg_gen_shli_tl(R, R, 1);
     tcg_gen_andi_tl(R0, R, 0xff);
-    tcg_gen_shri_tl(R1, R, 8);
-    tcg_gen_andi_tl(R1, R1, 0xff);
+    tcg_gen_extract_tl(R1, R, 8, 8);
 
     tcg_temp_free_i32(t1);
     tcg_temp_free_i32(t0);
@@ -959,8 +954,7 @@ static bool trans_FMULSU(DisasContext *ctx, arg_FMULSU *a)
     /* update output registers */
     tcg_gen_shli_tl(R, R, 1);
     tcg_gen_andi_tl(R0, R, 0xff);
-    tcg_gen_shri_tl(R1, R, 8);
-    tcg_gen_andi_tl(R1, R1, 0xff);
+    tcg_gen_extract_tl(R1, R, 8, 8);
 
     tcg_temp_free_i32(t0);
     tcg_temp_free_i32(R);
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Philippe Mathieu-Daudé

When running the scripts/coccinelle/tcg_gen_extract.cocci Coccinelle semantic patch on target/avr/, we get:

[DBG] candidate at target/avr/translate.c:228
[DBG] candidate at target/avr/translate.c:266
[DBG] candidate at target/avr/translate.c:885
[DBG] candidate at target/avr/translate.c:924
[DBG] candidate at target/avr/translate.c:962

Quoted 7 lines

Manually inspect and replace combinations of (shri, andi) opcodes by the extract opcode.

---
  target/avr/translate.c | 16 +++++-----------
  1 file changed, 5 insertions(+), 11 deletions(-)

r~

#2 lore raw

Hi Richard,

Quoted 13 lines · Richard Henderson
Quoted 12 lines · Philippe Mathieu-Daudé

When running the scripts/coccinelle/tcg_gen_extract.cocci Coccinelle semantic patch on target/avr/, we get:

   [DBG] candidate at target/avr/translate.c:228
   [DBG] candidate at target/avr/translate.c:266
   [DBG] candidate at target/avr/translate.c:885
   [DBG] candidate at target/avr/translate.c:924
   [DBG] candidate at target/avr/translate.c:962

Manually inspect and replace combinations of (shri, andi) opcodes by the extract opcode.

Quoted 6 lines
Quoted 4 lines

---
  target/avr/translate.c | 16 +++++-----------

  1 file changed, 5 insertions(+), 11 deletions(-)

Do you mind taking this patch via tcg-next?

#3 lore raw

hi Philippe

how was it tested?

Quoted 25 lines · Philippe Mathieu-Daudé

Hi Richard,

Quoted 13 lines · Richard Henderson
Quoted 12 lines · Philippe Mathieu-Daudé

When running the scripts/coccinelle/tcg_gen_extract.cocci Coccinelle semantic patch on target/avr/, we get:

[DBG] candidate at target/avr/translate.c:228
[DBG] candidate at target/avr/translate.c:266
[DBG] candidate at target/avr/translate.c:885
[DBG] candidate at target/avr/translate.c:924
[DBG] candidate at target/avr/translate.c:962

Manually inspect and replace combinations of (shri, andi) opcodes by the extract opcode.

Quoted 6 lines
Quoted 4 lines
---
  target/avr/translate.c | 16 +++++-----------
  1 file changed, 5 insertions(+), 11 deletions(-)

Do you mind taking this patch via tcg-next?

Signature · 2 lines
Best Regards,
Michael Rolnik