diff options
author | Ng Zhi An <zhin@chromium.org> | 2021-09-23 12:38:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-23 12:38:06 -0700 |
commit | 31252873463fd142a1eabb71b965da04a23a00e2 (patch) | |
tree | 0fe663c3e5ec0d95a0148e888837b50790e6ac29 | |
parent | 675295888609a688ee81dc9ad2024169da5aa7ed (diff) | |
download | binaryen-31252873463fd142a1eabb71b965da04a23a00e2.tar.gz binaryen-31252873463fd142a1eabb71b965da04a23a00e2.tar.bz2 binaryen-31252873463fd142a1eabb71b965da04a23a00e2.zip |
Add feature flag for relaxed-simd (#4183)
-rw-r--r-- | src/binaryen-c.cpp | 3 | ||||
-rw-r--r-- | src/binaryen-c.h | 1 | ||||
-rw-r--r-- | src/js/binaryen.js-post.js | 1 | ||||
-rw-r--r-- | src/tools/tool-options.h | 1 | ||||
-rw-r--r-- | src/wasm-binary.h | 1 | ||||
-rw-r--r-- | src/wasm-features.h | 7 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 1 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js | 1 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js.txt | 3 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 2 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 3 | ||||
-rw-r--r-- | test/lit/help/optimization-opts.test | 4 | ||||
-rw-r--r-- | test/lit/help/wasm-reduce.test | 4 | ||||
-rw-r--r-- | test/passes/strip-target-features_roundtrip_print-features_all-features.txt | 1 | ||||
-rw-r--r-- | test/unit/test_features.py | 1 |
16 files changed, 35 insertions, 3 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 68b0f86c2..72598d0dc 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -249,6 +249,9 @@ BinaryenFeatures BinaryenFeatureMemory64(void) { BinaryenFeatures BinaryenFeatureTypedFunctionReferences(void) { return static_cast<BinaryenFeatures>(FeatureSet::TypedFunctionReferences); } +BinaryenFeatures BinaryenFeatureRelaxedSIMD(void) { + return static_cast<BinaryenFeatures>(FeatureSet::RelaxedSIMD); +} BinaryenFeatures BinaryenFeatureAll(void) { return static_cast<BinaryenFeatures>(FeatureSet::All); } diff --git a/src/binaryen-c.h b/src/binaryen-c.h index b2c4351b1..f9c8719dd 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -161,6 +161,7 @@ BINARYEN_API BinaryenFeatures BinaryenFeatureMultivalue(void); BINARYEN_API BinaryenFeatures BinaryenFeatureGC(void); BINARYEN_API BinaryenFeatures BinaryenFeatureMemory64(void); BINARYEN_API BinaryenFeatures BinaryenFeatureTypedFunctionReferences(void); +BINARYEN_API BinaryenFeatures BinaryenFeatureRelaxedSIMD(void); BINARYEN_API BinaryenFeatures BinaryenFeatureAll(void); // Modules diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 94f2d446c..4c5f5ed3b 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -144,6 +144,7 @@ function initializeConstants() { 'GC', 'Memory64', 'TypedFunctionReferences', + 'RelaxedSIMD', 'All' ].forEach(name => { Module['Features'][name] = Module['_BinaryenFeature' + name](); diff --git a/src/tools/tool-options.h b/src/tools/tool-options.h index 0c40721d3..4b589b5b2 100644 --- a/src/tools/tool-options.h +++ b/src/tools/tool-options.h @@ -85,6 +85,7 @@ struct ToolOptions : public Options { .addFeature(FeatureSet::TypedFunctionReferences, "typed function references") .addFeature(FeatureSet::GCNNLocals, "GC non-null locals") + .addFeature(FeatureSet::RelaxedSIMD, "relaxed SIMD") .add("--no-validation", "-n", "Disables validation, assumes inputs are correct", diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 057a2a981..aea9e56d8 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -422,6 +422,7 @@ extern const char* MultivalueFeature; extern const char* GCFeature; extern const char* Memory64Feature; extern const char* TypedFunctionReferencesFeature; +extern const char* RelaxedSIMDFeature; enum Subsection { NameModule = 0, diff --git a/src/wasm-features.h b/src/wasm-features.h index e28dcf4d1..7311aadd3 100644 --- a/src/wasm-features.h +++ b/src/wasm-features.h @@ -41,7 +41,8 @@ struct FeatureSet { TypedFunctionReferences = 1 << 12, // TODO: Remove this feature when the wasm spec stabilizes. GCNNLocals = 1 << 13, - All = (1 << 14) - 1 + RelaxedSIMD = 1 << 14, + All = (1 << 15) - 1 }; static std::string toString(Feature f) { @@ -74,6 +75,8 @@ struct FeatureSet { return "typed-function-references"; case GCNNLocals: return "gc-nn-locals"; + case RelaxedSIMD: + return "relaxed-simd"; default: WASM_UNREACHABLE("unexpected feature"); } @@ -118,6 +121,7 @@ struct FeatureSet { return (features & TypedFunctionReferences) != 0; } bool hasGCNNLocals() const { return (features & GCNNLocals) != 0; } + bool hasRelaxedSIMD() const { return (features & RelaxedSIMD) != 0; } bool hasAll() const { return (features & All) != 0; } void set(FeatureSet f, bool v = true) { @@ -139,6 +143,7 @@ struct FeatureSet { set(TypedFunctionReferences, v); } void setGCNNLocals(bool v = true) { set(GCNNLocals, v); } + void setRelaxedSIMD(bool v = true) { set(RelaxedSIMD, v); } void setMVP() { features = MVP; } void setAll() { // Do not set GCNNLocals, which forces the user to opt in to that feature diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 74895c868..cd1cfaa0f 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1048,6 +1048,8 @@ void WasmBinaryWriter::writeFeaturesSection() { return BinaryConsts::UserSections::Memory64Feature; case FeatureSet::TypedFunctionReferences: return BinaryConsts::UserSections::TypedFunctionReferencesFeature; + case FeatureSet::RelaxedSIMD: + return BinaryConsts::UserSections::RelaxedSIMDFeature; default: WASM_UNREACHABLE("unexpected feature flag"); } @@ -3263,6 +3265,8 @@ void WasmBinaryBuilder::readFeatures(size_t payloadLen) { } else if (name == BinaryConsts::UserSections::TypedFunctionReferencesFeature) { feature = FeatureSet::TypedFunctionReferences; + } else if (name == BinaryConsts::UserSections::RelaxedSIMDFeature) { + feature = FeatureSet::RelaxedSIMD; } else { // Silently ignore unknown features (this may be and old binaryen running // on a new wasm). diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 792e43cbe..8565bfaa5 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -48,6 +48,7 @@ const char* MultivalueFeature = "multivalue"; const char* GCFeature = "gc"; const char* Memory64Feature = "memory64"; const char* TypedFunctionReferencesFeature = "typed-function-references"; +const char* RelaxedSIMDFeature = "relaxed-simd"; } // namespace UserSections } // namespace BinaryConsts diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js index 7a3007cfe..be7363ae5 100644 --- a/test/binaryen.js/kitchen-sink.js +++ b/test/binaryen.js/kitchen-sink.js @@ -115,6 +115,7 @@ function test_features() { console.log("Features.GC: " + binaryen.Features.GC); console.log("Features.Memory64: " + binaryen.Features.Memory64); console.log("Features.TypedFunctionReferences: " + binaryen.Features.TypedFunctionReferences); + console.log("Features.RelaxedSIMD: " + binaryen.Features.RelaxedSIMD); console.log("Features.All: " + binaryen.Features.All); } diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt index 95236a4be..21413d87a 100644 --- a/test/binaryen.js/kitchen-sink.js.txt +++ b/test/binaryen.js/kitchen-sink.js.txt @@ -42,7 +42,8 @@ Features.Multivalue: 512 Features.GC: 1024 Features.Memory64: 2048 Features.TypedFunctionReferences: 4096 -Features.All: 16383 +Features.RelaxedSIMD: 16384 +Features.All: 32767 InvalidId: 0 BlockId: 1 IfId: 2 diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index 633f4f1ff..f493914aa 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -263,6 +263,8 @@ void test_features() { printf("BinaryenFeatureMemory64: %d\n", BinaryenFeatureMemory64()); printf("BinaryenFeatureTypedFunctionReferences: %d\n", BinaryenFeatureTypedFunctionReferences()); + printf("BinaryenFeatureRelaxedSIMD: %d\n", + BinaryenFeatureRelaxedSIMD()); printf("BinaryenFeatureAll: %d\n", BinaryenFeatureAll()); } diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 4855f68b7..3372ba8b6 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -26,7 +26,8 @@ BinaryenFeatureMultivalue: 512 BinaryenFeatureGC: 1024 BinaryenFeatureMemory64: 2048 BinaryenFeatureTypedFunctionReferences: 4096 -BinaryenFeatureAll: 16383 +BinaryenFeatureRelaxedSIMD: 16384 +BinaryenFeatureAll: 32767 (f32.neg (f32.const -33.61199951171875) ) diff --git a/test/lit/help/optimization-opts.test b/test/lit/help/optimization-opts.test index 177a1b620..75e1d72a3 100644 --- a/test/lit/help/optimization-opts.test +++ b/test/lit/help/optimization-opts.test @@ -87,6 +87,10 @@ ;; CHECK-NEXT: ;; CHECK-NEXT: --disable-gc-nn-locals Disable GC non-null locals ;; CHECK-NEXT: +;; CHECK-NEXT: --enable-relaxed-simd Enable relaxed SIMD +;; CHECK-NEXT: +;; CHECK-NEXT: --disable-relaxed-simd Disable relaxed SIMD +;; CHECK-NEXT: ;; CHECK-NEXT: --no-validation,-n Disables validation, assumes ;; CHECK-NEXT: inputs are correct ;; CHECK-NEXT: diff --git a/test/lit/help/wasm-reduce.test b/test/lit/help/wasm-reduce.test index a75eeae9d..3d6894d89 100644 --- a/test/lit/help/wasm-reduce.test +++ b/test/lit/help/wasm-reduce.test @@ -83,6 +83,10 @@ ;; CHECK-NEXT: ;; CHECK-NEXT: --disable-gc-nn-locals Disable GC non-null locals ;; CHECK-NEXT: +;; CHECK-NEXT: --enable-relaxed-simd Enable relaxed SIMD +;; CHECK-NEXT: +;; CHECK-NEXT: --disable-relaxed-simd Disable relaxed SIMD +;; CHECK-NEXT: ;; CHECK-NEXT: --no-validation,-n Disables validation, assumes inputs are ;; CHECK-NEXT: correct ;; CHECK-NEXT: diff --git a/test/passes/strip-target-features_roundtrip_print-features_all-features.txt b/test/passes/strip-target-features_roundtrip_print-features_all-features.txt index 96cb9b785..5feeecc20 100644 --- a/test/passes/strip-target-features_roundtrip_print-features_all-features.txt +++ b/test/passes/strip-target-features_roundtrip_print-features_all-features.txt @@ -11,6 +11,7 @@ --enable-gc --enable-memory64 --enable-typed-function-references +--enable-relaxed-simd (module (type $none_=>_v128_externref (func (result v128 externref))) (func $foo (result v128 externref) diff --git a/test/unit/test_features.py b/test/unit/test_features.py index 79e6d4de0..93f715ef9 100644 --- a/test/unit/test_features.py +++ b/test/unit/test_features.py @@ -396,4 +396,5 @@ class TargetFeaturesSectionTest(utils.BinaryenTestCase): '--enable-gc', '--enable-memory64', '--enable-typed-function-references', + '--enable-relaxed-simd', ], p2.stdout.splitlines()) |