Skip to content

Commit 142e6f9

Browse files
authored
Update wasmi_ir2 (#1660)
* fix identifiers for signed v128 prefixes * remove non-existing simd ops * fix some ternary relaxed SIMD operators * clean-up and simplify UnaryOp[Kind] codegen * feature guard TernaryOp and impls
1 parent c7af4f7 commit 142e6f9

File tree

11 files changed

+234
-192
lines changed

11 files changed

+234
-192
lines changed

crates/ir2/build/display/constructors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::build::{
1212
StoreOp,
1313
TableGetOp,
1414
TableSetOp,
15+
TernaryOp,
1516
UnaryOp,
1617
V128LoadLaneOp,
1718
V128ReplaceLaneOp,
@@ -101,6 +102,7 @@ macro_rules! impl_display_constructor {
101102
impl_display_constructor! {
102103
UnaryOp,
103104
BinaryOp,
105+
TernaryOp,
104106
CmpBranchOp,
105107
CmpSelectOp,
106108
LoadOp,

crates/ir2/build/display/decode.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::build::{
1616
StoreOp,
1717
TableGetOp,
1818
TableSetOp,
19+
TernaryOp,
1920
UnaryOp,
2021
V128LoadLaneOp,
2122
V128ReplaceLaneOp,
@@ -74,6 +75,17 @@ impl Display for DisplayDecode<&'_ BinaryOp> {
7475
}
7576
}
7677

78+
impl Display for DisplayDecode<&'_ TernaryOp> {
79+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80+
let op = self.value;
81+
let camel_ident = DisplayIdent::camel(op);
82+
let a = op.a_field().ty;
83+
let b = op.b_field().ty;
84+
let c = op.c_field().ty;
85+
writeln!(f, "pub type {camel_ident} = TernaryOp<{a}, {b}, {c}>;")
86+
}
87+
}
88+
7789
impl Display for DisplayDecode<&'_ CmpBranchOp> {
7890
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7991
let op = self.value;

crates/ir2/build/display/encode.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::build::{
1212
StoreOp,
1313
TableGetOp,
1414
TableSetOp,
15+
TernaryOp,
1516
UnaryOp,
1617
V128LoadLaneOp,
1718
V128ReplaceLaneOp,
@@ -103,6 +104,7 @@ macro_rules! impl_display_encode {
103104
impl_display_encode! {
104105
UnaryOp,
105106
BinaryOp,
107+
TernaryOp,
106108
CmpBranchOp,
107109
CmpSelectOp,
108110
LoadOp,

crates/ir2/build/display/ident.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::build::{
1111
StoreOp,
1212
TableGetOp,
1313
TableSetOp,
14+
TernaryOp,
1415
UnaryOp,
1516
V128LoadLaneOp,
1617
V128ReplaceLaneOp,
@@ -53,10 +54,9 @@ impl Display for DisplayIdent<&'_ UnaryOp> {
5354
let kind = op.kind;
5455
let ident = case.wrap(kind.ident());
5556
let sep = case.wrap(Sep);
56-
let ident_prefix = DisplayConcat((case.wrap(kind.result_ty()), sep));
57+
let ident_prefix = DisplayConcat((case.wrap(kind.ident_prefix()), sep));
5758
let ident_suffix = kind
58-
.is_conversion()
59-
.then_some(kind.value_ty())
59+
.ident_suffix()
6060
.map(|i| (sep, case.wrap(i)))
6161
.map(DisplayConcat)
6262
.display_maybe();
@@ -86,6 +86,25 @@ impl Display for DisplayIdent<&'_ BinaryOp> {
8686
}
8787
}
8888

89+
impl Display for DisplayIdent<&'_ TernaryOp> {
90+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91+
let case = self.case;
92+
let sep = case.wrap(Sep);
93+
let op = self.value;
94+
let kind = op.kind;
95+
let ident = case.wrap(kind.ident());
96+
let ident_prefix = case.wrap(kind.ident_prefix());
97+
let result_suffix = case.wrap(OperandKind::Slot);
98+
let a_suffix = SnakeCase(OperandKind::Slot);
99+
let b_suffix = SnakeCase(OperandKind::Slot);
100+
let c_suffix = SnakeCase(OperandKind::Slot);
101+
write!(
102+
f,
103+
"{ident_prefix}{sep}{ident}_{result_suffix}{a_suffix}{b_suffix}{c_suffix}"
104+
)
105+
}
106+
}
107+
89108
impl Display for DisplayIdent<&'_ CmpBranchOp> {
90109
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91110
let case = self.case;

crates/ir2/build/display/op.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::build::{
1515
StoreOp,
1616
TableGetOp,
1717
TableSetOp,
18+
TernaryOp,
1819
UnaryOp,
1920
V128LoadLaneOp,
2021
V128ReplaceLaneOp,
@@ -105,6 +106,7 @@ macro_rules! impl_display_variant {
105106
impl_display_variant! {
106107
UnaryOp,
107108
BinaryOp,
109+
TernaryOp,
108110
CmpBranchOp,
109111
CmpSelectOp,
110112
LoadOp,

crates/ir2/build/display/result_mut.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::build::{
1010
StoreOp,
1111
TableGetOp,
1212
TableSetOp,
13+
TernaryOp,
1314
UnaryOp,
1415
V128LoadLaneOp,
1516
V128ReplaceLaneOp,
@@ -85,6 +86,12 @@ impl Display for DisplayResultMut<&'_ BinaryOp> {
8586
}
8687
}
8788

89+
impl Display for DisplayResultMut<&'_ TernaryOp> {
90+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91+
self.display_match_arm(f)
92+
}
93+
}
94+
8895
impl Display for DisplayResultMut<&'_ CmpBranchOp> {
8996
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
9097
Ok(())

crates/ir2/build/ident.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,13 @@ define_ident!(
306306
Store32Lane: store32_lane,
307307
Store64Lane: store64_lane,
308308

309+
Bitselect: bitselect,
309310
RelaxedDotI8x16I7x16: relaxed_dot_i8x16_i7x16,
310311
RelaxedDotI8x16I7x16Add: relaxed_dot_i8x16_i7x16_add,
311312
RelaxedMadd: relaxed_madd,
312313
RelaxedNmadd: relaxed_nmadd,
314+
315+
A: a,
316+
B: b,
317+
C: c,
313318
);

crates/ir2/build/isa.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use crate::build::{
1818
StoreOpKind,
1919
TableGetOp,
2020
TableSetOp,
21+
TernaryOp,
22+
TernaryOpKind,
2123
Ty,
2224
UnaryOp,
2325
UnaryOpKind,
@@ -860,8 +862,6 @@ fn add_simd_binary_ops(isa: &mut Isa) {
860862
BinaryOpKind::U16x8Le,
861863
BinaryOpKind::U32x4Lt,
862864
BinaryOpKind::U32x4Le,
863-
BinaryOpKind::U64x2Lt,
864-
BinaryOpKind::U64x2Le,
865865
// Float Comparisons
866866
BinaryOpKind::F32x4Eq,
867867
BinaryOpKind::F32x4NotEq,
@@ -891,6 +891,7 @@ fn add_simd_binary_ops(isa: &mut Isa) {
891891
BinaryOpKind::U8x16Max,
892892
BinaryOpKind::U8x16Avgr,
893893
// i16x8 Ops
894+
BinaryOpKind::S16x8RelaxedDotI8x16I7x16,
894895
BinaryOpKind::S16x8Q15MulrSat,
895896
BinaryOpKind::S16x8NarrowI32x4,
896897
BinaryOpKind::U16x8NarrowI32x4,
@@ -1115,14 +1116,14 @@ fn add_simd_store_ops(isa: &mut Isa) {
11151116

11161117
fn add_relaxed_simd_ops(isa: &mut Isa) {
11171118
let kinds = [
1118-
BinaryOpKind::S16x8RelaxedDotI8x16I7x16,
1119-
BinaryOpKind::S32x4RelaxedDotI8x16I7x16Add,
1120-
BinaryOpKind::F32x4RelaxedMadd,
1121-
BinaryOpKind::F32x4RelaxedNmadd,
1122-
BinaryOpKind::F64x2RelaxedMadd,
1123-
BinaryOpKind::F64x2RelaxedNmadd,
1119+
TernaryOpKind::I32x4RelaxedDotI8x16I7x16Add,
1120+
TernaryOpKind::F32x4RelaxedMadd,
1121+
TernaryOpKind::F32x4RelaxedNmadd,
1122+
TernaryOpKind::F64x2RelaxedMadd,
1123+
TernaryOpKind::F64x2RelaxedNmadd,
1124+
TernaryOpKind::V128Bitselect,
11241125
];
11251126
for kind in kinds {
1126-
isa.push_op(BinaryOp::new(kind, OperandKind::Slot, OperandKind::Slot));
1127+
isa.push_op(TernaryOp::new(kind));
11271128
}
11281129
}

0 commit comments

Comments
 (0)