Skip to content
Permalink
Browse files
[JSC] Improve the absThunkGenerator() for 64bit
https://bugs.webkit.org/show_bug.cgi?id=156888

Reviewed by Michael Saboff.

A few tests spend a lot of time in this abs() with double argument.

This patch adds custom handling for the JSValue64 representation.
In particular:
-Do not load the value twice. Unbox the GPR if it is not an Int32.
-Deal with IntMin inline instead of falling back to the C function call.
-Box the values ourself to avoid a duplicate function tail and return.

* jit/ThunkGenerators.cpp:
(JSC::absThunkGenerator):


Canonical link: https://commits.webkit.org/174995@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199865 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
BenjaminPoulain committed Apr 22, 2016
1 parent 213dab5 commit 42db8435171edc5023af5f3383b64d2eb78b984d
Showing with 55 additions and 0 deletions.
  1. +18 −0 Source/JavaScriptCore/ChangeLog
  2. +37 −0 Source/JavaScriptCore/jit/ThunkGenerators.cpp
@@ -1,3 +1,21 @@
2016-04-21 Benjamin Poulain <benjamin@webkit.org>

[JSC] Improve the absThunkGenerator() for 64bit
https://bugs.webkit.org/show_bug.cgi?id=156888

Reviewed by Michael Saboff.

A few tests spend a lot of time in this abs() with double argument.

This patch adds custom handling for the JSValue64 representation.
In particular:
-Do not load the value twice. Unbox the GPR if it is not an Int32.
-Deal with IntMin inline instead of falling back to the C function call.
-Box the values ourself to avoid a duplicate function tail and return.

* jit/ThunkGenerators.cpp:
(JSC::absThunkGenerator):

2016-04-21 Saam barati <sbarati@apple.com>

LLInt CallSiteIndex off by 1
@@ -928,6 +928,42 @@ MacroAssemblerCodeRef absThunkGenerator(VM* vm)
SpecializedThunkJIT jit(vm, 1);
if (!jit.supportsFloatingPointAbs())
return MacroAssemblerCodeRef::createSelfManagedCodeRef(vm->jitStubs->ctiNativeCall(vm));
#if USE(JSVALUE64)
unsigned virtualRegisterIndex = CallFrame::argumentOffset(0);
jit.load64(AssemblyHelpers::addressFor(virtualRegisterIndex), GPRInfo::regT0);
MacroAssembler::Jump notInteger = jit.branch64(MacroAssembler::Below, GPRInfo::regT0, GPRInfo::tagTypeNumberRegister);
// Abs Int32.
jit.rshift32(GPRInfo::regT0, MacroAssembler::TrustedImm32(31), GPRInfo::regT1);
jit.add32(GPRInfo::regT1, GPRInfo::regT0);
jit.xor32(GPRInfo::regT1, GPRInfo::regT0);
// IntMin cannot be inverted.
MacroAssembler::Jump integerIsIntMin = jit.branchTest32(MacroAssembler::Signed, GPRInfo::regT0);
// Box and finish.
jit.or64(GPRInfo::tagTypeNumberRegister, GPRInfo::regT0);
MacroAssembler::Jump doneWithIntegers = jit.jump();
// Handle Doubles.
notInteger.link(&jit);
jit.appendFailure(jit.branchTest64(MacroAssembler::Zero, GPRInfo::regT0, GPRInfo::tagTypeNumberRegister));
jit.unboxDoubleWithoutAssertions(GPRInfo::regT0, GPRInfo::regT0, FPRInfo::fpRegT0);
MacroAssembler::Label absFPR0Label = jit.label();
jit.absDouble(FPRInfo::fpRegT0, FPRInfo::fpRegT1);
jit.boxDouble(FPRInfo::fpRegT1, GPRInfo::regT0);
// Tail.
doneWithIntegers.link(&jit);
jit.returnJSValue(GPRInfo::regT0);
// We know the value of regT0 is IntMin. We could load that value from memory but
// it is simpler to just convert it.
integerIsIntMin.link(&jit);
jit.convertInt32ToDouble(GPRInfo::regT0, FPRInfo::fpRegT0);
jit.jump().linkTo(absFPR0Label, &jit);
#else
MacroAssembler::Jump nonIntJump;
jit.loadInt32Argument(0, SpecializedThunkJIT::regT0, nonIntJump);
jit.rshift32(SpecializedThunkJIT::regT0, MacroAssembler::TrustedImm32(31), SpecializedThunkJIT::regT1);
@@ -940,6 +976,7 @@ MacroAssemblerCodeRef absThunkGenerator(VM* vm)
jit.loadDoubleArgument(0, SpecializedThunkJIT::fpRegT0, SpecializedThunkJIT::regT0);
jit.absDouble(SpecializedThunkJIT::fpRegT0, SpecializedThunkJIT::fpRegT1);
jit.returnDouble(SpecializedThunkJIT::fpRegT1);
#endif
return jit.finalize(vm->jitStubs->ctiNativeTailCall(vm), "abs");
}

0 comments on commit 42db843

Please sign in to comment.