| 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 5508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5519 CHECK_EQ(static_cast<int64_t>(*i), m.Call(*i)); | 5519 CHECK_EQ(static_cast<int64_t>(*i), m.Call(*i)); |
| 5520 CHECK_NE(0, success); | 5520 CHECK_NE(0, success); |
| 5521 } else { | 5521 } else { |
| 5522 m.Call(*i); | 5522 m.Call(*i); |
| 5523 CHECK_EQ(0, success); | 5523 CHECK_EQ(0, success); |
| 5524 } | 5524 } |
| 5525 } | 5525 } |
| 5526 } | 5526 } |
| 5527 | 5527 |
| 5528 | 5528 |
| 5529 TEST(RunTruncateFloat32ToUint64) { | 5529 TEST(RunTryTruncateFloat32ToUint64WithoutCheck) { |
| 5530 BufferedRawMachineAssemblerTester<uint64_t> m(MachineType::Float32()); | 5530 BufferedRawMachineAssemblerTester<uint64_t> m(MachineType::Float32()); |
| 5531 m.Return(m.TryTruncateFloat32ToUint64(m.Parameter(0))); | 5531 m.Return(m.TryTruncateFloat32ToUint64(m.Parameter(0))); |
| 5532 | 5532 |
| 5533 FOR_UINT64_INPUTS(i) { | 5533 FOR_UINT64_INPUTS(i) { |
| 5534 float input = static_cast<float>(*i); | 5534 float input = static_cast<float>(*i); |
| 5535 if (input < 18446744073709551616.0) { | 5535 if (input < 18446744073709551616.0) { |
| 5536 CHECK_EQ(static_cast<uint64_t>(input), m.Call(input)); | 5536 CHECK_EQ(static_cast<uint64_t>(input), m.Call(input)); |
| 5537 } | 5537 } |
| 5538 } | 5538 } |
| 5539 FOR_FLOAT32_INPUTS(j) { | |
| 5540 if (*j < 18446744073709551616.0 && *j >= 0) { | |
| 5541 CHECK_EQ(static_cast<uint64_t>(*j), m.Call(*j)); | |
| 5542 } | |
| 5543 } | |
| 5544 } | 5539 } |
| 5545 | 5540 |
| 5546 | 5541 |
| 5547 TEST(RunTryTruncateFloat32ToUint64WithCheck) { | 5542 TEST(RunTryTruncateFloat32ToUint64WithCheck) { |
| 5548 int64_t success = 0; | 5543 int64_t success = 0; |
| 5549 BufferedRawMachineAssemblerTester<uint64_t> m(MachineType::Float32()); | 5544 BufferedRawMachineAssemblerTester<uint64_t> m(MachineType::Float32()); |
| 5550 Node* trunc = m.TryTruncateFloat32ToUint64(m.Parameter(0)); | 5545 Node* trunc = m.TryTruncateFloat32ToUint64(m.Parameter(0)); |
| 5551 Node* val = m.Projection(0, trunc); | 5546 Node* val = m.Projection(0, trunc); |
| 5552 Node* check = m.Projection(1, trunc); | 5547 Node* check = m.Projection(1, trunc); |
| 5553 m.StoreToPointer(&success, MachineRepresentation::kWord64, check); | 5548 m.StoreToPointer(&success, MachineRepresentation::kWord64, check); |
| 5554 m.Return(val); | 5549 m.Return(val); |
| 5555 | 5550 |
| 5556 FOR_FLOAT32_INPUTS(i) { | 5551 FOR_FLOAT32_INPUTS(i) { |
| 5557 if (*i < 18446744073709551616.0 && *i >= 0.0) { | 5552 if (*i < 18446744073709551616.0 && *i > -1.0) { |
| 5558 // Conversions within this range should succeed. | 5553 // Conversions within this range should succeed. |
| 5559 CHECK_EQ(static_cast<uint64_t>(*i), m.Call(*i)); | 5554 CHECK_EQ(static_cast<uint64_t>(*i), m.Call(*i)); |
| 5560 CHECK_NE(0, success); | 5555 CHECK_NE(0, success); |
| 5561 } else { | 5556 } else { |
| 5562 m.Call(*i); | 5557 m.Call(*i); |
| 5563 CHECK_EQ(0, success); | 5558 CHECK_EQ(0, success); |
| 5564 } | 5559 } |
| 5565 } | 5560 } |
| 5566 } | 5561 } |
| 5567 | 5562 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5583 TEST(RunTryTruncateFloat64ToUint64WithCheck) { | 5578 TEST(RunTryTruncateFloat64ToUint64WithCheck) { |
| 5584 int64_t success = 0; | 5579 int64_t success = 0; |
| 5585 BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Float64()); | 5580 BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Float64()); |
| 5586 Node* trunc = m.TryTruncateFloat64ToUint64(m.Parameter(0)); | 5581 Node* trunc = m.TryTruncateFloat64ToUint64(m.Parameter(0)); |
| 5587 Node* val = m.Projection(0, trunc); | 5582 Node* val = m.Projection(0, trunc); |
| 5588 Node* check = m.Projection(1, trunc); | 5583 Node* check = m.Projection(1, trunc); |
| 5589 m.StoreToPointer(&success, MachineRepresentation::kWord64, check); | 5584 m.StoreToPointer(&success, MachineRepresentation::kWord64, check); |
| 5590 m.Return(val); | 5585 m.Return(val); |
| 5591 | 5586 |
| 5592 FOR_FLOAT64_INPUTS(i) { | 5587 FOR_FLOAT64_INPUTS(i) { |
| 5593 if (*i < 18446744073709551616.0 && *i >= 0) { | 5588 if (*i < 18446744073709551616.0 && *i > -1) { |
| 5594 // Conversions within this range should succeed. | 5589 // Conversions within this range should succeed. |
| 5595 CHECK_EQ(static_cast<uint64_t>(*i), m.Call(*i)); | 5590 CHECK_EQ(static_cast<uint64_t>(*i), m.Call(*i)); |
| 5596 CHECK_NE(0, success); | 5591 CHECK_NE(0, success); |
| 5597 } else { | 5592 } else { |
| 5598 m.Call(*i); | 5593 m.Call(*i); |
| 5599 CHECK_EQ(0, success); | 5594 CHECK_EQ(0, success); |
| 5600 } | 5595 } |
| 5601 } | 5596 } |
| 5602 } | 5597 } |
| 5603 | 5598 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5874 Node* call = r.AddNode(r.common()->Call(desc), phi); | 5869 Node* call = r.AddNode(r.common()->Call(desc), phi); |
| 5875 r.Return(call); | 5870 r.Return(call); |
| 5876 | 5871 |
| 5877 CHECK_EQ(33, r.Call(1)); | 5872 CHECK_EQ(33, r.Call(1)); |
| 5878 CHECK_EQ(44, r.Call(0)); | 5873 CHECK_EQ(44, r.Call(0)); |
| 5879 } | 5874 } |
| 5880 | 5875 |
| 5881 } // namespace compiler | 5876 } // namespace compiler |
| 5882 } // namespace internal | 5877 } // namespace internal |
| 5883 } // namespace v8 | 5878 } // namespace v8 |
| OLD | NEW |