From 911efad68f11711ebf8808cee5aaf965ddfc75fd Mon Sep 17 00:00:00 2001 From: "Nicolas B. Pierron" Date: Mon, 26 Jan 2015 12:22:56 +0100 Subject: [PATCH] Bug 1118344 - IonMonkey: Inline SIMD.int32x4.add calls. r=bbouvier --- js/src/jit/IonBuilder.h | 4 ++++ js/src/jit/MCallOptimize.cpp | 37 ++++++++++++++++++++++++++++++++++++ js/src/jit/MIR.h | 14 ++++++++++---- js/src/jit/TypePolicy.cpp | 1 + 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/js/src/jit/IonBuilder.h b/js/src/jit/IonBuilder.h index e86fc5997b75..28bbb0b2084f 100644 --- a/js/src/jit/IonBuilder.h +++ b/js/src/jit/IonBuilder.h @@ -788,7 +788,11 @@ class IonBuilder bool elementAccessIsTypedObjectArrayOfScalarType(MDefinition* obj, MDefinition* id, ScalarTypeDescr::Type *arrayType); InliningStatus inlineConstructTypedObject(CallInfo &callInfo, TypeDescr *target); + + // SIMD intrinsics and natives. InliningStatus inlineConstructSimdObject(CallInfo &callInfo, SimdTypeDescr *target); + InliningStatus inlineSimdInt32x4BinaryArith(CallInfo &callInfo, JSNative native, + MSimdBinaryArith::Operation op); // Utility intrinsics. InliningStatus inlineIsCallable(CallInfo &callInfo); diff --git a/js/src/jit/MCallOptimize.cpp b/js/src/jit/MCallOptimize.cpp index 5c68a4c98d9e..8ea0a204d41f 100644 --- a/js/src/jit/MCallOptimize.cpp +++ b/js/src/jit/MCallOptimize.cpp @@ -7,6 +7,7 @@ #include "jsmath.h" #include "builtin/AtomicsObject.h" +#include "builtin/SIMD.h" #include "builtin/TestingFunctions.h" #include "builtin/TypedObject.h" #include "jit/BaselineInspector.h" @@ -246,6 +247,10 @@ IonBuilder::inlineNativeCall(CallInfo &callInfo, JSFunction *target) if (native == js::CallOrConstructBoundFunction) return inlineBoundFunction(callInfo, target); + // Simd functions + if (native == js::simd_int32x4_add) + return inlineSimdInt32x4BinaryArith(callInfo, native, MSimdBinaryArith::Add); + return InliningStatus_NotInlined; } @@ -2612,5 +2617,37 @@ IonBuilder::inlineConstructSimdObject(CallInfo &callInfo, SimdTypeDescr *descr) return InliningStatus_Inlined; } +IonBuilder::InliningStatus +IonBuilder::inlineSimdInt32x4BinaryArith(CallInfo &callInfo, JSNative native, + MSimdBinaryArith::Operation op) +{ + if (callInfo.argc() != 2) + return InliningStatus_NotInlined; + + JSObject *templateObject = inspector->getTemplateObjectForNative(pc, native); + if (!templateObject) + return InliningStatus_NotInlined; + + InlineTypedObject *inlineTypedObject = &templateObject->as(); + MOZ_ASSERT(inlineTypedObject->typeDescr().as().type() == js::Int32x4::type); + + // If the type of any of the arguments is neither a SIMD type, an Object + // type, or a Value, then the applyTypes phase will add a fallible box & + // unbox sequence. This does not matter much as the binary arithmetic + // instruction is supposed to produce a TypeError once it is called. + MSimdBinaryArith *ins = MSimdBinaryArith::New(alloc(), callInfo.getArg(0), callInfo.getArg(1), + op, MIRType_Int32x4); + + MSimdBox *obj = MSimdBox::New(alloc(), constraints(), ins, inlineTypedObject, + inlineTypedObject->type()->initialHeap(constraints())); + + current->add(ins); + current->add(obj); + current->push(obj); + + callInfo.setImplicitlyUsedUnchecked(); + return InliningStatus_Inlined; +} + } // namespace jit } // namespace js diff --git a/js/src/jit/MIR.h b/js/src/jit/MIR.h index 25aa92107caf..8d64878d13e2 100644 --- a/js/src/jit/MIR.h +++ b/js/src/jit/MIR.h @@ -1922,7 +1922,7 @@ class MSimdBinaryComp class MSimdBinaryArith : public MBinaryInstruction, - public NoTypePolicy::Data + public MixPolicy, SimdSameAsReturnedTypePolicy<1> >::Data { public: enum Operation { @@ -1958,8 +1958,6 @@ class MSimdBinaryArith { MOZ_ASSERT_IF(type == MIRType_Int32x4, op == Add || op == Sub || op == Mul); MOZ_ASSERT(IsSimdType(type)); - MOZ_ASSERT(left->type() == right->type()); - MOZ_ASSERT(left->type() == type); setResultType(type); setMovable(); if (op == Add || op == Mul || op == Min || op == Max) @@ -1968,10 +1966,18 @@ class MSimdBinaryArith public: INSTRUCTION_HEADER(SimdBinaryArith) + static MSimdBinaryArith *New(TempAllocator &alloc, MDefinition *left, MDefinition *right, + Operation op, MIRType t) + { + return new(alloc) MSimdBinaryArith(left, right, op, t); + } + static MSimdBinaryArith *NewAsmJS(TempAllocator &alloc, MDefinition *left, MDefinition *right, Operation op, MIRType t) { - return new(alloc) MSimdBinaryArith(left, right, op, t); + MOZ_ASSERT(left->type() == right->type()); + MOZ_ASSERT(left->type() == t); + return New(alloc, left, right, op, t); } AliasSet getAliasSet() const MOZ_OVERRIDE { diff --git a/js/src/jit/TypePolicy.cpp b/js/src/jit/TypePolicy.cpp index b38e4a9ca381..335dc62eff83 100644 --- a/js/src/jit/TypePolicy.cpp +++ b/js/src/jit/TypePolicy.cpp @@ -1065,6 +1065,7 @@ FilterTypeSetPolicy::adjustInputs(TempAllocator &alloc, MInstruction *ins) _(MixPolicy, StringPolicy<1> >) \ _(MixPolicy, ConvertToStringPolicy<2> >) \ _(MixPolicy, ConvertToStringPolicy<0> >) \ + _(MixPolicy, SimdSameAsReturnedTypePolicy<1> >) \ _(MixPolicy, IntPolicy<1> >) \ _(MixPolicy, StringPolicy<1> >) \ _(NoFloatPolicy<0>) \