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 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 __ mov(result_reg, left_reg); | 1337 __ mov(result_reg, left_reg); |
1338 | 1338 |
1339 __ bind(&done); | 1339 __ bind(&done); |
1340 } | 1340 } |
1341 } | 1341 } |
1342 | 1342 |
1343 | 1343 |
1344 void LCodeGen::DoDivI(LDivI* instr) { | 1344 void LCodeGen::DoDivI(LDivI* instr) { |
1345 if (!instr->is_flooring() && instr->hydrogen()->HasPowerOf2Divisor()) { | 1345 if (!instr->is_flooring() && instr->hydrogen()->HasPowerOf2Divisor()) { |
1346 Register dividend = ToRegister(instr->left()); | 1346 Register dividend = ToRegister(instr->left()); |
1347 int32_t divisor = | 1347 int32_t divisor = instr->hydrogen()->right()->GetInteger32Constant(); |
1348 HConstant::cast(instr->hydrogen()->right())->Integer32Value(); | |
1349 int32_t test_value = 0; | 1348 int32_t test_value = 0; |
1350 int32_t power = 0; | 1349 int32_t power = 0; |
1351 | 1350 |
1352 if (divisor > 0) { | 1351 if (divisor > 0) { |
1353 test_value = divisor - 1; | 1352 test_value = divisor - 1; |
1354 power = WhichPowerOf2(divisor); | 1353 power = WhichPowerOf2(divisor); |
1355 } else { | 1354 } else { |
1356 // Check for (0 / -x) that will produce negative zero. | 1355 // Check for (0 / -x) that will produce negative zero. |
1357 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1356 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1358 __ test(dividend, Operand(dividend)); | 1357 __ test(dividend, Operand(dividend)); |
1359 DeoptimizeIf(zero, instr->environment()); | 1358 DeoptimizeIf(zero, instr->environment()); |
1360 } | 1359 } |
1361 // Check for (kMinInt / -1). | 1360 // Check for (kMinInt / -1). |
1362 if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { | 1361 if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
1363 __ cmp(dividend, kMinInt); | 1362 __ cmp(dividend, kMinInt); |
1364 DeoptimizeIf(zero, instr->environment()); | 1363 DeoptimizeIf(zero, instr->environment()); |
1365 } | 1364 } |
1366 test_value = - divisor - 1; | 1365 test_value = - divisor - 1; |
1367 power = WhichPowerOf2(-divisor); | 1366 power = WhichPowerOf2(-divisor); |
1368 } | 1367 } |
1369 | 1368 |
1370 if (test_value != 0) { | 1369 if (test_value != 0) { |
1371 // Deoptimize if remainder is not 0. | 1370 if (instr->hydrogen()->CheckFlag( |
1372 __ test(dividend, Immediate(test_value)); | 1371 HInstruction::kAllUsesTruncatingToInt32)) { |
1373 DeoptimizeIf(not_zero, instr->environment()); | 1372 Label done, negative; |
1374 __ sar(dividend, power); | 1373 __ cmp(dividend, 0); |
| 1374 __ j(less, &negative, Label::kNear); |
| 1375 __ sar(dividend, power); |
| 1376 __ jmp(&done, Label::kNear); |
| 1377 |
| 1378 __ bind(&negative); |
| 1379 __ neg(dividend); |
| 1380 __ sar(dividend, power); |
| 1381 if (divisor > 0) __ neg(dividend); |
| 1382 __ bind(&done); |
| 1383 return; // Don't fall through to "__ neg" below. |
| 1384 } else { |
| 1385 // Deoptimize if remainder is not 0. |
| 1386 __ test(dividend, Immediate(test_value)); |
| 1387 DeoptimizeIf(not_zero, instr->environment()); |
| 1388 __ sar(dividend, power); |
| 1389 } |
1375 } | 1390 } |
1376 | 1391 |
1377 if (divisor < 0) __ neg(dividend); | 1392 if (divisor < 0) __ neg(dividend); |
1378 | 1393 |
1379 return; | 1394 return; |
1380 } | 1395 } |
1381 | 1396 |
1382 LOperand* right = instr->right(); | 1397 LOperand* right = instr->right(); |
1383 ASSERT(ToRegister(instr->result()).is(eax)); | 1398 ASSERT(ToRegister(instr->result()).is(eax)); |
1384 ASSERT(ToRegister(instr->left()).is(eax)); | 1399 ASSERT(ToRegister(instr->left()).is(eax)); |
(...skipping 26 matching lines...) Expand all Loading... |
1411 __ j(not_zero, &left_not_min_int, Label::kNear); | 1426 __ j(not_zero, &left_not_min_int, Label::kNear); |
1412 __ cmp(right_reg, -1); | 1427 __ cmp(right_reg, -1); |
1413 DeoptimizeIf(zero, instr->environment()); | 1428 DeoptimizeIf(zero, instr->environment()); |
1414 __ bind(&left_not_min_int); | 1429 __ bind(&left_not_min_int); |
1415 } | 1430 } |
1416 | 1431 |
1417 // Sign extend to edx. | 1432 // Sign extend to edx. |
1418 __ cdq(); | 1433 __ cdq(); |
1419 __ idiv(right_reg); | 1434 __ idiv(right_reg); |
1420 | 1435 |
1421 if (!instr->is_flooring()) { | 1436 if (instr->is_flooring()) { |
1422 // Deoptimize if remainder is not 0. | |
1423 __ test(edx, Operand(edx)); | |
1424 DeoptimizeIf(not_zero, instr->environment()); | |
1425 } else { | |
1426 Label done; | 1437 Label done; |
1427 __ test(edx, edx); | 1438 __ test(edx, edx); |
1428 __ j(zero, &done, Label::kNear); | 1439 __ j(zero, &done, Label::kNear); |
1429 __ xor_(edx, right_reg); | 1440 __ xor_(edx, right_reg); |
1430 __ sar(edx, 31); | 1441 __ sar(edx, 31); |
1431 __ add(eax, edx); | 1442 __ add(eax, edx); |
1432 __ bind(&done); | 1443 __ bind(&done); |
| 1444 } else if (!instr->hydrogen()->CheckFlag( |
| 1445 HInstruction::kAllUsesTruncatingToInt32)) { |
| 1446 // Deoptimize if remainder is not 0. |
| 1447 __ test(edx, Operand(edx)); |
| 1448 DeoptimizeIf(not_zero, instr->environment()); |
1433 } | 1449 } |
1434 } | 1450 } |
1435 | 1451 |
1436 | 1452 |
1437 void LCodeGen::DoMathFloorOfDiv(LMathFloorOfDiv* instr) { | 1453 void LCodeGen::DoMathFloorOfDiv(LMathFloorOfDiv* instr) { |
1438 ASSERT(instr->right()->IsConstantOperand()); | 1454 ASSERT(instr->right()->IsConstantOperand()); |
1439 | 1455 |
1440 Register dividend = ToRegister(instr->left()); | 1456 Register dividend = ToRegister(instr->left()); |
1441 int32_t divisor = ToInteger32(LConstantOperand::cast(instr->right())); | 1457 int32_t divisor = ToInteger32(LConstantOperand::cast(instr->right())); |
1442 Register result = ToRegister(instr->result()); | 1458 Register result = ToRegister(instr->result()); |
(...skipping 5065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6508 FixedArray::kHeaderSize - kPointerSize)); | 6524 FixedArray::kHeaderSize - kPointerSize)); |
6509 __ bind(&done); | 6525 __ bind(&done); |
6510 } | 6526 } |
6511 | 6527 |
6512 | 6528 |
6513 #undef __ | 6529 #undef __ |
6514 | 6530 |
6515 } } // namespace v8::internal | 6531 } } // namespace v8::internal |
6516 | 6532 |
6517 #endif // V8_TARGET_ARCH_IA32 | 6533 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |