v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
builtins-wasm-gen.cc
Go to the documentation of this file.
1// Copyright 2017 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
6
10#include "src/objects/map-inl.h"
13
14namespace v8::internal {
15
17
18TNode<WasmTrustedInstanceData>
20 return CAST(LoadFromParentFrame(WasmFrameConstants::kWasmInstanceDataOffset));
21}
22
27 instance_object, WasmInstanceObject::kTrustedDataOffset,
28 kWasmTrustedInstanceDataIndirectPointerTag));
29}
30
33 WasmFrameConstants::kWasmInstanceDataOffset);
34 TVARIABLE(NativeContext, context_result);
35 TNode<HeapObject> function_or_instance =
36 CAST(LoadFromParentFrame(WasmFrameConstants::kWasmInstanceDataOffset));
37 Label is_js_function(this);
38 Label is_import_data(this);
39 Label done(this);
40 TNode<Uint16T> instance_type =
41 LoadMapInstanceType(LoadMap(function_or_instance));
42 GotoIf(IsJSFunctionInstanceType(instance_type), &is_js_function);
43 GotoIf(Word32Equal(instance_type, Int32Constant(WASM_IMPORT_DATA_TYPE)),
44 &is_import_data);
45 context_result = LoadContextFromInstanceData(CAST(function_or_instance));
46 Goto(&done);
47
48 BIND(&is_js_function);
49 TNode<JSFunction> function = CAST(function_or_instance);
50 TNode<Context> context =
51 LoadObjectField<Context>(function, JSFunction::kContextOffset);
52 context_result = LoadNativeContext(context);
53 Goto(&done);
54
55 BIND(&is_import_data);
56 TNode<WasmImportData> import_data = CAST(function_or_instance);
57 context_result = LoadObjectField<NativeContext>(
58 import_data, WasmImportData::kNativeContextOffset);
59 Goto(&done);
60
61 BIND(&done);
62 return context_result.value();
63}
64
72
81
87
93
99
101#ifdef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
102 TNode<ExternalReference> string_to_float64 =
103 ExternalConstant(ExternalReference::wasm_string_to_f64());
105 CallCFunction(string_to_float64, MachineType::Float64(),
106 std::make_pair(MachineType::AnyTagged(), input)));
107#else
108 // We could support the fast path by passing the float via a stackslot, see
109 // MachineOperatorBuilder::StackSlot.
111 CallRuntime(Runtime::kStringParseFloat, NoContextConstant(), input);
113#endif
114}
115
116TF_BUILTIN(WasmFloat32ToNumber, WasmBuiltinsAssembler) {
117 auto val = UncheckedParameter<Float32T>(Descriptor::kValue);
118 Return(ChangeFloat32ToTagged(val));
119}
120
121TF_BUILTIN(WasmFloat64ToNumber, WasmBuiltinsAssembler) {
122 auto val = UncheckedParameter<Float64T>(Descriptor::kValue);
123 Return(ChangeFloat64ToTagged(val));
124}
125
126TF_BUILTIN(WasmFloat64ToString, WasmBuiltinsAssembler) {
127 TNode<Float64T> val = UncheckedParameter<Float64T>(Descriptor::kValue);
128 // Having to allocate a HeapNumber is a bit unfortunate, but the subsequent
129 // runtime call will have to allocate a string anyway, which probably
130 // dwarfs the cost of one more small allocation here.
131 TNode<Number> tagged = ChangeFloat64ToTagged(val);
132 Return(NumberToString(tagged));
133}
134
135TF_BUILTIN(JSToWasmLazyDeoptContinuation, WasmBuiltinsAssembler) {
136 // Reset thread_in_wasm_flag.
137 TNode<ExternalReference> thread_in_wasm_flag_address_address =
138 ExternalConstant(
139 ExternalReference::thread_in_wasm_flag_address_address(isolate()));
140 auto thread_in_wasm_flag_address =
141 Load<RawPtrT>(thread_in_wasm_flag_address_address);
142 StoreNoWriteBarrier(MachineRepresentation::kWord32,
143 thread_in_wasm_flag_address, Int32Constant(0));
144
145 // Return the argument.
146 auto value = Parameter<Object>(Descriptor::kArgument);
147 Return(value);
148}
149
150TF_BUILTIN(WasmToJsWrapperCSA, WasmBuiltinsAssembler) {
151 TorqueStructWasmToJSResult result = WasmToJSWrapper(
152 UncheckedParameter<WasmImportData>(Descriptor::kWasmImportData));
153 PopAndReturn(result.popCount, result.result0, result.result1, result.result2,
154 result.result3);
155}
156
157TF_BUILTIN(WasmToJsWrapperInvalidSig, WasmBuiltinsAssembler) {
159 UncheckedParameter<WasmImportData>(Descriptor::kWasmImportData);
160 TNode<Context> context =
161 LoadObjectField<Context>(data, WasmImportData::kNativeContextOffset);
162
163 CallRuntime(Runtime::kWasmThrowJSTypeError, context);
164 Unreachable();
165}
166
168
169} // namespace v8::internal
#define BIND(label)
#define TVARIABLE(...)
#define TF_BUILTIN(Name, AssemblerBase)
TNode< TrustedObject > LoadTrustedPointerFromObject(TNode< HeapObject > object, int offset, IndirectPointerTag tag)
TNode< T > LoadObjectField(TNode< HeapObject > object, int offset)
TNode< Object > LoadFromParentFrame(int offset)
TNode< Uint16T > LoadMapInstanceType(TNode< Map > map)
TNode< NativeContext > LoadNativeContext(TNode< Context > context)
TNode< Map > LoadMap(TNode< HeapObject > object)
TNode< Float64T > ChangeNumberToFloat64(TNode< Number > value)
TNode< BoolT > IsJSFunctionInstanceType(TNode< Int32T > instance_type)
static constexpr MachineType Float64()
static constexpr MachineType AnyTagged()
static TNode UncheckedCast(compiler::Node *node)
Definition tnode.h:413
TNode< FixedArray > LoadTablesFromInstanceData(TNode< WasmTrustedInstanceData >)
TNode< NativeContext > LoadContextFromInstanceData(TNode< WasmTrustedInstanceData >)
TNode< WasmTrustedInstanceData > LoadSharedPartFromInstanceData(TNode< WasmTrustedInstanceData >)
TNode< WasmTrustedInstanceData > LoadInstanceDataFromFrame()
TNode< FixedArray > LoadFuncRefsFromInstanceData(TNode< WasmTrustedInstanceData >)
TNode< WasmTrustedInstanceData > LoadTrustedDataFromInstance(TNode< WasmInstanceObject >)
TNode< NativeContext > LoadContextFromWasmOrJsFrame()
TNode< Float64T > StringToFloat64(TNode< String >)
TNode< FixedArray > LoadManagedObjectMapsFromInstanceData(TNode< WasmTrustedInstanceData >)
Node * LoadProtectedPointerFromObject(TNode< Object > object, TNode< IntPtrT > offset)
TNode< IntPtrT > IntPtrConstant(intptr_t value)
void GotoIf(TNode< IntegralT > condition, Label *true_label, GotoHint goto_hint=GotoHint::kNone)
Node * Load(MachineType type, Node *base)
TNode< ExternalReference > ExternalConstant(ExternalReference address)
TNode< Int32T > Int32Constant(int32_t value)
Node * CallCFunction(Node *function, std::optional< MachineType > return_type, CArgs... cargs)
TNode< BoolT > Word32Equal(TNode< Word32T > left, TNode< Word32T > right)
TNode< T > CallRuntime(Runtime::FunctionId function, TNode< Object > context, TArgs... args)
#define CAST(x)
Isolate * isolate
ZoneVector< RpoNumber > & result
const int kHeapObjectTag
Definition v8-internal.h:72
kMemory0SizeOffset Address kNewAllocationLimitAddressOffset Address kOldAllocationLimitAddressOffset uint8_t kGlobalsStartOffset kJumpTableStartOffset std::atomic< uint32_t > kTieringBudgetArrayOffset kDataSegmentStartsOffset kElementSegmentsOffset instance_object
i::Address Load(i::Address address)
Definition unwinder.cc:19