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 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 | 1356 |
1357 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { | 1357 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
1358 __ mov(ip, Operand(divisor)); | 1358 __ mov(ip, Operand(divisor)); |
1359 __ smull(scratch0(), ip, result, ip); | 1359 __ smull(scratch0(), ip, result, ip); |
1360 __ sub(scratch0(), scratch0(), dividend, SetCC); | 1360 __ sub(scratch0(), scratch0(), dividend, SetCC); |
1361 DeoptimizeIf(ne, instr->environment()); | 1361 DeoptimizeIf(ne, instr->environment()); |
1362 } | 1362 } |
1363 } | 1363 } |
1364 | 1364 |
1365 | 1365 |
| 1366 // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI. |
1366 void LCodeGen::DoDivI(LDivI* instr) { | 1367 void LCodeGen::DoDivI(LDivI* instr) { |
1367 HBinaryOperation* hdiv = instr->hydrogen(); | 1368 HBinaryOperation* hdiv = instr->hydrogen(); |
1368 Register left = ToRegister(instr->left()); | 1369 Register dividend = ToRegister(instr->dividend()); |
1369 Register right = ToRegister(instr->right()); | 1370 Register divisor = ToRegister(instr->divisor()); |
1370 Register result = ToRegister(instr->result()); | 1371 Register result = ToRegister(instr->result()); |
1371 | 1372 |
1372 // Check for x / 0. | 1373 // Check for x / 0. |
1373 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { | 1374 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
1374 __ cmp(right, Operand::Zero()); | 1375 __ cmp(divisor, Operand::Zero()); |
1375 DeoptimizeIf(eq, instr->environment()); | 1376 DeoptimizeIf(eq, instr->environment()); |
1376 } | 1377 } |
1377 | 1378 |
1378 // Check for (0 / -x) that will produce negative zero. | 1379 // Check for (0 / -x) that will produce negative zero. |
1379 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1380 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1380 Label positive; | 1381 Label positive; |
1381 if (!instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) { | 1382 if (!instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) { |
1382 // Do the test only if it hadn't be done above. | 1383 // Do the test only if it hadn't be done above. |
1383 __ cmp(right, Operand::Zero()); | 1384 __ cmp(divisor, Operand::Zero()); |
1384 } | 1385 } |
1385 __ b(pl, &positive); | 1386 __ b(pl, &positive); |
1386 __ cmp(left, Operand::Zero()); | 1387 __ cmp(dividend, Operand::Zero()); |
1387 DeoptimizeIf(eq, instr->environment()); | 1388 DeoptimizeIf(eq, instr->environment()); |
1388 __ bind(&positive); | 1389 __ bind(&positive); |
1389 } | 1390 } |
1390 | 1391 |
1391 // Check for (kMinInt / -1). | 1392 // Check for (kMinInt / -1). |
1392 if (hdiv->CheckFlag(HValue::kCanOverflow) && | 1393 if (hdiv->CheckFlag(HValue::kCanOverflow) && |
1393 (!CpuFeatures::IsSupported(SUDIV) || | 1394 (!CpuFeatures::IsSupported(SUDIV) || |
1394 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32))) { | 1395 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32))) { |
1395 // We don't need to check for overflow when truncating with sdiv | 1396 // We don't need to check for overflow when truncating with sdiv |
1396 // support because, on ARM, sdiv kMinInt, -1 -> kMinInt. | 1397 // support because, on ARM, sdiv kMinInt, -1 -> kMinInt. |
1397 __ cmp(left, Operand(kMinInt)); | 1398 __ cmp(dividend, Operand(kMinInt)); |
1398 __ cmp(right, Operand(-1), eq); | 1399 __ cmp(divisor, Operand(-1), eq); |
1399 DeoptimizeIf(eq, instr->environment()); | 1400 DeoptimizeIf(eq, instr->environment()); |
1400 } | 1401 } |
1401 | 1402 |
1402 if (CpuFeatures::IsSupported(SUDIV)) { | 1403 if (CpuFeatures::IsSupported(SUDIV)) { |
1403 CpuFeatureScope scope(masm(), SUDIV); | 1404 CpuFeatureScope scope(masm(), SUDIV); |
1404 __ sdiv(result, left, right); | 1405 __ sdiv(result, dividend, divisor); |
1405 } else { | 1406 } else { |
1406 DoubleRegister vleft = ToDoubleRegister(instr->temp()); | 1407 DoubleRegister vleft = ToDoubleRegister(instr->temp()); |
1407 DoubleRegister vright = double_scratch0(); | 1408 DoubleRegister vright = double_scratch0(); |
1408 __ vmov(double_scratch0().low(), left); | 1409 __ vmov(double_scratch0().low(), dividend); |
1409 __ vcvt_f64_s32(vleft, double_scratch0().low()); | 1410 __ vcvt_f64_s32(vleft, double_scratch0().low()); |
1410 __ vmov(double_scratch0().low(), right); | 1411 __ vmov(double_scratch0().low(), divisor); |
1411 __ vcvt_f64_s32(vright, double_scratch0().low()); | 1412 __ vcvt_f64_s32(vright, double_scratch0().low()); |
1412 __ vdiv(vleft, vleft, vright); // vleft now contains the result. | 1413 __ vdiv(vleft, vleft, vright); // vleft now contains the result. |
1413 __ vcvt_s32_f64(double_scratch0().low(), vleft); | 1414 __ vcvt_s32_f64(double_scratch0().low(), vleft); |
1414 __ vmov(result, double_scratch0().low()); | 1415 __ vmov(result, double_scratch0().low()); |
1415 } | 1416 } |
1416 | 1417 |
1417 if (hdiv->IsMathFloorOfDiv()) { | 1418 if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
1418 Label done; | |
1419 Register remainder = scratch0(); | |
1420 __ mls(remainder, result, right, left); | |
1421 __ cmp(remainder, Operand::Zero()); | |
1422 __ b(eq, &done); | |
1423 __ eor(remainder, remainder, Operand(right)); | |
1424 __ add(result, result, Operand(remainder, ASR, 31)); | |
1425 __ bind(&done); | |
1426 } else if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { | |
1427 // Compute remainder and deopt if it's not zero. | 1419 // Compute remainder and deopt if it's not zero. |
1428 Register remainder = scratch0(); | 1420 Register remainder = scratch0(); |
1429 __ mls(remainder, result, right, left); | 1421 __ mls(remainder, result, divisor, dividend); |
1430 __ cmp(remainder, Operand::Zero()); | 1422 __ cmp(remainder, Operand::Zero()); |
1431 DeoptimizeIf(ne, instr->environment()); | 1423 DeoptimizeIf(ne, instr->environment()); |
1432 } | 1424 } |
1433 } | 1425 } |
1434 | 1426 |
1435 | 1427 |
1436 void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) { | 1428 void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) { |
1437 DwVfpRegister addend = ToDoubleRegister(instr->addend()); | 1429 DwVfpRegister addend = ToDoubleRegister(instr->addend()); |
1438 DwVfpRegister multiplier = ToDoubleRegister(instr->multiplier()); | 1430 DwVfpRegister multiplier = ToDoubleRegister(instr->multiplier()); |
1439 DwVfpRegister multiplicand = ToDoubleRegister(instr->multiplicand()); | 1431 DwVfpRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1531 __ jmp(&done); | 1523 __ jmp(&done); |
1532 __ bind(&needs_adjustment); | 1524 __ bind(&needs_adjustment); |
1533 __ add(temp, dividend, Operand(divisor > 0 ? 1 : -1)); | 1525 __ add(temp, dividend, Operand(divisor > 0 ? 1 : -1)); |
1534 __ TruncatingDiv(result, temp, Abs(divisor)); | 1526 __ TruncatingDiv(result, temp, Abs(divisor)); |
1535 if (divisor < 0) __ rsb(result, result, Operand::Zero()); | 1527 if (divisor < 0) __ rsb(result, result, Operand::Zero()); |
1536 __ sub(result, result, Operand(1)); | 1528 __ sub(result, result, Operand(1)); |
1537 __ bind(&done); | 1529 __ bind(&done); |
1538 } | 1530 } |
1539 | 1531 |
1540 | 1532 |
| 1533 // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI. |
| 1534 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { |
| 1535 HBinaryOperation* hdiv = instr->hydrogen(); |
| 1536 Register left = ToRegister(instr->dividend()); |
| 1537 Register right = ToRegister(instr->divisor()); |
| 1538 Register result = ToRegister(instr->result()); |
| 1539 |
| 1540 // Check for x / 0. |
| 1541 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1542 __ cmp(right, Operand::Zero()); |
| 1543 DeoptimizeIf(eq, instr->environment()); |
| 1544 } |
| 1545 |
| 1546 // Check for (0 / -x) that will produce negative zero. |
| 1547 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1548 Label positive; |
| 1549 if (!instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1550 // Do the test only if it hadn't be done above. |
| 1551 __ cmp(right, Operand::Zero()); |
| 1552 } |
| 1553 __ b(pl, &positive); |
| 1554 __ cmp(left, Operand::Zero()); |
| 1555 DeoptimizeIf(eq, instr->environment()); |
| 1556 __ bind(&positive); |
| 1557 } |
| 1558 |
| 1559 // Check for (kMinInt / -1). |
| 1560 if (hdiv->CheckFlag(HValue::kCanOverflow) && |
| 1561 (!CpuFeatures::IsSupported(SUDIV) || |
| 1562 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32))) { |
| 1563 // We don't need to check for overflow when truncating with sdiv |
| 1564 // support because, on ARM, sdiv kMinInt, -1 -> kMinInt. |
| 1565 __ cmp(left, Operand(kMinInt)); |
| 1566 __ cmp(right, Operand(-1), eq); |
| 1567 DeoptimizeIf(eq, instr->environment()); |
| 1568 } |
| 1569 |
| 1570 if (CpuFeatures::IsSupported(SUDIV)) { |
| 1571 CpuFeatureScope scope(masm(), SUDIV); |
| 1572 __ sdiv(result, left, right); |
| 1573 } else { |
| 1574 DoubleRegister vleft = ToDoubleRegister(instr->temp()); |
| 1575 DoubleRegister vright = double_scratch0(); |
| 1576 __ vmov(double_scratch0().low(), left); |
| 1577 __ vcvt_f64_s32(vleft, double_scratch0().low()); |
| 1578 __ vmov(double_scratch0().low(), right); |
| 1579 __ vcvt_f64_s32(vright, double_scratch0().low()); |
| 1580 __ vdiv(vleft, vleft, vright); // vleft now contains the result. |
| 1581 __ vcvt_s32_f64(double_scratch0().low(), vleft); |
| 1582 __ vmov(result, double_scratch0().low()); |
| 1583 } |
| 1584 |
| 1585 Label done; |
| 1586 Register remainder = scratch0(); |
| 1587 __ mls(remainder, result, right, left); |
| 1588 __ cmp(remainder, Operand::Zero()); |
| 1589 __ b(eq, &done); |
| 1590 __ eor(remainder, remainder, Operand(right)); |
| 1591 __ add(result, result, Operand(remainder, ASR, 31)); |
| 1592 __ bind(&done); |
| 1593 } |
| 1594 |
| 1595 |
1541 void LCodeGen::DoMulI(LMulI* instr) { | 1596 void LCodeGen::DoMulI(LMulI* instr) { |
1542 Register result = ToRegister(instr->result()); | 1597 Register result = ToRegister(instr->result()); |
1543 // Note that result may alias left. | 1598 // Note that result may alias left. |
1544 Register left = ToRegister(instr->left()); | 1599 Register left = ToRegister(instr->left()); |
1545 LOperand* right_op = instr->right(); | 1600 LOperand* right_op = instr->right(); |
1546 | 1601 |
1547 bool bailout_on_minus_zero = | 1602 bool bailout_on_minus_zero = |
1548 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); | 1603 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); |
1549 bool overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | 1604 bool overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
1550 | 1605 |
(...skipping 4237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5788 __ ldr(result, FieldMemOperand(scratch, | 5843 __ ldr(result, FieldMemOperand(scratch, |
5789 FixedArray::kHeaderSize - kPointerSize)); | 5844 FixedArray::kHeaderSize - kPointerSize)); |
5790 __ bind(deferred->exit()); | 5845 __ bind(deferred->exit()); |
5791 __ bind(&done); | 5846 __ bind(&done); |
5792 } | 5847 } |
5793 | 5848 |
5794 | 5849 |
5795 #undef __ | 5850 #undef __ |
5796 | 5851 |
5797 } } // namespace v8::internal | 5852 } } // namespace v8::internal |
OLD | NEW |