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 |
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 if (divisor > 1) { | 1469 if (divisor > 1) { |
1470 __ mov(result, Operand(dividend, ASR, shift)); | 1470 __ mov(result, Operand(dividend, ASR, shift)); |
1471 return; | 1471 return; |
1472 } | 1472 } |
1473 | 1473 |
1474 // If the divisor is negative, we have to negate and handle edge cases. | 1474 // If the divisor is negative, we have to negate and handle edge cases. |
1475 __ rsb(result, dividend, Operand::Zero(), SetCC); | 1475 __ rsb(result, dividend, Operand::Zero(), SetCC); |
1476 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1476 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1477 DeoptimizeIf(eq, instr->environment()); | 1477 DeoptimizeIf(eq, instr->environment()); |
1478 } | 1478 } |
1479 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { | 1479 |
1480 // Note that we could emit branch-free code, but that would need one more | 1480 // If the negation could not overflow, simply shifting is OK. |
1481 // register. | 1481 if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { |
1482 if (divisor == -1) { | |
1483 DeoptimizeIf(vs, instr->environment()); | |
1484 __ mov(result, Operand(dividend, ASR, shift)); | |
1485 } else { | |
1486 __ mov(result, Operand(kMinInt / divisor), LeaveCC, vs); | |
1487 __ mov(result, Operand(dividend, ASR, shift), LeaveCC, vc); | |
1488 } | |
1489 } else { | |
1490 __ mov(result, Operand(dividend, ASR, shift)); | 1482 __ mov(result, Operand(dividend, ASR, shift)); |
| 1483 return; |
1491 } | 1484 } |
| 1485 |
| 1486 // Dividing by -1 is basically negation, unless we overflow. |
| 1487 if (divisor == -1) { |
| 1488 DeoptimizeIf(vs, instr->environment()); |
| 1489 return; |
| 1490 } |
| 1491 |
| 1492 __ mov(result, Operand(kMinInt / divisor), LeaveCC, vs); |
| 1493 __ mov(result, Operand(dividend, ASR, shift), LeaveCC, vc); |
1492 } | 1494 } |
1493 | 1495 |
1494 | 1496 |
1495 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { | 1497 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { |
1496 Register dividend = ToRegister(instr->dividend()); | 1498 Register dividend = ToRegister(instr->dividend()); |
1497 int32_t divisor = instr->divisor(); | 1499 int32_t divisor = instr->divisor(); |
1498 Register result = ToRegister(instr->result()); | 1500 Register result = ToRegister(instr->result()); |
1499 ASSERT(!dividend.is(result)); | 1501 ASSERT(!dividend.is(result)); |
1500 | 1502 |
1501 if (divisor == 0) { | 1503 if (divisor == 0) { |
(...skipping 4237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5739 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); | 5741 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); |
5740 __ ldr(result, FieldMemOperand(scratch, | 5742 __ ldr(result, FieldMemOperand(scratch, |
5741 FixedArray::kHeaderSize - kPointerSize)); | 5743 FixedArray::kHeaderSize - kPointerSize)); |
5742 __ bind(&done); | 5744 __ bind(&done); |
5743 } | 5745 } |
5744 | 5746 |
5745 | 5747 |
5746 #undef __ | 5748 #undef __ |
5747 | 5749 |
5748 } } // namespace v8::internal | 5750 } } // namespace v8::internal |
OLD | NEW |