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

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

Issue 14784011: Fixes for integer division on ARM hardware so that assembler tests pass. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 months 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_arm.cc ('k') | runtime/vm/constants_arm.h » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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_ARM) 6 #if defined(TARGET_ARCH_ARM)
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 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 EXPECT(test != NULL); 1382 EXPECT(test != NULL);
1383 typedef int (*Tst)(); 1383 typedef int (*Tst)();
1384 EXPECT_EQ(42, EXECUTE_TEST_CODE_INT32(Tst, test->entry())); 1384 EXPECT_EQ(42, EXECUTE_TEST_CODE_INT32(Tst, test->entry()));
1385 } 1385 }
1386 1386
1387 1387
1388 // Check that assembler mrc instruction encoding, and simulator decoding 1388 // Check that assembler mrc instruction encoding, and simulator decoding
1389 // are in agreement. 1389 // are in agreement.
1390 #if defined(USING_SIMULATOR) 1390 #if defined(USING_SIMULATOR)
1391 ASSEMBLER_TEST_GENERATE(MrcHaveDiv, assembler) { 1391 ASSEMBLER_TEST_GENERATE(MrcHaveDiv, assembler) {
1392 __ mrc(R0, 15, 0, 0, 2, 0); 1392 __ mrc(R0, 15, 0, 0, 2, 0); // Accesses ID_ISAR0.
1393 // Bits 24 - 27 describe the presence of integer division. Bit 24 is set if
1394 // it is available in the Thumb instruction set. Bit 25 is set if it is
1395 // available both in Thumb and in the ARM instruction set.
1393 __ Lsr(R0, R0, 24); 1396 __ Lsr(R0, R0, 24);
1394 __ and_(R0, R0, ShifterOperand(0xf)); 1397 __ and_(R0, R0, ShifterOperand(0xf));
1395 __ mov(PC, ShifterOperand(LR)); 1398 __ mov(PC, ShifterOperand(LR));
1396 } 1399 }
1397 1400
1398 1401
1399 ASSEMBLER_TEST_RUN(MrcHaveDiv, test) { 1402 ASSEMBLER_TEST_RUN(MrcHaveDiv, test) {
1400 EXPECT(test != NULL); 1403 EXPECT(test != NULL);
1401 typedef int (*Tst)(); 1404 typedef int (*Tst)();
1402 bool b = CPUFeatures::integer_division_supported(); 1405 bool b = CPUFeatures::integer_division_supported();
1403 CPUFeatures::set_integer_division_supported(true); 1406 CPUFeatures::set_integer_division_supported(true);
1404 EXPECT_LT(0, EXECUTE_TEST_CODE_INT32(Tst, test->entry())); 1407 EXPECT_EQ(2, EXECUTE_TEST_CODE_INT32(Tst, test->entry()));
1405 CPUFeatures::set_integer_division_supported(b); 1408 CPUFeatures::set_integer_division_supported(b);
1406 } 1409 }
1407 1410
1408 1411
1409 ASSEMBLER_TEST_GENERATE(MrcNoDiv, assembler) { 1412 ASSEMBLER_TEST_GENERATE(MrcNoDiv, assembler) {
1410 __ mrc(R0, 15, 0, 0, 2, 0); 1413 __ mrc(R0, 15, 0, 0, 2, 0);
1411 __ Lsr(R0, R0, 24); 1414 __ Lsr(R0, R0, 24);
1412 __ and_(R0, R0, ShifterOperand(0xf)); 1415 __ and_(R0, R0, ShifterOperand(0xf));
1413 __ mov(PC, ShifterOperand(LR)); 1416 __ mov(PC, ShifterOperand(LR));
1414 } 1417 }
1415 1418
1416 1419
1417 ASSEMBLER_TEST_RUN(MrcNoDiv, test) { 1420 ASSEMBLER_TEST_RUN(MrcNoDiv, test) {
1418 EXPECT(test != NULL); 1421 EXPECT(test != NULL);
1419 typedef int (*Tst)(); 1422 typedef int (*Tst)();
1420 bool b = CPUFeatures::integer_division_supported(); 1423 bool b = CPUFeatures::integer_division_supported();
1421 CPUFeatures::set_integer_division_supported(false); 1424 CPUFeatures::set_integer_division_supported(false);
1422 EXPECT_EQ(0, EXECUTE_TEST_CODE_INT32(Tst, test->entry())); 1425 EXPECT_EQ(0, EXECUTE_TEST_CODE_INT32(Tst, test->entry()));
1423 CPUFeatures::set_integer_division_supported(b); 1426 CPUFeatures::set_integer_division_supported(b);
1424 } 1427 }
1425 #endif // defined(USING_SIMULATOR)
1426 1428
1427 1429
1428 ASSEMBLER_TEST_GENERATE(MrcReal, assembler) { 1430 ASSEMBLER_TEST_GENERATE(MrcReal, assembler) {
1429 __ mrc(R0, 15, 0, 0, 2, 0); 1431 __ mrc(R0, 15, 0, 0, 2, 0);
1430 __ Lsr(R0, R0, 24); 1432 __ Lsr(R0, R0, 24);
1431 __ and_(R0, R0, ShifterOperand(0xf)); 1433 __ and_(R0, R0, ShifterOperand(0xf));
1432 __ mov(PC, ShifterOperand(LR)); 1434 __ mov(PC, ShifterOperand(LR));
1433 } 1435 }
1434 1436
1435 1437
1436 ASSEMBLER_TEST_RUN(MrcReal, test) { 1438 ASSEMBLER_TEST_RUN(MrcReal, test) {
1437 EXPECT(test != NULL); 1439 EXPECT(test != NULL);
1438 typedef int (*Tst)(); 1440 typedef int (*Tst)();
1439 bool have_div = CPUFeatures::integer_division_supported(); 1441 bool have_div = CPUFeatures::integer_division_supported();
1440 int32_t r = EXECUTE_TEST_CODE_INT32(Tst, test->entry()); 1442 int32_t r = EXECUTE_TEST_CODE_INT32(Tst, test->entry());
1441 if (have_div) { 1443 if (have_div) {
1442 EXPECT_LT(0, r); 1444 EXPECT_EQ(2, r);
1443 } else { 1445 } else {
1444 EXPECT_EQ(0, r); 1446 EXPECT_EQ(0, r);
1445 } 1447 }
1446 } 1448 }
1449 #endif // defined(USING_SIMULATOR)
1447 1450
1448 1451
1449 ASSEMBLER_TEST_GENERATE(Udiv, assembler) { 1452 ASSEMBLER_TEST_GENERATE(Udiv, assembler) {
1450 __ mov(R0, ShifterOperand(27)); 1453 if (CPUFeatures::integer_division_supported()) {
1451 __ mov(R1, ShifterOperand(9)); 1454 __ mov(R0, ShifterOperand(27));
1452 __ udiv(R2, R0, R1); 1455 __ mov(R1, ShifterOperand(9));
1453 __ Mov(R0, R2); 1456 __ udiv(R2, R0, R1);
1457 __ Mov(R0, R2);
1458 } else {
1459 __ mov(R0, ShifterOperand(3));
1460 }
1454 __ mov(PC, ShifterOperand(LR)); 1461 __ mov(PC, ShifterOperand(LR));
1455 } 1462 }
1456 1463
1457 1464
1458 ASSEMBLER_TEST_RUN(Udiv, test) { 1465 ASSEMBLER_TEST_RUN(Udiv, test) {
1459 EXPECT(test != NULL); 1466 EXPECT(test != NULL);
1460 typedef int (*Tst)(); 1467 typedef int (*Tst)();
1461 EXPECT_EQ(3, EXECUTE_TEST_CODE_INT32(Tst, test->entry())); 1468 EXPECT_EQ(3, EXECUTE_TEST_CODE_INT32(Tst, test->entry()));
1462 } 1469 }
1463 1470
1464 1471
1465 ASSEMBLER_TEST_GENERATE(Sdiv, assembler) { 1472 ASSEMBLER_TEST_GENERATE(Sdiv, assembler) {
1466 __ mov(R0, ShifterOperand(27)); 1473 if (CPUFeatures::integer_division_supported()) {
1467 __ LoadImmediate(R1, -9); 1474 __ mov(R0, ShifterOperand(27));
1468 __ sdiv(R2, R0, R1); 1475 __ LoadImmediate(R1, -9);
1469 __ Mov(R0, R2); 1476 __ sdiv(R2, R0, R1);
1477 __ Mov(R0, R2);
1478 } else {
1479 __ LoadImmediate(R0, -3);
1480 }
1470 __ mov(PC, ShifterOperand(LR)); 1481 __ mov(PC, ShifterOperand(LR));
1471 } 1482 }
1472 1483
1473 1484
1474 ASSEMBLER_TEST_RUN(Sdiv, test) { 1485 ASSEMBLER_TEST_RUN(Sdiv, test) {
1475 EXPECT(test != NULL); 1486 EXPECT(test != NULL);
1476 typedef int (*Tst)(); 1487 typedef int (*Tst)();
1477 EXPECT_EQ(-3, EXECUTE_TEST_CODE_INT32(Tst, test->entry())); 1488 EXPECT_EQ(-3, EXECUTE_TEST_CODE_INT32(Tst, test->entry()));
1478 } 1489 }
1479 1490
1480 1491
1481 ASSEMBLER_TEST_GENERATE(Udiv_zero, assembler) { 1492 ASSEMBLER_TEST_GENERATE(Udiv_zero, assembler) {
1482 __ mov(R0, ShifterOperand(27)); 1493 if (CPUFeatures::integer_division_supported()) {
1483 __ mov(R1, ShifterOperand(0)); 1494 __ mov(R0, ShifterOperand(27));
1484 __ udiv(R2, R0, R1); 1495 __ mov(R1, ShifterOperand(0));
1485 __ Mov(R0, R2); 1496 __ udiv(R2, R0, R1);
1497 __ Mov(R0, R2);
1498 } else {
1499 __ LoadImmediate(R0, 0);
1500 }
1486 __ mov(PC, ShifterOperand(LR)); 1501 __ mov(PC, ShifterOperand(LR));
1487 } 1502 }
1488 1503
1489 1504
1490 ASSEMBLER_TEST_RUN(Udiv_zero, test) { 1505 ASSEMBLER_TEST_RUN(Udiv_zero, test) {
1491 EXPECT(test != NULL); 1506 EXPECT(test != NULL);
1492 typedef int (*Tst)(); 1507 typedef int (*Tst)();
1493 EXPECT_EQ(0, EXECUTE_TEST_CODE_INT32(Tst, test->entry())); 1508 EXPECT_EQ(0, EXECUTE_TEST_CODE_INT32(Tst, test->entry()));
1494 } 1509 }
1495 1510
1496 1511
1497 ASSEMBLER_TEST_GENERATE(Sdiv_zero, assembler) { 1512 ASSEMBLER_TEST_GENERATE(Sdiv_zero, assembler) {
1498 __ mov(R0, ShifterOperand(27)); 1513 if (CPUFeatures::integer_division_supported()) {
1499 __ mov(R1, ShifterOperand(0)); 1514 __ mov(R0, ShifterOperand(27));
1500 __ udiv(R2, R0, R1); 1515 __ mov(R1, ShifterOperand(0));
1501 __ Mov(R0, R2); 1516 __ udiv(R2, R0, R1);
1517 __ Mov(R0, R2);
1518 } else {
1519 __ LoadImmediate(R0, 0);
1520 }
1502 __ mov(PC, ShifterOperand(LR)); 1521 __ mov(PC, ShifterOperand(LR));
1503 } 1522 }
1504 1523
1505 1524
1506 ASSEMBLER_TEST_RUN(Sdiv_zero, test) { 1525 ASSEMBLER_TEST_RUN(Sdiv_zero, test) {
1507 EXPECT(test != NULL); 1526 EXPECT(test != NULL);
1508 typedef int (*Tst)(); 1527 typedef int (*Tst)();
1509 EXPECT_EQ(0, EXECUTE_TEST_CODE_INT32(Tst, test->entry())); 1528 EXPECT_EQ(0, EXECUTE_TEST_CODE_INT32(Tst, test->entry()));
1510 } 1529 }
1511 1530
1512 1531
1513 ASSEMBLER_TEST_GENERATE(Udiv_corner, assembler) { 1532 ASSEMBLER_TEST_GENERATE(Udiv_corner, assembler) {
1514 __ LoadImmediate(R0, 0x80000000); 1533 if (CPUFeatures::integer_division_supported()) {
1515 __ LoadImmediate(R1, 0xffffffff); 1534 __ LoadImmediate(R0, 0x80000000);
1516 __ udiv(R2, R0, R1); 1535 __ LoadImmediate(R1, 0xffffffff);
1517 __ Mov(R0, R2); 1536 __ udiv(R2, R0, R1);
1537 __ Mov(R0, R2);
1538 } else {
1539 __ LoadImmediate(R0, 0);
1540 }
1518 __ mov(PC, ShifterOperand(LR)); 1541 __ mov(PC, ShifterOperand(LR));
1519 } 1542 }
1520 1543
1521 1544
1522 ASSEMBLER_TEST_RUN(Udiv_corner, test) { 1545 ASSEMBLER_TEST_RUN(Udiv_corner, test) {
1523 EXPECT(test != NULL); 1546 EXPECT(test != NULL);
1524 typedef int (*Tst)(); 1547 typedef int (*Tst)();
1525 EXPECT_EQ(0, EXECUTE_TEST_CODE_INT32(Tst, test->entry())); 1548 EXPECT_EQ(0, EXECUTE_TEST_CODE_INT32(Tst, test->entry()));
1526 } 1549 }
1527 1550
1528 1551
1529 ASSEMBLER_TEST_GENERATE(Sdiv_corner, assembler) { 1552 ASSEMBLER_TEST_GENERATE(Sdiv_corner, assembler) {
1530 __ LoadImmediate(R0, 0x80000000); 1553 if (CPUFeatures::integer_division_supported()) {
1531 __ LoadImmediate(R1, 0xffffffff); 1554 __ LoadImmediate(R0, 0x80000000);
1532 __ sdiv(R2, R0, R1); 1555 __ LoadImmediate(R1, 0xffffffff);
1533 __ Mov(R0, R2); 1556 __ sdiv(R2, R0, R1);
1557 __ Mov(R0, R2);
1558 } else {
1559 __ LoadImmediate(R0, 0x80000000);
1560 }
1534 __ mov(PC, ShifterOperand(LR)); 1561 __ mov(PC, ShifterOperand(LR));
1535 } 1562 }
1536 1563
1537 1564
1538 ASSEMBLER_TEST_RUN(Sdiv_corner, test) { 1565 ASSEMBLER_TEST_RUN(Sdiv_corner, test) {
1539 EXPECT(test != NULL); 1566 EXPECT(test != NULL);
1540 typedef int (*Tst)(); 1567 typedef int (*Tst)();
1541 EXPECT_EQ(static_cast<int32_t>(0x80000000), 1568 EXPECT_EQ(static_cast<int32_t>(0x80000000),
1542 EXECUTE_TEST_CODE_INT32(Tst, test->entry())); 1569 EXECUTE_TEST_CODE_INT32(Tst, test->entry()));
1543 } 1570 }
(...skipping 26 matching lines...) Expand all
1570 __ StoreIntoObject(R2, 1597 __ StoreIntoObject(R2,
1571 FieldAddress(R2, GrowableObjectArray::data_offset()), 1598 FieldAddress(R2, GrowableObjectArray::data_offset()),
1572 R1); 1599 R1);
1573 __ PopList((1 << CTX) | (1 << LR)); 1600 __ PopList((1 << CTX) | (1 << LR));
1574 __ Ret(); 1601 __ Ret();
1575 } 1602 }
1576 1603
1577 } // namespace dart 1604 } // namespace dart
1578 1605
1579 #endif // defined TARGET_ARCH_ARM 1606 #endif // defined TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « runtime/vm/assembler_arm.cc ('k') | runtime/vm/constants_arm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698