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/unittests/compiler/instruction-selector-unittest.h" | 5 #include "test/unittests/compiler/instruction-selector-unittest.h" |
6 | 6 |
7 #include "src/compiler/node-matchers.h" | 7 #include "src/compiler/node-matchers.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 | 27 |
28 TEST_F(InstructionSelectorTest, ChangeInt32ToInt64WithParameter) { | 28 TEST_F(InstructionSelectorTest, ChangeInt32ToInt64WithParameter) { |
29 StreamBuilder m(this, MachineType::Int64(), MachineType::Int32()); | 29 StreamBuilder m(this, MachineType::Int64(), MachineType::Int32()); |
30 m.Return(m.ChangeInt32ToInt64(m.Parameter(0))); | 30 m.Return(m.ChangeInt32ToInt64(m.Parameter(0))); |
31 Stream s = m.Build(); | 31 Stream s = m.Build(); |
32 ASSERT_EQ(1U, s.size()); | 32 ASSERT_EQ(1U, s.size()); |
33 EXPECT_EQ(kX64Movsxlq, s[0]->arch_opcode()); | 33 EXPECT_EQ(kX64Movsxlq, s[0]->arch_opcode()); |
34 } | 34 } |
35 | 35 |
36 | |
37 TEST_F(InstructionSelectorTest, ChangeUint32ToFloat64WithParameter) { | 36 TEST_F(InstructionSelectorTest, ChangeUint32ToFloat64WithParameter) { |
38 StreamBuilder m(this, MachineType::Float64(), MachineType::Uint32()); | 37 StreamBuilder m(this, MachineType::Float64(), MachineType::Uint32()); |
39 m.Return(m.ChangeUint32ToFloat64(m.Parameter(0))); | 38 m.Return(m.ChangeUint32ToFloat64(m.Parameter(0))); |
40 Stream s = m.Build(); | 39 Stream s = m.Build(); |
41 ASSERT_EQ(1U, s.size()); | 40 ASSERT_EQ(1U, s.size()); |
42 EXPECT_EQ(kSSEUint32ToFloat64, s[0]->arch_opcode()); | 41 EXPECT_EQ(kSSEUint32ToFloat64, s[0]->arch_opcode()); |
43 } | 42 } |
44 | 43 |
45 | 44 |
46 TEST_F(InstructionSelectorTest, ChangeUint32ToUint64WithParameter) { | 45 TEST_F(InstructionSelectorTest, ChangeUint32ToUint64WithParameter) { |
(...skipping 17 matching lines...) Expand all Loading... |
64 | 63 |
65 | 64 |
66 TEST_F(InstructionSelectorTest, TruncateInt64ToInt32WithParameter) { | 65 TEST_F(InstructionSelectorTest, TruncateInt64ToInt32WithParameter) { |
67 StreamBuilder m(this, MachineType::Int32(), MachineType::Int64()); | 66 StreamBuilder m(this, MachineType::Int32(), MachineType::Int64()); |
68 m.Return(m.TruncateInt64ToInt32(m.Parameter(0))); | 67 m.Return(m.TruncateInt64ToInt32(m.Parameter(0))); |
69 Stream s = m.Build(); | 68 Stream s = m.Build(); |
70 ASSERT_EQ(1U, s.size()); | 69 ASSERT_EQ(1U, s.size()); |
71 EXPECT_EQ(kX64Movl, s[0]->arch_opcode()); | 70 EXPECT_EQ(kX64Movl, s[0]->arch_opcode()); |
72 } | 71 } |
73 | 72 |
| 73 namespace { |
| 74 struct LoadWithToInt64Extension { |
| 75 MachineType type; |
| 76 ArchOpcode expected_opcode; |
| 77 }; |
| 78 |
| 79 std::ostream& operator<<(std::ostream& os, |
| 80 const LoadWithToInt64Extension& i32toi64) { |
| 81 return os << i32toi64.type; |
| 82 } |
| 83 |
| 84 static const LoadWithToInt64Extension kLoadWithToInt64Extensions[] = { |
| 85 {MachineType::Int8(), kX64Movsxbq}, |
| 86 {MachineType::Uint8(), kX64Movzxbq}, |
| 87 {MachineType::Int16(), kX64Movsxwq}, |
| 88 {MachineType::Uint16(), kX64Movzxwq}, |
| 89 {MachineType::Int32(), kX64Movsxlq}}; |
| 90 |
| 91 } // namespace |
| 92 |
| 93 typedef InstructionSelectorTestWithParam<LoadWithToInt64Extension> |
| 94 InstructionSelectorChangeInt32ToInt64Test; |
| 95 |
| 96 TEST_P(InstructionSelectorChangeInt32ToInt64Test, ChangeInt32ToInt64WithLoad) { |
| 97 const LoadWithToInt64Extension extension = GetParam(); |
| 98 StreamBuilder m(this, MachineType::Int64(), MachineType::Pointer()); |
| 99 m.Return(m.ChangeInt32ToInt64(m.Load(extension.type, m.Parameter(0)))); |
| 100 Stream s = m.Build(); |
| 101 ASSERT_EQ(1U, s.size()); |
| 102 EXPECT_EQ(extension.expected_opcode, s[0]->arch_opcode()); |
| 103 } |
| 104 |
| 105 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
| 106 InstructionSelectorChangeInt32ToInt64Test, |
| 107 ::testing::ValuesIn(kLoadWithToInt64Extensions)); |
74 | 108 |
75 // ----------------------------------------------------------------------------- | 109 // ----------------------------------------------------------------------------- |
76 // Loads and stores | 110 // Loads and stores |
77 | 111 |
78 | 112 |
79 namespace { | 113 namespace { |
80 | 114 |
81 struct MemoryAccess { | 115 struct MemoryAccess { |
82 MachineType type; | 116 MachineType type; |
83 ArchOpcode load_opcode; | 117 ArchOpcode load_opcode; |
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 EXPECT_EQ(kX64Lzcnt32, s[0]->arch_opcode()); | 1364 EXPECT_EQ(kX64Lzcnt32, s[0]->arch_opcode()); |
1331 ASSERT_EQ(1U, s[0]->InputCount()); | 1365 ASSERT_EQ(1U, s[0]->InputCount()); |
1332 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); | 1366 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
1333 ASSERT_EQ(1U, s[0]->OutputCount()); | 1367 ASSERT_EQ(1U, s[0]->OutputCount()); |
1334 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); | 1368 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); |
1335 } | 1369 } |
1336 | 1370 |
1337 } // namespace compiler | 1371 } // namespace compiler |
1338 } // namespace internal | 1372 } // namespace internal |
1339 } // namespace v8 | 1373 } // namespace v8 |
OLD | NEW |