| 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 4000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4011 BufferedRawMachineAssemblerTester<double> m(MachineType::Uint32()); | 4011 BufferedRawMachineAssemblerTester<double> m(MachineType::Uint32()); |
| 4012 m.Return(m.ChangeUint32ToFloat64(m.Parameter(0))); | 4012 m.Return(m.ChangeUint32ToFloat64(m.Parameter(0))); |
| 4013 | 4013 |
| 4014 FOR_UINT32_INPUTS(i) { CHECK_DOUBLE_EQ(static_cast<double>(*i), m.Call(*i)); } | 4014 FOR_UINT32_INPUTS(i) { CHECK_DOUBLE_EQ(static_cast<double>(*i), m.Call(*i)); } |
| 4015 } | 4015 } |
| 4016 | 4016 |
| 4017 | 4017 |
| 4018 TEST(RunTruncateFloat32ToInt32) { | 4018 TEST(RunTruncateFloat32ToInt32) { |
| 4019 BufferedRawMachineAssemblerTester<int32_t> m(MachineType::Float32()); | 4019 BufferedRawMachineAssemblerTester<int32_t> m(MachineType::Float32()); |
| 4020 m.Return(m.TruncateFloat32ToInt32(m.Parameter(0))); | 4020 m.Return(m.TruncateFloat32ToInt32(m.Parameter(0))); |
| 4021 // The upper bound is (INT32_MAX + 1), which is the lowest float-representable |
| 4022 // number above INT32_MAX which cannot be represented as int32. |
| 4023 float upper_bound = 2147483648.0f; |
| 4024 // We use INT32_MIN as a lower bound because (INT32_MIN - 1) is not |
| 4025 // representable as float, and no number between (INT32_MIN - 1) and INT32_MIN |
| 4026 // is. |
| 4027 float lower_bound = static_cast<float>(INT32_MIN); |
| 4021 FOR_FLOAT32_INPUTS(i) { | 4028 FOR_FLOAT32_INPUTS(i) { |
| 4022 if (*i <= static_cast<float>(std::numeric_limits<int32_t>::max()) && | 4029 if (*i < upper_bound && *i >= lower_bound) { |
| 4023 *i >= static_cast<float>(std::numeric_limits<int32_t>::min())) { | |
| 4024 CHECK_FLOAT_EQ(static_cast<int32_t>(*i), m.Call(*i)); | 4030 CHECK_FLOAT_EQ(static_cast<int32_t>(*i), m.Call(*i)); |
| 4025 } | 4031 } |
| 4026 } | 4032 } |
| 4027 } | 4033 } |
| 4028 | 4034 |
| 4029 | 4035 |
| 4030 TEST(RunTruncateFloat32ToUint32) { | 4036 TEST(RunTruncateFloat32ToUint32) { |
| 4031 BufferedRawMachineAssemblerTester<uint32_t> m(MachineType::Float32()); | 4037 BufferedRawMachineAssemblerTester<uint32_t> m(MachineType::Float32()); |
| 4032 m.Return(m.TruncateFloat32ToUint32(m.Parameter(0))); | 4038 m.Return(m.TruncateFloat32ToUint32(m.Parameter(0))); |
| 4033 { | 4039 // The upper bound is (UINT32_MAX + 1), which is the lowest |
| 4034 FOR_UINT32_INPUTS(i) { | 4040 // float-representable number above UINT32_MAX which cannot be represented as |
| 4035 volatile float input = static_cast<float>(*i); | 4041 // uint32. |
| 4036 // This condition on 'input' is required because | 4042 double upper_bound = 4294967296.0f; |
| 4037 // static_cast<float>(std::numeric_limits<uint32_t>::max()) results in a | 4043 double lower_bound = -1.0f; |
| 4038 // value outside uint32 range. | 4044 FOR_UINT32_INPUTS(i) { |
| 4039 if (input < static_cast<float>(std::numeric_limits<uint32_t>::max())) { | 4045 volatile float input = static_cast<float>(*i); |
| 4040 CHECK_EQ(static_cast<uint32_t>(input), m.Call(input)); | 4046 if (input < upper_bound) { |
| 4041 } | 4047 CHECK_EQ(static_cast<uint32_t>(input), m.Call(input)); |
| 4042 } | 4048 } |
| 4043 } | 4049 } |
| 4044 { | 4050 FOR_FLOAT32_INPUTS(j) { |
| 4045 FOR_FLOAT32_INPUTS(i) { | 4051 if ((*j < upper_bound) && (*j > lower_bound)) { |
| 4046 if (*i <= static_cast<float>(std::numeric_limits<uint32_t>::max()) && | 4052 CHECK_FLOAT_EQ(static_cast<uint32_t>(*j), m.Call(*j)); |
| 4047 *i >= static_cast<float>(std::numeric_limits<uint32_t>::min())) { | |
| 4048 CHECK_FLOAT_EQ(static_cast<uint32_t>(*i), m.Call(*i)); | |
| 4049 } | |
| 4050 } | 4053 } |
| 4051 } | 4054 } |
| 4052 } | 4055 } |
| 4053 | 4056 |
| 4054 | 4057 |
| 4055 TEST(RunChangeFloat64ToInt32_A) { | 4058 TEST(RunChangeFloat64ToInt32_A) { |
| 4056 BufferedRawMachineAssemblerTester<int32_t> m; | 4059 BufferedRawMachineAssemblerTester<int32_t> m; |
| 4057 double magic = 11.1; | 4060 double magic = 11.1; |
| 4058 m.Return(m.ChangeFloat64ToInt32(m.Float64Constant(magic))); | 4061 m.Return(m.ChangeFloat64ToInt32(m.Float64Constant(magic))); |
| 4059 CHECK_EQ(static_cast<int32_t>(magic), m.Call()); | 4062 CHECK_EQ(static_cast<int32_t>(magic), m.Call()); |
| (...skipping 2373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6433 r.Goto(&merge); | 6436 r.Goto(&merge); |
| 6434 r.Bind(&merge); | 6437 r.Bind(&merge); |
| 6435 Node* phi = r.Phi(MachineRepresentation::kWord32, fa, fb); | 6438 Node* phi = r.Phi(MachineRepresentation::kWord32, fa, fb); |
| 6436 r.Return(phi); | 6439 r.Return(phi); |
| 6437 CHECK_EQ(1, r.Call(1)); | 6440 CHECK_EQ(1, r.Call(1)); |
| 6438 } | 6441 } |
| 6439 | 6442 |
| 6440 } // namespace compiler | 6443 } // namespace compiler |
| 6441 } // namespace internal | 6444 } // namespace internal |
| 6442 } // namespace v8 | 6445 } // namespace v8 |
| OLD | NEW |