OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved.7 | 1 // Copyright 2012 the V8 project authors. All rights reserved.7 |
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 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 DeoptimizeIf(al, instr->environment()); | 1360 DeoptimizeIf(al, instr->environment()); |
1361 return; | 1361 return; |
1362 } | 1362 } |
1363 | 1363 |
1364 // Check for (0 / -x) that will produce negative zero. | 1364 // Check for (0 / -x) that will produce negative zero. |
1365 HMathFloorOfDiv* hdiv = instr->hydrogen(); | 1365 HMathFloorOfDiv* hdiv = instr->hydrogen(); |
1366 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | 1366 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
1367 DeoptimizeIf(eq, instr->environment(), dividend, Operand(zero_reg)); | 1367 DeoptimizeIf(eq, instr->environment(), dividend, Operand(zero_reg)); |
1368 } | 1368 } |
1369 | 1369 |
1370 // TODO(svenpanne) Add correction terms. | 1370 // Easy case: We need no dynamic check for the dividend and the flooring |
1371 __ TruncatingDiv(result, dividend, divisor); | 1371 // division is the same as the truncating division. |
| 1372 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) || |
| 1373 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) { |
| 1374 __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1375 if (divisor < 0) __ Subu(result, zero_reg, result); |
| 1376 return; |
| 1377 } |
| 1378 |
| 1379 // In the general case we may need to adjust before and after the truncating |
| 1380 // division to get a flooring division. |
| 1381 Register temp = ToRegister(instr->temp()); |
| 1382 ASSERT(!temp.is(dividend) && !temp.is(result)); |
| 1383 Label needs_adjustment, done; |
| 1384 __ Branch(&needs_adjustment, divisor > 0 ? lt : gt, |
| 1385 dividend, Operand(zero_reg)); |
| 1386 __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1387 if (divisor < 0) __ Subu(result, zero_reg, result); |
| 1388 __ jmp(&done); |
| 1389 __ bind(&needs_adjustment); |
| 1390 __ Addu(temp, dividend, Operand(divisor > 0 ? 1 : -1)); |
| 1391 __ TruncatingDiv(result, temp, Abs(divisor)); |
| 1392 if (divisor < 0) __ Subu(result, zero_reg, result); |
| 1393 __ Subu(result, result, Operand(1)); |
| 1394 __ bind(&done); |
1372 } | 1395 } |
1373 | 1396 |
1374 | 1397 |
1375 void LCodeGen::DoMulI(LMulI* instr) { | 1398 void LCodeGen::DoMulI(LMulI* instr) { |
1376 Register scratch = scratch0(); | 1399 Register scratch = scratch0(); |
1377 Register result = ToRegister(instr->result()); | 1400 Register result = ToRegister(instr->result()); |
1378 // Note that result may alias left. | 1401 // Note that result may alias left. |
1379 Register left = ToRegister(instr->left()); | 1402 Register left = ToRegister(instr->left()); |
1380 LOperand* right_op = instr->right(); | 1403 LOperand* right_op = instr->right(); |
1381 | 1404 |
(...skipping 4406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5788 __ Subu(scratch, result, scratch); | 5811 __ Subu(scratch, result, scratch); |
5789 __ lw(result, FieldMemOperand(scratch, | 5812 __ lw(result, FieldMemOperand(scratch, |
5790 FixedArray::kHeaderSize - kPointerSize)); | 5813 FixedArray::kHeaderSize - kPointerSize)); |
5791 __ bind(&done); | 5814 __ bind(&done); |
5792 } | 5815 } |
5793 | 5816 |
5794 | 5817 |
5795 #undef __ | 5818 #undef __ |
5796 | 5819 |
5797 } } // namespace v8::internal | 5820 } } // namespace v8::internal |
OLD | NEW |