Skip to content

Commit 42103c4

Browse files
committed
tcg/s390x: 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 fa65f13 commit 42103c4

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

tcg/s390x/tcg-target-has.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern uint64_t s390_facilities[3];
4848
#define TCG_TARGET_HAS_ctpop_i32 1
4949
#define TCG_TARGET_HAS_deposit_i32 1
5050
#define TCG_TARGET_HAS_extract_i32 1
51-
#define TCG_TARGET_HAS_sextract_i32 0
51+
#define TCG_TARGET_HAS_sextract_i32 1
5252
#define TCG_TARGET_HAS_extract2_i32 0
5353
#define TCG_TARGET_HAS_negsetcond_i32 1
5454
#define TCG_TARGET_HAS_add2_i32 1
@@ -82,7 +82,7 @@ extern uint64_t s390_facilities[3];
8282
#define TCG_TARGET_HAS_ctpop_i64 1
8383
#define TCG_TARGET_HAS_deposit_i64 1
8484
#define TCG_TARGET_HAS_extract_i64 1
85-
#define TCG_TARGET_HAS_sextract_i64 0
85+
#define TCG_TARGET_HAS_sextract_i64 1
8686
#define TCG_TARGET_HAS_extract2_i64 0
8787
#define TCG_TARGET_HAS_negsetcond_i64 1
8888
#define TCG_TARGET_HAS_add2_i64 1
@@ -121,4 +121,22 @@ extern uint64_t s390_facilities[3];
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 (ofs == 0) {
130+
switch (len) {
131+
case 8:
132+
case 16:
133+
return true;
134+
case 32:
135+
return type == TCG_TYPE_I64;
136+
}
137+
}
138+
return false;
139+
}
140+
#define TCG_TARGET_sextract_valid tcg_target_sextract_valid
141+
124142
#endif

tcg/s390x/tcg-target.c.inc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,9 +1572,41 @@ static void tgen_deposit(TCGContext *s, TCGReg dest, TCGReg src,
15721572
static void tgen_extract(TCGContext *s, TCGReg dest, TCGReg src,
15731573
int ofs, int len)
15741574
{
1575+
if (ofs == 0) {
1576+
switch (len) {
1577+
case 8:
1578+
tcg_out_ext8u(s, dest, src);
1579+
return;
1580+
case 16:
1581+
tcg_out_ext16u(s, dest, src);
1582+
return;
1583+
case 32:
1584+
tcg_out_ext32u(s, dest, src);
1585+
return;
1586+
}
1587+
}
15751588
tcg_out_risbg(s, dest, src, 64 - len, 63, 64 - ofs, 1);
15761589
}
15771590

1591+
static void tgen_sextract(TCGContext *s, TCGReg dest, TCGReg src,
1592+
int ofs, int len)
1593+
{
1594+
if (ofs == 0) {
1595+
switch (len) {
1596+
case 8:
1597+
tcg_out_ext8s(s, TCG_TYPE_REG, dest, src);
1598+
return;
1599+
case 16:
1600+
tcg_out_ext16s(s, TCG_TYPE_REG, dest, src);
1601+
return;
1602+
case 32:
1603+
tcg_out_ext32s(s, dest, src);
1604+
return;
1605+
}
1606+
}
1607+
g_assert_not_reached();
1608+
}
1609+
15781610
static void tgen_gotoi(TCGContext *s, int cc, const tcg_insn_unit *dest)
15791611
{
15801612
ptrdiff_t off = tcg_pcrel_diff(s, dest) >> 1;
@@ -2726,6 +2758,9 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, TCGType type,
27262758
OP_32_64(extract):
27272759
tgen_extract(s, args[0], args[1], args[2], args[3]);
27282760
break;
2761+
OP_32_64(sextract):
2762+
tgen_sextract(s, args[0], args[1], args[2], args[3]);
2763+
break;
27292764

27302765
case INDEX_op_clz_i64:
27312766
tgen_clz(s, args[0], args[1], args[2], const_args[2]);
@@ -3325,6 +3360,8 @@ tcg_target_op_def(TCGOpcode op, TCGType type, unsigned flags)
33253360
case INDEX_op_extu_i32_i64:
33263361
case INDEX_op_extract_i32:
33273362
case INDEX_op_extract_i64:
3363+
case INDEX_op_sextract_i32:
3364+
case INDEX_op_sextract_i64:
33283365
case INDEX_op_ctpop_i32:
33293366
case INDEX_op_ctpop_i64:
33303367
return C_O1_I1(r, r);

0 commit comments

Comments
 (0)