Optimizes check for Smi range in the code generator.
authorwhessev8 <whessev8@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 23 Jan 2009 13:06:15 +0000 (13:06 +0000)
committerwhessev8 <whessev8@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 23 Jan 2009 13:06:15 +0000 (13:06 +0000)
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

src/codegen-ia32.cc

index a02f545..602b66d 100644 (file)
@@ -1127,9 +1127,11 @@ void CodeGenerator::SmiOperation(Token::Value op,
         __ j(not_zero, deferred->enter(), not_taken);
         __ sar(ebx, kSmiTagSize);
         __ shl(ebx, shift_value);
-        __ lea(ecx, Operand(ebx, 0x40000000));
-        __ test(ecx, Immediate(0x80000000));
-        __ j(not_zero, deferred->enter(), not_taken);
+        // This is the Smi check for the shifted result.
+        // After signed subtraction of 0xc0000000, the valid 
+        // Smis are positive.
+        __ cmp(ebx, 0xc0000000);
+        __ j(sign, deferred->enter(), not_taken); 
         // tag result and store it in TOS (eax)
         ASSERT(kSmiTagSize == times_2);  // adjust code if not the case
         __ lea(eax, Operand(ebx, ebx, times_1, kSmiTag));
@@ -4274,9 +4276,8 @@ void GenericBinaryOpStub::GenerateSmiCode(MacroAssembler* masm, Label* slow) {
         case Token::SHL:
           __ shl(eax);
           // Check that the *signed* result fits in a smi.
-          __ lea(ecx, Operand(eax, 0x40000000));
-          __ test(ecx, Immediate(0x80000000));
-          __ j(not_zero, slow, not_taken);
+          __ cmp(eax, 0xc0000000);
+          __ j(sign, slow, not_taken);
           break;
         default:
           UNREACHABLE();