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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 StreamBuilder m(this, kMachFloat64, kMachFloat32); | 56 StreamBuilder m(this, kMachFloat64, kMachFloat32); |
57 m.Return(m.TruncateFloat64ToFloat32(m.Parameter(0))); | 57 m.Return(m.TruncateFloat64ToFloat32(m.Parameter(0))); |
58 Stream s = m.Build(); | 58 Stream s = m.Build(); |
59 ASSERT_EQ(1U, s.size()); | 59 ASSERT_EQ(1U, s.size()); |
60 EXPECT_EQ(kSSECvtsd2ss, s[0]->arch_opcode()); | 60 EXPECT_EQ(kSSECvtsd2ss, s[0]->arch_opcode()); |
61 EXPECT_EQ(1U, s[0]->InputCount()); | 61 EXPECT_EQ(1U, s[0]->InputCount()); |
62 EXPECT_EQ(1U, s[0]->OutputCount()); | 62 EXPECT_EQ(1U, s[0]->OutputCount()); |
63 } | 63 } |
64 | 64 |
65 | 65 |
66 TEST_F(InstructionSelectorTest, TruncateInt64ToInt32WithParameter) { | |
67 StreamBuilder m(this, kMachInt32, kMachInt64); | |
68 m.Return(m.TruncateInt64ToInt32(m.Parameter(0))); | |
69 Stream s = m.Build(); | |
70 ASSERT_EQ(1U, s.size()); | |
71 EXPECT_EQ(kX64Movl, s[0]->arch_opcode()); | |
72 } | |
73 | |
74 | |
75 // ----------------------------------------------------------------------------- | 66 // ----------------------------------------------------------------------------- |
76 // Loads and stores | 67 // Loads and stores |
77 | 68 |
78 namespace { | 69 namespace { |
79 | 70 |
80 struct MemoryAccess { | 71 struct MemoryAccess { |
81 MachineType type; | 72 MachineType type; |
82 ArchOpcode load_opcode; | 73 ArchOpcode load_opcode; |
83 ArchOpcode store_opcode; | 74 ArchOpcode store_opcode; |
84 }; | 75 }; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 190 |
200 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, | 191 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
201 InstructionSelectorChangeUint32ToUint64Test, | 192 InstructionSelectorChangeUint32ToUint64Test, |
202 ::testing::ValuesIn(kWord32BinaryOperations)); | 193 ::testing::ValuesIn(kWord32BinaryOperations)); |
203 | 194 |
204 | 195 |
205 // ----------------------------------------------------------------------------- | 196 // ----------------------------------------------------------------------------- |
206 // TruncateInt64ToInt32. | 197 // TruncateInt64ToInt32. |
207 | 198 |
208 | 199 |
209 TEST_F(InstructionSelectorTest, TruncateInt64ToInt32WithWord64Sar) { | 200 TEST_F(InstructionSelectorTest, TruncateInt64ToInt32WithParameter) { |
210 StreamBuilder m(this, kMachInt32, kMachInt64); | 201 StreamBuilder m(this, kMachInt32, kMachInt64); |
211 Node* const p = m.Parameter(0); | 202 m.Return(m.TruncateInt64ToInt32(m.Parameter(0))); |
212 Node* const t = m.TruncateInt64ToInt32(m.Word64Sar(p, m.Int64Constant(32))); | |
213 m.Return(t); | |
214 Stream s = m.Build(); | 203 Stream s = m.Build(); |
215 ASSERT_EQ(1U, s.size()); | 204 ASSERT_EQ(0U, s.size()); |
216 EXPECT_EQ(kX64Shr, s[0]->arch_opcode()); | |
217 ASSERT_EQ(2U, s[0]->InputCount()); | |
218 EXPECT_EQ(s.ToVreg(p), s.ToVreg(s[0]->InputAt(0))); | |
219 EXPECT_EQ(32, s.ToInt32(s[0]->InputAt(1))); | |
220 ASSERT_EQ(1U, s[0]->OutputCount()); | |
221 EXPECT_TRUE(s.IsSameAsFirst(s[0]->OutputAt(0))); | |
222 EXPECT_EQ(s.ToVreg(t), s.ToVreg(s[0]->OutputAt(0))); | |
223 } | 205 } |
224 | 206 |
225 | 207 |
226 TEST_F(InstructionSelectorTest, TruncateInt64ToInt32WithWord64Shr) { | 208 TEST_F(InstructionSelectorTest, TruncateInt64ToInt32WithWord64Sar) { |
227 StreamBuilder m(this, kMachInt32, kMachInt64); | 209 TRACED_FORRANGE(int32_t, k, 1, 32) { |
228 Node* const p = m.Parameter(0); | 210 StreamBuilder m(this, kMachInt32, kMachInt64); |
229 Node* const t = m.TruncateInt64ToInt32(m.Word64Shr(p, m.Int64Constant(32))); | 211 Node* const p = m.Parameter(0); |
230 m.Return(t); | 212 Node* const t = m.TruncateInt64ToInt32(m.Word64Sar(p, m.Int64Constant(k))); |
231 Stream s = m.Build(); | 213 m.Return(t); |
232 ASSERT_EQ(1U, s.size()); | 214 Stream s = m.Build(); |
233 EXPECT_EQ(kX64Shr, s[0]->arch_opcode()); | 215 ASSERT_EQ(1U, s.size()); |
234 ASSERT_EQ(2U, s[0]->InputCount()); | 216 EXPECT_EQ(kX64Shr, s[0]->arch_opcode()); |
235 EXPECT_EQ(s.ToVreg(p), s.ToVreg(s[0]->InputAt(0))); | 217 ASSERT_EQ(2U, s[0]->InputCount()); |
236 EXPECT_EQ(32, s.ToInt32(s[0]->InputAt(1))); | 218 EXPECT_EQ(s.ToVreg(p), s.ToVreg(s[0]->InputAt(0))); |
237 ASSERT_EQ(1U, s[0]->OutputCount()); | 219 EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(1))); |
238 EXPECT_TRUE(s.IsSameAsFirst(s[0]->OutputAt(0))); | 220 ASSERT_EQ(1U, s[0]->OutputCount()); |
239 EXPECT_EQ(s.ToVreg(t), s.ToVreg(s[0]->OutputAt(0))); | 221 EXPECT_TRUE(s.IsSameAsFirst(s[0]->OutputAt(0))); |
| 222 EXPECT_EQ(s.ToVreg(t), s.ToVreg(s[0]->OutputAt(0))); |
| 223 } |
240 } | 224 } |
241 | 225 |
242 | 226 |
| 227 TEST_F(InstructionSelectorTest, TruncateInt64ToInt32WithWord64Shl) { |
| 228 TRACED_FORRANGE(int32_t, k, 1, 31) { |
| 229 StreamBuilder m(this, kMachInt32, kMachInt64); |
| 230 Node* const p = m.Parameter(0); |
| 231 Node* const t = m.TruncateInt64ToInt32(m.Word64Shl(p, m.Int64Constant(k))); |
| 232 m.Return(t); |
| 233 Stream s = m.Build(); |
| 234 ASSERT_EQ(1U, s.size()); |
| 235 EXPECT_EQ(kX64Shl32, s[0]->arch_opcode()); |
| 236 ASSERT_EQ(2U, s[0]->InputCount()); |
| 237 EXPECT_EQ(s.ToVreg(p), s.ToVreg(s[0]->InputAt(0))); |
| 238 EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(1))); |
| 239 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 240 EXPECT_TRUE(s.IsSameAsFirst(s[0]->OutputAt(0))); |
| 241 EXPECT_EQ(s.ToVreg(t), s.ToVreg(s[0]->OutputAt(0))); |
| 242 } |
| 243 } |
| 244 |
| 245 |
243 // ----------------------------------------------------------------------------- | 246 // ----------------------------------------------------------------------------- |
244 // Addition. | 247 // Addition. |
245 | 248 |
246 | 249 |
247 TEST_F(InstructionSelectorTest, Int32AddWithInt32ParametersLea) { | 250 TEST_F(InstructionSelectorTest, Int32AddWithInt32ParametersLea) { |
248 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); | 251 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
249 Node* const p0 = m.Parameter(0); | 252 Node* const p0 = m.Parameter(0); |
250 Node* const p1 = m.Parameter(1); | 253 Node* const p1 = m.Parameter(1); |
251 Node* const a0 = m.Int32Add(p0, p1); | 254 Node* const a0 = m.Int32Add(p0, p1); |
252 // Additional uses of input to add chooses lea | 255 // Additional uses of input to add chooses lea |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 ASSERT_EQ(1U, s[0]->InputCount()); | 1126 ASSERT_EQ(1U, s[0]->InputCount()); |
1124 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); | 1127 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
1125 ASSERT_EQ(1U, s[0]->OutputCount()); | 1128 ASSERT_EQ(1U, s[0]->OutputCount()); |
1126 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); | 1129 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); |
1127 } | 1130 } |
1128 } | 1131 } |
1129 | 1132 |
1130 } // namespace compiler | 1133 } // namespace compiler |
1131 } // namespace internal | 1134 } // namespace internal |
1132 } // namespace v8 | 1135 } // namespace v8 |
OLD | NEW |