Skip to content

Commit 6be5417

Browse files
authored
Enable relaxed SIMD by default (#281)
* Enable relaxed SIMD by default * Rename `RelaxedSimd` to `TernaryOp`
1 parent 1e5d3e9 commit 6be5417

File tree

4 files changed

+92
-20
lines changed

4 files changed

+92
-20
lines changed

src/ir/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,13 @@ pub enum Instr {
314314
value: Value,
315315
},
316316

317+
/// Ternary operations, those requiring three operands
318+
TernOp {
319+
/// The operation being performed
320+
#[walrus(skip_visit)]
321+
op: TernaryOp,
322+
},
323+
317324
/// Binary operations, those requiring two operands
318325
Binop {
319326
/// The operation being performed
@@ -637,6 +644,21 @@ impl fmt::Display for Value {
637644
}
638645
}
639646

647+
/// Possible ternary operations in wasm
648+
#[allow(missing_docs)]
649+
#[derive(Copy, Clone, Debug)]
650+
pub enum TernaryOp {
651+
F32x4RelaxedMadd,
652+
F32x4RelaxedNmadd,
653+
F64x2RelaxedMadd,
654+
F64x2RelaxedNmadd,
655+
I8x16RelaxedLaneselect,
656+
I16x8RelaxedLaneselect,
657+
I32x4RelaxedLaneselect,
658+
I64x2RelaxedLaneselect,
659+
I32x4RelaxedDotI8x16I7x16AddS,
660+
}
661+
640662
/// Possible binary operations in wasm
641663
#[allow(missing_docs)]
642664
#[derive(Copy, Clone, Debug)]
@@ -875,6 +897,14 @@ pub enum BinaryOp {
875897
I64x2ExtMulHighI32x4S,
876898
I64x2ExtMulLowI32x4U,
877899
I64x2ExtMulHighI32x4U,
900+
901+
I8x16RelaxedSwizzle,
902+
F32x4RelaxedMin,
903+
F32x4RelaxedMax,
904+
F64x2RelaxedMin,
905+
F64x2RelaxedMax,
906+
I16x8RelaxedQ15mulrS,
907+
I16x8RelaxedDotI8x16I7x16S,
878908
}
879909

880910
/// Possible unary operations in wasm
@@ -1029,6 +1059,11 @@ pub enum UnaryOp {
10291059
I32x4WidenLowI16x8U,
10301060
I32x4WidenHighI16x8S,
10311061
I32x4WidenHighI16x8U,
1062+
1063+
I32x4RelaxedTruncF32x4S,
1064+
I32x4RelaxedTruncF32x4U,
1065+
I32x4RelaxedTruncF64x2SZero,
1066+
I32x4RelaxedTruncF64x2UZero,
10321067
}
10331068

10341069
/// The different kinds of load instructions that are part of a `Load` IR node
@@ -1247,6 +1282,7 @@ impl Instr {
12471282
| Instr::GlobalGet(..)
12481283
| Instr::GlobalSet(..)
12491284
| Instr::Const(..)
1285+
| Instr::TernOp(..)
12501286
| Instr::Binop(..)
12511287
| Instr::Unop(..)
12521288
| Instr::Select(..)

src/module/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ impl ModuleConfig {
175175
features.insert(WasmFeatures::REFERENCE_TYPES);
176176
features.insert(WasmFeatures::BULK_MEMORY);
177177
features.insert(WasmFeatures::SIMD);
178+
features.insert(WasmFeatures::RELAXED_SIMD);
178179
features.insert(WasmFeatures::TAIL_CALL);
179180
// Enable supported active proposals.
180181
if !self.only_stable_features {

src/module/functions/local_function/emit.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ impl<'instr> Visitor<'instr> for Emit<'_> {
187187
Instruction::MemoryFill(idx)
188188
}
189189

190+
TernOp(e) => {
191+
use crate::ir::TernaryOp::*;
192+
193+
match e.op {
194+
F32x4RelaxedMadd => Instruction::F32x4RelaxedMadd,
195+
F32x4RelaxedNmadd => Instruction::F32x4RelaxedNmadd,
196+
F64x2RelaxedMadd => Instruction::F64x2RelaxedMadd,
197+
F64x2RelaxedNmadd => Instruction::F64x2RelaxedNmadd,
198+
I8x16RelaxedLaneselect => Instruction::I8x16RelaxedLaneselect,
199+
I16x8RelaxedLaneselect => Instruction::I16x8RelaxedLaneselect,
200+
I32x4RelaxedLaneselect => Instruction::I32x4RelaxedLaneselect,
201+
I64x2RelaxedLaneselect => Instruction::I64x2RelaxedLaneselect,
202+
I32x4RelaxedDotI8x16I7x16AddS => Instruction::I32x4RelaxedDotI8x16I7x16AddS,
203+
}
204+
}
205+
190206
Binop(e) => {
191207
use crate::ir::BinaryOp::*;
192208

@@ -427,6 +443,14 @@ impl<'instr> Visitor<'instr> for Emit<'_> {
427443
I64x2ExtMulHighI32x4S => Instruction::I64x2ExtMulHighI32x4S,
428444
I64x2ExtMulLowI32x4U => Instruction::I64x2ExtMulLowI32x4U,
429445
I64x2ExtMulHighI32x4U => Instruction::I64x2ExtMulHighI32x4U,
446+
447+
I8x16RelaxedSwizzle => Instruction::I8x16RelaxedSwizzle,
448+
F32x4RelaxedMin => Instruction::F32x4RelaxedMin,
449+
F32x4RelaxedMax => Instruction::F32x4RelaxedMax,
450+
F64x2RelaxedMin => Instruction::F64x2RelaxedMin,
451+
F64x2RelaxedMax => Instruction::F64x2RelaxedMax,
452+
I16x8RelaxedQ15mulrS => Instruction::I16x8RelaxedQ15mulrS,
453+
I16x8RelaxedDotI8x16I7x16S => Instruction::I16x8RelaxedDotI8x16I7x16S,
430454
}
431455
}
432456

@@ -586,6 +610,11 @@ impl<'instr> Visitor<'instr> for Emit<'_> {
586610
F64x2ConvertLowI32x4U => Instruction::F64x2ConvertLowI32x4U,
587611
F32x4DemoteF64x2Zero => Instruction::F32x4DemoteF64x2Zero,
588612
F64x2PromoteLowF32x4 => Instruction::F64x2PromoteLowF32x4,
613+
614+
I32x4RelaxedTruncF32x4S => Instruction::I32x4RelaxedTruncF32x4S,
615+
I32x4RelaxedTruncF32x4U => Instruction::I32x4RelaxedTruncF32x4U,
616+
I32x4RelaxedTruncF64x2SZero => Instruction::I32x4RelaxedTruncF64x2SZero,
617+
I32x4RelaxedTruncF64x2UZero => Instruction::I32x4RelaxedTruncF64x2UZero,
589618
}
590619
}
591620

src/module/functions/local_function/mod.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ fn append_instruction(ctx: &mut ValidationContext, inst: Operator, loc: InstrLoc
317317
let binop = |ctx: &mut ValidationContext, op| {
318318
ctx.alloc_instr(Binop { op }, loc);
319319
};
320+
let ternop = |ctx: &mut ValidationContext, op| {
321+
ctx.alloc_instr(TernOp { op }, loc);
322+
};
320323

321324
let mem_arg = |ctx: &mut ValidationContext, arg: &wasmparser::MemArg| -> (MemoryId, MemArg) {
322325
(
@@ -1330,6 +1333,29 @@ fn append_instruction(ctx: &mut ValidationContext, inst: Operator, loc: InstrLoc
13301333
ctx.alloc_instr(ReturnCallIndirect { ty, table }, loc);
13311334
}
13321335

1336+
Operator::I8x16RelaxedSwizzle => binop(ctx, BinaryOp::I8x16RelaxedSwizzle),
1337+
Operator::I32x4RelaxedTruncF32x4S => unop(ctx, UnaryOp::I32x4RelaxedTruncF32x4S),
1338+
Operator::I32x4RelaxedTruncF32x4U => unop(ctx, UnaryOp::I32x4RelaxedTruncF32x4U),
1339+
Operator::I32x4RelaxedTruncF64x2SZero => unop(ctx, UnaryOp::I32x4RelaxedTruncF64x2SZero),
1340+
Operator::I32x4RelaxedTruncF64x2UZero => unop(ctx, UnaryOp::I32x4RelaxedTruncF64x2UZero),
1341+
Operator::F32x4RelaxedMadd => ternop(ctx, TernaryOp::F32x4RelaxedMadd),
1342+
Operator::F32x4RelaxedNmadd => ternop(ctx, TernaryOp::F32x4RelaxedNmadd),
1343+
Operator::F64x2RelaxedMadd => ternop(ctx, TernaryOp::F64x2RelaxedMadd),
1344+
Operator::F64x2RelaxedNmadd => ternop(ctx, TernaryOp::F64x2RelaxedNmadd),
1345+
Operator::I8x16RelaxedLaneselect => ternop(ctx, TernaryOp::I8x16RelaxedLaneselect),
1346+
Operator::I16x8RelaxedLaneselect => ternop(ctx, TernaryOp::I16x8RelaxedLaneselect),
1347+
Operator::I32x4RelaxedLaneselect => ternop(ctx, TernaryOp::I32x4RelaxedLaneselect),
1348+
Operator::I64x2RelaxedLaneselect => ternop(ctx, TernaryOp::I64x2RelaxedLaneselect),
1349+
Operator::F32x4RelaxedMin => binop(ctx, BinaryOp::F32x4RelaxedMin),
1350+
Operator::F32x4RelaxedMax => binop(ctx, BinaryOp::F32x4RelaxedMax),
1351+
Operator::F64x2RelaxedMin => binop(ctx, BinaryOp::F64x2RelaxedMin),
1352+
Operator::F64x2RelaxedMax => binop(ctx, BinaryOp::F64x2RelaxedMax),
1353+
Operator::I16x8RelaxedQ15mulrS => binop(ctx, BinaryOp::I16x8RelaxedQ15mulrS),
1354+
Operator::I16x8RelaxedDotI8x16I7x16S => binop(ctx, BinaryOp::I16x8RelaxedDotI8x16I7x16S),
1355+
Operator::I32x4RelaxedDotI8x16I7x16AddS => {
1356+
ternop(ctx, TernaryOp::I32x4RelaxedDotI8x16I7x16AddS)
1357+
}
1358+
13331359
// List all unimplmented operators instead of have a catch-all arm.
13341360
// So that future upgrades won't miss additions to this list that may be important to know.
13351361
Operator::TryTable { try_table: _ }
@@ -1465,26 +1491,6 @@ fn append_instruction(ctx: &mut ValidationContext, inst: Operator, loc: InstrLoc
14651491
ordering: _,
14661492
global_index: _,
14671493
}
1468-
| Operator::I8x16RelaxedSwizzle
1469-
| Operator::I32x4RelaxedTruncF32x4S
1470-
| Operator::I32x4RelaxedTruncF32x4U
1471-
| Operator::I32x4RelaxedTruncF64x2SZero
1472-
| Operator::I32x4RelaxedTruncF64x2UZero
1473-
| Operator::F32x4RelaxedMadd
1474-
| Operator::F32x4RelaxedNmadd
1475-
| Operator::F64x2RelaxedMadd
1476-
| Operator::F64x2RelaxedNmadd
1477-
| Operator::I8x16RelaxedLaneselect
1478-
| Operator::I16x8RelaxedLaneselect
1479-
| Operator::I32x4RelaxedLaneselect
1480-
| Operator::I64x2RelaxedLaneselect
1481-
| Operator::F32x4RelaxedMin
1482-
| Operator::F32x4RelaxedMax
1483-
| Operator::F64x2RelaxedMin
1484-
| Operator::F64x2RelaxedMax
1485-
| Operator::I16x8RelaxedQ15mulrS
1486-
| Operator::I16x8RelaxedDotI8x16I7x16S
1487-
| Operator::I32x4RelaxedDotI8x16I7x16AddS
14881494
| Operator::CallRef { type_index: _ }
14891495
| Operator::ReturnCallRef { type_index: _ }
14901496
| Operator::RefAsNonNull

0 commit comments

Comments
 (0)