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 <list> | 5 #include <list> |
6 | 6 |
7 #include "test/compiler-unittests/instruction-selector-unittest.h" | 7 #include "test/compiler-unittests/instruction-selector-unittest.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 StreamBuilder m(this, type, type, type); | 257 StreamBuilder m(this, type, type, type); |
258 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1))); | 258 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1))); |
259 Stream s = m.Build(); | 259 Stream s = m.Build(); |
260 ASSERT_EQ(1U, s.size()); | 260 ASSERT_EQ(1U, s.size()); |
261 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode()); | 261 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode()); |
262 EXPECT_EQ(2U, s[0]->InputCount()); | 262 EXPECT_EQ(2U, s[0]->InputCount()); |
263 EXPECT_EQ(1U, s[0]->OutputCount()); | 263 EXPECT_EQ(1U, s[0]->OutputCount()); |
264 } | 264 } |
265 | 265 |
266 | 266 |
267 TEST_P(InstructionSelectorAddSubTest, Immediate) { | 267 TEST_P(InstructionSelectorAddSubTest, ImmediateOnRight) { |
268 const MachInst2 dpi = GetParam(); | 268 const MachInst2 dpi = GetParam(); |
269 const MachineType type = dpi.machine_type; | 269 const MachineType type = dpi.machine_type; |
270 TRACED_FOREACH(int32_t, imm, kAddSubImmediates) { | 270 TRACED_FOREACH(int32_t, imm, kAddSubImmediates) { |
271 StreamBuilder m(this, type, type); | 271 StreamBuilder m(this, type, type); |
272 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Int32Constant(imm))); | 272 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Int32Constant(imm))); |
273 Stream s = m.Build(); | 273 Stream s = m.Build(); |
274 ASSERT_EQ(1U, s.size()); | 274 ASSERT_EQ(1U, s.size()); |
275 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode()); | 275 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode()); |
276 ASSERT_EQ(2U, s[0]->InputCount()); | 276 ASSERT_EQ(2U, s[0]->InputCount()); |
277 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate()); | 277 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate()); |
278 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); | 278 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); |
279 EXPECT_EQ(1U, s[0]->OutputCount()); | 279 EXPECT_EQ(1U, s[0]->OutputCount()); |
280 } | 280 } |
281 } | 281 } |
282 | 282 |
283 | 283 |
| 284 TEST_P(InstructionSelectorAddSubTest, ImmediateOnLeft) { |
| 285 const MachInst2 dpi = GetParam(); |
| 286 const MachineType type = dpi.machine_type; |
| 287 |
| 288 TRACED_FOREACH(int32_t, imm, kAddSubImmediates) { |
| 289 StreamBuilder m(this, type, type); |
| 290 m.Return((m.*dpi.constructor)(m.Int32Constant(imm), m.Parameter(0))); |
| 291 Stream s = m.Build(); |
| 292 |
| 293 // Add can support an immediate on the left by commuting, but Sub can't |
| 294 // commute. We test zero-on-left Sub later. |
| 295 if (strstr(dpi.constructor_name, "Add") != NULL) { |
| 296 ASSERT_EQ(1U, s.size()); |
| 297 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode()); |
| 298 ASSERT_EQ(2U, s[0]->InputCount()); |
| 299 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate()); |
| 300 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); |
| 301 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 302 } |
| 303 } |
| 304 } |
| 305 |
| 306 |
284 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorAddSubTest, | 307 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorAddSubTest, |
285 ::testing::ValuesIn(kAddSubInstructions)); | 308 ::testing::ValuesIn(kAddSubInstructions)); |
286 | 309 |
287 | 310 |
| 311 TEST_F(InstructionSelectorTest, SubZeroOnLeft) { |
| 312 // Subtraction with zero on the left maps to Neg. |
| 313 { |
| 314 // 32-bit subtract. |
| 315 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
| 316 m.Return(m.Int32Sub(m.Int32Constant(0), m.Parameter(0))); |
| 317 Stream s = m.Build(); |
| 318 |
| 319 ASSERT_EQ(1U, s.size()); |
| 320 EXPECT_EQ(kArm64Neg32, s[0]->arch_opcode()); |
| 321 EXPECT_EQ(1U, s[0]->InputCount()); |
| 322 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 323 } |
| 324 { |
| 325 // 64-bit subtract. |
| 326 StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64); |
| 327 m.Return(m.Int64Sub(m.Int32Constant(0), m.Parameter(0))); |
| 328 Stream s = m.Build(); |
| 329 |
| 330 ASSERT_EQ(1U, s.size()); |
| 331 EXPECT_EQ(kArm64Neg, s[0]->arch_opcode()); |
| 332 EXPECT_EQ(1U, s[0]->InputCount()); |
| 333 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 334 } |
| 335 } |
| 336 |
| 337 |
288 // ----------------------------------------------------------------------------- | 338 // ----------------------------------------------------------------------------- |
289 // Shift instructions. | 339 // Shift instructions. |
290 | 340 |
291 | 341 |
292 typedef InstructionSelectorTestWithParam<MachInst2> | 342 typedef InstructionSelectorTestWithParam<MachInst2> |
293 InstructionSelectorShiftTest; | 343 InstructionSelectorShiftTest; |
294 | 344 |
295 | 345 |
296 TEST_P(InstructionSelectorShiftTest, Parameter) { | 346 TEST_P(InstructionSelectorShiftTest, Parameter) { |
297 const MachInst2 dpi = GetParam(); | 347 const MachInst2 dpi = GetParam(); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 } | 535 } |
486 | 536 |
487 | 537 |
488 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, | 538 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
489 InstructionSelectorMemoryAccessTest, | 539 InstructionSelectorMemoryAccessTest, |
490 ::testing::ValuesIn(kMemoryAccesses)); | 540 ::testing::ValuesIn(kMemoryAccesses)); |
491 | 541 |
492 } // namespace compiler | 542 } // namespace compiler |
493 } // namespace internal | 543 } // namespace internal |
494 } // namespace v8 | 544 } // namespace v8 |
OLD | NEW |