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

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

Issue 1613163002: [interpreter] Wide register support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 11 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 812ee46c9c1b55ff37143b81979cff2ced3de573..bdcccfe6e183f7968306629ca1032f71afbf9dc8 100644
--- a/test/unittests/interpreter/bytecodes-unittest.cc
+++ b/test/unittests/interpreter/bytecodes-unittest.cc
@@ -9,16 +9,37 @@
#include "src/interpreter/bytecodes.h"
#include "test/unittests/test-utils.h"
-
namespace v8 {
namespace internal {
namespace interpreter {
TEST(OperandConversion, Registers) {
- for (int i = 0; i < 128; i++) {
- uint8_t operand_value = Register(i).ToOperand();
- Register r = Register::FromOperand(operand_value);
- CHECK_EQ(i, r.index());
+ int register_count = Register::MaxRegisterIndex() + 1;
+ int step = register_count / 7;
+ for (int i = 0; i < register_count; i += step) {
+ if (i <= kMaxInt8) {
+ uint8_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);
+ CHECK_EQ(i, reg1.index());
+
+ uint32_t operand2 = Register(i).ToRawOperand();
+ Register reg2 = Register::FromRawOperand(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) {
+ CHECK(reg.is_parameter());
+ } else {
+ CHECK(!reg.is_parameter());
+ }
}
}
@@ -40,24 +61,63 @@ TEST(OperandConversion, Parameters) {
TEST(OperandConversion, RegistersParametersNoOverlap) {
- std::vector<uint8_t> operand_count(256);
+ int register_count = Register::MaxRegisterIndex() + 1;
+ int parameter_count = Register::MaxParameterIndex() + 1;
+ 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);
+ std::vector<uint8_t> operand_count(range);
- for (int i = 0; i <= kMaxInt8; i++) {
+ for (int i = 0; i < register_count; i += 1) {
Register r = Register(i);
- uint8_t operand = r.ToOperand();
+ uint32_t operand = r.ToWideOperand();
+ CHECK_LT(operand, operand_count.size());
operand_count[operand] += 1;
CHECK_EQ(operand_count[operand], 1);
}
- int parameter_count = Register::MaxParameterIndex() + 1;
- for (int i = 0; i < parameter_count; i++) {
+ for (int i = 0; i < parameter_count; i += 1) {
Register r = Register::FromParameterIndex(i, parameter_count);
- uint8_t operand = r.ToOperand();
+ uint32_t operand = r.ToWideOperand();
+ CHECK_LT(operand, operand_count.size());
operand_count[operand] += 1;
CHECK_EQ(operand_count[operand], 1);
}
}
+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::kDeleteLookupSlot), 0);
+ 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);
+ CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kToName), 0);
+}
+
+TEST(Bytecodes, RegisterOperandBitmaps) {
+ CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kAdd), 1);
+ CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kCallRuntimeForPair),
+ 10);
+ CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kStar), 1);
+ CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kMov), 3);
+ CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kTestIn), 1);
+ CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kForInPrepare), 1);
+ CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kForInDone), 3);
+ CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kForInNext), 7);
+}
+
} // namespace interpreter
} // namespace internal
} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698