From fc263074870c11abbe4f751e453b68109e77bcfd Mon Sep 17 00:00:00 2001 From: "ager@chromium.org" Date: Mon, 21 Dec 2009 13:30:10 +0000 Subject: [PATCH] Remove complicated Math.sin and Math.cos optimizations that do not buy us much. Review URL: http://codereview.chromium.org/509006 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3507 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/codegen-arm-inl.h | 10 ------ src/arm/codegen-arm.cc | 15 --------- src/arm/codegen-arm.h | 6 ---- src/codegen.cc | 2 -- src/ia32/codegen-ia32-inl.h | 10 ------ src/ia32/codegen-ia32.cc | 74 ++------------------------------------------- src/ia32/codegen-ia32.h | 9 ------ src/math.js | 4 +-- src/x64/codegen-x64-inl.h | 10 ------ src/x64/codegen-x64.cc | 66 ---------------------------------------- src/x64/codegen-x64.h | 6 ---- 11 files changed, 5 insertions(+), 207 deletions(-) diff --git a/src/arm/codegen-arm-inl.h b/src/arm/codegen-arm-inl.h index 749f32d..17e18d9 100644 --- a/src/arm/codegen-arm-inl.h +++ b/src/arm/codegen-arm-inl.h @@ -67,16 +67,6 @@ void Reference::GetValueAndSpill() { void DeferredCode::Jump() { __ jmp(&entry_label_); } void DeferredCode::Branch(Condition cc) { __ b(cc, &entry_label_); } -void CodeGenerator::GenerateMathSin(ZoneList* args) { - GenerateFastMathOp(SIN, args); -} - - -void CodeGenerator::GenerateMathCos(ZoneList* args) { - GenerateFastMathOp(COS, args); -} - - #undef __ } } // namespace v8::internal diff --git a/src/arm/codegen-arm.cc b/src/arm/codegen-arm.cc index 89d974c..9d240dc 100644 --- a/src/arm/codegen-arm.cc +++ b/src/arm/codegen-arm.cc @@ -3544,21 +3544,6 @@ void CodeGenerator::GenerateRandomPositiveSmi(ZoneList* args) { } -void CodeGenerator::GenerateFastMathOp(MathOp op, ZoneList* 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* args) { ASSERT_EQ(2, args->length()); diff --git a/src/arm/codegen-arm.h b/src/arm/codegen-arm.h index e9f11e9..df7c805 100644 --- a/src/arm/codegen-arm.h +++ b/src/arm/codegen-arm.h @@ -360,12 +360,6 @@ class CodeGenerator: public AstVisitor { // Fast support for Math.random(). void GenerateRandomPositiveSmi(ZoneList* args); - // Fast support for Math.sin and Math.cos. - enum MathOp { SIN, COS }; - void GenerateFastMathOp(MathOp op, ZoneList* args); - inline void GenerateMathSin(ZoneList* args); - inline void GenerateMathCos(ZoneList* args); - // Fast support for StringAdd. void GenerateStringAdd(ZoneList* args); diff --git a/src/codegen.cc b/src/codegen.cc index 26e8d7d..1ae93fa 100644 --- a/src/codegen.cc +++ b/src/codegen.cc @@ -342,8 +342,6 @@ CodeGenerator::InlineRuntimeLUT CodeGenerator::kInlineRuntimeLUT[] = { {&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"}, diff --git a/src/ia32/codegen-ia32-inl.h b/src/ia32/codegen-ia32-inl.h index 44e937a..49c706d 100644 --- a/src/ia32/codegen-ia32-inl.h +++ b/src/ia32/codegen-ia32-inl.h @@ -39,16 +39,6 @@ namespace internal { void DeferredCode::Jump() { __ jmp(&entry_label_); } void DeferredCode::Branch(Condition cc) { __ j(cc, &entry_label_); } -void CodeGenerator::GenerateMathSin(ZoneList* args) { - GenerateFastMathOp(SIN, args); -} - - -void CodeGenerator::GenerateMathCos(ZoneList* args) { - GenerateFastMathOp(COS, args); -} - - #undef __ } } // namespace v8::internal diff --git a/src/ia32/codegen-ia32.cc b/src/ia32/codegen-ia32.cc index 7b2bff6..fa3fe3f 100644 --- a/src/ia32/codegen-ia32.cc +++ b/src/ia32/codegen-ia32.cc @@ -5375,75 +5375,6 @@ void CodeGenerator::GenerateRandomPositiveSmi(ZoneList* args) { } -void CodeGenerator::GenerateFastMathOp(MathOp op, ZoneList* 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* args) { ASSERT_EQ(2, args->length()); @@ -7465,8 +7396,9 @@ void IntegerConvert(MacroAssembler* masm, 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)); diff --git a/src/ia32/codegen-ia32.h b/src/ia32/codegen-ia32.h index 10b45d5..c5daca7 100644 --- a/src/ia32/codegen-ia32.h +++ b/src/ia32/codegen-ia32.h @@ -326,9 +326,6 @@ class CodeGenerator: public AstVisitor { 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 CodeGenerator(int buffer_size, Handle