Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: test/mjsunit/smi-ops.js

Issue 460060: Code generation for multiply-by-constant-smi.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ia32/codegen-ia32.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 var shift = 2.4; 631 var shift = 2.4;
632 assertEquals(5, 20.5 >> shift); 632 assertEquals(5, 20.5 >> shift);
633 assertEquals(5, 20.5 >> shift + 0.3); 633 assertEquals(5, 20.5 >> shift + 0.3);
634 shift = shift + zero; 634 shift = shift + zero;
635 assertEquals(5, 20.5 >> shift); 635 assertEquals(5, 20.5 >> shift);
636 assertEquals(5, 20.5 >> shift + 0.3); 636 assertEquals(5, 20.5 >> shift + 0.3);
637 } 637 }
638 638
639 testShiftNonSmis(); 639 testShiftNonSmis();
640 640
641 // Test specialized code generation for shifts by a constant
642
643 function testSpecializedShift(general, shift, specialized) {
644 function test(n) {
645 assertEquals(general(n, shift), specialized(n));
646 }
647 for (var i = -256; i <= 256; ++i) {
648 test(i);
649 test(i + 0.5);
650 var big = i * (1 << 24); // ranges from -2^32 to 2^32
651 test(big);
652 test(big + 7);
653 test(big - 7);
654 test(big * 1.0000001);
655 test(big / 1.0000001);
656 }
657 }
658
659 function testShrConstant() {
660 function shift0(n) { return n >>> 0; }
661 function shift1(n) { return n >>> 1; }
662 function shift2(n) { return n >>> 2; }
663 function shift3(n) { return n >>> 3; }
664 function shift28(n) { return n >>> 28; }
665 function shift29(n) { return n >>> 29; }
666 function shift30(n) { return n >>> 30; }
667 function shift31(n) { return n >>> 31; }
668 function shift(n, s) { return n >>> s; }
669
670 testSpecializedShift(shift, 0, shift0);
671 testSpecializedShift(shift, 1, shift1);
672 testSpecializedShift(shift, 2, shift2);
673 testSpecializedShift(shift, 3, shift3);
674 testSpecializedShift(shift, 28, shift28);
675 testSpecializedShift(shift, 29, shift29);
676 testSpecializedShift(shift, 30, shift30);
677 testSpecializedShift(shift, 31, shift31);
678 }
679
680 testShrConstant();
681
682 function testSarConstant() {
683 function shift0(n) { return n >> 0; }
684 function shift1(n) { return n >> 1; }
685 function shift2(n) { return n >> 2; }
686 function shift3(n) { return n >> 3; }
687 function shift28(n) { return n >> 28; }
688 function shift29(n) { return n >> 29; }
689 function shift30(n) { return n >> 30; }
690 function shift31(n) { return n >> 31; }
691 function shift(n, s) { return n >> s; }
692
693 testSpecializedShift(shift, 0, shift0);
694 testSpecializedShift(shift, 1, shift1);
695 testSpecializedShift(shift, 2, shift2);
696 testSpecializedShift(shift, 3, shift3);
697 testSpecializedShift(shift, 28, shift28);
698 testSpecializedShift(shift, 29, shift29);
699 testSpecializedShift(shift, 30, shift30);
700 testSpecializedShift(shift, 31, shift31);
701 }
702
703 testSarConstant();
704
705 function testShlConstant() {
706 function shift0(n) { return n << 0; }
707 function shift1(n) { return n << 1; }
708 function shift2(n) { return n << 2; }
709 function shift3(n) { return n << 3; }
710 function shift28(n) { return n << 28; }
711 function shift29(n) { return n << 29; }
712 function shift30(n) { return n << 30; }
713 function shift31(n) { return n << 31; }
714 function shift(n, s) { return n << s; }
715
716 testSpecializedShift(shift, 0, shift0);
717 testSpecializedShift(shift, 1, shift1);
718 testSpecializedShift(shift, 2, shift2);
719 testSpecializedShift(shift, 3, shift3);
720 testSpecializedShift(shift, 28, shift28);
721 testSpecializedShift(shift, 29, shift29);
722 testSpecializedShift(shift, 30, shift30);
723 testSpecializedShift(shift, 31, shift31);
724 }
725
726 testShlConstant();
641 727
642 // Verify that we handle the (optimized) corner case of shifting by 728 // Verify that we handle the (optimized) corner case of shifting by
643 // zero even for non-smis. 729 // zero even for non-smis.
644 function shiftByZero(n) { return n << 0; } 730 function shiftByZero(n) { return n << 0; }
645 731
646 assertEquals(3, shiftByZero(3.1415)); 732 assertEquals(3, shiftByZero(3.1415));
733 assertEquals(3, shiftByZero(3.9995));
734
735 // Multiplication by SMIs
736
737 function MulZeroa(x) {
738 return 0 * x;
739 }
740 function MulZerob(x) {
741 return x * 0;
742 }
743
744 function testMultiplyZero(mulZero) {
745 assertEquals(0, mulZero(0));
746 assertEquals(0, mulZero(100));
747 assertEquals(0, mulZero(1000));
748 assertEquals(Infinity, 1 / mulZero(1000));
749 assertEquals(-Infinity, 1 / mulZero(-1000));
750 }
751
752 testMultiplyZero(MulZeroa);
753 testMultiplyZero(MulZerob);
754
755 function MulNeg1a(x) {
756 return -1 * x;
757 }
758 function MulNeg1b(x) {
759 return x * -1;
760 }
761
762 function testMultiplyNeg1(mulNeg1) {
763 assertEquals(1, mulNeg1(-1));
764 assertEquals(-1000, mulNeg1(1000)); // fast case
765 assertEquals(SMI_MAX + 1, mulNeg1(SMI_MIN)); // overflows
766 assertEquals(SMI_MIN + 1, mulNeg1(SMI_MAX)); // fast case
767 assertEquals(-Infinity, 1 / mulNeg1(0)); // negative zero case
768 assertEquals(Infinity, 1 / mulNeg1(mulNeg1(0)));
769
770 assertEquals(-42, mulNeg1(OBJ_42));
771 }
772
773 testMultiplyNeg1(MulNeg1a);
774 testMultiplyNeg1(MulNeg1b);
775
776 function testMulSmi() {
777 var constants = [-256, -100, -10, -3, -2, -1, 0, 1, 2, 3, 4, 5, 10, 20, 1000,
778 100000, SMI_MIN, SMI_MAX, SMI_MIN+1, SMI_MAX-1, SMI_MIN+2, SMI_MAX-3,
779 16];
780 var values = [-Infinity, 1000000, 123.4, -10000000, OBJ_42];
781 values = values.concat(constants);
782
783 for (var i = 0; i < constants.length; ++i) {
784 var x = constants[i];
785 var f1 = eval("(function(y) { return (" + x + ") * y})");
786 var f2 = eval("(function(y) { return y * (" + x + ")})");
787 for (var j = 0; j < values.length; ++j) {
788 var y = values[j];
789 var product = x * y;
790 assertEquals(product, f1(y));
791 assertEquals(product, f2(y));
792 assertEquals(1/product, 1/f1(y));
793 assertEquals(1/product, 1/f2(y));
794 }
795 }
796 }
797 testMulSmi();
OLDNEW
« no previous file with comments | « src/ia32/codegen-ia32.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698