• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef PANDA_RUNTIME_VREGISTER_ITERATOR_H_
16 #define PANDA_RUNTIME_VREGISTER_ITERATOR_H_
17 
18 namespace ark::interpreter {
19 
20 template <BytecodeInstruction::Format FORMAT>
21 class VRegisterIterator {
22 public:
23     // NOLINTNEXTLINE(performance-move-const-arg)
VRegisterIterator(BytecodeInstruction insn,Frame * frame)24     explicit VRegisterIterator(BytecodeInstruction insn, Frame *frame) : instn_(std::move(insn)), frame_(frame) {}
25 
GetVRegIdx(size_t paramIdx)26     ALWAYS_INLINE size_t GetVRegIdx(size_t paramIdx) const
27     {
28         if constexpr (BytecodeInstruction::IsVregArgsShort(FORMAT)) {
29             switch (paramIdx) {
30                 case 0: {
31                     return instn_.GetVReg<FORMAT, 0>();
32                 }
33                 case 1: {
34                     return instn_.GetVReg<FORMAT, 1>();
35                 }
36                 default:
37                     UNREACHABLE();
38             }
39         } else if constexpr (BytecodeInstruction::IsVregArgs(FORMAT)) {
40             switch (paramIdx) {
41                 case 0U: {
42                     return instn_.GetVReg<FORMAT, 0U>();
43                 }
44                 case 1U: {
45                     return instn_.GetVReg<FORMAT, 1U>();
46                 }
47                 case 2U: {
48                     return instn_.GetVReg<FORMAT, 2U>();
49                 }
50                 case 3U: {
51                     return instn_.GetVReg<FORMAT, 3U>();
52                 }
53                 default:
54                     UNREACHABLE();
55             }
56         } else if constexpr (BytecodeInstruction::IsVregArgsRange(FORMAT)) {
57             return instn_.GetVReg<FORMAT, 0>() + paramIdx;
58         } else {
59             UNREACHABLE();
60             return SIZE_MAX;
61         }
62     }
63 
64     template <class T>
GetAs(size_t paramIdx)65     ALWAYS_INLINE T GetAs(size_t paramIdx) const
66     {
67         return frame_->GetVReg(GetVRegIdx(paramIdx)).template GetAs<T>();
68     }
69 
70 private:
71     BytecodeInstruction instn_;
72     Frame *frame_;
73 };
74 
75 template <BytecodeInstruction::Format FORMAT, bool IS_DYNAMIC>
76 class DimIterator final : VRegisterIterator<FORMAT> {
77 public:
78     // NOLINTNEXTLINE(performance-move-const-arg)
DimIterator(BytecodeInstruction insn,Frame * frame)79     explicit DimIterator(BytecodeInstruction insn, Frame *frame) : VRegisterIterator<FORMAT>(std::move(insn), frame) {}
80 
Get(size_t paramIdx)81     int32_t Get(size_t paramIdx) const
82     {
83         return this->template GetAs<int32_t>(paramIdx);
84     }
85 };
86 
87 }  // namespace ark::interpreter
88 
89 #endif  // PANDA_RUNTIME_CORETYPES_ARRAY_H_
90