Bug 1856126 [wpt PR 42137] - LoAF: ensure scripts are added after microtask checkpoin...
[gecko.git] / js / public / WasmFeatures.h
blob86282717ef739734e41c8d82b52b0c6e2886ed48
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef js_WasmFeatures_h
8 #define js_WasmFeatures_h
10 // [SMDOC] WebAssembly feature gating
12 // Declarative listing of WebAssembly optional features. This macro is used to
13 // generate most of the feature gating code in a centralized manner. See
14 // 'Adding a feature' below for the exact steps needed to add a new feature.
16 // Each feature is either `DEFAULT`, `TENTATIVE`, or `EXPERIMENTAL`:
18 // Default features are enabled by default in ContextOptions and in the
19 // JS-shell, and are given a `--no-wasm-FEATURE` shell flag to disable. The
20 // `--wasm-FEATURE` flag is rejected.
22 // Tentative features are like Default features, but the `--wasm-FEATURE` flag
23 // is silently ignored.
25 // Experimental features are disabled by default in ContextOptions and in the
26 // JS-shell, and are given a `--wasm-FEATURE` shell flag to enable. The
27 // `--no-wasm-FEATURE` flag is silently ignored.
29 // The browser pref is `javascript.options.wasm-FEATURE` for default, tentative,
30 // and experimental features alike.
32 // # Adding a feature
34 // 1. Add a configure switch for the feature in js/moz.configure
35 // 2. Add a WASM_FEATURE_ENABLED #define below
36 // 3. Add the feature to JS_FOR_WASM_FEATURES
37 // a. capitalized name: Used for naming of feature functions, including
38 // wasmFeatureEnabled shell function.
39 // b. lower case name: Used for naming of feature flag variables, including
40 // in wasm::FeatureArgs.
41 // c. compile predicate: Set to WASM_FEATURE_ENABLED
42 // d. compiler predicate: Expression of compilers that this feature depends
43 // on.
44 // e. flag predicate: Expression used to predicate enablement of feature
45 // flag. Useful for disabling a feature when dependent feature is not
46 // enabled or if we are fuzzing.
47 // f. shell flag: The stem of the JS-shell flag. Will be expanded to
48 // --no-wasm-FEATURE or --wasm-FEATURE as explained above.
49 // g. preference name: The stem of the browser preference. Will be expanded
50 // to `javascript.options.wasm-FEATURE`.
51 // 4. Add the preference to module/libpref/init/StaticPrefList.yaml
52 // a. Use conditionally compiled flag
53 // b. Set value to 'true' for default features, @IS_NIGHTLY_BUILD@ for
54 // tentative features, and 'false' for experimental features.
55 // 5. [fuzzing] Add the feature to gluesmith/src/lib.rs, if wasm-smith has
56 // support for it.
58 #ifdef ENABLE_WASM_RELAXED_SIMD
59 # define WASM_RELAXED_SIMD_ENABLED 1
60 #else
61 # define WASM_RELAXED_SIMD_ENABLED 0
62 #endif
63 #ifdef ENABLE_WASM_EXTENDED_CONST
64 # define WASM_EXTENDED_CONST_ENABLED 1
65 #else
66 # define WASM_EXTENDED_CONST_ENABLED 0
67 #endif
68 #ifdef ENABLE_WASM_FUNCTION_REFERENCES
69 # define WASM_FUNCTION_REFERENCES_ENABLED 1
70 #else
71 # define WASM_FUNCTION_REFERENCES_ENABLED 0
72 #endif
73 #ifdef ENABLE_WASM_GC
74 # define WASM_GC_ENABLED 1
75 #else
76 # define WASM_GC_ENABLED 0
77 #endif
78 #ifdef ENABLE_WASM_MEMORY64
79 # define WASM_MEMORY64_ENABLED 1
80 #else
81 # define WASM_MEMORY64_ENABLED 0
82 #endif
83 #ifdef ENABLE_WASM_MEMORY_CONTROL
84 # define WASM_MEMORY_CONTROL_ENABLED 1
85 #else
86 # define WASM_MEMORY_CONTROL_ENABLED 0
87 #endif
88 #ifdef ENABLE_WASM_TAIL_CALLS
89 # define WASM_TAIL_CALLS_ENABLED 1
90 #else
91 # define WASM_TAIL_CALLS_ENABLED 0
92 #endif
93 #ifdef ENABLE_WASM_MOZ_INTGEMM
94 # define WASM_MOZ_INTGEMM_ENABLED 1
95 #else
96 # define WASM_MOZ_INTGEMM_ENABLED 0
97 #endif
98 #ifdef ENABLE_WASM_MULTI_MEMORY
99 # define WASM_MULTI_MEMORY_ENABLED 1
100 #else
101 # define WASM_MULTI_MEMORY_ENABLED 0
102 #endif
104 enum class WasmFeatureStage {
105 Experimental = 0,
106 Tentative,
107 Default,
110 // clang-format off
111 #define JS_FOR_WASM_FEATURES(FEATURE) \
112 FEATURE( \
113 /* capitalized name */ ExtendedConst, \
114 /* lower case name */ extendedConst, \
115 /* stage */ WasmFeatureStage::Tentative, \
116 /* compile predicate */ WASM_EXTENDED_CONST_ENABLED, \
117 /* compiler predicate */ true, \
118 /* flag predicate */ true, \
119 /* flag force enable */ false, \
120 /* flag fuzz enable */ true, \
121 /* shell flag */ "extended-const", \
122 /* preference name */ "extended_const") \
123 FEATURE( \
124 /* capitalized name */ Exceptions, \
125 /* lower case name */ exceptions, \
126 /* stage */ WasmFeatureStage::Default, \
127 /* compile predicate */ true, \
128 /* compiler predicate */ AnyCompilerAvailable(cx), \
129 /* flag predicate */ true, \
130 /* flag force enable */ false, \
131 /* flag fuzz enable */ true, \
132 /* shell flag */ "exceptions", \
133 /* preference name */ "exceptions") \
134 FEATURE( \
135 /* capitalized name */ FunctionReferences, \
136 /* lower case name */ functionReferences, \
137 /* stage */ WasmFeatureStage::Tentative, \
138 /* compile predicate */ WASM_FUNCTION_REFERENCES_ENABLED, \
139 /* compiler predicate */ AnyCompilerAvailable(cx), \
140 /* flag predicate */ true, \
141 /* flag force enable */ WasmGcFlag(cx), \
142 /* flag fuzz enable */ false, \
143 /* shell flag */ "function-references", \
144 /* preference name */ "function_references") \
145 FEATURE( \
146 /* capitalized name */ Gc, \
147 /* lower case name */ gc, \
148 /* stage */ WasmFeatureStage::Tentative, \
149 /* compile predicate */ WASM_GC_ENABLED, \
150 /* compiler predicate */ AnyCompilerAvailable(cx), \
151 /* flag predicate */ true, \
152 /* flag force enable */ false, \
153 /* flag fuzz enable */ false, \
154 /* shell flag */ "gc", \
155 /* preference name */ "gc") \
156 FEATURE( \
157 /* capitalized name */ RelaxedSimd, \
158 /* lower case name */ v128Relaxed, \
159 /* stage */ WasmFeatureStage::Tentative, \
160 /* compile predicate */ WASM_RELAXED_SIMD_ENABLED, \
161 /* compiler predicate */ AnyCompilerAvailable(cx), \
162 /* flag predicate */ js::jit::JitSupportsWasmSimd(), \
163 /* flag force enable */ false, \
164 /* flag fuzz enable */ true, \
165 /* shell flag */ "relaxed-simd", \
166 /* preference name */ "relaxed_simd") \
167 FEATURE( \
168 /* capitalized name */ Memory64, \
169 /* lower case name */ memory64, \
170 /* stage */ WasmFeatureStage::Tentative, \
171 /* compile predicate */ WASM_MEMORY64_ENABLED, \
172 /* compiler predicate */ AnyCompilerAvailable(cx), \
173 /* flag predicate */ true, \
174 /* flag force enable */ false, \
175 /* flag fuzz enable */ true, \
176 /* shell flag */ "memory64", \
177 /* preference name */ "memory64") \
178 FEATURE( \
179 /* capitalized name */ MemoryControl, \
180 /* lower case name */ memoryControl, \
181 /* stage */ WasmFeatureStage::Experimental, \
182 /* compile predicate */ WASM_MEMORY_CONTROL_ENABLED, \
183 /* compiler predicate */ AnyCompilerAvailable(cx), \
184 /* flag predicate */ true, \
185 /* flag force enable */ false, \
186 /* flag fuzz enable */ false, \
187 /* shell flag */ "memory-control", \
188 /* preference name */ "memory_control") \
189 FEATURE( \
190 /* capitalized name */ MultiMemory, \
191 /* lower case name */ multiMemory, \
192 /* stage */ WasmFeatureStage::Experimental, \
193 /* compile predicate */ WASM_MULTI_MEMORY_ENABLED, \
194 /* compiler predicate */ AnyCompilerAvailable(cx), \
195 /* flag predicate */ true, \
196 /* flag force enable */ false, \
197 /* flag fuzz enable */ false, \
198 /* shell flag */ "multi-memory", \
199 /* preference name */ "multi_memory") \
200 FEATURE( \
201 /* capitalized name */ TailCalls, \
202 /* lower case name */ tailCalls, \
203 /* stage */ WasmFeatureStage::Experimental, \
204 /* compile predicate */ WASM_TAIL_CALLS_ENABLED, \
205 /* compiler predicate */ AnyCompilerAvailable(cx), \
206 /* flag predicate */ true, \
207 /* flag force enable */ false, \
208 /* flag fuzz enable */ true, \
209 /* shell flag */ "tail-calls", \
210 /* preference name */ "tail_calls") \
211 FEATURE( \
212 /* capitalized name */ MozIntGemm, \
213 /* lower case name */ mozIntGemm, \
214 /* stage */ WasmFeatureStage::Experimental, \
215 /* compile predicate */ WASM_MOZ_INTGEMM_ENABLED, \
216 /* compiler predicate */ AnyCompilerAvailable(cx), \
217 /* flag predicate */ IsSimdPrivilegedContext(cx), \
218 /* flag force enable */ false, \
219 /* flag fuzz enable */ false, \
220 /* shell flag */ "moz-intgemm", \
221 /* preference name */ "moz_intgemm") \
222 FEATURE( \
223 /* capitalized name */ TestSerialization, \
224 /* lower case name */ testSerialization, \
225 /* stage */ WasmFeatureStage::Experimental, \
226 /* compile predicate */ 1, \
227 /* compiler predicate */ IonAvailable(cx), \
228 /* flag predicate */ true, \
229 /* flag force enable */ false, \
230 /* flag fuzz enable */ false, \
231 /* shell flag */ "test-serialization", \
232 /* preference name */ "test-serialization") \
233 FEATURE( \
234 /* capitalized name */ TestMetadata, \
235 /* lower case name */ testMetadata, \
236 /* stage */ WasmFeatureStage::Experimental, \
237 /* compile predicate */ 1, \
238 /* compiler predicate */ AnyCompilerAvailable(cx), \
239 /* flag predicate */ true, \
240 /* flag force enable */ false, \
241 /* flag fuzz enable */ false, \
242 /* shell flag */ "test-metadata", \
243 /* preference name */ "test_metadata")
245 // clang-format on
247 #endif // js_WasmFeatures_h