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 // TODO(jochen): Remove this after the setting is turned on globally. | 5 // TODO(jochen): Remove this after the setting is turned on globally. |
6 #define V8_IMMINENT_DEPRECATION_WARNINGS | 6 #define V8_IMMINENT_DEPRECATION_WARNINGS |
7 | 7 |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "test/cctest/cctest.h" | 10 #include "test/cctest/cctest.h" |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64, | 445 CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64, |
446 IrOpcode::kChangeFloat64ToTagged, kRepFloat32, kRepTagged); | 446 IrOpcode::kChangeFloat64ToTagged, kRepFloat32, kRepTagged); |
447 CheckTwoChanges(IrOpcode::kChangeTaggedToFloat64, | 447 CheckTwoChanges(IrOpcode::kChangeTaggedToFloat64, |
448 IrOpcode::kTruncateFloat64ToFloat32, kRepTagged, kRepFloat32); | 448 IrOpcode::kTruncateFloat64ToFloat32, kRepTagged, kRepFloat32); |
449 } | 449 } |
450 | 450 |
451 | 451 |
452 TEST(SignednessInWord32) { | 452 TEST(SignednessInWord32) { |
453 RepresentationChangerTester r; | 453 RepresentationChangerTester r; |
454 | 454 |
455 // TODO(titzer): assume that uses of a word32 without a sign mean kTypeInt32. | 455 // TODO(titzer): assume that uses of a word32 without a sign mean kTypeInt32. |
Benedikt Meurer
2015/11/25 04:50:39
This comment seems to be wrong/useless. Can we rem
Jarin
2015/11/25 06:39:53
Done.
| |
456 CheckChange(IrOpcode::kChangeTaggedToInt32, kRepTagged | kTypeInt32, | 456 CheckChange(IrOpcode::kChangeTaggedToInt32, kRepTagged | kTypeInt32, |
457 kRepWord32 | kTypeInt32); | 457 kRepWord32); |
458 CheckChange(IrOpcode::kChangeTaggedToUint32, kRepTagged | kTypeUint32, | 458 CheckChange(IrOpcode::kChangeTaggedToUint32, kRepTagged | kTypeUint32, |
459 kRepWord32 | kTypeUint32); | 459 kRepWord32); |
460 CheckChange(IrOpcode::kChangeInt32ToFloat64, kRepWord32, kRepFloat64); | 460 CheckChange(IrOpcode::kChangeInt32ToFloat64, kRepWord32, kRepFloat64); |
461 CheckChange(IrOpcode::kChangeFloat64ToInt32, kRepFloat64 | kTypeInt32, | 461 CheckChange(IrOpcode::kChangeFloat64ToInt32, kRepFloat64 | kTypeInt32, |
462 kRepWord32); | 462 kRepWord32); |
463 CheckChange(IrOpcode::kTruncateFloat64ToInt32, kRepFloat64, kRepWord32); | 463 CheckChange(IrOpcode::kTruncateFloat64ToInt32, kRepFloat64, kRepWord32); |
464 | 464 |
465 CheckTwoChanges(IrOpcode::kChangeInt32ToFloat64, | 465 CheckTwoChanges(IrOpcode::kChangeInt32ToFloat64, |
466 IrOpcode::kTruncateFloat64ToFloat32, kRepWord32, kRepFloat32); | 466 IrOpcode::kTruncateFloat64ToFloat32, kRepWord32, kRepFloat32); |
467 CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64, | 467 CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64, |
468 IrOpcode::kTruncateFloat64ToInt32, kRepFloat32, kRepWord32); | 468 IrOpcode::kTruncateFloat64ToInt32, kRepFloat32, kRepWord32); |
469 } | 469 } |
470 | 470 |
471 | 471 |
472 TEST(Nops) { | 472 TEST(Nops) { |
473 RepresentationChangerTester r; | 473 RepresentationChangerTester r; |
474 | 474 |
475 // X -> X is always a nop for any single representation X. | 475 // X -> X is always a nop for any single representation X. |
476 for (size_t i = 0; i < arraysize(all_reps); i++) { | 476 for (size_t i = 0; i < arraysize(all_reps); i++) { |
477 r.CheckNop(all_reps[i], all_reps[i]); | 477 r.CheckNop(all_reps[i], all_reps[i]); |
478 } | 478 } |
479 | 479 |
480 // 32-bit floats. | 480 // 32-bit floats. |
481 r.CheckNop(kRepFloat32, kRepFloat32); | 481 r.CheckNop(kRepFloat32, kRepFloat32); |
482 r.CheckNop(kRepFloat32 | kTypeNumber, kRepFloat32); | 482 r.CheckNop(kRepFloat32 | kTypeNumber, kRepFloat32); |
483 r.CheckNop(kRepFloat32, kRepFloat32 | kTypeNumber); | |
484 | 483 |
485 // 32-bit words can be used as smaller word sizes and vice versa, because | 484 // 32-bit words can be used as smaller word sizes and vice versa, because |
486 // loads from memory implicitly sign or zero extend the value to the | 485 // loads from memory implicitly sign or zero extend the value to the |
487 // full machine word size, and stores implicitly truncate. | 486 // full machine word size, and stores implicitly truncate. |
488 r.CheckNop(kRepWord32, kRepWord8); | 487 r.CheckNop(kRepWord32, kRepWord8); |
489 r.CheckNop(kRepWord32, kRepWord16); | 488 r.CheckNop(kRepWord32, kRepWord16); |
490 r.CheckNop(kRepWord32, kRepWord32); | 489 r.CheckNop(kRepWord32, kRepWord32); |
491 r.CheckNop(kRepWord8, kRepWord32); | 490 r.CheckNop(kRepWord8, kRepWord32); |
492 r.CheckNop(kRepWord16, kRepWord32); | 491 r.CheckNop(kRepWord16, kRepWord32); |
493 | 492 |
494 // kRepBit (result of comparison) is implicitly a wordish thing. | 493 // kRepBit (result of comparison) is implicitly a wordish thing. |
495 r.CheckNop(kRepBit, kRepWord8); | 494 r.CheckNop(kRepBit, kRepWord8); |
496 r.CheckNop(kRepBit | kTypeBool, kRepWord8); | 495 r.CheckNop(kRepBit | kTypeBool, kRepWord8); |
497 r.CheckNop(kRepBit, kRepWord16); | 496 r.CheckNop(kRepBit, kRepWord16); |
498 r.CheckNop(kRepBit | kTypeBool, kRepWord16); | 497 r.CheckNop(kRepBit | kTypeBool, kRepWord16); |
499 r.CheckNop(kRepBit, kRepWord32); | 498 r.CheckNop(kRepBit, kRepWord32); |
500 r.CheckNop(kRepBit | kTypeBool, kRepWord32); | 499 r.CheckNop(kRepBit | kTypeBool, kRepWord32); |
501 r.CheckNop(kRepBit, kRepWord64); | 500 r.CheckNop(kRepBit, kRepWord64); |
502 r.CheckNop(kRepBit | kTypeBool, kRepWord64); | 501 r.CheckNop(kRepBit | kTypeBool, kRepWord64); |
503 } | 502 } |
504 | 503 |
505 | 504 |
506 TEST(TypeErrors) { | 505 TEST(TypeErrors) { |
507 RepresentationChangerTester r; | 506 RepresentationChangerTester r; |
508 | 507 |
509 // Wordish cannot be implicitly converted to/from comparison conditions. | 508 // Wordish cannot be implicitly converted to/from comparison conditions. |
510 r.CheckTypeError(kRepWord8, kRepBit); | 509 r.CheckTypeError(kRepWord8, kRepBit); |
511 r.CheckTypeError(kRepWord8, kRepBit | kTypeBool); | |
512 r.CheckTypeError(kRepWord16, kRepBit); | 510 r.CheckTypeError(kRepWord16, kRepBit); |
513 r.CheckTypeError(kRepWord16, kRepBit | kTypeBool); | |
514 r.CheckTypeError(kRepWord32, kRepBit); | 511 r.CheckTypeError(kRepWord32, kRepBit); |
515 r.CheckTypeError(kRepWord32, kRepBit | kTypeBool); | |
516 r.CheckTypeError(kRepWord64, kRepBit); | 512 r.CheckTypeError(kRepWord64, kRepBit); |
517 r.CheckTypeError(kRepWord64, kRepBit | kTypeBool); | |
518 | 513 |
519 // Floats cannot be implicitly converted to/from comparison conditions. | 514 // Floats cannot be implicitly converted to/from comparison conditions. |
520 r.CheckTypeError(kRepFloat64, kRepBit); | 515 r.CheckTypeError(kRepFloat64, kRepBit); |
521 r.CheckTypeError(kRepFloat64, kRepBit | kTypeBool); | |
522 r.CheckTypeError(kRepBit, kRepFloat64); | 516 r.CheckTypeError(kRepBit, kRepFloat64); |
523 r.CheckTypeError(kRepBit | kTypeBool, kRepFloat64); | 517 r.CheckTypeError(kRepBit | kTypeBool, kRepFloat64); |
524 | 518 |
525 // Floats cannot be implicitly converted to/from comparison conditions. | 519 // Floats cannot be implicitly converted to/from comparison conditions. |
526 r.CheckTypeError(kRepFloat32, kRepBit); | 520 r.CheckTypeError(kRepFloat32, kRepBit); |
527 r.CheckTypeError(kRepFloat32, kRepBit | kTypeBool); | |
528 r.CheckTypeError(kRepBit, kRepFloat32); | 521 r.CheckTypeError(kRepBit, kRepFloat32); |
529 r.CheckTypeError(kRepBit | kTypeBool, kRepFloat32); | 522 r.CheckTypeError(kRepBit | kTypeBool, kRepFloat32); |
530 | 523 |
531 // Word64 is internal and shouldn't be implicitly converted. | 524 // Word64 is internal and shouldn't be implicitly converted. |
532 r.CheckTypeError(kRepWord64, kRepTagged | kTypeBool); | |
533 r.CheckTypeError(kRepWord64, kRepTagged); | 525 r.CheckTypeError(kRepWord64, kRepTagged); |
534 r.CheckTypeError(kRepWord64, kRepTagged | kTypeBool); | |
535 r.CheckTypeError(kRepTagged, kRepWord64); | 526 r.CheckTypeError(kRepTagged, kRepWord64); |
536 r.CheckTypeError(kRepTagged | kTypeBool, kRepWord64); | 527 r.CheckTypeError(kRepTagged | kTypeBool, kRepWord64); |
537 | 528 |
538 // Word64 / Word32 shouldn't be implicitly converted. | 529 // Word64 / Word32 shouldn't be implicitly converted. |
539 r.CheckTypeError(kRepWord64, kRepWord32); | 530 r.CheckTypeError(kRepWord64, kRepWord32); |
540 r.CheckTypeError(kRepWord32, kRepWord64); | 531 r.CheckTypeError(kRepWord32, kRepWord64); |
541 r.CheckTypeError(kRepWord64, kRepWord32 | kTypeInt32); | |
542 r.CheckTypeError(kRepWord32 | kTypeInt32, kRepWord64); | 532 r.CheckTypeError(kRepWord32 | kTypeInt32, kRepWord64); |
543 r.CheckTypeError(kRepWord64, kRepWord32 | kTypeUint32); | |
544 r.CheckTypeError(kRepWord32 | kTypeUint32, kRepWord64); | 533 r.CheckTypeError(kRepWord32 | kTypeUint32, kRepWord64); |
545 | 534 |
546 for (size_t i = 0; i < arraysize(all_reps); i++) { | 535 for (size_t i = 0; i < arraysize(all_reps); i++) { |
547 for (size_t j = 0; j < arraysize(all_reps); j++) { | 536 for (size_t j = 0; j < arraysize(all_reps); j++) { |
548 if (i == j) continue; | 537 if (i == j) continue; |
549 // Only a single from representation is allowed. | 538 // Only a single from representation is allowed. |
550 r.CheckTypeError(all_reps[i] | all_reps[j], kRepTagged); | 539 r.CheckTypeError(all_reps[i] | all_reps[j], kRepTagged); |
551 } | 540 } |
552 } | 541 } |
553 } | 542 } |
554 | 543 |
555 } // namespace compiler | 544 } // namespace compiler |
556 } // namespace internal | 545 } // namespace internal |
557 } // namespace v8 | 546 } // namespace v8 |
OLD | NEW |