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