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

Side by Side Diff: src/arm/lithium-codegen-arm.cc

Issue 23536045: ARM: Tweak the integer division operation. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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 | « src/arm/lithium-arm.cc ('k') | test/mjsunit/lithium/DivI.js » ('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 1365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 // it gets implemented. 1376 // it gets implemented.
1377 __ mul(scratch, result, ip); 1377 __ mul(scratch, result, ip);
1378 __ sub(remainder, dividend, scratch); 1378 __ sub(remainder, dividend, scratch);
1379 } 1379 }
1380 } 1380 }
1381 } 1381 }
1382 1382
1383 1383
1384 void LCodeGen::DoDivI(LDivI* instr) { 1384 void LCodeGen::DoDivI(LDivI* instr) {
1385 if (instr->hydrogen()->HasPowerOf2Divisor()) { 1385 if (instr->hydrogen()->HasPowerOf2Divisor()) {
1386 Register dividend = ToRegister(instr->left()); 1386 const Register dividend = ToRegister(instr->left());
1387 const Register result = ToRegister(instr->result());
1387 int32_t divisor = instr->hydrogen()->right()->GetInteger32Constant(); 1388 int32_t divisor = instr->hydrogen()->right()->GetInteger32Constant();
1388 int32_t test_value = 0; 1389 int32_t test_value = 0;
1389 int32_t power = 0; 1390 int32_t power = 0;
1390 1391
1391 if (divisor > 0) { 1392 if (divisor > 0) {
1392 test_value = divisor - 1; 1393 test_value = divisor - 1;
1393 power = WhichPowerOf2(divisor); 1394 power = WhichPowerOf2(divisor);
1394 } else { 1395 } else {
1395 // Check for (0 / -x) that will produce negative zero. 1396 // Check for (0 / -x) that will produce negative zero.
1396 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { 1397 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
1397 __ tst(dividend, Operand(dividend)); 1398 __ cmp(dividend, Operand::Zero());
1398 DeoptimizeIf(eq, instr->environment()); 1399 DeoptimizeIf(eq, instr->environment());
1399 } 1400 }
1400 // Check for (kMinInt / -1). 1401 // Check for (kMinInt / -1).
1401 if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { 1402 if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
1402 __ cmp(dividend, Operand(kMinInt)); 1403 __ cmp(dividend, Operand(kMinInt));
1403 DeoptimizeIf(eq, instr->environment()); 1404 DeoptimizeIf(eq, instr->environment());
1404 } 1405 }
1405 test_value = - divisor - 1; 1406 test_value = - divisor - 1;
1406 power = WhichPowerOf2(-divisor); 1407 power = WhichPowerOf2(-divisor);
1407 } 1408 }
1408 1409
1409 if (test_value != 0) { 1410 if (test_value != 0) {
1410 if (instr->hydrogen()->CheckFlag( 1411 if (instr->hydrogen()->CheckFlag(
1411 HInstruction::kAllUsesTruncatingToInt32)) { 1412 HInstruction::kAllUsesTruncatingToInt32)) {
1412 __ cmp(dividend, Operand(0)); 1413 __ sub(result, dividend, Operand::Zero(), SetCC);
1413 __ rsb(dividend, dividend, Operand(0), LeaveCC, lt); 1414 __ rsb(result, result, Operand::Zero(), LeaveCC, lt);
1414 __ mov(dividend, Operand(dividend, ASR, power)); 1415 __ mov(result, Operand(result, ASR, power));
1415 if (divisor > 0) __ rsb(dividend, dividend, Operand(0), LeaveCC, lt); 1416 if (divisor > 0) __ rsb(result, result, Operand::Zero(), LeaveCC, lt);
1416 if (divisor < 0) __ rsb(dividend, dividend, Operand(0), LeaveCC, gt); 1417 if (divisor < 0) __ rsb(result, result, Operand::Zero(), LeaveCC, gt);
1417 return; // Don't fall through to "__ rsb" below. 1418 return; // Don't fall through to "__ rsb" below.
1418 } else { 1419 } else {
1419 // Deoptimize if remainder is not 0. 1420 // Deoptimize if remainder is not 0.
1420 __ tst(dividend, Operand(test_value)); 1421 __ tst(dividend, Operand(test_value));
1421 DeoptimizeIf(ne, instr->environment()); 1422 DeoptimizeIf(ne, instr->environment());
1422 __ mov(dividend, Operand(dividend, ASR, power)); 1423 __ mov(result, Operand(dividend, ASR, power));
1424 if (divisor < 0) __ rsb(result, result, Operand(0));
1425 }
1426 } else {
1427 if (divisor < 0) {
1428 __ rsb(result, dividend, Operand(0));
1429 } else {
1430 __ Move(result, dividend);
1423 } 1431 }
1424 } 1432 }
1425 if (divisor < 0) __ rsb(dividend, dividend, Operand(0));
1426 1433
1427 return; 1434 return;
1428 } 1435 }
1429 1436
1430 const Register left = ToRegister(instr->left()); 1437 const Register left = ToRegister(instr->left());
1431 const Register right = ToRegister(instr->right()); 1438 const Register right = ToRegister(instr->right());
1432 const Register result = ToRegister(instr->result()); 1439 const Register result = ToRegister(instr->result());
1433 1440
1434 // Check for x / 0. 1441 // Check for x / 0.
1435 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { 1442 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) {
1436 __ cmp(right, Operand::Zero()); 1443 __ cmp(right, Operand::Zero());
1437 DeoptimizeIf(eq, instr->environment()); 1444 DeoptimizeIf(eq, instr->environment());
1438 } 1445 }
1439 1446
1440 // Check for (0 / -x) that will produce negative zero. 1447 // Check for (0 / -x) that will produce negative zero.
1441 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { 1448 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
1442 Label left_not_zero; 1449 Label positive;
1450 if (!instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) {
1451 // Do the test only if it hadn't be done above.
1452 __ cmp(right, Operand::Zero());
1453 }
1454 __ b(pl, &positive);
1443 __ cmp(left, Operand::Zero()); 1455 __ cmp(left, Operand::Zero());
1444 __ b(ne, &left_not_zero); 1456 DeoptimizeIf(eq, instr->environment());
1445 __ cmp(right, Operand::Zero()); 1457 __ bind(&positive);
1446 DeoptimizeIf(mi, instr->environment());
1447 __ bind(&left_not_zero);
1448 } 1458 }
1449 1459
1450 // Check for (kMinInt / -1). 1460 // Check for (kMinInt / -1).
1451 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { 1461 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
1452 Label left_not_min_int; 1462 Label left_not_min_int;
1453 __ cmp(left, Operand(kMinInt)); 1463 __ cmp(left, Operand(kMinInt));
1454 __ b(ne, &left_not_min_int); 1464 __ b(ne, &left_not_min_int);
1455 __ cmp(right, Operand(-1)); 1465 __ cmp(right, Operand(-1));
1456 DeoptimizeIf(eq, instr->environment()); 1466 DeoptimizeIf(eq, instr->environment());
1457 __ bind(&left_not_min_int); 1467 __ bind(&left_not_min_int);
(...skipping 4329 matching lines...) Expand 10 before | Expand all | Expand 10 after
5787 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); 5797 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index));
5788 __ ldr(result, FieldMemOperand(scratch, 5798 __ ldr(result, FieldMemOperand(scratch,
5789 FixedArray::kHeaderSize - kPointerSize)); 5799 FixedArray::kHeaderSize - kPointerSize));
5790 __ bind(&done); 5800 __ bind(&done);
5791 } 5801 }
5792 5802
5793 5803
5794 #undef __ 5804 #undef __
5795 5805
5796 } } // namespace v8::internal 5806 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/lithium-arm.cc ('k') | test/mjsunit/lithium/DivI.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698