v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-builtin-list.h
Go to the documentation of this file.
1// Copyright 2023 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_BUILTIN_LIST_H_
6#define V8_WASM_WASM_BUILTIN_LIST_H_
7
8#include "src/base/macros.h"
10#include "src/common/globals.h"
11
12#if !V8_ENABLE_WEBASSEMBLY
13#error This header should only be included if WebAssembly is enabled.
14#endif // !V8_ENABLE_WEBASSEMBLY
15
16namespace v8::internal::wasm {
17// Convenience macro listing all builtins called directly from wasm via the far
18// jump table. Note that the first few elements of the list coincide with
19// {compiler::TrapId}, order matters.
20#define WASM_BUILTINS_WITH_JUMP_TABLE_SLOT(V, VTRAP) /* */ \
21 FOREACH_WASM_TRAPREASON(VTRAP) \
22 V(WasmCompileLazy) \
23 V(WasmTriggerTierUp) \
24 V(WasmLiftoffFrameSetup) \
25 V(WasmDebugBreak) \
26 V(WasmInt32ToHeapNumber) \
27 V(WasmFloat64ToString) \
28 V(WasmStringToDouble) \
29 V(WasmIntToString) \
30 V(WasmTaggedNonSmiToInt32) \
31 V(WasmFloat32ToNumber) \
32 V(WasmFloat64ToNumber) \
33 V(WasmTaggedToFloat64) \
34 V(WasmAllocateJSArray) \
35 V(WasmI32AtomicWait) \
36 V(WasmI64AtomicWait) \
37 V(WasmGetOwnProperty) \
38 V(WasmRefFunc) \
39 V(WasmInternalFunctionCreateExternal) \
40 V(WasmMemoryGrow) \
41 V(WasmTableInit) \
42 V(WasmTableCopy) \
43 V(WasmTableFill) \
44 V(WasmTableGrow) \
45 V(WasmTableGet) \
46 V(WasmTableSet) \
47 V(WasmTableGetFuncRef) \
48 V(WasmTableSetFuncRef) \
49 V(WasmFunctionTableGet) \
50 V(WasmStackGuard) \
51 V(WasmGrowableStackGuard) \
52 V(WasmStackOverflow) \
53 V(WasmAllocateFixedArray) \
54 V(WasmThrow) \
55 V(WasmRethrow) \
56 V(WasmThrowRef) \
57 V(WasmRethrowExplicitContext) \
58 V(WasmHandleStackOverflow) \
59 V(WasmTraceEnter) \
60 V(WasmTraceExit) \
61 V(WasmTraceMemory) \
62 V(BigIntToI32Pair) \
63 V(BigIntToI64) \
64 V(CallRefIC) \
65 V(CallIndirectIC) \
66 V(DoubleToI) \
67 V(I32PairToBigInt) \
68 V(I64ToBigInt) \
69 V(RecordWriteSaveFP) \
70 V(RecordWriteIgnoreFP) \
71 V(ThrowDataViewTypeError) \
72 V(ThrowDataViewDetachedError) \
73 V(ThrowDataViewOutOfBounds) \
74 V(ThrowIndexOfCalledOnNull) \
75 V(ThrowToLowerCaseCalledOnNull) \
76 IF_INTL(V, StringToLowerCaseIntl) \
77 IF_TSAN(V, TSANRelaxedStore8IgnoreFP) \
78 IF_TSAN(V, TSANRelaxedStore8SaveFP) \
79 IF_TSAN(V, TSANRelaxedStore16IgnoreFP) \
80 IF_TSAN(V, TSANRelaxedStore16SaveFP) \
81 IF_TSAN(V, TSANRelaxedStore32IgnoreFP) \
82 IF_TSAN(V, TSANRelaxedStore32SaveFP) \
83 IF_TSAN(V, TSANRelaxedStore64IgnoreFP) \
84 IF_TSAN(V, TSANRelaxedStore64SaveFP) \
85 IF_TSAN(V, TSANSeqCstStore8IgnoreFP) \
86 IF_TSAN(V, TSANSeqCstStore8SaveFP) \
87 IF_TSAN(V, TSANSeqCstStore16IgnoreFP) \
88 IF_TSAN(V, TSANSeqCstStore16SaveFP) \
89 IF_TSAN(V, TSANSeqCstStore32IgnoreFP) \
90 IF_TSAN(V, TSANSeqCstStore32SaveFP) \
91 IF_TSAN(V, TSANSeqCstStore64IgnoreFP) \
92 IF_TSAN(V, TSANSeqCstStore64SaveFP) \
93 IF_TSAN(V, TSANRelaxedLoad32IgnoreFP) \
94 IF_TSAN(V, TSANRelaxedLoad32SaveFP) \
95 IF_TSAN(V, TSANRelaxedLoad64IgnoreFP) \
96 IF_TSAN(V, TSANRelaxedLoad64SaveFP) \
97 V(WasmAllocateArray_Uninitialized) \
98 V(WasmArrayCopy) \
99 V(WasmArrayNewSegment) \
100 V(WasmArrayInitSegment) \
101 V(WasmAllocateStructWithRtt) \
102 V(WasmAllocateDescriptorStruct) \
103 V(WasmOnStackReplace) \
104 V(WasmReject) \
105 V(WasmStringNewWtf8) \
106 V(WasmStringNewWtf16) \
107 V(WasmStringConst) \
108 V(WasmStringMeasureUtf8) \
109 V(WasmStringMeasureWtf8) \
110 V(WasmStringEncodeWtf8) \
111 V(WasmStringEncodeWtf16) \
112 V(WasmStringConcat) \
113 V(WasmStringEqual) \
114 V(WasmStringIsUSVSequence) \
115 V(WasmStringAsWtf16) \
116 V(WasmStringViewWtf16GetCodeUnit) \
117 V(WasmStringCodePointAt) \
118 V(WasmStringViewWtf16Encode) \
119 V(WasmStringViewWtf16Slice) \
120 V(WasmStringNewWtf8Array) \
121 V(WasmStringNewWtf16Array) \
122 V(WasmStringEncodeWtf8Array) \
123 V(WasmStringToUtf8Array) \
124 V(WasmStringEncodeWtf16Array) \
125 V(WasmStringAsWtf8) \
126 V(WasmStringViewWtf8Advance) \
127 V(WasmStringViewWtf8Encode) \
128 V(WasmStringViewWtf8Slice) \
129 V(WasmStringAsIter) \
130 V(WasmStringViewIterNext) \
131 V(WasmStringViewIterAdvance) \
132 V(WasmStringViewIterRewind) \
133 V(WasmStringViewIterSlice) \
134 V(StringCompare) \
135 V(StringIndexOf) \
136 V(WasmStringFromCodePoint) \
137 V(WasmStringHash) \
138 V(WasmAnyConvertExtern) \
139 V(WasmStringFromDataSegment) \
140 V(StringAdd_CheckNone) \
141 V(DebugPrintFloat64) \
142 V(DebugPrintWordPtr) \
143 V(WasmFastApiCallTypeCheckAndUpdateIC) \
144 V(DeoptimizationEntry_Eager) \
145 V(WasmLiftoffDeoptFinish) \
146 V(WasmPropagateException) \
147 IF_SHADOW_STACK(V, AdaptShadowStackForDeopt)
148
149// Other wasm builtins that are not called via the far jump table, but need the
150// {is_wasm} assembler option for proper stack-switching support.
151#define WASM_BUILTINS_WITHOUT_JUMP_TABLE_SLOT(V) \
152 V(IterableToFixedArrayForWasm) \
153 V(WasmAllocateInYoungGeneration) \
154 V(WasmAllocateInOldGeneration) \
155 V(WasmAllocateZeroedFixedArray) \
156 V(WasmSuspend) \
157 V(WasmToJsWrapperInvalidSig) \
158 V(WasmTrap) \
159 V(WasmTrapHandlerThrowTrap)
160
161#define WASM_BUILTIN_LIST(V, VTRAP) \
162 WASM_BUILTINS_WITH_JUMP_TABLE_SLOT(V, VTRAP) \
163 WASM_BUILTINS_WITHOUT_JUMP_TABLE_SLOT(V)
164
165namespace detail {
166constexpr std::array<uint8_t, static_cast<int>(Builtin::kFirstBytecodeHandler)>
168 std::array<uint8_t, static_cast<int>(Builtin::kFirstBytecodeHandler)>
169 result{};
170 uint8_t next_index = 0;
171#define DEF_INIT_LOOKUP(NAME) \
172 result[static_cast<int>(Builtin::k##NAME)] = next_index++;
173#define DEF_INIT_LOOKUP_TRAP(NAME) DEF_INIT_LOOKUP(ThrowWasm##NAME)
175#undef DEF_INIT_LOOKUP_TRAP
176#undef DEF_INIT_LOOKUP
177 return result;
178}
179} // namespace detail
181 public:
182 static constexpr int JumptableIndexForBuiltin(Builtin builtin) {
183 int result = kBuiltinToFarJumpTableIndex[static_cast<int>(builtin)];
185 return result;
186 }
187
188 static constexpr Builtin BuiltinForJumptableIndex(int index) {
190 DCHECK_EQ(index, kBuiltinToFarJumpTableIndex[static_cast<int>(result)]);
191 return result;
192 }
193
194 static constexpr int BuiltinCount() { return kBuiltinCount; }
195
196 static bool IsWasmBuiltinId(Builtin id) {
197 switch (id) {
198#define BUILTIN_ID(Name) \
199 case Builtin::k##Name: \
200 return true;
201#define BUILTIN_ID_TRAP(Name) \
202 case Builtin::kThrowWasm##Name: \
203 return true;
205 default:
206 return false;
207 }
208 }
209
210 private:
211#define BUILTIN_COUNTER(NAME) +1
212 static constexpr int kBuiltinCount =
214#undef BUILTIN_COUNTER
215
216 static constexpr auto kFarJumpTableIndexToBuiltin =
218 size_t next_index = 0;
219#define DEF_INIT_LOOKUP(NAME) \
220 if (index == next_index) { \
221 return Builtin::k##NAME; \
222 } \
223 ++next_index;
224#define DEF_INIT_LOOKUP_TRAP(NAME) DEF_INIT_LOOKUP(ThrowWasm##NAME)
227#undef DEF_INIT_LOOKUP_TRAP
228#undef DEF_INIT_LOOKUP
230 });
231
232 static constexpr auto kBuiltinToFarJumpTableIndex =
234};
235
236} // namespace v8::internal::wasm
237
238#undef WASM_BUILTIN_LIST
239#undef WASM_BUILTINS_WITHOUT_JUMP_TABLE_SLOT
240#undef WASM_BUILTINS_WITH_JUMP_TABLE_SLOT
241
242#endif // V8_WASM_WASM_BUILTIN_LIST_H_
static constexpr auto kFarJumpTableIndexToBuiltin
static constexpr int JumptableIndexForBuiltin(Builtin builtin)
static constexpr Builtin BuiltinForJumptableIndex(int index)
static bool IsWasmBuiltinId(Builtin id)
static constexpr auto kBuiltinToFarJumpTableIndex
ZoneVector< RpoNumber > & result
Builtin builtin
constexpr auto make_array(Function f)
constexpr std::array< uint8_t, static_cast< int >(Builtin::kFirstBytecodeHandler)> InitBuiltinToFarJumpTableIndex()
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define BUILTIN_COUNTER(NAME)
#define WASM_BUILTIN_LIST(V, VTRAP)
#define DEF_INIT_LOOKUP(NAME)
#define BUILTIN_ID(Name)
#define DEF_INIT_LOOKUP_TRAP(NAME)
#define BUILTIN_ID_TRAP(Name)
#define WASM_BUILTINS_WITH_JUMP_TABLE_SLOT(V, VTRAP)