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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "test/cctest/cctest.h" | 7 #include "test/cctest/cctest.h" |
8 #include "test/cctest/compiler/codegen-tester.h" | 8 #include "test/cctest/compiler/codegen-tester.h" |
9 #include "test/cctest/compiler/graph-builder-tester.h" | 9 #include "test/cctest/compiler/graph-builder-tester.h" |
10 #include "test/cctest/compiler/value-helper.h" | 10 #include "test/cctest/compiler/value-helper.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 r.CheckInt32Constant(true_bit, 1); | 130 r.CheckInt32Constant(true_bit, 1); |
131 | 131 |
132 Node* false_node = r.jsgraph()->FalseConstant(); | 132 Node* false_node = r.jsgraph()->FalseConstant(); |
133 Node* false_use = r.Return(false_node); | 133 Node* false_use = r.Return(false_node); |
134 Node* false_bit = r.changer()->GetRepresentationFor( | 134 Node* false_bit = r.changer()->GetRepresentationFor( |
135 false_node, MachineRepresentation::kTagged, Type::None(), false_use, | 135 false_node, MachineRepresentation::kTagged, Type::None(), false_use, |
136 UseInfo(MachineRepresentation::kBit, Truncation::None())); | 136 UseInfo(MachineRepresentation::kBit, Truncation::None())); |
137 r.CheckInt32Constant(false_bit, 0); | 137 r.CheckInt32Constant(false_bit, 0); |
138 } | 138 } |
139 | 139 |
140 | |
141 TEST(BitToBool_constant) { | |
142 RepresentationChangerTester r; | |
143 | |
144 for (int i = -5; i < 5; i++) { | |
145 Node* node = r.jsgraph()->Int32Constant(i); | |
146 Node* use = r.Return(node); | |
147 Node* val = r.changer()->GetRepresentationFor( | |
148 node, MachineRepresentation::kBit, Type::Boolean(), use, | |
149 UseInfo(MachineRepresentation::kTagged, Truncation::None())); | |
150 r.CheckHeapConstant(val, i == 0 ? r.isolate()->heap()->false_value() | |
151 : r.isolate()->heap()->true_value()); | |
152 } | |
153 } | |
154 | |
155 | |
156 TEST(ToTagged_constant) { | 140 TEST(ToTagged_constant) { |
157 RepresentationChangerTester r; | 141 RepresentationChangerTester r; |
158 | 142 |
159 { | 143 for (double i : ValueHelper::float64_vector()) { |
160 FOR_FLOAT64_INPUTS(i) { | 144 Node* n = r.jsgraph()->Constant(i); |
161 Node* n = r.jsgraph()->Float64Constant(*i); | 145 Node* use = r.Return(n); |
162 Node* use = r.Return(n); | 146 Node* c = r.changer()->GetRepresentationFor( |
163 Node* c = r.changer()->GetRepresentationFor( | 147 n, MachineRepresentation::kFloat64, Type::None(), use, |
164 n, MachineRepresentation::kFloat64, Type::None(), use, | 148 UseInfo(MachineRepresentation::kTagged, Truncation::None())); |
165 UseInfo(MachineRepresentation::kTagged, Truncation::None())); | 149 r.CheckNumberConstant(c, i); |
166 r.CheckNumberConstant(c, *i); | |
167 } | |
168 } | 150 } |
169 | 151 |
170 { | 152 for (int i : ValueHelper::int32_vector()) { |
171 FOR_FLOAT64_INPUTS(i) { | 153 Node* n = r.jsgraph()->Constant(i); |
172 Node* n = r.jsgraph()->Constant(*i); | 154 Node* use = r.Return(n); |
173 Node* use = r.Return(n); | 155 Node* c = r.changer()->GetRepresentationFor( |
174 Node* c = r.changer()->GetRepresentationFor( | 156 n, MachineRepresentation::kWord32, Type::Signed32(), use, |
175 n, MachineRepresentation::kFloat64, Type::None(), use, | 157 UseInfo(MachineRepresentation::kTagged, Truncation::None())); |
176 UseInfo(MachineRepresentation::kTagged, Truncation::None())); | 158 r.CheckNumberConstant(c, i); |
177 r.CheckNumberConstant(c, *i); | |
178 } | |
179 } | 159 } |
180 | 160 |
181 { | 161 for (uint32_t i : ValueHelper::uint32_vector()) { |
182 FOR_FLOAT32_INPUTS(i) { | 162 Node* n = r.jsgraph()->Constant(i); |
183 Node* n = r.jsgraph()->Float32Constant(*i); | 163 Node* use = r.Return(n); |
184 Node* use = r.Return(n); | 164 Node* c = r.changer()->GetRepresentationFor( |
185 Node* c = r.changer()->GetRepresentationFor( | 165 n, MachineRepresentation::kWord32, Type::Unsigned32(), use, |
186 n, MachineRepresentation::kFloat32, Type::None(), use, | 166 UseInfo(MachineRepresentation::kTagged, Truncation::None())); |
187 UseInfo(MachineRepresentation::kTagged, Truncation::None())); | 167 r.CheckNumberConstant(c, i); |
188 r.CheckNumberConstant(c, *i); | |
189 } | |
190 } | |
191 | |
192 { | |
193 FOR_INT32_INPUTS(i) { | |
194 Node* n = r.jsgraph()->Int32Constant(*i); | |
195 Node* use = r.Return(n); | |
196 Node* c = r.changer()->GetRepresentationFor( | |
197 n, MachineRepresentation::kWord32, Type::Signed32(), use, | |
198 UseInfo(MachineRepresentation::kTagged, Truncation::None())); | |
199 r.CheckNumberConstant(c, *i); | |
200 } | |
201 } | |
202 | |
203 { | |
204 FOR_UINT32_INPUTS(i) { | |
205 Node* n = r.jsgraph()->Int32Constant(*i); | |
206 Node* use = r.Return(n); | |
207 Node* c = r.changer()->GetRepresentationFor( | |
208 n, MachineRepresentation::kWord32, Type::Unsigned32(), use, | |
209 UseInfo(MachineRepresentation::kTagged, Truncation::None())); | |
210 r.CheckNumberConstant(c, *i); | |
211 } | |
212 } | 168 } |
213 } | 169 } |
214 | 170 |
215 | |
216 TEST(ToFloat64_constant) { | 171 TEST(ToFloat64_constant) { |
217 RepresentationChangerTester r; | 172 RepresentationChangerTester r; |
218 | 173 |
219 { | 174 for (double i : ValueHelper::float64_vector()) { |
220 FOR_FLOAT64_INPUTS(i) { | 175 Node* n = r.jsgraph()->Constant(i); |
221 Node* n = r.jsgraph()->Float64Constant(*i); | 176 Node* use = r.Return(n); |
222 Node* use = r.Return(n); | 177 Node* c = r.changer()->GetRepresentationFor( |
223 Node* c = r.changer()->GetRepresentationFor( | 178 n, MachineRepresentation::kTagged, Type::None(), use, |
224 n, MachineRepresentation::kFloat64, Type::None(), use, | 179 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); |
225 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); | 180 r.CheckFloat64Constant(c, i); |
226 CHECK_EQ(n, c); | |
227 } | |
228 } | 181 } |
229 | 182 |
230 { | 183 for (int i : ValueHelper::int32_vector()) { |
231 FOR_FLOAT64_INPUTS(i) { | 184 Node* n = r.jsgraph()->Constant(i); |
232 Node* n = r.jsgraph()->Constant(*i); | 185 Node* use = r.Return(n); |
233 Node* use = r.Return(n); | 186 Node* c = r.changer()->GetRepresentationFor( |
234 Node* c = r.changer()->GetRepresentationFor( | 187 n, MachineRepresentation::kWord32, Type::Signed32(), use, |
235 n, MachineRepresentation::kTagged, Type::None(), use, | 188 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); |
236 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); | 189 r.CheckFloat64Constant(c, i); |
237 r.CheckFloat64Constant(c, *i); | |
238 } | |
239 } | 190 } |
240 | 191 |
241 { | 192 for (uint32_t i : ValueHelper::uint32_vector()) { |
242 FOR_FLOAT32_INPUTS(i) { | 193 Node* n = r.jsgraph()->Constant(i); |
243 Node* n = r.jsgraph()->Float32Constant(*i); | 194 Node* use = r.Return(n); |
244 Node* use = r.Return(n); | 195 Node* c = r.changer()->GetRepresentationFor( |
245 Node* c = r.changer()->GetRepresentationFor( | 196 n, MachineRepresentation::kWord32, Type::Unsigned32(), use, |
246 n, MachineRepresentation::kFloat32, Type::None(), use, | 197 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); |
247 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); | 198 r.CheckFloat64Constant(c, i); |
248 r.CheckFloat64Constant(c, *i); | |
249 } | |
250 } | |
251 | |
252 { | |
253 FOR_INT32_INPUTS(i) { | |
254 Node* n = r.jsgraph()->Int32Constant(*i); | |
255 Node* use = r.Return(n); | |
256 Node* c = r.changer()->GetRepresentationFor( | |
257 n, MachineRepresentation::kWord32, Type::Signed32(), use, | |
258 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); | |
259 r.CheckFloat64Constant(c, *i); | |
260 } | |
261 } | |
262 | |
263 { | |
264 FOR_UINT32_INPUTS(i) { | |
265 Node* n = r.jsgraph()->Int32Constant(*i); | |
266 Node* use = r.Return(n); | |
267 Node* c = r.changer()->GetRepresentationFor( | |
268 n, MachineRepresentation::kWord32, Type::Unsigned32(), use, | |
269 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); | |
270 r.CheckFloat64Constant(c, *i); | |
271 } | |
272 } | 199 } |
273 } | 200 } |
274 | 201 |
275 | 202 |
276 static bool IsFloat32Int32(int32_t val) { | 203 static bool IsFloat32Int32(int32_t val) { |
277 return val >= -(1 << 23) && val <= (1 << 23); | 204 return val >= -(1 << 23) && val <= (1 << 23); |
278 } | 205 } |
279 | 206 |
280 | 207 |
281 static bool IsFloat32Uint32(uint32_t val) { return val <= (1 << 23); } | 208 static bool IsFloat32Uint32(uint32_t val) { return val <= (1 << 23); } |
282 | 209 |
283 | 210 |
284 TEST(ToFloat32_constant) { | 211 TEST(ToFloat32_constant) { |
285 RepresentationChangerTester r; | 212 RepresentationChangerTester r; |
286 | 213 |
287 { | 214 for (double i : ValueHelper::float32_vector()) { |
288 FOR_FLOAT32_INPUTS(i) { | 215 Node* n = r.jsgraph()->Constant(i); |
289 Node* n = r.jsgraph()->Float32Constant(*i); | 216 Node* use = r.Return(n); |
290 Node* use = r.Return(n); | 217 Node* c = r.changer()->GetRepresentationFor( |
291 Node* c = r.changer()->GetRepresentationFor( | 218 n, MachineRepresentation::kTagged, Type::None(), use, |
292 n, MachineRepresentation::kFloat32, Type::None(), use, | 219 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); |
293 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); | 220 r.CheckFloat32Constant(c, i); |
294 CHECK_EQ(n, c); | |
295 } | |
296 } | 221 } |
297 | 222 |
298 { | 223 for (int i : ValueHelper::int32_vector()) { |
299 FOR_FLOAT32_INPUTS(i) { | 224 if (!IsFloat32Int32(i)) continue; |
300 Node* n = r.jsgraph()->Constant(*i); | 225 Node* n = r.jsgraph()->Constant(i); |
301 Node* use = r.Return(n); | 226 Node* use = r.Return(n); |
302 Node* c = r.changer()->GetRepresentationFor( | 227 Node* c = r.changer()->GetRepresentationFor( |
303 n, MachineRepresentation::kTagged, Type::None(), use, | 228 n, MachineRepresentation::kWord32, Type::Signed32(), use, |
304 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); | 229 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); |
305 r.CheckFloat32Constant(c, *i); | 230 r.CheckFloat32Constant(c, static_cast<float>(i)); |
306 } | |
307 } | 231 } |
308 | 232 |
309 { | 233 for (uint32_t i : ValueHelper::uint32_vector()) { |
310 FOR_FLOAT32_INPUTS(i) { | 234 if (!IsFloat32Uint32(i)) continue; |
311 Node* n = r.jsgraph()->Float64Constant(*i); | 235 Node* n = r.jsgraph()->Constant(i); |
312 Node* use = r.Return(n); | 236 Node* use = r.Return(n); |
313 Node* c = r.changer()->GetRepresentationFor( | 237 Node* c = r.changer()->GetRepresentationFor( |
314 n, MachineRepresentation::kFloat64, Type::None(), use, | 238 n, MachineRepresentation::kWord32, Type::Unsigned32(), use, |
315 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); | 239 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); |
316 r.CheckFloat32Constant(c, *i); | 240 r.CheckFloat32Constant(c, static_cast<float>(i)); |
317 } | |
318 } | |
319 | |
320 { | |
321 FOR_INT32_INPUTS(i) { | |
322 if (!IsFloat32Int32(*i)) continue; | |
323 Node* n = r.jsgraph()->Int32Constant(*i); | |
324 Node* use = r.Return(n); | |
325 Node* c = r.changer()->GetRepresentationFor( | |
326 n, MachineRepresentation::kWord32, Type::Signed32(), use, | |
327 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); | |
328 r.CheckFloat32Constant(c, static_cast<float>(*i)); | |
329 } | |
330 } | |
331 | |
332 { | |
333 FOR_UINT32_INPUTS(i) { | |
334 if (!IsFloat32Uint32(*i)) continue; | |
335 Node* n = r.jsgraph()->Int32Constant(*i); | |
336 Node* use = r.Return(n); | |
337 Node* c = r.changer()->GetRepresentationFor( | |
338 n, MachineRepresentation::kWord32, Type::Unsigned32(), use, | |
339 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); | |
340 r.CheckFloat32Constant(c, static_cast<float>(*i)); | |
341 } | |
342 } | 241 } |
343 } | 242 } |
344 | 243 |
345 | |
346 TEST(ToInt32_constant) { | 244 TEST(ToInt32_constant) { |
347 RepresentationChangerTester r; | 245 RepresentationChangerTester r; |
348 | |
349 { | |
350 FOR_INT32_INPUTS(i) { | |
351 Node* n = r.jsgraph()->Int32Constant(*i); | |
352 Node* use = r.Return(n); | |
353 Node* c = r.changer()->GetRepresentationFor( | |
354 n, MachineRepresentation::kWord32, Type::Signed32(), use, | |
355 UseInfo(MachineRepresentation::kWord32, Truncation::None())); | |
356 r.CheckInt32Constant(c, *i); | |
357 } | |
358 } | |
359 | |
360 { | |
361 FOR_INT32_INPUTS(i) { | |
362 if (!IsFloat32Int32(*i)) continue; | |
363 Node* n = r.jsgraph()->Float32Constant(static_cast<float>(*i)); | |
364 Node* use = r.Return(n); | |
365 Node* c = r.changer()->GetRepresentationFor( | |
366 n, MachineRepresentation::kFloat32, Type::Signed32(), use, | |
367 UseInfo(MachineRepresentation::kWord32, Truncation::None())); | |
368 r.CheckInt32Constant(c, *i); | |
369 } | |
370 } | |
371 | |
372 { | |
373 FOR_INT32_INPUTS(i) { | |
374 Node* n = r.jsgraph()->Float64Constant(*i); | |
375 Node* use = r.Return(n); | |
376 Node* c = r.changer()->GetRepresentationFor( | |
377 n, MachineRepresentation::kFloat64, Type::Signed32(), use, | |
378 UseInfo(MachineRepresentation::kWord32, Truncation::None())); | |
379 r.CheckInt32Constant(c, *i); | |
380 } | |
381 } | |
382 | |
383 { | 246 { |
384 FOR_INT32_INPUTS(i) { | 247 FOR_INT32_INPUTS(i) { |
385 Node* n = r.jsgraph()->Constant(*i); | 248 Node* n = r.jsgraph()->Constant(*i); |
386 Node* use = r.Return(n); | 249 Node* use = r.Return(n); |
387 Node* c = r.changer()->GetRepresentationFor( | 250 Node* c = r.changer()->GetRepresentationFor( |
388 n, MachineRepresentation::kTagged, Type::Signed32(), use, | 251 n, MachineRepresentation::kTagged, Type::Signed32(), use, |
389 UseInfo(MachineRepresentation::kWord32, Truncation::None())); | 252 UseInfo(MachineRepresentation::kWord32, Truncation::None())); |
390 r.CheckInt32Constant(c, *i); | 253 r.CheckInt32Constant(c, *i); |
391 } | 254 } |
392 } | 255 } |
393 } | 256 } |
394 | 257 |
395 | |
396 TEST(ToUint32_constant) { | 258 TEST(ToUint32_constant) { |
397 RepresentationChangerTester r; | 259 RepresentationChangerTester r; |
398 | 260 FOR_UINT32_INPUTS(i) { |
399 { | 261 Node* n = r.jsgraph()->Constant(static_cast<double>(*i)); |
400 FOR_UINT32_INPUTS(i) { | 262 Node* use = r.Return(n); |
401 Node* n = r.jsgraph()->Int32Constant(*i); | 263 Node* c = r.changer()->GetRepresentationFor( |
402 Node* use = r.Return(n); | 264 n, MachineRepresentation::kTagged, Type::Unsigned32(), use, |
403 Node* c = r.changer()->GetRepresentationFor( | 265 UseInfo(MachineRepresentation::kWord32, Truncation::None())); |
404 n, MachineRepresentation::kWord32, Type::Unsigned32(), use, | 266 r.CheckUint32Constant(c, *i); |
405 UseInfo(MachineRepresentation::kWord32, Truncation::None())); | |
406 r.CheckUint32Constant(c, *i); | |
407 } | |
408 } | |
409 | |
410 { | |
411 FOR_UINT32_INPUTS(i) { | |
412 if (!IsFloat32Uint32(*i)) continue; | |
413 Node* n = r.jsgraph()->Float32Constant(static_cast<float>(*i)); | |
414 Node* use = r.Return(n); | |
415 Node* c = r.changer()->GetRepresentationFor( | |
416 n, MachineRepresentation::kFloat32, Type::Unsigned32(), use, | |
417 UseInfo(MachineRepresentation::kWord32, Truncation::None())); | |
418 r.CheckUint32Constant(c, *i); | |
419 } | |
420 } | |
421 | |
422 { | |
423 FOR_UINT32_INPUTS(i) { | |
424 Node* n = r.jsgraph()->Float64Constant(*i); | |
425 Node* use = r.Return(n); | |
426 Node* c = r.changer()->GetRepresentationFor( | |
427 n, MachineRepresentation::kFloat64, Type::Unsigned32(), use, | |
428 UseInfo(MachineRepresentation::kWord32, Truncation::None())); | |
429 r.CheckUint32Constant(c, *i); | |
430 } | |
431 } | |
432 | |
433 { | |
434 FOR_UINT32_INPUTS(i) { | |
435 Node* n = r.jsgraph()->Constant(static_cast<double>(*i)); | |
436 Node* use = r.Return(n); | |
437 Node* c = r.changer()->GetRepresentationFor( | |
438 n, MachineRepresentation::kTagged, Type::Unsigned32(), use, | |
439 UseInfo(MachineRepresentation::kWord32, Truncation::None())); | |
440 r.CheckUint32Constant(c, *i); | |
441 } | |
442 } | 267 } |
443 } | 268 } |
444 | 269 |
445 static void CheckChange(IrOpcode::Value expected, MachineRepresentation from, | 270 static void CheckChange(IrOpcode::Value expected, MachineRepresentation from, |
446 Type* from_type, UseInfo use_info) { | 271 Type* from_type, UseInfo use_info) { |
447 RepresentationChangerTester r; | 272 RepresentationChangerTester r; |
448 | 273 |
449 Node* n = r.Parameter(); | 274 Node* n = r.Parameter(); |
450 Node* use = r.Return(n); | 275 Node* use = r.Return(n); |
451 Node* c = | 276 Node* c = |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 MachineRepresentation::kWord64); | 531 MachineRepresentation::kWord64); |
707 r.CheckTypeError(MachineRepresentation::kWord32, Type::Signed32(), | 532 r.CheckTypeError(MachineRepresentation::kWord32, Type::Signed32(), |
708 MachineRepresentation::kWord64); | 533 MachineRepresentation::kWord64); |
709 r.CheckTypeError(MachineRepresentation::kWord32, Type::Unsigned32(), | 534 r.CheckTypeError(MachineRepresentation::kWord32, Type::Unsigned32(), |
710 MachineRepresentation::kWord64); | 535 MachineRepresentation::kWord64); |
711 } | 536 } |
712 | 537 |
713 } // namespace compiler | 538 } // namespace compiler |
714 } // namespace internal | 539 } // namespace internal |
715 } // namespace v8 | 540 } // namespace v8 |
OLD | NEW |