diff options
Diffstat (limited to 'deps/v8/src/interpreter/bytecode-traits.h')
-rw-r--r-- | deps/v8/src/interpreter/bytecode-traits.h | 183 |
1 files changed, 106 insertions, 77 deletions
diff --git a/deps/v8/src/interpreter/bytecode-traits.h b/deps/v8/src/interpreter/bytecode-traits.h index c724827356..672a687faf 100644 --- a/deps/v8/src/interpreter/bytecode-traits.h +++ b/deps/v8/src/interpreter/bytecode-traits.h @@ -30,17 +30,41 @@ OPERAND_TYPE_INFO_LIST(DECLARE_OPERAND_TYPE_INFO) template <OperandType> struct OperandTraits { - typedef OperandTypeInfoTraits<OperandTypeInfo::kNone> TypeInfo; + typedef OperandTypeInfoTraits<OperandTypeInfo::kNone> TypeInfoTraits; + static const OperandTypeInfo kOperandTypeInfo = OperandTypeInfo::kNone; }; -#define DECLARE_OPERAND_TYPE_TRAITS(Name, InfoType) \ - template <> \ - struct OperandTraits<OperandType::k##Name> { \ - typedef OperandTypeInfoTraits<InfoType> TypeInfo; \ +#define DECLARE_OPERAND_TYPE_TRAITS(Name, InfoType) \ + template <> \ + struct OperandTraits<OperandType::k##Name> { \ + typedef OperandTypeInfoTraits<InfoType> TypeInfoTraits; \ + static const OperandTypeInfo kOperandTypeInfo = InfoType; \ }; OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE_TRAITS) #undef DECLARE_OPERAND_TYPE_TRAITS +template <OperandType operand_type, OperandScale operand_scale> +struct OperandScaler { + template <bool, OperandSize, OperandScale> + struct Helper { + static const int kSize = 0; + }; + template <OperandSize size, OperandScale scale> + struct Helper<false, size, scale> { + static const int kSize = static_cast<int>(size); + }; + template <OperandSize size, OperandScale scale> + struct Helper<true, size, scale> { + static const int kSize = static_cast<int>(size) * static_cast<int>(scale); + }; + + static const int kSize = + Helper<OperandTraits<operand_type>::TypeInfoTraits::kIsScalable, + OperandTraits<operand_type>::TypeInfoTraits::kUnscaledSize, + operand_scale>::kSize; + static const OperandSize kOperandSize = static_cast<OperandSize>(kSize); +}; + template <OperandType> struct RegisterOperandTraits { static const int kIsRegisterOperand = 0; @@ -61,11 +85,19 @@ template <AccumulatorUse accumulator_use, OperandType operand_0, OperandType operand_1, OperandType operand_2, OperandType operand_3> struct BytecodeTraits<accumulator_use, operand_0, operand_1, operand_2, operand_3> { - static OperandType GetOperandType(int i) { - DCHECK(0 <= i && i < kOperandCount); - const OperandType kOperands[] = {operand_0, operand_1, operand_2, - operand_3}; - return kOperands[i]; + static const OperandType* GetOperandTypes() { + static const OperandType operand_types[] = {operand_0, operand_1, operand_2, + operand_3, OperandType::kNone}; + return operand_types; + } + + static const OperandTypeInfo* GetOperandTypeInfos() { + static const OperandTypeInfo operand_type_infos[] = { + OperandTraits<operand_0>::kOperandTypeInfo, + OperandTraits<operand_1>::kOperandTypeInfo, + OperandTraits<operand_2>::kOperandTypeInfo, + OperandTraits<operand_3>::kOperandTypeInfo, OperandTypeInfo::kNone}; + return operand_type_infos; } template <OperandType ot> @@ -75,10 +107,10 @@ struct BytecodeTraits<accumulator_use, operand_0, operand_1, operand_2, } static inline bool IsScalable() { - return (OperandTraits<operand_0>::TypeInfo::kIsScalable | - OperandTraits<operand_1>::TypeInfo::kIsScalable | - OperandTraits<operand_2>::TypeInfo::kIsScalable | - OperandTraits<operand_3>::TypeInfo::kIsScalable); + return (OperandTraits<operand_0>::TypeInfoTraits::kIsScalable | + OperandTraits<operand_1>::TypeInfoTraits::kIsScalable | + OperandTraits<operand_2>::TypeInfoTraits::kIsScalable | + OperandTraits<operand_3>::TypeInfoTraits::kIsScalable); } static const AccumulatorUse kAccumulatorUse = accumulator_use; @@ -88,20 +120,23 @@ struct BytecodeTraits<accumulator_use, operand_0, operand_1, operand_2, RegisterOperandTraits<operand_1>::kIsRegisterOperand + RegisterOperandTraits<operand_2>::kIsRegisterOperand + RegisterOperandTraits<operand_3>::kIsRegisterOperand; - static const int kRegisterOperandBitmap = - RegisterOperandTraits<operand_0>::kIsRegisterOperand + - (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1) + - (RegisterOperandTraits<operand_2>::kIsRegisterOperand << 2) + - (RegisterOperandTraits<operand_3>::kIsRegisterOperand << 3); }; template <AccumulatorUse accumulator_use, OperandType operand_0, OperandType operand_1, OperandType operand_2> struct BytecodeTraits<accumulator_use, operand_0, operand_1, operand_2> { - static inline OperandType GetOperandType(int i) { - DCHECK(0 <= i && i <= 2); - const OperandType kOperands[] = {operand_0, operand_1, operand_2}; - return kOperands[i]; + static const OperandType* GetOperandTypes() { + static const OperandType operand_types[] = {operand_0, operand_1, operand_2, + OperandType::kNone}; + return operand_types; + } + + static const OperandTypeInfo* GetOperandTypeInfos() { + static const OperandTypeInfo operand_type_infos[] = { + OperandTraits<operand_0>::kOperandTypeInfo, + OperandTraits<operand_1>::kOperandTypeInfo, + OperandTraits<operand_2>::kOperandTypeInfo, OperandTypeInfo::kNone}; + return operand_type_infos; } template <OperandType ot> @@ -110,9 +145,9 @@ struct BytecodeTraits<accumulator_use, operand_0, operand_1, operand_2> { } static inline bool IsScalable() { - return (OperandTraits<operand_0>::TypeInfo::kIsScalable | - OperandTraits<operand_1>::TypeInfo::kIsScalable | - OperandTraits<operand_2>::TypeInfo::kIsScalable); + return (OperandTraits<operand_0>::TypeInfoTraits::kIsScalable | + OperandTraits<operand_1>::TypeInfoTraits::kIsScalable | + OperandTraits<operand_2>::TypeInfoTraits::kIsScalable); } static const AccumulatorUse kAccumulatorUse = accumulator_use; @@ -121,19 +156,22 @@ struct BytecodeTraits<accumulator_use, operand_0, operand_1, operand_2> { RegisterOperandTraits<operand_0>::kIsRegisterOperand + RegisterOperandTraits<operand_1>::kIsRegisterOperand + RegisterOperandTraits<operand_2>::kIsRegisterOperand; - static const int kRegisterOperandBitmap = - RegisterOperandTraits<operand_0>::kIsRegisterOperand + - (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1) + - (RegisterOperandTraits<operand_2>::kIsRegisterOperand << 2); }; template <AccumulatorUse accumulator_use, OperandType operand_0, OperandType operand_1> struct BytecodeTraits<accumulator_use, operand_0, operand_1> { - static inline OperandType GetOperandType(int i) { - DCHECK(0 <= i && i < kOperandCount); - const OperandType kOperands[] = {operand_0, operand_1}; - return kOperands[i]; + static const OperandType* GetOperandTypes() { + static const OperandType operand_types[] = {operand_0, operand_1, + OperandType::kNone}; + return operand_types; + } + + static const OperandTypeInfo* GetOperandTypeInfos() { + static const OperandTypeInfo operand_type_infos[] = { + OperandTraits<operand_0>::kOperandTypeInfo, + OperandTraits<operand_1>::kOperandTypeInfo, OperandTypeInfo::kNone}; + return operand_type_infos; } template <OperandType ot> @@ -142,8 +180,8 @@ struct BytecodeTraits<accumulator_use, operand_0, operand_1> { } static inline bool IsScalable() { - return (OperandTraits<operand_0>::TypeInfo::kIsScalable | - OperandTraits<operand_1>::TypeInfo::kIsScalable); + return (OperandTraits<operand_0>::TypeInfoTraits::kIsScalable | + OperandTraits<operand_1>::TypeInfoTraits::kIsScalable); } static const AccumulatorUse kAccumulatorUse = accumulator_use; @@ -151,16 +189,19 @@ struct BytecodeTraits<accumulator_use, operand_0, operand_1> { static const int kRegisterOperandCount = RegisterOperandTraits<operand_0>::kIsRegisterOperand + RegisterOperandTraits<operand_1>::kIsRegisterOperand; - static const int kRegisterOperandBitmap = - RegisterOperandTraits<operand_0>::kIsRegisterOperand + - (RegisterOperandTraits<operand_1>::kIsRegisterOperand << 1); }; template <AccumulatorUse accumulator_use, OperandType operand_0> struct BytecodeTraits<accumulator_use, operand_0> { - static inline OperandType GetOperandType(int i) { - DCHECK(i == 0); - return operand_0; + static const OperandType* GetOperandTypes() { + static const OperandType operand_types[] = {operand_0, OperandType::kNone}; + return operand_types; + } + + static const OperandTypeInfo* GetOperandTypeInfos() { + static const OperandTypeInfo operand_type_infos[] = { + OperandTraits<operand_0>::kOperandTypeInfo, OperandTypeInfo::kNone}; + return operand_type_infos; } template <OperandType ot> @@ -169,22 +210,26 @@ struct BytecodeTraits<accumulator_use, operand_0> { } static inline bool IsScalable() { - return OperandTraits<operand_0>::TypeInfo::kIsScalable; + return OperandTraits<operand_0>::TypeInfoTraits::kIsScalable; } static const AccumulatorUse kAccumulatorUse = accumulator_use; static const int kOperandCount = 1; static const int kRegisterOperandCount = RegisterOperandTraits<operand_0>::kIsRegisterOperand; - static const int kRegisterOperandBitmap = - RegisterOperandTraits<operand_0>::kIsRegisterOperand; }; template <AccumulatorUse accumulator_use> struct BytecodeTraits<accumulator_use> { - static inline OperandType GetOperandType(int i) { - UNREACHABLE(); - return OperandType::kNone; + static const OperandType* GetOperandTypes() { + static const OperandType operand_types[] = {OperandType::kNone}; + return operand_types; + } + + static const OperandTypeInfo* GetOperandTypeInfos() { + static const OperandTypeInfo operand_type_infos[] = { + OperandTypeInfo::kNone}; + return operand_type_infos; } template <OperandType ot> @@ -197,40 +242,24 @@ struct BytecodeTraits<accumulator_use> { static const AccumulatorUse kAccumulatorUse = accumulator_use; static const int kOperandCount = 0; static const int kRegisterOperandCount = 0; - static const int kRegisterOperandBitmap = 0; -}; - -template <bool> -struct OperandScaler { - static int Multiply(int size, int operand_scale) { return 0; } -}; - -template <> -struct OperandScaler<false> { - static int Multiply(int size, int operand_scale) { return size; } -}; - -template <> -struct OperandScaler<true> { - static int Multiply(int size, int operand_scale) { - return size * operand_scale; - } }; static OperandSize ScaledOperandSize(OperandType operand_type, OperandScale operand_scale) { + STATIC_ASSERT(static_cast<int>(OperandScale::kQuadruple) == 4 && + OperandScale::kLast == OperandScale::kQuadruple); + int index = static_cast<int>(operand_scale) >> 1; switch (operand_type) { -#define CASE(Name, TypeInfo) \ - case OperandType::k##Name: { \ - OperandSize base_size = OperandTypeInfoTraits<TypeInfo>::kUnscaledSize; \ - int size = \ - OperandScaler<OperandTypeInfoTraits<TypeInfo>::kIsScalable>::Multiply( \ - static_cast<int>(base_size), static_cast<int>(operand_scale)); \ - OperandSize operand_size = static_cast<OperandSize>(size); \ - DCHECK(operand_size == OperandSize::kByte || \ - operand_size == OperandSize::kShort || \ - operand_size == OperandSize::kQuad); \ - return operand_size; \ +#define CASE(Name, TypeInfo) \ + case OperandType::k##Name: { \ + static const OperandSize kOperandSizes[] = { \ + OperandScaler<OperandType::k##Name, \ + OperandScale::kSingle>::kOperandSize, \ + OperandScaler<OperandType::k##Name, \ + OperandScale::kDouble>::kOperandSize, \ + OperandScaler<OperandType::k##Name, \ + OperandScale::kQuadruple>::kOperandSize}; \ + return kOperandSizes[index]; \ } OPERAND_TYPE_LIST(CASE) #undef CASE |