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_IA32_INTERFACE_DESCRIPTORS_IA32_INL_H_
61cb0ef41Sopenharmony_ci#define V8_CODEGEN_IA32_INTERFACE_DESCRIPTORS_IA32_INL_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_IA32
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(eax, ecx, edx, edi);
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(esi));
281cb0ef41Sopenharmony_ci  if (nof_expected_args >= 2) DCHECK(allocatable_regs.has(edi));
291cb0ef41Sopenharmony_ci  // Additional arguments are passed on the stack.
301cb0ef41Sopenharmony_ci}
311cb0ef41Sopenharmony_ci#endif  // DEBUG
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci// static
341cb0ef41Sopenharmony_ciconstexpr auto WriteBarrierDescriptor::registers() {
351cb0ef41Sopenharmony_ci  return RegisterArray(edi, ecx, edx, esi, kReturnRegister0);
361cb0ef41Sopenharmony_ci}
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci// static
391cb0ef41Sopenharmony_ciconstexpr Register LoadDescriptor::ReceiverRegister() { return edx; }
401cb0ef41Sopenharmony_ci// static
411cb0ef41Sopenharmony_ciconstexpr Register LoadDescriptor::NameRegister() { return ecx; }
421cb0ef41Sopenharmony_ci// static
431cb0ef41Sopenharmony_ciconstexpr Register LoadDescriptor::SlotRegister() { return eax; }
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci// static
461cb0ef41Sopenharmony_ciconstexpr Register LoadWithVectorDescriptor::VectorRegister() { return no_reg; }
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci// static
491cb0ef41Sopenharmony_ciconstexpr Register KeyedLoadBaselineDescriptor::ReceiverRegister() {
501cb0ef41Sopenharmony_ci  return edx;
511cb0ef41Sopenharmony_ci}
521cb0ef41Sopenharmony_ci// static
531cb0ef41Sopenharmony_ciconstexpr Register KeyedLoadBaselineDescriptor::NameRegister() {
541cb0ef41Sopenharmony_ci  return kInterpreterAccumulatorRegister;
551cb0ef41Sopenharmony_ci}
561cb0ef41Sopenharmony_ci// static
571cb0ef41Sopenharmony_ciconstexpr Register KeyedLoadBaselineDescriptor::SlotRegister() { return ecx; }
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci// static
601cb0ef41Sopenharmony_ciconstexpr Register KeyedLoadWithVectorDescriptor::VectorRegister() {
611cb0ef41Sopenharmony_ci  return no_reg;
621cb0ef41Sopenharmony_ci}
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci// static
651cb0ef41Sopenharmony_ciconstexpr Register KeyedHasICBaselineDescriptor::ReceiverRegister() {
661cb0ef41Sopenharmony_ci  return kInterpreterAccumulatorRegister;
671cb0ef41Sopenharmony_ci}
681cb0ef41Sopenharmony_ci// static
691cb0ef41Sopenharmony_ciconstexpr Register KeyedHasICBaselineDescriptor::NameRegister() { return edx; }
701cb0ef41Sopenharmony_ci// static
711cb0ef41Sopenharmony_ciconstexpr Register KeyedHasICBaselineDescriptor::SlotRegister() { return ecx; }
721cb0ef41Sopenharmony_ci
731cb0ef41Sopenharmony_ci// static
741cb0ef41Sopenharmony_ciconstexpr Register KeyedHasICWithVectorDescriptor::VectorRegister() {
751cb0ef41Sopenharmony_ci  return no_reg;
761cb0ef41Sopenharmony_ci}
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ci// static
791cb0ef41Sopenharmony_ciconstexpr Register
801cb0ef41Sopenharmony_ciLoadWithReceiverAndVectorDescriptor::LookupStartObjectRegister() {
811cb0ef41Sopenharmony_ci  return edi;
821cb0ef41Sopenharmony_ci}
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_ci// static
851cb0ef41Sopenharmony_ciconstexpr Register StoreDescriptor::ReceiverRegister() { return edx; }
861cb0ef41Sopenharmony_ci// static
871cb0ef41Sopenharmony_ciconstexpr Register StoreDescriptor::NameRegister() { return ecx; }
881cb0ef41Sopenharmony_ci// static
891cb0ef41Sopenharmony_ciconstexpr Register StoreDescriptor::ValueRegister() { return no_reg; }
901cb0ef41Sopenharmony_ci// static
911cb0ef41Sopenharmony_ciconstexpr Register StoreDescriptor::SlotRegister() { return no_reg; }
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ci// static
941cb0ef41Sopenharmony_ciconstexpr Register StoreWithVectorDescriptor::VectorRegister() {
951cb0ef41Sopenharmony_ci  return no_reg;
961cb0ef41Sopenharmony_ci}
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ci// static
991cb0ef41Sopenharmony_ciconstexpr Register StoreTransitionDescriptor::MapRegister() { return edi; }
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ci// static
1021cb0ef41Sopenharmony_ciconstexpr Register ApiGetterDescriptor::HolderRegister() { return ecx; }
1031cb0ef41Sopenharmony_ci// static
1041cb0ef41Sopenharmony_ciconstexpr Register ApiGetterDescriptor::CallbackRegister() { return eax; }
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ci// static
1071cb0ef41Sopenharmony_ciconstexpr Register GrowArrayElementsDescriptor::ObjectRegister() { return eax; }
1081cb0ef41Sopenharmony_ci// static
1091cb0ef41Sopenharmony_ciconstexpr Register GrowArrayElementsDescriptor::KeyRegister() { return ecx; }
1101cb0ef41Sopenharmony_ci
1111cb0ef41Sopenharmony_ci// static
1121cb0ef41Sopenharmony_ciconstexpr Register BaselineLeaveFrameDescriptor::ParamsSizeRegister() {
1131cb0ef41Sopenharmony_ci  return esi;
1141cb0ef41Sopenharmony_ci}
1151cb0ef41Sopenharmony_ci// static
1161cb0ef41Sopenharmony_ciconstexpr Register BaselineLeaveFrameDescriptor::WeightRegister() {
1171cb0ef41Sopenharmony_ci  return edi;
1181cb0ef41Sopenharmony_ci}
1191cb0ef41Sopenharmony_ci
1201cb0ef41Sopenharmony_ci// static
1211cb0ef41Sopenharmony_ciconstexpr Register TypeConversionDescriptor::ArgumentRegister() { return eax; }
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ci// static
1241cb0ef41Sopenharmony_ciconstexpr auto TypeofDescriptor::registers() { return RegisterArray(eax); }
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ci// static
1271cb0ef41Sopenharmony_ciconstexpr auto CallTrampolineDescriptor::registers() {
1281cb0ef41Sopenharmony_ci  // eax : number of arguments
1291cb0ef41Sopenharmony_ci  // edi : the target to call
1301cb0ef41Sopenharmony_ci  return RegisterArray(edi, eax);
1311cb0ef41Sopenharmony_ci}
1321cb0ef41Sopenharmony_ci
1331cb0ef41Sopenharmony_ci// static
1341cb0ef41Sopenharmony_ciconstexpr auto CopyDataPropertiesWithExcludedPropertiesDescriptor::registers() {
1351cb0ef41Sopenharmony_ci  // edi : the source
1361cb0ef41Sopenharmony_ci  // eax : the excluded property count
1371cb0ef41Sopenharmony_ci  return RegisterArray(edi, eax);
1381cb0ef41Sopenharmony_ci}
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_ci// static
1411cb0ef41Sopenharmony_ciconstexpr auto
1421cb0ef41Sopenharmony_ciCopyDataPropertiesWithExcludedPropertiesOnStackDescriptor::registers() {
1431cb0ef41Sopenharmony_ci  // edi : the source
1441cb0ef41Sopenharmony_ci  // eax : the excluded property count
1451cb0ef41Sopenharmony_ci  // ecx : the excluded property base
1461cb0ef41Sopenharmony_ci  return RegisterArray(edi, eax, ecx);
1471cb0ef41Sopenharmony_ci}
1481cb0ef41Sopenharmony_ci
1491cb0ef41Sopenharmony_ci// static
1501cb0ef41Sopenharmony_ciconstexpr auto CallVarargsDescriptor::registers() {
1511cb0ef41Sopenharmony_ci  // eax : number of arguments (on the stack)
1521cb0ef41Sopenharmony_ci  // edi : the target to call
1531cb0ef41Sopenharmony_ci  // ecx : arguments list length (untagged)
1541cb0ef41Sopenharmony_ci  // On the stack : arguments list (FixedArray)
1551cb0ef41Sopenharmony_ci  return RegisterArray(edi, eax, ecx);
1561cb0ef41Sopenharmony_ci}
1571cb0ef41Sopenharmony_ci
1581cb0ef41Sopenharmony_ci// static
1591cb0ef41Sopenharmony_ciconstexpr auto CallForwardVarargsDescriptor::registers() {
1601cb0ef41Sopenharmony_ci  // eax : number of arguments
1611cb0ef41Sopenharmony_ci  // ecx : start index (to support rest parameters)
1621cb0ef41Sopenharmony_ci  // edi : the target to call
1631cb0ef41Sopenharmony_ci  return RegisterArray(edi, eax, ecx);
1641cb0ef41Sopenharmony_ci}
1651cb0ef41Sopenharmony_ci
1661cb0ef41Sopenharmony_ci// static
1671cb0ef41Sopenharmony_ciconstexpr auto CallFunctionTemplateDescriptor::registers() {
1681cb0ef41Sopenharmony_ci  // edx : function template info
1691cb0ef41Sopenharmony_ci  // ecx : number of arguments (on the stack)
1701cb0ef41Sopenharmony_ci  return RegisterArray(edx, ecx);
1711cb0ef41Sopenharmony_ci}
1721cb0ef41Sopenharmony_ci
1731cb0ef41Sopenharmony_ci// static
1741cb0ef41Sopenharmony_ciconstexpr auto CallWithSpreadDescriptor::registers() {
1751cb0ef41Sopenharmony_ci  // eax : number of arguments (on the stack)
1761cb0ef41Sopenharmony_ci  // edi : the target to call
1771cb0ef41Sopenharmony_ci  // ecx : the object to spread
1781cb0ef41Sopenharmony_ci  return RegisterArray(edi, eax, ecx);
1791cb0ef41Sopenharmony_ci}
1801cb0ef41Sopenharmony_ci
1811cb0ef41Sopenharmony_ci// static
1821cb0ef41Sopenharmony_ciconstexpr auto CallWithArrayLikeDescriptor::registers() {
1831cb0ef41Sopenharmony_ci  // edi : the target to call
1841cb0ef41Sopenharmony_ci  // edx : the arguments list
1851cb0ef41Sopenharmony_ci  return RegisterArray(edi, edx);
1861cb0ef41Sopenharmony_ci}
1871cb0ef41Sopenharmony_ci
1881cb0ef41Sopenharmony_ci// static
1891cb0ef41Sopenharmony_ciconstexpr auto ConstructVarargsDescriptor::registers() {
1901cb0ef41Sopenharmony_ci  // eax : number of arguments (on the stack)
1911cb0ef41Sopenharmony_ci  // edi : the target to call
1921cb0ef41Sopenharmony_ci  // edx : the new target
1931cb0ef41Sopenharmony_ci  // ecx : arguments list length (untagged)
1941cb0ef41Sopenharmony_ci  // On the stack : arguments list (FixedArray)
1951cb0ef41Sopenharmony_ci  return RegisterArray(edi, edx, eax, ecx);
1961cb0ef41Sopenharmony_ci}
1971cb0ef41Sopenharmony_ci
1981cb0ef41Sopenharmony_ci// static
1991cb0ef41Sopenharmony_ciconstexpr auto ConstructForwardVarargsDescriptor::registers() {
2001cb0ef41Sopenharmony_ci  // eax : number of arguments
2011cb0ef41Sopenharmony_ci  // edx : the new target
2021cb0ef41Sopenharmony_ci  // ecx : start index (to support rest parameters)
2031cb0ef41Sopenharmony_ci  // edi : the target to call
2041cb0ef41Sopenharmony_ci  return RegisterArray(edi, edx, eax, ecx);
2051cb0ef41Sopenharmony_ci}
2061cb0ef41Sopenharmony_ci
2071cb0ef41Sopenharmony_ci// static
2081cb0ef41Sopenharmony_ciconstexpr auto ConstructWithSpreadDescriptor::registers() {
2091cb0ef41Sopenharmony_ci  // eax : number of arguments (on the stack)
2101cb0ef41Sopenharmony_ci  // edi : the target to call
2111cb0ef41Sopenharmony_ci  // edx : the new target
2121cb0ef41Sopenharmony_ci  // ecx : the object to spread
2131cb0ef41Sopenharmony_ci  return RegisterArray(edi, edx, eax, ecx);
2141cb0ef41Sopenharmony_ci}
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_ci// static
2171cb0ef41Sopenharmony_ciconstexpr auto ConstructWithArrayLikeDescriptor::registers() {
2181cb0ef41Sopenharmony_ci  // edi : the target to call
2191cb0ef41Sopenharmony_ci  // edx : the new target
2201cb0ef41Sopenharmony_ci  // ecx : the arguments list
2211cb0ef41Sopenharmony_ci  return RegisterArray(edi, edx, ecx);
2221cb0ef41Sopenharmony_ci}
2231cb0ef41Sopenharmony_ci
2241cb0ef41Sopenharmony_ci// static
2251cb0ef41Sopenharmony_ciconstexpr auto ConstructStubDescriptor::registers() {
2261cb0ef41Sopenharmony_ci  // eax : number of arguments
2271cb0ef41Sopenharmony_ci  // edx : the new target
2281cb0ef41Sopenharmony_ci  // edi : the target to call
2291cb0ef41Sopenharmony_ci  // ecx : allocation site or undefined
2301cb0ef41Sopenharmony_ci  // TODO(jgruber): Remove the unused allocation site parameter.
2311cb0ef41Sopenharmony_ci  return RegisterArray(edi, edx, eax, ecx);
2321cb0ef41Sopenharmony_ci}
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ci// static
2351cb0ef41Sopenharmony_ciconstexpr auto AbortDescriptor::registers() { return RegisterArray(edx); }
2361cb0ef41Sopenharmony_ci
2371cb0ef41Sopenharmony_ci// static
2381cb0ef41Sopenharmony_ciconstexpr auto CompareDescriptor::registers() {
2391cb0ef41Sopenharmony_ci  return RegisterArray(edx, eax);
2401cb0ef41Sopenharmony_ci}
2411cb0ef41Sopenharmony_ci
2421cb0ef41Sopenharmony_ci// static
2431cb0ef41Sopenharmony_ciconstexpr auto Compare_BaselineDescriptor::registers() {
2441cb0ef41Sopenharmony_ci  return RegisterArray(edx, eax, ecx);
2451cb0ef41Sopenharmony_ci}
2461cb0ef41Sopenharmony_ci
2471cb0ef41Sopenharmony_ci// static
2481cb0ef41Sopenharmony_ciconstexpr auto BinaryOpDescriptor::registers() {
2491cb0ef41Sopenharmony_ci  return RegisterArray(edx, eax);
2501cb0ef41Sopenharmony_ci}
2511cb0ef41Sopenharmony_ci
2521cb0ef41Sopenharmony_ci// static
2531cb0ef41Sopenharmony_ciconstexpr auto BinaryOp_BaselineDescriptor::registers() {
2541cb0ef41Sopenharmony_ci  return RegisterArray(edx, eax, ecx);
2551cb0ef41Sopenharmony_ci}
2561cb0ef41Sopenharmony_ci
2571cb0ef41Sopenharmony_ci// static
2581cb0ef41Sopenharmony_ciconstexpr auto BinarySmiOp_BaselineDescriptor::registers() {
2591cb0ef41Sopenharmony_ci  return RegisterArray(eax, edx, ecx);
2601cb0ef41Sopenharmony_ci}
2611cb0ef41Sopenharmony_ci
2621cb0ef41Sopenharmony_ci// static
2631cb0ef41Sopenharmony_ciconstexpr auto ApiCallbackDescriptor::registers() {
2641cb0ef41Sopenharmony_ci  return RegisterArray(edx,   // kApiFunctionAddress
2651cb0ef41Sopenharmony_ci                       ecx,   // kArgc
2661cb0ef41Sopenharmony_ci                       eax,   // kCallData
2671cb0ef41Sopenharmony_ci                       edi);  // kHolder
2681cb0ef41Sopenharmony_ci}
2691cb0ef41Sopenharmony_ci
2701cb0ef41Sopenharmony_ci// static
2711cb0ef41Sopenharmony_ciconstexpr auto InterpreterDispatchDescriptor::registers() {
2721cb0ef41Sopenharmony_ci  return RegisterArray(
2731cb0ef41Sopenharmony_ci      kInterpreterAccumulatorRegister, kInterpreterBytecodeOffsetRegister,
2741cb0ef41Sopenharmony_ci      kInterpreterBytecodeArrayRegister, kInterpreterDispatchTableRegister);
2751cb0ef41Sopenharmony_ci}
2761cb0ef41Sopenharmony_ci
2771cb0ef41Sopenharmony_ci// static
2781cb0ef41Sopenharmony_ciconstexpr auto InterpreterPushArgsThenCallDescriptor::registers() {
2791cb0ef41Sopenharmony_ci  return RegisterArray(eax,   // argument count
2801cb0ef41Sopenharmony_ci                       ecx,   // address of first argument
2811cb0ef41Sopenharmony_ci                       edi);  // the target callable to be call
2821cb0ef41Sopenharmony_ci}
2831cb0ef41Sopenharmony_ci
2841cb0ef41Sopenharmony_ci// static
2851cb0ef41Sopenharmony_ciconstexpr auto InterpreterPushArgsThenConstructDescriptor::registers() {
2861cb0ef41Sopenharmony_ci  return RegisterArray(eax,   // argument count
2871cb0ef41Sopenharmony_ci                       ecx);  // address of first argument
2881cb0ef41Sopenharmony_ci}
2891cb0ef41Sopenharmony_ci
2901cb0ef41Sopenharmony_ci// static
2911cb0ef41Sopenharmony_ciconstexpr auto ResumeGeneratorDescriptor::registers() {
2921cb0ef41Sopenharmony_ci  return RegisterArray(eax,   // the value to pass to the generator
2931cb0ef41Sopenharmony_ci                       edx);  // the JSGeneratorObject to resume
2941cb0ef41Sopenharmony_ci}
2951cb0ef41Sopenharmony_ci
2961cb0ef41Sopenharmony_ci// static
2971cb0ef41Sopenharmony_ciconstexpr auto RunMicrotasksEntryDescriptor::registers() {
2981cb0ef41Sopenharmony_ci  return RegisterArray();
2991cb0ef41Sopenharmony_ci}
3001cb0ef41Sopenharmony_ci
3011cb0ef41Sopenharmony_ci// static
3021cb0ef41Sopenharmony_ciconstexpr auto WasmFloat32ToNumberDescriptor::registers() {
3031cb0ef41Sopenharmony_ci  // Work around using eax, whose register code is 0, and leads to the FP
3041cb0ef41Sopenharmony_ci  // parameter being passed via xmm0, which is not allocatable on ia32.
3051cb0ef41Sopenharmony_ci  return RegisterArray(ecx);
3061cb0ef41Sopenharmony_ci}
3071cb0ef41Sopenharmony_ci
3081cb0ef41Sopenharmony_ci// static
3091cb0ef41Sopenharmony_ciconstexpr auto WasmFloat64ToNumberDescriptor::registers() {
3101cb0ef41Sopenharmony_ci  // Work around using eax, whose register code is 0, and leads to the FP
3111cb0ef41Sopenharmony_ci  // parameter being passed via xmm0, which is not allocatable on ia32.
3121cb0ef41Sopenharmony_ci  return RegisterArray(ecx);
3131cb0ef41Sopenharmony_ci}
3141cb0ef41Sopenharmony_ci
3151cb0ef41Sopenharmony_ci}  // namespace internal
3161cb0ef41Sopenharmony_ci}  // namespace v8
3171cb0ef41Sopenharmony_ci
3181cb0ef41Sopenharmony_ci#endif  // V8_TARGET_ARCH_IA32
3191cb0ef41Sopenharmony_ci
3201cb0ef41Sopenharmony_ci#endif  // V8_CODEGEN_IA32_INTERFACE_DESCRIPTORS_IA32_INL_H_
321