bytecode-traits.h 6.59 KB
Newer Older
1 2 3 4 5 6 7
// 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_

8
#include "src/interpreter/bytecode-operands.h"
9 10 11 12 13

namespace v8 {
namespace internal {
namespace interpreter {

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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

31
template <OperandType>
32
struct OperandTraits {
33
  using TypeInfoTraits = OperandTypeInfoTraits<OperandTypeInfo::kNone>;
34
  static const OperandTypeInfo kOperandTypeInfo = OperandTypeInfo::kNone;
35
};
36

37 38 39
#define DECLARE_OPERAND_TYPE_TRAITS(Name, InfoType)           \
  template <>                                                 \
  struct OperandTraits<OperandType::k##Name> {                \
40
    using TypeInfoTraits = OperandTypeInfoTraits<InfoType>;   \
41
    static const OperandTypeInfo kOperandTypeInfo = InfoType; \
42
  };
43 44
OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE_TRAITS)
#undef DECLARE_OPERAND_TYPE_TRAITS
45

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
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 =
62 63
      Helper<OperandTraits<operand_type>::TypeInfoTraits::kIsScalable,
             OperandTraits<operand_type>::TypeInfoTraits::kUnscaledSize,
64 65 66 67
             operand_scale>::kSize;
  static const OperandSize kOperandSize = static_cast<OperandSize>(kSize);
};

68 69 70 71 72
template <int... values>
struct SumHelper;
template <int value>
struct SumHelper<value> {
  static const int kValue = value;
73
};
74 75 76
template <int value, int... values>
struct SumHelper<value, values...> {
  static const int kValue = value + SumHelper<values...>::kValue;
77 78
};

79
template <ImplicitRegisterUse implicit_register_use, OperandType... operands>
80 81 82 83 84 85 86 87 88 89 90 91
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;
92
  static const ImplicitRegisterUse kImplicitRegisterUse = implicit_register_use;
93
  static const int kOperandCount = sizeof...(operands);
94 95
};

96
template <ImplicitRegisterUse implicit_register_use, OperandType... operands>
97
STATIC_CONST_MEMBER_DEFINITION const OperandType
98
    BytecodeTraits<implicit_register_use, operands...>::kOperandTypes[] = {
99
        operands...};
100
template <ImplicitRegisterUse implicit_register_use, OperandType... operands>
101
STATIC_CONST_MEMBER_DEFINITION const OperandTypeInfo
102
    BytecodeTraits<implicit_register_use, operands...>::kOperandTypeInfos[] = {
103
        OperandTraits<operands>::kOperandTypeInfo...};
104 105 106 107 108 109 110 111 112
template <ImplicitRegisterUse implicit_register_use, OperandType... operands>
STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits<
    implicit_register_use, operands...>::kSingleScaleOperandSizes[] = {
    OperandScaler<operands, OperandScale::kSingle>::kOperandSize...};
template <ImplicitRegisterUse implicit_register_use, OperandType... operands>
STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits<
    implicit_register_use, operands...>::kDoubleScaleOperandSizes[] = {
    OperandScaler<operands, OperandScale::kDouble>::kOperandSize...};
template <ImplicitRegisterUse implicit_register_use, OperandType... operands>
113
STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits<
114
    implicit_register_use, operands...>::kQuadrupleScaleOperandSizes[] = {
115
    OperandScaler<operands, OperandScale::kQuadruple>::kOperandSize...};
116

117 118
template <ImplicitRegisterUse implicit_register_use>
struct BytecodeTraits<implicit_register_use> {
119 120 121 122 123 124 125 126
  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;
127
  static const ImplicitRegisterUse kImplicitRegisterUse = implicit_register_use;
128 129 130
  static const int kOperandCount = 0;
};

131
template <ImplicitRegisterUse implicit_register_use>
132
STATIC_CONST_MEMBER_DEFINITION const OperandType
133 134 135
    BytecodeTraits<implicit_register_use>::kOperandTypes[] = {
        OperandType::kNone};
template <ImplicitRegisterUse implicit_register_use>
136
STATIC_CONST_MEMBER_DEFINITION const OperandTypeInfo
137
    BytecodeTraits<implicit_register_use>::kOperandTypeInfos[] = {
138
        OperandTypeInfo::kNone};
139
template <ImplicitRegisterUse implicit_register_use>
140
STATIC_CONST_MEMBER_DEFINITION const OperandSize
141
    BytecodeTraits<implicit_register_use>::kSingleScaleOperandSizes[] = {
142
        OperandSize::kNone};
143
template <ImplicitRegisterUse implicit_register_use>
144
STATIC_CONST_MEMBER_DEFINITION const OperandSize
145
    BytecodeTraits<implicit_register_use>::kDoubleScaleOperandSizes[] = {
146
        OperandSize::kNone};
147
template <ImplicitRegisterUse implicit_register_use>
148
STATIC_CONST_MEMBER_DEFINITION const OperandSize
149
    BytecodeTraits<implicit_register_use>::kQuadrupleScaleOperandSizes[] = {
150
        OperandSize::kNone};
151

152 153 154 155 156
}  // namespace interpreter
}  // namespace internal
}  // namespace v8

#endif  // V8_INTERPRETER_BYTECODE_TRAITS_H_