OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 25 matching lines...) Expand all Loading... |
36 using namespace v8::internal; | 36 using namespace v8::internal; |
37 | 37 |
38 | 38 |
39 // Define these function prototypes to match JSEntryFunction in execution.cc. | 39 // Define these function prototypes to match JSEntryFunction in execution.cc. |
40 typedef Object* (*F1)(int x, int p1, int p2, int p3, int p4); | 40 typedef Object* (*F1)(int x, int p1, int p2, int p3, int p4); |
41 typedef Object* (*F2)(int x, int y, int p2, int p3, int p4); | 41 typedef Object* (*F2)(int x, int y, int p2, int p3, int p4); |
42 typedef Object* (*F3)(void* p0, int p1, int p2, int p3, int p4); | 42 typedef Object* (*F3)(void* p0, int p1, int p2, int p3, int p4); |
43 typedef Object* (*F4)(void* p0, void* p1, int p2, int p3, int p4); | 43 typedef Object* (*F4)(void* p0, void* p1, int p2, int p3, int p4); |
44 | 44 |
45 | 45 |
46 static v8::Persistent<v8::Context> env; | |
47 | |
48 | |
49 static void InitializeVM() { | |
50 if (env.IsEmpty()) { | |
51 env = v8::Context::New(); | |
52 } | |
53 } | |
54 | |
55 | |
56 #define __ assm. | 46 #define __ assm. |
57 | 47 |
58 TEST(0) { | 48 TEST(0) { |
59 InitializeVM(); | 49 CcTest::InitializeVM(); |
60 Isolate* isolate = Isolate::Current(); | 50 Isolate* isolate = Isolate::Current(); |
61 HandleScope scope(isolate); | 51 HandleScope scope(isolate); |
62 | 52 |
63 Assembler assm(isolate, NULL, 0); | 53 Assembler assm(isolate, NULL, 0); |
64 | 54 |
65 __ add(r0, r0, Operand(r1)); | 55 __ add(r0, r0, Operand(r1)); |
66 __ mov(pc, Operand(lr)); | 56 __ mov(pc, Operand(lr)); |
67 | 57 |
68 CodeDesc desc; | 58 CodeDesc desc; |
69 assm.GetCode(&desc); | 59 assm.GetCode(&desc); |
70 Object* code = isolate->heap()->CreateCode( | 60 Object* code = isolate->heap()->CreateCode( |
71 desc, | 61 desc, |
72 Code::ComputeFlags(Code::STUB), | 62 Code::ComputeFlags(Code::STUB), |
73 Handle<Code>())->ToObjectChecked(); | 63 Handle<Code>())->ToObjectChecked(); |
74 CHECK(code->IsCode()); | 64 CHECK(code->IsCode()); |
75 #ifdef DEBUG | 65 #ifdef DEBUG |
76 Code::cast(code)->Print(); | 66 Code::cast(code)->Print(); |
77 #endif | 67 #endif |
78 F2 f = FUNCTION_CAST<F2>(Code::cast(code)->entry()); | 68 F2 f = FUNCTION_CAST<F2>(Code::cast(code)->entry()); |
79 int res = reinterpret_cast<int>(CALL_GENERATED_CODE(f, 3, 4, 0, 0, 0)); | 69 int res = reinterpret_cast<int>(CALL_GENERATED_CODE(f, 3, 4, 0, 0, 0)); |
80 ::printf("f() = %d\n", res); | 70 ::printf("f() = %d\n", res); |
81 CHECK_EQ(7, res); | 71 CHECK_EQ(7, res); |
82 } | 72 } |
83 | 73 |
84 | 74 |
85 TEST(1) { | 75 TEST(1) { |
86 InitializeVM(); | 76 CcTest::InitializeVM(); |
87 Isolate* isolate = Isolate::Current(); | 77 Isolate* isolate = Isolate::Current(); |
88 HandleScope scope(isolate); | 78 HandleScope scope(isolate); |
89 | 79 |
90 Assembler assm(isolate, NULL, 0); | 80 Assembler assm(isolate, NULL, 0); |
91 Label L, C; | 81 Label L, C; |
92 | 82 |
93 __ mov(r1, Operand(r0)); | 83 __ mov(r1, Operand(r0)); |
94 __ mov(r0, Operand::Zero()); | 84 __ mov(r0, Operand::Zero()); |
95 __ b(&C); | 85 __ b(&C); |
96 | 86 |
(...skipping 17 matching lines...) Expand all Loading... |
114 Code::cast(code)->Print(); | 104 Code::cast(code)->Print(); |
115 #endif | 105 #endif |
116 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); | 106 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); |
117 int res = reinterpret_cast<int>(CALL_GENERATED_CODE(f, 100, 0, 0, 0, 0)); | 107 int res = reinterpret_cast<int>(CALL_GENERATED_CODE(f, 100, 0, 0, 0, 0)); |
118 ::printf("f() = %d\n", res); | 108 ::printf("f() = %d\n", res); |
119 CHECK_EQ(5050, res); | 109 CHECK_EQ(5050, res); |
120 } | 110 } |
121 | 111 |
122 | 112 |
123 TEST(2) { | 113 TEST(2) { |
124 InitializeVM(); | 114 CcTest::InitializeVM(); |
125 Isolate* isolate = Isolate::Current(); | 115 Isolate* isolate = Isolate::Current(); |
126 HandleScope scope(isolate); | 116 HandleScope scope(isolate); |
127 | 117 |
128 Assembler assm(isolate, NULL, 0); | 118 Assembler assm(isolate, NULL, 0); |
129 Label L, C; | 119 Label L, C; |
130 | 120 |
131 __ mov(r1, Operand(r0)); | 121 __ mov(r1, Operand(r0)); |
132 __ mov(r0, Operand(1)); | 122 __ mov(r0, Operand(1)); |
133 __ b(&C); | 123 __ b(&C); |
134 | 124 |
(...skipping 26 matching lines...) Expand all Loading... |
161 Code::cast(code)->Print(); | 151 Code::cast(code)->Print(); |
162 #endif | 152 #endif |
163 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); | 153 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); |
164 int res = reinterpret_cast<int>(CALL_GENERATED_CODE(f, 10, 0, 0, 0, 0)); | 154 int res = reinterpret_cast<int>(CALL_GENERATED_CODE(f, 10, 0, 0, 0, 0)); |
165 ::printf("f() = %d\n", res); | 155 ::printf("f() = %d\n", res); |
166 CHECK_EQ(3628800, res); | 156 CHECK_EQ(3628800, res); |
167 } | 157 } |
168 | 158 |
169 | 159 |
170 TEST(3) { | 160 TEST(3) { |
171 InitializeVM(); | 161 CcTest::InitializeVM(); |
172 Isolate* isolate = Isolate::Current(); | 162 Isolate* isolate = Isolate::Current(); |
173 HandleScope scope(isolate); | 163 HandleScope scope(isolate); |
174 | 164 |
175 typedef struct { | 165 typedef struct { |
176 int i; | 166 int i; |
177 char c; | 167 char c; |
178 int16_t s; | 168 int16_t s; |
179 } T; | 169 } T; |
180 T t; | 170 T t; |
181 | 171 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 ::printf("f() = %d\n", res); | 207 ::printf("f() = %d\n", res); |
218 CHECK_EQ(101010, res); | 208 CHECK_EQ(101010, res); |
219 CHECK_EQ(100000/2, t.i); | 209 CHECK_EQ(100000/2, t.i); |
220 CHECK_EQ(10*4, t.c); | 210 CHECK_EQ(10*4, t.c); |
221 CHECK_EQ(1000/8, t.s); | 211 CHECK_EQ(1000/8, t.s); |
222 } | 212 } |
223 | 213 |
224 | 214 |
225 TEST(4) { | 215 TEST(4) { |
226 // Test the VFP floating point instructions. | 216 // Test the VFP floating point instructions. |
227 InitializeVM(); | 217 CcTest::InitializeVM(); |
228 Isolate* isolate = Isolate::Current(); | 218 Isolate* isolate = Isolate::Current(); |
229 HandleScope scope(isolate); | 219 HandleScope scope(isolate); |
230 | 220 |
231 typedef struct { | 221 typedef struct { |
232 double a; | 222 double a; |
233 double b; | 223 double b; |
234 double c; | 224 double c; |
235 double d; | 225 double d; |
236 double e; | 226 double e; |
237 double f; | 227 double f; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 CHECK_EQ(1.000000059604644775390625, t.d); | 346 CHECK_EQ(1.000000059604644775390625, t.d); |
357 CHECK_EQ(4.25, t.c); | 347 CHECK_EQ(4.25, t.c); |
358 CHECK_EQ(-4.1875, t.b); | 348 CHECK_EQ(-4.1875, t.b); |
359 CHECK_EQ(1.5, t.a); | 349 CHECK_EQ(1.5, t.a); |
360 } | 350 } |
361 } | 351 } |
362 | 352 |
363 | 353 |
364 TEST(5) { | 354 TEST(5) { |
365 // Test the ARMv7 bitfield instructions. | 355 // Test the ARMv7 bitfield instructions. |
366 InitializeVM(); | 356 CcTest::InitializeVM(); |
367 Isolate* isolate = Isolate::Current(); | 357 Isolate* isolate = Isolate::Current(); |
368 HandleScope scope(isolate); | 358 HandleScope scope(isolate); |
369 | 359 |
370 Assembler assm(isolate, NULL, 0); | 360 Assembler assm(isolate, NULL, 0); |
371 | 361 |
372 if (CpuFeatures::IsSupported(ARMv7)) { | 362 if (CpuFeatures::IsSupported(ARMv7)) { |
373 CpuFeatureScope scope(&assm, ARMv7); | 363 CpuFeatureScope scope(&assm, ARMv7); |
374 // On entry, r0 = 0xAAAAAAAA = 0b10..10101010. | 364 // On entry, r0 = 0xAAAAAAAA = 0b10..10101010. |
375 __ ubfx(r0, r0, 1, 12); // 0b00..010101010101 = 0x555 | 365 __ ubfx(r0, r0, 1, 12); // 0b00..010101010101 = 0x555 |
376 __ sbfx(r0, r0, 0, 5); // 0b11..111111110101 = -11 | 366 __ sbfx(r0, r0, 0, 5); // 0b11..111111110101 = -11 |
(...skipping 16 matching lines...) Expand all Loading... |
393 int res = reinterpret_cast<int>( | 383 int res = reinterpret_cast<int>( |
394 CALL_GENERATED_CODE(f, 0xAAAAAAAA, 0, 0, 0, 0)); | 384 CALL_GENERATED_CODE(f, 0xAAAAAAAA, 0, 0, 0, 0)); |
395 ::printf("f() = %d\n", res); | 385 ::printf("f() = %d\n", res); |
396 CHECK_EQ(-7, res); | 386 CHECK_EQ(-7, res); |
397 } | 387 } |
398 } | 388 } |
399 | 389 |
400 | 390 |
401 TEST(6) { | 391 TEST(6) { |
402 // Test saturating instructions. | 392 // Test saturating instructions. |
403 InitializeVM(); | 393 CcTest::InitializeVM(); |
404 Isolate* isolate = Isolate::Current(); | 394 Isolate* isolate = Isolate::Current(); |
405 HandleScope scope(isolate); | 395 HandleScope scope(isolate); |
406 | 396 |
407 Assembler assm(isolate, NULL, 0); | 397 Assembler assm(isolate, NULL, 0); |
408 | 398 |
409 if (CpuFeatures::IsSupported(ARMv7)) { | 399 if (CpuFeatures::IsSupported(ARMv7)) { |
410 CpuFeatureScope scope(&assm, ARMv7); | 400 CpuFeatureScope scope(&assm, ARMv7); |
411 __ usat(r1, 8, Operand(r0)); // Sat 0xFFFF to 0-255 = 0xFF. | 401 __ usat(r1, 8, Operand(r0)); // Sat 0xFFFF to 0-255 = 0xFF. |
412 __ usat(r2, 12, Operand(r0, ASR, 9)); // Sat (0xFFFF>>9) to 0-4095 = 0x7F. | 402 __ usat(r2, 12, Operand(r0, ASR, 9)); // Sat (0xFFFF>>9) to 0-4095 = 0x7F. |
413 __ usat(r3, 1, Operand(r0, LSL, 16)); // Sat (0xFFFF<<16) to 0-1 = 0x0. | 403 __ usat(r3, 1, Operand(r0, LSL, 16)); // Sat (0xFFFF<<16) to 0-1 = 0x0. |
(...skipping 23 matching lines...) Expand all Loading... |
437 enum VCVTTypes { | 427 enum VCVTTypes { |
438 s32_f64, | 428 s32_f64, |
439 u32_f64 | 429 u32_f64 |
440 }; | 430 }; |
441 | 431 |
442 static void TestRoundingMode(VCVTTypes types, | 432 static void TestRoundingMode(VCVTTypes types, |
443 VFPRoundingMode mode, | 433 VFPRoundingMode mode, |
444 double value, | 434 double value, |
445 int expected, | 435 int expected, |
446 bool expected_exception = false) { | 436 bool expected_exception = false) { |
447 InitializeVM(); | 437 CcTest::InitializeVM(); |
448 Isolate* isolate = Isolate::Current(); | 438 Isolate* isolate = Isolate::Current(); |
449 HandleScope scope(isolate); | 439 HandleScope scope(isolate); |
450 | 440 |
451 Assembler assm(isolate, NULL, 0); | 441 Assembler assm(isolate, NULL, 0); |
452 | 442 |
453 if (CpuFeatures::IsSupported(VFP3)) { | 443 if (CpuFeatures::IsSupported(VFP3)) { |
454 CpuFeatureScope scope(&assm, VFP3); | 444 CpuFeatureScope scope(&assm, VFP3); |
455 | 445 |
456 Label wrong_exception; | 446 Label wrong_exception; |
457 | 447 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 TestRoundingMode(u32_f64, RN, (kMaxInt + 0.49), kMaxInt); | 605 TestRoundingMode(u32_f64, RN, (kMaxInt + 0.49), kMaxInt); |
616 TestRoundingMode(u32_f64, RN, (kMaxInt + 0.5), | 606 TestRoundingMode(u32_f64, RN, (kMaxInt + 0.5), |
617 static_cast<uint32_t>(kMaxInt) + 1); | 607 static_cast<uint32_t>(kMaxInt) + 1); |
618 TestRoundingMode(u32_f64, RN, (kMaxUInt + 0.49), kMaxUInt); | 608 TestRoundingMode(u32_f64, RN, (kMaxUInt + 0.49), kMaxUInt); |
619 TestRoundingMode(u32_f64, RN, (kMaxUInt + 0.5), kMaxUInt, true); | 609 TestRoundingMode(u32_f64, RN, (kMaxUInt + 0.5), kMaxUInt, true); |
620 TestRoundingMode(u32_f64, RN, (kMaxUInt + 1.0), kMaxUInt, true); | 610 TestRoundingMode(u32_f64, RN, (kMaxUInt + 1.0), kMaxUInt, true); |
621 } | 611 } |
622 | 612 |
623 TEST(8) { | 613 TEST(8) { |
624 // Test VFP multi load/store with ia_w. | 614 // Test VFP multi load/store with ia_w. |
625 InitializeVM(); | 615 CcTest::InitializeVM(); |
626 Isolate* isolate = Isolate::Current(); | 616 Isolate* isolate = Isolate::Current(); |
627 HandleScope scope(isolate); | 617 HandleScope scope(isolate); |
628 | 618 |
629 typedef struct { | 619 typedef struct { |
630 double a; | 620 double a; |
631 double b; | 621 double b; |
632 double c; | 622 double c; |
633 double d; | 623 double d; |
634 double e; | 624 double e; |
635 double f; | 625 double f; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 CHECK_EQ(2.0, f.d); | 713 CHECK_EQ(2.0, f.d); |
724 CHECK_EQ(3.0, f.e); | 714 CHECK_EQ(3.0, f.e); |
725 CHECK_EQ(4.0, f.f); | 715 CHECK_EQ(4.0, f.f); |
726 CHECK_EQ(5.0, f.g); | 716 CHECK_EQ(5.0, f.g); |
727 CHECK_EQ(6.0, f.h); | 717 CHECK_EQ(6.0, f.h); |
728 } | 718 } |
729 | 719 |
730 | 720 |
731 TEST(9) { | 721 TEST(9) { |
732 // Test VFP multi load/store with ia. | 722 // Test VFP multi load/store with ia. |
733 InitializeVM(); | 723 CcTest::InitializeVM(); |
734 Isolate* isolate = Isolate::Current(); | 724 Isolate* isolate = Isolate::Current(); |
735 HandleScope scope(isolate); | 725 HandleScope scope(isolate); |
736 | 726 |
737 typedef struct { | 727 typedef struct { |
738 double a; | 728 double a; |
739 double b; | 729 double b; |
740 double c; | 730 double c; |
741 double d; | 731 double d; |
742 double e; | 732 double e; |
743 double f; | 733 double f; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 CHECK_EQ(2.0, f.d); | 825 CHECK_EQ(2.0, f.d); |
836 CHECK_EQ(3.0, f.e); | 826 CHECK_EQ(3.0, f.e); |
837 CHECK_EQ(4.0, f.f); | 827 CHECK_EQ(4.0, f.f); |
838 CHECK_EQ(5.0, f.g); | 828 CHECK_EQ(5.0, f.g); |
839 CHECK_EQ(6.0, f.h); | 829 CHECK_EQ(6.0, f.h); |
840 } | 830 } |
841 | 831 |
842 | 832 |
843 TEST(10) { | 833 TEST(10) { |
844 // Test VFP multi load/store with db_w. | 834 // Test VFP multi load/store with db_w. |
845 InitializeVM(); | 835 CcTest::InitializeVM(); |
846 Isolate* isolate = Isolate::Current(); | 836 Isolate* isolate = Isolate::Current(); |
847 HandleScope scope(isolate); | 837 HandleScope scope(isolate); |
848 | 838 |
849 typedef struct { | 839 typedef struct { |
850 double a; | 840 double a; |
851 double b; | 841 double b; |
852 double c; | 842 double c; |
853 double d; | 843 double d; |
854 double e; | 844 double e; |
855 double f; | 845 double f; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 CHECK_EQ(2.0, f.d); | 933 CHECK_EQ(2.0, f.d); |
944 CHECK_EQ(3.0, f.e); | 934 CHECK_EQ(3.0, f.e); |
945 CHECK_EQ(4.0, f.f); | 935 CHECK_EQ(4.0, f.f); |
946 CHECK_EQ(5.0, f.g); | 936 CHECK_EQ(5.0, f.g); |
947 CHECK_EQ(6.0, f.h); | 937 CHECK_EQ(6.0, f.h); |
948 } | 938 } |
949 | 939 |
950 | 940 |
951 TEST(11) { | 941 TEST(11) { |
952 // Test instructions using the carry flag. | 942 // Test instructions using the carry flag. |
953 InitializeVM(); | 943 CcTest::InitializeVM(); |
954 Isolate* isolate = Isolate::Current(); | 944 Isolate* isolate = Isolate::Current(); |
955 HandleScope scope(isolate); | 945 HandleScope scope(isolate); |
956 | 946 |
957 typedef struct { | 947 typedef struct { |
958 int32_t a; | 948 int32_t a; |
959 int32_t b; | 949 int32_t b; |
960 int32_t c; | 950 int32_t c; |
961 int32_t d; | 951 int32_t d; |
962 } I; | 952 } I; |
963 I i; | 953 I i; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 | 999 |
1010 CHECK_EQ(0xabcd0001, i.a); | 1000 CHECK_EQ(0xabcd0001, i.a); |
1011 CHECK_EQ(static_cast<int32_t>(0xabcd0000) >> 1, i.b); | 1001 CHECK_EQ(static_cast<int32_t>(0xabcd0000) >> 1, i.b); |
1012 CHECK_EQ(0x00000000, i.c); | 1002 CHECK_EQ(0x00000000, i.c); |
1013 CHECK_EQ(0xffffffff, i.d); | 1003 CHECK_EQ(0xffffffff, i.d); |
1014 } | 1004 } |
1015 | 1005 |
1016 | 1006 |
1017 TEST(12) { | 1007 TEST(12) { |
1018 // Test chaining of label usages within instructions (issue 1644). | 1008 // Test chaining of label usages within instructions (issue 1644). |
1019 InitializeVM(); | 1009 CcTest::InitializeVM(); |
1020 Isolate* isolate = Isolate::Current(); | 1010 Isolate* isolate = Isolate::Current(); |
1021 HandleScope scope(isolate); | 1011 HandleScope scope(isolate); |
1022 | 1012 |
1023 Assembler assm(isolate, NULL, 0); | 1013 Assembler assm(isolate, NULL, 0); |
1024 Label target; | 1014 Label target; |
1025 __ b(eq, &target); | 1015 __ b(eq, &target); |
1026 __ b(ne, &target); | 1016 __ b(ne, &target); |
1027 __ bind(&target); | 1017 __ bind(&target); |
1028 __ nop(); | 1018 __ nop(); |
1029 } | 1019 } |
1030 | 1020 |
1031 | 1021 |
1032 TEST(13) { | 1022 TEST(13) { |
1033 // Test VFP instructions using registers d16-d31. | 1023 // Test VFP instructions using registers d16-d31. |
1034 InitializeVM(); | 1024 CcTest::InitializeVM(); |
1035 Isolate* isolate = Isolate::Current(); | 1025 Isolate* isolate = Isolate::Current(); |
1036 HandleScope scope(isolate); | 1026 HandleScope scope(isolate); |
1037 | 1027 |
1038 if (!CpuFeatures::IsSupported(VFP32DREGS)) { | 1028 if (!CpuFeatures::IsSupported(VFP32DREGS)) { |
1039 return; | 1029 return; |
1040 } | 1030 } |
1041 | 1031 |
1042 typedef struct { | 1032 typedef struct { |
1043 double a; | 1033 double a; |
1044 double b; | 1034 double b; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 CHECK_EQ(2.75, t.x); | 1131 CHECK_EQ(2.75, t.x); |
1142 CHECK_EQ(1.5, t.y); | 1132 CHECK_EQ(1.5, t.y); |
1143 CHECK_EQ(17.0, t.z); | 1133 CHECK_EQ(17.0, t.z); |
1144 CHECK_EQ(14.7610017472335499, t.i); | 1134 CHECK_EQ(14.7610017472335499, t.i); |
1145 CHECK_EQ(16.0, t.j); | 1135 CHECK_EQ(16.0, t.j); |
1146 CHECK_EQ(73.8818412254460241, t.k); | 1136 CHECK_EQ(73.8818412254460241, t.k); |
1147 } | 1137 } |
1148 } | 1138 } |
1149 | 1139 |
1150 #undef __ | 1140 #undef __ |
OLD | NEW |