Reviewers: William Hesse,

Description:
Fix handling of -0 in the unary-op IC and avoid repeated patching/transitions.

When the stub return a heap number we do a state transition to
a version HEAP_NUMBER that can handle -0.

There is room for further improvement in the typefeedback for the
case of -0. This change however does not address this and only fixes
the acute issue.

Please review this at http://codereview.chromium.org/7037025/

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/arm/code-stubs-arm.cc
  M     src/ia32/code-stubs-ia32.cc
  M     src/ic.h
  M     src/ic.cc
  M     src/x64/code-stubs-x64.cc


Index: src/arm/code-stubs-arm.cc
===================================================================
--- src/arm/code-stubs-arm.cc   (revision 7936)
+++ src/arm/code-stubs-arm.cc   (working copy)
@@ -1847,12 +1847,14 @@


void TypeRecordingUnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) {
-  Label non_smi, slow;
-  GenerateSmiCodeSub(masm, &non_smi, &slow);
+  Label non_smi, slow, &call_builtin;
+  GenerateSmiCodeSub(masm, &non_smi, &call_builtin);
   __ bind(&non_smi);
   GenerateHeapNumberCodeSub(masm, &slow);
   __ bind(&slow);
   GenerateTypeTransition(masm);
+  __ bind(&call_builtin);
+  GenerateGenericCodeFallback(masm);
 }


Index: src/ia32/code-stubs-ia32.cc
===================================================================
--- src/ia32/code-stubs-ia32.cc (revision 7936)
+++ src/ia32/code-stubs-ia32.cc (working copy)
@@ -622,10 +622,13 @@
 }


-void TypeRecordingUnaryOpStub::GenerateSmiCodeSub(
-    MacroAssembler* masm, Label* non_smi, Label* undo, Label* slow,
-    Label::Distance non_smi_near, Label::Distance undo_near,
-    Label::Distance slow_near) {
+void TypeRecordingUnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm,
+                                                  Label* non_smi,
+                                                  Label* undo,
+                                                  Label* slow,
+ Label::Distance non_smi_near, + Label::Distance undo_near, + Label::Distance slow_near) {
   // Check whether the value is a smi.
   __ test(eax, Immediate(kSmiTagMask));
   __ j(not_zero, non_smi, non_smi_near);
@@ -679,14 +682,16 @@


void TypeRecordingUnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) {
-  Label non_smi, undo, slow;
-  GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear);
+  Label non_smi, undo, slow, call_builtin;
+  GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear);
   __ bind(&non_smi);
   GenerateHeapNumberCodeSub(masm, &slow);
   __ bind(&undo);
   GenerateSmiCodeUndo(masm);
   __ bind(&slow);
   GenerateTypeTransition(masm);
+  __ bind(&call_builtin);
+  GenerateGenericCodeFallback(masm);
 }


Index: src/ic.cc
===================================================================
--- src/ic.cc   (revision 7936)
+++ src/ic.cc   (working copy)
@@ -2200,9 +2200,23 @@
 }


-TRUnaryOpIC::TypeInfo TRUnaryOpIC::JoinTypes(TRUnaryOpIC::TypeInfo x,
-                                             TRUnaryOpIC::TypeInfo y) {
-  return x >= y ? x : y;
+TRUnaryOpIC::TypeInfo TRUnaryOpIC::ComputeNewType(
+    TRUnaryOpIC::TypeInfo type,
+    TRUnaryOpIC::TypeInfo previous) {
+  switch (previous) {
+    case TRUnaryOpIC::UNINITIALIZED:
+      return type;
+    case TRUnaryOpIC::SMI:
+      return (type == TRUnaryOpIC::GENERIC)
+          ? TRUnaryOpIC::GENERIC
+          : TRUnaryOpIC::HEAP_NUMBER;
+    case TRUnaryOpIC::HEAP_NUMBER:
+      return TRUnaryOpIC::GENERIC;
+    case TRUnaryOpIC::GENERIC:
+      // We should never do patching if we are in GENERIC state.
+      UNREACHABLE();
+      return TRUnaryOpIC::GENERIC;
+  }
 }


@@ -2314,7 +2328,7 @@
       static_cast<TRUnaryOpIC::TypeInfo>(Smi::cast(args[3])->value());

   TRUnaryOpIC::TypeInfo type = TRUnaryOpIC::GetTypeInfo(operand);
-  type = TRUnaryOpIC::JoinTypes(type, previous_type);
+  type = TRUnaryOpIC::ComputeNewType(type, previous_type);

   Handle<Code> code = GetTypeRecordingUnaryOpStub(key, type);
   if (!code.is_null()) {
Index: src/ic.h
===================================================================
--- src/ic.h    (revision 7936)
+++ src/ic.h    (working copy)
@@ -643,7 +643,7 @@

   static TypeInfo GetTypeInfo(Handle<Object> operand);

-  static TypeInfo JoinTypes(TypeInfo x, TypeInfo y);
+  static TypeInfo ComputeNewType(TypeInfo type, TypeInfo previous);
 };


Index: src/x64/code-stubs-x64.cc
===================================================================
--- src/x64/code-stubs-x64.cc   (revision 7936)
+++ src/x64/code-stubs-x64.cc   (working copy)
@@ -525,11 +525,13 @@

void TypeRecordingUnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) {
   Label non_smi, slow;
-  GenerateSmiCodeSub(masm, &non_smi, &slow, Label::kNear);
+  GenerateSmiCodeSub(masm, &non_smi, &call_builtin, Label::kNear);
   __ bind(&non_smi);
   GenerateHeapNumberCodeSub(masm, &slow);
   __ bind(&slow);
   GenerateTypeTransition(masm);
+  __ bind(&call_builtin);
+  GenerateGenericCodeFallBack(masm);
 }




--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to