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 4118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4129 m.Return(m.TruncateFloat32ToInt32(m.Parameter(0))); | 4129 m.Return(m.TruncateFloat32ToInt32(m.Parameter(0))); |
4130 FOR_FLOAT32_INPUTS(i) { | 4130 FOR_FLOAT32_INPUTS(i) { |
4131 if (*i <= static_cast<float>(std::numeric_limits<int32_t>::max()) && | 4131 if (*i <= static_cast<float>(std::numeric_limits<int32_t>::max()) && |
4132 *i >= static_cast<float>(std::numeric_limits<int32_t>::min())) { | 4132 *i >= static_cast<float>(std::numeric_limits<int32_t>::min())) { |
4133 CheckFloatEq(static_cast<int32_t>(*i), m.Call(*i)); | 4133 CheckFloatEq(static_cast<int32_t>(*i), m.Call(*i)); |
4134 } | 4134 } |
4135 } | 4135 } |
4136 } | 4136 } |
4137 | 4137 |
4138 | 4138 |
| 4139 TEST(RunTruncateFloat32ToUint32) { |
| 4140 BufferedRawMachineAssemblerTester<uint32_t> m(MachineType::Float32()); |
| 4141 m.Return(m.TruncateFloat32ToUint32(m.Parameter(0))); |
| 4142 { |
| 4143 FOR_UINT32_INPUTS(i) { |
| 4144 float input = static_cast<float>(*i); |
| 4145 // This condition on 'input' is required because |
| 4146 // static_cast<float>(std::numeric_limits<uint32_t>::max()) results in a |
| 4147 // value outside uint32 range. |
| 4148 if (input < static_cast<float>(std::numeric_limits<uint32_t>::max())) { |
| 4149 CHECK_EQ(static_cast<uint32_t>(input), m.Call(input)); |
| 4150 } |
| 4151 } |
| 4152 } |
| 4153 { |
| 4154 FOR_FLOAT32_INPUTS(i) { |
| 4155 if (*i <= static_cast<float>(std::numeric_limits<uint32_t>::max()) && |
| 4156 *i >= static_cast<float>(std::numeric_limits<uint32_t>::min())) { |
| 4157 CheckFloatEq(static_cast<uint32_t>(*i), m.Call(*i)); |
| 4158 } |
| 4159 } |
| 4160 } |
| 4161 } |
| 4162 |
| 4163 |
4139 TEST(RunChangeFloat64ToInt32_A) { | 4164 TEST(RunChangeFloat64ToInt32_A) { |
4140 BufferedRawMachineAssemblerTester<int32_t> m; | 4165 BufferedRawMachineAssemblerTester<int32_t> m; |
4141 double magic = 11.1; | 4166 double magic = 11.1; |
4142 m.Return(m.ChangeFloat64ToInt32(m.Float64Constant(magic))); | 4167 m.Return(m.ChangeFloat64ToInt32(m.Float64Constant(magic))); |
4143 CHECK_EQ(static_cast<int32_t>(magic), m.Call()); | 4168 CHECK_EQ(static_cast<int32_t>(magic), m.Call()); |
4144 } | 4169 } |
4145 | 4170 |
4146 | 4171 |
4147 TEST(RunChangeFloat64ToInt32_B) { | 4172 TEST(RunChangeFloat64ToInt32_B) { |
4148 BufferedRawMachineAssemblerTester<int32_t> m(MachineType::Float64()); | 4173 BufferedRawMachineAssemblerTester<int32_t> m(MachineType::Float64()); |
(...skipping 1934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6083 Node* call = r.AddNode(r.common()->Call(desc), phi); | 6108 Node* call = r.AddNode(r.common()->Call(desc), phi); |
6084 r.Return(call); | 6109 r.Return(call); |
6085 | 6110 |
6086 CHECK_EQ(33, r.Call(1)); | 6111 CHECK_EQ(33, r.Call(1)); |
6087 CHECK_EQ(44, r.Call(0)); | 6112 CHECK_EQ(44, r.Call(0)); |
6088 } | 6113 } |
6089 | 6114 |
6090 } // namespace compiler | 6115 } // namespace compiler |
6091 } // namespace internal | 6116 } // namespace internal |
6092 } // namespace v8 | 6117 } // namespace v8 |
OLD | NEW |