Revision: 3507
Author: [email protected]
Date: Mon Dec 21 05:30:10 2009
Log: Remove complicated Math.sin and Math.cos optimizations that do not buy
us much.
Review URL: http://codereview.chromium.org/509006
http://code.google.com/p/v8/source/detail?r=3507

Modified:
  /branches/bleeding_edge/src/arm/codegen-arm-inl.h
  /branches/bleeding_edge/src/arm/codegen-arm.cc
  /branches/bleeding_edge/src/arm/codegen-arm.h
  /branches/bleeding_edge/src/codegen.cc
  /branches/bleeding_edge/src/ia32/codegen-ia32-inl.h
  /branches/bleeding_edge/src/ia32/codegen-ia32.cc
  /branches/bleeding_edge/src/ia32/codegen-ia32.h
  /branches/bleeding_edge/src/math.js
  /branches/bleeding_edge/src/x64/codegen-x64-inl.h
  /branches/bleeding_edge/src/x64/codegen-x64.cc
  /branches/bleeding_edge/src/x64/codegen-x64.h

=======================================
--- /branches/bleeding_edge/src/arm/codegen-arm-inl.h   Wed Nov  4 05:56:41  
2009
+++ /branches/bleeding_edge/src/arm/codegen-arm-inl.h   Mon Dec 21 05:30:10  
2009
@@ -67,16 +67,6 @@
  void DeferredCode::Jump() { __ jmp(&entry_label_); }
  void DeferredCode::Branch(Condition cc) { __ b(cc, &entry_label_); }

-void CodeGenerator::GenerateMathSin(ZoneList<Expression*>* args) {
-  GenerateFastMathOp(SIN, args);
-}
-
-
-void CodeGenerator::GenerateMathCos(ZoneList<Expression*>* args) {
-  GenerateFastMathOp(COS, args);
-}
-
-
  #undef __

  } }  // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/arm/codegen-arm.cc      Fri Dec 11 02:40:01 2009
+++ /branches/bleeding_edge/src/arm/codegen-arm.cc      Mon Dec 21 05:30:10 2009
@@ -3542,21 +3542,6 @@
            RelocInfo::RUNTIME_ENTRY);
    frame_->EmitPush(r0);
  }
-
-
-void CodeGenerator::GenerateFastMathOp(MathOp op, ZoneList<Expression*>*  
args) {
-  VirtualFrame::SpilledScope spilled_scope;
-  LoadAndSpill(args->at(0));
-  switch (op) {
-    case SIN:
-      frame_->CallRuntime(Runtime::kMath_sin, 1);
-      break;
-    case COS:
-      frame_->CallRuntime(Runtime::kMath_cos, 1);
-      break;
-  }
-  frame_->EmitPush(r0);
-}


  void CodeGenerator::GenerateStringAdd(ZoneList<Expression*>* args) {
=======================================
--- /branches/bleeding_edge/src/arm/codegen-arm.h       Fri Dec 11 02:40:01 2009
+++ /branches/bleeding_edge/src/arm/codegen-arm.h       Mon Dec 21 05:30:10 2009
@@ -360,12 +360,6 @@
    // Fast support for Math.random().
    void GenerateRandomPositiveSmi(ZoneList<Expression*>* args);

-  // Fast support for Math.sin and Math.cos.
-  enum MathOp { SIN, COS };
-  void GenerateFastMathOp(MathOp op, ZoneList<Expression*>* args);
-  inline void GenerateMathSin(ZoneList<Expression*>* args);
-  inline void GenerateMathCos(ZoneList<Expression*>* args);
-
    // Fast support for StringAdd.
    void GenerateStringAdd(ZoneList<Expression*>* args);

=======================================
--- /branches/bleeding_edge/src/codegen.cc      Wed Dec  2 23:56:21 2009
+++ /branches/bleeding_edge/src/codegen.cc      Mon Dec 21 05:30:10 2009
@@ -342,8 +342,6 @@
    {&CodeGenerator::GenerateObjectEquals, "_ObjectEquals"},
    {&CodeGenerator::GenerateLog, "_Log"},
    {&CodeGenerator::GenerateRandomPositiveSmi, "_RandomPositiveSmi"},
-  {&CodeGenerator::GenerateMathSin, "_Math_sin"},
-  {&CodeGenerator::GenerateMathCos, "_Math_cos"},
    {&CodeGenerator::GenerateIsObject, "_IsObject"},
    {&CodeGenerator::GenerateIsFunction, "_IsFunction"},
    {&CodeGenerator::GenerateStringAdd, "_StringAdd"},
=======================================
--- /branches/bleeding_edge/src/ia32/codegen-ia32-inl.h Thu Aug 27 02:08:16  
2009
+++ /branches/bleeding_edge/src/ia32/codegen-ia32-inl.h Mon Dec 21 05:30:10  
2009
@@ -39,16 +39,6 @@
  void DeferredCode::Jump() { __ jmp(&entry_label_); }
  void DeferredCode::Branch(Condition cc) { __ j(cc, &entry_label_); }

-void CodeGenerator::GenerateMathSin(ZoneList<Expression*>* args) {
-  GenerateFastMathOp(SIN, args);
-}
-
-
-void CodeGenerator::GenerateMathCos(ZoneList<Expression*>* args) {
-  GenerateFastMathOp(COS, args);
-}
-
-
  #undef __

  } }  // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/ia32/codegen-ia32.cc    Mon Dec 21 04:08:59  
2009
+++ /branches/bleeding_edge/src/ia32/codegen-ia32.cc    Mon Dec 21 05:30:10  
2009
@@ -5373,75 +5373,6 @@
    Result result = allocator_->Allocate(eax);
    frame_->Push(&result);
  }
-
-
-void CodeGenerator::GenerateFastMathOp(MathOp op, ZoneList<Expression*>*  
args) {
-  JumpTarget done;
-  JumpTarget call_runtime;
-  ASSERT(args->length() == 1);
-
-  // Load number and duplicate it.
-  Load(args->at(0));
-  frame_->Dup();
-
-  // Get the number into an unaliased register and load it onto the
-  // floating point stack still leaving one copy on the frame.
-  Result number = frame_->Pop();
-  number.ToRegister();
-  frame_->Spill(number.reg());
-  FloatingPointHelper::LoadFloatOperand(masm_, number.reg());
-
-  // Check whether the exponent is so big that performing a sine or
-  // cosine operation could result in inaccurate results or an
-  // exception.  In that case call the runtime routine.
-  __ and_(number.reg(), HeapNumber::kExponentMask);
-  __ cmp(Operand(number.reg()), Immediate(kTwoToThePowerOf63Exponent));
-  call_runtime.Branch(greater_equal, not_taken);
-  number.Unuse();
-
-  // Perform the operation on the number.  This will succeed since we
-  // already checked that it is in range.
-  switch (op) {
-    case SIN:
-      __ fsin();
-      break;
-    case COS:
-      __ fcos();
-      break;
-  }
-
-  // Allocate heap number for result if possible.
-  Result scratch1 = allocator()->Allocate();
-  Result scratch2 = allocator()->Allocate();
-  Result heap_number = allocator()->Allocate();
-  __ AllocateHeapNumber(heap_number.reg(),
-                        scratch1.reg(),
-                        scratch2.reg(),
-                        call_runtime.entry_label());
-  scratch1.Unuse();
-  scratch2.Unuse();
-
-  // Store the result in the allocated heap number.
-  __ fstp_d(FieldOperand(heap_number.reg(), HeapNumber::kValueOffset));
-  // Replace the extra copy of the argument with the result.
-  frame_->SetElementAt(0, &heap_number);
-  done.Jump();
-
-  call_runtime.Bind();
-  // Free ST(0) which was not popped before calling into the runtime.
-  __ ffree(0);
-  Result answer;
-  switch (op) {
-    case SIN:
-      answer = frame_->CallRuntime(Runtime::kMath_sin, 1);
-      break;
-    case COS:
-      answer = frame_->CallRuntime(Runtime::kMath_cos, 1);
-      break;
-  }
-  frame_->Push(&answer);
-  done.Bind();
-}


  void CodeGenerator::GenerateStringAdd(ZoneList<Expression*>* args) {
@@ -7465,8 +7396,9 @@
    if (use_sse3) {
      CpuFeatures::Scope scope(SSE3);
      // Check whether the exponent is too big for a 64 bit signed integer.
-    __ cmp(Operand(scratch2),
-           Immediate(CodeGenerator::kTwoToThePowerOf63Exponent));
+    static const uint32_t kTooBigExponent =
+        (HeapNumber::kExponentBias + 63) << HeapNumber::kExponentShift;
+    __ cmp(Operand(scratch2), Immediate(kTooBigExponent));
      __ j(greater_equal, conversion_failure);
      // Load x87 register with heap number.
      __ fld_d(FieldOperand(source, HeapNumber::kValueOffset));
=======================================
--- /branches/bleeding_edge/src/ia32/codegen-ia32.h     Mon Dec 21 04:08:59 2009
+++ /branches/bleeding_edge/src/ia32/codegen-ia32.h     Mon Dec 21 05:30:10 2009
@@ -325,9 +325,6 @@

    bool in_spilled_code() const { return in_spilled_code_; }
    void set_in_spilled_code(bool flag) { in_spilled_code_ = flag; }
-
-  static const uint32_t kTwoToThePowerOf63Exponent =
-      (HeapNumber::kExponentBias + 63) << HeapNumber::kExponentShift;

   private:
    // Construction/Destruction
@@ -544,12 +541,6 @@
    // Fast support for Math.random().
    void GenerateRandomPositiveSmi(ZoneList<Expression*>* args);

-  // Fast support for Math.sin and Math.cos.
-  enum MathOp { SIN, COS };
-  void GenerateFastMathOp(MathOp op, ZoneList<Expression*>* args);
-  inline void GenerateMathSin(ZoneList<Expression*>* args);
-  inline void GenerateMathCos(ZoneList<Expression*>* args);
-
    // Fast support for StringAdd.
    void GenerateStringAdd(ZoneList<Expression*>* args);

=======================================
--- /branches/bleeding_edge/src/math.js Tue Dec  8 02:18:28 2009
+++ /branches/bleeding_edge/src/math.js Mon Dec 21 05:30:10 2009
@@ -84,7 +84,7 @@
  // ECMA 262 - 15.8.2.7
  function MathCos(x) {
    if (!IS_NUMBER(x)) x = ToNumber(x);
-  return %_Math_cos(x);
+  return %Math_cos(x);
  }

  // ECMA 262 - 15.8.2.8
@@ -176,7 +176,7 @@
  // ECMA 262 - 15.8.2.16
  function MathSin(x) {
    if (!IS_NUMBER(x)) x = ToNumber(x);
-  return %_Math_sin(x);
+  return %Math_sin(x);
  }

  // ECMA 262 - 15.8.2.17
=======================================
--- /branches/bleeding_edge/src/x64/codegen-x64-inl.h   Thu Aug 27 23:18:36  
2009
+++ /branches/bleeding_edge/src/x64/codegen-x64-inl.h   Mon Dec 21 05:30:10  
2009
@@ -38,16 +38,6 @@

  void DeferredCode::Jump() { __ jmp(&entry_label_); }
  void DeferredCode::Branch(Condition cc) { __ j(cc, &entry_label_); }
-
-
-void CodeGenerator::GenerateMathSin(ZoneList<Expression*>* args) {
-  GenerateFastMathOp(SIN, args);
-}
-
-
-void CodeGenerator::GenerateMathCos(ZoneList<Expression*>* args) {
-  GenerateFastMathOp(COS, args);
-}

  #undef __

=======================================
--- /branches/bleeding_edge/src/x64/codegen-x64.cc      Wed Dec 16 23:18:05 2009
+++ /branches/bleeding_edge/src/x64/codegen-x64.cc      Mon Dec 21 05:30:10 2009
@@ -3977,72 +3977,6 @@
    Result result = allocator_->Allocate(rax);
    frame_->Push(&result);
  }
-
-
-void CodeGenerator::GenerateFastMathOp(MathOp op, ZoneList<Expression*>*  
args) {
-  JumpTarget done;
-  JumpTarget call_runtime;
-  ASSERT(args->length() == 1);
-
-  // Load number and duplicate it.
-  Load(args->at(0));
-  frame_->Dup();
-
-  // Get the number into an unaliased register and load it onto the
-  // floating point stack still leaving one copy on the frame.
-  Result number = frame_->Pop();
-  number.ToRegister();
-  frame_->Spill(number.reg());
-  FloatingPointHelper::LoadFloatOperand(masm_, number.reg());
-  number.Unuse();
-
-  // Perform the operation on the number.
-  switch (op) {
-    case SIN:
-      __ fsin();
-      break;
-    case COS:
-      __ fcos();
-      break;
-  }
-
-  // Go slow case if argument to operation is out of range.
-  Result eax_reg = allocator()->Allocate(rax);
-  ASSERT(eax_reg.is_valid());
-  __ fnstsw_ax();
-  __ testl(rax, Immediate(0x0400));  // Bit 10 is condition flag C2.
-  eax_reg.Unuse();
-  call_runtime.Branch(not_zero);
-
-  // Allocate heap number for result if possible.
-  Result scratch = allocator()->Allocate();
-  Result heap_number = allocator()->Allocate();
-  __ AllocateHeapNumber(heap_number.reg(),
-                        scratch.reg(),
-                        call_runtime.entry_label());
-  scratch.Unuse();
-
-  // Store the result in the allocated heap number.
-  __ fstp_d(FieldOperand(heap_number.reg(), HeapNumber::kValueOffset));
-  // Replace the extra copy of the argument with the result.
-  frame_->SetElementAt(0, &heap_number);
-  done.Jump();
-
-  call_runtime.Bind();
-  // Free ST(0) which was not popped before calling into the runtime.
-  __ ffree(0);
-  Result answer;
-  switch (op) {
-    case SIN:
-      answer = frame_->CallRuntime(Runtime::kMath_sin, 1);
-      break;
-    case COS:
-      answer = frame_->CallRuntime(Runtime::kMath_cos, 1);
-      break;
-  }
-  frame_->Push(&answer);
-  done.Bind();
-}


  void CodeGenerator::GenerateStringAdd(ZoneList<Expression*>* args) {
=======================================
--- /branches/bleeding_edge/src/x64/codegen-x64.h       Wed Dec 16 23:18:05 2009
+++ /branches/bleeding_edge/src/x64/codegen-x64.h       Mon Dec 21 05:30:10 2009
@@ -538,12 +538,6 @@
    // Fast support for Math.random().
    void GenerateRandomPositiveSmi(ZoneList<Expression*>* args);

-  // Fast support for Math.sin and Math.cos.
-  enum MathOp { SIN, COS };
-  void GenerateFastMathOp(MathOp op, ZoneList<Expression*>* args);
-  inline void GenerateMathSin(ZoneList<Expression*>* args);
-  inline void GenerateMathCos(ZoneList<Expression*>* args);
-
    // Fast support for StringAdd.
    void GenerateStringAdd(ZoneList<Expression*>* args);

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

Reply via email to