Reviewers: Erik Corry, Description: Optimize sine and cosine by checking up front if the fsin or fcos operation can throw an exception.
Please review this at http://codereview.chromium.org/504073 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M src/ia32/codegen-ia32.cc Index: src/ia32/codegen-ia32.cc =================================================================== --- src/ia32/codegen-ia32.cc (revision 3504) +++ src/ia32/codegen-ia32.cc (working copy) @@ -5390,9 +5390,19 @@ 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. + const uint32_t too_big_exponent = + (HeapNumber::kExponentBias + 63) << HeapNumber::kExponentShift; + __ and_(number.reg(), HeapNumber::kExponentMask); + __ cmp(Operand(number.reg()), Immediate(too_big_exponent)); + call_runtime.Branch(greater_equal, not_taken); number.Unuse(); - // Perform the operation on the number. + // Perform the operation on the number. This will succeed since we + // already checked that it is in range. switch (op) { case SIN: __ fsin(); @@ -5402,14 +5412,6 @@ break; } - // Go slow case if argument to operation is out of range. - Result eax_reg = allocator_->Allocate(eax); - ASSERT(eax_reg.is_valid()); - __ fnstsw_ax(); - __ sahf(); - eax_reg.Unuse(); - call_runtime.Branch(parity_even, not_taken); - // Allocate heap number for result if possible. Result scratch1 = allocator()->Allocate(); Result scratch2 = allocator()->Allocate(); -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev
