Revision: 17941
Author:   [email protected]
Date:     Wed Nov 20 19:01:33 2013 UTC
Log:      MIPS: Use SmiTst and TrySmiTag MacroAssembler instructions.

BUG=
[email protected]

Review URL: https://codereview.chromium.org/78403002

Patch from Balazs Kilvady <[email protected]>.
http://code.google.com/p/v8/source/detail?r=17941

Modified:
 /branches/bleeding_edge/src/mips/builtins-mips.cc
 /branches/bleeding_edge/src/mips/code-stubs-mips.cc
 /branches/bleeding_edge/src/mips/full-codegen-mips.cc
 /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc
 /branches/bleeding_edge/src/mips/macro-assembler-mips.cc
 /branches/bleeding_edge/src/mips/macro-assembler-mips.h
 /branches/bleeding_edge/src/mips/stub-cache-mips.cc

=======================================
--- /branches/bleeding_edge/src/mips/builtins-mips.cc Wed Nov 20 18:22:18 2013 UTC +++ /branches/bleeding_edge/src/mips/builtins-mips.cc Wed Nov 20 19:01:33 2013 UTC
@@ -122,7 +122,7 @@
   if (FLAG_debug_code) {
     // Initial map for the builtin InternalArray functions should be maps.
__ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
-    __ And(t0, a2, Operand(kSmiTagMask));
+    __ SmiTst(a2, t0);
     __ Assert(ne, kUnexpectedInitialMapForInternalArrayFunction,
               t0, Operand(zero_reg));
     __ GetObjectType(a2, a3, t0);
@@ -152,7 +152,7 @@
   if (FLAG_debug_code) {
     // Initial map for the builtin Array functions should be maps.
__ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
-    __ And(t0, a2, Operand(kSmiTagMask));
+    __ SmiTst(a2, t0);
     __ Assert(ne, kUnexpectedInitialMapForArrayFunction1,
               t0, Operand(zero_reg));
     __ GetObjectType(a2, a3, t0);
=======================================
--- /branches/bleeding_edge/src/mips/code-stubs-mips.cc Fri Nov 15 21:12:51 2013 UTC +++ /branches/bleeding_edge/src/mips/code-stubs-mips.cc Wed Nov 20 19:01:33 2013 UTC
@@ -2969,7 +2969,7 @@
   // Check that the RegExp has been compiled (data contains a fixed array).
   __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
   if (FLAG_debug_code) {
-    __ And(t0, regexp_data, Operand(kSmiTagMask));
+    __ SmiTst(regexp_data, t0);
     __ Check(nz,
              kUnexpectedTypeForRegExpDataFixedArrayExpected,
              t0,
@@ -6164,7 +6164,7 @@
     // Initial map for the builtin Array function should be a map.
__ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
     // Will both indicate a NULL and a Smi.
-    __ And(at, a3, Operand(kSmiTagMask));
+    __ SmiTst(a3, at);
     __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
         at, Operand(zero_reg));
     __ GetObjectType(a3, a3, t0);
@@ -6253,7 +6253,7 @@
     // Initial map for the builtin Array function should be a map.
__ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
     // Will both indicate a NULL and a Smi.
-    __ And(at, a3, Operand(kSmiTagMask));
+    __ SmiTst(a3, at);
     __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
         at, Operand(zero_reg));
     __ GetObjectType(a3, a3, t0);
=======================================
--- /branches/bleeding_edge/src/mips/full-codegen-mips.cc Wed Nov 20 14:17:47 2013 UTC +++ /branches/bleeding_edge/src/mips/full-codegen-mips.cc Wed Nov 20 19:01:33 2013 UTC
@@ -2914,7 +2914,7 @@
                          &if_true, &if_false, &fall_through);

   PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
-  __ And(t0, v0, Operand(kSmiTagMask));
+  __ SmiTst(v0, t0);
   Split(eq, t0, Operand(zero_reg), if_true, if_false, fall_through);

   context()->Plug(if_true, if_false);
@@ -2935,7 +2935,7 @@
                          &if_true, &if_false, &fall_through);

   PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
-  __ And(at, v0, Operand(kSmiTagMask | 0x80000000));
+  __ NonNegativeSmiTst(v0, at);
   Split(eq, at, Operand(zero_reg), if_true, if_false, fall_through);

   context()->Plug(if_true, if_false);
@@ -3528,9 +3528,9 @@
   __ Pop(index, value);

   if (FLAG_debug_code) {
-    __ And(at, value, Operand(kSmiTagMask));
+    __ SmiTst(value, at);
     __ ThrowIf(ne, kNonSmiValue, at, Operand(zero_reg));
-    __ And(at, index, Operand(kSmiTagMask));
+    __ SmiTst(index, at);
     __ ThrowIf(ne, kNonSmiIndex, at, Operand(zero_reg));
     __ SmiUntag(index, index);
static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
@@ -3565,9 +3565,9 @@
   __ Pop(index, value);

   if (FLAG_debug_code) {
-    __ And(at, value, Operand(kSmiTagMask));
+    __ SmiTst(value, at);
     __ ThrowIf(ne, kNonSmiValue, at, Operand(zero_reg));
-    __ And(at, index, Operand(kSmiTagMask));
+    __ SmiTst(index, at);
     __ ThrowIf(ne, kNonSmiIndex, at, Operand(zero_reg));
     __ SmiUntag(index, index);
static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
=======================================
--- /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc Wed Nov 20 18:22:18 2013 UTC +++ /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc Wed Nov 20 19:01:33 2013 UTC
@@ -1704,7 +1704,7 @@
   ASSERT(!scratch.is(scratch0()));
   ASSERT(!scratch.is(object));

-  __ And(at, object, Operand(kSmiTagMask));
+  __ SmiTst(object, at);
   DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg));
   __ GetObjectType(object, scratch, scratch);
   DeoptimizeIf(ne, instr->environment(), scratch, Operand(JS_DATE_TYPE));
@@ -2115,7 +2115,7 @@
         __ JumpIfSmi(reg, instr->TrueLabel(chunk_));
       } else if (expected.NeedsMap()) {
         // If we need a map later and have a Smi -> deopt.
-        __ And(at, reg, Operand(kSmiTagMask));
+        __ SmiTst(reg, at);
         DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg));
       }

@@ -3208,7 +3208,7 @@
   // Check for the hole value.
   if (instr->hydrogen()->RequiresHoleCheck()) {
     if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) {
-      __ And(scratch, result, Operand(kSmiTagMask));
+      __ SmiTst(result, scratch);
       DeoptimizeIf(ne, instr->environment(), scratch, Operand(zero_reg));
     } else {
       __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
@@ -3357,7 +3357,7 @@
   __ Branch(&global_object, eq, receiver, Operand(scratch));

   // Deoptimize if the receiver is not a JS object.
-  __ And(scratch, receiver, Operand(kSmiTagMask));
+  __ SmiTst(receiver, scratch);
   DeoptimizeIf(eq, instr->environment(), scratch, Operand(zero_reg));

   __ GetObjectType(receiver, scratch, scratch);
@@ -4135,7 +4135,7 @@
   if (FLAG_track_heap_object_fields && representation.IsHeapObject()) {
     Register value = ToRegister(instr->value());
     if (!instr->hydrogen()->value()->type().IsHeapObject()) {
-      __ And(scratch, value, Operand(kSmiTagMask));
+      __ SmiTst(value, scratch);
       DeoptimizeIf(eq, instr->environment(), scratch, Operand(zero_reg));
     }
   } else if (FLAG_track_double_fields && representation.IsDouble()) {
@@ -5130,7 +5130,7 @@

 void LCodeGen::DoCheckSmi(LCheckSmi* instr) {
   LOperand* input = instr->value();
-  __ And(at, ToRegister(input), Operand(kSmiTagMask));
+  __ SmiTst(ToRegister(input), at);
   DeoptimizeIf(ne, instr->environment(), at, Operand(zero_reg));
 }

@@ -5138,7 +5138,7 @@
 void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) {
   if (!instr->hydrogen()->value()->IsHeapObject()) {
     LOperand* input = instr->value();
-    __ And(at, ToRegister(input), Operand(kSmiTagMask));
+    __ SmiTst(ToRegister(input), at);
     DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg));
   }
 }
@@ -5211,7 +5211,7 @@
         instr->pointer_map(), 1, Safepoint::kNoLazyDeopt);
     __ StoreToSafepointRegisterSlot(v0, scratch0());
   }
-  __ And(at, scratch0(), Operand(kSmiTagMask));
+  __ SmiTst(scratch0(), at);
   DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg));
 }

=======================================
--- /branches/bleeding_edge/src/mips/macro-assembler-mips.cc Wed Nov 20 18:22:18 2013 UTC +++ /branches/bleeding_edge/src/mips/macro-assembler-mips.cc Wed Nov 20 19:01:33 2013 UTC
@@ -4845,7 +4845,7 @@
 void MacroAssembler::AssertString(Register object) {
   if (emit_debug_code()) {
     STATIC_ASSERT(kSmiTag == 0);
-    And(t0, object, Operand(kSmiTagMask));
+    SmiTst(object, t0);
     Check(ne, kOperandIsASmiAndNotAString, t0, Operand(zero_reg));
     push(object);
     lw(object, FieldMemOperand(object, HeapObject::kMapOffset));
@@ -4859,7 +4859,7 @@
 void MacroAssembler::AssertName(Register object) {
   if (emit_debug_code()) {
     STATIC_ASSERT(kSmiTag == 0);
-    And(t0, object, Operand(kSmiTagMask));
+    SmiTst(object, t0);
     Check(ne, kOperandIsASmiAndNotAName, t0, Operand(zero_reg));
     push(object);
     lw(object, FieldMemOperand(object, HeapObject::kMapOffset));
@@ -5059,7 +5059,7 @@
                                                Register scratch,
                                                uint32_t encoding_mask) {
   Label is_object;
-  And(at, string, Operand(kSmiTagMask));
+  SmiTst(string, at);
   ThrowIf(eq, kNonObject, at, Operand(zero_reg));

   lw(at, FieldMemOperand(string, HeapObject::kMapOffset));
@@ -5073,9 +5073,7 @@
// string length without using a temp register, it is restored at the end of
   // this function.
   Label index_tag_ok, index_tag_bad;
-  // On ARM TrySmiTag is used here.
-  AdduAndCheckForOverflow(index, index, index, scratch);
-  BranchOnOverflow(&index_tag_bad, scratch);
+  TrySmiTag(index, scratch, &index_tag_bad);
   Branch(&index_tag_ok);
   bind(&index_tag_bad);
   Throw(kIndexIsTooLarge);
=======================================
--- /branches/bleeding_edge/src/mips/macro-assembler-mips.h Tue Nov 19 22:23:41 2013 UTC +++ /branches/bleeding_edge/src/mips/macro-assembler-mips.h Wed Nov 20 19:01:33 2013 UTC
@@ -1370,6 +1370,21 @@
   void SmiTag(Register dst, Register src) {
     Addu(dst, src, src);
   }
+
+  // Try to convert int32 to smi. If the value is to large, preserve
+  // the original value and jump to not_a_smi. Destroys scratch and
+  // sets flags.
+  void TrySmiTag(Register reg, Register scratch, Label* not_a_smi) {
+    TrySmiTag(reg, reg, scratch, not_a_smi);
+  }
+  void TrySmiTag(Register dst,
+                 Register src,
+                 Register scratch,
+                 Label* not_a_smi) {
+    SmiTagCheckOverflow(at, src, scratch);
+    BranchOnOverflow(not_a_smi, scratch);
+    mov(dst, at);
+  }

   void SmiUntag(Register reg) {
     sra(reg, reg, kSmiTagSize);
@@ -1378,6 +1393,14 @@
   void SmiUntag(Register dst, Register src) {
     sra(dst, src, kSmiTagSize);
   }
+
+  // Test if the register contains a smi.
+  inline void SmiTst(Register value, Register scratch) {
+    And(scratch, value, Operand(kSmiTagMask));
+  }
+  inline void NonNegativeSmiTst(Register value, Register scratch) {
+    And(scratch, value, Operand(kSmiTagMask | kSmiSignMask));
+  }

   // Untag the source value into destination and jump if source is a smi.
   // Souce and destination can be the same register.
=======================================
--- /branches/bleeding_edge/src/mips/stub-cache-mips.cc Tue Nov 19 16:06:11 2013 UTC +++ /branches/bleeding_edge/src/mips/stub-cache-mips.cc Wed Nov 20 19:01:33 2013 UTC
@@ -2316,7 +2316,7 @@

   // If the argument is a smi, just return.
   STATIC_ASSERT(kSmiTag == 0);
-  __ And(t0, v0, Operand(kSmiTagMask));
+  __ SmiTst(v0, t0);
   __ DropAndRet(argc + 1, eq, t0, Operand(zero_reg));

__ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to