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

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

Issue 1633153002: [interpreter] Reduce move operations for wide register support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove RegisterOperandIsMovable from RegisterMover interface 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 unified diff | Download patch
« no previous file with comments | « test/unittests/interpreter/bytecodes-unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stack> 5 #include <stack>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/interpreter/register-translator.h" 9 #include "src/interpreter/register-translator.h"
10 #include "src/isolate.h" 10 #include "src/isolate.h"
11 #include "test/unittests/test-utils.h" 11 #include "test/unittests/test-utils.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 namespace interpreter { 15 namespace interpreter {
16 16
17 class RegisterTranslatorTest : public TestWithIsolateAndZone, 17 class RegisterTranslatorTest : public TestWithIsolateAndZone,
18 private RegisterMover { 18 private RegisterMover {
19 public: 19 public:
20 RegisterTranslatorTest() : translator_(this), move_count_(0) { 20 RegisterTranslatorTest() : translator_(this), move_count_(0) {
21 window_start_ = 21 window_start_ =
22 RegisterTranslator::DistanceToTranslationWindow(Register(0)); 22 RegisterTranslator::DistanceToTranslationWindow(Register(0));
23 window_width_ = 23 window_width_ =
24 Register::MaxRegisterIndexForByteOperand() - window_start_ + 1; 24 Register::MaxRegisterIndexForByteOperand() - window_start_ + 1;
25 } 25 }
26 26
27 ~RegisterTranslatorTest() override {} 27 ~RegisterTranslatorTest() override {}
28 28
29 bool PopMoveAndMatch(Register from, Register to) { 29 bool PopMoveAndMatch(Register from, Register to) {
30 CHECK(from.is_valid() && to.is_valid()); 30 if (!moves_.empty()) {
31 const std::pair<Register, Register> top = moves_.top(); 31 CHECK(from.is_valid() && to.is_valid());
32 moves_.pop(); 32 const std::pair<Register, Register> top = moves_.top();
33 return top.first == from && top.second == to; 33 moves_.pop();
34 return top.first == from && top.second == to;
35 } else {
36 return false;
37 }
34 } 38 }
35 39
36 int move_count() const { return move_count_; } 40 int move_count() const { return move_count_; }
37 RegisterTranslator* translator() { return &translator_; } 41 RegisterTranslator* translator() { return &translator_; }
38 42
39 int window_start() const { return window_start_; } 43 int window_start() const { return window_start_; }
40 int window_width() const { return window_width_; } 44 int window_width() const { return window_width_; }
41 int window_limit() const { return window_start_ + window_width_; } 45 int window_limit() const { return window_start_ + window_width_; }
42 46
43 protected: 47 protected:
44 static const char* const kBadOperandRegex; 48 static const char* const kBadOperandRegex;
45 49
46 private: 50 private:
47 void MoveRegisterUntranslated(Register from, Register to) override { 51 void MoveRegisterUntranslated(Register from, Register to) override {
48 moves_.push(std::make_pair(from, to)); 52 moves_.push(std::make_pair(from, to));
49 move_count_++; 53 move_count_++;
50 } 54 }
51 55
52 bool RegisterOperandIsMovable(Bytecode bytecode, int operand_index) override {
53 OperandType operand_type =
54 Bytecodes::GetOperandType(bytecode, operand_index);
55 if (operand_type == OperandType::kReg8 ||
56 operand_type == OperandType::kReg16) {
57 if (operand_index == Bytecodes::NumberOfOperands(bytecode) - 1) {
58 return true;
59 }
60 OperandType next_operand_type =
61 Bytecodes::GetOperandType(bytecode, operand_index + 1);
62 return (next_operand_type != OperandType::kRegCount8 &&
63 next_operand_type != OperandType::kRegCount16);
64 } else {
65 return false;
66 }
67 }
68
69 RegisterTranslator translator_; 56 RegisterTranslator translator_;
70 std::stack<std::pair<Register, Register>> moves_; 57 std::stack<std::pair<Register, Register>> moves_;
71 int move_count_; 58 int move_count_;
72 int window_start_; 59 int window_start_;
73 int window_width_; 60 int window_width_;
74 }; 61 };
75 62
76 const char* const RegisterTranslatorTest::kBadOperandRegex = 63 const char* const RegisterTranslatorTest::kBadOperandRegex =
77 ".*OperandType::kReg8 && mover\\(\\)->RegisterOperandIsMovable.*"; 64 ".*OperandType::kReg8 \\|\\| .*OperandType::kRegOut8\\) && "
65 "RegisterIsMovableToWindow.*";
78 66
79 TEST_F(RegisterTranslatorTest, TestFrameSizeAdjustmentsForTranslationWindow) { 67 TEST_F(RegisterTranslatorTest, TestFrameSizeAdjustmentsForTranslationWindow) {
80 EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(0, 0)); 68 EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(0, 0));
81 EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(10, 10)); 69 EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(10, 10));
82 EXPECT_EQ(window_width(), 70 EXPECT_EQ(window_width(),
83 RegisterTranslator::RegisterCountAdjustment(173, 0)); 71 RegisterTranslator::RegisterCountAdjustment(173, 0));
84 EXPECT_EQ(window_width(), 72 EXPECT_EQ(window_width(),
85 RegisterTranslator::RegisterCountAdjustment(173, 137)); 73 RegisterTranslator::RegisterCountAdjustment(173, 137));
86 EXPECT_EQ(window_width(), 74 EXPECT_EQ(window_width(),
87 RegisterTranslator::RegisterCountAdjustment(173, 137)); 75 RegisterTranslator::RegisterCountAdjustment(173, 137));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 TEST_F(RegisterTranslatorTest, NoTranslationRequired) { 138 TEST_F(RegisterTranslatorTest, NoTranslationRequired) {
151 Register window_reg(window_start()); 139 Register window_reg(window_start());
152 Register local_reg(57); 140 Register local_reg(57);
153 uint32_t operands[] = {local_reg.ToRawOperand()}; 141 uint32_t operands[] = {local_reg.ToRawOperand()};
154 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1); 142 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1);
155 translator()->TranslateOutputRegisters(); 143 translator()->TranslateOutputRegisters();
156 EXPECT_EQ(0, move_count()); 144 EXPECT_EQ(0, move_count());
157 145
158 Register param_reg = Register::FromParameterIndex(129, 130); 146 Register param_reg = Register::FromParameterIndex(129, 130);
159 operands[0] = param_reg.ToRawOperand(); 147 operands[0] = param_reg.ToRawOperand();
160 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1); 148 translator()->TranslateInputRegisters(Bytecode::kAdd, operands, 1);
161 translator()->TranslateOutputRegisters(); 149 translator()->TranslateOutputRegisters();
162 EXPECT_EQ(0, move_count()); 150 EXPECT_EQ(0, move_count());
163 } 151 }
164 152
165 TEST_F(RegisterTranslatorTest, TranslationRequired) { 153 TEST_F(RegisterTranslatorTest, TranslationRequired) {
166 Register window_reg(window_start()); 154 Register window_reg(window_start());
167 Register local_reg(137); 155 Register local_reg(137);
168 Register local_reg_translated(local_reg.index() + window_width()); 156 Register local_reg_translated(local_reg.index() + window_width());
169 157
170 uint32_t operands[] = {local_reg.ToRawOperand()}; 158 uint32_t operands[] = {local_reg.ToRawOperand()};
171 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1); 159 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1);
172 EXPECT_EQ(1, move_count()); 160 EXPECT_EQ(1, move_count());
173 EXPECT_TRUE(PopMoveAndMatch(local_reg_translated, window_reg)); 161 EXPECT_TRUE(PopMoveAndMatch(local_reg_translated, window_reg));
174 translator()->TranslateOutputRegisters(); 162 translator()->TranslateOutputRegisters();
163 EXPECT_EQ(1, move_count());
164 EXPECT_FALSE(PopMoveAndMatch(window_reg, local_reg_translated));
165
166 operands[0] = local_reg.ToRawOperand();
167 translator()->TranslateInputRegisters(Bytecode::kStar, operands, 1);
168 EXPECT_EQ(1, move_count());
169 EXPECT_FALSE(PopMoveAndMatch(local_reg_translated, window_reg));
170 translator()->TranslateOutputRegisters();
175 EXPECT_EQ(2, move_count()); 171 EXPECT_EQ(2, move_count());
176 EXPECT_TRUE(PopMoveAndMatch(window_reg, local_reg_translated)); 172 EXPECT_TRUE(PopMoveAndMatch(window_reg, local_reg_translated));
177 173
178 Register param_reg = Register::FromParameterIndex(0, 130); 174 Register param_reg = Register::FromParameterIndex(0, 130);
179 operands[0] = {param_reg.ToRawOperand()}; 175 operands[0] = {param_reg.ToRawOperand()};
180 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1); 176 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1);
181 EXPECT_EQ(3, move_count()); 177 EXPECT_EQ(3, move_count());
182 EXPECT_TRUE(PopMoveAndMatch(param_reg, window_reg)); 178 EXPECT_TRUE(PopMoveAndMatch(param_reg, window_reg));
183 translator()->TranslateOutputRegisters(); 179 translator()->TranslateOutputRegisters();
180 EXPECT_EQ(3, move_count());
181 EXPECT_FALSE(PopMoveAndMatch(window_reg, param_reg));
182
183 operands[0] = {param_reg.ToRawOperand()};
184 translator()->TranslateInputRegisters(Bytecode::kStar, operands, 1);
185 EXPECT_EQ(3, move_count());
186 EXPECT_FALSE(PopMoveAndMatch(local_reg_translated, window_reg));
187 translator()->TranslateOutputRegisters();
184 EXPECT_EQ(4, move_count()); 188 EXPECT_EQ(4, move_count());
185 EXPECT_TRUE(PopMoveAndMatch(window_reg, param_reg)); 189 EXPECT_TRUE(PopMoveAndMatch(window_reg, param_reg));
186 } 190 }
187 191
188 TEST_F(RegisterTranslatorTest, RangeTranslation) { 192 TEST_F(RegisterTranslatorTest, RangeTranslation) {
189 Register window0(window_start()); 193 Register window0(window_start());
190 Register window1(window_start() + 1); 194 Register window1(window_start() + 1);
191 Register window2(window_start() + 2); 195 Register window2(window_start() + 2);
192 uint32_t operands[3]; 196 uint32_t operands[3];
193 197
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 uint32_t operands[] = {receiver.ToRawOperand(), index.ToRawOperand(), 249 uint32_t operands[] = {receiver.ToRawOperand(), index.ToRawOperand(),
246 cache_info_pair.ToRawOperand()}; 250 cache_info_pair.ToRawOperand()};
247 ASSERT_DEATH_IF_SUPPORTED( 251 ASSERT_DEATH_IF_SUPPORTED(
248 translator()->TranslateInputRegisters(Bytecode::kForInNext, operands, 3), 252 translator()->TranslateInputRegisters(Bytecode::kForInNext, operands, 3),
249 kBadOperandRegex); 253 kBadOperandRegex);
250 } 254 }
251 255
252 } // namespace interpreter 256 } // namespace interpreter
253 } // namespace internal 257 } // namespace internal
254 } // namespace v8 258 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/interpreter/bytecodes-unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698