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 5511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5522 CHECK_EQ(static_cast<int64_t>(*i), m.Call(*i)); | 5522 CHECK_EQ(static_cast<int64_t>(*i), m.Call(*i)); |
5523 CHECK_NE(0, success); | 5523 CHECK_NE(0, success); |
5524 } else { | 5524 } else { |
5525 m.Call(*i); | 5525 m.Call(*i); |
5526 CHECK_EQ(0, success); | 5526 CHECK_EQ(0, success); |
5527 } | 5527 } |
5528 } | 5528 } |
5529 } | 5529 } |
5530 | 5530 |
5531 | 5531 |
5532 TEST(RunTruncateFloat32ToUint64) { | 5532 TEST(RunTryTruncateFloat32ToUint64WithoutCheck) { |
5533 BufferedRawMachineAssemblerTester<uint64_t> m(MachineType::Float32()); | 5533 BufferedRawMachineAssemblerTester<uint64_t> m(MachineType::Float32()); |
5534 m.Return(m.TryTruncateFloat32ToUint64(m.Parameter(0))); | 5534 m.Return(m.TryTruncateFloat32ToUint64(m.Parameter(0))); |
5535 | 5535 |
5536 FOR_UINT64_INPUTS(i) { | 5536 FOR_UINT64_INPUTS(i) { |
5537 float input = static_cast<float>(*i); | 5537 float input = static_cast<float>(*i); |
5538 if (input < 18446744073709551616.0) { | 5538 // This condition on 'input' is required because |
| 5539 // static_cast<float>(UINT64_MAX) results in a value outside uint64 range. |
| 5540 if (input < static_cast<float>(UINT64_MAX)) { |
5539 CHECK_EQ(static_cast<uint64_t>(input), m.Call(input)); | 5541 CHECK_EQ(static_cast<uint64_t>(input), m.Call(input)); |
5540 } | 5542 } |
5541 } | 5543 } |
5542 FOR_FLOAT32_INPUTS(j) { | |
5543 if (*j < 18446744073709551616.0 && *j >= 0) { | |
5544 CHECK_EQ(static_cast<uint64_t>(*j), m.Call(*j)); | |
5545 } | |
5546 } | |
5547 } | 5544 } |
5548 | 5545 |
5549 | 5546 |
5550 TEST(RunTryTruncateFloat32ToUint64WithCheck) { | 5547 TEST(RunTryTruncateFloat32ToUint64WithCheck) { |
5551 int64_t success = 0; | 5548 int64_t success = 0; |
5552 BufferedRawMachineAssemblerTester<uint64_t> m(MachineType::Float32()); | 5549 BufferedRawMachineAssemblerTester<uint64_t> m(MachineType::Float32()); |
5553 Node* trunc = m.TryTruncateFloat32ToUint64(m.Parameter(0)); | 5550 Node* trunc = m.TryTruncateFloat32ToUint64(m.Parameter(0)); |
5554 Node* val = m.Projection(0, trunc); | 5551 Node* val = m.Projection(0, trunc); |
5555 Node* check = m.Projection(1, trunc); | 5552 Node* check = m.Projection(1, trunc); |
5556 m.StoreToPointer(&success, MachineRepresentation::kWord64, check); | 5553 m.StoreToPointer(&success, MachineRepresentation::kWord64, check); |
5557 m.Return(val); | 5554 m.Return(val); |
5558 | 5555 |
5559 FOR_FLOAT32_INPUTS(i) { | 5556 FOR_FLOAT32_INPUTS(i) { |
5560 if (*i < 18446744073709551616.0 && *i >= 0.0) { | 5557 if (*i < static_cast<float>(UINT64_MAX) && *i > -1.0) { |
5561 // Conversions within this range should succeed. | 5558 // Conversions within this range should succeed. |
5562 CHECK_EQ(static_cast<uint64_t>(*i), m.Call(*i)); | 5559 CHECK_EQ(static_cast<uint64_t>(*i), m.Call(*i)); |
5563 CHECK_NE(0, success); | 5560 CHECK_NE(0, success); |
5564 } else { | 5561 } else { |
5565 m.Call(*i); | 5562 m.Call(*i); |
5566 CHECK_EQ(0, success); | 5563 CHECK_EQ(0, success); |
5567 } | 5564 } |
5568 } | 5565 } |
5569 } | 5566 } |
5570 | 5567 |
5571 | 5568 |
5572 TEST(RunTryTruncateFloat64ToUint64WithoutCheck) { | 5569 TEST(RunTryTruncateFloat64ToUint64WithoutCheck) { |
5573 BufferedRawMachineAssemblerTester<uint64_t> m(MachineType::Float64()); | 5570 BufferedRawMachineAssemblerTester<uint64_t> m(MachineType::Float64()); |
5574 m.Return(m.TruncateFloat64ToUint64(m.Parameter(0))); | 5571 m.Return(m.TruncateFloat64ToUint64(m.Parameter(0))); |
5575 | 5572 |
5576 FOR_UINT64_INPUTS(j) { | 5573 FOR_UINT64_INPUTS(j) { |
5577 double input = static_cast<double>(*j); | 5574 double input = static_cast<double>(*j); |
5578 | 5575 |
5579 if (input < 18446744073709551616.0) { | 5576 if (input < static_cast<float>(UINT64_MAX)) { |
5580 CHECK_EQ(static_cast<uint64_t>(input), m.Call(input)); | 5577 CHECK_EQ(static_cast<uint64_t>(input), m.Call(input)); |
5581 } | 5578 } |
5582 } | 5579 } |
5583 } | 5580 } |
5584 | 5581 |
5585 | 5582 |
5586 TEST(RunTryTruncateFloat64ToUint64WithCheck) { | 5583 TEST(RunTryTruncateFloat64ToUint64WithCheck) { |
5587 int64_t success = 0; | 5584 int64_t success = 0; |
5588 BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Float64()); | 5585 BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Float64()); |
5589 Node* trunc = m.TryTruncateFloat64ToUint64(m.Parameter(0)); | 5586 Node* trunc = m.TryTruncateFloat64ToUint64(m.Parameter(0)); |
5590 Node* val = m.Projection(0, trunc); | 5587 Node* val = m.Projection(0, trunc); |
5591 Node* check = m.Projection(1, trunc); | 5588 Node* check = m.Projection(1, trunc); |
5592 m.StoreToPointer(&success, MachineRepresentation::kWord64, check); | 5589 m.StoreToPointer(&success, MachineRepresentation::kWord64, check); |
5593 m.Return(val); | 5590 m.Return(val); |
5594 | 5591 |
5595 FOR_FLOAT64_INPUTS(i) { | 5592 FOR_FLOAT64_INPUTS(i) { |
5596 if (*i < 18446744073709551616.0 && *i >= 0) { | 5593 if (*i < 18446744073709551616.0 && *i > -1) { |
5597 // Conversions within this range should succeed. | 5594 // Conversions within this range should succeed. |
5598 CHECK_EQ(static_cast<uint64_t>(*i), m.Call(*i)); | 5595 CHECK_EQ(static_cast<uint64_t>(*i), m.Call(*i)); |
5599 CHECK_NE(0, success); | 5596 CHECK_NE(0, success); |
5600 } else { | 5597 } else { |
5601 m.Call(*i); | 5598 m.Call(*i); |
5602 CHECK_EQ(0, success); | 5599 CHECK_EQ(0, success); |
5603 } | 5600 } |
5604 } | 5601 } |
5605 } | 5602 } |
5606 | 5603 |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5877 Node* call = r.AddNode(r.common()->Call(desc), phi); | 5874 Node* call = r.AddNode(r.common()->Call(desc), phi); |
5878 r.Return(call); | 5875 r.Return(call); |
5879 | 5876 |
5880 CHECK_EQ(33, r.Call(1)); | 5877 CHECK_EQ(33, r.Call(1)); |
5881 CHECK_EQ(44, r.Call(0)); | 5878 CHECK_EQ(44, r.Call(0)); |
5882 } | 5879 } |
5883 | 5880 |
5884 } // namespace compiler | 5881 } // namespace compiler |
5885 } // namespace internal | 5882 } // namespace internal |
5886 } // namespace v8 | 5883 } // namespace v8 |
OLD | NEW |