// Copyright 2017 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/builtins/builtins-wasm-gen.h" #include "src/builtins/builtins-utils-gen.h" #include "src/codegen/code-stub-assembler.h" #include "src/codegen/interface-descriptors.h" #include "src/objects/objects-inl.h" #include "src/wasm/wasm-objects.h" namespace v8 { namespace internal { TNode WasmBuiltinsAssembler::LoadInstanceFromFrame() { return CAST(LoadFromParentFrame(WasmFrameConstants::kWasmInstanceOffset)); } TNode WasmBuiltinsAssembler::LoadContextFromInstance( TNode instance) { return CAST(Load(MachineType::AnyTagged(), instance, IntPtrConstant(WasmInstanceObject::kNativeContextOffset - kHeapObjectTag))); } TNode WasmBuiltinsAssembler::LoadTablesFromInstance( TNode instance) { return LoadObjectField(instance, WasmInstanceObject::kTablesOffset); } TNode WasmBuiltinsAssembler::LoadInternalFunctionsFromInstance( TNode instance) { return LoadObjectField( instance, WasmInstanceObject::kWasmInternalFunctionsOffset); } TNode WasmBuiltinsAssembler::LoadManagedObjectMapsFromInstance( TNode instance) { return LoadObjectField( instance, WasmInstanceObject::kManagedObjectMapsOffset); } TF_BUILTIN(WasmFloat32ToNumber, WasmBuiltinsAssembler) { auto val = UncheckedParameter(Descriptor::kValue); Return(ChangeFloat32ToTagged(val)); } TF_BUILTIN(WasmFloat64ToNumber, WasmBuiltinsAssembler) { auto val = UncheckedParameter(Descriptor::kValue); Return(ChangeFloat64ToTagged(val)); } TF_BUILTIN(WasmI32AtomicWait32, WasmBuiltinsAssembler) { if (!Is32()) { Unreachable(); return; } auto address = UncheckedParameter(Descriptor::kAddress); TNode address_number = ChangeUint32ToTagged(address); auto expected_value = UncheckedParameter(Descriptor::kExpectedValue); TNode expected_value_number = ChangeInt32ToTagged(expected_value); auto timeout_low = UncheckedParameter(Descriptor::kTimeoutLow); auto timeout_high = UncheckedParameter(Descriptor::kTimeoutHigh); TNode timeout = BigIntFromInt32Pair(timeout_low, timeout_high); TNode instance = LoadInstanceFromFrame(); TNode context = LoadContextFromInstance(instance); TNode result_smi = CAST(CallRuntime(Runtime::kWasmI32AtomicWait, context, instance, address_number, expected_value_number, timeout)); Return(Unsigned(SmiToInt32(result_smi))); } TF_BUILTIN(WasmI64AtomicWait32, WasmBuiltinsAssembler) { if (!Is32()) { Unreachable(); return; } auto address = UncheckedParameter(Descriptor::kAddress); TNode address_number = ChangeUint32ToTagged(address); auto expected_value_low = UncheckedParameter(Descriptor::kExpectedValueLow); auto expected_value_high = UncheckedParameter(Descriptor::kExpectedValueHigh); TNode expected_value = BigIntFromInt32Pair(expected_value_low, expected_value_high); auto timeout_low = UncheckedParameter(Descriptor::kTimeoutLow); auto timeout_high = UncheckedParameter(Descriptor::kTimeoutHigh); TNode timeout = BigIntFromInt32Pair(timeout_low, timeout_high); TNode instance = LoadInstanceFromFrame(); TNode context = LoadContextFromInstance(instance); TNode result_smi = CAST(CallRuntime(Runtime::kWasmI64AtomicWait, context, instance, address_number, expected_value, timeout)); Return(Unsigned(SmiToInt32(result_smi))); } TF_BUILTIN(JSToWasmLazyDeoptContinuation, WasmBuiltinsAssembler) { // Reset thread_in_wasm_flag. TNode thread_in_wasm_flag_address_address = ExternalConstant( ExternalReference::thread_in_wasm_flag_address_address(isolate())); auto thread_in_wasm_flag_address = Load(thread_in_wasm_flag_address_address); StoreNoWriteBarrier(MachineRepresentation::kWord32, thread_in_wasm_flag_address, Int32Constant(0)); // Return the argument. auto value = Parameter(Descriptor::kArgument); Return(value); } } // namespace internal } // namespace v8