• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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_EXECUTION_LOONG64_FRAME_CONSTANTS_LOONG64_H_
6 #define V8_EXECUTION_LOONG64_FRAME_CONSTANTS_LOONG64_H_
7 
8 #include "src/base/bits.h"
9 #include "src/base/macros.h"
10 #include "src/codegen/register.h"
11 #include "src/execution/frame-constants.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 class EntryFrameConstants : public AllStatic {
17  public:
18   // This is the offset to where JSEntry pushes the current value of
19   // Isolate::c_entry_fp onto the stack.
20   static constexpr int kCallerFPOffset = -3 * kSystemPointerSize;
21 };
22 
23 class WasmCompileLazyFrameConstants : public TypedFrameConstants {
24  public:
25   static constexpr int kNumberOfSavedGpParamRegs = 7;
26   static constexpr int kNumberOfSavedFpParamRegs = 8;
27   static constexpr int kNumberOfSavedAllParamRegs = 15;
28 
29   // FP-relative.
30   // See Generate_WasmCompileLazy in builtins-loong64.cc.
31   static constexpr int kWasmInstanceOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(6);
32   static constexpr int kFixedFrameSizeFromFp =
33       TypedFrameConstants::kFixedFrameSizeFromFp +
34       kNumberOfSavedGpParamRegs * kPointerSize +
35       kNumberOfSavedFpParamRegs * kDoubleSize;
36 };
37 
38 // Frame constructed by the {WasmDebugBreak} builtin.
39 // After pushing the frame type marker, the builtin pushes all Liftoff cache
40 // registers (see liftoff-assembler-defs.h).
41 class WasmDebugBreakFrameConstants : public TypedFrameConstants {
42  public:
43   // {a0 ... a7, t0 ... t5, s0, s1, s2, s5, s7, s8}
44   static constexpr RegList kPushedGpRegs = {a0, a1, a2, a3, a4, a5, a6,
45                                             a7, t0, t1, t2, t3, t4, t5,
46                                             s0, s1, s2, s5, s7, s8};
47   // {f0, f1, f2, ... f27, f28}
48   static constexpr DoubleRegList kPushedFpRegs = {
49       f0,  f1,  f2,  f3,  f4,  f5,  f6,  f7,  f8,  f9,  f10, f11, f12, f13, f14,
50       f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28};
51 
52   static constexpr int kNumPushedGpRegisters = kPushedGpRegs.Count();
53   static constexpr int kNumPushedFpRegisters = kPushedFpRegs.Count();
54 
55   static constexpr int kLastPushedGpRegisterOffset =
56       -kFixedFrameSizeFromFp - kNumPushedGpRegisters * kSystemPointerSize;
57   static constexpr int kLastPushedFpRegisterOffset =
58       kLastPushedGpRegisterOffset - kNumPushedFpRegisters * kDoubleSize;
59 
60   // Offsets are fp-relative.
GetPushedGpRegisterOffset(int reg_code)61   static int GetPushedGpRegisterOffset(int reg_code) {
62     DCHECK_NE(0, kPushedGpRegs.bits() & (1 << reg_code));
63     uint32_t lower_regs =
64         kPushedGpRegs.bits() & ((uint32_t{1} << reg_code) - 1);
65     return kLastPushedGpRegisterOffset +
66            base::bits::CountPopulation(lower_regs) * kSystemPointerSize;
67   }
68 
GetPushedFpRegisterOffset(int reg_code)69   static int GetPushedFpRegisterOffset(int reg_code) {
70     DCHECK_NE(0, kPushedFpRegs.bits() & (1 << reg_code));
71     uint32_t lower_regs =
72         kPushedFpRegs.bits() & ((uint32_t{1} << reg_code) - 1);
73     return kLastPushedFpRegisterOffset +
74            base::bits::CountPopulation(lower_regs) * kDoubleSize;
75   }
76 };
77 
78 }  // namespace internal
79 }  // namespace v8
80 
81 #endif  // V8_EXECUTION_LOONG64_FRAME_CONSTANTS_LOONG64_H_
82