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 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 return; | 1500 return; |
1501 } | 1501 } |
1502 | 1502 |
1503 // Check for (0 / -x) that will produce negative zero. | 1503 // Check for (0 / -x) that will produce negative zero. |
1504 HMathFloorOfDiv* hdiv = instr->hydrogen(); | 1504 HMathFloorOfDiv* hdiv = instr->hydrogen(); |
1505 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | 1505 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
1506 __ cmp(dividend, Operand::Zero()); | 1506 __ cmp(dividend, Operand::Zero()); |
1507 DeoptimizeIf(eq, instr->environment()); | 1507 DeoptimizeIf(eq, instr->environment()); |
1508 } | 1508 } |
1509 | 1509 |
1510 // TODO(svenpanne) Add correction terms. | 1510 // Easy case: We need no dynamic check for the dividend and the flooring |
1511 __ TruncatingDiv(result, dividend, divisor); | 1511 // division is the same as the truncating division. |
| 1512 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) || |
| 1513 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) { |
| 1514 __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1515 if (divisor < 0) __ rsb(result, result, Operand::Zero()); |
| 1516 return; |
| 1517 } |
| 1518 |
| 1519 // In the general case we may need to adjust before and after the truncating |
| 1520 // division to get a flooring division. |
| 1521 Register temp = ToRegister(instr->temp()); |
| 1522 ASSERT(!temp.is(dividend) && !temp.is(result)); |
| 1523 Label needs_adjustment, done; |
| 1524 __ cmp(dividend, Operand::Zero()); |
| 1525 __ b(divisor > 0 ? lt : gt, &needs_adjustment); |
| 1526 __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1527 if (divisor < 0) __ rsb(result, result, Operand::Zero()); |
| 1528 __ jmp(&done); |
| 1529 __ bind(&needs_adjustment); |
| 1530 __ add(temp, dividend, Operand(divisor > 0 ? 1 : -1)); |
| 1531 __ TruncatingDiv(result, temp, Abs(divisor)); |
| 1532 if (divisor < 0) __ rsb(result, result, Operand::Zero()); |
| 1533 __ sub(result, result, Operand(1)); |
| 1534 __ bind(&done); |
1512 } | 1535 } |
1513 | 1536 |
1514 | 1537 |
1515 void LCodeGen::DoMulI(LMulI* instr) { | 1538 void LCodeGen::DoMulI(LMulI* instr) { |
1516 Register result = ToRegister(instr->result()); | 1539 Register result = ToRegister(instr->result()); |
1517 // Note that result may alias left. | 1540 // Note that result may alias left. |
1518 Register left = ToRegister(instr->left()); | 1541 Register left = ToRegister(instr->left()); |
1519 LOperand* right_op = instr->right(); | 1542 LOperand* right_op = instr->right(); |
1520 | 1543 |
1521 bool bailout_on_minus_zero = | 1544 bool bailout_on_minus_zero = |
(...skipping 4190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5712 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); | 5735 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); |
5713 __ ldr(result, FieldMemOperand(scratch, | 5736 __ ldr(result, FieldMemOperand(scratch, |
5714 FixedArray::kHeaderSize - kPointerSize)); | 5737 FixedArray::kHeaderSize - kPointerSize)); |
5715 __ bind(&done); | 5738 __ bind(&done); |
5716 } | 5739 } |
5717 | 5740 |
5718 | 5741 |
5719 #undef __ | 5742 #undef __ |
5720 | 5743 |
5721 } } // namespace v8::internal | 5744 } } // namespace v8::internal |
OLD | NEW |