Skip to content

Commit 94d5939

Browse files
committed
tcg/ppc: Fold the ext{8,16,32}[us] cases into {s}extract
Accept byte and word extensions with the extract opcodes. This is preparatory to removing the specialized extracts. Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Richard Henderson <[email protected]>
1 parent 791d030 commit 94d5939

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

tcg/ppc/tcg-target-has.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define TCG_TARGET_HAS_ctpop_i32 have_isa_2_06
4040
#define TCG_TARGET_HAS_deposit_i32 1
4141
#define TCG_TARGET_HAS_extract_i32 1
42-
#define TCG_TARGET_HAS_sextract_i32 0
42+
#define TCG_TARGET_HAS_sextract_i32 1
4343
#define TCG_TARGET_HAS_extract2_i32 0
4444
#define TCG_TARGET_HAS_negsetcond_i32 1
4545
#define TCG_TARGET_HAS_mulu2_i32 0
@@ -75,7 +75,7 @@
7575
#define TCG_TARGET_HAS_ctpop_i64 have_isa_2_06
7676
#define TCG_TARGET_HAS_deposit_i64 1
7777
#define TCG_TARGET_HAS_extract_i64 1
78-
#define TCG_TARGET_HAS_sextract_i64 0
78+
#define TCG_TARGET_HAS_sextract_i64 1
7979
#define TCG_TARGET_HAS_extract2_i64 0
8080
#define TCG_TARGET_HAS_negsetcond_i64 1
8181
#define TCG_TARGET_HAS_add2_i64 1
@@ -121,4 +121,16 @@
121121
#define TCG_TARGET_HAS_cmpsel_vec 1
122122
#define TCG_TARGET_HAS_tst_vec 0
123123

124+
#define TCG_TARGET_extract_valid(type, ofs, len) 1
125+
126+
static inline bool
127+
tcg_target_sextract_valid(TCGType type, unsigned ofs, unsigned len)
128+
{
129+
if (type == TCG_TYPE_I64 && ofs + len == 32) {
130+
return true;
131+
}
132+
return ofs == 0 && (len == 8 || len == 16);
133+
}
134+
#define TCG_TARGET_sextract_valid tcg_target_sextract_valid
135+
124136
#endif

tcg/ppc/tcg-target.c.inc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,13 +3430,41 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, TCGType type,
34303430
break;
34313431

34323432
case INDEX_op_extract_i32:
3433+
if (args[2] == 0 && args[3] <= 16) {
3434+
tcg_out32(s, ANDI | SAI(args[1], args[0], (1 << args[3]) - 1));
3435+
break;
3436+
}
34333437
tcg_out_rlw(s, RLWINM, args[0], args[1],
34343438
32 - args[2], 32 - args[3], 31);
34353439
break;
34363440
case INDEX_op_extract_i64:
3441+
if (args[2] == 0 && args[3] <= 16) {
3442+
tcg_out32(s, ANDI | SAI(args[1], args[0], (1 << args[3]) - 1));
3443+
break;
3444+
}
34373445
tcg_out_rld(s, RLDICL, args[0], args[1], 64 - args[2], 64 - args[3]);
34383446
break;
34393447

3448+
case INDEX_op_sextract_i64:
3449+
if (args[2] + args[3] == 32) {
3450+
if (args[2] == 0) {
3451+
tcg_out_ext32s(s, args[0], args[1]);
3452+
} else {
3453+
tcg_out_sari32(s, args[0], args[1], args[2]);
3454+
}
3455+
break;
3456+
}
3457+
/* FALLTHRU */
3458+
case INDEX_op_sextract_i32:
3459+
if (args[2] == 0 && args[3] == 8) {
3460+
tcg_out_ext8s(s, TCG_TYPE_I32, args[0], args[1]);
3461+
} else if (args[2] == 0 && args[3] == 16) {
3462+
tcg_out_ext16s(s, TCG_TYPE_I32, args[0], args[1]);
3463+
} else {
3464+
g_assert_not_reached();
3465+
}
3466+
break;
3467+
34403468
case INDEX_op_movcond_i32:
34413469
tcg_out_movcond(s, TCG_TYPE_I32, args[5], args[0], args[1], args[2],
34423470
args[3], args[4], const_args[2]);
@@ -4160,6 +4188,7 @@ tcg_target_op_def(TCGOpcode op, TCGType type, unsigned flags)
41604188
case INDEX_op_bswap16_i32:
41614189
case INDEX_op_bswap32_i32:
41624190
case INDEX_op_extract_i32:
4191+
case INDEX_op_sextract_i32:
41634192
case INDEX_op_ld8u_i64:
41644193
case INDEX_op_ld8s_i64:
41654194
case INDEX_op_ld16u_i64:
@@ -4179,6 +4208,7 @@ tcg_target_op_def(TCGOpcode op, TCGType type, unsigned flags)
41794208
case INDEX_op_bswap32_i64:
41804209
case INDEX_op_bswap64_i64:
41814210
case INDEX_op_extract_i64:
4211+
case INDEX_op_sextract_i64:
41824212
return C_O1_I1(r, r);
41834213

41844214
case INDEX_op_st8_i32:

0 commit comments

Comments
 (0)