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

Unified Diff: test/unittests/interpreter/bytecodes-unittest.cc

Issue 1783483002: [interpreter] Add support for scalable operands. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Re-generate golden files. Created 4 years, 9 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: test/unittests/interpreter/bytecodes-unittest.cc
diff --git a/test/unittests/interpreter/bytecodes-unittest.cc b/test/unittests/interpreter/bytecodes-unittest.cc
index 212e02996b65c98a8674dbd453a60a0ef68fcd26..5472927a40630ac98b34345d3da890903c821298 100644
--- a/test/unittests/interpreter/bytecodes-unittest.cc
+++ b/test/unittests/interpreter/bytecodes-unittest.cc
@@ -14,28 +14,27 @@ namespace internal {
namespace interpreter {
TEST(OperandConversion, Registers) {
- int register_count = Register::MaxRegisterIndex() + 1;
+ int register_count = 128;
int step = register_count / 7;
for (int i = 0; i < register_count; i += step) {
if (i <= kMaxInt8) {
- uint8_t operand0 = Register(i).ToOperand();
+ uint32_t operand0 = Register(i).ToOperand();
Register reg0 = Register::FromOperand(operand0);
CHECK_EQ(i, reg0.index());
}
- uint16_t operand1 = Register(i).ToWideOperand();
- Register reg1 = Register::FromWideOperand(operand1);
+ uint32_t operand1 = Register(i).ToOperand();
+ Register reg1 = Register::FromOperand(operand1);
CHECK_EQ(i, reg1.index());
- uint32_t operand2 = Register(i).ToRawOperand();
- Register reg2 = Register::FromRawOperand(operand2);
+ uint32_t operand2 = Register(i).ToOperand();
+ Register reg2 = Register::FromOperand(operand2);
CHECK_EQ(i, reg2.index());
}
for (int i = 0; i <= kMaxUInt8; i++) {
- uint8_t operand = static_cast<uint8_t>(i);
- Register reg = Register::FromOperand(operand);
- if (i > 0 && i < -kMinInt8) {
+ Register reg = Register::FromOperand(i);
+ if (i > 0) {
CHECK(reg.is_parameter());
} else {
CHECK(!reg.is_parameter());
@@ -51,7 +50,7 @@ TEST(OperandConversion, Parameters) {
int parameter_count = parameter_counts[p];
for (int i = 0; i < parameter_count; i++) {
Register r = Register::FromParameterIndex(i, parameter_count);
- uint8_t operand_value = r.ToOperand();
+ uint32_t operand_value = r.ToOperand();
Register s = Register::FromOperand(operand_value);
CHECK_EQ(i, s.ToParameterIndex(parameter_count));
}
@@ -59,8 +58,8 @@ TEST(OperandConversion, Parameters) {
}
TEST(OperandConversion, RegistersParametersNoOverlap) {
- int register_count = Register::MaxRegisterIndex() + 1;
- int parameter_count = Register::MaxParameterIndex() + 1;
+ int register_count = 128;
+ int parameter_count = 100;
int32_t register_space_size = base::bits::RoundUpToPowerOfTwo32(
static_cast<uint32_t>(register_count + parameter_count));
uint32_t range = static_cast<uint32_t>(register_space_size);
@@ -68,18 +67,33 @@ TEST(OperandConversion, RegistersParametersNoOverlap) {
for (int i = 0; i < register_count; i += 1) {
Register r = Register(i);
- uint32_t operand = r.ToWideOperand();
- CHECK_LT(operand, operand_count.size());
- operand_count[operand] += 1;
- CHECK_EQ(operand_count[operand], 1);
+ int32_t operand = r.ToOperand();
+ uint8_t index = static_cast<uint8_t>(operand);
+ CHECK_LT(index, operand_count.size());
+ operand_count[index] += 1;
+ CHECK_EQ(operand_count[index], 1);
}
for (int i = 0; i < parameter_count; i += 1) {
Register r = Register::FromParameterIndex(i, parameter_count);
- uint32_t operand = r.ToWideOperand();
- CHECK_LT(operand, operand_count.size());
- operand_count[operand] += 1;
- CHECK_EQ(operand_count[operand], 1);
+ uint32_t operand = r.ToOperand();
+ uint8_t index = static_cast<uint8_t>(operand);
+ CHECK_LT(index, operand_count.size());
+ operand_count[index] += 1;
+ CHECK_EQ(operand_count[index], 1);
+ }
+}
+
+TEST(OperandScaling, ScalableAndNonScalable) {
+ for (OperandScale operand_scale = OperandScale::kSingle;
+ operand_scale <= OperandScale::kMaxValid;
+ operand_scale = Bytecodes::NextOperandScale(operand_scale)) {
+ int scale = static_cast<int>(operand_scale);
+ CHECK_EQ(Bytecodes::Size(Bytecode::kCallRuntime, operand_scale),
+ 1 + 2 + 2 * scale);
+ CHECK_EQ(Bytecodes::Size(Bytecode::kCreateObjectLiteral, operand_scale),
+ 1 + 2 * scale + 1);
+ CHECK_EQ(Bytecodes::Size(Bytecode::kTestIn, operand_scale), 1 + scale);
}
}
@@ -87,16 +101,11 @@ TEST(Bytecodes, HasAnyRegisterOperands) {
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kAdd), 1);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCall), 2);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntime), 1);
- CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntimeWide), 1);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntimeForPair),
2);
- CHECK_EQ(
- Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntimeForPairWide),
- 2);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kDeletePropertyStrict),
1);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kForInPrepare), 1);
- CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kForInPrepareWide), 1);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kInc), 0);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kJumpIfTrue), 0);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kNew), 2);
@@ -116,11 +125,11 @@ TEST(Bytecodes, RegisterOperandBitmaps) {
}
TEST(Bytecodes, RegisterOperands) {
- CHECK(Bytecodes::IsRegisterOperandType(OperandType::kReg8));
- CHECK(Bytecodes::IsRegisterInputOperandType(OperandType::kReg8));
- CHECK(!Bytecodes::IsRegisterOutputOperandType(OperandType::kReg8));
- CHECK(!Bytecodes::IsRegisterInputOperandType(OperandType::kRegOut8));
- CHECK(Bytecodes::IsRegisterOutputOperandType(OperandType::kRegOut8));
+ CHECK(Bytecodes::IsRegisterOperandType(OperandType::kReg));
+ CHECK(Bytecodes::IsRegisterInputOperandType(OperandType::kReg));
+ CHECK(!Bytecodes::IsRegisterOutputOperandType(OperandType::kReg));
+ CHECK(!Bytecodes::IsRegisterInputOperandType(OperandType::kRegOut));
+ CHECK(Bytecodes::IsRegisterOutputOperandType(OperandType::kRegOut));
#define IS_REGISTER_OPERAND_TYPE(Name, _) \
CHECK(Bytecodes::IsRegisterOperandType(OperandType::k##Name));
@@ -155,16 +164,52 @@ TEST(Bytecodes, RegisterOperands) {
#undef IS_NOT_REGISTER_INPUT_OPERAND_TYPE
}
-TEST(Bytecodes, DebugBreak) {
- for (uint32_t i = 0; i < Bytecodes::ToByte(Bytecode::kLast); i++) {
- Bytecode bytecode = Bytecodes::FromByte(i);
- Bytecode debugbreak = Bytecodes::GetDebugBreak(bytecode);
- if (!Bytecodes::IsDebugBreak(debugbreak)) {
- PrintF("Bytecode %s has no matching debug break with length %d\n",
- Bytecodes::ToString(bytecode), Bytecodes::Size(bytecode));
- CHECK(false);
- }
+TEST(Bytecodes, DebugBreakExistForEachBytecode) {
+ static const OperandScale kOperandScale = OperandScale::kSingle;
+#define CHECK_DEBUG_BREAK_SIZE(Name, ...) \
+ if (!Bytecodes::IsDebugBreak(Bytecode::k##Name) && \
+ !Bytecodes::IsPrefixScalingBytecode(Bytecode::k##Name)) { \
+ Bytecode debug_bytecode = Bytecodes::GetDebugBreak(Bytecode::k##Name); \
+ CHECK_EQ(Bytecodes::Size(Bytecode::k##Name, kOperandScale), \
+ Bytecodes::Size(debug_bytecode, kOperandScale)); \
}
+ BYTECODE_LIST(CHECK_DEBUG_BREAK_SIZE)
+#undef CHECK_DEBUG_BREAK_SIZE
+}
+
+TEST(Bytecodes, DebugBreakForPrefixBytecodes) {
+ CHECK_EQ(Bytecode::kDebugBreakWide,
+ Bytecodes::GetDebugBreak(Bytecode::kWide));
+ CHECK_EQ(Bytecode::kDebugBreakExtraWide,
+ Bytecodes::GetDebugBreak(Bytecode::kExtraWide));
+}
+
+TEST(Bytecodes, PrefixMappings) {
+ Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide};
+ TRACED_FOREACH(Bytecode, prefix, prefixes) {
+ CHECK_EQ(prefix, Bytecodes::OperandScaleToPrefixBytecode(
+ Bytecodes::PrefixBytecodeToOperandScale(prefix)));
+ }
+}
+
+TEST(OperandScale, PrefixesScale) {
+ CHECK(Bytecodes::NextOperandScale(OperandScale::kSingle) ==
+ OperandScale::kDouble);
+ CHECK(Bytecodes::NextOperandScale(OperandScale::kDouble) ==
+ OperandScale::kQuadruple);
+ CHECK(Bytecodes::NextOperandScale(OperandScale::kQuadruple) ==
+ OperandScale::kInvalid);
+}
+
+TEST(OperandScale, PrefixesRequired) {
+ CHECK(!Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kSingle));
+ CHECK(Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kDouble));
+ CHECK(
+ Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kQuadruple));
+ CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kDouble) ==
+ Bytecode::kWide);
+ CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kQuadruple) ==
+ Bytecode::kExtraWide);
}
} // namespace interpreter

Powered by Google App Engine
This is Rietveld 408576698