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 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 codegen()->DoDeferredBinaryOpStub(instr_->pointer_map(), | 1391 codegen()->DoDeferredBinaryOpStub(instr_->pointer_map(), |
1392 instr_->left(), | 1392 instr_->left(), |
1393 instr_->right(), | 1393 instr_->right(), |
1394 Token::DIV); | 1394 Token::DIV); |
1395 } | 1395 } |
1396 virtual LInstruction* instr() { return instr_; } | 1396 virtual LInstruction* instr() { return instr_; } |
1397 private: | 1397 private: |
1398 LDivI* instr_; | 1398 LDivI* instr_; |
1399 }; | 1399 }; |
1400 | 1400 |
| 1401 if (instr->hydrogen()->HasPowerOf2Divisor()) { |
| 1402 Register dividend = ToRegister(instr->left()); |
| 1403 int32_t divisor = |
| 1404 HConstant::cast(instr->hydrogen()->right())->Integer32Value(); |
| 1405 int32_t test_value = 0; |
| 1406 int32_t power = 0; |
| 1407 |
| 1408 if (divisor > 0) { |
| 1409 test_value = divisor - 1; |
| 1410 power = WhichPowerOf2(divisor); |
| 1411 } else { |
| 1412 // Check for (0 / -x) that will produce negative zero. |
| 1413 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1414 __ tst(dividend, Operand(dividend)); |
| 1415 DeoptimizeIf(eq, instr->environment()); |
| 1416 } |
| 1417 // Check for (kMinInt / -1). |
| 1418 if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1419 __ cmp(dividend, Operand(kMinInt)); |
| 1420 DeoptimizeIf(eq, instr->environment()); |
| 1421 } |
| 1422 test_value = - divisor - 1; |
| 1423 power = WhichPowerOf2(-divisor); |
| 1424 } |
| 1425 |
| 1426 if (test_value != 0) { |
| 1427 // Deoptimize if remainder is not 0. |
| 1428 __ tst(dividend, Operand(test_value)); |
| 1429 DeoptimizeIf(ne, instr->environment()); |
| 1430 __ mov(dividend, Operand(dividend, ASR, power)); |
| 1431 } |
| 1432 if (divisor < 0) __ rsb(dividend, dividend, Operand(0)); |
| 1433 |
| 1434 return; |
| 1435 } |
| 1436 |
1401 const Register left = ToRegister(instr->left()); | 1437 const Register left = ToRegister(instr->left()); |
1402 const Register right = ToRegister(instr->right()); | 1438 const Register right = ToRegister(instr->right()); |
1403 const Register scratch = scratch0(); | 1439 const Register scratch = scratch0(); |
1404 const Register result = ToRegister(instr->result()); | 1440 const Register result = ToRegister(instr->result()); |
1405 | 1441 |
1406 // Check for x / 0. | 1442 // Check for x / 0. |
1407 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { | 1443 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
1408 __ cmp(right, Operand::Zero()); | 1444 __ cmp(right, Operand::Zero()); |
1409 DeoptimizeIf(eq, instr->environment()); | 1445 DeoptimizeIf(eq, instr->environment()); |
1410 } | 1446 } |
(...skipping 4914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6325 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); | 6361 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); |
6326 __ ldr(result, FieldMemOperand(scratch, | 6362 __ ldr(result, FieldMemOperand(scratch, |
6327 FixedArray::kHeaderSize - kPointerSize)); | 6363 FixedArray::kHeaderSize - kPointerSize)); |
6328 __ bind(&done); | 6364 __ bind(&done); |
6329 } | 6365 } |
6330 | 6366 |
6331 | 6367 |
6332 #undef __ | 6368 #undef __ |
6333 | 6369 |
6334 } } // namespace v8::internal | 6370 } } // namespace v8::internal |
OLD | NEW |