Commit ffd1b25c authored by whessev8's avatar whessev8

Optimizes check for Smi range in the code generator.

The check whether a 32-bit signed integer is in the Smi
range is now Sign bit( value + 0x40000000 ) == 0,
done with a single cmp instruction.
Review URL: http://codereview.chromium.org/18710

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1134 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 8a731355
...@@ -1127,9 +1127,11 @@ void CodeGenerator::SmiOperation(Token::Value op, ...@@ -1127,9 +1127,11 @@ void CodeGenerator::SmiOperation(Token::Value op,
__ j(not_zero, deferred->enter(), not_taken); __ j(not_zero, deferred->enter(), not_taken);
__ sar(ebx, kSmiTagSize); __ sar(ebx, kSmiTagSize);
__ shl(ebx, shift_value); __ shl(ebx, shift_value);
__ lea(ecx, Operand(ebx, 0x40000000)); // This is the Smi check for the shifted result.
__ test(ecx, Immediate(0x80000000)); // After signed subtraction of 0xc0000000, the valid
__ j(not_zero, deferred->enter(), not_taken); // Smis are positive.
__ cmp(ebx, 0xc0000000);
__ j(sign, deferred->enter(), not_taken);
// tag result and store it in TOS (eax) // tag result and store it in TOS (eax)
ASSERT(kSmiTagSize == times_2); // adjust code if not the case ASSERT(kSmiTagSize == times_2); // adjust code if not the case
__ lea(eax, Operand(ebx, ebx, times_1, kSmiTag)); __ lea(eax, Operand(ebx, ebx, times_1, kSmiTag));
...@@ -4274,9 +4276,8 @@ void GenericBinaryOpStub::GenerateSmiCode(MacroAssembler* masm, Label* slow) { ...@@ -4274,9 +4276,8 @@ void GenericBinaryOpStub::GenerateSmiCode(MacroAssembler* masm, Label* slow) {
case Token::SHL: case Token::SHL:
__ shl(eax); __ shl(eax);
// Check that the *signed* result fits in a smi. // Check that the *signed* result fits in a smi.
__ lea(ecx, Operand(eax, 0x40000000)); __ cmp(eax, 0xc0000000);
__ test(ecx, Immediate(0x80000000)); __ j(sign, slow, not_taken);
__ j(not_zero, slow, not_taken);
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment