11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_CODEGEN_X64_INTERFACE_DESCRIPTORS_X64_INL_H_ 61cb0ef41Sopenharmony_ci#define V8_CODEGEN_X64_INTERFACE_DESCRIPTORS_X64_INL_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_X64 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#include "src/codegen/interface-descriptors.h" 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cinamespace v8 { 131cb0ef41Sopenharmony_cinamespace internal { 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciconstexpr auto CallInterfaceDescriptor::DefaultRegisterArray() { 161cb0ef41Sopenharmony_ci auto registers = RegisterArray(rax, rbx, rcx, rdx, rdi); 171cb0ef41Sopenharmony_ci STATIC_ASSERT(registers.size() == kMaxBuiltinRegisterParams); 181cb0ef41Sopenharmony_ci return registers; 191cb0ef41Sopenharmony_ci} 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci#if DEBUG 221cb0ef41Sopenharmony_citemplate <typename DerivedDescriptor> 231cb0ef41Sopenharmony_civoid StaticCallInterfaceDescriptor<DerivedDescriptor>:: 241cb0ef41Sopenharmony_ci VerifyArgumentRegisterCount(CallInterfaceDescriptorData* data, 251cb0ef41Sopenharmony_ci int nof_expected_args) { 261cb0ef41Sopenharmony_ci RegList allocatable_regs = data->allocatable_registers(); 271cb0ef41Sopenharmony_ci if (nof_expected_args >= 1) DCHECK(allocatable_regs.has(arg_reg_1)); 281cb0ef41Sopenharmony_ci if (nof_expected_args >= 2) DCHECK(allocatable_regs.has(arg_reg_2)); 291cb0ef41Sopenharmony_ci if (nof_expected_args >= 3) DCHECK(allocatable_regs.has(arg_reg_3)); 301cb0ef41Sopenharmony_ci if (nof_expected_args >= 4) DCHECK(allocatable_regs.has(arg_reg_4)); 311cb0ef41Sopenharmony_ci // Additional arguments are passed on the stack. 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci#endif // DEBUG 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci// static 361cb0ef41Sopenharmony_ciconstexpr auto WriteBarrierDescriptor::registers() { 371cb0ef41Sopenharmony_ci#if V8_TARGET_OS_WIN 381cb0ef41Sopenharmony_ci return RegisterArray(rdi, r8, rcx, rax, r9, rdx, rsi); 391cb0ef41Sopenharmony_ci#else 401cb0ef41Sopenharmony_ci return RegisterArray(rdi, rbx, rdx, rcx, rax, rsi); 411cb0ef41Sopenharmony_ci#endif // V8_TARGET_OS_WIN 421cb0ef41Sopenharmony_ci} 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci#ifdef V8_IS_TSAN 451cb0ef41Sopenharmony_ci// static 461cb0ef41Sopenharmony_ciconstexpr auto TSANStoreDescriptor::registers() { 471cb0ef41Sopenharmony_ci return RegisterArray(arg_reg_1, arg_reg_2, kReturnRegister0); 481cb0ef41Sopenharmony_ci} 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci// static 511cb0ef41Sopenharmony_ciconstexpr auto TSANLoadDescriptor::registers() { 521cb0ef41Sopenharmony_ci return RegisterArray(arg_reg_1, kReturnRegister0); 531cb0ef41Sopenharmony_ci} 541cb0ef41Sopenharmony_ci#endif // V8_IS_TSAN 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci// static 571cb0ef41Sopenharmony_ciconstexpr Register LoadDescriptor::ReceiverRegister() { return rdx; } 581cb0ef41Sopenharmony_ci// static 591cb0ef41Sopenharmony_ciconstexpr Register LoadDescriptor::NameRegister() { return rcx; } 601cb0ef41Sopenharmony_ci// static 611cb0ef41Sopenharmony_ciconstexpr Register LoadDescriptor::SlotRegister() { return rax; } 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci// static 641cb0ef41Sopenharmony_ciconstexpr Register LoadWithVectorDescriptor::VectorRegister() { return rbx; } 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci// static 671cb0ef41Sopenharmony_ciconstexpr Register KeyedLoadBaselineDescriptor::ReceiverRegister() { 681cb0ef41Sopenharmony_ci return rdx; 691cb0ef41Sopenharmony_ci} 701cb0ef41Sopenharmony_ci// static 711cb0ef41Sopenharmony_ciconstexpr Register KeyedLoadBaselineDescriptor::NameRegister() { 721cb0ef41Sopenharmony_ci return kInterpreterAccumulatorRegister; 731cb0ef41Sopenharmony_ci} 741cb0ef41Sopenharmony_ci// static 751cb0ef41Sopenharmony_ciconstexpr Register KeyedLoadBaselineDescriptor::SlotRegister() { return rcx; } 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci// static 781cb0ef41Sopenharmony_ciconstexpr Register KeyedLoadWithVectorDescriptor::VectorRegister() { 791cb0ef41Sopenharmony_ci return rbx; 801cb0ef41Sopenharmony_ci} 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ci// static 831cb0ef41Sopenharmony_ciconstexpr Register KeyedHasICBaselineDescriptor::ReceiverRegister() { 841cb0ef41Sopenharmony_ci return kInterpreterAccumulatorRegister; 851cb0ef41Sopenharmony_ci} 861cb0ef41Sopenharmony_ci// static 871cb0ef41Sopenharmony_ciconstexpr Register KeyedHasICBaselineDescriptor::NameRegister() { return rdx; } 881cb0ef41Sopenharmony_ci// static 891cb0ef41Sopenharmony_ciconstexpr Register KeyedHasICBaselineDescriptor::SlotRegister() { return rcx; } 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ci// static 921cb0ef41Sopenharmony_ciconstexpr Register KeyedHasICWithVectorDescriptor::VectorRegister() { 931cb0ef41Sopenharmony_ci return rbx; 941cb0ef41Sopenharmony_ci} 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ci// static 971cb0ef41Sopenharmony_ciconstexpr Register 981cb0ef41Sopenharmony_ciLoadWithReceiverAndVectorDescriptor::LookupStartObjectRegister() { 991cb0ef41Sopenharmony_ci return rdi; 1001cb0ef41Sopenharmony_ci} 1011cb0ef41Sopenharmony_ci 1021cb0ef41Sopenharmony_ci// static 1031cb0ef41Sopenharmony_ciconstexpr Register StoreDescriptor::ReceiverRegister() { return rdx; } 1041cb0ef41Sopenharmony_ci// static 1051cb0ef41Sopenharmony_ciconstexpr Register StoreDescriptor::NameRegister() { return rcx; } 1061cb0ef41Sopenharmony_ci// static 1071cb0ef41Sopenharmony_ciconstexpr Register StoreDescriptor::ValueRegister() { return rax; } 1081cb0ef41Sopenharmony_ci// static 1091cb0ef41Sopenharmony_ciconstexpr Register StoreDescriptor::SlotRegister() { return rdi; } 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ci// static 1121cb0ef41Sopenharmony_ciconstexpr Register StoreWithVectorDescriptor::VectorRegister() { return rbx; } 1131cb0ef41Sopenharmony_ci 1141cb0ef41Sopenharmony_ci// static 1151cb0ef41Sopenharmony_ciconstexpr Register StoreTransitionDescriptor::MapRegister() { return r11; } 1161cb0ef41Sopenharmony_ci 1171cb0ef41Sopenharmony_ci// static 1181cb0ef41Sopenharmony_ciconstexpr Register ApiGetterDescriptor::HolderRegister() { return rcx; } 1191cb0ef41Sopenharmony_ci// static 1201cb0ef41Sopenharmony_ciconstexpr Register ApiGetterDescriptor::CallbackRegister() { return rbx; } 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_ci// static 1231cb0ef41Sopenharmony_ciconstexpr Register GrowArrayElementsDescriptor::ObjectRegister() { return rax; } 1241cb0ef41Sopenharmony_ci// static 1251cb0ef41Sopenharmony_ciconstexpr Register GrowArrayElementsDescriptor::KeyRegister() { return rbx; } 1261cb0ef41Sopenharmony_ci 1271cb0ef41Sopenharmony_ci// static 1281cb0ef41Sopenharmony_ciconstexpr Register BaselineLeaveFrameDescriptor::ParamsSizeRegister() { 1291cb0ef41Sopenharmony_ci return rbx; 1301cb0ef41Sopenharmony_ci} 1311cb0ef41Sopenharmony_ci// static 1321cb0ef41Sopenharmony_ciconstexpr Register BaselineLeaveFrameDescriptor::WeightRegister() { 1331cb0ef41Sopenharmony_ci return rcx; 1341cb0ef41Sopenharmony_ci} 1351cb0ef41Sopenharmony_ci 1361cb0ef41Sopenharmony_ci// static 1371cb0ef41Sopenharmony_ciconstexpr Register TypeConversionDescriptor::ArgumentRegister() { return rax; } 1381cb0ef41Sopenharmony_ci 1391cb0ef41Sopenharmony_ci// static 1401cb0ef41Sopenharmony_ciconstexpr auto TypeofDescriptor::registers() { return RegisterArray(rax); } 1411cb0ef41Sopenharmony_ci 1421cb0ef41Sopenharmony_ci// static 1431cb0ef41Sopenharmony_ciconstexpr auto CallTrampolineDescriptor::registers() { 1441cb0ef41Sopenharmony_ci // rax : number of arguments 1451cb0ef41Sopenharmony_ci // rdi : the target to call 1461cb0ef41Sopenharmony_ci return RegisterArray(rdi, rax); 1471cb0ef41Sopenharmony_ci} 1481cb0ef41Sopenharmony_ci// static 1491cb0ef41Sopenharmony_ciconstexpr auto CopyDataPropertiesWithExcludedPropertiesDescriptor::registers() { 1501cb0ef41Sopenharmony_ci // rdi : the source 1511cb0ef41Sopenharmony_ci // rax : the excluded property count 1521cb0ef41Sopenharmony_ci return RegisterArray(rdi, rax); 1531cb0ef41Sopenharmony_ci} 1541cb0ef41Sopenharmony_ci 1551cb0ef41Sopenharmony_ci// static 1561cb0ef41Sopenharmony_ciconstexpr auto 1571cb0ef41Sopenharmony_ciCopyDataPropertiesWithExcludedPropertiesOnStackDescriptor::registers() { 1581cb0ef41Sopenharmony_ci // rdi : the source 1591cb0ef41Sopenharmony_ci // rax : the excluded property count 1601cb0ef41Sopenharmony_ci // rcx : the excluded property base 1611cb0ef41Sopenharmony_ci return RegisterArray(rdi, rax, rcx); 1621cb0ef41Sopenharmony_ci} 1631cb0ef41Sopenharmony_ci 1641cb0ef41Sopenharmony_ci// static 1651cb0ef41Sopenharmony_ciconstexpr auto CallVarargsDescriptor::registers() { 1661cb0ef41Sopenharmony_ci // rax : number of arguments (on the stack) 1671cb0ef41Sopenharmony_ci // rdi : the target to call 1681cb0ef41Sopenharmony_ci // rcx : arguments list length (untagged) 1691cb0ef41Sopenharmony_ci // rbx : arguments list (FixedArray) 1701cb0ef41Sopenharmony_ci return RegisterArray(rdi, rax, rcx, rbx); 1711cb0ef41Sopenharmony_ci} 1721cb0ef41Sopenharmony_ci 1731cb0ef41Sopenharmony_ci// static 1741cb0ef41Sopenharmony_ciconstexpr auto CallForwardVarargsDescriptor::registers() { 1751cb0ef41Sopenharmony_ci // rax : number of arguments 1761cb0ef41Sopenharmony_ci // rcx : start index (to support rest parameters) 1771cb0ef41Sopenharmony_ci // rdi : the target to call 1781cb0ef41Sopenharmony_ci return RegisterArray(rdi, rax, rcx); 1791cb0ef41Sopenharmony_ci} 1801cb0ef41Sopenharmony_ci 1811cb0ef41Sopenharmony_ci// static 1821cb0ef41Sopenharmony_ciconstexpr auto CallFunctionTemplateDescriptor::registers() { 1831cb0ef41Sopenharmony_ci // rdx: the function template info 1841cb0ef41Sopenharmony_ci // rcx: number of arguments (on the stack) 1851cb0ef41Sopenharmony_ci return RegisterArray(rdx, rcx); 1861cb0ef41Sopenharmony_ci} 1871cb0ef41Sopenharmony_ci 1881cb0ef41Sopenharmony_ci// static 1891cb0ef41Sopenharmony_ciconstexpr auto CallWithSpreadDescriptor::registers() { 1901cb0ef41Sopenharmony_ci // rax : number of arguments (on the stack) 1911cb0ef41Sopenharmony_ci // rdi : the target to call 1921cb0ef41Sopenharmony_ci // rbx : the object to spread 1931cb0ef41Sopenharmony_ci return RegisterArray(rdi, rax, rbx); 1941cb0ef41Sopenharmony_ci} 1951cb0ef41Sopenharmony_ci 1961cb0ef41Sopenharmony_ci// static 1971cb0ef41Sopenharmony_ciconstexpr auto CallWithArrayLikeDescriptor::registers() { 1981cb0ef41Sopenharmony_ci // rdi : the target to call 1991cb0ef41Sopenharmony_ci // rbx : the arguments list 2001cb0ef41Sopenharmony_ci return RegisterArray(rdi, rbx); 2011cb0ef41Sopenharmony_ci} 2021cb0ef41Sopenharmony_ci 2031cb0ef41Sopenharmony_ci// static 2041cb0ef41Sopenharmony_ciconstexpr auto ConstructVarargsDescriptor::registers() { 2051cb0ef41Sopenharmony_ci // rax : number of arguments (on the stack) 2061cb0ef41Sopenharmony_ci // rdi : the target to call 2071cb0ef41Sopenharmony_ci // rdx : the new target 2081cb0ef41Sopenharmony_ci // rcx : arguments list length (untagged) 2091cb0ef41Sopenharmony_ci // rbx : arguments list (FixedArray) 2101cb0ef41Sopenharmony_ci return RegisterArray(rdi, rdx, rax, rcx, rbx); 2111cb0ef41Sopenharmony_ci} 2121cb0ef41Sopenharmony_ci 2131cb0ef41Sopenharmony_ci// static 2141cb0ef41Sopenharmony_ciconstexpr auto ConstructForwardVarargsDescriptor::registers() { 2151cb0ef41Sopenharmony_ci // rax : number of arguments 2161cb0ef41Sopenharmony_ci // rdx : the new target 2171cb0ef41Sopenharmony_ci // rcx : start index (to support rest parameters) 2181cb0ef41Sopenharmony_ci // rdi : the target to call 2191cb0ef41Sopenharmony_ci return RegisterArray(rdi, rdx, rax, rcx); 2201cb0ef41Sopenharmony_ci} 2211cb0ef41Sopenharmony_ci 2221cb0ef41Sopenharmony_ci// static 2231cb0ef41Sopenharmony_ciconstexpr auto ConstructWithSpreadDescriptor::registers() { 2241cb0ef41Sopenharmony_ci // rax : number of arguments (on the stack) 2251cb0ef41Sopenharmony_ci // rdi : the target to call 2261cb0ef41Sopenharmony_ci // rdx : the new target 2271cb0ef41Sopenharmony_ci // rbx : the object to spread 2281cb0ef41Sopenharmony_ci return RegisterArray(rdi, rdx, rax, rbx); 2291cb0ef41Sopenharmony_ci} 2301cb0ef41Sopenharmony_ci 2311cb0ef41Sopenharmony_ci// static 2321cb0ef41Sopenharmony_ciconstexpr auto ConstructWithArrayLikeDescriptor::registers() { 2331cb0ef41Sopenharmony_ci // rdi : the target to call 2341cb0ef41Sopenharmony_ci // rdx : the new target 2351cb0ef41Sopenharmony_ci // rbx : the arguments list 2361cb0ef41Sopenharmony_ci return RegisterArray(rdi, rdx, rbx); 2371cb0ef41Sopenharmony_ci} 2381cb0ef41Sopenharmony_ci 2391cb0ef41Sopenharmony_ci// static 2401cb0ef41Sopenharmony_ciconstexpr auto ConstructStubDescriptor::registers() { 2411cb0ef41Sopenharmony_ci // rax : number of arguments 2421cb0ef41Sopenharmony_ci // rdx : the new target 2431cb0ef41Sopenharmony_ci // rdi : the target to call 2441cb0ef41Sopenharmony_ci // rbx : allocation site or undefined 2451cb0ef41Sopenharmony_ci return RegisterArray(rdi, rdx, rax, rbx); 2461cb0ef41Sopenharmony_ci} 2471cb0ef41Sopenharmony_ci 2481cb0ef41Sopenharmony_ci// static 2491cb0ef41Sopenharmony_ciconstexpr auto AbortDescriptor::registers() { return RegisterArray(rdx); } 2501cb0ef41Sopenharmony_ci 2511cb0ef41Sopenharmony_ci// static 2521cb0ef41Sopenharmony_ciconstexpr auto CompareDescriptor::registers() { 2531cb0ef41Sopenharmony_ci return RegisterArray(rdx, rax); 2541cb0ef41Sopenharmony_ci} 2551cb0ef41Sopenharmony_ci 2561cb0ef41Sopenharmony_ci// static 2571cb0ef41Sopenharmony_ciconstexpr auto BinaryOpDescriptor::registers() { 2581cb0ef41Sopenharmony_ci return RegisterArray(rdx, rax); 2591cb0ef41Sopenharmony_ci} 2601cb0ef41Sopenharmony_ci 2611cb0ef41Sopenharmony_ci// static 2621cb0ef41Sopenharmony_ciconstexpr auto Compare_BaselineDescriptor::registers() { 2631cb0ef41Sopenharmony_ci return RegisterArray(rdx, rax, rbx); 2641cb0ef41Sopenharmony_ci} 2651cb0ef41Sopenharmony_ci 2661cb0ef41Sopenharmony_ci// static 2671cb0ef41Sopenharmony_ciconstexpr auto BinaryOp_BaselineDescriptor::registers() { 2681cb0ef41Sopenharmony_ci return RegisterArray(rdx, rax, rbx); 2691cb0ef41Sopenharmony_ci} 2701cb0ef41Sopenharmony_ci 2711cb0ef41Sopenharmony_ci// static 2721cb0ef41Sopenharmony_ciconstexpr auto BinarySmiOp_BaselineDescriptor::registers() { 2731cb0ef41Sopenharmony_ci return RegisterArray(rax, rdx, rbx); 2741cb0ef41Sopenharmony_ci} 2751cb0ef41Sopenharmony_ci 2761cb0ef41Sopenharmony_ci// static 2771cb0ef41Sopenharmony_ciconstexpr auto ApiCallbackDescriptor::registers() { 2781cb0ef41Sopenharmony_ci return RegisterArray(rdx, // api function address 2791cb0ef41Sopenharmony_ci rcx, // argument count (not including receiver) 2801cb0ef41Sopenharmony_ci rbx, // call data 2811cb0ef41Sopenharmony_ci rdi); // holder 2821cb0ef41Sopenharmony_ci} 2831cb0ef41Sopenharmony_ci 2841cb0ef41Sopenharmony_ci// static 2851cb0ef41Sopenharmony_ciconstexpr auto InterpreterDispatchDescriptor::registers() { 2861cb0ef41Sopenharmony_ci return RegisterArray( 2871cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, kInterpreterBytecodeOffsetRegister, 2881cb0ef41Sopenharmony_ci kInterpreterBytecodeArrayRegister, kInterpreterDispatchTableRegister); 2891cb0ef41Sopenharmony_ci} 2901cb0ef41Sopenharmony_ci 2911cb0ef41Sopenharmony_ci// static 2921cb0ef41Sopenharmony_ciconstexpr auto InterpreterPushArgsThenCallDescriptor::registers() { 2931cb0ef41Sopenharmony_ci return RegisterArray(rax, // argument count 2941cb0ef41Sopenharmony_ci rbx, // address of first argument 2951cb0ef41Sopenharmony_ci rdi); // the target callable to be call 2961cb0ef41Sopenharmony_ci} 2971cb0ef41Sopenharmony_ci 2981cb0ef41Sopenharmony_ci// static 2991cb0ef41Sopenharmony_ciconstexpr auto InterpreterPushArgsThenConstructDescriptor::registers() { 3001cb0ef41Sopenharmony_ci return RegisterArray( 3011cb0ef41Sopenharmony_ci rax, // argument count 3021cb0ef41Sopenharmony_ci rcx, // address of first argument 3031cb0ef41Sopenharmony_ci rdi, // constructor to call 3041cb0ef41Sopenharmony_ci rdx, // new target 3051cb0ef41Sopenharmony_ci rbx); // allocation site feedback if available, undefined otherwise 3061cb0ef41Sopenharmony_ci} 3071cb0ef41Sopenharmony_ci 3081cb0ef41Sopenharmony_ci// static 3091cb0ef41Sopenharmony_ciconstexpr auto ResumeGeneratorDescriptor::registers() { 3101cb0ef41Sopenharmony_ci return RegisterArray( 3111cb0ef41Sopenharmony_ci rax, // the value to pass to the generator 3121cb0ef41Sopenharmony_ci rdx); // the JSGeneratorObject / JSAsyncGeneratorObject to resume 3131cb0ef41Sopenharmony_ci} 3141cb0ef41Sopenharmony_ci 3151cb0ef41Sopenharmony_ci// static 3161cb0ef41Sopenharmony_ciconstexpr auto RunMicrotasksEntryDescriptor::registers() { 3171cb0ef41Sopenharmony_ci return RegisterArray(arg_reg_1, arg_reg_2); 3181cb0ef41Sopenharmony_ci} 3191cb0ef41Sopenharmony_ci 3201cb0ef41Sopenharmony_ci} // namespace internal 3211cb0ef41Sopenharmony_ci} // namespace v8 3221cb0ef41Sopenharmony_ci 3231cb0ef41Sopenharmony_ci#endif // V8_TARGET_ARCH_X64 3241cb0ef41Sopenharmony_ci 3251cb0ef41Sopenharmony_ci#endif // V8_CODEGEN_X64_INTERFACE_DESCRIPTORS_X64_INL_H_ 326