Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Unified Diff: src/interpreter/bytecode-traits.h

Issue 2351763002: [Interpreter] Optimize BytecodeArrayBuilder and BytecodeArrayWriter. (Closed)
Patch Set: [Interpreter] Optimize BytecodeArrayBuilder and BytecodeArrayWriter. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/interpreter/bytecode-traits.h
diff --git a/src/interpreter/bytecode-traits.h b/src/interpreter/bytecode-traits.h
index 672a687faf0f7cddabea7314190cb6f3ff6140fc..a7ac0561931cacf1cf7d2dd0f7d7f7bfe1d9d3c1 100644
--- a/src/interpreter/bytecode-traits.h
+++ b/src/interpreter/bytecode-traits.h
@@ -5,7 +5,7 @@
#ifndef V8_INTERPRETER_BYTECODE_TRAITS_H_
#define V8_INTERPRETER_BYTECODE_TRAITS_H_
-#include "src/interpreter/bytecodes.h"
+#include "src/interpreter/bytecode-operands.h"
namespace v8 {
namespace internal {
@@ -65,19 +65,6 @@ struct OperandScaler {
static const OperandSize kOperandSize = static_cast<OperandSize>(kSize);
};
-template <OperandType>
-struct RegisterOperandTraits {
- static const int kIsRegisterOperand = 0;
-};
-
-#define DECLARE_REGISTER_OPERAND(Name, _) \
- template <> \
- struct RegisterOperandTraits<OperandType::k##Name> { \
- static const int kIsRegisterOperand = 1; \
- };
-REGISTER_OPERAND_TYPE_LIST(DECLARE_REGISTER_OPERAND)
-#undef DECLARE_REGISTER_OPERAND
-
template <AccumulatorUse, OperandType...>
struct BytecodeTraits {};
@@ -85,188 +72,248 @@ template <AccumulatorUse accumulator_use, OperandType operand_0,
OperandType operand_1, OperandType operand_2, OperandType operand_3>
Leszek Swirski 2016/09/20 10:37:56 Would this code benefit from template packs? e.g.
rmcilroy 2016/09/20 16:57:25 Great suggestion! Works like a charm, thanks.
struct BytecodeTraits<accumulator_use, operand_0, operand_1, operand_2,
operand_3> {
- 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>
- static inline bool HasAnyOperandsOfType() {
- return operand_0 == ot || operand_1 == ot || operand_2 == ot ||
- operand_3 == ot;
- }
-
- static inline bool IsScalable() {
- 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;
- static const int kOperandCount = 4;
- static const int kRegisterOperandCount =
- RegisterOperandTraits<operand_0>::kIsRegisterOperand +
- RegisterOperandTraits<operand_1>::kIsRegisterOperand +
- RegisterOperandTraits<operand_2>::kIsRegisterOperand +
- RegisterOperandTraits<operand_3>::kIsRegisterOperand;
+ static constexpr OperandType kOperandTypes[] = {operand_0, operand_1,
+ operand_2, operand_3};
+ static constexpr OperandTypeInfo kOperandTypeInfos[] = {
+ OperandTraits<operand_0>::kOperandTypeInfo,
+ OperandTraits<operand_1>::kOperandTypeInfo,
+ OperandTraits<operand_2>::kOperandTypeInfo,
+ OperandTraits<operand_3>::kOperandTypeInfo};
+ static constexpr OperandSize kSingleScaleOperandSizes[] = {
+ OperandScaler<operand_0, OperandScale::kSingle>::kOperandSize,
+ OperandScaler<operand_1, OperandScale::kSingle>::kOperandSize,
+ OperandScaler<operand_2, OperandScale::kSingle>::kOperandSize,
+ OperandScaler<operand_3, OperandScale::kSingle>::kOperandSize};
+ static constexpr OperandSize kDoubleScaleOperandSizes[] = {
+ OperandScaler<operand_0, OperandScale::kDouble>::kOperandSize,
+ OperandScaler<operand_1, OperandScale::kDouble>::kOperandSize,
+ OperandScaler<operand_2, OperandScale::kDouble>::kOperandSize,
+ OperandScaler<operand_3, OperandScale::kDouble>::kOperandSize};
+ static constexpr OperandSize kQuadrupleScaleOperandSizes[] = {
+ OperandScaler<operand_0, OperandScale::kQuadruple>::kOperandSize,
+ OperandScaler<operand_1, OperandScale::kQuadruple>::kOperandSize,
+ OperandScaler<operand_2, OperandScale::kQuadruple>::kOperandSize,
+ OperandScaler<operand_3, OperandScale::kQuadruple>::kOperandSize};
+ static constexpr int kSingleScaleSize =
+ 1 + OperandScaler<operand_0, OperandScale::kSingle>::kSize +
+ OperandScaler<operand_1, OperandScale::kSingle>::kSize +
+ OperandScaler<operand_2, OperandScale::kSingle>::kSize +
+ OperandScaler<operand_3, OperandScale::kSingle>::kSize;
+ static constexpr int kDoubleScaleSize =
+ 1 + OperandScaler<operand_0, OperandScale::kDouble>::kSize +
+ OperandScaler<operand_1, OperandScale::kDouble>::kSize +
+ OperandScaler<operand_2, OperandScale::kDouble>::kSize +
+ OperandScaler<operand_3, OperandScale::kDouble>::kSize;
+ static constexpr int kQuadrupleScaleSize =
+ 1 + OperandScaler<operand_0, OperandScale::kQuadruple>::kSize +
+ OperandScaler<operand_1, OperandScale::kQuadruple>::kSize +
+ OperandScaler<operand_2, OperandScale::kQuadruple>::kSize +
+ OperandScaler<operand_3, OperandScale::kQuadruple>::kSize;
+ static constexpr AccumulatorUse kAccumulatorUse = accumulator_use;
+ static constexpr int kOperandCount = 4;
};
template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1, OperandType operand_2, OperandType operand_3>
+constexpr OperandType BytecodeTraits<accumulator_use, operand_0, operand_1,
+ operand_2, operand_3>::kOperandTypes[];
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1, OperandType operand_2, OperandType operand_3>
+constexpr OperandTypeInfo
+ BytecodeTraits<accumulator_use, operand_0, operand_1, operand_2,
+ operand_3>::kOperandTypeInfos[];
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1, OperandType operand_2, OperandType operand_3>
+constexpr OperandSize
+ BytecodeTraits<accumulator_use, operand_0, operand_1, operand_2,
+ operand_3>::kSingleScaleOperandSizes[];
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1, OperandType operand_2, OperandType operand_3>
+constexpr OperandSize
+ BytecodeTraits<accumulator_use, operand_0, operand_1, operand_2,
+ operand_3>::kDoubleScaleOperandSizes[];
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1, OperandType operand_2, OperandType operand_3>
+constexpr OperandSize
+ BytecodeTraits<accumulator_use, operand_0, operand_1, operand_2,
+ operand_3>::kQuadrupleScaleOperandSizes[];
+
+template <AccumulatorUse accumulator_use, OperandType operand_0,
OperandType operand_1, OperandType operand_2>
struct BytecodeTraits<accumulator_use, operand_0, operand_1, operand_2> {
- 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>
- static inline bool HasAnyOperandsOfType() {
- return operand_0 == ot || operand_1 == ot || operand_2 == ot;
- }
-
- static inline bool IsScalable() {
- return (OperandTraits<operand_0>::TypeInfoTraits::kIsScalable |
- OperandTraits<operand_1>::TypeInfoTraits::kIsScalable |
- OperandTraits<operand_2>::TypeInfoTraits::kIsScalable);
- }
-
+ static constexpr OperandType kOperandTypes[] = {operand_0, operand_1,
+ operand_2};
+ static constexpr OperandTypeInfo kOperandTypeInfos[] = {
+ OperandTraits<operand_0>::kOperandTypeInfo,
+ OperandTraits<operand_1>::kOperandTypeInfo,
+ OperandTraits<operand_2>::kOperandTypeInfo};
+ static constexpr OperandSize kSingleScaleOperandSizes[] = {
+ OperandScaler<operand_0, OperandScale::kSingle>::kOperandSize,
+ OperandScaler<operand_1, OperandScale::kSingle>::kOperandSize,
+ OperandScaler<operand_2, OperandScale::kSingle>::kOperandSize};
+ static constexpr OperandSize kDoubleScaleOperandSizes[] = {
+ OperandScaler<operand_0, OperandScale::kDouble>::kOperandSize,
+ OperandScaler<operand_1, OperandScale::kDouble>::kOperandSize,
+ OperandScaler<operand_2, OperandScale::kDouble>::kOperandSize};
+ static constexpr OperandSize kQuadrupleScaleOperandSizes[] = {
+ OperandScaler<operand_0, OperandScale::kQuadruple>::kOperandSize,
+ OperandScaler<operand_1, OperandScale::kQuadruple>::kOperandSize,
+ OperandScaler<operand_2, OperandScale::kQuadruple>::kOperandSize};
+ static constexpr int kSingleScaleSize =
+ 1 + OperandScaler<operand_0, OperandScale::kSingle>::kSize +
+ OperandScaler<operand_1, OperandScale::kSingle>::kSize +
+ OperandScaler<operand_2, OperandScale::kSingle>::kSize;
+ static constexpr int kDoubleScaleSize =
+ 1 + OperandScaler<operand_0, OperandScale::kDouble>::kSize +
+ OperandScaler<operand_1, OperandScale::kDouble>::kSize +
+ OperandScaler<operand_2, OperandScale::kDouble>::kSize;
+ static constexpr int kQuadrupleScaleSize =
+ 1 + OperandScaler<operand_0, OperandScale::kQuadruple>::kSize +
+ OperandScaler<operand_1, OperandScale::kQuadruple>::kSize +
+ OperandScaler<operand_2, OperandScale::kQuadruple>::kSize;
static const AccumulatorUse kAccumulatorUse = accumulator_use;
static const int kOperandCount = 3;
- static const int kRegisterOperandCount =
- RegisterOperandTraits<operand_0>::kIsRegisterOperand +
- RegisterOperandTraits<operand_1>::kIsRegisterOperand +
- RegisterOperandTraits<operand_2>::kIsRegisterOperand;
};
template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1, OperandType operand_2>
+constexpr OperandType BytecodeTraits<accumulator_use, operand_0, operand_1,
+ operand_2>::kOperandTypes[];
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1, OperandType operand_2>
+constexpr OperandTypeInfo BytecodeTraits<accumulator_use, operand_0, operand_1,
+ operand_2>::kOperandTypeInfos[];
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1, OperandType operand_2>
+constexpr OperandSize BytecodeTraits<accumulator_use, operand_0, operand_1,
+ operand_2>::kSingleScaleOperandSizes[];
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1, OperandType operand_2>
+constexpr OperandSize BytecodeTraits<accumulator_use, operand_0, operand_1,
+ operand_2>::kDoubleScaleOperandSizes[];
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1, OperandType operand_2>
+constexpr OperandSize BytecodeTraits<accumulator_use, operand_0, operand_1,
+ operand_2>::kQuadrupleScaleOperandSizes[];
+
+template <AccumulatorUse accumulator_use, OperandType operand_0,
OperandType operand_1>
struct BytecodeTraits<accumulator_use, operand_0, operand_1> {
- 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>
- static inline bool HasAnyOperandsOfType() {
- return operand_0 == ot || operand_1 == ot;
- }
-
- static inline bool IsScalable() {
- return (OperandTraits<operand_0>::TypeInfoTraits::kIsScalable |
- OperandTraits<operand_1>::TypeInfoTraits::kIsScalable);
- }
-
- static const AccumulatorUse kAccumulatorUse = accumulator_use;
- static const int kOperandCount = 2;
- static const int kRegisterOperandCount =
- RegisterOperandTraits<operand_0>::kIsRegisterOperand +
- RegisterOperandTraits<operand_1>::kIsRegisterOperand;
+ static constexpr OperandType kOperandTypes[] = {operand_0, operand_1};
+ static constexpr OperandTypeInfo kOperandTypeInfos[] = {
+ OperandTraits<operand_0>::kOperandTypeInfo,
+ OperandTraits<operand_1>::kOperandTypeInfo};
+ static constexpr OperandSize kSingleScaleOperandSizes[] = {
+ OperandScaler<operand_0, OperandScale::kSingle>::kOperandSize,
+ OperandScaler<operand_1, OperandScale::kSingle>::kOperandSize};
+ static constexpr OperandSize kDoubleScaleOperandSizes[] = {
+ OperandScaler<operand_0, OperandScale::kDouble>::kOperandSize,
+ OperandScaler<operand_1, OperandScale::kDouble>::kOperandSize};
+ static constexpr OperandSize kQuadrupleScaleOperandSizes[] = {
+ OperandScaler<operand_0, OperandScale::kQuadruple>::kOperandSize,
+ OperandScaler<operand_1, OperandScale::kQuadruple>::kOperandSize};
+ static constexpr int kSingleScaleSize =
+ 1 + OperandScaler<operand_0, OperandScale::kSingle>::kSize +
+ OperandScaler<operand_1, OperandScale::kSingle>::kSize;
+ static constexpr int kDoubleScaleSize =
+ 1 + OperandScaler<operand_0, OperandScale::kDouble>::kSize +
+ OperandScaler<operand_1, OperandScale::kDouble>::kSize;
+ static constexpr int kQuadrupleScaleSize =
+ 1 + OperandScaler<operand_0, OperandScale::kQuadruple>::kSize +
+ OperandScaler<operand_1, OperandScale::kQuadruple>::kSize;
+ static constexpr AccumulatorUse kAccumulatorUse = accumulator_use;
+ static constexpr int kOperandCount = 2;
};
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1>
+constexpr OperandType
+ BytecodeTraits<accumulator_use, operand_0, operand_1>::kOperandTypes[];
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1>
+constexpr OperandTypeInfo
+ BytecodeTraits<accumulator_use, operand_0, operand_1>::kOperandTypeInfos[];
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1>
+constexpr OperandSize BytecodeTraits<accumulator_use, operand_0,
+ operand_1>::kSingleScaleOperandSizes[];
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1>
+constexpr OperandSize BytecodeTraits<accumulator_use, operand_0,
+ operand_1>::kDoubleScaleOperandSizes[];
+template <AccumulatorUse accumulator_use, OperandType operand_0,
+ OperandType operand_1>
+constexpr OperandSize BytecodeTraits<accumulator_use, operand_0,
+ operand_1>::kQuadrupleScaleOperandSizes[];
+
template <AccumulatorUse accumulator_use, OperandType operand_0>
struct BytecodeTraits<accumulator_use, 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>
- static inline bool HasAnyOperandsOfType() {
- return operand_0 == ot;
- }
-
- static inline bool IsScalable() {
- 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 constexpr OperandType kOperandTypes[] = {operand_0};
+ static constexpr OperandTypeInfo kOperandTypeInfos[] = {
+ OperandTraits<operand_0>::kOperandTypeInfo};
+ static constexpr OperandSize kSingleScaleOperandSizes[] = {
+ OperandScaler<operand_0, OperandScale::kSingle>::kOperandSize};
+ static constexpr OperandSize kDoubleScaleOperandSizes[] = {
+ OperandScaler<operand_0, OperandScale::kDouble>::kOperandSize};
+ static constexpr OperandSize kQuadrupleScaleOperandSizes[] = {
+ OperandScaler<operand_0, OperandScale::kQuadruple>::kOperandSize};
+ static constexpr int kSingleScaleSize =
+ 1 + OperandScaler<operand_0, OperandScale::kSingle>::kSize;
+ static constexpr int kDoubleScaleSize =
+ 1 + OperandScaler<operand_0, OperandScale::kDouble>::kSize;
+ static constexpr int kQuadrupleScaleSize =
+ 1 + OperandScaler<operand_0, OperandScale::kQuadruple>::kSize;
+ static constexpr AccumulatorUse kAccumulatorUse = accumulator_use;
+ static constexpr int kOperandCount = 1;
};
+template <AccumulatorUse accumulator_use, OperandType operand_0>
+constexpr OperandType
+ BytecodeTraits<accumulator_use, operand_0>::kOperandTypes[];
+template <AccumulatorUse accumulator_use, OperandType operand_0>
+constexpr OperandTypeInfo
+ BytecodeTraits<accumulator_use, operand_0>::kOperandTypeInfos[];
+template <AccumulatorUse accumulator_use, OperandType operand_0>
+constexpr OperandSize
+ BytecodeTraits<accumulator_use, operand_0>::kSingleScaleOperandSizes[];
+template <AccumulatorUse accumulator_use, OperandType operand_0>
+constexpr OperandSize
+ BytecodeTraits<accumulator_use, operand_0>::kDoubleScaleOperandSizes[];
+template <AccumulatorUse accumulator_use, OperandType operand_0>
+constexpr OperandSize
+ BytecodeTraits<accumulator_use, operand_0>::kQuadrupleScaleOperandSizes[];
+
template <AccumulatorUse accumulator_use>
struct BytecodeTraits<accumulator_use> {
- 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>
- static inline bool HasAnyOperandsOfType() {
- return false;
- }
-
- static inline bool IsScalable() { return false; }
-
- static const AccumulatorUse kAccumulatorUse = accumulator_use;
- static const int kOperandCount = 0;
- static const int kRegisterOperandCount = 0;
+ static constexpr OperandType kOperandTypes[] = {OperandType::kNone};
+ static constexpr OperandTypeInfo kOperandTypeInfos[] = {
+ OperandTypeInfo::kNone};
+ static constexpr OperandSize kSingleScaleOperandSizes[] = {
+ OperandSize::kNone};
+ static constexpr OperandSize kDoubleScaleOperandSizes[] = {
+ OperandSize::kNone};
+ static constexpr OperandSize kQuadrupleScaleOperandSizes[] = {
+ OperandSize::kNone};
+ static constexpr int kSingleScaleSize = 1;
+ static constexpr int kDoubleScaleSize = 1;
+ static constexpr int kQuadrupleScaleSize = 1;
+ static constexpr AccumulatorUse kAccumulatorUse = accumulator_use;
+ static constexpr int kOperandCount = 0;
};
-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: { \
- 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
- }
- UNREACHABLE();
- return OperandSize::kNone;
-}
+template <AccumulatorUse accumulator_use>
+constexpr OperandType BytecodeTraits<accumulator_use>::kOperandTypes[];
+template <AccumulatorUse accumulator_use>
+constexpr OperandTypeInfo BytecodeTraits<accumulator_use>::kOperandTypeInfos[];
+template <AccumulatorUse accumulator_use>
+constexpr OperandSize
+ BytecodeTraits<accumulator_use>::kSingleScaleOperandSizes[];
+template <AccumulatorUse accumulator_use>
+constexpr OperandSize
+ BytecodeTraits<accumulator_use>::kDoubleScaleOperandSizes[];
+template <AccumulatorUse accumulator_use>
+constexpr OperandSize
+ BytecodeTraits<accumulator_use>::kQuadrupleScaleOperandSizes[];
} // namespace interpreter
} // namespace internal

Powered by Google App Engine
This is Rietveld 408576698