Skip to content

Commit ee97eef

Browse files
committed
tcg/riscv: Use BEXTI for single-bit extractions
Acked-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20250102181601.1421059-3-richard.henderson@linaro.org>
1 parent 2c48155 commit ee97eef

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

tcg/riscv/tcg-target-has.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,13 @@ tcg_target_extract_valid(TCGType type, unsigned ofs, unsigned len)
110110
/* ofs > 0 uses SRLIW; ofs == 0 uses add.uw. */
111111
return ofs || (cpuinfo & CPUINFO_ZBA);
112112
}
113-
return (cpuinfo & CPUINFO_ZBB) && ofs == 0 && len == 16;
113+
switch (len) {
114+
case 1:
115+
return (cpuinfo & CPUINFO_ZBS) && ofs != 0;
116+
case 16:
117+
return (cpuinfo & CPUINFO_ZBB) && ofs == 0;
118+
}
119+
return false;
114120
}
115121
#define TCG_TARGET_extract_valid tcg_target_extract_valid
116122

tcg/riscv/tcg-target.c.inc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ typedef enum {
163163
OPC_ANDI = 0x7013,
164164
OPC_AUIPC = 0x17,
165165
OPC_BEQ = 0x63,
166+
OPC_BEXTI = 0x48005013,
166167
OPC_BGE = 0x5063,
167168
OPC_BGEU = 0x7063,
168169
OPC_BLT = 0x4063,
@@ -2354,9 +2355,15 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, TCGType type,
23542355
}
23552356
/* FALLTHRU */
23562357
case INDEX_op_extract_i32:
2357-
if (a2 == 0 && args[3] == 16) {
2358+
switch (args[3]) {
2359+
case 1:
2360+
tcg_out_opc_imm(s, OPC_BEXTI, a0, a1, a2);
2361+
break;
2362+
case 16:
2363+
tcg_debug_assert(a2 == 0);
23582364
tcg_out_ext16u(s, a0, a1);
2359-
} else {
2365+
break;
2366+
default:
23602367
g_assert_not_reached();
23612368
}
23622369
break;

0 commit comments

Comments
 (0)