From 0e8b83129e71712f0beefd2a9ee4b7ff324894c9 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 11 Sep 2013 02:10:17 -0700 Subject: [PATCH] Bug 900257: Inline Math.fround in IonMonkey; r=sstangl --- js/src/jit/IonBuilder.h | 1 + js/src/jit/MCallOptimize.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/js/src/jit/IonBuilder.h b/js/src/jit/IonBuilder.h index 42ef30965ca..8dbc0286c90 100644 --- a/js/src/jit/IonBuilder.h +++ b/js/src/jit/IonBuilder.h @@ -516,6 +516,7 @@ class IonBuilder : public MIRGenerator InliningStatus inlineMathPow(CallInfo &callInfo); InliningStatus inlineMathRandom(CallInfo &callInfo); InliningStatus inlineMathImul(CallInfo &callInfo); + InliningStatus inlineMathFRound(CallInfo &callInfo); InliningStatus inlineMathFunction(CallInfo &callInfo, MMathFunction::Function function); // String natives. diff --git a/js/src/jit/MCallOptimize.cpp b/js/src/jit/MCallOptimize.cpp index 086add0fdc4..3fdd8471de0 100644 --- a/js/src/jit/MCallOptimize.cpp +++ b/js/src/jit/MCallOptimize.cpp @@ -9,6 +9,7 @@ #include "builtin/ParallelArray.h" #include "builtin/TestingFunctions.h" #include "jit/IonBuilder.h" +#include "jit/Lowering.h" #include "jit/MIR.h" #include "jit/MIRGraph.h" @@ -55,6 +56,8 @@ IonBuilder::inlineNativeCall(CallInfo &callInfo, JSNative native) return inlineMathRandom(callInfo); if (native == js::math_imul) return inlineMathImul(callInfo); + if (native == js::math_fround) + return inlineMathFRound(callInfo); if (native == js::math_sin) return inlineMathFunction(callInfo, MMathFunction::Sin); if (native == js::math_cos) @@ -811,6 +814,33 @@ IonBuilder::inlineMathImul(CallInfo &callInfo) return InliningStatus_Inlined; } +IonBuilder::InliningStatus +IonBuilder::inlineMathFRound(CallInfo &callInfo) +{ + if (!LIRGenerator::allowFloat32Optimizations()) + return InliningStatus_NotInlined; + + if (callInfo.argc() != 1 || callInfo.constructing()) + return InliningStatus_NotInlined; + + // MIRType can't be Float32, as this point, as getInlineReturnType uses JSVal types + // to infer the returned MIR type. + MIRType returnType = getInlineReturnType(); + if (!IsNumberType(returnType)) + return InliningStatus_NotInlined; + + MIRType arg = callInfo.getArg(0)->type(); + if (!IsNumberType(arg)) + return InliningStatus_NotInlined; + + callInfo.unwrapArgs(); + + MToFloat32 *ins = MToFloat32::New(callInfo.getArg(0)); + current->add(ins); + current->push(ins); + return InliningStatus_Inlined; +} + IonBuilder::InliningStatus IonBuilder::inlineMathMinMax(CallInfo &callInfo, bool max) {