1/*
2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26// DO NO EDIT! - This file was generated by /home/dima/wk/webkit/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py
27
28#pragma once
29
30#if ENABLE(WEBASSEMBLY)
31
32#include <cstdint>
33
34namespace JSC { namespace Wasm {
35
36static constexpr unsigned expectedVersionNumber = 1;
37
38static constexpr unsigned numTypes = 7;
39
40#define FOR_EACH_WASM_TYPE(macro) \
41 macro(Anyfunc, -0x10, B3::Void, 0) \
42 macro(I32, -0x1, B3::Int32, 1) \
43 macro(Void, -0x40, B3::Void, 2) \
44 macro(I64, -0x2, B3::Int64, 3) \
45 macro(F32, -0x3, B3::Float, 4) \
46 macro(Func, -0x20, B3::Void, 5) \
47 macro(F64, -0x4, B3::Double, 6)
48#define CREATE_ENUM_VALUE(name, id, b3type, inc) name = id,
49enum Type : int8_t {
50 FOR_EACH_WASM_TYPE(CREATE_ENUM_VALUE)
51};
52#undef CREATE_ENUM_VALUE
53
54#define CREATE_CASE(name, id, b3type, inc) case id: return true;
55template <typename Int>
56inline bool isValidType(Int i)
57{
58 switch (i) {
59 default: return false;
60 FOR_EACH_WASM_TYPE(CREATE_CASE)
61 }
62 RELEASE_ASSERT_NOT_REACHED();
63 return false;
64}
65#undef CREATE_CASE
66
67#define CREATE_CASE(name, id, b3type, inc) case name: return b3type;
68inline B3::Type toB3Type(Type type)
69{
70 switch (type) {
71 FOR_EACH_WASM_TYPE(CREATE_CASE)
72 }
73 RELEASE_ASSERT_NOT_REACHED();
74 return B3::Void;
75}
76#undef CREATE_CASE
77
78#define CREATE_CASE(name, id, b3type, inc) case name: return #name;
79inline const char* makeString(Type type)
80{
81 switch (type) {
82 FOR_EACH_WASM_TYPE(CREATE_CASE)
83 }
84 RELEASE_ASSERT_NOT_REACHED();
85 return nullptr;
86}
87#undef CREATE_CASE
88
89#define CREATE_CASE(name, id, b3type, inc) case id: return inc;
90inline int linearizeType(Type type)
91{
92 switch (type) {
93 FOR_EACH_WASM_TYPE(CREATE_CASE)
94 }
95 RELEASE_ASSERT_NOT_REACHED();
96 return 0;
97}
98#undef CREATE_CASE
99
100#define CREATE_CASE(name, id, b3type, inc) case inc: return name;
101inline Type linearizedToType(int i)
102{
103 switch (i) {
104 FOR_EACH_WASM_TYPE(CREATE_CASE)
105 }
106 RELEASE_ASSERT_NOT_REACHED();
107 return Void;
108}
109#undef CREATE_CASE
110
111
112#define FOR_EACH_WASM_SPECIAL_OP(macro) \
113 macro(F64Const, 0x44, Oops, 0) \
114 macro(GrowMemory, 0x40, Oops, 1) \
115 macro(I64Const, 0x42, Oops, 2) \
116 macro(TeeLocal, 0x22, Oops, 3) \
117 macro(SetLocal, 0x21, Oops, 4) \
118 macro(I32Const, 0x41, Oops, 5) \
119 macro(CurrentMemory, 0x3f, Oops, 6) \
120 macro(F32Const, 0x43, Oops, 7) \
121 macro(SetGlobal, 0x24, Oops, 8) \
122 macro(GetGlobal, 0x23, Oops, 9) \
123 macro(Call, 0x10, Oops, 10) \
124 macro(GetLocal, 0x20, Oops, 11) \
125 macro(CallIndirect, 0x11, Oops, 12)
126
127#define FOR_EACH_WASM_CONTROL_FLOW_OP(macro) \
128 macro(Return, 0xf, Oops, 0) \
129 macro(Nop, 0x1, Oops, 1) \
130 macro(Drop, 0x1a, Oops, 2) \
131 macro(BrIf, 0xd, Oops, 3) \
132 macro(Br, 0xc, Oops, 4) \
133 macro(Select, 0x1b, Oops, 5) \
134 macro(Unreachable, 0x0, Oops, 6) \
135 macro(Else, 0x5, Oops, 7) \
136 macro(BrTable, 0xe, Oops, 8) \
137 macro(Loop, 0x3, Oops, 9) \
138 macro(If, 0x4, Oops, 10) \
139 macro(End, 0xb, Oops, 11) \
140 macro(Block, 0x2, Oops, 12)
141
142#define FOR_EACH_WASM_SIMPLE_UNARY_OP(macro) \
143 macro(F32Ceil, 0x8d, Ceil, 0) \
144 macro(F32DemoteF64, 0xb6, DoubleToFloat, 1) \
145 macro(I32Clz, 0x67, Clz, 2) \
146 macro(F64ConvertUI32, 0xb8, IToD(ZExt32(@0)), 3) \
147 macro(F32ReinterpretI32, 0xbe, BitwiseCast, 4) \
148 macro(F32Sqrt, 0x91, Sqrt, 5) \
149 macro(I64Eqz, 0x50, Equal(i64(0), @0), 6) \
150 macro(I64Clz, 0x79, Clz, 7) \
151 macro(F32Neg, 0x8c, Neg, 8) \
152 macro(F64Abs, 0x99, Abs, 9) \
153 macro(F32ConvertSI64, 0xb4, IToF, 10) \
154 macro(F64ConvertSI32, 0xb7, IToD, 11) \
155 macro(F32ConvertUI32, 0xb3, IToF(ZExt32(@0)), 12) \
156 macro(F64Ceil, 0x9b, Ceil, 13) \
157 macro(F64Floor, 0x9c, Floor, 14) \
158 macro(F32Abs, 0x8b, Abs, 15) \
159 macro(I32ReinterpretF32, 0xbc, BitwiseCast, 16) \
160 macro(F64ConvertSI64, 0xb9, IToD, 17) \
161 macro(F64PromoteF32, 0xbb, FloatToDouble, 18) \
162 macro(I64ExtendUI32, 0xad, ZExt32, 19) \
163 macro(F64ReinterpretI64, 0xbf, BitwiseCast, 20) \
164 macro(F32Floor, 0x8e, Floor, 21) \
165 macro(F32ConvertSI32, 0xb2, IToF, 22) \
166 macro(I32Eqz, 0x45, Equal(i32(0), @0), 23) \
167 macro(I64ReinterpretF64, 0xbd, BitwiseCast, 24) \
168 macro(F64Sqrt, 0x9f, Sqrt, 25) \
169 macro(I32WrapI64, 0xa7, Trunc, 26) \
170 macro(I64ExtendSI32, 0xac, SExt32, 27) \
171 macro(F64Neg, 0x9a, Neg, 28)
172
173#define FOR_EACH_WASM_UNARY_OP(macro) \
174 FOR_EACH_WASM_SIMPLE_UNARY_OP(macro) \
175 macro(I64TruncSF32, 0xae, Oops, 0) \
176 macro(F32ConvertUI64, 0xb5, Oops, 1) \
177 macro(I32Ctz, 0x68, Oops, 2) \
178 macro(I32TruncSF64, 0xaa, Oops, 3) \
179 macro(I32TruncUF64, 0xab, Oops, 4) \
180 macro(I32Popcnt, 0x69, Oops, 5) \
181 macro(I64Popcnt, 0x7b, Oops, 6) \
182 macro(I64Ctz, 0x7a, Oops, 7) \
183 macro(I32TruncSF32, 0xa8, Oops, 8) \
184 macro(I64TruncUF64, 0xb1, Oops, 9) \
185 macro(I64TruncSF64, 0xb0, Oops, 10) \
186 macro(F64ConvertUI64, 0xba, Oops, 11) \
187 macro(F64Nearest, 0x9e, Oops, 12) \
188 macro(F64Trunc, 0x9d, Oops, 13) \
189 macro(F32Trunc, 0x8f, Oops, 14) \
190 macro(I32TruncUF32, 0xa9, Oops, 15) \
191 macro(I64TruncUF32, 0xaf, Oops, 16) \
192 macro(F32Nearest, 0x90, Oops, 17)
193
194#define FOR_EACH_WASM_SIMPLE_BINARY_OP(macro) \
195 macro(I32Mul, 0x6c, Mul, 0) \
196 macro(I32Sub, 0x6b, Sub, 1) \
197 macro(F64Le, 0x65, LessEqual, 2) \
198 macro(F32Min, 0x96, Select(Equal(@0, @1), BitOr(@0, @1), Select(LessThan(@0, @1), @0, Select(GreaterThan(@0, @1), @1, Add(@0, @1)))), 3) \
199 macro(F64Ne, 0x62, NotEqual, 4) \
200 macro(F64Lt, 0x63, LessThan, 5) \
201 macro(F32Max, 0x97, Select(Equal(@0, @1), BitAnd(@0, @1), Select(LessThan(@0, @1), @1, Select(GreaterThan(@0, @1), @0, Add(@0, @1)))), 6) \
202 macro(F64Mul, 0xa2, Mul, 7) \
203 macro(F32Div, 0x95, Div, 8) \
204 macro(F32Copysign, 0x98, BitwiseCast(BitOr(BitAnd(BitwiseCast(@1), i32(0x80000000)), BitAnd(BitwiseCast(@0), i32(0x7fffffff)))), 9) \
205 macro(I64And, 0x83, BitAnd, 10) \
206 macro(F32Ne, 0x5c, NotEqual, 11) \
207 macro(F64Gt, 0x64, GreaterThan, 12) \
208 macro(F64Ge, 0x66, GreaterEqual, 13) \
209 macro(I64GtS, 0x55, GreaterThan, 14) \
210 macro(I64GtU, 0x56, Above, 15) \
211 macro(F64Div, 0xa3, Div, 16) \
212 macro(F32Add, 0x92, Add, 17) \
213 macro(I64Or, 0x84, BitOr, 18) \
214 macro(I32LeU, 0x4d, BelowEqual, 19) \
215 macro(I32LeS, 0x4c, LessEqual, 20) \
216 macro(I64Ne, 0x52, NotEqual, 21) \
217 macro(I32And, 0x71, BitAnd, 22) \
218 macro(I32LtU, 0x49, Below, 23) \
219 macro(I64Rotr, 0x8a, RotR(@0, Trunc(@1)), 24) \
220 macro(I32LtS, 0x48, LessThan, 25) \
221 macro(I32Eq, 0x46, Equal, 26) \
222 macro(F64Copysign, 0xa6, BitwiseCast(BitOr(BitAnd(BitwiseCast(@1), i64(0x8000000000000000)), BitAnd(BitwiseCast(@0), i64(0x7fffffffffffffff)))), 27) \
223 macro(I64Rotl, 0x89, RotL(@0, Trunc(@1)), 28) \
224 macro(F32Lt, 0x5d, LessThan, 29) \
225 macro(F64Eq, 0x61, Equal, 30) \
226 macro(F32Le, 0x5f, LessEqual, 31) \
227 macro(F32Ge, 0x60, GreaterEqual, 32) \
228 macro(I32ShrU, 0x76, ZShr, 33) \
229 macro(I32ShrS, 0x75, SShr, 34) \
230 macro(I32GeU, 0x4f, AboveEqual, 35) \
231 macro(I32GeS, 0x4e, GreaterEqual, 36) \
232 macro(I32Shl, 0x74, Shl, 37) \
233 macro(I32Xor, 0x73, BitXor, 38) \
234 macro(F64Min, 0xa4, Select(Equal(@0, @1), BitOr(@0, @1), Select(LessThan(@0, @1), @0, Select(GreaterThan(@0, @1), @1, Add(@0, @1)))), 39) \
235 macro(F32Mul, 0x94, Mul, 40) \
236 macro(I64Sub, 0x7d, Sub, 41) \
237 macro(I32Add, 0x6a, Add, 42) \
238 macro(F64Sub, 0xa1, Sub, 43) \
239 macro(I32Or, 0x72, BitOr, 44) \
240 macro(I64LtU, 0x54, Below, 45) \
241 macro(I64LtS, 0x53, LessThan, 46) \
242 macro(I64Xor, 0x85, BitXor, 47) \
243 macro(I64GeU, 0x5a, AboveEqual, 48) \
244 macro(I64Mul, 0x7e, Mul, 49) \
245 macro(F32Sub, 0x93, Sub, 50) \
246 macro(F64Add, 0xa0, Add, 51) \
247 macro(I64GeS, 0x59, GreaterEqual, 52) \
248 macro(I32Ne, 0x47, NotEqual, 53) \
249 macro(F32Eq, 0x5b, Equal, 54) \
250 macro(I64Eq, 0x51, Equal, 55) \
251 macro(I64ShrS, 0x87, SShr(@0, Trunc(@1)), 56) \
252 macro(I64ShrU, 0x88, ZShr(@0, Trunc(@1)), 57) \
253 macro(I64Shl, 0x86, Shl(@0, Trunc(@1)), 58) \
254 macro(F32Gt, 0x5e, GreaterThan, 59) \
255 macro(I32Rotl, 0x77, RotL, 60) \
256 macro(I32Rotr, 0x78, RotR, 61) \
257 macro(I32GtU, 0x4b, Above, 62) \
258 macro(I32GtS, 0x4a, GreaterThan, 63) \
259 macro(F64Max, 0xa5, Select(Equal(@0, @1), BitAnd(@0, @1), Select(LessThan(@0, @1), @1, Select(GreaterThan(@0, @1), @0, Add(@0, @1)))), 64) \
260 macro(I64LeU, 0x58, BelowEqual, 65) \
261 macro(I64LeS, 0x57, LessEqual, 66) \
262 macro(I64Add, 0x7c, Add, 67)
263
264#define FOR_EACH_WASM_BINARY_OP(macro) \
265 FOR_EACH_WASM_SIMPLE_BINARY_OP(macro) \
266 macro(I32DivU, 0x6e, Oops, 0) \
267 macro(I32DivS, 0x6d, Oops, 1) \
268 macro(I32RemU, 0x70, Oops, 2) \
269 macro(I32RemS, 0x6f, Oops, 3) \
270 macro(I64RemS, 0x81, Oops, 4) \
271 macro(I64RemU, 0x82, Oops, 5) \
272 macro(I64DivU, 0x80, Oops, 6) \
273 macro(I64DivS, 0x7f, Oops, 7)
274
275#define FOR_EACH_WASM_MEMORY_LOAD_OP(macro) \
276 macro(I64Load32U, 0x35, Oops, 0) \
277 macro(I64Load32S, 0x34, Oops, 1) \
278 macro(I32Load16S, 0x2e, Oops, 2) \
279 macro(I32Load16U, 0x2f, Oops, 3) \
280 macro(I64Load, 0x29, Oops, 4) \
281 macro(F64Load, 0x2b, Oops, 5) \
282 macro(I32Load8S, 0x2c, Oops, 6) \
283 macro(I32Load8U, 0x2d, Oops, 7) \
284 macro(I32Load, 0x28, Oops, 8) \
285 macro(F32Load, 0x2a, Oops, 9) \
286 macro(I64Load8U, 0x31, Oops, 10) \
287 macro(I64Load8S, 0x30, Oops, 11) \
288 macro(I64Load16S, 0x32, Oops, 12) \
289 macro(I64Load16U, 0x33, Oops, 13)
290
291#define FOR_EACH_WASM_MEMORY_STORE_OP(macro) \
292 macro(I64Store16, 0x3d, Oops, 0) \
293 macro(I64Store8, 0x3c, Oops, 1) \
294 macro(I32Store, 0x36, Oops, 2) \
295 macro(I32Store16, 0x3b, Oops, 3) \
296 macro(F32Store, 0x38, Oops, 4) \
297 macro(I64Store, 0x37, Oops, 5) \
298 macro(F64Store, 0x39, Oops, 6) \
299 macro(I32Store8, 0x3a, Oops, 7) \
300 macro(I64Store32, 0x3e, Oops, 8)
301
302
303#define FOR_EACH_WASM_OP(macro) \
304 FOR_EACH_WASM_SPECIAL_OP(macro) \
305 FOR_EACH_WASM_CONTROL_FLOW_OP(macro) \
306 FOR_EACH_WASM_UNARY_OP(macro) \
307 FOR_EACH_WASM_BINARY_OP(macro) \
308 FOR_EACH_WASM_MEMORY_LOAD_OP(macro) \
309 FOR_EACH_WASM_MEMORY_STORE_OP(macro)
310
311#define CREATE_ENUM_VALUE(name, id, b3op, inc) name = id,
312
313enum OpType : uint8_t {
314 FOR_EACH_WASM_OP(CREATE_ENUM_VALUE)
315};
316
317template<typename Int>
318inline bool isValidOpType(Int i)
319{
320 // Bitset of valid ops.
321 static const uint8_t valid[] = { 0x3f, 0xf8, 0x3, 0xc, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
322 return 0 <= i && i <= 191 && (valid[i / 8] & (1 << (i % 8)));
323}
324
325enum class BinaryOpType : uint8_t {
326 FOR_EACH_WASM_BINARY_OP(CREATE_ENUM_VALUE)
327};
328
329enum class UnaryOpType : uint8_t {
330 FOR_EACH_WASM_UNARY_OP(CREATE_ENUM_VALUE)
331};
332
333enum class LoadOpType : uint8_t {
334 FOR_EACH_WASM_MEMORY_LOAD_OP(CREATE_ENUM_VALUE)
335};
336
337enum class StoreOpType : uint8_t {
338 FOR_EACH_WASM_MEMORY_STORE_OP(CREATE_ENUM_VALUE)
339};
340
341#undef CREATE_ENUM_VALUE
342
343inline bool isControlOp(OpType op)
344{
345 switch (op) {
346#define CREATE_CASE(name, id, b3op, inc) case OpType::name:
347 FOR_EACH_WASM_CONTROL_FLOW_OP(CREATE_CASE)
348 return true;
349#undef CREATE_CASE
350 default:
351 break;
352 }
353 return false;
354}
355
356inline bool isSimple(UnaryOpType op)
357{
358 switch (op) {
359#define CREATE_CASE(name, id, b3op, inc) case UnaryOpType::name:
360 FOR_EACH_WASM_SIMPLE_UNARY_OP(CREATE_CASE)
361 return true;
362#undef CREATE_CASE
363 default:
364 break;
365 }
366 return false;
367}
368
369inline bool isSimple(BinaryOpType op)
370{
371 switch (op) {
372#define CREATE_CASE(name, id, b3op, inc) case BinaryOpType::name:
373 FOR_EACH_WASM_SIMPLE_BINARY_OP(CREATE_CASE)
374 return true;
375#undef CREATE_CASE
376 default:
377 break;
378 }
379 return false;
380}
381
382inline uint32_t memoryLog2Alignment(OpType op)
383{
384 switch (op) {
385 case I64Load32U: return 2;
386 case I64Load32S: return 2;
387 case I32Load16S: return 1;
388 case I32Load16U: return 1;
389 case I64Load: return 3;
390 case F64Load: return 3;
391 case I32Load8S: return 0;
392 case I32Load8U: return 0;
393 case I32Load: return 2;
394 case F32Load: return 2;
395 case I64Load8U: return 0;
396 case I64Load8S: return 0;
397 case I64Load16S: return 1;
398 case I64Load16U: return 1;
399 case I64Store16: return 1;
400 case I64Store8: return 0;
401 case I32Store: return 2;
402 case I32Store16: return 1;
403 case F32Store: return 2;
404 case I64Store: return 3;
405 case F64Store: return 3;
406 case I32Store8: return 0;
407 case I64Store32: return 2;
408 default:
409 break;
410 }
411 RELEASE_ASSERT_NOT_REACHED();
412 return 0;
413}
414
415#define CREATE_CASE(name, id, b3type, inc) case name: return #name;
416inline const char* makeString(OpType op)
417{
418 switch (op) {
419 FOR_EACH_WASM_OP(CREATE_CASE)
420 }
421 RELEASE_ASSERT_NOT_REACHED();
422 return nullptr;
423}
424#undef CREATE_CASE
425
426} } // namespace JSC::Wasm
427
428#endif // ENABLE(WEBASSEMBLY)
429
430