Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable relaxed SIMD by default #281

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ pub enum Instr {
value: Value,
},

/// Ternary operations, those requiring three operands
TernOp {
/// The operation being performed
#[walrus(skip_visit)]
op: TernaryOp,
},

/// Binary operations, those requiring two operands
Binop {
/// The operation being performed
Expand Down Expand Up @@ -637,6 +644,21 @@ impl fmt::Display for Value {
}
}

/// Possible ternary operations in wasm
#[allow(missing_docs)]
#[derive(Copy, Clone, Debug)]
pub enum TernaryOp {
F32x4RelaxedMadd,
F32x4RelaxedNmadd,
F64x2RelaxedMadd,
F64x2RelaxedNmadd,
I8x16RelaxedLaneselect,
I16x8RelaxedLaneselect,
I32x4RelaxedLaneselect,
I64x2RelaxedLaneselect,
I32x4RelaxedDotI8x16I7x16AddS,
}

/// Possible binary operations in wasm
#[allow(missing_docs)]
#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -875,6 +897,14 @@ pub enum BinaryOp {
I64x2ExtMulHighI32x4S,
I64x2ExtMulLowI32x4U,
I64x2ExtMulHighI32x4U,

I8x16RelaxedSwizzle,
F32x4RelaxedMin,
F32x4RelaxedMax,
F64x2RelaxedMin,
F64x2RelaxedMax,
I16x8RelaxedQ15mulrS,
I16x8RelaxedDotI8x16I7x16S,
}

/// Possible unary operations in wasm
Expand Down Expand Up @@ -1029,6 +1059,11 @@ pub enum UnaryOp {
I32x4WidenLowI16x8U,
I32x4WidenHighI16x8S,
I32x4WidenHighI16x8U,

I32x4RelaxedTruncF32x4S,
I32x4RelaxedTruncF32x4U,
I32x4RelaxedTruncF64x2SZero,
I32x4RelaxedTruncF64x2UZero,
}

/// The different kinds of load instructions that are part of a `Load` IR node
Expand Down Expand Up @@ -1247,6 +1282,7 @@ impl Instr {
| Instr::GlobalGet(..)
| Instr::GlobalSet(..)
| Instr::Const(..)
| Instr::TernOp(..)
| Instr::Binop(..)
| Instr::Unop(..)
| Instr::Select(..)
Expand Down
1 change: 1 addition & 0 deletions src/module/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ impl ModuleConfig {
features.insert(WasmFeatures::REFERENCE_TYPES);
features.insert(WasmFeatures::BULK_MEMORY);
features.insert(WasmFeatures::SIMD);
features.insert(WasmFeatures::RELAXED_SIMD);
features.insert(WasmFeatures::TAIL_CALL);
// Enable supported active proposals.
if !self.only_stable_features {
Expand Down
29 changes: 29 additions & 0 deletions src/module/functions/local_function/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ impl<'instr> Visitor<'instr> for Emit<'_> {
Instruction::MemoryFill(idx)
}

TernOp(e) => {
use crate::ir::TernaryOp::*;

match e.op {
F32x4RelaxedMadd => Instruction::F32x4RelaxedMadd,
F32x4RelaxedNmadd => Instruction::F32x4RelaxedNmadd,
F64x2RelaxedMadd => Instruction::F64x2RelaxedMadd,
F64x2RelaxedNmadd => Instruction::F64x2RelaxedNmadd,
I8x16RelaxedLaneselect => Instruction::I8x16RelaxedLaneselect,
I16x8RelaxedLaneselect => Instruction::I16x8RelaxedLaneselect,
I32x4RelaxedLaneselect => Instruction::I32x4RelaxedLaneselect,
I64x2RelaxedLaneselect => Instruction::I64x2RelaxedLaneselect,
I32x4RelaxedDotI8x16I7x16AddS => Instruction::I32x4RelaxedDotI8x16I7x16AddS,
}
}

Binop(e) => {
use crate::ir::BinaryOp::*;

Expand Down Expand Up @@ -427,6 +443,14 @@ impl<'instr> Visitor<'instr> for Emit<'_> {
I64x2ExtMulHighI32x4S => Instruction::I64x2ExtMulHighI32x4S,
I64x2ExtMulLowI32x4U => Instruction::I64x2ExtMulLowI32x4U,
I64x2ExtMulHighI32x4U => Instruction::I64x2ExtMulHighI32x4U,

I8x16RelaxedSwizzle => Instruction::I8x16RelaxedSwizzle,
F32x4RelaxedMin => Instruction::F32x4RelaxedMin,
F32x4RelaxedMax => Instruction::F32x4RelaxedMax,
F64x2RelaxedMin => Instruction::F64x2RelaxedMin,
F64x2RelaxedMax => Instruction::F64x2RelaxedMax,
I16x8RelaxedQ15mulrS => Instruction::I16x8RelaxedQ15mulrS,
I16x8RelaxedDotI8x16I7x16S => Instruction::I16x8RelaxedDotI8x16I7x16S,
}
}

Expand Down Expand Up @@ -586,6 +610,11 @@ impl<'instr> Visitor<'instr> for Emit<'_> {
F64x2ConvertLowI32x4U => Instruction::F64x2ConvertLowI32x4U,
F32x4DemoteF64x2Zero => Instruction::F32x4DemoteF64x2Zero,
F64x2PromoteLowF32x4 => Instruction::F64x2PromoteLowF32x4,

I32x4RelaxedTruncF32x4S => Instruction::I32x4RelaxedTruncF32x4S,
I32x4RelaxedTruncF32x4U => Instruction::I32x4RelaxedTruncF32x4U,
I32x4RelaxedTruncF64x2SZero => Instruction::I32x4RelaxedTruncF64x2SZero,
I32x4RelaxedTruncF64x2UZero => Instruction::I32x4RelaxedTruncF64x2UZero,
}
}

Expand Down
46 changes: 26 additions & 20 deletions src/module/functions/local_function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ fn append_instruction(ctx: &mut ValidationContext, inst: Operator, loc: InstrLoc
let binop = |ctx: &mut ValidationContext, op| {
ctx.alloc_instr(Binop { op }, loc);
};
let ternop = |ctx: &mut ValidationContext, op| {
ctx.alloc_instr(TernOp { op }, loc);
};

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

Operator::I8x16RelaxedSwizzle => binop(ctx, BinaryOp::I8x16RelaxedSwizzle),
Operator::I32x4RelaxedTruncF32x4S => unop(ctx, UnaryOp::I32x4RelaxedTruncF32x4S),
Operator::I32x4RelaxedTruncF32x4U => unop(ctx, UnaryOp::I32x4RelaxedTruncF32x4U),
Operator::I32x4RelaxedTruncF64x2SZero => unop(ctx, UnaryOp::I32x4RelaxedTruncF64x2SZero),
Operator::I32x4RelaxedTruncF64x2UZero => unop(ctx, UnaryOp::I32x4RelaxedTruncF64x2UZero),
Operator::F32x4RelaxedMadd => ternop(ctx, TernaryOp::F32x4RelaxedMadd),
Operator::F32x4RelaxedNmadd => ternop(ctx, TernaryOp::F32x4RelaxedNmadd),
Operator::F64x2RelaxedMadd => ternop(ctx, TernaryOp::F64x2RelaxedMadd),
Operator::F64x2RelaxedNmadd => ternop(ctx, TernaryOp::F64x2RelaxedNmadd),
Operator::I8x16RelaxedLaneselect => ternop(ctx, TernaryOp::I8x16RelaxedLaneselect),
Operator::I16x8RelaxedLaneselect => ternop(ctx, TernaryOp::I16x8RelaxedLaneselect),
Operator::I32x4RelaxedLaneselect => ternop(ctx, TernaryOp::I32x4RelaxedLaneselect),
Operator::I64x2RelaxedLaneselect => ternop(ctx, TernaryOp::I64x2RelaxedLaneselect),
Operator::F32x4RelaxedMin => binop(ctx, BinaryOp::F32x4RelaxedMin),
Operator::F32x4RelaxedMax => binop(ctx, BinaryOp::F32x4RelaxedMax),
Operator::F64x2RelaxedMin => binop(ctx, BinaryOp::F64x2RelaxedMin),
Operator::F64x2RelaxedMax => binop(ctx, BinaryOp::F64x2RelaxedMax),
Operator::I16x8RelaxedQ15mulrS => binop(ctx, BinaryOp::I16x8RelaxedQ15mulrS),
Operator::I16x8RelaxedDotI8x16I7x16S => binop(ctx, BinaryOp::I16x8RelaxedDotI8x16I7x16S),
Operator::I32x4RelaxedDotI8x16I7x16AddS => {
ternop(ctx, TernaryOp::I32x4RelaxedDotI8x16I7x16AddS)
}

// List all unimplmented operators instead of have a catch-all arm.
// So that future upgrades won't miss additions to this list that may be important to know.
Operator::TryTable { try_table: _ }
Expand Down Expand Up @@ -1465,26 +1491,6 @@ fn append_instruction(ctx: &mut ValidationContext, inst: Operator, loc: InstrLoc
ordering: _,
global_index: _,
}
| Operator::I8x16RelaxedSwizzle
| Operator::I32x4RelaxedTruncF32x4S
| Operator::I32x4RelaxedTruncF32x4U
| Operator::I32x4RelaxedTruncF64x2SZero
| Operator::I32x4RelaxedTruncF64x2UZero
| Operator::F32x4RelaxedMadd
| Operator::F32x4RelaxedNmadd
| Operator::F64x2RelaxedMadd
| Operator::F64x2RelaxedNmadd
| Operator::I8x16RelaxedLaneselect
| Operator::I16x8RelaxedLaneselect
| Operator::I32x4RelaxedLaneselect
| Operator::I64x2RelaxedLaneselect
| Operator::F32x4RelaxedMin
| Operator::F32x4RelaxedMax
| Operator::F64x2RelaxedMin
| Operator::F64x2RelaxedMax
| Operator::I16x8RelaxedQ15mulrS
| Operator::I16x8RelaxedDotI8x16I7x16S
| Operator::I32x4RelaxedDotI8x16I7x16AddS
| Operator::CallRef { type_index: _ }
| Operator::ReturnCallRef { type_index: _ }
| Operator::RefAsNonNull
Expand Down