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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
| 28 #include <iostream> // NOLINT(readability/streams) |
| 29 |
28 #include "src/v8.h" | 30 #include "src/v8.h" |
29 | 31 |
30 #include "src/disassembler.h" | 32 #include "src/disassembler.h" |
31 #include "src/factory.h" | 33 #include "src/factory.h" |
32 #include "src/macro-assembler.h" | 34 #include "src/macro-assembler.h" |
33 #include "src/mips64/macro-assembler-mips64.h" | 35 #include "src/mips64/macro-assembler-mips64.h" |
34 #include "src/mips64/simulator-mips64.h" | 36 #include "src/mips64/simulator-mips64.h" |
35 | 37 |
36 #include "test/cctest/cctest.h" | 38 #include "test/cctest/cctest.h" |
37 | 39 |
(...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1376 | 1378 |
1377 // Signed data, 32 & 64. | 1379 // Signed data, 32 & 64. |
1378 CHECK_EQ(static_cast<int64_t>(0x33333333ffffbbccL), t.r3); | 1380 CHECK_EQ(static_cast<int64_t>(0x33333333ffffbbccL), t.r3); |
1379 CHECK_EQ(static_cast<int64_t>(0xffffffff0000bbccL), t.r4); | 1381 CHECK_EQ(static_cast<int64_t>(0xffffffff0000bbccL), t.r4); |
1380 | 1382 |
1381 // Signed data, 32 & 64. | 1383 // Signed data, 32 & 64. |
1382 CHECK_EQ(static_cast<int64_t>(0x55555555ffffffccL), t.r5); | 1384 CHECK_EQ(static_cast<int64_t>(0x55555555ffffffccL), t.r5); |
1383 CHECK_EQ(static_cast<int64_t>(0x000000003333bbccL), t.r6); | 1385 CHECK_EQ(static_cast<int64_t>(0x000000003333bbccL), t.r6); |
1384 } | 1386 } |
1385 | 1387 |
| 1388 |
| 1389 TEST(jump_tables1) { |
| 1390 // Test jump tables with forward jumps. |
| 1391 CcTest::InitializeVM(); |
| 1392 Isolate* isolate = CcTest::i_isolate(); |
| 1393 HandleScope scope(isolate); |
| 1394 Assembler assm(isolate, nullptr, 0); |
| 1395 |
| 1396 const int kNumCases = 512; |
| 1397 int values[kNumCases]; |
| 1398 isolate->random_number_generator()->NextBytes(values, sizeof(values)); |
| 1399 Label labels[kNumCases]; |
| 1400 |
| 1401 __ daddiu(sp, sp, -8); |
| 1402 __ sd(ra, MemOperand(sp)); |
| 1403 if ((assm.pc_offset() & 7) == 0) { |
| 1404 __ nop(); |
| 1405 } |
| 1406 |
| 1407 Label done; |
| 1408 { |
| 1409 PredictableCodeSizeScope predictable( |
| 1410 &assm, (kNumCases * 2 + 7) * Assembler::kInstrSize); |
| 1411 Label here; |
| 1412 |
| 1413 __ bal(&here); |
| 1414 __ nop(); |
| 1415 __ bind(&here); |
| 1416 __ dsll(at, a0, 3); |
| 1417 __ daddu(at, at, ra); |
| 1418 __ ld(at, MemOperand(at, 5 * Assembler::kInstrSize)); |
| 1419 __ jr(at); |
| 1420 __ nop(); |
| 1421 for (int i = 0; i < kNumCases; ++i) { |
| 1422 __ dd(&labels[i]); |
| 1423 } |
| 1424 } |
| 1425 |
| 1426 for (int i = 0; i < kNumCases; ++i) { |
| 1427 __ bind(&labels[i]); |
| 1428 __ lui(v0, (values[i] >> 16) & 0xffff); |
| 1429 __ ori(v0, v0, values[i] & 0xffff); |
| 1430 __ b(&done); |
| 1431 __ nop(); |
| 1432 } |
| 1433 |
| 1434 __ bind(&done); |
| 1435 __ ld(ra, MemOperand(sp)); |
| 1436 __ daddiu(sp, sp, 8); |
| 1437 __ jr(ra); |
| 1438 __ nop(); |
| 1439 |
| 1440 CodeDesc desc; |
| 1441 assm.GetCode(&desc); |
| 1442 Handle<Code> code = isolate->factory()->NewCode( |
| 1443 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 1444 #ifdef OBJECT_PRINT |
| 1445 code->Print(std::cout); |
| 1446 #endif |
| 1447 F1 f = FUNCTION_CAST<F1>(code->entry()); |
| 1448 for (int i = 0; i < kNumCases; ++i) { |
| 1449 int res = reinterpret_cast<int64_t>(CALL_GENERATED_CODE(f, i, 0, 0, 0, 0)); |
| 1450 ::printf("f(%d) = %d\n", i, res); |
| 1451 CHECK_EQ(values[i], static_cast<int>(res)); |
| 1452 } |
| 1453 } |
| 1454 |
| 1455 |
| 1456 TEST(jump_tables2) { |
| 1457 // Test jump tables with backward jumps. |
| 1458 CcTest::InitializeVM(); |
| 1459 Isolate* isolate = CcTest::i_isolate(); |
| 1460 HandleScope scope(isolate); |
| 1461 Assembler assm(isolate, nullptr, 0); |
| 1462 |
| 1463 const int kNumCases = 512; |
| 1464 int values[kNumCases]; |
| 1465 isolate->random_number_generator()->NextBytes(values, sizeof(values)); |
| 1466 Label labels[kNumCases]; |
| 1467 |
| 1468 __ daddiu(sp, sp, -8); |
| 1469 __ sd(ra, MemOperand(sp)); |
| 1470 |
| 1471 Label done, dispatch; |
| 1472 __ b(&dispatch); |
| 1473 __ nop(); |
| 1474 |
| 1475 for (int i = 0; i < kNumCases; ++i) { |
| 1476 __ bind(&labels[i]); |
| 1477 __ lui(v0, (values[i] >> 16) & 0xffff); |
| 1478 __ ori(v0, v0, values[i] & 0xffff); |
| 1479 __ b(&done); |
| 1480 __ nop(); |
| 1481 } |
| 1482 |
| 1483 if ((assm.pc_offset() & 7) == 0) { |
| 1484 __ nop(); |
| 1485 } |
| 1486 __ bind(&dispatch); |
| 1487 { |
| 1488 PredictableCodeSizeScope predictable( |
| 1489 &assm, (kNumCases * 2 + 7) * Assembler::kInstrSize); |
| 1490 Label here; |
| 1491 |
| 1492 __ bal(&here); |
| 1493 __ nop(); |
| 1494 __ bind(&here); |
| 1495 __ dsll(at, a0, 3); |
| 1496 __ daddu(at, at, ra); |
| 1497 __ ld(at, MemOperand(at, 5 * Assembler::kInstrSize)); |
| 1498 __ jr(at); |
| 1499 __ nop(); |
| 1500 for (int i = 0; i < kNumCases; ++i) { |
| 1501 __ dd(&labels[i]); |
| 1502 } |
| 1503 } |
| 1504 |
| 1505 __ bind(&done); |
| 1506 __ ld(ra, MemOperand(sp)); |
| 1507 __ daddiu(sp, sp, 8); |
| 1508 __ jr(ra); |
| 1509 __ nop(); |
| 1510 |
| 1511 CodeDesc desc; |
| 1512 assm.GetCode(&desc); |
| 1513 Handle<Code> code = isolate->factory()->NewCode( |
| 1514 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 1515 #ifdef OBJECT_PRINT |
| 1516 code->Print(std::cout); |
| 1517 #endif |
| 1518 F1 f = FUNCTION_CAST<F1>(code->entry()); |
| 1519 for (int i = 0; i < kNumCases; ++i) { |
| 1520 int res = reinterpret_cast<int64_t>(CALL_GENERATED_CODE(f, i, 0, 0, 0, 0)); |
| 1521 ::printf("f(%d) = %d\n", i, res); |
| 1522 CHECK_EQ(values[i], res); |
| 1523 } |
| 1524 } |
| 1525 |
| 1526 |
| 1527 TEST(jump_tables3) { |
| 1528 // Test jump tables with backward jumps and embedded heap objects. |
| 1529 CcTest::InitializeVM(); |
| 1530 Isolate* isolate = CcTest::i_isolate(); |
| 1531 HandleScope scope(isolate); |
| 1532 Assembler assm(isolate, nullptr, 0); |
| 1533 |
| 1534 const int kNumCases = 512; |
| 1535 Handle<Object> values[kNumCases]; |
| 1536 for (int i = 0; i < kNumCases; ++i) { |
| 1537 double value = isolate->random_number_generator()->NextDouble(); |
| 1538 values[i] = isolate->factory()->NewHeapNumber(value, IMMUTABLE, TENURED); |
| 1539 } |
| 1540 Label labels[kNumCases]; |
| 1541 Object* obj; |
| 1542 int64_t imm64; |
| 1543 |
| 1544 __ daddiu(sp, sp, -8); |
| 1545 __ sd(ra, MemOperand(sp)); |
| 1546 |
| 1547 Label done, dispatch; |
| 1548 __ b(&dispatch); |
| 1549 |
| 1550 |
| 1551 for (int i = 0; i < kNumCases; ++i) { |
| 1552 __ bind(&labels[i]); |
| 1553 obj = *values[i]; |
| 1554 imm64 = reinterpret_cast<intptr_t>(obj); |
| 1555 __ lui(v0, (imm64 >> 32) & kImm16Mask); |
| 1556 __ ori(v0, v0, (imm64 >> 16) & kImm16Mask); |
| 1557 __ dsll(v0, v0, 16); |
| 1558 __ ori(v0, v0, imm64 & kImm16Mask); |
| 1559 __ b(&done); |
| 1560 __ nop(); |
| 1561 } |
| 1562 |
| 1563 __ stop("chk"); |
| 1564 if ((assm.pc_offset() & 7) == 0) { |
| 1565 __ nop(); |
| 1566 } |
| 1567 __ bind(&dispatch); |
| 1568 { |
| 1569 PredictableCodeSizeScope predictable( |
| 1570 &assm, (kNumCases * 2 + 7) * Assembler::kInstrSize); |
| 1571 Label here; |
| 1572 |
| 1573 __ bal(&here); |
| 1574 __ nop(); |
| 1575 __ bind(&here); |
| 1576 __ dsll(at, a0, 3); |
| 1577 __ daddu(at, at, ra); |
| 1578 __ ld(at, MemOperand(at, 5 * Assembler::kInstrSize)); |
| 1579 __ jr(at); |
| 1580 __ nop(); |
| 1581 for (int i = 0; i < kNumCases; ++i) { |
| 1582 __ dd(&labels[i]); |
| 1583 } |
| 1584 } |
| 1585 |
| 1586 __ bind(&done); |
| 1587 __ ld(ra, MemOperand(sp)); |
| 1588 __ addiu(sp, sp, 8); |
| 1589 __ jr(ra); |
| 1590 __ nop(); |
| 1591 |
| 1592 CodeDesc desc; |
| 1593 assm.GetCode(&desc); |
| 1594 Handle<Code> code = isolate->factory()->NewCode( |
| 1595 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 1596 #ifdef OBJECT_PRINT |
| 1597 // code->Print(std::cout); |
| 1598 #endif |
| 1599 F1 f = FUNCTION_CAST<F1>(code->entry()); |
| 1600 for (int i = 0; i < kNumCases; ++i) { |
| 1601 Handle<Object> result(CALL_GENERATED_CODE(f, i, 0, 0, 0, 0), isolate); |
| 1602 #ifdef OBJECT_PRINT |
| 1603 ::printf("f(%d) = ", i); |
| 1604 result->Print(std::cout); |
| 1605 ::printf("\n"); |
| 1606 #endif |
| 1607 CHECK(values[i].is_identical_to(result)); |
| 1608 } |
| 1609 } |
| 1610 |
| 1611 |
1386 #undef __ | 1612 #undef __ |
OLD | NEW |