| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_INTERPRETER_BYTECODE_TRAITS_H_ | 5 #ifndef V8_INTERPRETER_BYTECODE_TRAITS_H_ |
| 6 #define V8_INTERPRETER_BYTECODE_TRAITS_H_ | 6 #define V8_INTERPRETER_BYTECODE_TRAITS_H_ |
| 7 | 7 |
| 8 #include "src/interpreter/bytecodes.h" | 8 #include "src/interpreter/bytecodes.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 #define DECLARE_OPERAND_SIZE(Name, Size) \ | 22 #define DECLARE_OPERAND_SIZE(Name, Size) \ |
| 23 template <> \ | 23 template <> \ |
| 24 struct OperandTraits<OperandType::k##Name> { \ | 24 struct OperandTraits<OperandType::k##Name> { \ |
| 25 static const OperandSize kSizeType = Size; \ | 25 static const OperandSize kSizeType = Size; \ |
| 26 static const int kSize = static_cast<int>(Size); \ | 26 static const int kSize = static_cast<int>(Size); \ |
| 27 }; | 27 }; |
| 28 OPERAND_TYPE_LIST(DECLARE_OPERAND_SIZE) | 28 OPERAND_TYPE_LIST(DECLARE_OPERAND_SIZE) |
| 29 #undef DECLARE_OPERAND_SIZE | 29 #undef DECLARE_OPERAND_SIZE |
| 30 | 30 |
| 31 template <OperandType> |
| 32 struct RegisterOperandTraits { |
| 33 static const int kIsRegisterOperand = 0; |
| 34 }; |
| 35 |
| 36 #define DECLARE_REGISTER_OPERAND(Name, _) \ |
| 37 template <> \ |
| 38 struct RegisterOperandTraits<OperandType::k##Name> { \ |
| 39 static const int kIsRegisterOperand = 1; \ |
| 40 }; |
| 41 REGISTER_OPERAND_TYPE_LIST(DECLARE_REGISTER_OPERAND) |
| 42 #undef DECLARE_REGISTER_OPERAND |
| 31 | 43 |
| 32 template <OperandType... Args> | 44 template <OperandType... Args> |
| 33 struct BytecodeTraits {}; | 45 struct BytecodeTraits {}; |
| 34 | 46 |
| 35 template <OperandType operand_0, OperandType operand_1, OperandType operand_2, | 47 template <OperandType operand_0, OperandType operand_1, OperandType operand_2, |
| 36 OperandType operand_3> | 48 OperandType operand_3> |
| 37 struct BytecodeTraits<operand_0, operand_1, operand_2, operand_3, | 49 struct BytecodeTraits<operand_0, operand_1, operand_2, operand_3, |
| 38 OPERAND_TERM> { | 50 OPERAND_TERM> { |
| 39 static OperandType GetOperandType(int i) { | 51 static OperandType GetOperandType(int i) { |
| 40 DCHECK(0 <= i && i < kOperandCount); | 52 DCHECK(0 <= i && i < kOperandCount); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 static inline int GetOperandOffset(int i) { | 68 static inline int GetOperandOffset(int i) { |
| 57 DCHECK(0 <= i && i < kOperandCount); | 69 DCHECK(0 <= i && i < kOperandCount); |
| 58 const int kOffset0 = 1; | 70 const int kOffset0 = 1; |
| 59 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize; | 71 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize; |
| 60 const int kOffset2 = kOffset1 + OperandTraits<operand_1>::kSize; | 72 const int kOffset2 = kOffset1 + OperandTraits<operand_1>::kSize; |
| 61 const int kOffset3 = kOffset2 + OperandTraits<operand_2>::kSize; | 73 const int kOffset3 = kOffset2 + OperandTraits<operand_2>::kSize; |
| 62 const int kOperandOffsets[] = {kOffset0, kOffset1, kOffset2, kOffset3}; | 74 const int kOperandOffsets[] = {kOffset0, kOffset1, kOffset2, kOffset3}; |
| 63 return kOperandOffsets[i]; | 75 return kOperandOffsets[i]; |
| 64 } | 76 } |
| 65 | 77 |
| 78 template <OperandType ot> |
| 79 static inline bool HasAnyOperandsOfType() { |
| 80 return operand_0 == ot || operand_1 == ot || operand_2 == ot || |
| 81 operand_3 == ot; |
| 82 } |
| 83 |
| 66 static const int kOperandCount = 4; | 84 static const int kOperandCount = 4; |
| 85 static const int kRegisterOperandCount = |
| 86 RegisterOperandTraits<operand_0>::kIsRegisterOperand + |
| 87 RegisterOperandTraits<operand_1>::kIsRegisterOperand + |
| 88 RegisterOperandTraits<operand_2>::kIsRegisterOperand + |
| 89 RegisterOperandTraits<operand_3>::kIsRegisterOperand; |
| 90 static const int kRegisterOperandBitmap = |
| 91 RegisterOperandTraits<operand_0>::kIsRegisterOperand + |
| 92 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1) + |
| 93 (RegisterOperandTraits<operand_2>::kIsRegisterOperand << 2) + |
| 94 (RegisterOperandTraits<operand_3>::kIsRegisterOperand << 3); |
| 67 static const int kSize = | 95 static const int kSize = |
| 68 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize + | 96 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize + |
| 69 OperandTraits<operand_2>::kSize + OperandTraits<operand_3>::kSize; | 97 OperandTraits<operand_2>::kSize + OperandTraits<operand_3>::kSize; |
| 70 }; | 98 }; |
| 71 | 99 |
| 72 | |
| 73 template <OperandType operand_0, OperandType operand_1, OperandType operand_2> | 100 template <OperandType operand_0, OperandType operand_1, OperandType operand_2> |
| 74 struct BytecodeTraits<operand_0, operand_1, operand_2, OPERAND_TERM> { | 101 struct BytecodeTraits<operand_0, operand_1, operand_2, OPERAND_TERM> { |
| 75 static inline OperandType GetOperandType(int i) { | 102 static inline OperandType GetOperandType(int i) { |
| 76 DCHECK(0 <= i && i <= 2); | 103 DCHECK(0 <= i && i <= 2); |
| 77 const OperandType kOperands[] = {operand_0, operand_1, operand_2}; | 104 const OperandType kOperands[] = {operand_0, operand_1, operand_2}; |
| 78 return kOperands[i]; | 105 return kOperands[i]; |
| 79 } | 106 } |
| 80 | 107 |
| 81 static inline OperandSize GetOperandSize(int i) { | 108 static inline OperandSize GetOperandSize(int i) { |
| 82 DCHECK(0 <= i && i < kOperandCount); | 109 DCHECK(0 <= i && i < kOperandCount); |
| 83 const OperandSize kOperandSizes[] = | 110 const OperandSize kOperandSizes[] = |
| 84 {OperandTraits<operand_0>::kSizeType, | 111 {OperandTraits<operand_0>::kSizeType, |
| 85 OperandTraits<operand_1>::kSizeType, | 112 OperandTraits<operand_1>::kSizeType, |
| 86 OperandTraits<operand_2>::kSizeType}; | 113 OperandTraits<operand_2>::kSizeType}; |
| 87 return kOperandSizes[i]; | 114 return kOperandSizes[i]; |
| 88 } | 115 } |
| 89 | 116 |
| 90 static inline int GetOperandOffset(int i) { | 117 static inline int GetOperandOffset(int i) { |
| 91 DCHECK(0 <= i && i < kOperandCount); | 118 DCHECK(0 <= i && i < kOperandCount); |
| 92 const int kOffset0 = 1; | 119 const int kOffset0 = 1; |
| 93 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize; | 120 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize; |
| 94 const int kOffset2 = kOffset1 + OperandTraits<operand_1>::kSize; | 121 const int kOffset2 = kOffset1 + OperandTraits<operand_1>::kSize; |
| 95 const int kOperandOffsets[] = {kOffset0, kOffset1, kOffset2}; | 122 const int kOperandOffsets[] = {kOffset0, kOffset1, kOffset2}; |
| 96 return kOperandOffsets[i]; | 123 return kOperandOffsets[i]; |
| 97 } | 124 } |
| 98 | 125 |
| 126 template <OperandType ot> |
| 127 static inline bool HasAnyOperandsOfType() { |
| 128 return operand_0 == ot || operand_1 == ot || operand_2 == ot; |
| 129 } |
| 130 |
| 99 static const int kOperandCount = 3; | 131 static const int kOperandCount = 3; |
| 132 static const int kRegisterOperandCount = |
| 133 RegisterOperandTraits<operand_0>::kIsRegisterOperand + |
| 134 RegisterOperandTraits<operand_1>::kIsRegisterOperand + |
| 135 RegisterOperandTraits<operand_2>::kIsRegisterOperand; |
| 136 static const int kRegisterOperandBitmap = |
| 137 RegisterOperandTraits<operand_0>::kIsRegisterOperand + |
| 138 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1) + |
| 139 (RegisterOperandTraits<operand_2>::kIsRegisterOperand << 2); |
| 100 static const int kSize = | 140 static const int kSize = |
| 101 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize + | 141 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize + |
| 102 OperandTraits<operand_2>::kSize; | 142 OperandTraits<operand_2>::kSize; |
| 103 }; | 143 }; |
| 104 | 144 |
| 105 template <OperandType operand_0, OperandType operand_1> | 145 template <OperandType operand_0, OperandType operand_1> |
| 106 struct BytecodeTraits<operand_0, operand_1, OPERAND_TERM> { | 146 struct BytecodeTraits<operand_0, operand_1, OPERAND_TERM> { |
| 107 static inline OperandType GetOperandType(int i) { | 147 static inline OperandType GetOperandType(int i) { |
| 108 DCHECK(0 <= i && i < kOperandCount); | 148 DCHECK(0 <= i && i < kOperandCount); |
| 109 const OperandType kOperands[] = {operand_0, operand_1}; | 149 const OperandType kOperands[] = {operand_0, operand_1}; |
| 110 return kOperands[i]; | 150 return kOperands[i]; |
| 111 } | 151 } |
| 112 | 152 |
| 113 static inline OperandSize GetOperandSize(int i) { | 153 static inline OperandSize GetOperandSize(int i) { |
| 114 DCHECK(0 <= i && i < kOperandCount); | 154 DCHECK(0 <= i && i < kOperandCount); |
| 115 const OperandSize kOperandSizes[] = | 155 const OperandSize kOperandSizes[] = |
| 116 {OperandTraits<operand_0>::kSizeType, | 156 {OperandTraits<operand_0>::kSizeType, |
| 117 OperandTraits<operand_1>::kSizeType}; | 157 OperandTraits<operand_1>::kSizeType}; |
| 118 return kOperandSizes[i]; | 158 return kOperandSizes[i]; |
| 119 } | 159 } |
| 120 | 160 |
| 121 static inline int GetOperandOffset(int i) { | 161 static inline int GetOperandOffset(int i) { |
| 122 DCHECK(0 <= i && i < kOperandCount); | 162 DCHECK(0 <= i && i < kOperandCount); |
| 123 const int kOffset0 = 1; | 163 const int kOffset0 = 1; |
| 124 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize; | 164 const int kOffset1 = kOffset0 + OperandTraits<operand_0>::kSize; |
| 125 const int kOperandOffsets[] = {kOffset0, kOffset1}; | 165 const int kOperandOffsets[] = {kOffset0, kOffset1}; |
| 126 return kOperandOffsets[i]; | 166 return kOperandOffsets[i]; |
| 127 } | 167 } |
| 128 | 168 |
| 169 template <OperandType ot> |
| 170 static inline bool HasAnyOperandsOfType() { |
| 171 return operand_0 == ot || operand_1 == ot; |
| 172 } |
| 173 |
| 129 static const int kOperandCount = 2; | 174 static const int kOperandCount = 2; |
| 175 static const int kRegisterOperandCount = |
| 176 RegisterOperandTraits<operand_0>::kIsRegisterOperand + |
| 177 RegisterOperandTraits<operand_1>::kIsRegisterOperand; |
| 178 static const int kRegisterOperandBitmap = |
| 179 RegisterOperandTraits<operand_0>::kIsRegisterOperand + |
| 180 (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1); |
| 130 static const int kSize = | 181 static const int kSize = |
| 131 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize; | 182 1 + OperandTraits<operand_0>::kSize + OperandTraits<operand_1>::kSize; |
| 132 }; | 183 }; |
| 133 | 184 |
| 134 template <OperandType operand_0> | 185 template <OperandType operand_0> |
| 135 struct BytecodeTraits<operand_0, OPERAND_TERM> { | 186 struct BytecodeTraits<operand_0, OPERAND_TERM> { |
| 136 static inline OperandType GetOperandType(int i) { | 187 static inline OperandType GetOperandType(int i) { |
| 137 DCHECK(i == 0); | 188 DCHECK(i == 0); |
| 138 return operand_0; | 189 return operand_0; |
| 139 } | 190 } |
| 140 | 191 |
| 141 static inline OperandSize GetOperandSize(int i) { | 192 static inline OperandSize GetOperandSize(int i) { |
| 142 DCHECK(i == 0); | 193 DCHECK(i == 0); |
| 143 return OperandTraits<operand_0>::kSizeType; | 194 return OperandTraits<operand_0>::kSizeType; |
| 144 } | 195 } |
| 145 | 196 |
| 146 static inline int GetOperandOffset(int i) { | 197 static inline int GetOperandOffset(int i) { |
| 147 DCHECK(i == 0); | 198 DCHECK(i == 0); |
| 148 return 1; | 199 return 1; |
| 149 } | 200 } |
| 150 | 201 |
| 202 template <OperandType ot> |
| 203 static inline bool HasAnyOperandsOfType() { |
| 204 return operand_0 == ot; |
| 205 } |
| 206 |
| 151 static const int kOperandCount = 1; | 207 static const int kOperandCount = 1; |
| 208 static const int kRegisterOperandCount = |
| 209 RegisterOperandTraits<operand_0>::kIsRegisterOperand; |
| 210 static const int kRegisterOperandBitmap = |
| 211 RegisterOperandTraits<operand_0>::kIsRegisterOperand; |
| 152 static const int kSize = 1 + OperandTraits<operand_0>::kSize; | 212 static const int kSize = 1 + OperandTraits<operand_0>::kSize; |
| 153 }; | 213 }; |
| 154 | 214 |
| 155 template <> | 215 template <> |
| 156 struct BytecodeTraits<OperandType::kNone, OPERAND_TERM> { | 216 struct BytecodeTraits<OperandType::kNone, OPERAND_TERM> { |
| 157 static inline OperandType GetOperandType(int i) { | 217 static inline OperandType GetOperandType(int i) { |
| 158 UNREACHABLE(); | 218 UNREACHABLE(); |
| 159 return OperandType::kNone; | 219 return OperandType::kNone; |
| 160 } | 220 } |
| 161 | 221 |
| 162 static inline OperandSize GetOperandSize(int i) { | 222 static inline OperandSize GetOperandSize(int i) { |
| 163 UNREACHABLE(); | 223 UNREACHABLE(); |
| 164 return OperandSize::kNone; | 224 return OperandSize::kNone; |
| 165 } | 225 } |
| 166 | 226 |
| 167 static inline int GetOperandOffset(int i) { | 227 static inline int GetOperandOffset(int i) { |
| 168 UNREACHABLE(); | 228 UNREACHABLE(); |
| 169 return 1; | 229 return 1; |
| 170 } | 230 } |
| 171 | 231 |
| 232 template <OperandType ot> |
| 233 static inline bool HasAnyOperandsOfType() { |
| 234 return false; |
| 235 } |
| 236 |
| 172 static const int kOperandCount = 0; | 237 static const int kOperandCount = 0; |
| 238 static const int kRegisterOperandCount = 0; |
| 239 static const int kRegisterOperandBitmap = 0; |
| 173 static const int kSize = 1 + OperandTraits<OperandType::kNone>::kSize; | 240 static const int kSize = 1 + OperandTraits<OperandType::kNone>::kSize; |
| 174 }; | 241 }; |
| 175 | 242 |
| 176 } // namespace interpreter | 243 } // namespace interpreter |
| 177 } // namespace internal | 244 } // namespace internal |
| 178 } // namespace v8 | 245 } // namespace v8 |
| 179 | 246 |
| 180 #endif // V8_INTERPRETER_BYTECODE_TRAITS_H_ | 247 #endif // V8_INTERPRETER_BYTECODE_TRAITS_H_ |
| OLD | NEW |