v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-constants.h
Go to the documentation of this file.
1// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_WASM_WASM_CONSTANTS_H_
6#define V8_WASM_WASM_CONSTANTS_H_
7
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
10#endif // !V8_ENABLE_WEBASSEMBLY
11
12#include <cstddef>
13#include <cstdint>
14
15#include "src/common/globals.h"
16
17namespace v8 {
18namespace internal {
19namespace wasm {
20
21// Binary encoding of the module header.
22constexpr uint32_t kWasmMagic = 0x6d736100;
23constexpr uint32_t kWasmVersion = 0x01;
24
25// Binary encoding of value and heap types.
26enum ValueTypeCode : uint8_t {
27 // Current value types
28 kVoidCode = 0x40,
29 kI32Code = 0x7f, // -0x01
30 kI64Code = 0x7e, // -0x02
31 kF32Code = 0x7d, // -0x03
32 kF64Code = 0x7c, // -0x04
33 kS128Code = 0x7b, // -0x05
34 kI8Code = 0x78, // -0x08, packed type
35 kI16Code = 0x77, // -0x09, packed type
36 kF16Code = 0x76, // -0x0a, packed type
37 kNoExnCode = 0x74, // -0x0c
38 kNoFuncCode = 0x73, // -0x0d
39 kNoExternCode = 0x72, // -0x0e
40 kNoneCode = 0x71, // -0x0f
41 kFuncRefCode = 0x70, // -0x10
42 kExternRefCode = 0x6f, // -0x11
43 kAnyRefCode = 0x6e, // -0x12
44 kEqRefCode = 0x6d, // -0x13
45 kI31RefCode = 0x6c, // -0x14
46 kStructRefCode = 0x6b, // -0x15
47 kArrayRefCode = 0x6a, // -0x16
48 kRefCode = 0x64, // -0x1c
49 kRefNullCode = 0x63, // -0x1d
50 // Non-finalized proposals below.
51 kExactCode = 0x62, // -0x1e
52 kExnRefCode = 0x69, // -0x17
53 kContRefCode = 0x68, // -0x18
54 kNoContCode = 0x75, // -0x0b
55 kStringRefCode = 0x67, // -0x19
56 kStringViewWtf8Code = 0x66, // -0x1a
57 kStringViewWtf16Code = 0x60, // -0x20
58 kStringViewIterCode = 0x61, // -0x1f
59
60 // For decoding, we build an array for all heap types with these bounds:
61 kFirstHeapTypeCode = kStringViewWtf16Code, // Lowest assigned code.
62 kLastHeapTypeCode = kNoContCode, // Highest assigned code.
63};
64
65// Binary encoding of type definitions.
66constexpr uint8_t kSharedFlagCode = 0x65;
67constexpr uint8_t kWasmFunctionTypeCode = 0x60;
68constexpr uint8_t kWasmStructTypeCode = 0x5f;
69constexpr uint8_t kWasmArrayTypeCode = 0x5e;
70constexpr uint8_t kWasmContTypeCode = 0x5d;
71constexpr uint8_t kWasmSubtypeCode = 0x50;
72constexpr uint8_t kWasmSubtypeFinalCode = 0x4f;
73constexpr uint8_t kWasmRecursiveTypeGroupCode = 0x4e;
74constexpr uint8_t kWasmDescriptorCode = 0x4d;
75constexpr uint8_t kWasmDescribesCode = 0x4c;
76
77// Binary encoding of import/export kinds.
85
86// The limits structure: valid for both memory and table limits.
97
98// Flags for data and element segments.
99enum SegmentFlags : uint8_t {
100 kActiveNoIndex = 0, // Active segment with a memory/table index of zero.
101 kPassive = 1, // Passive segment.
102 kActiveWithIndex = 2, // Active segment with a given memory/table index.
103};
104
105// Binary encoding of sections identifiers.
106enum SectionCode : int8_t {
107 kUnknownSectionCode = 0, // code for unknown sections
108 kTypeSectionCode = 1, // Function signature declarations
109 kImportSectionCode = 2, // Import declarations
110 kFunctionSectionCode = 3, // Function declarations
111 kTableSectionCode = 4, // Indirect function table and others
112 kMemorySectionCode = 5, // Memory attributes
113 kGlobalSectionCode = 6, // Global declarations
114 kExportSectionCode = 7, // Exports
115 kStartSectionCode = 8, // Start function declaration
116 kElementSectionCode = 9, // Elements section
117 kCodeSectionCode = 10, // Function code
118 kDataSectionCode = 11, // Data segments
119 kDataCountSectionCode = 12, // Number of data segments
120 kTagSectionCode = 13, // Tag section
121 kStringRefSectionCode = 14, // Stringref literal section
122
123 // The following sections are custom sections, and are identified using a
124 // string rather than an integer. Their enumeration values are not guaranteed
125 // to be consistent.
126 kNameSectionCode, // Name section (encoded as a string)
127 kSourceMappingURLSectionCode, // Source Map URL section
128 kDebugInfoSectionCode, // DWARF section .debug_info
129 kExternalDebugInfoSectionCode, // Section encoding the external symbol path
130 kBuildIdSectionCode, // Unique build id to match the symbol file
131 kInstTraceSectionCode, // Instruction trace section
132 kCompilationHintsSectionCode, // Compilation hints section
133 kBranchHintsSectionCode, // Branch hints section
134
135 // Helper values
139};
140
141// Binary encoding of compilation hints.
142constexpr uint8_t kDefaultCompilationHint = 0x0;
143constexpr uint8_t kNoCompilationHint = kMaxUInt8;
144
145// Binary encoding of name section kinds.
146enum NameSectionKindCode : uint8_t {
150 // https://github.com/WebAssembly/extended-name-section/
158 // https://github.com/WebAssembly/gc/issues/193
160 // https://github.com/WebAssembly/exception-handling/pull/213
162};
163
171
172enum SwitchKind : uint8_t {
174 kSwitch = 0x1,
176};
177
178constexpr size_t kWasmPageSize = 0x10000;
179constexpr uint32_t kWasmPageSizeLog2 = 16;
180static_assert(kWasmPageSize == size_t{1} << kWasmPageSizeLog2, "consistency");
181
182// TODO(wasm): Wrap WasmCodePosition in a struct.
185
186constexpr uint32_t kExceptionAttribute = 0;
187
188constexpr int kAnonymousFuncIndex = -1;
189
190// This needs to survive round-tripping through a Smi without changing
191// its value.
192constexpr uint32_t kInvalidCanonicalIndex = static_cast<uint32_t>(-1);
193static_assert(static_cast<uint32_t>(Internals::SmiValue(Internals::IntToSmi(
194 static_cast<int>(kInvalidCanonicalIndex)))) ==
196
197// The number of calls to an exported Wasm function that will be handled
198// by the generic wrapper. Once the budget is exhausted, a specific wrapper
199// is to be compiled for the function's signature.
200// The abstract goal of the tiering strategy for the js-to-wasm wrappers is to
201// use the generic wrapper as much as possible (less space, no need to compile),
202// but fall back to compiling a specific wrapper for any function (signature)
203// that is used often enough for the generic wrapper's small execution penalty
204// to start adding up.
205// So, when choosing a value for the initial budget, we are interested in a
206// value that skips on tiering up functions that are called only a few times and
207// the tier-up only wastes resources, but triggers compilation of specific
208// wrappers early on for those functions that have the potential to be called
209// often enough.
210constexpr uint32_t kGenericWrapperBudget = 1000;
211
212// The minimum length of supertype arrays for wasm-gc types. Having a size > 0
213// gives up some module size for faster access to the supertypes.
214constexpr uint32_t kMinimumSupertypeArraySize = 3;
215
216// Maximum number of call targets tracked per call.
217constexpr int kMaxPolymorphism = 4;
218
219// A struct field beyond this limit needs an explicit null check (trapping null
220// access not guaranteed to behave properly).
222
223#if V8_TARGET_ARCH_X64
224constexpr int32_t kOSRTargetOffset = 4 * kSystemPointerSize;
225#endif
226
227} // namespace wasm
228} // namespace internal
229} // namespace v8
230
231#endif // V8_WASM_WASM_CONSTANTS_H_
static V8_INLINE constexpr Address IntToSmi(int value)
static V8_INLINE constexpr int SmiValue(Address value)
constexpr uint8_t kNoCompilationHint
constexpr int kAnonymousFuncIndex
constexpr uint32_t kWasmPageSizeLog2
constexpr uint32_t kWasmMagic
constexpr uint8_t kWasmRecursiveTypeGroupCode
constexpr uint32_t kMinimumSupertypeArraySize
constexpr uint8_t kSharedFlagCode
constexpr uint8_t kWasmDescribesCode
constexpr uint8_t kWasmSubtypeCode
constexpr uint8_t kWasmContTypeCode
constexpr WasmCodePosition kNoCodePosition
constexpr uint32_t kInvalidCanonicalIndex
constexpr uint32_t kGenericWrapperBudget
constexpr uint8_t kWasmStructTypeCode
constexpr int kMaxPolymorphism
constexpr uint8_t kWasmSubtypeFinalCode
constexpr uint8_t kWasmFunctionTypeCode
constexpr int kMaxStructFieldIndexForImplicitNullCheck
constexpr uint8_t kDefaultCompilationHint
constexpr size_t kWasmPageSize
constexpr uint32_t kWasmVersion
constexpr uint8_t kWasmArrayTypeCode
constexpr uint32_t kExceptionAttribute
constexpr uint8_t kWasmDescriptorCode
constexpr int kMaxUInt8
Definition globals.h:378
constexpr int kSystemPointerSize
Definition globals.h:410
Definition c-api.cc:87