Skip to content

Commit 7f3617c

Browse files
Add feature flag for wide arithmetic
1 parent 2e86518 commit 7f3617c

24 files changed

Lines changed: 68 additions & 4 deletions

src/binaryen-c.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ BinaryenFeatures BinaryenFeatureMultibyte(void) {
508508
BinaryenFeatures BinaryenFeatureCustomPageSizes(void) {
509509
return static_cast<BinaryenFeatures>(FeatureSet::CustomPageSizes);
510510
}
511+
BinaryenFeatures BinaryenFeatureWideArithmetic(void) {
512+
return static_cast<BinaryenFeatures>(FeatureSet::WideArithmetic);
513+
}
511514
BinaryenFeatures BinaryenFeatureAll(void) {
512515
return static_cast<BinaryenFeatures>(FeatureSet::All);
513516
}

src/binaryen-c.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ BINARYEN_API BinaryenFeatures BinaryenFeatureCallIndirectOverlong(void);
246246
BINARYEN_API BinaryenFeatures BinaryenFeatureRelaxedAtomics(void);
247247
BINARYEN_API BinaryenFeatures BinaryenFeatureMultibyte(void);
248248
BINARYEN_API BinaryenFeatures BinaryenFeatureCustomPageSizes(void);
249+
BINARYEN_API BinaryenFeatures BinaryenFeatureWideArithmetic(void);
249250
BINARYEN_API BinaryenFeatures BinaryenFeatureAll(void);
250251

251252
// Modules

src/js/binaryen.js-post.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ function initializeConstants() {
194194
'CallIndirectOverlong',
195195
'RelaxedAtomics',
196196
'CustomPageSizes',
197+
'WideArithmetic',
197198
'All'
198199
].forEach(name => {
199200
Module['Features'][name] = Module['_BinaryenFeature' + name]();

src/tools/tool-options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct ToolOptions : public Options {
112112
.addFeature(FeatureSet::RelaxedAtomics,
113113
"acquire/release atomic memory operations")
114114
.addFeature(FeatureSet::CustomPageSizes, "custom page sizes")
115+
.addFeature(FeatureSet::WideArithmetic, "wide arithmetic")
115116
.add("--enable-typed-function-references",
116117
"",
117118
"Deprecated compatibility flag",

src/wasm-binary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ extern const char* CustomDescriptorsFeature;
474474
extern const char* RelaxedAtomicsFeature;
475475
extern const char* MultibyteFeature;
476476
extern const char* CustomPageSizesFeature;
477+
extern const char* WideArithmeticFeature;
477478

478479
enum Subsection {
479480
NameModule = 0,

src/wasm-features.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ struct FeatureSet {
5858
RelaxedAtomics = 1 << 22,
5959
CustomPageSizes = 1 << 23,
6060
Multibyte = 1 << 24,
61+
WideArithmetic = 1 << 25,
6162
MVP = None,
6263
// Keep in sync with llvm default features:
6364
// https://github.com/llvm/llvm-project/blob/c7576cb89d6c95f03968076e902d3adfd1996577/clang/lib/Basic/Targets/WebAssembly.cpp#L150-L153
6465
Default = SignExt | MutableGlobals,
65-
All = (1 << 25) - 1,
66+
All = (1 << 26) - 1,
6667
};
6768

6869
static std::string toString(Feature f) {
@@ -117,6 +118,8 @@ struct FeatureSet {
117118
return "custom-page-sizes";
118119
case Multibyte:
119120
return "multibyte";
121+
case WideArithmetic:
122+
return "wide-arithmetic";
120123
case MVP:
121124
case Default:
122125
case All:
@@ -180,6 +183,7 @@ struct FeatureSet {
180183
bool hasRelaxedAtomics() const { return (features & RelaxedAtomics) != 0; }
181184
bool hasCustomPageSizes() const { return (features & CustomPageSizes) != 0; }
182185
bool hasMultibyte() const { return (features & Multibyte) != 0; }
186+
bool hasWideArithmetic() const { return (features & WideArithmetic) != 0; }
183187
bool hasAll() const { return (features & All) != 0; }
184188

185189
void set(FeatureSet f, bool v = true) {
@@ -208,6 +212,7 @@ struct FeatureSet {
208212
void setCustomDescriptors(bool v = true) { set(CustomDescriptors, v); }
209213
void setRelaxedAtomics(bool v = true) { set(RelaxedAtomics, v); }
210214
void setMultibyte(bool v = true) { set(Multibyte, v); }
215+
void setWideArithmetic(bool v = true) { set(WideArithmetic, v); }
211216
void setMVP() { features = MVP; }
212217
void setAll() { features = All; }
213218

src/wasm/wasm-binary.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,8 @@ void WasmBinaryWriter::writeFeaturesSection() {
14861486
return BinaryConsts::CustomSections::RelaxedAtomicsFeature;
14871487
case FeatureSet::CustomPageSizes:
14881488
return BinaryConsts::CustomSections::CustomPageSizesFeature;
1489+
case FeatureSet::WideArithmetic:
1490+
return BinaryConsts::CustomSections::WideArithmeticFeature;
14891491
case FeatureSet::None:
14901492
case FeatureSet::Default:
14911493
case FeatureSet::All:
@@ -5446,6 +5448,8 @@ void WasmBinaryReader::readFeatures(size_t sectionPos, size_t payloadLen) {
54465448
feature = FeatureSet::RelaxedAtomics;
54475449
} else if (name == BinaryConsts::CustomSections::CustomPageSizesFeature) {
54485450
feature = FeatureSet::CustomPageSizes;
5451+
} else if (name == BinaryConsts::CustomSections::WideArithmeticFeature) {
5452+
feature = FeatureSet::WideArithmetic;
54495453
} else {
54505454
// Silently ignore unknown features (this may be and old binaryen running
54515455
// on a new wasm).

src/wasm/wasm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const char* CustomDescriptorsFeature = "custom-descriptors";
7979
const char* RelaxedAtomicsFeature = "relaxed-atomics";
8080
const char* MultibyteFeature = "multibyte";
8181
const char* CustomPageSizesFeature = "custom-page-sizes";
82+
const char* WideArithmeticFeature = "wide-arithmetic";
8283

8384
} // namespace BinaryConsts::CustomSections
8485

test/binaryen.js/kitchen-sink.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ function test_features() {
102102
console.log("Features.MultiMemory: " + binaryen.Features.MultiMemory);
103103
console.log("Features.RelaxedAtomics: " + binaryen.Features.RelaxedAtomics);
104104
console.log("Features.CustomPageSizes: " + binaryen.Features.CustomPageSizes);
105+
console.log("Features.WideArithmetic: " + binaryen.Features.WideArithmetic);
105106
console.log("Features.All: " + binaryen.Features.All);
106107
}
107108

test/binaryen.js/kitchen-sink.js.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Features.Strings: 16384
3535
Features.MultiMemory: 32768
3636
Features.RelaxedAtomics: 4194304
3737
Features.CustomPageSizes: 8388608
38-
Features.All: 33554431
38+
Features.WideArithmetic: 33554432
39+
Features.All: 67108863
3940
InvalidId: 0
4041
BlockId: 1
4142
IfId: 2

0 commit comments

Comments
 (0)