| 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/utils/random-number-generator.h" | 10 #include "src/base/utils/random-number-generator.h" |
| (...skipping 5447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5458 FOR_FLOAT64_INPUTS(i) { CHECK_EQ(bit_cast<int64_t>(*i), m.Call(*i)); } | 5458 FOR_FLOAT64_INPUTS(i) { CHECK_EQ(bit_cast<int64_t>(*i), m.Call(*i)); } |
| 5459 } | 5459 } |
| 5460 | 5460 |
| 5461 | 5461 |
| 5462 TEST(RunTryTruncateFloat32ToInt64WithoutCheck) { | 5462 TEST(RunTryTruncateFloat32ToInt64WithoutCheck) { |
| 5463 BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Float32()); | 5463 BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Float32()); |
| 5464 m.Return(m.TryTruncateFloat32ToInt64(m.Parameter(0))); | 5464 m.Return(m.TryTruncateFloat32ToInt64(m.Parameter(0))); |
| 5465 | 5465 |
| 5466 FOR_INT64_INPUTS(i) { | 5466 FOR_INT64_INPUTS(i) { |
| 5467 float input = static_cast<float>(*i); | 5467 float input = static_cast<float>(*i); |
| 5468 if (input < 9223372036854775808.0 && input > -9223372036854775809.0) { | 5468 if (input < static_cast<float>(INT64_MAX) && |
| 5469 input >= static_cast<float>(INT64_MIN)) { |
| 5469 CHECK_EQ(static_cast<int64_t>(input), m.Call(input)); | 5470 CHECK_EQ(static_cast<int64_t>(input), m.Call(input)); |
| 5470 } | 5471 } |
| 5471 } | 5472 } |
| 5472 } | 5473 } |
| 5473 | 5474 |
| 5474 | 5475 |
| 5475 TEST(RunTryTruncateFloat32ToInt64WithCheck) { | 5476 TEST(RunTryTruncateFloat32ToInt64WithCheck) { |
| 5476 int64_t success = 0; | 5477 int64_t success = 0; |
| 5477 BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Float32()); | 5478 BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Float32()); |
| 5478 Node* trunc = m.TryTruncateFloat32ToInt64(m.Parameter(0)); | 5479 Node* trunc = m.TryTruncateFloat32ToInt64(m.Parameter(0)); |
| 5479 Node* val = m.Projection(0, trunc); | 5480 Node* val = m.Projection(0, trunc); |
| 5480 Node* check = m.Projection(1, trunc); | 5481 Node* check = m.Projection(1, trunc); |
| 5481 m.StoreToPointer(&success, MachineRepresentation::kWord64, check); | 5482 m.StoreToPointer(&success, MachineRepresentation::kWord64, check); |
| 5482 m.Return(val); | 5483 m.Return(val); |
| 5483 | 5484 |
| 5484 FOR_FLOAT32_INPUTS(i) { | 5485 FOR_FLOAT32_INPUTS(i) { |
| 5485 if (*i < 9223372036854775808.0 && *i > -9223372036854775809.0) { | 5486 if (*i < static_cast<float>(INT64_MAX) && |
| 5487 *i >= static_cast<float>(INT64_MIN)) { |
| 5486 CHECK_EQ(static_cast<int64_t>(*i), m.Call(*i)); | 5488 CHECK_EQ(static_cast<int64_t>(*i), m.Call(*i)); |
| 5487 CHECK_NE(0, success); | 5489 CHECK_NE(0, success); |
| 5488 } else { | 5490 } else { |
| 5489 m.Call(*i); | 5491 m.Call(*i); |
| 5490 CHECK_EQ(0, success); | 5492 CHECK_EQ(0, success); |
| 5491 } | 5493 } |
| 5492 } | 5494 } |
| 5493 } | 5495 } |
| 5494 | 5496 |
| 5495 | 5497 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5507 TEST(RunTryTruncateFloat64ToInt64WithCheck) { | 5509 TEST(RunTryTruncateFloat64ToInt64WithCheck) { |
| 5508 int64_t success = 0; | 5510 int64_t success = 0; |
| 5509 BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Float64()); | 5511 BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Float64()); |
| 5510 Node* trunc = m.TryTruncateFloat64ToInt64(m.Parameter(0)); | 5512 Node* trunc = m.TryTruncateFloat64ToInt64(m.Parameter(0)); |
| 5511 Node* val = m.Projection(0, trunc); | 5513 Node* val = m.Projection(0, trunc); |
| 5512 Node* check = m.Projection(1, trunc); | 5514 Node* check = m.Projection(1, trunc); |
| 5513 m.StoreToPointer(&success, MachineRepresentation::kWord64, check); | 5515 m.StoreToPointer(&success, MachineRepresentation::kWord64, check); |
| 5514 m.Return(val); | 5516 m.Return(val); |
| 5515 | 5517 |
| 5516 FOR_FLOAT64_INPUTS(i) { | 5518 FOR_FLOAT64_INPUTS(i) { |
| 5517 if (*i < 9223372036854775808.0 && *i > -9223372036854775809.0) { | 5519 if (*i < static_cast<double>(INT64_MAX) && |
| 5520 *i >= static_cast<double>(INT64_MIN)) { |
| 5518 // Conversions within this range should succeed. | 5521 // Conversions within this range should succeed. |
| 5519 CHECK_EQ(static_cast<int64_t>(*i), m.Call(*i)); | 5522 CHECK_EQ(static_cast<int64_t>(*i), m.Call(*i)); |
| 5520 CHECK_NE(0, success); | 5523 CHECK_NE(0, success); |
| 5521 } else { | 5524 } else { |
| 5522 m.Call(*i); | 5525 m.Call(*i); |
| 5523 CHECK_EQ(0, success); | 5526 CHECK_EQ(0, success); |
| 5524 } | 5527 } |
| 5525 } | 5528 } |
| 5526 } | 5529 } |
| 5527 | 5530 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5874 Node* call = r.AddNode(r.common()->Call(desc), phi); | 5877 Node* call = r.AddNode(r.common()->Call(desc), phi); |
| 5875 r.Return(call); | 5878 r.Return(call); |
| 5876 | 5879 |
| 5877 CHECK_EQ(33, r.Call(1)); | 5880 CHECK_EQ(33, r.Call(1)); |
| 5878 CHECK_EQ(44, r.Call(0)); | 5881 CHECK_EQ(44, r.Call(0)); |
| 5879 } | 5882 } |
| 5880 | 5883 |
| 5881 } // namespace compiler | 5884 } // namespace compiler |
| 5882 } // namespace internal | 5885 } // namespace internal |
| 5883 } // namespace v8 | 5886 } // namespace v8 |
| OLD | NEW |