OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // This calling convention is used on Linux, with GCC, and on Mac OS, | 92 // This calling convention is used on Linux, with GCC, and on Mac OS, |
93 // with GCC. A different convention is used on 64-bit windows. | 93 // with GCC. A different convention is used on 64-bit windows. |
94 | 94 |
95 typedef int (*F0)(); | 95 typedef int (*F0)(); |
96 | 96 |
97 #define __ masm-> | 97 #define __ masm-> |
98 | 98 |
99 | 99 |
100 static void EntryCode(MacroAssembler* masm) { | 100 static void EntryCode(MacroAssembler* masm) { |
101 // Smi constant register is callee save. | 101 // Smi constant register is callee save. |
102 __ push(i::kSmiConstantRegister); | 102 __ pushq(i::kSmiConstantRegister); |
103 __ push(i::kRootRegister); | 103 __ pushq(i::kRootRegister); |
104 __ InitializeSmiConstantRegister(); | 104 __ InitializeSmiConstantRegister(); |
105 __ InitializeRootRegister(); | 105 __ InitializeRootRegister(); |
106 } | 106 } |
107 | 107 |
108 | 108 |
109 static void ExitCode(MacroAssembler* masm) { | 109 static void ExitCode(MacroAssembler* masm) { |
110 // Return -1 if kSmiConstantRegister was clobbered during the test. | 110 // Return -1 if kSmiConstantRegister was clobbered during the test. |
111 __ Move(rdx, Smi::FromInt(1)); | 111 __ Move(rdx, Smi::FromInt(1)); |
112 __ cmpq(rdx, i::kSmiConstantRegister); | 112 __ cmpq(rdx, i::kSmiConstantRegister); |
113 __ movq(rdx, Immediate(-1)); | 113 __ movq(rdx, Immediate(-1)); |
114 __ cmovq(not_equal, rax, rdx); | 114 __ cmovq(not_equal, rax, rdx); |
115 __ pop(i::kRootRegister); | 115 __ popq(i::kRootRegister); |
116 __ pop(i::kSmiConstantRegister); | 116 __ popq(i::kSmiConstantRegister); |
117 } | 117 } |
118 | 118 |
119 | 119 |
120 TEST(Smi) { | 120 TEST(Smi) { |
121 // Check that C++ Smi operations work as expected. | 121 // Check that C++ Smi operations work as expected. |
122 int64_t test_numbers[] = { | 122 int64_t test_numbers[] = { |
123 0, 1, -1, 127, 128, -128, -129, 255, 256, -256, -257, | 123 0, 1, -1, 127, 128, -128, -129, 255, 256, -256, -257, |
124 Smi::kMaxValue, static_cast<int64_t>(Smi::kMaxValue) + 1, | 124 Smi::kMaxValue, static_cast<int64_t>(Smi::kMaxValue) + 1, |
125 Smi::kMinValue, static_cast<int64_t>(Smi::kMinValue) - 1 | 125 Smi::kMinValue, static_cast<int64_t>(Smi::kMinValue) - 1 |
126 }; | 126 }; |
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1353 true)); | 1353 true)); |
1354 CHECK(buffer); | 1354 CHECK(buffer); |
1355 Isolate* isolate = CcTest::i_isolate(); | 1355 Isolate* isolate = CcTest::i_isolate(); |
1356 HandleScope handles(isolate); | 1356 HandleScope handles(isolate); |
1357 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size)); | 1357 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size)); |
1358 | 1358 |
1359 MacroAssembler* masm = &assembler; | 1359 MacroAssembler* masm = &assembler; |
1360 EntryCode(masm); | 1360 EntryCode(masm); |
1361 Label exit; | 1361 Label exit; |
1362 | 1362 |
1363 __ push(r14); | 1363 __ pushq(r14); |
1364 __ push(r15); | 1364 __ pushq(r15); |
1365 TestSmiDiv(masm, &exit, 0x10, 1, 1); | 1365 TestSmiDiv(masm, &exit, 0x10, 1, 1); |
1366 TestSmiDiv(masm, &exit, 0x20, 1, 0); | 1366 TestSmiDiv(masm, &exit, 0x20, 1, 0); |
1367 TestSmiDiv(masm, &exit, 0x30, -1, 0); | 1367 TestSmiDiv(masm, &exit, 0x30, -1, 0); |
1368 TestSmiDiv(masm, &exit, 0x40, 0, 1); | 1368 TestSmiDiv(masm, &exit, 0x40, 0, 1); |
1369 TestSmiDiv(masm, &exit, 0x50, 0, -1); | 1369 TestSmiDiv(masm, &exit, 0x50, 0, -1); |
1370 TestSmiDiv(masm, &exit, 0x60, 4, 2); | 1370 TestSmiDiv(masm, &exit, 0x60, 4, 2); |
1371 TestSmiDiv(masm, &exit, 0x70, -4, 2); | 1371 TestSmiDiv(masm, &exit, 0x70, -4, 2); |
1372 TestSmiDiv(masm, &exit, 0x80, 4, -2); | 1372 TestSmiDiv(masm, &exit, 0x80, 4, -2); |
1373 TestSmiDiv(masm, &exit, 0x90, -4, -2); | 1373 TestSmiDiv(masm, &exit, 0x90, -4, -2); |
1374 TestSmiDiv(masm, &exit, 0xa0, 3, 2); | 1374 TestSmiDiv(masm, &exit, 0xa0, 3, 2); |
1375 TestSmiDiv(masm, &exit, 0xb0, 3, 4); | 1375 TestSmiDiv(masm, &exit, 0xb0, 3, 4); |
1376 TestSmiDiv(masm, &exit, 0xc0, 1, Smi::kMaxValue); | 1376 TestSmiDiv(masm, &exit, 0xc0, 1, Smi::kMaxValue); |
1377 TestSmiDiv(masm, &exit, 0xd0, -1, Smi::kMaxValue); | 1377 TestSmiDiv(masm, &exit, 0xd0, -1, Smi::kMaxValue); |
1378 TestSmiDiv(masm, &exit, 0xe0, Smi::kMaxValue, 1); | 1378 TestSmiDiv(masm, &exit, 0xe0, Smi::kMaxValue, 1); |
1379 TestSmiDiv(masm, &exit, 0xf0, Smi::kMaxValue, Smi::kMaxValue); | 1379 TestSmiDiv(masm, &exit, 0xf0, Smi::kMaxValue, Smi::kMaxValue); |
1380 TestSmiDiv(masm, &exit, 0x100, Smi::kMaxValue, -Smi::kMaxValue); | 1380 TestSmiDiv(masm, &exit, 0x100, Smi::kMaxValue, -Smi::kMaxValue); |
1381 TestSmiDiv(masm, &exit, 0x110, Smi::kMaxValue, -1); | 1381 TestSmiDiv(masm, &exit, 0x110, Smi::kMaxValue, -1); |
1382 TestSmiDiv(masm, &exit, 0x120, Smi::kMinValue, 1); | 1382 TestSmiDiv(masm, &exit, 0x120, Smi::kMinValue, 1); |
1383 TestSmiDiv(masm, &exit, 0x130, Smi::kMinValue, Smi::kMinValue); | 1383 TestSmiDiv(masm, &exit, 0x130, Smi::kMinValue, Smi::kMinValue); |
1384 TestSmiDiv(masm, &exit, 0x140, Smi::kMinValue, -1); | 1384 TestSmiDiv(masm, &exit, 0x140, Smi::kMinValue, -1); |
1385 | 1385 |
1386 __ xor_(r15, r15); // Success. | 1386 __ xor_(r15, r15); // Success. |
1387 __ bind(&exit); | 1387 __ bind(&exit); |
1388 __ movq(rax, r15); | 1388 __ movq(rax, r15); |
1389 __ pop(r15); | 1389 __ popq(r15); |
1390 __ pop(r14); | 1390 __ popq(r14); |
1391 ExitCode(masm); | 1391 ExitCode(masm); |
1392 __ ret(0); | 1392 __ ret(0); |
1393 | 1393 |
1394 CodeDesc desc; | 1394 CodeDesc desc; |
1395 masm->GetCode(&desc); | 1395 masm->GetCode(&desc); |
1396 // Call the function from C++. | 1396 // Call the function from C++. |
1397 int result = FUNCTION_CAST<F0>(buffer)(); | 1397 int result = FUNCTION_CAST<F0>(buffer)(); |
1398 CHECK_EQ(0, result); | 1398 CHECK_EQ(0, result); |
1399 } | 1399 } |
1400 | 1400 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 true)); | 1463 true)); |
1464 CHECK(buffer); | 1464 CHECK(buffer); |
1465 Isolate* isolate = CcTest::i_isolate(); | 1465 Isolate* isolate = CcTest::i_isolate(); |
1466 HandleScope handles(isolate); | 1466 HandleScope handles(isolate); |
1467 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size)); | 1467 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size)); |
1468 | 1468 |
1469 MacroAssembler* masm = &assembler; | 1469 MacroAssembler* masm = &assembler; |
1470 EntryCode(masm); | 1470 EntryCode(masm); |
1471 Label exit; | 1471 Label exit; |
1472 | 1472 |
1473 __ push(r14); | 1473 __ pushq(r14); |
1474 __ push(r15); | 1474 __ pushq(r15); |
1475 TestSmiMod(masm, &exit, 0x10, 1, 1); | 1475 TestSmiMod(masm, &exit, 0x10, 1, 1); |
1476 TestSmiMod(masm, &exit, 0x20, 1, 0); | 1476 TestSmiMod(masm, &exit, 0x20, 1, 0); |
1477 TestSmiMod(masm, &exit, 0x30, -1, 0); | 1477 TestSmiMod(masm, &exit, 0x30, -1, 0); |
1478 TestSmiMod(masm, &exit, 0x40, 0, 1); | 1478 TestSmiMod(masm, &exit, 0x40, 0, 1); |
1479 TestSmiMod(masm, &exit, 0x50, 0, -1); | 1479 TestSmiMod(masm, &exit, 0x50, 0, -1); |
1480 TestSmiMod(masm, &exit, 0x60, 4, 2); | 1480 TestSmiMod(masm, &exit, 0x60, 4, 2); |
1481 TestSmiMod(masm, &exit, 0x70, -4, 2); | 1481 TestSmiMod(masm, &exit, 0x70, -4, 2); |
1482 TestSmiMod(masm, &exit, 0x80, 4, -2); | 1482 TestSmiMod(masm, &exit, 0x80, 4, -2); |
1483 TestSmiMod(masm, &exit, 0x90, -4, -2); | 1483 TestSmiMod(masm, &exit, 0x90, -4, -2); |
1484 TestSmiMod(masm, &exit, 0xa0, 3, 2); | 1484 TestSmiMod(masm, &exit, 0xa0, 3, 2); |
1485 TestSmiMod(masm, &exit, 0xb0, 3, 4); | 1485 TestSmiMod(masm, &exit, 0xb0, 3, 4); |
1486 TestSmiMod(masm, &exit, 0xc0, 1, Smi::kMaxValue); | 1486 TestSmiMod(masm, &exit, 0xc0, 1, Smi::kMaxValue); |
1487 TestSmiMod(masm, &exit, 0xd0, -1, Smi::kMaxValue); | 1487 TestSmiMod(masm, &exit, 0xd0, -1, Smi::kMaxValue); |
1488 TestSmiMod(masm, &exit, 0xe0, Smi::kMaxValue, 1); | 1488 TestSmiMod(masm, &exit, 0xe0, Smi::kMaxValue, 1); |
1489 TestSmiMod(masm, &exit, 0xf0, Smi::kMaxValue, Smi::kMaxValue); | 1489 TestSmiMod(masm, &exit, 0xf0, Smi::kMaxValue, Smi::kMaxValue); |
1490 TestSmiMod(masm, &exit, 0x100, Smi::kMaxValue, -Smi::kMaxValue); | 1490 TestSmiMod(masm, &exit, 0x100, Smi::kMaxValue, -Smi::kMaxValue); |
1491 TestSmiMod(masm, &exit, 0x110, Smi::kMaxValue, -1); | 1491 TestSmiMod(masm, &exit, 0x110, Smi::kMaxValue, -1); |
1492 TestSmiMod(masm, &exit, 0x120, Smi::kMinValue, 1); | 1492 TestSmiMod(masm, &exit, 0x120, Smi::kMinValue, 1); |
1493 TestSmiMod(masm, &exit, 0x130, Smi::kMinValue, Smi::kMinValue); | 1493 TestSmiMod(masm, &exit, 0x130, Smi::kMinValue, Smi::kMinValue); |
1494 TestSmiMod(masm, &exit, 0x140, Smi::kMinValue, -1); | 1494 TestSmiMod(masm, &exit, 0x140, Smi::kMinValue, -1); |
1495 | 1495 |
1496 __ xor_(r15, r15); // Success. | 1496 __ xor_(r15, r15); // Success. |
1497 __ bind(&exit); | 1497 __ bind(&exit); |
1498 __ movq(rax, r15); | 1498 __ movq(rax, r15); |
1499 __ pop(r15); | 1499 __ popq(r15); |
1500 __ pop(r14); | 1500 __ popq(r14); |
1501 ExitCode(masm); | 1501 ExitCode(masm); |
1502 __ ret(0); | 1502 __ ret(0); |
1503 | 1503 |
1504 CodeDesc desc; | 1504 CodeDesc desc; |
1505 masm->GetCode(&desc); | 1505 masm->GetCode(&desc); |
1506 // Call the function from C++. | 1506 // Call the function from C++. |
1507 int result = FUNCTION_CAST<F0>(buffer)(); | 1507 int result = FUNCTION_CAST<F0>(buffer)(); |
1508 CHECK_EQ(0, result); | 1508 CHECK_EQ(0, result); |
1509 } | 1509 } |
1510 | 1510 |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2317 true)); | 2317 true)); |
2318 CHECK(buffer); | 2318 CHECK(buffer); |
2319 Isolate* isolate = CcTest::i_isolate(); | 2319 Isolate* isolate = CcTest::i_isolate(); |
2320 HandleScope handles(isolate); | 2320 HandleScope handles(isolate); |
2321 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size)); | 2321 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size)); |
2322 | 2322 |
2323 MacroAssembler* masm = &assembler; | 2323 MacroAssembler* masm = &assembler; |
2324 Label exit; | 2324 Label exit; |
2325 | 2325 |
2326 EntryCode(masm); | 2326 EntryCode(masm); |
2327 __ push(r13); | 2327 __ pushq(r13); |
2328 __ push(r14); | 2328 __ pushq(r14); |
2329 __ push(rbx); | 2329 __ pushq(rbx); |
2330 __ push(rbp); | 2330 __ pushq(rbp); |
2331 __ push(Immediate(0x100)); // <-- rbp | 2331 __ pushq(Immediate(0x100)); // <-- rbp |
2332 __ movq(rbp, rsp); | 2332 __ movq(rbp, rsp); |
2333 __ push(Immediate(0x101)); | 2333 __ pushq(Immediate(0x101)); |
2334 __ push(Immediate(0x102)); | 2334 __ pushq(Immediate(0x102)); |
2335 __ push(Immediate(0x103)); | 2335 __ pushq(Immediate(0x103)); |
2336 __ push(Immediate(0x104)); | 2336 __ pushq(Immediate(0x104)); |
2337 __ push(Immediate(0x105)); // <-- rbx | 2337 __ pushq(Immediate(0x105)); // <-- rbx |
2338 __ push(Immediate(0x106)); | 2338 __ pushq(Immediate(0x106)); |
2339 __ push(Immediate(0x107)); | 2339 __ pushq(Immediate(0x107)); |
2340 __ push(Immediate(0x108)); | 2340 __ pushq(Immediate(0x108)); |
2341 __ push(Immediate(0x109)); // <-- rsp | 2341 __ pushq(Immediate(0x109)); // <-- rsp |
2342 // rbp = rsp[9] | 2342 // rbp = rsp[9] |
2343 // r15 = rsp[3] | 2343 // r15 = rsp[3] |
2344 // rbx = rsp[5] | 2344 // rbx = rsp[5] |
2345 // r13 = rsp[7] | 2345 // r13 = rsp[7] |
2346 __ lea(r14, Operand(rsp, 3 * kPointerSize)); | 2346 __ lea(r14, Operand(rsp, 3 * kPointerSize)); |
2347 __ lea(r13, Operand(rbp, -3 * kPointerSize)); | 2347 __ lea(r13, Operand(rbp, -3 * kPointerSize)); |
2348 __ lea(rbx, Operand(rbp, -5 * kPointerSize)); | 2348 __ lea(rbx, Operand(rbp, -5 * kPointerSize)); |
2349 __ movl(rcx, Immediate(2)); | 2349 __ movl(rcx, Immediate(2)); |
2350 __ Move(r8, reinterpret_cast<Address>(&data[128]), RelocInfo::NONE64); | 2350 __ Move(r8, reinterpret_cast<Address>(&data[128]), RelocInfo::NONE64); |
2351 __ movl(rax, Immediate(1)); | 2351 __ movl(rax, Immediate(1)); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2637 __ movl(rdx, Operand(r80, -254)); | 2637 __ movl(rdx, Operand(r80, -254)); |
2638 __ cmpl(rdx, Immediate(0x41414040)); | 2638 __ cmpl(rdx, Immediate(0x41414040)); |
2639 __ j(not_equal, &exit); | 2639 __ j(not_equal, &exit); |
2640 __ incq(rax); | 2640 __ incq(rax); |
2641 | 2641 |
2642 // Success. | 2642 // Success. |
2643 | 2643 |
2644 __ movl(rax, Immediate(0)); | 2644 __ movl(rax, Immediate(0)); |
2645 __ bind(&exit); | 2645 __ bind(&exit); |
2646 __ lea(rsp, Operand(rbp, kPointerSize)); | 2646 __ lea(rsp, Operand(rbp, kPointerSize)); |
2647 __ pop(rbp); | 2647 __ popq(rbp); |
2648 __ pop(rbx); | 2648 __ popq(rbx); |
2649 __ pop(r14); | 2649 __ popq(r14); |
2650 __ pop(r13); | 2650 __ popq(r13); |
2651 ExitCode(masm); | 2651 ExitCode(masm); |
2652 __ ret(0); | 2652 __ ret(0); |
2653 | 2653 |
2654 | 2654 |
2655 CodeDesc desc; | 2655 CodeDesc desc; |
2656 masm->GetCode(&desc); | 2656 masm->GetCode(&desc); |
2657 // Call the function from C++. | 2657 // Call the function from C++. |
2658 int result = FUNCTION_CAST<F0>(buffer)(); | 2658 int result = FUNCTION_CAST<F0>(buffer)(); |
2659 CHECK_EQ(0, result); | 2659 CHECK_EQ(0, result); |
2660 } | 2660 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2804 | 2804 |
2805 CodeDesc desc; | 2805 CodeDesc desc; |
2806 masm->GetCode(&desc); | 2806 masm->GetCode(&desc); |
2807 // Call the function from C++. | 2807 // Call the function from C++. |
2808 int result = FUNCTION_CAST<F0>(buffer)(); | 2808 int result = FUNCTION_CAST<F0>(buffer)(); |
2809 CHECK_EQ(0, result); | 2809 CHECK_EQ(0, result); |
2810 } | 2810 } |
2811 | 2811 |
2812 | 2812 |
2813 #undef __ | 2813 #undef __ |
OLD | NEW |