// Copyright 2015 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_INTERPRETER_BYTECODE_TRAITS_H_ #define V8_INTERPRETER_BYTECODE_TRAITS_H_ #include "src/interpreter/bytecode-operands.h" namespace v8 { namespace internal { namespace interpreter { template struct OperandTypeInfoTraits { static const bool kIsScalable = false; static const bool kIsUnsigned = false; static const OperandSize kUnscaledSize = OperandSize::kNone; }; #define DECLARE_OPERAND_TYPE_INFO(Name, Scalable, Unsigned, BaseSize) \ template <> \ struct OperandTypeInfoTraits { \ static const bool kIsScalable = Scalable; \ static const bool kIsUnsigned = Unsigned; \ static const OperandSize kUnscaledSize = BaseSize; \ }; OPERAND_TYPE_INFO_LIST(DECLARE_OPERAND_TYPE_INFO) #undef DECLARE_OPERAND_TYPE_INFO template struct OperandTraits { typedef OperandTypeInfoTraits TypeInfoTraits; static const OperandTypeInfo kOperandTypeInfo = OperandTypeInfo::kNone; }; #define DECLARE_OPERAND_TYPE_TRAITS(Name, InfoType) \ template <> \ struct OperandTraits { \ typedef OperandTypeInfoTraits TypeInfoTraits; \ static const OperandTypeInfo kOperandTypeInfo = InfoType; \ }; OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE_TRAITS) #undef DECLARE_OPERAND_TYPE_TRAITS template struct OperandScaler { template struct Helper { static const int kSize = 0; }; template struct Helper { static const int kSize = static_cast(size); }; template struct Helper { static const int kSize = static_cast(size) * static_cast(scale); }; static const int kSize = Helper::TypeInfoTraits::kIsScalable, OperandTraits::TypeInfoTraits::kUnscaledSize, operand_scale>::kSize; static const OperandSize kOperandSize = static_cast(kSize); }; template struct SumHelper; template struct SumHelper { static const int kValue = value; }; template struct SumHelper { static const int kValue = value + SumHelper::kValue; }; template struct BytecodeTraits { static const OperandType kOperandTypes[]; static const OperandTypeInfo kOperandTypeInfos[]; static const OperandSize kSingleScaleOperandSizes[]; static const OperandSize kDoubleScaleOperandSizes[]; static const OperandSize kQuadrupleScaleOperandSizes[]; static const int kSingleScaleSize = SumHelper< 1, OperandScaler::kSize...>::kValue; static const int kDoubleScaleSize = SumHelper< 1, OperandScaler::kSize...>::kValue; static const int kQuadrupleScaleSize = SumHelper< 1, OperandScaler::kSize...>::kValue; static const AccumulatorUse kAccumulatorUse = accumulator_use; static const int kOperandCount = sizeof...(operands); }; template STATIC_CONST_MEMBER_DEFINITION const OperandType BytecodeTraits::kOperandTypes[] = { operands...}; template STATIC_CONST_MEMBER_DEFINITION const OperandTypeInfo BytecodeTraits::kOperandTypeInfos[] = { OperandTraits::kOperandTypeInfo...}; template STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits::kSingleScaleOperandSizes[] = { OperandScaler::kOperandSize...}; template STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits::kDoubleScaleOperandSizes[] = { OperandScaler::kOperandSize...}; template STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits< accumulator_use, operands...>::kQuadrupleScaleOperandSizes[] = { OperandScaler::kOperandSize...}; template struct BytecodeTraits { static const OperandType kOperandTypes[]; static const OperandTypeInfo kOperandTypeInfos[]; static const OperandSize kSingleScaleOperandSizes[]; static const OperandSize kDoubleScaleOperandSizes[]; static const OperandSize kQuadrupleScaleOperandSizes[]; static const int kSingleScaleSize = 1; static const int kDoubleScaleSize = 1; static const int kQuadrupleScaleSize = 1; static const AccumulatorUse kAccumulatorUse = accumulator_use; static const int kOperandCount = 0; }; template STATIC_CONST_MEMBER_DEFINITION const OperandType BytecodeTraits::kOperandTypes[] = {OperandType::kNone}; template STATIC_CONST_MEMBER_DEFINITION const OperandTypeInfo BytecodeTraits::kOperandTypeInfos[] = { OperandTypeInfo::kNone}; template STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits::kSingleScaleOperandSizes[] = { OperandSize::kNone}; template STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits::kDoubleScaleOperandSizes[] = { OperandSize::kNone}; template STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits::kQuadrupleScaleOperandSizes[] = { OperandSize::kNone}; } // namespace interpreter } // namespace internal } // namespace v8 #endif // V8_INTERPRETER_BYTECODE_TRAITS_H_