OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. Use of this | 1 // Copyright 2014 the V8 project authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #include <cmath> | 5 #include <cmath> |
6 #include <functional> | 6 #include <functional> |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/base/ieee754.h" | 10 #include "src/base/ieee754.h" |
(...skipping 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 RawMachineAssemblerTester<uint32_t> m(MachineType::Uint32()); | 2074 RawMachineAssemblerTester<uint32_t> m(MachineType::Uint32()); |
2075 m.Return(m.Int32Mul(m.Parameter(0), m.Int32Constant(*i))); | 2075 m.Return(m.Int32Mul(m.Parameter(0), m.Int32Constant(*i))); |
2076 FOR_UINT32_INPUTS(j) { | 2076 FOR_UINT32_INPUTS(j) { |
2077 uint32_t expected = *j * *i; | 2077 uint32_t expected = *j * *i; |
2078 CHECK_EQ(expected, m.Call(*j)); | 2078 CHECK_EQ(expected, m.Call(*j)); |
2079 } | 2079 } |
2080 } | 2080 } |
2081 } | 2081 } |
2082 } | 2082 } |
2083 | 2083 |
2084 | |
2085 TEST(RunInt32MulAndInt32AddP) { | 2084 TEST(RunInt32MulAndInt32AddP) { |
2086 { | 2085 { |
2087 FOR_INT32_INPUTS(i) { | 2086 FOR_INT32_INPUTS(i) { |
2088 FOR_INT32_INPUTS(j) { | 2087 FOR_INT32_INPUTS(j) { |
2089 RawMachineAssemblerTester<int32_t> m(MachineType::Int32()); | 2088 RawMachineAssemblerTester<int32_t> m(MachineType::Int32()); |
2090 int32_t p0 = *i; | 2089 int32_t p0 = *i; |
2091 int32_t p1 = *j; | 2090 int32_t p1 = *j; |
2092 m.Return(m.Int32Add(m.Int32Constant(p0), | 2091 m.Return(m.Int32Add(m.Int32Constant(p0), |
2093 m.Int32Mul(m.Parameter(0), m.Int32Constant(p1)))); | 2092 m.Int32Mul(m.Parameter(0), m.Int32Constant(p1)))); |
2094 FOR_INT32_INPUTS(k) { | 2093 FOR_INT32_INPUTS(k) { |
(...skipping 3172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5267 bt.AddReturn(val); | 5266 bt.AddReturn(val); |
5268 FOR_INT32_INPUTS(i) { | 5267 FOR_INT32_INPUTS(i) { |
5269 FOR_INT32_INPUTS(j) { | 5268 FOR_INT32_INPUTS(j) { |
5270 int32_t expected; | 5269 int32_t expected; |
5271 if (bits::SignedSubOverflow32(*i, *j, &expected)) expected = constant; | 5270 if (bits::SignedSubOverflow32(*i, *j, &expected)) expected = constant; |
5272 CHECK_EQ(expected, bt.call(*i, *j)); | 5271 CHECK_EQ(expected, bt.call(*i, *j)); |
5273 } | 5272 } |
5274 } | 5273 } |
5275 } | 5274 } |
5276 | 5275 |
| 5276 TEST(RunInt32MulWithOverflowP) { |
| 5277 int32_t actual_val = -1; |
| 5278 RawMachineAssemblerTester<int32_t> m; |
| 5279 Int32BinopTester bt(&m); |
| 5280 Node* add = m.Int32MulWithOverflow(bt.param0, bt.param1); |
| 5281 Node* val = m.Projection(0, add); |
| 5282 Node* ovf = m.Projection(1, add); |
| 5283 m.StoreToPointer(&actual_val, MachineRepresentation::kWord32, val); |
| 5284 bt.AddReturn(ovf); |
| 5285 FOR_INT32_INPUTS(i) { |
| 5286 FOR_INT32_INPUTS(j) { |
| 5287 int32_t expected_val; |
| 5288 int expected_ovf = bits::SignedMulOverflow32(*i, *j, &expected_val); |
| 5289 CHECK_EQ(expected_ovf, bt.call(*i, *j)); |
| 5290 if (!expected_ovf) { |
| 5291 CHECK_EQ(expected_val, actual_val); |
| 5292 } |
| 5293 } |
| 5294 } |
| 5295 } |
| 5296 |
| 5297 TEST(RunInt32MulWithOverflowImm) { |
| 5298 int32_t actual_val = -1, expected_val = 0; |
| 5299 FOR_INT32_INPUTS(i) { |
| 5300 { |
| 5301 RawMachineAssemblerTester<int32_t> m(MachineType::Int32()); |
| 5302 Node* add = m.Int32MulWithOverflow(m.Int32Constant(*i), m.Parameter(0)); |
| 5303 Node* val = m.Projection(0, add); |
| 5304 Node* ovf = m.Projection(1, add); |
| 5305 m.StoreToPointer(&actual_val, MachineRepresentation::kWord32, val); |
| 5306 m.Return(ovf); |
| 5307 FOR_INT32_INPUTS(j) { |
| 5308 int expected_ovf = bits::SignedMulOverflow32(*i, *j, &expected_val); |
| 5309 CHECK_EQ(expected_ovf, m.Call(*j)); |
| 5310 if (!expected_ovf) { |
| 5311 CHECK_EQ(expected_val, actual_val); |
| 5312 } |
| 5313 } |
| 5314 } |
| 5315 { |
| 5316 RawMachineAssemblerTester<int32_t> m(MachineType::Int32()); |
| 5317 Node* add = m.Int32MulWithOverflow(m.Parameter(0), m.Int32Constant(*i)); |
| 5318 Node* val = m.Projection(0, add); |
| 5319 Node* ovf = m.Projection(1, add); |
| 5320 m.StoreToPointer(&actual_val, MachineRepresentation::kWord32, val); |
| 5321 m.Return(ovf); |
| 5322 FOR_INT32_INPUTS(j) { |
| 5323 int expected_ovf = bits::SignedMulOverflow32(*i, *j, &expected_val); |
| 5324 CHECK_EQ(expected_ovf, m.Call(*j)); |
| 5325 if (!expected_ovf) { |
| 5326 CHECK_EQ(expected_val, actual_val); |
| 5327 } |
| 5328 } |
| 5329 } |
| 5330 FOR_INT32_INPUTS(j) { |
| 5331 RawMachineAssemblerTester<int32_t> m; |
| 5332 Node* add = |
| 5333 m.Int32MulWithOverflow(m.Int32Constant(*i), m.Int32Constant(*j)); |
| 5334 Node* val = m.Projection(0, add); |
| 5335 Node* ovf = m.Projection(1, add); |
| 5336 m.StoreToPointer(&actual_val, MachineRepresentation::kWord32, val); |
| 5337 m.Return(ovf); |
| 5338 int expected_ovf = bits::SignedMulOverflow32(*i, *j, &expected_val); |
| 5339 CHECK_EQ(expected_ovf, m.Call()); |
| 5340 if (!expected_ovf) { |
| 5341 CHECK_EQ(expected_val, actual_val); |
| 5342 } |
| 5343 } |
| 5344 } |
| 5345 } |
| 5346 |
| 5347 TEST(RunInt32MulWithOverflowInBranchP) { |
| 5348 int constant = 911777; |
| 5349 RawMachineLabel blocka, blockb; |
| 5350 RawMachineAssemblerTester<int32_t> m; |
| 5351 Int32BinopTester bt(&m); |
| 5352 Node* add = m.Int32MulWithOverflow(bt.param0, bt.param1); |
| 5353 Node* ovf = m.Projection(1, add); |
| 5354 m.Branch(ovf, &blocka, &blockb); |
| 5355 m.Bind(&blocka); |
| 5356 bt.AddReturn(m.Int32Constant(constant)); |
| 5357 m.Bind(&blockb); |
| 5358 Node* val = m.Projection(0, add); |
| 5359 bt.AddReturn(val); |
| 5360 FOR_INT32_INPUTS(i) { |
| 5361 FOR_INT32_INPUTS(j) { |
| 5362 int32_t expected; |
| 5363 if (bits::SignedMulOverflow32(*i, *j, &expected)) expected = constant; |
| 5364 CHECK_EQ(expected, bt.call(*i, *j)); |
| 5365 } |
| 5366 } |
| 5367 } |
5277 | 5368 |
5278 TEST(RunWord64EqualInBranchP) { | 5369 TEST(RunWord64EqualInBranchP) { |
5279 int64_t input; | 5370 int64_t input; |
5280 RawMachineLabel blocka, blockb; | 5371 RawMachineLabel blocka, blockb; |
5281 RawMachineAssemblerTester<int64_t> m; | 5372 RawMachineAssemblerTester<int64_t> m; |
5282 if (!m.machine()->Is64()) return; | 5373 if (!m.machine()->Is64()) return; |
5283 Node* value = m.LoadFromPointer(&input, MachineType::Int64()); | 5374 Node* value = m.LoadFromPointer(&input, MachineType::Int64()); |
5284 m.Branch(m.Word64Equal(value, m.Int64Constant(0)), &blocka, &blockb); | 5375 m.Branch(m.Word64Equal(value, m.Int64Constant(0)), &blocka, &blockb); |
5285 m.Bind(&blocka); | 5376 m.Bind(&blocka); |
5286 m.Return(m.Int32Constant(1)); | 5377 m.Return(m.Int32Constant(1)); |
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6459 r.Goto(&merge); | 6550 r.Goto(&merge); |
6460 r.Bind(&merge); | 6551 r.Bind(&merge); |
6461 Node* phi = r.Phi(MachineRepresentation::kWord32, fa, fb); | 6552 Node* phi = r.Phi(MachineRepresentation::kWord32, fa, fb); |
6462 r.Return(phi); | 6553 r.Return(phi); |
6463 CHECK_EQ(1, r.Call(1)); | 6554 CHECK_EQ(1, r.Call(1)); |
6464 } | 6555 } |
6465 | 6556 |
6466 } // namespace compiler | 6557 } // namespace compiler |
6467 } // namespace internal | 6558 } // namespace internal |
6468 } // namespace v8 | 6559 } // namespace v8 |
OLD | NEW |