Commit 9baee14c authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[interpreter] Micro-optimize bytecode-operands.h

- Use IsInRange
- Convert scale to index using >>1 which works for 1, 2, 4
- Use mask to check Reads/Writes accumulator

Change-Id: Iaeb2236a2d179dc70b62fa599c08984800170336
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1541039
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Auto-Submit: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60595}
parent f2b2dfa9
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define V8_INTERPRETER_BYTECODE_OPERANDS_H_ #define V8_INTERPRETER_BYTECODE_OPERANDS_H_
#include "src/globals.h" #include "src/globals.h"
#include "src/utils.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -115,14 +116,16 @@ enum class AccumulatorUse : uint8_t { ...@@ -115,14 +116,16 @@ enum class AccumulatorUse : uint8_t {
kReadWrite = kRead | kWrite kReadWrite = kRead | kWrite
}; };
inline AccumulatorUse operator&(AccumulatorUse lhs, AccumulatorUse rhs) { constexpr inline AccumulatorUse operator&(AccumulatorUse lhs,
int result = static_cast<int>(lhs) & static_cast<int>(rhs); AccumulatorUse rhs) {
return static_cast<AccumulatorUse>(result); return static_cast<AccumulatorUse>(static_cast<int>(lhs) &
static_cast<int>(rhs));
} }
inline AccumulatorUse operator|(AccumulatorUse lhs, AccumulatorUse rhs) { constexpr inline AccumulatorUse operator|(AccumulatorUse lhs,
int result = static_cast<int>(lhs) | static_cast<int>(rhs); AccumulatorUse rhs) {
return static_cast<AccumulatorUse>(result); return static_cast<AccumulatorUse>(static_cast<int>(lhs) |
static_cast<int>(rhs));
} }
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
...@@ -145,41 +148,47 @@ class BytecodeOperands : public AllStatic { ...@@ -145,41 +148,47 @@ class BytecodeOperands : public AllStatic {
0 OPERAND_SCALE_LIST(OPERAND_SCALE_COUNT); 0 OPERAND_SCALE_LIST(OPERAND_SCALE_COUNT);
#undef OPERAND_SCALE_COUNT #undef OPERAND_SCALE_COUNT
static int OperandScaleAsIndex(OperandScale operand_scale) { static constexpr int OperandScaleAsIndex(OperandScale operand_scale) {
#ifdef V8_CAN_HAVE_DCHECK_IN_CONSTEXPR
#ifdef DEBUG
int result = static_cast<int>(operand_scale) >> 1;
switch (operand_scale) { switch (operand_scale) {
case OperandScale::kSingle: case OperandScale::kSingle:
return 0; DCHECK_EQ(0, result);
break;
case OperandScale::kDouble: case OperandScale::kDouble:
return 1; DCHECK_EQ(1, result);
break;
case OperandScale::kQuadruple: case OperandScale::kQuadruple:
return 2; DCHECK_EQ(2, result);
break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
#endif
#endif
return static_cast<int>(operand_scale) >> 1;
} }
// Returns true if |accumulator_use| reads the accumulator. // Returns true if |accumulator_use| reads the accumulator.
static constexpr bool ReadsAccumulator(AccumulatorUse accumulator_use) { static constexpr bool ReadsAccumulator(AccumulatorUse accumulator_use) {
return accumulator_use == AccumulatorUse::kRead || return (accumulator_use & AccumulatorUse::kRead) == AccumulatorUse::kRead;
accumulator_use == AccumulatorUse::kReadWrite;
} }
// Returns true if |accumulator_use| writes the accumulator. // Returns true if |accumulator_use| writes the accumulator.
static constexpr bool WritesAccumulator(AccumulatorUse accumulator_use) { static constexpr bool WritesAccumulator(AccumulatorUse accumulator_use) {
return accumulator_use == AccumulatorUse::kWrite || return (accumulator_use & AccumulatorUse::kWrite) == AccumulatorUse::kWrite;
accumulator_use == AccumulatorUse::kReadWrite;
} }
// Returns true if |operand_type| is a scalable signed byte. // Returns true if |operand_type| is a scalable signed byte.
static constexpr bool IsScalableSignedByte(OperandType operand_type) { static constexpr bool IsScalableSignedByte(OperandType operand_type) {
return operand_type >= OperandType::kImm && return IsInRange(operand_type, OperandType::kImm,
operand_type <= OperandType::kRegOutTriple; OperandType::kRegOutTriple);
} }
// Returns true if |operand_type| is a scalable unsigned byte. // Returns true if |operand_type| is a scalable unsigned byte.
static constexpr bool IsScalableUnsignedByte(OperandType operand_type) { static constexpr bool IsScalableUnsignedByte(OperandType operand_type) {
return operand_type >= OperandType::kIdx && return IsInRange(operand_type, OperandType::kIdx, OperandType::kRegCount);
operand_type <= OperandType::kRegCount;
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment