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

Side by Side Diff: test/cctest/test-assembler-arm.cc

Issue 677483005: [turbofan] Implement the correct semantics for integer division/modulus. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixes and tests Created 6 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 | « src/compiler/machine-operator-reducer.cc ('k') | test/unittests/base/bits-unittest.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 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 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 1435
1436 1436
1437 #define TEST_SDIV(expected_, dividend_, divisor_) \ 1437 #define TEST_SDIV(expected_, dividend_, divisor_) \
1438 t.dividend = dividend_; \ 1438 t.dividend = dividend_; \
1439 t.divisor = divisor_; \ 1439 t.divisor = divisor_; \
1440 t.result = 0; \ 1440 t.result = 0; \
1441 dummy = CALL_GENERATED_CODE(f, &t, 0, 0, 0, 0); \ 1441 dummy = CALL_GENERATED_CODE(f, &t, 0, 0, 0, 0); \
1442 CHECK_EQ(expected_, t.result); 1442 CHECK_EQ(expected_, t.result);
1443 1443
1444 1444
1445 TEST(18) { 1445 TEST(sdiv) {
1446 // Test the sdiv. 1446 // Test the sdiv.
1447 CcTest::InitializeVM(); 1447 CcTest::InitializeVM();
1448 Isolate* isolate = CcTest::i_isolate(); 1448 Isolate* isolate = CcTest::i_isolate();
1449 HandleScope scope(isolate); 1449 HandleScope scope(isolate);
1450 Assembler assm(isolate, NULL, 0);
1450 1451
1451 typedef struct { 1452 struct T {
1452 uint32_t dividend; 1453 int32_t dividend;
1453 uint32_t divisor; 1454 int32_t divisor;
1454 uint32_t result; 1455 int32_t result;
1455 } T; 1456 } t;
1456 T t;
1457
1458 Assembler assm(isolate, NULL, 0);
1459 1457
1460 if (CpuFeatures::IsSupported(SUDIV)) { 1458 if (CpuFeatures::IsSupported(SUDIV)) {
1461 CpuFeatureScope scope(&assm, SUDIV); 1459 CpuFeatureScope scope(&assm, SUDIV);
1462 1460
1463 __ mov(r3, Operand(r0)); 1461 __ mov(r3, Operand(r0));
1464 1462
1465 __ ldr(r0, MemOperand(r3, OFFSET_OF(T, dividend))); 1463 __ ldr(r0, MemOperand(r3, OFFSET_OF(T, dividend)));
1466 __ ldr(r1, MemOperand(r3, OFFSET_OF(T, divisor))); 1464 __ ldr(r1, MemOperand(r3, OFFSET_OF(T, divisor)));
1467 1465
1468 __ sdiv(r2, r0, r1); 1466 __ sdiv(r2, r0, r1);
1469 __ str(r2, MemOperand(r3, OFFSET_OF(T, result))); 1467 __ str(r2, MemOperand(r3, OFFSET_OF(T, result)));
1470 1468
1471 __ bx(lr); 1469 __ bx(lr);
1472 1470
1473 CodeDesc desc; 1471 CodeDesc desc;
1474 assm.GetCode(&desc); 1472 assm.GetCode(&desc);
1475 Handle<Code> code = isolate->factory()->NewCode( 1473 Handle<Code> code = isolate->factory()->NewCode(
1476 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); 1474 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
1477 #ifdef DEBUG 1475 #ifdef DEBUG
1478 OFStream os(stdout); 1476 OFStream os(stdout);
1479 code->Print(os); 1477 code->Print(os);
1480 #endif 1478 #endif
1481 F3 f = FUNCTION_CAST<F3>(code->entry()); 1479 F3 f = FUNCTION_CAST<F3>(code->entry());
1482 Object* dummy; 1480 Object* dummy;
1481 TEST_SDIV(0, kMinInt, 0);
1482 TEST_SDIV(0, 1024, 0);
1483 TEST_SDIV(1073741824, kMinInt, -2); 1483 TEST_SDIV(1073741824, kMinInt, -2);
1484 TEST_SDIV(kMinInt, kMinInt, -1); 1484 TEST_SDIV(kMinInt, kMinInt, -1);
1485 TEST_SDIV(5, 10, 2); 1485 TEST_SDIV(5, 10, 2);
1486 TEST_SDIV(3, 10, 3); 1486 TEST_SDIV(3, 10, 3);
1487 TEST_SDIV(-5, 10, -2); 1487 TEST_SDIV(-5, 10, -2);
1488 TEST_SDIV(-3, 10, -3); 1488 TEST_SDIV(-3, 10, -3);
1489 TEST_SDIV(-5, -10, 2); 1489 TEST_SDIV(-5, -10, 2);
1490 TEST_SDIV(-3, -10, 3); 1490 TEST_SDIV(-3, -10, 3);
1491 TEST_SDIV(5, -10, -2); 1491 TEST_SDIV(5, -10, -2);
1492 TEST_SDIV(3, -10, -3); 1492 TEST_SDIV(3, -10, -3);
1493 USE(dummy); 1493 USE(dummy);
1494 } 1494 }
1495 } 1495 }
1496 1496
1497 1497
1498 #undef TEST_SDIV 1498 #undef TEST_SDIV
1499 1499
1500 1500
1501 #define TEST_UDIV(expected_, dividend_, divisor_) \
1502 t.dividend = dividend_; \
1503 t.divisor = divisor_; \
1504 t.result = 0; \
1505 dummy = CALL_GENERATED_CODE(f, &t, 0, 0, 0, 0); \
1506 CHECK_EQ(expected_, t.result);
1507
1508
1509 TEST(udiv) {
1510 // Test the udiv.
1511 CcTest::InitializeVM();
1512 Isolate* isolate = CcTest::i_isolate();
1513 HandleScope scope(isolate);
1514 Assembler assm(isolate, NULL, 0);
1515
1516 struct T {
1517 uint32_t dividend;
1518 uint32_t divisor;
1519 uint32_t result;
1520 } t;
1521
1522 if (CpuFeatures::IsSupported(SUDIV)) {
1523 CpuFeatureScope scope(&assm, SUDIV);
1524
1525 __ mov(r3, Operand(r0));
1526
1527 __ ldr(r0, MemOperand(r3, OFFSET_OF(T, dividend)));
1528 __ ldr(r1, MemOperand(r3, OFFSET_OF(T, divisor)));
1529
1530 __ sdiv(r2, r0, r1);
1531 __ str(r2, MemOperand(r3, OFFSET_OF(T, result)));
1532
1533 __ bx(lr);
1534
1535 CodeDesc desc;
1536 assm.GetCode(&desc);
1537 Handle<Code> code = isolate->factory()->NewCode(
1538 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
1539 #ifdef DEBUG
1540 OFStream os(stdout);
1541 code->Print(os);
1542 #endif
1543 F3 f = FUNCTION_CAST<F3>(code->entry());
1544 Object* dummy;
1545 TEST_UDIV(0, 0, 0);
1546 TEST_UDIV(0, 1024, 0);
1547 TEST_UDIV(5, 10, 2);
1548 TEST_UDIV(3, 10, 3);
1549 USE(dummy);
1550 }
1551 }
1552
1553
1554 #undef TEST_UDIV
1555
1556
1501 TEST(smmla) { 1557 TEST(smmla) {
1502 CcTest::InitializeVM(); 1558 CcTest::InitializeVM();
1503 Isolate* const isolate = CcTest::i_isolate(); 1559 Isolate* const isolate = CcTest::i_isolate();
1504 HandleScope scope(isolate); 1560 HandleScope scope(isolate);
1505 RandomNumberGenerator* const rng = isolate->random_number_generator(); 1561 RandomNumberGenerator* const rng = isolate->random_number_generator();
1506 Assembler assm(isolate, nullptr, 0); 1562 Assembler assm(isolate, nullptr, 0);
1507 __ smmla(r1, r1, r2, r3); 1563 __ smmla(r1, r1, r2, r3);
1508 __ str(r1, MemOperand(r0)); 1564 __ str(r1, MemOperand(r0));
1509 __ bx(lr); 1565 __ bx(lr);
1510 CodeDesc desc; 1566 CodeDesc desc;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 assm.GetCode(&desc); 1670 assm.GetCode(&desc);
1615 Handle<Code> code = isolate->factory()->NewCode( 1671 Handle<Code> code = isolate->factory()->NewCode(
1616 desc, Code::ComputeFlags(Code::STUB), code_object); 1672 desc, Code::ComputeFlags(Code::STUB), code_object);
1617 F1 f = FUNCTION_CAST<F1>(code->entry()); 1673 F1 f = FUNCTION_CAST<F1>(code->entry());
1618 int res = reinterpret_cast<int>(CALL_GENERATED_CODE(f, 21, 0, 0, 0, 0)); 1674 int res = reinterpret_cast<int>(CALL_GENERATED_CODE(f, 21, 0, 0, 0, 0));
1619 ::printf("f() = %d\n", res); 1675 ::printf("f() = %d\n", res);
1620 CHECK_EQ(42, res); 1676 CHECK_EQ(42, res);
1621 } 1677 }
1622 1678
1623 #undef __ 1679 #undef __
OLDNEW
« no previous file with comments | « src/compiler/machine-operator-reducer.cc ('k') | test/unittests/base/bits-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698