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 2423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2434 __ mov(right, Operand(scratch1), LeaveCC, ne); | 2434 __ mov(right, Operand(scratch1), LeaveCC, ne); |
2435 __ Ret(ne); | 2435 __ Ret(ne); |
2436 // We need -0 if we were multiplying a negative number with 0 to get 0. | 2436 // We need -0 if we were multiplying a negative number with 0 to get 0. |
2437 // We know one of them was zero. | 2437 // We know one of them was zero. |
2438 __ add(scratch2, right, Operand(left), SetCC); | 2438 __ add(scratch2, right, Operand(left), SetCC); |
2439 __ mov(right, Operand(Smi::FromInt(0)), LeaveCC, pl); | 2439 __ mov(right, Operand(Smi::FromInt(0)), LeaveCC, pl); |
2440 __ Ret(pl); // Return smi 0 if the non-zero one was positive. | 2440 __ Ret(pl); // Return smi 0 if the non-zero one was positive. |
2441 // We fall through here if we multiplied a negative number with 0, because | 2441 // We fall through here if we multiplied a negative number with 0, because |
2442 // that would mean we should produce -0. | 2442 // that would mean we should produce -0. |
2443 break; | 2443 break; |
2444 case Token::DIV: | 2444 case Token::DIV: { |
danno
2012/12/20 16:25:38
nit: indentation
| |
2445 Label div_with_sdiv; | |
2446 | |
2447 // Check for 0 divisor. | |
2448 __ cmp(right, Operand(0)); | |
2449 __ b(eq, ¬_smi_result); | |
2450 | |
2445 // Check for power of two on the right hand side. | 2451 // Check for power of two on the right hand side. |
2446 __ JumpIfNotPowerOfTwoOrZero(right, scratch1, ¬_smi_result); | 2452 __ sub(scratch1, right, Operand(1)); |
2447 // Check for positive and no remainder (scratch1 contains right - 1). | 2453 __ tst(scratch1, right); |
2448 __ orr(scratch2, scratch1, Operand(0x80000000u)); | 2454 if (CpuFeatures::IsSupported(SUDIV)) { |
2449 __ tst(left, scratch2); | 2455 __ b(ne, &div_with_sdiv); |
2450 __ b(ne, ¬_smi_result); | 2456 // Check for no remainder. |
2457 __ tst(left, scratch1); | |
2458 __ b(ne, ¬_smi_result); | |
2459 // Check for positive left hand side. | |
2460 __ cmp(left, Operand(0)); | |
2461 __ b(mi, &div_with_sdiv); | |
2462 } else { | |
2463 __ b(ne, ¬_smi_result); | |
2464 // Check for positive and no remainder. | |
2465 __ orr(scratch2, scratch1, Operand(0x80000000u)); | |
2466 __ tst(left, scratch2); | |
2467 __ b(ne, ¬_smi_result); | |
2468 } | |
2451 | 2469 |
2452 // Perform division by shifting. | 2470 // Perform division by shifting. |
2453 __ CountLeadingZeros(scratch1, scratch1, scratch2); | 2471 __ CountLeadingZeros(scratch1, scratch1, scratch2); |
2454 __ rsb(scratch1, scratch1, Operand(31)); | 2472 __ rsb(scratch1, scratch1, Operand(31)); |
2455 __ mov(right, Operand(left, LSR, scratch1)); | 2473 __ mov(right, Operand(left, LSR, scratch1)); |
2456 __ Ret(); | 2474 __ Ret(); |
2475 | |
2476 if (CpuFeatures::IsSupported(SUDIV)) { | |
2477 Label result_not_zero; | |
2478 | |
2479 __ bind(&div_with_sdiv); | |
2480 // Do division. | |
2481 __ sdiv(scratch1, left, right); | |
2482 // Check that the remainder is zero. | |
2483 __ mls(scratch2, scratch1, right, left); | |
2484 __ cmp(scratch2, Operand(0)); | |
2485 __ b(ne, ¬_smi_result); | |
2486 // Check for negative zero result. | |
2487 __ cmp(scratch1, Operand(0)); | |
2488 __ b(ne, &result_not_zero); | |
2489 __ cmp(right, Operand(0)); | |
2490 __ b(lt, ¬_smi_result); | |
2491 __ bind(&result_not_zero); | |
2492 // Check for the corner case of dividing the most negative smi by -1. | |
2493 __ cmp(scratch1, Operand(0x40000000)); | |
2494 __ b(eq, ¬_smi_result); | |
2495 // Tag and return the result. | |
2496 __ SmiTag(right, scratch1); | |
2497 __ Ret(); | |
2498 } | |
2457 break; | 2499 break; |
2458 case Token::MOD: | 2500 } |
2459 // Check for two positive smis. | 2501 case Token::MOD: { |
2460 __ orr(scratch1, left, Operand(right)); | 2502 Label modulo_with_sdiv; |
2461 __ tst(scratch1, Operand(0x80000000u | kSmiTagMask)); | |
2462 __ b(ne, ¬_smi_result); | |
2463 | 2503 |
2464 // Check for power of two on the right hand side. | 2504 if (CpuFeatures::IsSupported(SUDIV)) { |
2465 __ JumpIfNotPowerOfTwoOrZero(right, scratch1, ¬_smi_result); | 2505 // Check for x % 0. |
2506 __ cmp(right, Operand(0)); | |
2507 __ b(eq, ¬_smi_result); | |
2466 | 2508 |
2467 // Perform modulus by masking. | 2509 // Check for two positive smis. |
2510 __ orr(scratch1, left, Operand(right)); | |
2511 __ tst(scratch1, Operand(0x80000000u)); | |
2512 __ b(ne, &modulo_with_sdiv); | |
2513 | |
2514 // Check for power of two on the right hand side. | |
2515 __ sub(scratch1, right, Operand(1)); | |
2516 __ tst(scratch1, right); | |
2517 __ b(ne, &modulo_with_sdiv); | |
2518 } else { | |
2519 // Check for two positive smis. | |
2520 __ orr(scratch1, left, Operand(right)); | |
2521 __ tst(scratch1, Operand(0x80000000u)); | |
2522 __ b(ne, ¬_smi_result); | |
2523 | |
2524 // Check for power of two on the right hand side. | |
2525 __ JumpIfNotPowerOfTwoOrZero(right, scratch1, ¬_smi_result); | |
2526 } | |
2527 | |
2528 // Perform modulus by masking (scratch1 contains right - 1). | |
2468 __ and_(right, left, Operand(scratch1)); | 2529 __ and_(right, left, Operand(scratch1)); |
2469 __ Ret(); | 2530 __ Ret(); |
2531 | |
2532 if (CpuFeatures::IsSupported(SUDIV)) { | |
2533 __ bind(&modulo_with_sdiv); | |
2534 __ mov(scratch2, right); | |
2535 // Perform modulus with sdiv and mls. | |
2536 __ sdiv(scratch1, left, right); | |
2537 __ mls(right, scratch1, right, left); | |
2538 // Return if the result is not 0. | |
2539 __ cmp(right, Operand(0)); | |
2540 __ Ret(ne); | |
2541 // The result is 0, check for -0 case. | |
2542 __ cmp(left, Operand(0)); | |
2543 __ Ret(pl); | |
2544 // This is a -0 case, restore the value of right. | |
2545 __ mov(right, scratch2); | |
2546 // We fall through here to not_smi_result to produce -0. | |
2547 } | |
2470 break; | 2548 break; |
2549 } | |
2471 case Token::BIT_OR: | 2550 case Token::BIT_OR: |
2472 __ orr(right, left, Operand(right)); | 2551 __ orr(right, left, Operand(right)); |
2473 __ Ret(); | 2552 __ Ret(); |
2474 break; | 2553 break; |
2475 case Token::BIT_AND: | 2554 case Token::BIT_AND: |
2476 __ and_(right, left, Operand(right)); | 2555 __ and_(right, left, Operand(right)); |
2477 __ Ret(); | 2556 __ Ret(); |
2478 break; | 2557 break; |
2479 case Token::BIT_XOR: | 2558 case Token::BIT_XOR: |
2480 __ eor(right, left, Operand(right)); | 2559 __ eor(right, left, Operand(right)); |
(...skipping 5151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7632 | 7711 |
7633 __ Pop(lr, r5, r1); | 7712 __ Pop(lr, r5, r1); |
7634 __ Ret(); | 7713 __ Ret(); |
7635 } | 7714 } |
7636 | 7715 |
7637 #undef __ | 7716 #undef __ |
7638 | 7717 |
7639 } } // namespace v8::internal | 7718 } } // namespace v8::internal |
7640 | 7719 |
7641 #endif // V8_TARGET_ARCH_ARM | 7720 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |