Skip to content

Commit fa65f13

Browse files
committed
tcg/riscv: Use SRAIW, SRLIW for {s}extract_i64
Extracts which abut bit 32 may use 32-bit shifts. Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Richard Henderson <[email protected]>
1 parent 841e2c5 commit fa65f13

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

tcg/riscv/tcg-target-has.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,21 @@
112112
static inline bool
113113
tcg_target_extract_valid(TCGType type, unsigned ofs, unsigned len)
114114
{
115-
if (ofs == 0) {
116-
switch (len) {
117-
case 16:
118-
return cpuinfo & CPUINFO_ZBB;
119-
case 32:
120-
return (cpuinfo & CPUINFO_ZBA) && type == TCG_TYPE_I64;
121-
}
115+
if (type == TCG_TYPE_I64 && ofs + len == 32) {
116+
/* ofs > 0 uses SRLIW; ofs == 0 uses add.uw. */
117+
return ofs || (cpuinfo & CPUINFO_ZBA);
122118
}
123-
return false;
119+
return (cpuinfo & CPUINFO_ZBB) && ofs == 0 && len == 16;
124120
}
125121
#define TCG_TARGET_extract_valid tcg_target_extract_valid
126122

127123
static inline bool
128124
tcg_target_sextract_valid(TCGType type, unsigned ofs, unsigned len)
129125
{
130-
if (ofs == 0) {
131-
switch (len) {
132-
case 8:
133-
case 16:
134-
return cpuinfo & CPUINFO_ZBB;
135-
case 32:
136-
return type == TCG_TYPE_I64;
137-
}
126+
if (type == TCG_TYPE_I64 && ofs + len == 32) {
127+
return true;
138128
}
139-
return false;
129+
return (cpuinfo & CPUINFO_ZBB) && ofs == 0 && (len == 8 || len == 16);
140130
}
141131
#define TCG_TARGET_sextract_valid tcg_target_sextract_valid
142132

tcg/riscv/tcg-target.c.inc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,8 +2344,12 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, TCGType type,
23442344
break;
23452345

23462346
case INDEX_op_extract_i64:
2347-
if (a2 == 0 && args[3] == 32) {
2348-
tcg_out_ext32u(s, a0, a1);
2347+
if (a2 + args[3] == 32) {
2348+
if (a2 == 0) {
2349+
tcg_out_ext32u(s, a0, a1);
2350+
} else {
2351+
tcg_out_opc_imm(s, OPC_SRLIW, a0, a1, a2);
2352+
}
23492353
break;
23502354
}
23512355
/* FALLTHRU */
@@ -2358,8 +2362,12 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, TCGType type,
23582362
break;
23592363

23602364
case INDEX_op_sextract_i64:
2361-
if (a2 == 0 && args[3] == 32) {
2362-
tcg_out_ext32s(s, a0, a1);
2365+
if (a2 + args[3] == 32) {
2366+
if (a2 == 0) {
2367+
tcg_out_ext32s(s, a0, a1);
2368+
} else {
2369+
tcg_out_opc_imm(s, OPC_SRAIW, a0, a1, a2);
2370+
}
23632371
break;
23642372
}
23652373
/* FALLTHRU */

0 commit comments

Comments
 (0)