| 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 |
* |
| 4 |
* Copyright 2015 Mozilla Foundation |
| 5 |
* |
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
* you may not use this file except in compliance with the License. |
| 8 |
* You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, software |
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
* See the License for the specific language governing permissions and |
| 16 |
* limitations under the License. |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef wasm_constants_h |
| 20 |
#define wasm_constants_h |
| 21 |
|
| 22 |
#include <stdint.h> |
| 23 |
|
| 24 |
#include "wasm/WasmBuiltinModuleGenerated.h" |
| 25 |
#include "wasm/WasmSerialize.h" |
| 26 |
|
| 27 |
namespace js { |
| 28 |
namespace wasm { |
| 29 |
|
| 30 |
static const uint32_t MagicNumber = 0x6d736100; // "\0asm" |
| 31 |
static const uint32_t EncodingVersion = 0x01; |
| 32 |
|
| 33 |
enum class SectionId { |
| 34 |
Custom = 0, |
| 35 |
Type = 1, |
| 36 |
Import = 2, |
| 37 |
Function = 3, |
| 38 |
Table = 4, |
| 39 |
Memory = 5, |
| 40 |
Global = 6, |
| 41 |
Export = 7, |
| 42 |
Start = 8, |
| 43 |
Elem = 9, |
| 44 |
Code = 10, |
| 45 |
Data = 11, |
| 46 |
DataCount = 12, |
| 47 |
Tag = 13, |
| 48 |
}; |
| 49 |
|
| 50 |
// WebAssembly type encodings are all single-byte negative SLEB128s, hence: |
| 51 |
// forall tc:TypeCode. ((tc & SLEB128SignMask) == SLEB128SignBit |
| 52 |
static const uint8_t SLEB128SignMask = 0xc0; |
| 53 |
static const uint8_t SLEB128SignBit = 0x40; |
| 54 |
|
| 55 |
enum class TypeCode { |
| 56 |
|
| 57 |
// If more "simple primitive" (non-reference, non-constructor, |
| 58 |
// non-special-purpose) types are added here then you MUST update |
| 59 |
// LowestPrimitiveTypeCode, below. |
| 60 |
|
| 61 |
I32 = 0x7f, // SLEB128(-0x01) |
| 62 |
I64 = 0x7e, // SLEB128(-0x02) |
| 63 |
F32 = 0x7d, // SLEB128(-0x03) |
| 64 |
F64 = 0x7c, // SLEB128(-0x04) |
| 65 |
V128 = 0x7b, // SLEB128(-0x05) |
| 66 |
|
| 67 |
I8 = 0x78, // SLEB128(-0x08) |
| 68 |
I16 = 0x77, // SLEB128(-0x09) |
| 69 |
|
| 70 |
// A function pointer with any signature |
| 71 |
FuncRef = 0x70, // SLEB128(-0x10) |
| 72 |
|
| 73 |
// A reference to any host value. |
| 74 |
ExternRef = 0x6f, // SLEB128(-0x11) |
| 75 |
|
| 76 |
// A reference to any wasm gc value. |
| 77 |
AnyRef = 0x6e, // SLEB128(-0x12) |
| 78 |
|
| 79 |
// A reference to a struct/array value. |
| 80 |
EqRef = 0x6d, // SLEB128(-0x13) |
| 81 |
|
| 82 |
// Type constructor for nullable reference types. |
| 83 |
NullableRef = 0x63, // SLEB128(-0x1D) |
| 84 |
|
| 85 |
// Type constructor for non-nullable reference types. |
| 86 |
Ref = 0x64, // SLEB128(-0x1C) |
| 87 |
|
| 88 |
// A reference to an unboxed 31-bit integer. |
| 89 |
I31Ref = 0x6c, // SLEB128(-0x14) |
| 90 |
|
| 91 |
// A null reference in the extern hierarchy. |
| 92 |
NullExternRef = 0x72, // SLEB128(-0x0E) |
| 93 |
|
| 94 |
// A null reference in the func hierarchy. |
| 95 |
NullFuncRef = 0x73, // SLEB128(-0x0D) |
| 96 |
|
| 97 |
// A null reference in the exn hierarchy. |
| 98 |
NullExnRef = 0x74, // SLEB128(-0x0C) |
| 99 |
|
| 100 |
// A reference to any struct value. |
| 101 |
StructRef = 0x6b, // SLEB128(-0x15) |
| 102 |
|
| 103 |
// A reference to any array value. |
| 104 |
ArrayRef = 0x6a, // SLEB128(-0x16) |
| 105 |
|
| 106 |
// A reference to an exception value. |
| 107 |
ExnRef = 0x69, // SLEB128(-0x17) |
| 108 |
|
| 109 |
// A null reference in the any hierarchy. |
| 110 |
NullAnyRef = 0x71, // SLEB128(-0x0F) |
| 111 |
|
| 112 |
// Type constructor for function types |
| 113 |
Func = 0x60, // SLEB128(-0x20) |
| 114 |
|
| 115 |
// Type constructor for structure types - gc proposal |
| 116 |
Struct = 0x5f, // SLEB128(-0x21) |
| 117 |
|
| 118 |
// Type constructor for array types - gc proposal |
| 119 |
Array = 0x5e, // SLEB128(-0x22) |
| 120 |
|
| 121 |
// Value for non-nullable type present. |
| 122 |
TableHasInitExpr = 0x40, |
| 123 |
|
| 124 |
// The 'empty' case of blocktype. |
| 125 |
BlockVoid = 0x40, // SLEB128(-0x40) |
| 126 |
|
| 127 |
// Type constructor for recursion groups - gc proposal |
| 128 |
RecGroup = 0x4e, // SLEB128(-0x31) |
| 129 |
|
| 130 |
// Type prefix for parent types - gc proposal |
| 131 |
SubNoFinalType = 0x50, // SLEB128(-0x30) |
| 132 |
|
| 133 |
// Type prefix for final types - gc proposal |
| 134 |
SubFinalType = 0x4f, // SLEB128(-0x32) |
| 135 |
|
| 136 |
Limit = 0x80 |
| 137 |
}; |
| 138 |
|
| 139 |
// This is the lowest-valued TypeCode that is a primitive type, used in |
| 140 |
// UnpackTypeCodeTypeAbstracted(). If primitive typecodes are added below any |
| 141 |
// reference typecode then the logic in that function MUST change. |
| 142 |
|
| 143 |
static constexpr TypeCode LowestPrimitiveTypeCode = TypeCode::I16; |
| 144 |
|
| 145 |
// An arbitrary reference type used as the result of |
| 146 |
// UnpackTypeCodeTypeAbstracted() when a value type is a reference. |
| 147 |
|
| 148 |
static constexpr TypeCode AbstractReferenceTypeCode = TypeCode::ExternRef; |
| 149 |
|
| 150 |
// A type code used to represent (ref null? T) whether or not the type |
| 151 |
// is encoded with 'Ref' or 'NullableRef'. |
| 152 |
|
| 153 |
static constexpr TypeCode AbstractTypeRefCode = TypeCode::Ref; |
| 154 |
|
| 155 |
// wasm traps are machine instructions that can fail to execute for reasons |
| 156 |
// that have to do with some condition in the wasm that they were compiled |
| 157 |
// from. The failure manifests as a (machine-level) exception of some sort, |
| 158 |
// which leads execution to a signal handler, and is eventually reported as a |
| 159 |
// WebAssembly.RuntimeError. Generated code may also jump to a Trap |
| 160 |
// symbolically, passing the bytecode offset to report as the trap offset. |
| 161 |
// The generated jump will be bound to a tiny stub which fills the offset and |
| 162 |
// then jumps to a per-Trap shared stub at the end of the module. |
| 163 |
// |
| 164 |
// Traps are described by a value from Trap and, in debug builds only, a value |
| 165 |
// from TrapInsn. |
| 166 |
// |
| 167 |
// * A Trap indicates why the trap has happened and is used to construct the |
| 168 |
// WebAssembly.Runtime message. |
| 169 |
// |
| 170 |
// * A TrapMachineInsn (not defined in this file) describes roughly what kind |
| 171 |
// of machine instruction has caused the trap. This is used only for |
| 172 |
// validation of trap placement in debug builds, in |
| 173 |
// ModuleGenerator::finishMetadataTier, and is not necessary for execution |
| 174 |
// of wasm code. |
| 175 |
|
| 176 |
enum class Trap { |
| 177 |
// The Unreachable opcode has been executed. |
| 178 |
Unreachable, |
| 179 |
// An integer arithmetic operation led to an overflow. |
| 180 |
IntegerOverflow, |
| 181 |
// Trying to coerce NaN to an integer. |
| 182 |
InvalidConversionToInteger, |
| 183 |
// Integer division by zero. |
| 184 |
IntegerDivideByZero, |
| 185 |
// Out of bounds on wasm memory accesses. |
| 186 |
OutOfBounds, |
| 187 |
// Unaligned on wasm atomic accesses; also used for non-standard ARM |
| 188 |
// unaligned access faults. |
| 189 |
UnalignedAccess, |
| 190 |
// call_indirect to null. |
| 191 |
IndirectCallToNull, |
| 192 |
// call_indirect signature mismatch. |
| 193 |
IndirectCallBadSig, |
| 194 |
// Dereference null pointer in operation on (Ref T) |
| 195 |
NullPointerDereference, |
| 196 |
// Failed to cast a (Ref T) in a ref.cast instruction |
| 197 |
BadCast, |
| 198 |
|
| 199 |
// The internal stack space was exhausted. For compatibility, this throws |
| 200 |
// the same over-recursed error as JS. |
| 201 |
StackOverflow, |
| 202 |
|
| 203 |
// The wasm execution has potentially run too long and the engine must call |
| 204 |
// CheckForInterrupt(). This trap is resumable. |
| 205 |
CheckInterrupt, |
| 206 |
|
| 207 |
// Signal an error that was reported in C++ code. |
| 208 |
ThrowReported, |
| 209 |
|
| 210 |
Limit |
| 211 |
}; |
| 212 |
|
| 213 |
enum class DefinitionKind { |
| 214 |
Function = 0x00, |
| 215 |
Table = 0x01, |
| 216 |
Memory = 0x02, |
| 217 |
Global = 0x03, |
| 218 |
Tag = 0x04, |
| 219 |
}; |
| 220 |
|
| 221 |
enum class GlobalTypeImmediate { IsMutable = 0x1, AllowedMask = 0x1 }; |
| 222 |
|
| 223 |
enum class LimitsFlags { |
| 224 |
Default = 0x0, |
| 225 |
HasMaximum = 0x1, |
| 226 |
IsShared = 0x2, |
| 227 |
IsI64 = 0x4, |
| 228 |
}; |
| 229 |
|
| 230 |
enum class LimitsMask { |
| 231 |
#ifdef ENABLE_WASM_MEMORY64 |
| 232 |
Table = uint8_t(LimitsFlags::HasMaximum) | uint8_t(LimitsFlags::IsI64), |
| 233 |
Memory = uint8_t(LimitsFlags::HasMaximum) | uint8_t(LimitsFlags::IsShared) | |
| 234 |
uint8_t(LimitsFlags::IsI64), |
| 235 |
#else |
| 236 |
Table = uint8_t(LimitsFlags::HasMaximum), |
| 237 |
Memory = uint8_t(LimitsFlags::HasMaximum) | uint8_t(LimitsFlags::IsShared), |
| 238 |
#endif |
| 239 |
}; |
| 240 |
|
| 241 |
enum class DataSegmentKind { |
| 242 |
Active = 0x00, |
| 243 |
Passive = 0x01, |
| 244 |
ActiveWithMemoryIndex = 0x02 |
| 245 |
}; |
| 246 |
|
| 247 |
enum class ElemSegmentKind : uint32_t { |
| 248 |
Active = 0x0, |
| 249 |
Passive = 0x1, |
| 250 |
ActiveWithTableIndex = 0x2, |
| 251 |
Declared = 0x3, |
| 252 |
}; |
| 253 |
|
| 254 |
enum class ElemSegmentPayload : uint32_t { |
| 255 |
Indices = 0x0, |
| 256 |
Expressions = 0x4, |
| 257 |
}; |
| 258 |
|
| 259 |
enum class TagKind { |
| 260 |
Exception = 0x0, |
| 261 |
}; |
| 262 |
|
| 263 |
enum class Op { |
| 264 |
// Control flow operators |
| 265 |
Unreachable = 0x00, |
| 266 |
Nop = 0x01, |
| 267 |
Block = 0x02, |
| 268 |
Loop = 0x03, |
| 269 |
If = 0x04, |
| 270 |
Else = 0x05, |
| 271 |
Try = 0x06, |
| 272 |
Catch = 0x07, |
| 273 |
Throw = 0x08, |
| 274 |
Rethrow = 0x09, |
| 275 |
ThrowRef = 0x0a, |
| 276 |
End = 0x0b, |
| 277 |
Br = 0x0c, |
| 278 |
BrIf = 0x0d, |
| 279 |
BrTable = 0x0e, |
| 280 |
Return = 0x0f, |
| 281 |
|
| 282 |
// Call operators |
| 283 |
Call = 0x10, |
| 284 |
CallIndirect = 0x11, |
| 285 |
ReturnCall = 0x12, |
| 286 |
ReturnCallIndirect = 0x13, |
| 287 |
CallRef = 0x14, |
| 288 |
ReturnCallRef = 0x15, |
| 289 |
|
| 290 |
// Additional exception operators |
| 291 |
Delegate = 0x18, |
| 292 |
CatchAll = 0x19, |
| 293 |
|
| 294 |
// Parametric operators |
| 295 |
Drop = 0x1a, |
| 296 |
SelectNumeric = 0x1b, |
| 297 |
SelectTyped = 0x1c, |
| 298 |
|
| 299 |
// Additional exception operators |
| 300 |
TryTable = 0x1f, |
| 301 |
|
| 302 |
// Variable access |
| 303 |
LocalGet = 0x20, |
| 304 |
LocalSet = 0x21, |
| 305 |
LocalTee = 0x22, |
| 306 |
GlobalGet = 0x23, |
| 307 |
GlobalSet = 0x24, |
| 308 |
TableGet = 0x25, // Reftypes, |
| 309 |
TableSet = 0x26, // per proposal as of February 2019 |
| 310 |
|
| 311 |
// Memory-related operators |
| 312 |
I32Load = 0x28, |
| 313 |
I64Load = 0x29, |
| 314 |
F32Load = 0x2a, |
| 315 |
F64Load = 0x2b, |
| 316 |
I32Load8S = 0x2c, |
| 317 |
I32Load8U = 0x2d, |
| 318 |
I32Load16S = 0x2e, |
| 319 |
I32Load16U = 0x2f, |
| 320 |
I64Load8S = 0x30, |
| 321 |
I64Load8U = 0x31, |
| 322 |
I64Load16S = 0x32, |
| 323 |
I64Load16U = 0x33, |
| 324 |
I64Load32S = 0x34, |
| 325 |
I64Load32U = 0x35, |
| 326 |
I32Store = 0x36, |
| 327 |
I64Store = 0x37, |
| 328 |
F32Store = 0x38, |
| 329 |
F64Store = 0x39, |
| 330 |
I32Store8 = 0x3a, |
| 331 |
I32Store16 = 0x3b, |
| 332 |
I64Store8 = 0x3c, |
| 333 |
I64Store16 = 0x3d, |
| 334 |
I64Store32 = 0x3e, |
| 335 |
MemorySize = 0x3f, |
| 336 |
MemoryGrow = 0x40, |
| 337 |
|
| 338 |
// Constants |
| 339 |
I32Const = 0x41, |
| 340 |
I64Const = 0x42, |
| 341 |
F32Const = 0x43, |
| 342 |
F64Const = 0x44, |
| 343 |
|
| 344 |
// Comparison operators |
| 345 |
I32Eqz = 0x45, |
| 346 |
I32Eq = 0x46, |
| 347 |
I32Ne = 0x47, |
| 348 |
I32LtS = 0x48, |
| 349 |
I32LtU = 0x49, |
| 350 |
I32GtS = 0x4a, |
| 351 |
I32GtU = 0x4b, |
| 352 |
I32LeS = 0x4c, |
| 353 |
I32LeU = 0x4d, |
| 354 |
I32GeS = 0x4e, |
| 355 |
I32GeU = 0x4f, |
| 356 |
I64Eqz = 0x50, |
| 357 |
I64Eq = 0x51, |
| 358 |
I64Ne = 0x52, |
| 359 |
I64LtS = 0x53, |
| 360 |
I64LtU = 0x54, |
| 361 |
I64GtS = 0x55, |
| 362 |
I64GtU = 0x56, |
| 363 |
I64LeS = 0x57, |
| 364 |
I64LeU = 0x58, |
| 365 |
I64GeS = 0x59, |
| 366 |
I64GeU = 0x5a, |
| 367 |
F32Eq = 0x5b, |
| 368 |
F32Ne = 0x5c, |
| 369 |
F32Lt = 0x5d, |
| 370 |
F32Gt = 0x5e, |
| 371 |
F32Le = 0x5f, |
| 372 |
F32Ge = 0x60, |
| 373 |
F64Eq = 0x61, |
| 374 |
F64Ne = 0x62, |
| 375 |
F64Lt = 0x63, |
| 376 |
F64Gt = 0x64, |
| 377 |
F64Le = 0x65, |
| 378 |
F64Ge = 0x66, |
| 379 |
|
| 380 |
// Numeric operators |
| 381 |
I32Clz = 0x67, |
| 382 |
I32Ctz = 0x68, |
| 383 |
I32Popcnt = 0x69, |
| 384 |
I32Add = 0x6a, |
| 385 |
I32Sub = 0x6b, |
| 386 |
I32Mul = 0x6c, |
| 387 |
I32DivS = 0x6d, |
| 388 |
I32DivU = 0x6e, |
| 389 |
I32RemS = 0x6f, |
| 390 |
I32RemU = 0x70, |
| 391 |
I32And = 0x71, |
| 392 |
I32Or = 0x72, |
| 393 |
I32Xor = 0x73, |
| 394 |
I32Shl = 0x74, |
| 395 |
I32ShrS = 0x75, |
| 396 |
I32ShrU = 0x76, |
| 397 |
I32Rotl = 0x77, |
| 398 |
I32Rotr = 0x78, |
| 399 |
I64Clz = 0x79, |
| 400 |
I64Ctz = 0x7a, |
| 401 |
I64Popcnt = 0x7b, |
| 402 |
I64Add = 0x7c, |
| 403 |
I64Sub = 0x7d, |
| 404 |
I64Mul = 0x7e, |
| 405 |
I64DivS = 0x7f, |
| 406 |
I64DivU = 0x80, |
| 407 |
I64RemS = 0x81, |
| 408 |
I64RemU = 0x82, |
| 409 |
I64And = 0x83, |
| 410 |
I64Or = 0x84, |
| 411 |
I64Xor = 0x85, |
| 412 |
I64Shl = 0x86, |
| 413 |
I64ShrS = 0x87, |
| 414 |
I64ShrU = 0x88, |
| 415 |
I64Rotl = 0x89, |
| 416 |
I64Rotr = 0x8a, |
| 417 |
F32Abs = 0x8b, |
| 418 |
F32Neg = 0x8c, |
| 419 |
F32Ceil = 0x8d, |
| 420 |
F32Floor = 0x8e, |
| 421 |
F32Trunc = 0x8f, |
| 422 |
F32Nearest = 0x90, |
| 423 |
F32Sqrt = 0x91, |
| 424 |
F32Add = 0x92, |
| 425 |
F32Sub = 0x93, |
| 426 |
F32Mul = 0x94, |
| 427 |
F32Div = 0x95, |
| 428 |
F32Min = 0x96, |
| 429 |
F32Max = 0x97, |
| 430 |
F32CopySign = 0x98, |
| 431 |
F64Abs = 0x99, |
| 432 |
F64Neg = 0x9a, |
| 433 |
F64Ceil = 0x9b, |
| 434 |
F64Floor = 0x9c, |
| 435 |
F64Trunc = 0x9d, |
| 436 |
F64Nearest = 0x9e, |
| 437 |
F64Sqrt = 0x9f, |
| 438 |
F64Add = 0xa0, |
| 439 |
F64Sub = 0xa1, |
| 440 |
F64Mul = 0xa2, |
| 441 |
F64Div = 0xa3, |
| 442 |
F64Min = 0xa4, |
| 443 |
F64Max = 0xa5, |
| 444 |
F64CopySign = 0xa6, |
| 445 |
|
| 446 |
// Conversions |
| 447 |
I32WrapI64 = 0xa7, |
| 448 |
I32TruncF32S = 0xa8, |
| 449 |
I32TruncF32U = 0xa9, |
| 450 |
I32TruncF64S = 0xaa, |
| 451 |
I32TruncF64U = 0xab, |
| 452 |
I64ExtendI32S = 0xac, |
| 453 |
I64ExtendI32U = 0xad, |
| 454 |
I64TruncF32S = 0xae, |
| 455 |
I64TruncF32U = 0xaf, |
| 456 |
I64TruncF64S = 0xb0, |
| 457 |
I64TruncF64U = 0xb1, |
| 458 |
F32ConvertI32S = 0xb2, |
| 459 |
F32ConvertI32U = 0xb3, |
| 460 |
F32ConvertI64S = 0xb4, |
| 461 |
F32ConvertI64U = 0xb5, |
| 462 |
F32DemoteF64 = 0xb6, |
| 463 |
F64ConvertI32S = 0xb7, |
| 464 |
F64ConvertI32U = 0xb8, |
| 465 |
F64ConvertI64S = 0xb9, |
| 466 |
F64ConvertI64U = 0xba, |
| 467 |
F64PromoteF32 = 0xbb, |
| 468 |
|
| 469 |
// Reinterpretations |
| 470 |
I32ReinterpretF32 = 0xbc, |
| 471 |
I64ReinterpretF64 = 0xbd, |
| 472 |
F32ReinterpretI32 = 0xbe, |
| 473 |
F64ReinterpretI64 = 0xbf, |
| 474 |
|
| 475 |
// Sign extension |
| 476 |
I32Extend8S = 0xc0, |
| 477 |
I32Extend16S = 0xc1, |
| 478 |
I64Extend8S = 0xc2, |
| 479 |
I64Extend16S = 0xc3, |
| 480 |
I64Extend32S = 0xc4, |
| 481 |
|
| 482 |
// Reference types |
| 483 |
RefNull = 0xd0, |
| 484 |
RefIsNull = 0xd1, |
| 485 |
RefFunc = 0xd2, |
| 486 |
|
| 487 |
// Function references |
| 488 |
RefAsNonNull = 0xd4, |
| 489 |
BrOnNull = 0xd5, |
| 490 |
|
| 491 |
// GC (experimental) |
| 492 |
RefEq = 0xd3, |
| 493 |
|
| 494 |
// Function references |
| 495 |
BrOnNonNull = 0xd6, |
| 496 |
|
| 497 |
FirstPrefix = 0xfa, |
| 498 |
GcPrefix = 0xfb, |
| 499 |
MiscPrefix = 0xfc, |
| 500 |
SimdPrefix = 0xfd, |
| 501 |
ThreadPrefix = 0xfe, |
| 502 |
MozPrefix = 0xff, |
| 503 |
|
| 504 |
Limit = 0x100 |
| 505 |
}; |
| 506 |
|
| 507 |
inline bool IsPrefixByte(uint8_t b) { return b >= uint8_t(Op::FirstPrefix); } |
| 508 |
|
| 509 |
// Opcodes in the GC opcode space. |
| 510 |
enum class GcOp { |
| 511 |
// Structure operations |
| 512 |
StructNew = 0x0, |
| 513 |
StructNewDefault = 0x1, |
| 514 |
StructGet = 0x02, |
| 515 |
StructGetS = 0x03, |
| 516 |
StructGetU = 0x04, |
| 517 |
StructSet = 0x05, |
| 518 |
|
| 519 |
// Array operations |
| 520 |
ArrayNew = 0x6, |
| 521 |
ArrayNewDefault = 0x7, |
| 522 |
ArrayNewFixed = 0x8, |
| 523 |
ArrayNewData = 0x9, |
| 524 |
ArrayNewElem = 0xa, |
| 525 |
ArrayGet = 0xb, |
| 526 |
ArrayGetS = 0xc, |
| 527 |
ArrayGetU = 0xd, |
| 528 |
ArraySet = 0xe, |
| 529 |
ArrayLen = 0xf, |
| 530 |
ArrayFill = 0x10, |
| 531 |
ArrayCopy = 0x11, |
| 532 |
ArrayInitData = 0x12, |
| 533 |
ArrayInitElem = 0x13, |
| 534 |
|
| 535 |
// Ref operations |
| 536 |
RefTest = 0x14, |
| 537 |
RefTestNull = 0x15, |
| 538 |
RefCast = 0x16, |
| 539 |
RefCastNull = 0x17, |
| 540 |
BrOnCast = 0x18, |
| 541 |
BrOnCastFail = 0x19, |
| 542 |
|
| 543 |
// Extern/any coercion operations |
| 544 |
AnyConvertExtern = 0x1a, |
| 545 |
ExternConvertAny = 0x1b, |
| 546 |
|
| 547 |
// I31 operations |
| 548 |
RefI31 = 0x1c, |
| 549 |
I31GetS = 0x1d, |
| 550 |
I31GetU = 0x1e, |
| 551 |
|
| 552 |
Limit |
| 553 |
}; |
| 554 |
|
| 555 |
// Opcode list from the SIMD proposal post-renumbering in May, 2020. |
| 556 |
|
| 557 |
// Opcodes with suffix 'Experimental' are proposed but not standardized, and are |
| 558 |
// compatible with those same opcodes in V8. No opcode labeled 'Experimental' |
| 559 |
// will ship in a Release build where SIMD is enabled by default. |
| 560 |
|
| 561 |
enum class SimdOp { |
| 562 |
V128Load = 0x00, |
| 563 |
V128Load8x8S = 0x01, |
| 564 |
V128Load8x8U = 0x02, |
| 565 |
V128Load16x4S = 0x03, |
| 566 |
V128Load16x4U = 0x04, |
| 567 |
V128Load32x2S = 0x05, |
| 568 |
V128Load32x2U = 0x06, |
| 569 |
V128Load8Splat = 0x07, |
| 570 |
V128Load16Splat = 0x08, |
| 571 |
V128Load32Splat = 0x09, |
| 572 |
V128Load64Splat = 0x0a, |
| 573 |
V128Store = 0x0b, |
| 574 |
V128Const = 0x0c, |
| 575 |
I8x16Shuffle = 0x0d, |
| 576 |
I8x16Swizzle = 0x0e, |
| 577 |
I8x16Splat = 0x0f, |
| 578 |
I16x8Splat = 0x10, |
| 579 |
I32x4Splat = 0x11, |
| 580 |
I64x2Splat = 0x12, |
| 581 |
F32x4Splat = 0x13, |
| 582 |
F64x2Splat = 0x14, |
| 583 |
I8x16ExtractLaneS = 0x15, |
| 584 |
I8x16ExtractLaneU = 0x16, |
| 585 |
I8x16ReplaceLane = 0x17, |
| 586 |
I16x8ExtractLaneS = 0x18, |
| 587 |
I16x8ExtractLaneU = 0x19, |
| 588 |
I16x8ReplaceLane = 0x1a, |
| 589 |
I32x4ExtractLane = 0x1b, |
| 590 |
I32x4ReplaceLane = 0x1c, |
| 591 |
I64x2ExtractLane = 0x1d, |
| 592 |
I64x2ReplaceLane = 0x1e, |
| 593 |
F32x4ExtractLane = 0x1f, |
| 594 |
F32x4ReplaceLane = 0x20, |
| 595 |
F64x2ExtractLane = 0x21, |
| 596 |
F64x2ReplaceLane = 0x22, |
| 597 |
I8x16Eq = 0x23, |
| 598 |
I8x16Ne = 0x24, |
| 599 |
I8x16LtS = 0x25, |
| 600 |
I8x16LtU = 0x26, |
| 601 |
I8x16GtS = 0x27, |
| 602 |
I8x16GtU = 0x28, |
| 603 |
I8x16LeS = 0x29, |
| 604 |
I8x16LeU = 0x2a, |
| 605 |
I8x16GeS = 0x2b, |
| 606 |
I8x16GeU = 0x2c, |
| 607 |
I16x8Eq = 0x2d, |
| 608 |
I16x8Ne = 0x2e, |
| 609 |
I16x8LtS = 0x2f, |
| 610 |
I16x8LtU = 0x30, |
| 611 |
I16x8GtS = 0x31, |
| 612 |
I16x8GtU = 0x32, |
| 613 |
I16x8LeS = 0x33, |
| 614 |
I16x8LeU = 0x34, |
| 615 |
I16x8GeS = 0x35, |
| 616 |
I16x8GeU = 0x36, |
| 617 |
I32x4Eq = 0x37, |
| 618 |
I32x4Ne = 0x38, |
| 619 |
I32x4LtS = 0x39, |
| 620 |
I32x4LtU = 0x3a, |
| 621 |
I32x4GtS = 0x3b, |
| 622 |
I32x4GtU = 0x3c, |
| 623 |
I32x4LeS = 0x3d, |
| 624 |
I32x4LeU = 0x3e, |
| 625 |
I32x4GeS = 0x3f, |
| 626 |
I32x4GeU = 0x40, |
| 627 |
F32x4Eq = 0x41, |
| 628 |
F32x4Ne = 0x42, |
| 629 |
F32x4Lt = 0x43, |
| 630 |
F32x4Gt = 0x44, |
| 631 |
F32x4Le = 0x45, |
| 632 |
F32x4Ge = 0x46, |
| 633 |
F64x2Eq = 0x47, |
| 634 |
F64x2Ne = 0x48, |
| 635 |
F64x2Lt = 0x49, |
| 636 |
F64x2Gt = 0x4a, |
| 637 |
F64x2Le = 0x4b, |
| 638 |
F64x2Ge = 0x4c, |
| 639 |
V128Not = 0x4d, |
| 640 |
V128And = 0x4e, |
| 641 |
V128AndNot = 0x4f, |
| 642 |
V128Or = 0x50, |
| 643 |
V128Xor = 0x51, |
| 644 |
V128Bitselect = 0x52, |
| 645 |
V128AnyTrue = 0x53, |
| 646 |
V128Load8Lane = 0x54, |
| 647 |
V128Load16Lane = 0x55, |
| 648 |
V128Load32Lane = 0x56, |
| 649 |
V128Load64Lane = 0x57, |
| 650 |
V128Store8Lane = 0x58, |
| 651 |
V128Store16Lane = 0x59, |
| 652 |
V128Store32Lane = 0x5a, |
| 653 |
V128Store64Lane = 0x5b, |
| 654 |
V128Load32Zero = 0x5c, |
| 655 |
V128Load64Zero = 0x5d, |
| 656 |
F32x4DemoteF64x2Zero = 0x5e, |
| 657 |
F64x2PromoteLowF32x4 = 0x5f, |
| 658 |
I8x16Abs = 0x60, |
| 659 |
I8x16Neg = 0x61, |
| 660 |
I8x16Popcnt = 0x62, |
| 661 |
I8x16AllTrue = 0x63, |
| 662 |
I8x16Bitmask = 0x64, |
| 663 |
I8x16NarrowI16x8S = 0x65, |
| 664 |
I8x16NarrowI16x8U = 0x66, |
| 665 |
F32x4Ceil = 0x67, |
| 666 |
F32x4Floor = 0x68, |
| 667 |
F32x4Trunc = 0x69, |
| 668 |
F32x4Nearest = 0x6a, |
| 669 |
I8x16Shl = 0x6b, |
| 670 |
I8x16ShrS = 0x6c, |
| 671 |
I8x16ShrU = 0x6d, |
| 672 |
I8x16Add = 0x6e, |
| 673 |
I8x16AddSatS = 0x6f, |
| 674 |
I8x16AddSatU = 0x70, |
| 675 |
I8x16Sub = 0x71, |
| 676 |
I8x16SubSatS = 0x72, |
| 677 |
I8x16SubSatU = 0x73, |
| 678 |
F64x2Ceil = 0x74, |
| 679 |
F64x2Floor = 0x75, |
| 680 |
I8x16MinS = 0x76, |
| 681 |
I8x16MinU = 0x77, |
| 682 |
I8x16MaxS = 0x78, |
| 683 |
I8x16MaxU = 0x79, |
| 684 |
F64x2Trunc = 0x7a, |
| 685 |
I8x16AvgrU = 0x7b, |
| 686 |
I16x8ExtaddPairwiseI8x16S = 0x7c, |
| 687 |
I16x8ExtaddPairwiseI8x16U = 0x7d, |
| 688 |
I32x4ExtaddPairwiseI16x8S = 0x7e, |
| 689 |
I32x4ExtaddPairwiseI16x8U = 0x7f, |
| 690 |
I16x8Abs = 0x80, |
| 691 |
I16x8Neg = 0x81, |
| 692 |
I16x8Q15MulrSatS = 0x82, |
| 693 |
I16x8AllTrue = 0x83, |
| 694 |
I16x8Bitmask = 0x84, |
| 695 |
I16x8NarrowI32x4S = 0x85, |
| 696 |
I16x8NarrowI32x4U = 0x86, |
| 697 |
I16x8ExtendLowI8x16S = 0x87, |
| 698 |
I16x8ExtendHighI8x16S = 0x88, |
| 699 |
I16x8ExtendLowI8x16U = 0x89, |
| 700 |
I16x8ExtendHighI8x16U = 0x8a, |
| 701 |
I16x8Shl = 0x8b, |
| 702 |
I16x8ShrS = 0x8c, |
| 703 |
I16x8ShrU = 0x8d, |
| 704 |
I16x8Add = 0x8e, |
| 705 |
I16x8AddSatS = 0x8f, |
| 706 |
I16x8AddSatU = 0x90, |
| 707 |
I16x8Sub = 0x91, |
| 708 |
I16x8SubSatS = 0x92, |
| 709 |
I16x8SubSatU = 0x93, |
| 710 |
F64x2Nearest = 0x94, |
| 711 |
I16x8Mul = 0x95, |
| 712 |
I16x8MinS = 0x96, |
| 713 |
I16x8MinU = 0x97, |
| 714 |
I16x8MaxS = 0x98, |
| 715 |
I16x8MaxU = 0x99, |
| 716 |
// Unused = 0x9a |
| 717 |
I16x8AvgrU = 0x9b, |
| 718 |
I16x8ExtmulLowI8x16S = 0x9c, |
| 719 |
I16x8ExtmulHighI8x16S = 0x9d, |
| 720 |
I16x8ExtmulLowI8x16U = 0x9e, |
| 721 |
I16x8ExtmulHighI8x16U = 0x9f, |
| 722 |
I32x4Abs = 0xa0, |
| 723 |
I32x4Neg = 0xa1, |
| 724 |
// Unused = 0xa2 |
| 725 |
I32x4AllTrue = 0xa3, |
| 726 |
I32x4Bitmask = 0xa4, |
| 727 |
// Unused = 0xa5 |
| 728 |
// Unused = 0xa6 |
| 729 |
I32x4ExtendLowI16x8S = 0xa7, |
| 730 |
I32x4ExtendHighI16x8S = 0xa8, |
| 731 |
I32x4ExtendLowI16x8U = 0xa9, |
| 732 |
I32x4ExtendHighI16x8U = 0xaa, |
| 733 |
I32x4Shl = 0xab, |
| 734 |
I32x4ShrS = 0xac, |
| 735 |
I32x4ShrU = 0xad, |
| 736 |
I32x4Add = 0xae, |
| 737 |
// Unused = 0xaf |
| 738 |
// Unused = 0xb0 |
| 739 |
I32x4Sub = 0xb1, |
| 740 |
// Unused = 0xb2 |
| 741 |
// Unused = 0xb3 |
| 742 |
// Unused = 0xb4 |
| 743 |
I32x4Mul = 0xb5, |
| 744 |
I32x4MinS = 0xb6, |
| 745 |
I32x4MinU = 0xb7, |
| 746 |
I32x4MaxS = 0xb8, |
| 747 |
I32x4MaxU = 0xb9, |
| 748 |
I32x4DotI16x8S = 0xba, |
| 749 |
// Unused = 0xbb |
| 750 |
I32x4ExtmulLowI16x8S = 0xbc, |
| 751 |
I32x4ExtmulHighI16x8S = 0xbd, |
| 752 |
I32x4ExtmulLowI16x8U = 0xbe, |
| 753 |
I32x4ExtmulHighI16x8U = 0xbf, |
| 754 |
I64x2Abs = 0xc0, |
| 755 |
I64x2Neg = 0xc1, |
| 756 |
// AnyTrue = 0xc2 |
| 757 |
I64x2AllTrue = 0xc3, |
| 758 |
I64x2Bitmask = 0xc4, |
| 759 |
// Unused = 0xc5 |
| 760 |
// Unused = 0xc6 |
| 761 |
I64x2ExtendLowI32x4S = 0xc7, |
| 762 |
I64x2ExtendHighI32x4S = 0xc8, |
| 763 |
I64x2ExtendLowI32x4U = 0xc9, |
| 764 |
I64x2ExtendHighI32x4U = 0xca, |
| 765 |
I64x2Shl = 0xcb, |
| 766 |
I64x2ShrS = 0xcc, |
| 767 |
I64x2ShrU = 0xcd, |
| 768 |
I64x2Add = 0xce, |
| 769 |
// Unused = 0xcf |
| 770 |
// Unused = 0xd0 |
| 771 |
I64x2Sub = 0xd1, |
| 772 |
// Unused = 0xd2 |
| 773 |
// Unused = 0xd3 |
| 774 |
// Unused = 0xd4 |
| 775 |
I64x2Mul = 0xd5, |
| 776 |
I64x2Eq = 0xd6, |
| 777 |
I64x2Ne = 0xd7, |
| 778 |
I64x2LtS = 0xd8, |
| 779 |
I64x2GtS = 0xd9, |
| 780 |
I64x2LeS = 0xda, |
| 781 |
I64x2GeS = 0xdb, |
| 782 |
I64x2ExtmulLowI32x4S = 0xdc, |
| 783 |
I64x2ExtmulHighI32x4S = 0xdd, |
| 784 |
I64x2ExtmulLowI32x4U = 0xde, |
| 785 |
I64x2ExtmulHighI32x4U = 0xdf, |
| 786 |
F32x4Abs = 0xe0, |
| 787 |
F32x4Neg = 0xe1, |
| 788 |
// Unused = 0xe2 |
| 789 |
F32x4Sqrt = 0xe3, |
| 790 |
F32x4Add = 0xe4, |
| 791 |
F32x4Sub = 0xe5, |
| 792 |
F32x4Mul = 0xe6, |
| 793 |
F32x4Div = 0xe7, |
| 794 |
F32x4Min = 0xe8, |
| 795 |
F32x4Max = 0xe9, |
| 796 |
F32x4PMin = 0xea, |
| 797 |
F32x4PMax = 0xeb, |
| 798 |
F64x2Abs = 0xec, |
| 799 |
F64x2Neg = 0xed, |
| 800 |
// Unused = 0xee |
| 801 |
F64x2Sqrt = 0xef, |
| 802 |
F64x2Add = 0xf0, |
| 803 |
F64x2Sub = 0xf1, |
| 804 |
F64x2Mul = 0xf2, |
| 805 |
F64x2Div = 0xf3, |
| 806 |
F64x2Min = 0xf4, |
| 807 |
F64x2Max = 0xf5, |
| 808 |
F64x2PMin = 0xf6, |
| 809 |
F64x2PMax = 0xf7, |
| 810 |
I32x4TruncSatF32x4S = 0xf8, |
| 811 |
I32x4TruncSatF32x4U = 0xf9, |
| 812 |
F32x4ConvertI32x4S = 0xfa, |
| 813 |
F32x4ConvertI32x4U = 0xfb, |
| 814 |
I32x4TruncSatF64x2SZero = 0xfc, |
| 815 |
I32x4TruncSatF64x2UZero = 0xfd, |
| 816 |
F64x2ConvertLowI32x4S = 0xfe, |
| 817 |
F64x2ConvertLowI32x4U = 0xff, |
| 818 |
I8x16RelaxedSwizzle = 0x100, |
| 819 |
I32x4RelaxedTruncF32x4S = 0x101, |
| 820 |
I32x4RelaxedTruncF32x4U = 0x102, |
| 821 |
I32x4RelaxedTruncF64x2SZero = 0x103, |
| 822 |
I32x4RelaxedTruncF64x2UZero = 0x104, |
| 823 |
F32x4RelaxedMadd = 0x105, |
| 824 |
F32x4RelaxedNmadd = 0x106, |
| 825 |
F64x2RelaxedMadd = 0x107, |
| 826 |
F64x2RelaxedNmadd = 0x108, |
| 827 |
I8x16RelaxedLaneSelect = 0x109, |
| 828 |
I16x8RelaxedLaneSelect = 0x10a, |
| 829 |
I32x4RelaxedLaneSelect = 0x10b, |
| 830 |
I64x2RelaxedLaneSelect = 0x10c, |
| 831 |
F32x4RelaxedMin = 0x10d, |
| 832 |
F32x4RelaxedMax = 0x10e, |
| 833 |
F64x2RelaxedMin = 0x10f, |
| 834 |
F64x2RelaxedMax = 0x110, |
| 835 |
I16x8RelaxedQ15MulrS = 0x111, |
| 836 |
I16x8RelaxedDotI8x16I7x16S = 0x112, |
| 837 |
I32x4RelaxedDotI8x16I7x16AddS = 0x113, |
| 838 |
|
| 839 |
// Reserved for Relaxed SIMD = 0x114-0x12f |
| 840 |
|
| 841 |
// Unused = 0x130 and up |
| 842 |
|
| 843 |
// Mozilla extensions |
| 844 |
MozPMADDUBSW = 0x201, |
| 845 |
|
| 846 |
Limit |
| 847 |
}; |
| 848 |
|
| 849 |
// Opcodes in the "miscellaneous" opcode space. |
| 850 |
enum class MiscOp { |
| 851 |
// Saturating float-to-int conversions |
| 852 |
I32TruncSatF32S = 0x00, |
| 853 |
I32TruncSatF32U = 0x01, |
| 854 |
I32TruncSatF64S = 0x02, |
| 855 |
I32TruncSatF64U = 0x03, |
| 856 |
I64TruncSatF32S = 0x04, |
| 857 |
I64TruncSatF32U = 0x05, |
| 858 |
I64TruncSatF64S = 0x06, |
| 859 |
I64TruncSatF64U = 0x07, |
| 860 |
|
| 861 |
// Bulk memory operations, per proposal as of February 2019. |
| 862 |
MemoryInit = 0x08, |
| 863 |
DataDrop = 0x09, |
| 864 |
MemoryCopy = 0x0a, |
| 865 |
MemoryFill = 0x0b, |
| 866 |
TableInit = 0x0c, |
| 867 |
ElemDrop = 0x0d, |
| 868 |
TableCopy = 0x0e, |
| 869 |
|
| 870 |
// Reftypes, per proposal as of February 2019. |
| 871 |
TableGrow = 0x0f, |
| 872 |
TableSize = 0x10, |
| 873 |
TableFill = 0x11, |
| 874 |
|
| 875 |
MemoryDiscard = 0x12, |
| 876 |
|
| 877 |
Limit |
| 878 |
}; |
| 879 |
|
| 880 |
// Opcodes from threads proposal as of June 30, 2017 |
| 881 |
enum class ThreadOp { |
| 882 |
// Wait and notify |
| 883 |
Notify = 0x00, |
| 884 |
I32Wait = 0x01, |
| 885 |
I64Wait = 0x02, |
| 886 |
Fence = 0x03, |
| 887 |
|
| 888 |
// Load and store |
| 889 |
I32AtomicLoad = 0x10, |
| 890 |
I64AtomicLoad = 0x11, |
| 891 |
I32AtomicLoad8U = 0x12, |
| 892 |
I32AtomicLoad16U = 0x13, |
| 893 |
I64AtomicLoad8U = 0x14, |
| 894 |
I64AtomicLoad16U = 0x15, |
| 895 |
I64AtomicLoad32U = 0x16, |
| 896 |
I32AtomicStore = 0x17, |
| 897 |
I64AtomicStore = 0x18, |
| 898 |
I32AtomicStore8U = 0x19, |
| 899 |
I32AtomicStore16U = 0x1a, |
| 900 |
I64AtomicStore8U = 0x1b, |
| 901 |
I64AtomicStore16U = 0x1c, |
| 902 |
I64AtomicStore32U = 0x1d, |
| 903 |
|
| 904 |
// Read-modify-write operations |
| 905 |
I32AtomicAdd = 0x1e, |
| 906 |
I64AtomicAdd = 0x1f, |
| 907 |
I32AtomicAdd8U = 0x20, |
| 908 |
I32AtomicAdd16U = 0x21, |
| 909 |
I64AtomicAdd8U = 0x22, |
| 910 |
I64AtomicAdd16U = 0x23, |
| 911 |
I64AtomicAdd32U = 0x24, |
| 912 |
|
| 913 |
I32AtomicSub = 0x25, |
| 914 |
I64AtomicSub = 0x26, |
| 915 |
I32AtomicSub8U = 0x27, |
| 916 |
I32AtomicSub16U = 0x28, |
| 917 |
I64AtomicSub8U = 0x29, |
| 918 |
I64AtomicSub16U = 0x2a, |
| 919 |
I64AtomicSub32U = 0x2b, |
| 920 |
|
| 921 |
I32AtomicAnd = 0x2c, |
| 922 |
I64AtomicAnd = 0x2d, |
| 923 |
I32AtomicAnd8U = 0x2e, |
| 924 |
I32AtomicAnd16U = 0x2f, |
| 925 |
I64AtomicAnd8U = 0x30, |
| 926 |
I64AtomicAnd16U = 0x31, |
| 927 |
I64AtomicAnd32U = 0x32, |
| 928 |
|
| 929 |
I32AtomicOr = 0x33, |
| 930 |
I64AtomicOr = 0x34, |
| 931 |
I32AtomicOr8U = 0x35, |
| 932 |
I32AtomicOr16U = 0x36, |
| 933 |
I64AtomicOr8U = 0x37, |
| 934 |
I64AtomicOr16U = 0x38, |
| 935 |
I64AtomicOr32U = 0x39, |
| 936 |
|
| 937 |
I32AtomicXor = 0x3a, |
| 938 |
I64AtomicXor = 0x3b, |
| 939 |
I32AtomicXor8U = 0x3c, |
| 940 |
I32AtomicXor16U = 0x3d, |
| 941 |
I64AtomicXor8U = 0x3e, |
| 942 |
I64AtomicXor16U = 0x3f, |
| 943 |
I64AtomicXor32U = 0x40, |
| 944 |
|
| 945 |
I32AtomicXchg = 0x41, |
| 946 |
I64AtomicXchg = 0x42, |
| 947 |
I32AtomicXchg8U = 0x43, |
| 948 |
I32AtomicXchg16U = 0x44, |
| 949 |
I64AtomicXchg8U = 0x45, |
| 950 |
I64AtomicXchg16U = 0x46, |
| 951 |
I64AtomicXchg32U = 0x47, |
| 952 |
|
| 953 |
// CompareExchange |
| 954 |
I32AtomicCmpXchg = 0x48, |
| 955 |
I64AtomicCmpXchg = 0x49, |
| 956 |
I32AtomicCmpXchg8U = 0x4a, |
| 957 |
I32AtomicCmpXchg16U = 0x4b, |
| 958 |
I64AtomicCmpXchg8U = 0x4c, |
| 959 |
I64AtomicCmpXchg16U = 0x4d, |
| 960 |
I64AtomicCmpXchg32U = 0x4e, |
| 961 |
|
| 962 |
Limit |
| 963 |
}; |
| 964 |
|
| 965 |
enum class BuiltinModuleFuncId { |
| 966 |
None = 0, |
| 967 |
|
| 968 |
// ------------------------------------------------------------------------ |
| 969 |
// These are part/suffix of the MozOp::CallBuiltinModuleFunc operators that are |
| 970 |
// emitted internally when compiling intrinsic modules and are rejected by wasm |
| 971 |
// validation. |
| 972 |
// See wasm/WasmBuiltinModule.yaml for the list. |
| 973 |
#define VISIT_BUILTIN_FUNC(op, export, sa_name, abitype, entry, uses_memory, \ |
| 974 |
inline_op, idx) \ |
| 975 |
op = idx + 1, // NOLINT |
| 976 |
FOR_EACH_BUILTIN_MODULE_FUNC(VISIT_BUILTIN_FUNC) |
| 977 |
#undef VISIT_BUILTIN_FUNC |
| 978 |
|
| 979 |
// Op limit. |
| 980 |
Limit |
| 981 |
}; |
| 982 |
|
| 983 |
enum class BuiltinInlineOp { |
| 984 |
None = 0, |
| 985 |
|
| 986 |
StringCast, |
| 987 |
StringTest, |
| 988 |
StringLength, |
| 989 |
|
| 990 |
// Op limit. |
| 991 |
Limit |
| 992 |
}; |
| 993 |
|
| 994 |
enum class BuiltinModuleId { |
| 995 |
SelfTest = 0, |
| 996 |
IntGemm, |
| 997 |
JSString, |
| 998 |
|
| 999 |
// Not technically a builtin module, but it uses most of the same machinery. |
| 1000 |
JSStringConstants, |
| 1001 |
}; |
| 1002 |
|
| 1003 |
enum class StackSwitchKind { |
| 1004 |
SwitchToSuspendable, |
| 1005 |
SwitchToMain, |
| 1006 |
ContinueOnSuspendable, |
| 1007 |
}; |
| 1008 |
|
| 1009 |
enum class UpdateSuspenderStateAction { |
| 1010 |
Enter, |
| 1011 |
Suspend, |
| 1012 |
Resume, |
| 1013 |
Leave, |
| 1014 |
}; |
| 1015 |
|
| 1016 |
enum class MozOp { |
| 1017 |
// ------------------------------------------------------------------------ |
| 1018 |
// These operators are emitted internally when compiling asm.js and are |
| 1019 |
// rejected by wasm validation. They are prefixed by MozPrefix. |
| 1020 |
|
| 1021 |
// asm.js-specific operators. They start at 1 so as to check for |
| 1022 |
// uninitialized (zeroed) storage. |
| 1023 |
TeeGlobal = 0x01, |
| 1024 |
I32Min, |
| 1025 |
I32Max, |
| 1026 |
I32Neg, |
| 1027 |
I32BitNot, |
| 1028 |
I32Abs, |
| 1029 |
F32TeeStoreF64, |
| 1030 |
F64TeeStoreF32, |
| 1031 |
I32TeeStore8, |
| 1032 |
I32TeeStore16, |
| 1033 |
I64TeeStore8, |
| 1034 |
I64TeeStore16, |
| 1035 |
I64TeeStore32, |
| 1036 |
I32TeeStore, |
| 1037 |
I64TeeStore, |
| 1038 |
F32TeeStore, |
| 1039 |
F64TeeStore, |
| 1040 |
F64Mod, |
| 1041 |
F64SinNative, |
| 1042 |
F64SinFdlibm, |
| 1043 |
F64CosNative, |
| 1044 |
F64CosFdlibm, |
| 1045 |
F64TanNative, |
| 1046 |
F64TanFdlibm, |
| 1047 |
F64Asin, |
| 1048 |
F64Acos, |
| 1049 |
F64Atan, |
| 1050 |
F64Exp, |
| 1051 |
F64Log, |
| 1052 |
F64Pow, |
| 1053 |
F64Atan2, |
| 1054 |
|
| 1055 |
// asm.js-style call_indirect with the callee evaluated first. |
| 1056 |
OldCallDirect, |
| 1057 |
OldCallIndirect, |
| 1058 |
|
| 1059 |
// Call a builtin module funcs. The operator has argument leb u32 to specify |
| 1060 |
// particular operation id. See BuiltinModuleFuncId above. |
| 1061 |
CallBuiltinModuleFunc, |
| 1062 |
|
| 1063 |
StackSwitch, |
| 1064 |
|
| 1065 |
Limit |
| 1066 |
}; |
| 1067 |
|
| 1068 |
struct OpBytes { |
| 1069 |
// b0 is a byte value but has a 16-bit representation to allow for a full |
| 1070 |
// 256-value range plus a sentinel Limit value. |
| 1071 |
uint16_t b0; |
| 1072 |
// b1 is a LEB128 value but 32 bits is enough for now. |
| 1073 |
uint32_t b1; |
| 1074 |
|
| 1075 |
explicit OpBytes(Op x) { |
| 1076 |
b0 = uint16_t(x); |
| 1077 |
b1 = 0; |
| 1078 |
} |
| 1079 |
OpBytes(uint16_t b0, uint16_t b1) : b0(b0), b1(b1) {} |
| 1080 |
OpBytes() = default; |
| 1081 |
|
| 1082 |
uint32_t toPacked() const { |
| 1083 |
// In practice all of our secondary bytecodes are actually 16-bit right now. |
| 1084 |
MOZ_RELEASE_ASSERT(b1 <= UINT16_MAX); |
| 1085 |
return b0 | (b1 << 16); |
| 1086 |
} |
| 1087 |
|
| 1088 |
static OpBytes fromPacked(uint32_t packed) { |
| 1089 |
return OpBytes(packed & 0xFFFF, packed >> 16); |
| 1090 |
} |
| 1091 |
|
| 1092 |
// Whether this opcode should have a breakpoint site inserted directly before |
| 1093 |
// the opcode in baseline when debugging. We use this as a heuristic to |
| 1094 |
// reduce the number of breakpoint sites. |
| 1095 |
bool shouldHaveBreakpoint() const { |
| 1096 |
switch (Op(b0)) { |
| 1097 |
// Block-like instructions don't get their own breakpoint site, a |
| 1098 |
// breakpoint can be used on instructions in the block. |
| 1099 |
case Op::Block: |
| 1100 |
case Op::Loop: |
| 1101 |
case Op::If: |
| 1102 |
case Op::Else: |
| 1103 |
case Op::Try: |
| 1104 |
case Op::Delegate: |
| 1105 |
case Op::Catch: |
| 1106 |
case Op::CatchAll: |
| 1107 |
case Op::End: |
| 1108 |
// Effect-less instructions without inputs are leaf nodes in expressions, |
| 1109 |
// a breakpoint can be used on instructions that consume these values. |
| 1110 |
case Op::LocalGet: |
| 1111 |
case Op::GlobalGet: |
| 1112 |
case Op::I32Const: |
| 1113 |
case Op::I64Const: |
| 1114 |
case Op::F32Const: |
| 1115 |
case Op::F64Const: |
| 1116 |
case Op::RefNull: |
| 1117 |
case Op::Drop: |
| 1118 |
return false; |
| 1119 |
default: |
| 1120 |
return true; |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
// Defined in WasmOpIter.cpp |
| 1125 |
const char* toString() const; |
| 1126 |
}; |
| 1127 |
|
| 1128 |
static const char NameSectionName[] = "name"; |
| 1129 |
static const char SourceMappingURLSectionName[] = "sourceMappingURL"; |
| 1130 |
static const char BranchHintingSectionName[] = "metadata.code.branch_hint"; |
| 1131 |
|
| 1132 |
enum class NameType { Module = 0, Function = 1, Local = 2 }; |
| 1133 |
|
| 1134 |
enum class FieldFlags { Mutable = 0x01, AllowedMask = 0x01 }; |
| 1135 |
|
| 1136 |
enum class FieldWideningOp { None, Signed, Unsigned }; |
| 1137 |
|
| 1138 |
// The WebAssembly spec hard-codes the virtual page size to be 64KiB and |
| 1139 |
// requires the size of linear memory to always be a multiple of 64KiB. |
| 1140 |
|
| 1141 |
static const unsigned PageSize = 64 * 1024; |
| 1142 |
static const unsigned PageBits = 16; |
| 1143 |
static_assert(PageSize == (1u << PageBits)); |
| 1144 |
|
| 1145 |
static const unsigned PageMask = ((1u << PageBits) - 1); |
| 1146 |
|
| 1147 |
// These limits are agreed upon with other engines for consistency. |
| 1148 |
|
| 1149 |
static const unsigned MaxRecGroups = 1000000; |
| 1150 |
static const unsigned MaxTypes = 1000000; |
| 1151 |
static const unsigned MaxSubTypingDepth = 63; |
| 1152 |
static const unsigned MaxTags = 1000000; |
| 1153 |
static const unsigned MaxFuncs = 1000000; |
| 1154 |
static const unsigned MaxTables = 100000; |
| 1155 |
static const unsigned MaxMemories = 100000; |
| 1156 |
static const unsigned MaxImports = 1000000; |
| 1157 |
static const unsigned MaxExports = 1000000; |
| 1158 |
static const unsigned MaxGlobals = 1000000; |
| 1159 |
static const unsigned MaxDataSegments = 100000; |
| 1160 |
static const unsigned MaxDataSegmentLengthPages = 16384; |
| 1161 |
static const unsigned MaxElemSegments = 10000000; |
| 1162 |
static const unsigned MaxElemSegmentLength = 10000000; |
| 1163 |
static const uint64_t MaxTable32ElemsValidation = UINT32_MAX; |
| 1164 |
static const uint64_t MaxTable64ElemsValidation = UINT64_MAX; |
| 1165 |
static const unsigned MaxTableElemsRuntime = 10000000; |
| 1166 |
static const unsigned MaxLocals = 50000; |
| 1167 |
static const unsigned MaxParams = 1000; |
| 1168 |
static const unsigned MaxResults = 1000; |
| 1169 |
static const unsigned MaxStructFields = 10000; |
| 1170 |
static const uint64_t MaxMemory32PagesValidation = uint64_t(1) << 16; |
| 1171 |
static const uint64_t MaxMemory64PagesValidation = uint64_t(1) << 48; |
| 1172 |
static const unsigned MaxStringBytes = 100000; |
| 1173 |
static const unsigned MaxModuleBytes = 1024 * 1024 * 1024; |
| 1174 |
static const unsigned MaxFunctionBytes = 7654321; |
| 1175 |
static const unsigned MaxArrayNewFixedElements = 10000; |
| 1176 |
|
| 1177 |
// Maximum payload size, in bytes, of a gc-proposal Array. Puts it fairly |
| 1178 |
// close to 2^31 without exposing us to potential danger at the signed-i32 |
| 1179 |
// wraparound boundary. Note that gc-proposal Struct sizes are limited by |
| 1180 |
// MaxStructFields above. Some code assumes that the payload size will fit in |
| 1181 |
// a uint32_t, hence the static assert. |
| 1182 |
static const unsigned MaxArrayPayloadBytes = 1987654321; |
| 1183 |
static_assert(uint64_t(MaxArrayPayloadBytes) < |
| 1184 |
(uint64_t(1) << (8 * sizeof(uint32_t)))); |
| 1185 |
|
| 1186 |
// These limits pertain to our WebAssembly implementation only. |
| 1187 |
|
| 1188 |
static const unsigned MaxTryTableCatches = 10000; |
| 1189 |
static const unsigned MaxBrTableElems = 65520; |
| 1190 |
static const unsigned MaxCodeSectionBytes = MaxModuleBytes; |
| 1191 |
static const unsigned MaxBranchHintValue = 2; |
| 1192 |
|
| 1193 |
// 512KiB should be enough, considering how Rabaldr uses the stack and |
| 1194 |
// what the standard limits are: |
| 1195 |
// |
| 1196 |
// - 1,000 parameters |
| 1197 |
// - 50,000 locals |
| 1198 |
// - 10,000 values on the eval stack (not an official limit) |
| 1199 |
// |
| 1200 |
// At sizeof(int64) bytes per slot this works out to about 480KiB. |
| 1201 |
|
| 1202 |
static const unsigned MaxFrameSize = 512 * 1024; |
| 1203 |
|
| 1204 |
// Limit for the amount of stacks present in the runtime. |
| 1205 |
static const size_t SuspendableStacksMaxCount = 100; |
| 1206 |
|
| 1207 |
// Max size of an allocated stack. |
| 1208 |
static const size_t SuspendableStackSize = 0x100000; |
| 1209 |
|
| 1210 |
// Size of additional space at the top of a suspendable stack. |
| 1211 |
// The space is allocated to C++ handlers such as error/trap handlers, |
| 1212 |
// or stack snapshots utilities. |
| 1213 |
static const size_t SuspendableRedZoneSize = 0x6000; |
| 1214 |
|
| 1215 |
// Total size of a suspendable stack to be reserved. |
| 1216 |
static constexpr size_t SuspendableStackPlusRedZoneSize = |
| 1217 |
SuspendableStackSize + SuspendableRedZoneSize; |
| 1218 |
|
| 1219 |
// Asserted by Decoder::readVarU32. |
| 1220 |
|
| 1221 |
static const unsigned MaxVarU32DecodedBytes = 5; |
| 1222 |
|
| 1223 |
// The CompileMode controls how compilation of a module is performed. |
| 1224 |
enum class CompileMode { |
| 1225 |
// Compile the module just once using a given tier. |
| 1226 |
Once, |
| 1227 |
// Compile the module first with baseline, then eagerly launch an ion |
| 1228 |
// background compile to compile the module again. |
| 1229 |
EagerTiering, |
| 1230 |
// Compile the module first with baseline, then lazily compile functions with |
| 1231 |
// ion when they trigger a hotness threshold. |
| 1232 |
LazyTiering, |
| 1233 |
}; |
| 1234 |
|
| 1235 |
// CompileState tracks where in the compilation process we are for a module. |
| 1236 |
enum class CompileState { |
| 1237 |
// We're compiling the module using the 'once' mode. |
| 1238 |
Once, |
| 1239 |
// We're compiling the module using the eager tiering mode. We're |
| 1240 |
// currently compiling the first tier. The second tier task will be launched |
| 1241 |
// once we're done compiling the first tier. |
| 1242 |
EagerTier1, |
| 1243 |
// We're compiling the module using the eager tiering mode. We're now |
| 1244 |
// compiling the second tier. |
| 1245 |
EagerTier2, |
| 1246 |
// We're compiling the module eagerly using the lazy tiering mode. We're |
| 1247 |
// compiling the first tier. |
| 1248 |
LazyTier1, |
| 1249 |
// We're compiling the module eagerly using the lazy tiering strategy. We're |
| 1250 |
// compiling the second tier. |
| 1251 |
LazyTier2, |
| 1252 |
}; |
| 1253 |
|
| 1254 |
// Typed enum for whether debugging is enabled. |
| 1255 |
|
| 1256 |
enum class DebugEnabled { False, True }; |
| 1257 |
|
| 1258 |
} // namespace wasm |
| 1259 |
} // namespace js |
| 1260 |
|
| 1261 |
#endif // wasm_constants_h |