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

Side by Side Diff: runtime/vm/assembler_x64_test.cc

Issue 11362210: Restrict immediate operands to smi where only smis are supported. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | « runtime/vm/assembler_x64.cc ('k') | runtime/vm/disassembler_x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" 5 #include "vm/globals.h"
6 #if defined(TARGET_ARCH_X64) 6 #if defined(TARGET_ARCH_X64)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/os.h" 9 #include "vm/os.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 } 339 }
340 340
341 341
342 ASSEMBLER_TEST_RUN(SignedMultiply, entry) { 342 ASSEMBLER_TEST_RUN(SignedMultiply, entry) {
343 typedef int (*SignedMultiply)(); 343 typedef int (*SignedMultiply)();
344 EXPECT_EQ(8000, reinterpret_cast<SignedMultiply>(entry)()); 344 EXPECT_EQ(8000, reinterpret_cast<SignedMultiply>(entry)());
345 } 345 }
346 346
347 347
348 ASSEMBLER_TEST_GENERATE(SignedMultiply64, assembler) { 348 ASSEMBLER_TEST_GENERATE(SignedMultiply64, assembler) {
349 __ pushq(R15); // Callee saved.
349 __ movq(RAX, Immediate(2)); 350 __ movq(RAX, Immediate(2));
350 __ movq(RCX, Immediate(4)); 351 __ movq(RCX, Immediate(4));
351 __ imulq(RAX, RCX); 352 __ imulq(RAX, RCX);
353
352 __ movq(R8, Immediate(2)); 354 __ movq(R8, Immediate(2));
353 __ movq(R9, Immediate(4)); 355 __ movq(R9, Immediate(4));
354 __ pushq(R9); 356 __ pushq(R9);
355 __ imulq(R8, Address(RSP, 0)); 357 __ imulq(R8, Address(RSP, 0));
356 __ popq(R9); 358 __ popq(R9);
357 __ addq(RAX, R8); 359 __ addq(RAX, R8);
360
361 __ movq(R10, Immediate(2));
362 __ movq(R11, Immediate(4));
363 __ imulq(R10, R11);
364 __ addq(RAX, R10);
365
366 __ movq(R15, Immediate(2));
367 __ imulq(R15, Immediate(4));
368 __ addq(RAX, R15);
369 __ popq(R15);
358 __ ret(); 370 __ ret();
359 } 371 }
360 372
361 373
362 ASSEMBLER_TEST_RUN(SignedMultiply64, entry) { 374 ASSEMBLER_TEST_RUN(SignedMultiply64, entry) {
363 typedef int64_t (*SignedMultiply64)(); 375 typedef int64_t (*SignedMultiply64)();
364 EXPECT_EQ(16, reinterpret_cast<SignedMultiply64>(entry)()); 376 EXPECT_EQ(32, reinterpret_cast<SignedMultiply64>(entry)());
365 } 377 }
366 378
367 379
368 static const int64_t kLargeConstant = 0x1234567887654321; 380 static const int64_t kLargeConstant = 0x1234567887654321;
369 static const int64_t kAnotherLargeConstant = 987654321987654321LL; 381 static const int64_t kAnotherLargeConstant = 987654321987654321LL;
370 static const int64_t kProductLargeConstants = 0x5bbb29a7f52fbbd1; 382 static const int64_t kProductLargeConstants = 0x5bbb29a7f52fbbd1;
371 383
372 384
373 ASSEMBLER_TEST_GENERATE(SignedMultiplyLong, assembler) { 385 ASSEMBLER_TEST_GENERATE(SignedMultiplyLong, assembler) {
386 Label done;
374 __ movq(RAX, Immediate(kLargeConstant)); 387 __ movq(RAX, Immediate(kLargeConstant));
375 __ movq(RCX, Immediate(kAnotherLargeConstant)); 388 __ movq(RCX, Immediate(kAnotherLargeConstant));
376 __ imulq(RAX, RCX); 389 __ imulq(RAX, RCX);
390 __ imulq(RCX, Immediate(kLargeConstant));
391 __ cmpq(RAX, RCX);
392 __ j(EQUAL, &done);
393 __ int3();
394 __ Bind(&done);
377 __ ret(); 395 __ ret();
378 } 396 }
379 397
380 398
381 ASSEMBLER_TEST_RUN(SignedMultiplyLong, entry) { 399 ASSEMBLER_TEST_RUN(SignedMultiplyLong, entry) {
382 typedef int64_t (*SignedMultiplyLong)(); 400 typedef int64_t (*SignedMultiplyLong)();
383 EXPECT_EQ(kProductLargeConstants, 401 EXPECT_EQ(kProductLargeConstants,
384 reinterpret_cast<SignedMultiplyLong>(entry)()); 402 reinterpret_cast<SignedMultiplyLong>(entry)());
385 } 403 }
386 404
(...skipping 23 matching lines...) Expand all
410 __ ret(); 428 __ ret();
411 } 429 }
412 430
413 431
414 ASSEMBLER_TEST_RUN(SignedMultiply1, entry) { 432 ASSEMBLER_TEST_RUN(SignedMultiply1, entry) {
415 typedef int (*SignedMultiply1)(); 433 typedef int (*SignedMultiply1)();
416 EXPECT_EQ(8000, reinterpret_cast<SignedMultiply1>(entry)()); 434 EXPECT_EQ(8000, reinterpret_cast<SignedMultiply1>(entry)());
417 } 435 }
418 436
419 437
438 ASSEMBLER_TEST_GENERATE(SignedMultiply2, assembler) {
439 __ pushq(R15); // Callee saved.
440 __ movl(R15, Immediate(2));
441 __ imull(R15, Immediate(1000));
442 __ movl(RAX, R15);
443 __ popq(R15);
444 __ ret();
445 }
446
447
448 ASSEMBLER_TEST_RUN(SignedMultiply2, entry) {
449 typedef int (*SignedMultiply2)();
450 EXPECT_EQ(2000, reinterpret_cast<SignedMultiply2>(entry)());
451 }
452
453
420 ASSEMBLER_TEST_GENERATE(SignedDivide, assembler) { 454 ASSEMBLER_TEST_GENERATE(SignedDivide, assembler) {
421 __ movl(RAX, Immediate(-87)); 455 __ movl(RAX, Immediate(-87));
422 __ movl(RDX, Immediate(123)); 456 __ movl(RDX, Immediate(123));
423 __ cdq(); 457 __ cdq();
424 __ movl(RCX, Immediate(42)); 458 __ movl(RCX, Immediate(42));
425 __ idivl(RCX); 459 __ idivl(RCX);
426 __ ret(); 460 __ ret();
427 } 461 }
428 462
429 463
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 EXPECT_EQ(0, reinterpret_cast<LogicalOpsCode>(entry)()); 801 EXPECT_EQ(0, reinterpret_cast<LogicalOpsCode>(entry)());
768 } 802 }
769 803
770 804
771 ASSEMBLER_TEST_GENERATE(LogicalOps64, assembler) { 805 ASSEMBLER_TEST_GENERATE(LogicalOps64, assembler) {
772 Label donetest1; 806 Label donetest1;
773 __ movq(RAX, Immediate(4)); 807 __ movq(RAX, Immediate(4));
774 __ andq(RAX, Immediate(2)); 808 __ andq(RAX, Immediate(2));
775 __ cmpq(RAX, Immediate(0)); 809 __ cmpq(RAX, Immediate(0));
776 __ j(EQUAL, &donetest1); 810 __ j(EQUAL, &donetest1);
777 // Be sure to skip this crashing code. 811 __ int3();
778 __ movq(RAX, Immediate(0));
779 __ movq(Address(RAX, 0), RAX);
780 __ Bind(&donetest1); 812 __ Bind(&donetest1);
781 813
782 Label donetest2; 814 Label donetest2;
783 __ movq(RCX, Immediate(4)); 815 __ movq(RCX, Immediate(4));
784 __ pushq(RCX); 816 __ pushq(RCX);
785 __ andq(RCX, Address(RSP, 0)); 817 __ andq(RCX, Address(RSP, 0));
786 __ popq(RAX); 818 __ popq(RAX);
787 __ cmpq(RCX, Immediate(0)); 819 __ cmpq(RCX, Immediate(0));
788 __ j(NOT_EQUAL, &donetest2); 820 __ j(NOT_EQUAL, &donetest2);
789 // Be sure to skip this crashing code. 821 __ int3();
790 __ movq(RAX, Immediate(0));
791 __ movq(Address(RAX, 0), RAX);
792 __ Bind(&donetest2); 822 __ Bind(&donetest2);
793 823
794 Label donetest3; 824 Label donetest3;
795 __ movq(RAX, Immediate(0)); 825 __ movq(RAX, Immediate(0));
796 __ orq(RAX, Immediate(0)); 826 __ orq(RAX, Immediate(0));
797 __ cmpq(RAX, Immediate(0)); 827 __ cmpq(RAX, Immediate(0));
798 __ j(EQUAL, &donetest3); 828 __ j(EQUAL, &donetest3);
799 // Be sure to skip this crashing code. 829 __ int3();
800 __ movq(RAX, Immediate(0));
801 __ movq(Address(RAX, 0), RAX);
802 __ Bind(&donetest3); 830 __ Bind(&donetest3);
803 831
804 Label donetest4; 832 Label donetest4;
805 __ movq(RAX, Immediate(4)); 833 __ movq(RAX, Immediate(4));
806 __ orq(RAX, Immediate(0)); 834 __ orq(RAX, Immediate(0));
807 __ cmpq(RAX, Immediate(0)); 835 __ cmpq(RAX, Immediate(0));
808 __ j(NOT_EQUAL, &donetest4); 836 __ j(NOT_EQUAL, &donetest4);
809 // Be sure to skip this crashing code. 837 __ int3();
810 __ movq(RAX, Immediate(0));
811 __ movq(Address(RAX, 0), RAX);
812 __ Bind(&donetest4); 838 __ Bind(&donetest4);
813 839
814 Label donetest5; 840 Label donetest5;
815 __ pushq(RAX); 841 __ pushq(RAX);
816 __ movq(RAX, Immediate(0xff)); 842 __ movq(RAX, Immediate(0xff));
817 __ movq(Address(RSP, 0), RAX); 843 __ movq(Address(RSP, 0), RAX);
818 __ cmpq(Address(RSP, 0), Immediate(0xff)); 844 __ cmpq(Address(RSP, 0), Immediate(0xff));
819 __ j(EQUAL, &donetest5); 845 __ j(EQUAL, &donetest5);
820 // Be sure to skip this crashing code. 846 __ int3();
821 __ movq(RAX, Immediate(0));
822 __ movq(Address(RAX, 0), RAX);
823 __ Bind(&donetest5); 847 __ Bind(&donetest5);
824 __ popq(RAX); 848 __ popq(RAX);
825 849
826 Label donetest6; 850 Label donetest6;
827 __ movq(RAX, Immediate(1)); 851 __ movq(RAX, Immediate(1));
828 __ shlq(RAX, Immediate(3)); 852 __ shlq(RAX, Immediate(3));
829 __ cmpq(RAX, Immediate(8)); 853 __ cmpq(RAX, Immediate(8));
830 __ j(EQUAL, &donetest6); 854 __ j(EQUAL, &donetest6);
831 // Be sure to skip this crashing code. 855 __ int3();
832 __ movq(RAX, Immediate(0));
833 __ movq(Address(RAX, 0), RAX);
834 __ Bind(&donetest6); 856 __ Bind(&donetest6);
835 857
836 Label donetest7; 858 Label donetest7;
837 __ movq(RAX, Immediate(2)); 859 __ movq(RAX, Immediate(2));
838 __ shrq(RAX, Immediate(1)); 860 __ shrq(RAX, Immediate(1));
839 __ cmpq(RAX, Immediate(1)); 861 __ cmpq(RAX, Immediate(1));
840 __ j(EQUAL, &donetest7); 862 __ j(EQUAL, &donetest7);
841 // Be sure to skip this crashing code. 863 __ int3();
842 __ movq(RAX, Immediate(0));
843 __ movq(Address(RAX, 0), RAX);
844 __ Bind(&donetest7); 864 __ Bind(&donetest7);
845 865
846 Label donetest8; 866 Label donetest8;
847 __ movq(RAX, Immediate(8)); 867 __ movq(RAX, Immediate(8));
848 __ shrq(RAX, Immediate(3)); 868 __ shrq(RAX, Immediate(3));
849 __ cmpq(RAX, Immediate(1)); 869 __ cmpq(RAX, Immediate(1));
850 __ j(EQUAL, &donetest8); 870 __ j(EQUAL, &donetest8);
851 // Be sure to skip this crashing code. 871 __ int3();
852 __ movq(RAX, Immediate(0));
853 __ movq(Address(RAX, 0), RAX);
854 __ Bind(&donetest8); 872 __ Bind(&donetest8);
855 873
856 Label donetest9; 874 Label donetest9;
857 __ movq(RAX, Immediate(1)); 875 __ movq(RAX, Immediate(1));
858 __ movq(RCX, Immediate(3)); 876 __ movq(RCX, Immediate(3));
859 __ shlq(RAX, RCX); 877 __ shlq(RAX, RCX);
860 __ cmpq(RAX, Immediate(8)); 878 __ cmpq(RAX, Immediate(8));
861 __ j(EQUAL, &donetest9); 879 __ j(EQUAL, &donetest9);
862 // Be sure to skip this crashing code. 880 __ int3();
863 __ movq(RAX, Immediate(0));
864 __ movq(Address(RAX, 0), RAX);
865 __ Bind(&donetest9); 881 __ Bind(&donetest9);
866 882
867 Label donetest10; 883 Label donetest10;
868 __ movq(RAX, Immediate(8)); 884 __ movq(RAX, Immediate(8));
869 __ movq(RCX, Immediate(3)); 885 __ movq(RCX, Immediate(3));
870 __ shrq(RAX, RCX); 886 __ shrq(RAX, RCX);
871 __ cmpq(RAX, Immediate(1)); 887 __ cmpq(RAX, Immediate(1));
872 __ j(EQUAL, &donetest10); 888 __ j(EQUAL, &donetest10);
873 // Be sure to skip this crashing code. 889 __ int3();
874 __ movq(RAX, Immediate(0));
875 __ movq(Address(RAX, 0), RAX);
876 __ Bind(&donetest10); 890 __ Bind(&donetest10);
877 891
878 Label donetest6a; 892 Label donetest6a;
879 __ movq(RAX, Immediate(1)); 893 __ movq(RAX, Immediate(1));
880 __ shlq(RAX, Immediate(3)); 894 __ shlq(RAX, Immediate(3));
881 __ cmpq(RAX, Immediate(8)); 895 __ cmpq(RAX, Immediate(8));
882 __ j(EQUAL, &donetest6a); 896 __ j(EQUAL, &donetest6a);
883 // Be sure to skip this crashing code. 897 // Be sure to skip this crashing code.
884 __ movq(RAX, Immediate(0)); 898 __ movq(RAX, Immediate(0));
885 __ movq(Address(RAX, 0), RAX); 899 __ movq(Address(RAX, 0), RAX);
886 __ Bind(&donetest6a); 900 __ Bind(&donetest6a);
887 901
888 Label donetest7a; 902 Label donetest7a;
889 __ movq(RAX, Immediate(2)); 903 __ movq(RAX, Immediate(2));
890 __ shrq(RAX, Immediate(1)); 904 __ shrq(RAX, Immediate(1));
891 __ cmpq(RAX, Immediate(1)); 905 __ cmpq(RAX, Immediate(1));
892 __ j(EQUAL, &donetest7a); 906 __ j(EQUAL, &donetest7a);
893 // Be sure to skip this crashing code. 907 __ int3();
894 __ movq(RAX, Immediate(0));
895 __ movq(Address(RAX, 0), RAX);
896 __ Bind(&donetest7a); 908 __ Bind(&donetest7a);
897 909
898 Label donetest8a; 910 Label donetest8a;
899 __ movq(RAX, Immediate(8)); 911 __ movq(RAX, Immediate(8));
900 __ shrq(RAX, Immediate(3)); 912 __ shrq(RAX, Immediate(3));
901 __ cmpq(RAX, Immediate(1)); 913 __ cmpq(RAX, Immediate(1));
902 __ j(EQUAL, &donetest8a); 914 __ j(EQUAL, &donetest8a);
903 // Be sure to skip this crashing code. 915 __ int3();
904 __ movq(RAX, Immediate(0));
905 __ movq(Address(RAX, 0), RAX);
906 __ Bind(&donetest8a); 916 __ Bind(&donetest8a);
907 917
908 Label donetest9a; 918 Label donetest9a;
909 __ movq(RAX, Immediate(1)); 919 __ movq(RAX, Immediate(1));
910 __ movq(RCX, Immediate(3)); 920 __ movq(RCX, Immediate(3));
911 __ shlq(RAX, RCX); 921 __ shlq(RAX, RCX);
912 __ cmpq(RAX, Immediate(8)); 922 __ cmpq(RAX, Immediate(8));
913 __ j(EQUAL, &donetest9a); 923 __ j(EQUAL, &donetest9a);
914 // Be sure to skip this crashing code. 924 __ int3();
915 __ movq(RAX, Immediate(0));
916 __ movq(Address(RAX, 0), RAX);
917 __ Bind(&donetest9a); 925 __ Bind(&donetest9a);
918 926
919 Label donetest10a; 927 Label donetest10a;
920 __ movq(RAX, Immediate(8)); 928 __ movq(RAX, Immediate(8));
921 __ movq(RCX, Immediate(3)); 929 __ movq(RCX, Immediate(3));
922 __ shrq(RAX, RCX); 930 __ shrq(RAX, RCX);
923 __ cmpq(RAX, Immediate(1)); 931 __ cmpq(RAX, Immediate(1));
924 __ j(EQUAL, &donetest10a); 932 __ j(EQUAL, &donetest10a);
925 // Be sure to skip this crashing code. 933 __ int3();
926 __ movq(RAX, Immediate(0));
927 __ movq(Address(RAX, 0), RAX);
928 __ Bind(&donetest10a); 934 __ Bind(&donetest10a);
929 935
930 Label donetest11a; 936 Label donetest11a;
931 __ movq(RAX, Immediate(1)); 937 __ movq(RAX, Immediate(1));
932 __ shlq(RAX, Immediate(31)); 938 __ shlq(RAX, Immediate(31));
933 __ shrq(RAX, Immediate(3)); 939 __ shrq(RAX, Immediate(3));
934 __ cmpq(RAX, Immediate(0x10000000)); 940 __ cmpq(RAX, Immediate(0x10000000));
935 __ j(EQUAL, &donetest11a); 941 __ j(EQUAL, &donetest11a);
936 // Be sure to skip this crashing code. 942 __ int3();
937 __ movq(RAX, Immediate(0));
938 __ movq(Address(RAX, 0), RAX);
939 __ Bind(&donetest11a); 943 __ Bind(&donetest11a);
940 944
941 Label donetest12a; 945 Label donetest12a;
942 __ movq(RAX, Immediate(1)); 946 __ movq(RAX, Immediate(1));
943 __ shlq(RAX, Immediate(63)); 947 __ shlq(RAX, Immediate(63));
944 __ sarq(RAX, Immediate(3)); 948 __ sarq(RAX, Immediate(3));
945 __ cmpq(RAX, Immediate(0xf000000000000000)); 949 __ cmpq(RAX, Immediate(0xf000000000000000));
946 __ j(EQUAL, &donetest12a); 950 __ j(EQUAL, &donetest12a);
947 // Be sure to skip this crashing code. 951 __ int3();
948 __ movq(RAX, Immediate(0));
949 __ movq(Address(RAX, 0), RAX);
950 __ Bind(&donetest12a); 952 __ Bind(&donetest12a);
951 953
952 Label donetest13a; 954 Label donetest13a;
953 __ movq(RAX, Immediate(1)); 955 __ movq(RAX, Immediate(1));
954 __ movq(RCX, Immediate(3)); 956 __ movq(RCX, Immediate(3));
955 __ shlq(RAX, Immediate(63)); 957 __ shlq(RAX, Immediate(63));
956 __ sarq(RAX, RCX); 958 __ sarq(RAX, RCX);
957 __ cmpq(RAX, Immediate(0xf000000000000000)); 959 __ cmpq(RAX, Immediate(0xf000000000000000));
958 __ j(EQUAL, &donetest13a); 960 __ j(EQUAL, &donetest13a);
959 // Be sure to skip this crashing code. 961 __ int3();
960 __ movq(RAX, Immediate(0));
961 __ movq(Address(RAX, 0), RAX);
962 __ Bind(&donetest13a); 962 __ Bind(&donetest13a);
963 963
964 Label donetest14, donetest15;
965 __ pushq(R15); // Callee saved.
966 __ movq(R15, Immediate(0xf000000000000001));
967 __ andq(R15, Immediate(-1));
968 __ andq(R15, Immediate(0x8000000000000001));
969 __ orq(R15, Immediate(2));
970 __ orq(R15, Immediate(0xf800000000000000));
971 __ xorq(R15, Immediate(1));
972 __ xorq(R15, Immediate(0x0800000000000000));
973 __ cmpq(R15, Immediate(0xf000000000000002));
974 __ j(EQUAL, &donetest14);
975 __ int3();
976 __ Bind(&donetest14);
977 __ andq(R15, Immediate(2));
978 __ cmpq(R15, Immediate(2));
979 __ j(EQUAL, &donetest15);
980 __ int3();
981 __ Bind(&donetest15);
982 __ popq(R15); // Callee saved.
983
964 __ movq(RAX, Immediate(0)); 984 __ movq(RAX, Immediate(0));
965 __ ret(); 985 __ ret();
966 } 986 }
967 987
968 988
969 ASSEMBLER_TEST_RUN(LogicalOps64, entry) { 989 ASSEMBLER_TEST_RUN(LogicalOps64, entry) {
970 typedef int (*LogicalOpsCode)(); 990 typedef int (*LogicalOpsCode)();
971 EXPECT_EQ(0, reinterpret_cast<LogicalOpsCode>(entry)()); 991 EXPECT_EQ(0, reinterpret_cast<LogicalOpsCode>(entry)());
972 } 992 }
973 993
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 EXPECT_EQ(0, res); 1746 EXPECT_EQ(0, res);
1727 res = reinterpret_cast<ExtractSignBits>(entry)(-1.0); 1747 res = reinterpret_cast<ExtractSignBits>(entry)(-1.0);
1728 EXPECT_EQ(1, res); 1748 EXPECT_EQ(1, res);
1729 res = reinterpret_cast<ExtractSignBits>(entry)(-0.0); 1749 res = reinterpret_cast<ExtractSignBits>(entry)(-0.0);
1730 EXPECT_EQ(1, res); 1750 EXPECT_EQ(1, res);
1731 } 1751 }
1732 1752
1733 } // namespace dart 1753 } // namespace dart
1734 1754
1735 #endif // defined TARGET_ARCH_X64 1755 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/assembler_x64.cc ('k') | runtime/vm/disassembler_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698