OLD | NEW |
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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 private: | 46 private: |
47 void MoveRegisterUntranslated(Register from, Register to) override { | 47 void MoveRegisterUntranslated(Register from, Register to) override { |
48 moves_.push(std::make_pair(from, to)); | 48 moves_.push(std::make_pair(from, to)); |
49 move_count_++; | 49 move_count_++; |
50 } | 50 } |
51 | 51 |
52 bool RegisterOperandIsMovable(Bytecode bytecode, int operand_index) override { | 52 bool RegisterOperandIsMovable(Bytecode bytecode, int operand_index) override { |
53 OperandType operand_type = | 53 OperandType operand_type = |
54 Bytecodes::GetOperandType(bytecode, operand_index); | 54 Bytecodes::GetOperandType(bytecode, operand_index); |
| 55 |
| 56 EXPECT_TRUE(Bytecodes::IsRegisterOperandType(operand_type)); |
55 if (operand_type == OperandType::kReg8 || | 57 if (operand_type == OperandType::kReg8 || |
56 operand_type == OperandType::kReg16) { | 58 operand_type == OperandType::kRegOut8) { |
57 if (operand_index == Bytecodes::NumberOfOperands(bytecode) - 1) { | 59 if (operand_index == Bytecodes::NumberOfOperands(bytecode) - 1) { |
58 return true; | 60 return true; |
59 } | 61 } |
60 OperandType next_operand_type = | 62 OperandType next_operand_type = |
61 Bytecodes::GetOperandType(bytecode, operand_index + 1); | 63 Bytecodes::GetOperandType(bytecode, operand_index + 1); |
62 return (next_operand_type != OperandType::kRegCount8 && | 64 return (next_operand_type != OperandType::kRegCount8 && |
63 next_operand_type != OperandType::kRegCount16); | 65 next_operand_type != OperandType::kRegCount16); |
64 } else { | 66 } else { |
65 return false; | 67 return false; |
66 } | 68 } |
67 } | 69 } |
68 | 70 |
69 RegisterTranslator translator_; | 71 RegisterTranslator translator_; |
70 std::stack<std::pair<Register, Register>> moves_; | 72 std::stack<std::pair<Register, Register>> moves_; |
71 int move_count_; | 73 int move_count_; |
72 int window_start_; | 74 int window_start_; |
73 int window_width_; | 75 int window_width_; |
74 }; | 76 }; |
75 | 77 |
76 const char* const RegisterTranslatorTest::kBadOperandRegex = | 78 const char* const RegisterTranslatorTest::kBadOperandRegex = |
77 ".*OperandType::kReg8 && mover\\(\\)->RegisterOperandIsMovable.*"; | 79 ".*OperandType::kReg8 \\|\\| .*OperandType::kRegOut8\\) && " |
| 80 "mover\\(\\)->RegisterOperandIsMovable.*"; |
78 | 81 |
79 TEST_F(RegisterTranslatorTest, TestFrameSizeAdjustmentsForTranslationWindow) { | 82 TEST_F(RegisterTranslatorTest, TestFrameSizeAdjustmentsForTranslationWindow) { |
80 EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(0, 0)); | 83 EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(0, 0)); |
81 EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(10, 10)); | 84 EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(10, 10)); |
82 EXPECT_EQ(window_width(), | 85 EXPECT_EQ(window_width(), |
83 RegisterTranslator::RegisterCountAdjustment(173, 0)); | 86 RegisterTranslator::RegisterCountAdjustment(173, 0)); |
84 EXPECT_EQ(window_width(), | 87 EXPECT_EQ(window_width(), |
85 RegisterTranslator::RegisterCountAdjustment(173, 137)); | 88 RegisterTranslator::RegisterCountAdjustment(173, 137)); |
86 EXPECT_EQ(window_width(), | 89 EXPECT_EQ(window_width(), |
87 RegisterTranslator::RegisterCountAdjustment(173, 137)); | 90 RegisterTranslator::RegisterCountAdjustment(173, 137)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 TEST_F(RegisterTranslatorTest, NoTranslationRequired) { | 153 TEST_F(RegisterTranslatorTest, NoTranslationRequired) { |
151 Register window_reg(window_start()); | 154 Register window_reg(window_start()); |
152 Register local_reg(57); | 155 Register local_reg(57); |
153 uint32_t operands[] = {local_reg.ToRawOperand()}; | 156 uint32_t operands[] = {local_reg.ToRawOperand()}; |
154 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1); | 157 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1); |
155 translator()->TranslateOutputRegisters(); | 158 translator()->TranslateOutputRegisters(); |
156 EXPECT_EQ(0, move_count()); | 159 EXPECT_EQ(0, move_count()); |
157 | 160 |
158 Register param_reg = Register::FromParameterIndex(129, 130); | 161 Register param_reg = Register::FromParameterIndex(129, 130); |
159 operands[0] = param_reg.ToRawOperand(); | 162 operands[0] = param_reg.ToRawOperand(); |
160 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1); | 163 translator()->TranslateInputRegisters(Bytecode::kAdd, operands, 1); |
161 translator()->TranslateOutputRegisters(); | 164 translator()->TranslateOutputRegisters(); |
162 EXPECT_EQ(0, move_count()); | 165 EXPECT_EQ(0, move_count()); |
163 } | 166 } |
164 | 167 |
165 TEST_F(RegisterTranslatorTest, TranslationRequired) { | 168 TEST_F(RegisterTranslatorTest, TranslationRequired) { |
166 Register window_reg(window_start()); | 169 Register window_reg(window_start()); |
167 Register local_reg(137); | 170 Register local_reg(137); |
168 Register local_reg_translated(local_reg.index() + window_width()); | 171 Register local_reg_translated(local_reg.index() + window_width()); |
169 | 172 |
170 uint32_t operands[] = {local_reg.ToRawOperand()}; | 173 uint32_t operands[] = {local_reg.ToRawOperand()}; |
171 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1); | 174 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1); |
172 EXPECT_EQ(1, move_count()); | 175 EXPECT_EQ(1, move_count()); |
173 EXPECT_TRUE(PopMoveAndMatch(local_reg_translated, window_reg)); | 176 EXPECT_TRUE(PopMoveAndMatch(local_reg_translated, window_reg)); |
174 translator()->TranslateOutputRegisters(); | 177 translator()->TranslateOutputRegisters(); |
| 178 EXPECT_EQ(1, move_count()); |
| 179 EXPECT_FALSE(PopMoveAndMatch(window_reg, local_reg_translated)); |
| 180 |
| 181 operands[0] = local_reg.ToRawOperand(); |
| 182 translator()->TranslateInputRegisters(Bytecode::kStar, operands, 1); |
| 183 EXPECT_EQ(1, move_count()); |
| 184 EXPECT_FALSE(PopMoveAndMatch(local_reg_translated, window_reg)); |
| 185 translator()->TranslateOutputRegisters(); |
175 EXPECT_EQ(2, move_count()); | 186 EXPECT_EQ(2, move_count()); |
176 EXPECT_TRUE(PopMoveAndMatch(window_reg, local_reg_translated)); | 187 EXPECT_TRUE(PopMoveAndMatch(window_reg, local_reg_translated)); |
177 | 188 |
178 Register param_reg = Register::FromParameterIndex(0, 130); | 189 Register param_reg = Register::FromParameterIndex(0, 130); |
179 operands[0] = {param_reg.ToRawOperand()}; | 190 operands[0] = {param_reg.ToRawOperand()}; |
180 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1); | 191 translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1); |
181 EXPECT_EQ(3, move_count()); | 192 EXPECT_EQ(3, move_count()); |
182 EXPECT_TRUE(PopMoveAndMatch(param_reg, window_reg)); | 193 EXPECT_TRUE(PopMoveAndMatch(param_reg, window_reg)); |
183 translator()->TranslateOutputRegisters(); | 194 translator()->TranslateOutputRegisters(); |
| 195 EXPECT_EQ(3, move_count()); |
| 196 EXPECT_FALSE(PopMoveAndMatch(window_reg, param_reg)); |
| 197 |
| 198 operands[0] = {param_reg.ToRawOperand()}; |
| 199 translator()->TranslateInputRegisters(Bytecode::kStar, operands, 1); |
| 200 EXPECT_EQ(3, move_count()); |
| 201 EXPECT_FALSE(PopMoveAndMatch(local_reg_translated, window_reg)); |
| 202 translator()->TranslateOutputRegisters(); |
184 EXPECT_EQ(4, move_count()); | 203 EXPECT_EQ(4, move_count()); |
185 EXPECT_TRUE(PopMoveAndMatch(window_reg, param_reg)); | 204 EXPECT_TRUE(PopMoveAndMatch(window_reg, param_reg)); |
186 } | 205 } |
187 | 206 |
188 TEST_F(RegisterTranslatorTest, RangeTranslation) { | 207 TEST_F(RegisterTranslatorTest, RangeTranslation) { |
189 Register window0(window_start()); | 208 Register window0(window_start()); |
190 Register window1(window_start() + 1); | 209 Register window1(window_start() + 1); |
191 Register window2(window_start() + 2); | 210 Register window2(window_start() + 2); |
192 uint32_t operands[3]; | 211 uint32_t operands[3]; |
193 | 212 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 uint32_t operands[] = {receiver.ToRawOperand(), index.ToRawOperand(), | 264 uint32_t operands[] = {receiver.ToRawOperand(), index.ToRawOperand(), |
246 cache_info_pair.ToRawOperand()}; | 265 cache_info_pair.ToRawOperand()}; |
247 ASSERT_DEATH_IF_SUPPORTED( | 266 ASSERT_DEATH_IF_SUPPORTED( |
248 translator()->TranslateInputRegisters(Bytecode::kForInNext, operands, 3), | 267 translator()->TranslateInputRegisters(Bytecode::kForInNext, operands, 3), |
249 kBadOperandRegex); | 268 kBadOperandRegex); |
250 } | 269 } |
251 | 270 |
252 } // namespace interpreter | 271 } // namespace interpreter |
253 } // namespace internal | 272 } // namespace internal |
254 } // namespace v8 | 273 } // namespace v8 |
OLD | NEW |