From 576b035153715864ef304db001bb4aa46cd98efa Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 19 Dec 2013 15:32:59 +0100 Subject: [PATCH] Bug 936740: inline call to libc's ceil for Math.ceil(); r=jandem --- js/src/jit/CodeGenerator.cpp | 4 ++++ js/src/jit/IonBuilder.h | 1 + js/src/jit/MCallOptimize.cpp | 32 ++++++++++++++++++++++++++++++++ js/src/jit/MIR.cpp | 1 + js/src/jit/MIR.h | 4 +++- 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/js/src/jit/CodeGenerator.cpp b/js/src/jit/CodeGenerator.cpp index a265dec6d5a6..beec82507461 100644 --- a/js/src/jit/CodeGenerator.cpp +++ b/js/src/jit/CodeGenerator.cpp @@ -4099,6 +4099,9 @@ CodeGenerator::visitMathFunctionD(LMathFunctionD *ins) case MMathFunction::Floor: funptr = JS_FUNC_TO_DATA_PTR(void *, js::math_floor_impl); break; + case MMathFunction::Ceil: + funptr = JS_FUNC_TO_DATA_PTR(void *, js::math_ceil_impl); + break; case MMathFunction::Round: funptr = JS_FUNC_TO_DATA_PTR(void *, js::math_round_impl); break; @@ -4133,6 +4136,7 @@ CodeGenerator::visitMathFunctionF(LMathFunctionF *ins) case MMathFunction::ASin: funptr = JS_FUNC_TO_DATA_PTR(void *, asinf); break; case MMathFunction::ACos: funptr = JS_FUNC_TO_DATA_PTR(void *, acosf); break; case MMathFunction::Floor: funptr = JS_FUNC_TO_DATA_PTR(void *, floorf); break; + case MMathFunction::Ceil: funptr = JS_FUNC_TO_DATA_PTR(void *, ceilf); break; default: MOZ_ASSUME_UNREACHABLE("Unknown or unsupported float32 math function"); } diff --git a/js/src/jit/IonBuilder.h b/js/src/jit/IonBuilder.h index ebd31b3fb620..adf4320e6d21 100644 --- a/js/src/jit/IonBuilder.h +++ b/js/src/jit/IonBuilder.h @@ -611,6 +611,7 @@ class IonBuilder : public MIRGenerator // Math natives. InliningStatus inlineMathAbs(CallInfo &callInfo); InliningStatus inlineMathFloor(CallInfo &callInfo); + InliningStatus inlineMathCeil(CallInfo &callInfo); InliningStatus inlineMathRound(CallInfo &callInfo); InliningStatus inlineMathSqrt(CallInfo &callInfo); InliningStatus inlineMathAtan2(CallInfo &callInfo); diff --git a/js/src/jit/MCallOptimize.cpp b/js/src/jit/MCallOptimize.cpp index 3e2b5d4976a9..1eaa3566e2b8 100644 --- a/js/src/jit/MCallOptimize.cpp +++ b/js/src/jit/MCallOptimize.cpp @@ -43,6 +43,8 @@ IonBuilder::inlineNativeCall(CallInfo &callInfo, JSNative native) return inlineMathAbs(callInfo); if (native == js::math_floor) return inlineMathFloor(callInfo); + if (native == js::math_ceil) + return inlineMathCeil(callInfo); if (native == js::math_round) return inlineMathRound(callInfo); if (native == js_math_sqrt) @@ -588,6 +590,36 @@ IonBuilder::inlineMathFloor(CallInfo &callInfo) return InliningStatus_NotInlined; } +IonBuilder::InliningStatus +IonBuilder::inlineMathCeil(CallInfo &callInfo) +{ + if (callInfo.constructing()) + return InliningStatus_NotInlined; + + if (callInfo.argc() != 1) + return InliningStatus_NotInlined; + + MIRType argType = callInfo.getArg(0)->type(); + MIRType returnType = getInlineReturnType(); + + // Math.ceil(int(x)) == int(x) + if (argType == MIRType_Int32 && returnType == MIRType_Int32) { + callInfo.unwrapArgs(); + current->push(callInfo.getArg(0)); + return InliningStatus_Inlined; + } + + if (IsFloatingPointType(argType) && returnType == MIRType_Double) { + callInfo.unwrapArgs(); + MMathFunction *ins = MMathFunction::New(alloc(), callInfo.getArg(0), MMathFunction::Ceil, nullptr); + current->add(ins); + current->push(ins); + return InliningStatus_Inlined; + } + + return InliningStatus_NotInlined; +} + IonBuilder::InliningStatus IonBuilder::inlineMathRound(CallInfo &callInfo) { diff --git a/js/src/jit/MIR.cpp b/js/src/jit/MIR.cpp index 8b02743156c2..aac62cf80a92 100644 --- a/js/src/jit/MIR.cpp +++ b/js/src/jit/MIR.cpp @@ -604,6 +604,7 @@ MMathFunction::FunctionName(Function function) case Trunc: return "Trunc"; case Cbrt: return "Cbrt"; case Floor: return "Floor"; + case Ceil: return "Ceil"; case Round: return "Round"; default: MOZ_ASSUME_UNREACHABLE("Unknown math function"); diff --git a/js/src/jit/MIR.h b/js/src/jit/MIR.h index 0267c32d9377..305b67560aa5 100644 --- a/js/src/jit/MIR.h +++ b/js/src/jit/MIR.h @@ -3875,6 +3875,7 @@ class MMathFunction Trunc, Cbrt, Floor, + Ceil, Round }; @@ -3931,7 +3932,8 @@ class MMathFunction bool isFloat32Commutative() const { return function_ == Log || function_ == Sin || function_ == Cos || function_ == Exp || function_ == Tan || function_ == ATan - || function_ == ASin || function_ == ACos || function_ == Floor; + || function_ == ASin || function_ == ACos || function_ == Floor + || function_ == Ceil; } void trySpecializeFloat32(TempAllocator &alloc); void computeRange(TempAllocator &alloc);