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

Unified Diff: test/unittests/interpreter/register-translator-unittest.cc

Issue 1613163002: [interpreter] Wide register support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added tests, fixed off-by-one error in register indicies. 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/register-translator-unittest.cc
diff --git a/test/unittests/interpreter/register-translator-unittest.cc b/test/unittests/interpreter/register-translator-unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c7ee54c96a9658002620c739bcc437a8dd808fe1
--- /dev/null
+++ b/test/unittests/interpreter/register-translator-unittest.cc
@@ -0,0 +1,250 @@
+// Copyright 2014 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.
+
+#include <stack>
+
+#include "src/v8.h"
+
+#include "src/interpreter/register-translator.h"
+#include "src/isolate.h"
+#include "test/unittests/test-utils.h"
+
+namespace v8 {
+namespace internal {
+namespace interpreter {
+
+class RegisterTranslatorTest : public TestWithIsolateAndZone,
+ private RegisterMover {
+ public:
+ RegisterTranslatorTest() : translator_(this), move_count_(0) {}
+ ~RegisterTranslatorTest() override {}
+
+ bool PopMoveAndMatch(Register from, Register to) {
+ bool match = false;
+ if (from.is_valid()) {
+ CHECK(to.is_valid());
+ match =
+ (moves_.top().first.is_valid() && moves_.top().second.is_valid() &&
+ moves_.top().first == from && moves_.top().second == to);
+ } else {
+ CHECK(!to.is_valid());
+ match =
+ (!moves_.top().first.is_valid() && !moves_.top().second.is_valid());
+ }
+ moves_.pop();
+ return match;
+ }
+
+ int move_count() const { return move_count_; }
+ RegisterTranslator* translator() { return &translator_; }
+
+ private:
+ bool MoveRegisterUntranslated(Register from, Register to) override {
+ moves_.push(std::make_pair(from, to));
+ move_count_++;
+ return from.is_valid() && to.is_valid();
+ }
+
+ RegisterTranslator translator_;
+ std::stack<std::pair<Register, Register>> moves_;
+ int move_count_;
+};
+
+
+TEST_F(RegisterTranslatorTest, TestFrameSizeAdjustmentsForTranslationWindow) {
+ int window_start_index =
+ RegisterTranslator::DistanceToTranslationWindow(Register(0));
+ int window_width = kMaxInt8 - window_start_index + 1;
+
+ EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(0, 0));
+ EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(10, 10));
+ EXPECT_EQ(window_width, RegisterTranslator::RegisterCountAdjustment(173, 0));
+ EXPECT_EQ(window_width,
+ RegisterTranslator::RegisterCountAdjustment(173, 137));
+ EXPECT_EQ(window_width,
+ RegisterTranslator::RegisterCountAdjustment(173, 137));
+ EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(0, 120));
+ EXPECT_EQ(kMaxInt8 + 1, RegisterTranslator::RegisterCountAdjustment(0, 128));
+ EXPECT_EQ(kMaxInt8 + 1, RegisterTranslator::RegisterCountAdjustment(0, 129));
+ EXPECT_EQ(kMaxInt8 + 1 - 32,
+ RegisterTranslator::RegisterCountAdjustment(32, 129));
+}
+
+
+TEST_F(RegisterTranslatorTest, TestInTranslationWindow) {
+ int window_start_index =
+ RegisterTranslator::DistanceToTranslationWindow(Register(0));
+ EXPECT_GE(window_start_index, 0);
+ EXPECT_FALSE(RegisterTranslator::InTranslationWindow(
+ Register(window_start_index - 1)));
+ EXPECT_TRUE(RegisterTranslator::InTranslationWindow(Register(kMaxInt8)));
+ EXPECT_FALSE(RegisterTranslator::InTranslationWindow(Register(kMaxInt8 + 1)));
+ for (int index = window_start_index; index < kMaxInt8; index += 1) {
+ EXPECT_TRUE(RegisterTranslator::InTranslationWindow(Register(index)));
+ }
+}
+
+
+TEST_F(RegisterTranslatorTest, FitsInReg8Operand) {
+ int window_start_index =
+ RegisterTranslator::DistanceToTranslationWindow(Register(0));
+ EXPECT_GT(window_start_index, 0);
+ EXPECT_TRUE(RegisterTranslator::FitsInReg8Operand(
+ Register::FromParameterIndex(0, 3)));
+ EXPECT_TRUE(RegisterTranslator::FitsInReg8Operand(
+ Register::FromParameterIndex(2, 3)));
+ EXPECT_TRUE(RegisterTranslator::FitsInReg8Operand(Register(0)));
+ EXPECT_TRUE(
+ RegisterTranslator::FitsInReg8Operand(Register(window_start_index - 1)));
+ EXPECT_FALSE(RegisterTranslator::FitsInReg8Operand(Register(kMaxInt8)));
+ EXPECT_FALSE(RegisterTranslator::FitsInReg8Operand(Register(kMaxInt8 + 1)));
+ for (int index = window_start_index; index < kMaxInt8; index += 1) {
+ EXPECT_FALSE(RegisterTranslator::FitsInReg8Operand(Register(index)));
+ }
+}
+
+
+TEST_F(RegisterTranslatorTest, FitsInReg16Operand) {
+ int window_start_index =
+ RegisterTranslator::DistanceToTranslationWindow(Register(0));
+ int window_width = kMaxInt8 - window_start_index + 1;
+ EXPECT_GT(window_start_index, 0);
+ EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(
+ Register::FromParameterIndex(0, 3)));
+ EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(
+ Register::FromParameterIndex(2, 3)));
+ EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(
+ Register::FromParameterIndex(0, 999)));
+ EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(
+ Register::FromParameterIndex(0, Register::MaxParameterIndex() + 1)));
+ EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(Register(0)));
+ EXPECT_TRUE(
+ RegisterTranslator::FitsInReg16Operand(Register(window_start_index - 1)));
+ EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(Register(kMaxInt8)));
+ EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(Register(kMaxInt8 + 1)));
+ for (int index = 0; index <= kMaxInt16 - window_width; index += 1) {
+ EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(Register(index)));
+ }
+ for (int index = Register::MaxRegisterIndex() - window_width + 1;
+ index < Register::MaxRegisterIndex() + 2; index += 1) {
+ EXPECT_FALSE(RegisterTranslator::FitsInReg16Operand(Register(index)));
+ }
+}
+
+
+TEST_F(RegisterTranslatorTest, NoTranslationRequired) {
+ int window_start_index =
+ RegisterTranslator::DistanceToTranslationWindow(Register(0));
+
+ Register window_reg(window_start_index);
+ Register local_reg(57);
+ EXPECT_EQ(translator()->Translate(Bytecode::kLdar, local_reg), local_reg);
+ translator()->CompleteTranslations();
+ EXPECT_EQ(0, move_count());
+
+ Register param_reg = Register::FromParameterIndex(129, 130);
+ EXPECT_EQ(translator()->Translate(Bytecode::kLdar, param_reg), param_reg);
+ translator()->CompleteTranslations();
+ EXPECT_EQ(0, move_count());
+}
+
+
+TEST_F(RegisterTranslatorTest, TranslationRequired) {
+ int window_start_index =
+ RegisterTranslator::DistanceToTranslationWindow(Register(0));
+ int window_width = kMaxInt8 - window_start_index + 1;
+
+ Register window_reg(window_start_index);
+ Register local_reg(137);
+ Register local_reg_translated(local_reg.index() + window_width);
+ EXPECT_EQ(translator()->Translate(Bytecode::kLdar, local_reg), window_reg);
+ EXPECT_EQ(1, move_count());
+ EXPECT_TRUE(PopMoveAndMatch(local_reg_translated, window_reg));
+ translator()->CompleteTranslations();
+ EXPECT_EQ(2, move_count());
+ EXPECT_TRUE(PopMoveAndMatch(window_reg, local_reg_translated));
+
+ Register param_reg = Register::FromParameterIndex(0, 130);
+ EXPECT_EQ(translator()->Translate(Bytecode::kLdar, param_reg), window_reg);
+ EXPECT_EQ(3, move_count());
+ EXPECT_TRUE(PopMoveAndMatch(param_reg, window_reg));
+ translator()->CompleteTranslations();
+ EXPECT_EQ(4, move_count());
+ EXPECT_TRUE(PopMoveAndMatch(window_reg, param_reg));
+}
+
+
+TEST_F(RegisterTranslatorTest, RangeTranslation) {
+ int window_start_index =
+ RegisterTranslator::DistanceToTranslationWindow(Register(0));
+ int window_width = kMaxInt8 - window_start_index + 1;
+
+ Register window0(window_start_index);
+ Register window1(window_start_index + 1);
+ Register window2(window_start_index + 2);
+ Register bad = Register::IllegalRegister();
+
+ // Bytecode::kNew with valid range operand.
+ Register constructor0(0);
+ Register args0(1);
+ EXPECT_EQ(translator()->Translate(Bytecode::kNew, constructor0),
+ constructor0);
+ EXPECT_EQ(translator()->Translate(Bytecode::kNew, args0), args0);
+ translator()->CompleteTranslations();
+ EXPECT_EQ(0, move_count());
+
+ // Bytecode::kNewWide with valid range operand.
+ Register constructor1(128);
+ Register constructor1_translated(constructor1.index() + window_width);
+ Register args1(129);
+ Register args1_translated(args1.index() + window_width);
+ EXPECT_EQ(translator()->Translate(Bytecode::kNewWide, constructor1),
+ constructor1_translated);
+ EXPECT_EQ(translator()->Translate(Bytecode::kNewWide, args1),
+ args1_translated);
+ EXPECT_EQ(0, move_count());
+ translator()->CompleteTranslations();
+ EXPECT_EQ(0, move_count());
+
+ // Bytecode::kNew with invalid range operand (kMaybeReg8).
+ EXPECT_EQ(window0, translator()->Translate(Bytecode::kNew, constructor1));
+ EXPECT_TRUE(PopMoveAndMatch(constructor1_translated, window0));
+ EXPECT_EQ(window1, translator()->Translate(Bytecode::kNew, args1));
+ EXPECT_TRUE(PopMoveAndMatch(bad, bad));
+ translator()->CompleteTranslations();
+ EXPECT_TRUE(PopMoveAndMatch(window0, constructor1_translated));
+ EXPECT_TRUE(PopMoveAndMatch(window1, args1_translated));
+
+ // Bytecode::kForInPrepare with invalid range operand (kRegTriple8)
+ Register for_in_state(160);
+ Register for_in_state_translated(for_in_state.index() + window_width);
+ EXPECT_EQ(window0,
+ translator()->Translate(Bytecode::kForInPrepare, for_in_state));
+ EXPECT_TRUE(PopMoveAndMatch(bad, bad));
+ translator()->CompleteTranslations();
+ EXPECT_TRUE(PopMoveAndMatch(window0, for_in_state_translated));
+
+ // Bytecode::kForInNext with invalid range operand (kRegPair8)
+ Register receiver(192);
+ Register receiver_translated(receiver.index() + window_width);
+ Register index(193);
+ Register index_translated(index.index() + window_width);
+ Register cache_info_pair(194);
+ Register cache_info_pair_translated(cache_info_pair.index() + window_width);
+ EXPECT_EQ(window0, translator()->Translate(Bytecode::kForInNext, receiver));
+ EXPECT_TRUE(PopMoveAndMatch(receiver_translated, window0));
+ EXPECT_EQ(window1, translator()->Translate(Bytecode::kForInNext, index));
+ EXPECT_TRUE(PopMoveAndMatch(index_translated, window1));
+ EXPECT_EQ(window2,
+ translator()->Translate(Bytecode::kForInNext, cache_info_pair));
+ EXPECT_TRUE(PopMoveAndMatch(bad, bad));
+ translator()->CompleteTranslations();
+ EXPECT_TRUE(PopMoveAndMatch(window0, receiver_translated));
+ EXPECT_TRUE(PopMoveAndMatch(window1, index_translated));
+ EXPECT_TRUE(PopMoveAndMatch(window2, cache_info_pair_translated));
+}
+
+} // namespace interpreter
+} // namespace internal
+} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698