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>(UINT32_MAX) results in a value outside uint32 range. | |
4147 if (input < static_cast<float>(UINT32_MAX)) { | |
4148 CHECK_EQ(static_cast<uint32_t>(input), m.Call(input)); | |
4149 } | |
4150 } | |
4151 } | |
4152 { | |
4153 FOR_FLOAT32_INPUTS(i) { | |
4154 if (*i <= static_cast<float>(std::numeric_limits<uint32_t>::max()) && | |
ahaas
2016/02/03 13:47:02
Nit: I think you should use either UINT32_MAX or s
| |
4155 *i >= static_cast<float>(std::numeric_limits<uint32_t>::min())) { | |
4156 CheckFloatEq(static_cast<uint32_t>(*i), m.Call(*i)); | |
4157 } | |
4158 } | |
4159 } | |
4160 } | |
4161 | |
4162 | |
4139 TEST(RunChangeFloat64ToInt32_A) { | 4163 TEST(RunChangeFloat64ToInt32_A) { |
4140 BufferedRawMachineAssemblerTester<int32_t> m; | 4164 BufferedRawMachineAssemblerTester<int32_t> m; |
4141 double magic = 11.1; | 4165 double magic = 11.1; |
4142 m.Return(m.ChangeFloat64ToInt32(m.Float64Constant(magic))); | 4166 m.Return(m.ChangeFloat64ToInt32(m.Float64Constant(magic))); |
4143 CHECK_EQ(static_cast<int32_t>(magic), m.Call()); | 4167 CHECK_EQ(static_cast<int32_t>(magic), m.Call()); |
4144 } | 4168 } |
4145 | 4169 |
4146 | 4170 |
4147 TEST(RunChangeFloat64ToInt32_B) { | 4171 TEST(RunChangeFloat64ToInt32_B) { |
4148 BufferedRawMachineAssemblerTester<int32_t> m(MachineType::Float64()); | 4172 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); | 6107 Node* call = r.AddNode(r.common()->Call(desc), phi); |
6084 r.Return(call); | 6108 r.Return(call); |
6085 | 6109 |
6086 CHECK_EQ(33, r.Call(1)); | 6110 CHECK_EQ(33, r.Call(1)); |
6087 CHECK_EQ(44, r.Call(0)); | 6111 CHECK_EQ(44, r.Call(0)); |
6088 } | 6112 } |
6089 | 6113 |
6090 } // namespace compiler | 6114 } // namespace compiler |
6091 } // namespace internal | 6115 } // namespace internal |
6092 } // namespace v8 | 6116 } // namespace v8 |
OLD | NEW |