Implement the relaxed SIMD proposal (#5892)
* Initial support for the Relaxed SIMD proposal This commit adds initial scaffolding and support for the Relaxed SIMD proposal for WebAssembly. Codegen support is supported on the x64 and AArch64 backends on this time. The purpose of this commit is to get all the boilerplate out of the way in terms of plumbing through a new feature, adding tests, etc. The tests are copied from the upstream repository at this time while the WebAssembly/testsuite repository hasn't been updated. A summary of changes made in this commit are: * Lowerings for all relaxed simd opcodes have been added, currently all exhibiting deterministic behavior. This means that few lowerings are optimal on the x86 backend, but on the AArch64 backend, for example, all lowerings should be optimal. * Support is added to codegen to, eventually, conditionally generate different code based on input codegen flags. This is intended to enable codegen to more efficient instructions on x86 by default, for example, while still allowing embedders to force architecture-independent semantics and behavior. One good example of this is the `f32x4.relaxed_fmadd` instruction which when deterministic forces the `fma` instruction, but otherwise if the backend doesn't have support for `fma` then intermediate operations are performed instead. * Lowerings of `iadd_pairwise` for `i16x8` and `i32x4` were added to the x86 backend as they're now exercised by the deterministic lowerings of relaxed simd instructions. * Sample codegen tests for added for x86 and aarch64 for some relaxed simd instructions. * Wasmtime embedder support for the relaxed-simd proposal and forcing determinism have been added to `Config` and the CLI. * Support has been added to the `*.wast` runtime execution for the `(either ...)` matcher used in the relaxed-simd proposal. * Tests for relaxed-simd are run both with a default `Engine` as well as a "force deterministic" `Engine` to test both configurations. * All tests from the upstream repository were copied into Wasmtime. These tests should be deleted when WebAssembly/testsuite is updated. * x64: Add x86-specific lowerings for relaxed simd This commit builds on the prior commit and adds an array of `x86_*` instructions to Cranelift which have semantics that match their corresponding x86 equivalents. Translation for relaxed simd is then additionally updated to conditionally generate different CLIF for relaxed simd instructions depending on whether the target is x86 or not. This means that for AArch64 no changes are made but for x86 most relaxed instructions now lower to some x86-equivalent with slightly different semantics than the "deterministic" lowering. * Add libcall support for fma to Wasmtime This will be required to implement the `f32x4.relaxed_madd` instruction (and others) when an x86 host doesn't specify the `has_fma` feature. * Ignore relaxed-simd tests on s390x and riscv64 * Enable relaxed-simd tests on s390x * Update cranelift/codegen/meta/src/shared/instructions.rs Co-authored-by: Andrew Brown <andrew.brown@intel.com> * Add a FIXME from review * Add notes about deterministic semantics * Don't default `has_native_fma` to `true` * Review comments and rebase fixes --------- Co-authored-by: Andrew Brown <andrew.brown@intel.com>
This commit is contained in:
@@ -35,6 +35,10 @@ pub const SUPPORTED_WASM_FEATURES: &[(&str, &str)] = &[
|
||||
("multi-value", "enables support for multi-value functions"),
|
||||
("reference-types", "enables support for reference types"),
|
||||
("simd", "enables support for proposed SIMD instructions"),
|
||||
(
|
||||
"relaxed-simd",
|
||||
"enables support for the relaxed simd proposal",
|
||||
),
|
||||
("threads", "enables support for WebAssembly threads"),
|
||||
("memory64", "enables support for 64-bit memories"),
|
||||
#[cfg(feature = "component-model")]
|
||||
@@ -235,6 +239,17 @@ pub struct CommonOptions {
|
||||
/// stack overflow is reported.
|
||||
#[clap(long)]
|
||||
pub max_wasm_stack: Option<usize>,
|
||||
|
||||
/// Whether or not to force deterministic and host-independent behavior of
|
||||
/// the relaxed-simd instructions.
|
||||
///
|
||||
/// By default these instructions may have architecture-specific behavior as
|
||||
/// allowed by the specification, but this can be used to force the behavior
|
||||
/// of these instructions to match the deterministic behavior classified in
|
||||
/// the specification. Note that enabling this option may come at a
|
||||
/// performance cost.
|
||||
#[clap(long)]
|
||||
pub relaxed_simd_deterministic: bool,
|
||||
}
|
||||
|
||||
impl CommonOptions {
|
||||
@@ -329,12 +344,15 @@ impl CommonOptions {
|
||||
config.max_wasm_stack(max);
|
||||
}
|
||||
|
||||
config.relaxed_simd_deterministic(self.relaxed_simd_deterministic);
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
pub fn enable_wasm_features(&self, config: &mut Config) {
|
||||
let WasmFeatures {
|
||||
simd,
|
||||
relaxed_simd,
|
||||
bulk_memory,
|
||||
reference_types,
|
||||
multi_value,
|
||||
@@ -348,6 +366,9 @@ impl CommonOptions {
|
||||
if let Some(enable) = simd {
|
||||
config.wasm_simd(enable);
|
||||
}
|
||||
if let Some(enable) = relaxed_simd {
|
||||
config.wasm_relaxed_simd(enable);
|
||||
}
|
||||
if let Some(enable) = bulk_memory {
|
||||
config.wasm_bulk_memory(enable);
|
||||
}
|
||||
@@ -400,6 +421,7 @@ pub struct WasmFeatures {
|
||||
pub multi_value: Option<bool>,
|
||||
pub bulk_memory: Option<bool>,
|
||||
pub simd: Option<bool>,
|
||||
pub relaxed_simd: Option<bool>,
|
||||
pub threads: Option<bool>,
|
||||
pub multi_memory: Option<bool>,
|
||||
pub memory64: Option<bool>,
|
||||
@@ -450,6 +472,7 @@ fn parse_wasm_features(features: &str) -> Result<WasmFeatures> {
|
||||
multi_value: all.or(values["multi-value"]),
|
||||
bulk_memory: all.or(values["bulk-memory"]),
|
||||
simd: all.or(values["simd"]),
|
||||
relaxed_simd: all.or(values["relaxed-simd"]),
|
||||
threads: all.or(values["threads"]),
|
||||
multi_memory: all.or(values["multi-memory"]),
|
||||
memory64: all.or(values["memory64"]),
|
||||
@@ -560,6 +583,7 @@ mod test {
|
||||
multi_value,
|
||||
bulk_memory,
|
||||
simd,
|
||||
relaxed_simd,
|
||||
threads,
|
||||
multi_memory,
|
||||
memory64,
|
||||
@@ -572,6 +596,7 @@ mod test {
|
||||
assert_eq!(threads, Some(true));
|
||||
assert_eq!(multi_memory, Some(true));
|
||||
assert_eq!(memory64, Some(true));
|
||||
assert_eq!(relaxed_simd, Some(true));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -585,6 +610,7 @@ mod test {
|
||||
multi_value,
|
||||
bulk_memory,
|
||||
simd,
|
||||
relaxed_simd,
|
||||
threads,
|
||||
multi_memory,
|
||||
memory64,
|
||||
@@ -597,6 +623,7 @@ mod test {
|
||||
assert_eq!(threads, Some(false));
|
||||
assert_eq!(multi_memory, Some(false));
|
||||
assert_eq!(memory64, Some(false));
|
||||
assert_eq!(relaxed_simd, Some(false));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -613,6 +640,7 @@ mod test {
|
||||
multi_value,
|
||||
bulk_memory,
|
||||
simd,
|
||||
relaxed_simd,
|
||||
threads,
|
||||
multi_memory,
|
||||
memory64,
|
||||
@@ -625,6 +653,7 @@ mod test {
|
||||
assert_eq!(threads, None);
|
||||
assert_eq!(multi_memory, Some(true));
|
||||
assert_eq!(memory64, Some(true));
|
||||
assert_eq!(relaxed_simd, None);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -662,6 +691,7 @@ mod test {
|
||||
feature_test!(test_multi_value_feature, multi_value, "multi-value");
|
||||
feature_test!(test_bulk_memory_feature, bulk_memory, "bulk-memory");
|
||||
feature_test!(test_simd_feature, simd, "simd");
|
||||
feature_test!(test_relaxed_simd_feature, relaxed_simd, "relaxed-simd");
|
||||
feature_test!(test_threads_feature, threads, "threads");
|
||||
feature_test!(test_multi_memory_feature, multi_memory, "multi-memory");
|
||||
feature_test!(test_memory64_feature, memory64, "memory64");
|
||||
|
||||
Reference in New Issue
Block a user