Skip to contentSkip to conversation

target/s390x: Optimize save_link_info() using extract() TCG opcode

PATCH In review Philippe Mathieu-Daudé 2 participants 3 messages Oct 3, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/s390x: Optimize save_link_info() using extract() TCG opcode

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

    [DBG] candidate at target/s390x/tcg/translate.c:1560

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

---
 target/s390x/tcg/translate.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
target/s390x/tcg/translate.c +1 -2
index f284870cd2f..bfd805920c6 100644
@@ -1557,8 +1557,7 @@ static void save_link_info(DisasContext *s, DisasOps *o)
     tcg_gen_andi_i64(o->out, o->out, 0xffffffff00000000ull);
     tcg_gen_ori_i64(o->out, o->out, ((s->ilen / 2) << 30) | s->pc_tmp);
     t = tcg_temp_new_i64();
-    tcg_gen_shri_i64(t, psw_mask, 16);
-    tcg_gen_andi_i64(t, t, 0x0f000000);
+    tcg_gen_extract_i64(t, psw_mask, 40, 4);
     tcg_gen_or_i64(o->out, o->out, t);
     tcg_gen_extu_i32_i64(t, cc_op);
     tcg_gen_shli_i64(t, t, 28);
Signature · 1 line
2.31.1
#1 lore raw

target/s390x/tcg/translate.c static void save_link_info(DisasContext *s, DisasOps *o) · line 1560

Quoted 3 lines · Philippe Mathieu-Daudé
target/s390x/tcg/translate.c +1 -2
-    tcg_gen_shri_i64(t, psw_mask, 16);
-    tcg_gen_andi_i64(t, t, 0x0f000000);
+    tcg_gen_extract_i64(t, psw_mask, 40, 4);

No, the result should not be at bit 0, but bit 24.

r~

#2 lore raw
Quoted 6 lines · Richard Henderson
Quoted 3 lines · Philippe Mathieu-Daudé

-    tcg_gen_shri_i64(t, psw_mask, 16);
-    tcg_gen_andi_i64(t, t, 0x0f000000);
+    tcg_gen_extract_i64(t, psw_mask, 40, 4);

No, the result should not be at bit 0, but bit 24.

Good catch. I was no sure about that one, should have tagged RFC.

Thanks for the multiple reviews!