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 <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 5052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5063 -two_52 + 1, | 5063 -two_52 + 1, |
5064 -two_52 + 1 - 0.1, | 5064 -two_52 + 1 - 0.1, |
5065 -two_52 + 1 - 0.5, | 5065 -two_52 + 1 - 0.5, |
5066 -two_52 + 1 - 0.7}; | 5066 -two_52 + 1 - 0.7}; |
5067 | 5067 |
5068 | 5068 |
5069 TEST(RunFloat64RoundDown1) { | 5069 TEST(RunFloat64RoundDown1) { |
5070 double input = -1.0; | 5070 double input = -1.0; |
5071 double result = 0.0; | 5071 double result = 0.0; |
5072 RawMachineAssemblerTester<int32_t> m; | 5072 RawMachineAssemblerTester<int32_t> m; |
5073 if (!m.machine()->HasFloat64RoundDown()) return; | 5073 if (!m.machine()->Float64RoundDown().IsSupported()) return; |
5074 m.StoreToPointer(&result, kMachFloat64, | 5074 m.StoreToPointer(&result, kMachFloat64, |
5075 m.Float64RoundDown(m.LoadFromPointer(&input, kMachFloat64))); | 5075 m.Float64RoundDown(m.LoadFromPointer(&input, kMachFloat64))); |
5076 m.Return(m.Int32Constant(0)); | 5076 m.Return(m.Int32Constant(0)); |
5077 for (size_t i = 0; i < arraysize(kValues); ++i) { | 5077 for (size_t i = 0; i < arraysize(kValues); ++i) { |
5078 input = kValues[i]; | 5078 input = kValues[i]; |
5079 CHECK_EQ(0, m.Call()); | 5079 CHECK_EQ(0, m.Call()); |
5080 double expected = std::floor(kValues[i]); | 5080 double expected = std::floor(kValues[i]); |
5081 CHECK_EQ(expected, result); | 5081 CHECK_EQ(expected, result); |
5082 } | 5082 } |
5083 } | 5083 } |
5084 | 5084 |
5085 | 5085 |
5086 TEST(RunFloat64RoundDown2) { | 5086 TEST(RunFloat64RoundDown2) { |
5087 double input = -1.0; | 5087 double input = -1.0; |
5088 double result = 0.0; | 5088 double result = 0.0; |
5089 RawMachineAssemblerTester<int32_t> m; | 5089 RawMachineAssemblerTester<int32_t> m; |
5090 if (!m.machine()->HasFloat64RoundDown()) return; | 5090 if (!m.machine()->Float64RoundDown().IsSupported()) return; |
5091 m.StoreToPointer(&result, kMachFloat64, | 5091 m.StoreToPointer(&result, kMachFloat64, |
5092 m.Float64Sub(m.Float64Constant(-0.0), | 5092 m.Float64Sub(m.Float64Constant(-0.0), |
5093 m.Float64RoundDown(m.Float64Sub( | 5093 m.Float64RoundDown(m.Float64Sub( |
5094 m.Float64Constant(-0.0), | 5094 m.Float64Constant(-0.0), |
5095 m.LoadFromPointer(&input, kMachFloat64))))); | 5095 m.LoadFromPointer(&input, kMachFloat64))))); |
5096 m.Return(m.Int32Constant(0)); | 5096 m.Return(m.Int32Constant(0)); |
5097 for (size_t i = 0; i < arraysize(kValues); ++i) { | 5097 for (size_t i = 0; i < arraysize(kValues); ++i) { |
5098 input = kValues[i]; | 5098 input = kValues[i]; |
5099 CHECK_EQ(0, m.Call()); | 5099 CHECK_EQ(0, m.Call()); |
5100 double expected = std::ceil(kValues[i]); | 5100 double expected = std::ceil(kValues[i]); |
5101 CHECK_EQ(expected, result); | 5101 CHECK_EQ(expected, result); |
5102 } | 5102 } |
5103 } | 5103 } |
5104 | 5104 |
5105 | 5105 |
5106 TEST(RunFloat64RoundTruncate) { | 5106 TEST(RunFloat64RoundTruncate) { |
5107 double input = -1.0; | 5107 double input = -1.0; |
5108 double result = 0.0; | 5108 double result = 0.0; |
5109 RawMachineAssemblerTester<int32_t> m; | 5109 RawMachineAssemblerTester<int32_t> m; |
5110 if (!m.machine()->HasFloat64RoundTruncate()) return; | 5110 if (!m.machine()->Float64RoundTruncate().IsSupported()) return; |
5111 m.StoreToPointer( | 5111 m.StoreToPointer( |
5112 &result, kMachFloat64, | 5112 &result, kMachFloat64, |
5113 m.Float64RoundTruncate(m.LoadFromPointer(&input, kMachFloat64))); | 5113 m.Float64RoundTruncate(m.LoadFromPointer(&input, kMachFloat64))); |
5114 m.Return(m.Int32Constant(0)); | 5114 m.Return(m.Int32Constant(0)); |
5115 for (size_t i = 0; i < arraysize(kValues); ++i) { | 5115 for (size_t i = 0; i < arraysize(kValues); ++i) { |
5116 input = kValues[i]; | 5116 input = kValues[i]; |
5117 CHECK_EQ(0, m.Call()); | 5117 CHECK_EQ(0, m.Call()); |
5118 double expected = trunc(kValues[i]); | 5118 double expected = trunc(kValues[i]); |
5119 CHECK_EQ(expected, result); | 5119 CHECK_EQ(expected, result); |
5120 } | 5120 } |
5121 } | 5121 } |
5122 | 5122 |
5123 | 5123 |
5124 TEST(RunFloat64RoundTiesAway) { | 5124 TEST(RunFloat64RoundTiesAway) { |
5125 double input = -1.0; | 5125 double input = -1.0; |
5126 double result = 0.0; | 5126 double result = 0.0; |
5127 RawMachineAssemblerTester<int32_t> m; | 5127 RawMachineAssemblerTester<int32_t> m; |
5128 if (!m.machine()->HasFloat64RoundTiesAway()) return; | 5128 if (!m.machine()->Float64RoundTiesAway().IsSupported()) return; |
5129 m.StoreToPointer( | 5129 m.StoreToPointer( |
5130 &result, kMachFloat64, | 5130 &result, kMachFloat64, |
5131 m.Float64RoundTiesAway(m.LoadFromPointer(&input, kMachFloat64))); | 5131 m.Float64RoundTiesAway(m.LoadFromPointer(&input, kMachFloat64))); |
5132 m.Return(m.Int32Constant(0)); | 5132 m.Return(m.Int32Constant(0)); |
5133 for (size_t i = 0; i < arraysize(kValues); ++i) { | 5133 for (size_t i = 0; i < arraysize(kValues); ++i) { |
5134 input = kValues[i]; | 5134 input = kValues[i]; |
5135 CHECK_EQ(0, m.Call()); | 5135 CHECK_EQ(0, m.Call()); |
5136 double expected = round(kValues[i]); | 5136 double expected = round(kValues[i]); |
5137 CHECK_EQ(expected, result); | 5137 CHECK_EQ(expected, result); |
5138 } | 5138 } |
5139 } | 5139 } |
5140 | 5140 |
5141 #endif // V8_TURBOFAN_TARGET | 5141 #endif // V8_TURBOFAN_TARGET |
OLD | NEW |