| 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 "test/compiler-unittests/instruction-selector-unittest.h" | 5 #include "test/compiler-unittests/instruction-selector-unittest.h" |
| 6 | 6 |
| 7 namespace v8 { | 7 namespace v8 { |
| 8 namespace internal { | 8 namespace internal { |
| 9 namespace compiler { | 9 namespace compiler { |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // Immediates (random subset). | 13 // Immediates (random subset). |
| 14 static const int32_t kImmediates[] = { | 14 static const int32_t kImmediates[] = { |
| 15 kMinInt, -42, -1, 0, 1, 2, 3, 4, 5, | 15 kMinInt, -42, -1, 0, 1, 2, 3, 4, 5, |
| 16 6, 7, 8, 16, 42, 0xff, 0xffff, 0x0f0f0f0f, kMaxInt}; | 16 6, 7, 8, 16, 42, 0xff, 0xffff, 0x0f0f0f0f, kMaxInt}; |
| 17 | 17 |
| 18 } // namespace | 18 } // namespace |
| 19 | 19 |
| 20 | 20 |
| 21 TEST_F(InstructionSelectorTest, Int32AddWithParameter) { | 21 TEST_F(InstructionSelectorTest, Int32AddWithParameter) { |
| 22 StreamBuilder m(this, kMachineWord32, kMachineWord32, kMachineWord32); | 22 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
| 23 m.Return(m.Int32Add(m.Parameter(0), m.Parameter(1))); | 23 m.Return(m.Int32Add(m.Parameter(0), m.Parameter(1))); |
| 24 Stream s = m.Build(); | 24 Stream s = m.Build(); |
| 25 ASSERT_EQ(1U, s.size()); | 25 ASSERT_EQ(1U, s.size()); |
| 26 EXPECT_EQ(kIA32Add, s[0]->arch_opcode()); | 26 EXPECT_EQ(kIA32Add, s[0]->arch_opcode()); |
| 27 } | 27 } |
| 28 | 28 |
| 29 | 29 |
| 30 TEST_F(InstructionSelectorTest, Int32AddWithImmediate) { | 30 TEST_F(InstructionSelectorTest, Int32AddWithImmediate) { |
| 31 TRACED_FOREACH(int32_t, imm, kImmediates) { | 31 TRACED_FOREACH(int32_t, imm, kImmediates) { |
| 32 { | 32 { |
| 33 StreamBuilder m(this, kMachineWord32, kMachineWord32); | 33 StreamBuilder m(this, kMachInt32, kMachInt32); |
| 34 m.Return(m.Int32Add(m.Parameter(0), m.Int32Constant(imm))); | 34 m.Return(m.Int32Add(m.Parameter(0), m.Int32Constant(imm))); |
| 35 Stream s = m.Build(); | 35 Stream s = m.Build(); |
| 36 ASSERT_EQ(1U, s.size()); | 36 ASSERT_EQ(1U, s.size()); |
| 37 EXPECT_EQ(kIA32Add, s[0]->arch_opcode()); | 37 EXPECT_EQ(kIA32Add, s[0]->arch_opcode()); |
| 38 ASSERT_EQ(2U, s[0]->InputCount()); | 38 ASSERT_EQ(2U, s[0]->InputCount()); |
| 39 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); | 39 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); |
| 40 } | 40 } |
| 41 { | 41 { |
| 42 StreamBuilder m(this, kMachineWord32, kMachineWord32); | 42 StreamBuilder m(this, kMachInt32, kMachInt32); |
| 43 m.Return(m.Int32Add(m.Int32Constant(imm), m.Parameter(0))); | 43 m.Return(m.Int32Add(m.Int32Constant(imm), m.Parameter(0))); |
| 44 Stream s = m.Build(); | 44 Stream s = m.Build(); |
| 45 ASSERT_EQ(1U, s.size()); | 45 ASSERT_EQ(1U, s.size()); |
| 46 EXPECT_EQ(kIA32Add, s[0]->arch_opcode()); | 46 EXPECT_EQ(kIA32Add, s[0]->arch_opcode()); |
| 47 ASSERT_EQ(2U, s[0]->InputCount()); | 47 ASSERT_EQ(2U, s[0]->InputCount()); |
| 48 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); | 48 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 TEST_F(InstructionSelectorTest, Int32SubWithParameter) { | 54 TEST_F(InstructionSelectorTest, Int32SubWithParameter) { |
| 55 StreamBuilder m(this, kMachineWord32, kMachineWord32, kMachineWord32); | 55 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
| 56 m.Return(m.Int32Sub(m.Parameter(0), m.Parameter(1))); | 56 m.Return(m.Int32Sub(m.Parameter(0), m.Parameter(1))); |
| 57 Stream s = m.Build(); | 57 Stream s = m.Build(); |
| 58 ASSERT_EQ(1U, s.size()); | 58 ASSERT_EQ(1U, s.size()); |
| 59 EXPECT_EQ(kIA32Sub, s[0]->arch_opcode()); | 59 EXPECT_EQ(kIA32Sub, s[0]->arch_opcode()); |
| 60 EXPECT_EQ(1U, s[0]->OutputCount()); | 60 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 | 63 |
| 64 TEST_F(InstructionSelectorTest, Int32SubWithImmediate) { | 64 TEST_F(InstructionSelectorTest, Int32SubWithImmediate) { |
| 65 TRACED_FOREACH(int32_t, imm, kImmediates) { | 65 TRACED_FOREACH(int32_t, imm, kImmediates) { |
| 66 StreamBuilder m(this, kMachineWord32, kMachineWord32); | 66 StreamBuilder m(this, kMachInt32, kMachInt32); |
| 67 m.Return(m.Int32Sub(m.Parameter(0), m.Int32Constant(imm))); | 67 m.Return(m.Int32Sub(m.Parameter(0), m.Int32Constant(imm))); |
| 68 Stream s = m.Build(); | 68 Stream s = m.Build(); |
| 69 ASSERT_EQ(1U, s.size()); | 69 ASSERT_EQ(1U, s.size()); |
| 70 EXPECT_EQ(kIA32Sub, s[0]->arch_opcode()); | 70 EXPECT_EQ(kIA32Sub, s[0]->arch_opcode()); |
| 71 ASSERT_EQ(2U, s[0]->InputCount()); | 71 ASSERT_EQ(2U, s[0]->InputCount()); |
| 72 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); | 72 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace compiler | 76 } // namespace compiler |
| 77 } // namespace internal | 77 } // namespace internal |
| 78 } // namespace v8 | 78 } // namespace v8 |
| OLD | NEW |