Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ BinaryenFeatures BinaryenFeatureMultibyte(void) {
BinaryenFeatures BinaryenFeatureCustomPageSizes(void) {
return static_cast<BinaryenFeatures>(FeatureSet::CustomPageSizes);
}
BinaryenFeatures BinaryenFeatureWideArithmetic(void) {
return static_cast<BinaryenFeatures>(FeatureSet::WideArithmetic);
}
BinaryenFeatures BinaryenFeatureAll(void) {
return static_cast<BinaryenFeatures>(FeatureSet::All);
}
Expand Down
1 change: 1 addition & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ BINARYEN_API BinaryenFeatures BinaryenFeatureCallIndirectOverlong(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureRelaxedAtomics(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureMultibyte(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureCustomPageSizes(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureWideArithmetic(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureAll(void);

// Modules
Expand Down
1 change: 1 addition & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ function initializeConstants() {
'CallIndirectOverlong',
'RelaxedAtomics',
'CustomPageSizes',
'WideArithmetic',
'All'
].forEach(name => {
Module['Features'][name] = Module['_BinaryenFeature' + name]();
Expand Down
1 change: 1 addition & 0 deletions src/tools/tool-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct ToolOptions : public Options {
.addFeature(FeatureSet::RelaxedAtomics,
"acquire/release atomic memory operations")
.addFeature(FeatureSet::CustomPageSizes, "custom page sizes")
.addFeature(FeatureSet::WideArithmetic, "wide arithmetic")
.add("--enable-typed-function-references",
"",
"Deprecated compatibility flag",
Expand Down
1 change: 1 addition & 0 deletions src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ extern const char* CustomDescriptorsFeature;
extern const char* RelaxedAtomicsFeature;
extern const char* MultibyteFeature;
extern const char* CustomPageSizesFeature;
extern const char* WideArithmeticFeature;

enum Subsection {
NameModule = 0,
Expand Down
7 changes: 6 additions & 1 deletion src/wasm-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ struct FeatureSet {
RelaxedAtomics = 1 << 22,
CustomPageSizes = 1 << 23,
Multibyte = 1 << 24,
WideArithmetic = 1 << 25,
MVP = None,
// Keep in sync with llvm default features:
// https://github.com/llvm/llvm-project/blob/c7576cb89d6c95f03968076e902d3adfd1996577/clang/lib/Basic/Targets/WebAssembly.cpp#L150-L153
Default = SignExt | MutableGlobals,
All = (1 << 25) - 1,
All = (1 << 26) - 1,
};

static std::string toString(Feature f) {
Expand Down Expand Up @@ -117,6 +118,8 @@ struct FeatureSet {
return "custom-page-sizes";
case Multibyte:
return "multibyte";
case WideArithmetic:
return "wide-arithmetic";
case MVP:
case Default:
case All:
Expand Down Expand Up @@ -180,6 +183,7 @@ struct FeatureSet {
bool hasRelaxedAtomics() const { return (features & RelaxedAtomics) != 0; }
bool hasCustomPageSizes() const { return (features & CustomPageSizes) != 0; }
bool hasMultibyte() const { return (features & Multibyte) != 0; }
bool hasWideArithmetic() const { return (features & WideArithmetic) != 0; }
bool hasAll() const { return (features & All) != 0; }

void set(FeatureSet f, bool v = true) {
Expand Down Expand Up @@ -208,6 +212,7 @@ struct FeatureSet {
void setCustomDescriptors(bool v = true) { set(CustomDescriptors, v); }
void setRelaxedAtomics(bool v = true) { set(RelaxedAtomics, v); }
void setMultibyte(bool v = true) { set(Multibyte, v); }
void setWideArithmetic(bool v = true) { set(WideArithmetic, v); }
void setMVP() { features = MVP; }
void setAll() { features = All; }

Expand Down
4 changes: 4 additions & 0 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,8 @@ void WasmBinaryWriter::writeFeaturesSection() {
return BinaryConsts::CustomSections::RelaxedAtomicsFeature;
case FeatureSet::CustomPageSizes:
return BinaryConsts::CustomSections::CustomPageSizesFeature;
case FeatureSet::WideArithmetic:
return BinaryConsts::CustomSections::WideArithmeticFeature;
case FeatureSet::None:
case FeatureSet::Default:
case FeatureSet::All:
Expand Down Expand Up @@ -5446,6 +5448,8 @@ void WasmBinaryReader::readFeatures(size_t sectionPos, size_t payloadLen) {
feature = FeatureSet::RelaxedAtomics;
} else if (name == BinaryConsts::CustomSections::CustomPageSizesFeature) {
feature = FeatureSet::CustomPageSizes;
} else if (name == BinaryConsts::CustomSections::WideArithmeticFeature) {
feature = FeatureSet::WideArithmetic;
} else {
// Silently ignore unknown features (this may be and old binaryen running
// on a new wasm).
Expand Down
1 change: 1 addition & 0 deletions src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const char* CustomDescriptorsFeature = "custom-descriptors";
const char* RelaxedAtomicsFeature = "relaxed-atomics";
const char* MultibyteFeature = "multibyte";
const char* CustomPageSizesFeature = "custom-page-sizes";
const char* WideArithmeticFeature = "wide-arithmetic";

} // namespace BinaryConsts::CustomSections

Expand Down
1 change: 1 addition & 0 deletions test/binaryen.js/kitchen-sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function test_features() {
console.log("Features.MultiMemory: " + binaryen.Features.MultiMemory);
console.log("Features.RelaxedAtomics: " + binaryen.Features.RelaxedAtomics);
console.log("Features.CustomPageSizes: " + binaryen.Features.CustomPageSizes);
console.log("Features.WideArithmetic: " + binaryen.Features.WideArithmetic);
console.log("Features.All: " + binaryen.Features.All);
}

Expand Down
3 changes: 2 additions & 1 deletion test/binaryen.js/kitchen-sink.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Features.Strings: 16384
Features.MultiMemory: 32768
Features.RelaxedAtomics: 4194304
Features.CustomPageSizes: 8388608
Features.All: 33554431
Features.WideArithmetic: 33554432
Features.All: 67108863
InvalidId: 0
BlockId: 1
IfId: 2
Expand Down
2 changes: 2 additions & 0 deletions test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ void test_features() {
printf("BinaryenFeatureCustomPageSizes: %d\n",
BinaryenFeatureCustomPageSizes());
printf("BinaryenFeatureMultibyte: %d\n", BinaryenFeatureMultibyte());
printf("BinaryenFeatureWideArithmetic: %d\n",
BinaryenFeatureWideArithmetic());
printf("BinaryenFeatureAll: %d\n", BinaryenFeatureAll());
}

Expand Down
3 changes: 2 additions & 1 deletion test/example/c-api-kitchen-sink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ BinaryenFeatureStrings: 16384
BinaryenFeatureRelaxedAtomics: 4194304
BinaryenFeatureCustomPageSizes: 8388608
BinaryenFeatureMultibyte: 16777216
BinaryenFeatureAll: 33554431
BinaryenFeatureWideArithmetic: 33554432
BinaryenFeatureAll: 67108863
(f32.neg
(f32.const -33.61199951171875)
)
Expand Down
4 changes: 4 additions & 0 deletions test/lit/help/wasm-as.test
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-custom-page-sizes Disable custom page sizes
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-wide-arithmetic Enable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-wide-arithmetic Disable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
4 changes: 4 additions & 0 deletions test/lit/help/wasm-ctor-eval.test
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-custom-page-sizes Disable custom page sizes
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-wide-arithmetic Enable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-wide-arithmetic Disable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
4 changes: 4 additions & 0 deletions test/lit/help/wasm-dis.test
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-custom-page-sizes Disable custom page sizes
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-wide-arithmetic Enable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-wide-arithmetic Disable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
4 changes: 4 additions & 0 deletions test/lit/help/wasm-emscripten-finalize.test
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-custom-page-sizes Disable custom page sizes
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-wide-arithmetic Enable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-wide-arithmetic Disable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
4 changes: 4 additions & 0 deletions test/lit/help/wasm-merge.test
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-custom-page-sizes Disable custom page sizes
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-wide-arithmetic Enable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-wide-arithmetic Disable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
4 changes: 4 additions & 0 deletions test/lit/help/wasm-metadce.test
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-custom-page-sizes Disable custom page sizes
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-wide-arithmetic Enable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-wide-arithmetic Disable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
4 changes: 4 additions & 0 deletions test/lit/help/wasm-opt.test
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-custom-page-sizes Disable custom page sizes
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-wide-arithmetic Enable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-wide-arithmetic Disable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
4 changes: 4 additions & 0 deletions test/lit/help/wasm-reduce.test
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-custom-page-sizes Disable custom page sizes
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-wide-arithmetic Enable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-wide-arithmetic Disable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
4 changes: 4 additions & 0 deletions test/lit/help/wasm-split.test
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-custom-page-sizes Disable custom page sizes
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-wide-arithmetic Enable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-wide-arithmetic Disable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
4 changes: 4 additions & 0 deletions test/lit/help/wasm2js.test
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-custom-page-sizes Disable custom page sizes
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-wide-arithmetic Enable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-wide-arithmetic Disable wide arithmetic
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
--enable-relaxed-atomics
--enable-custom-page-sizes
--enable-multibyte
--enable-wide-arithmetic
(module
(type $0 (func (result v128 externref)))
(func $foo (type $0) (result v128 externref)
Expand Down
1 change: 1 addition & 0 deletions test/unit/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,5 @@ def test_emit_all_features(self):
'--enable-custom-descriptors',
'--enable-relaxed-atomics',
'--enable-custom-page-sizes',
'--enable-wide-arithmetic',
], p2.stdout.splitlines())
Loading