Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix 32-bit build issues in WebAssembly
https://bugs.webkit.org/show_bug.cgi?id=149240

Patch by Sukolsak Sakshuwong <sukolsak@gmail.com> on 2015-09-16
Reviewed by Geoffrey Garen.

Fix the syntax error and replace the instructions that are not available on
64-bit platforms.

* wasm/WASMFunctionCompiler.h:
(JSC::WASMFunctionCompiler::startFunction):
(JSC::WASMFunctionCompiler::endFunction):
(JSC::WASMFunctionCompiler::buildReturn):
(JSC::WASMFunctionCompiler::callAndUnboxResult):
(JSC::WASMFunctionCompiler::loadValueAndConvertToDouble):

Canonical link: https://commits.webkit.org/167343@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189891 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
sukolsak authored and webkit-commit-queue committed Sep 17, 2015
1 parent da947dc commit 6f6ecb9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
17 changes: 17 additions & 0 deletions Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,20 @@
2015-09-16 Sukolsak Sakshuwong <sukolsak@gmail.com>

Fix 32-bit build issues in WebAssembly
https://bugs.webkit.org/show_bug.cgi?id=149240

Reviewed by Geoffrey Garen.

Fix the syntax error and replace the instructions that are not available on
64-bit platforms.

* wasm/WASMFunctionCompiler.h:
(JSC::WASMFunctionCompiler::startFunction):
(JSC::WASMFunctionCompiler::endFunction):
(JSC::WASMFunctionCompiler::buildReturn):
(JSC::WASMFunctionCompiler::callAndUnboxResult):
(JSC::WASMFunctionCompiler::loadValueAndConvertToDouble):

2015-09-16 Geoffrey Garen <ggaren@apple.com>

JavaScriptCore should discard baseline code after some time
Expand Down
37 changes: 31 additions & 6 deletions Source/JavaScriptCore/wasm/WASMFunctionCompiler.h
Expand Up @@ -135,8 +135,15 @@ class WASMFunctionCompiler : private CCallHelpers {
store32(TrustedImm32(0), localAddress(localIndex++));
for (uint32_t i = 0; i < numberOfF32LocalVariables; ++i)
store32(TrustedImm32(0), localAddress(localIndex++));
for (uint32_t i = 0; i < numberOfF64LocalVariables; ++i)
for (uint32_t i = 0; i < numberOfF64LocalVariables; ++i) {
#if USE(JSVALUE64)
store64(TrustedImm64(0), localAddress(localIndex++));
#else
store32(TrustedImm32(0), localAddress(localIndex));
store32(TrustedImm32(0), localAddress(localIndex).withOffset(4));
localIndex++;
#endif
}

m_codeBlock->setNumParameters(1 + arguments.size());
}
Expand All @@ -146,7 +153,12 @@ class WASMFunctionCompiler : private CCallHelpers {
ASSERT(!m_tempStackTop);

// FIXME: Remove these if the last statement is a return statement.
move(TrustedImm64(JSValue::encode(jsUndefined())), GPRInfo::returnValueGPR);
#if USE(JSVALUE64)
JSValueRegs returnValueRegs(GPRInfo::returnValueGPR);
#else
JSValueRegs returnValueRegs(GPRInfo::returnValueGPR2, GPRInfo::returnValueGPR);
#endif
moveTrustedValue(jsUndefined(), returnValueRegs);
emitFunctionEpilogue();
ret();

Expand Down Expand Up @@ -244,6 +256,11 @@ class WASMFunctionCompiler : private CCallHelpers {

void buildReturn(int, WASMExpressionType returnType)
{
#if USE(JSVALUE64)
JSValueRegs returnValueRegs(GPRInfo::returnValueGPR);
#else
JSValueRegs returnValueRegs(GPRInfo::returnValueGPR2, GPRInfo::returnValueGPR);
#endif
switch (returnType) {
case WASMExpressionType::I32:
load32(temporaryAddress(m_tempStackTop - 1), GPRInfo::returnValueGPR);
Expand All @@ -267,7 +284,7 @@ class WASMFunctionCompiler : private CCallHelpers {
m_tempStackTop--;
break;
case WASMExpressionType::Void:
move(TrustedImm64(JSValue::encode(jsUndefined())), GPRInfo::returnValueGPR);
moveTrustedValue(jsUndefined(), returnValueRegs);
break;
default:
ASSERT_NOT_REACHED();
Expand Down Expand Up @@ -839,6 +856,14 @@ class WASMFunctionCompiler : private CCallHelpers {
appendCallSetResult(operation, dst);
}
#else
// EncodedJSValue in JSVALUE32_64 is a 64-bit integer. When being compiled in ARM EABI, it must be aligned even-numbered register (r0, r2 or [sp]).
// To avoid assemblies from using wrong registers, let's occupy r1 or r3 with a dummy argument when necessary.
#if (COMPILER_SUPPORTS(EABI) && CPU(ARM)) || CPU(MIPS)
#define EABI_32BIT_DUMMY_ARG TrustedImm32(0),
#else
#define EABI_32BIT_DUMMY_ARG
#endif

void callOperation(Z_JITOperation_EJ operation, GPRReg srcTag, GPRReg srcPayload, GPRReg dst)
{
setupArgumentsWithExecState(EABI_32BIT_DUMMY_ARG srcPayload, srcTag);
Expand Down Expand Up @@ -906,8 +931,8 @@ class WASMFunctionCompiler : private CCallHelpers {
#if USE(JSVALUE64)
store64(GPRInfo::regT0, Address(stackPointerRegister, JSStack::Callee * static_cast<int>(sizeof(Register)) - sizeof(CallerFrameAndPC)));
#else
store32(regT0, Address(stackPointerRegister, JSStack::Callee * static_cast<int>(sizeof(Register)) + PayloadOffset - sizeof(CallerFrameAndPC)));
store32(TrustedImm32(CellTag), Address(stackPointerRegister, JSStack::Callee * static_cast<int>(sizeof(Register)) + TagOffset - sizeof(CallerFrameAndPC)));
store32(GPRInfo::regT0, Address(stackPointerRegister, JSStack::Callee * static_cast<int>(sizeof(Register)) + PayloadOffset - sizeof(CallerFrameAndPC)));
store32(TrustedImm32(JSValue::CellTag), Address(stackPointerRegister, JSStack::Callee * static_cast<int>(sizeof(Register)) + TagOffset - sizeof(CallerFrameAndPC)));
#endif

DataLabelPtr addressOfLinkedFunctionCheck;
Expand Down Expand Up @@ -999,7 +1024,7 @@ class WASMFunctionCompiler : private CCallHelpers {
end.append(jump());

checkJSNumber.link(this);
unboxDouble(tempRegs.tagGPR(), tempRegs.payloadGPR(), dst, fpScratch)
unboxDouble(tempRegs.tagGPR(), tempRegs.payloadGPR(), dst, fpScratch);
end.link(this);
}
#endif
Expand Down

0 comments on commit 6f6ecb9

Please sign in to comment.