2015-10-01 17:22:58 +00:00
|
|
|
// 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_
|
|
|
|
|
2016-09-22 16:34:16 +00:00
|
|
|
#include "src/interpreter/bytecode-operands.h"
|
2015-10-01 17:22:58 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace interpreter {
|
|
|
|
|
2016-03-21 17:08:21 +00:00
|
|
|
template <OperandTypeInfo>
|
|
|
|
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<OperandTypeInfo::k##Name> { \
|
|
|
|
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
|
|
|
|
|
2015-10-01 17:22:58 +00:00
|
|
|
template <OperandType>
|
2016-03-21 17:08:21 +00:00
|
|
|
struct OperandTraits {
|
2016-06-10 10:34:50 +00:00
|
|
|
typedef OperandTypeInfoTraits<OperandTypeInfo::kNone> TypeInfoTraits;
|
|
|
|
static const OperandTypeInfo kOperandTypeInfo = OperandTypeInfo::kNone;
|
2016-03-21 17:08:21 +00:00
|
|
|
};
|
2015-10-01 17:22:58 +00:00
|
|
|
|
2016-06-10 10:34:50 +00:00
|
|
|
#define DECLARE_OPERAND_TYPE_TRAITS(Name, InfoType) \
|
|
|
|
template <> \
|
|
|
|
struct OperandTraits<OperandType::k##Name> { \
|
|
|
|
typedef OperandTypeInfoTraits<InfoType> TypeInfoTraits; \
|
|
|
|
static const OperandTypeInfo kOperandTypeInfo = InfoType; \
|
2015-10-01 17:22:58 +00:00
|
|
|
};
|
2016-03-21 17:08:21 +00:00
|
|
|
OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE_TRAITS)
|
|
|
|
#undef DECLARE_OPERAND_TYPE_TRAITS
|
2015-10-01 17:22:58 +00:00
|
|
|
|
2016-05-12 19:18:07 +00:00
|
|
|
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 =
|
2016-06-10 10:34:50 +00:00
|
|
|
Helper<OperandTraits<operand_type>::TypeInfoTraits::kIsScalable,
|
|
|
|
OperandTraits<operand_type>::TypeInfoTraits::kUnscaledSize,
|
2016-05-12 19:18:07 +00:00
|
|
|
operand_scale>::kSize;
|
|
|
|
static const OperandSize kOperandSize = static_cast<OperandSize>(kSize);
|
|
|
|
};
|
|
|
|
|
2016-09-22 16:34:16 +00:00
|
|
|
template <int... values>
|
|
|
|
struct SumHelper;
|
|
|
|
template <int value>
|
|
|
|
struct SumHelper<value> {
|
|
|
|
static const int kValue = value;
|
2016-01-26 13:55:28 +00:00
|
|
|
};
|
2016-09-22 16:34:16 +00:00
|
|
|
template <int value, int... values>
|
|
|
|
struct SumHelper<value, values...> {
|
|
|
|
static const int kValue = value + SumHelper<values...>::kValue;
|
2015-10-01 17:22:58 +00:00
|
|
|
};
|
|
|
|
|
2016-09-22 16:34:16 +00:00
|
|
|
template <AccumulatorUse accumulator_use, OperandType... operands>
|
|
|
|
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<operands, OperandScale::kSingle>::kSize...>::kValue;
|
|
|
|
static const int kDoubleScaleSize = SumHelper<
|
|
|
|
1, OperandScaler<operands, OperandScale::kDouble>::kSize...>::kValue;
|
|
|
|
static const int kQuadrupleScaleSize = SumHelper<
|
|
|
|
1, OperandScaler<operands, OperandScale::kQuadruple>::kSize...>::kValue;
|
2016-04-06 07:57:35 +00:00
|
|
|
static const AccumulatorUse kAccumulatorUse = accumulator_use;
|
2016-09-22 16:34:16 +00:00
|
|
|
static const int kOperandCount = sizeof...(operands);
|
2015-10-01 17:22:58 +00:00
|
|
|
};
|
|
|
|
|
2016-09-22 16:34:16 +00:00
|
|
|
template <AccumulatorUse accumulator_use, OperandType... operands>
|
|
|
|
STATIC_CONST_MEMBER_DEFINITION const OperandType
|
|
|
|
BytecodeTraits<accumulator_use, operands...>::kOperandTypes[] = {
|
|
|
|
operands...};
|
|
|
|
template <AccumulatorUse accumulator_use, OperandType... operands>
|
|
|
|
STATIC_CONST_MEMBER_DEFINITION const OperandTypeInfo
|
|
|
|
BytecodeTraits<accumulator_use, operands...>::kOperandTypeInfos[] = {
|
|
|
|
OperandTraits<operands>::kOperandTypeInfo...};
|
|
|
|
template <AccumulatorUse accumulator_use, OperandType... operands>
|
|
|
|
STATIC_CONST_MEMBER_DEFINITION const OperandSize
|
|
|
|
BytecodeTraits<accumulator_use, operands...>::kSingleScaleOperandSizes[] = {
|
|
|
|
OperandScaler<operands, OperandScale::kSingle>::kOperandSize...};
|
|
|
|
template <AccumulatorUse accumulator_use, OperandType... operands>
|
|
|
|
STATIC_CONST_MEMBER_DEFINITION const OperandSize
|
|
|
|
BytecodeTraits<accumulator_use, operands...>::kDoubleScaleOperandSizes[] = {
|
|
|
|
OperandScaler<operands, OperandScale::kDouble>::kOperandSize...};
|
|
|
|
template <AccumulatorUse accumulator_use, OperandType... operands>
|
|
|
|
STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits<
|
|
|
|
accumulator_use, operands...>::kQuadrupleScaleOperandSizes[] = {
|
|
|
|
OperandScaler<operands, OperandScale::kQuadruple>::kOperandSize...};
|
2015-10-01 17:22:58 +00:00
|
|
|
|
2016-04-06 07:57:35 +00:00
|
|
|
template <AccumulatorUse accumulator_use>
|
|
|
|
struct BytecodeTraits<accumulator_use> {
|
2016-09-22 16:34:16 +00:00
|
|
|
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;
|
2016-04-06 07:57:35 +00:00
|
|
|
static const AccumulatorUse kAccumulatorUse = accumulator_use;
|
2015-10-01 17:22:58 +00:00
|
|
|
static const int kOperandCount = 0;
|
|
|
|
};
|
|
|
|
|
2016-09-22 16:34:16 +00:00
|
|
|
template <AccumulatorUse accumulator_use>
|
|
|
|
STATIC_CONST_MEMBER_DEFINITION const OperandType
|
|
|
|
BytecodeTraits<accumulator_use>::kOperandTypes[] = {OperandType::kNone};
|
|
|
|
template <AccumulatorUse accumulator_use>
|
|
|
|
STATIC_CONST_MEMBER_DEFINITION const OperandTypeInfo
|
|
|
|
BytecodeTraits<accumulator_use>::kOperandTypeInfos[] = {
|
|
|
|
OperandTypeInfo::kNone};
|
|
|
|
template <AccumulatorUse accumulator_use>
|
|
|
|
STATIC_CONST_MEMBER_DEFINITION const OperandSize
|
|
|
|
BytecodeTraits<accumulator_use>::kSingleScaleOperandSizes[] = {
|
|
|
|
OperandSize::kNone};
|
|
|
|
template <AccumulatorUse accumulator_use>
|
|
|
|
STATIC_CONST_MEMBER_DEFINITION const OperandSize
|
|
|
|
BytecodeTraits<accumulator_use>::kDoubleScaleOperandSizes[] = {
|
|
|
|
OperandSize::kNone};
|
|
|
|
template <AccumulatorUse accumulator_use>
|
|
|
|
STATIC_CONST_MEMBER_DEFINITION const OperandSize
|
|
|
|
BytecodeTraits<accumulator_use>::kQuadrupleScaleOperandSizes[] = {
|
|
|
|
OperandSize::kNone};
|
2016-03-21 17:08:21 +00:00
|
|
|
|
2015-10-01 17:22:58 +00:00
|
|
|
} // namespace interpreter
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_INTERPRETER_BYTECODE_TRAITS_H_
|