Skip to content

Commit

Permalink
fix wasm on xplat
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeHolman committed Jan 11, 2018
1 parent 0dd3ff3 commit b05cfa6
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 149 deletions.
4 changes: 2 additions & 2 deletions lib/Backend/JnHelperMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ DECLSPEC_GUARDIGNORE _NOINLINE intptr_t GetNonTableMethodAddress(ThreadContextI
return ShiftAddr(context, (void*(*)(void *, void const*, size_t))memcpy);

case HelperDirectMath_FloorFlt:
return ShiftAddr(context, (float(*)(float))floor);
return ShiftAddr(context, (float(*)(float))floorf);

case HelperDirectMath_CeilFlt:
return ShiftAddr(context, (float(*)(float))ceil);
return ShiftAddr(context, (float(*)(float))ceilf);

#if defined(_M_X64)
case HelperDirectMath_Acos:
Expand Down
3 changes: 0 additions & 3 deletions lib/Common/CommonDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,15 +727,12 @@
#endif

#if defined(ASMJS_PLAT)
// xplat-todo: once all the wasm tests are passing on xplat, enable it for release builds
#if defined(_WIN32) || (defined(__clang__) && defined(ENABLE_DEBUG_CONFIG_OPTIONS))
#define ENABLE_WASM

#ifdef CAN_BUILD_WABT
#define ENABLE_WABT
#endif

#endif
#endif

#if _M_IX86
Expand Down
5 changes: 0 additions & 5 deletions lib/Common/ConfigFlagsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,7 @@ PHASE(All)
#endif
#endif // #ifdef ENABLE_SIMDJS

#ifdef _WIN32
#define DEFAULT_CONFIG_Wasm (true)
#else
// Do not enable wasm by default on xplat builds
#define DEFAULT_CONFIG_Wasm (false)
#endif
#define DEFAULT_CONFIG_WasmI64 (false)
#if ENABLE_FAST_ARRAYBUFFER
#define DEFAULT_CONFIG_WasmFastArray (true)
Expand Down
19 changes: 7 additions & 12 deletions lib/Runtime/Language/InterpreterStackFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3000,7 +3000,7 @@ namespace Js
// Move the arguments to the right location
ArgSlot argCount = info->GetArgCount();

#if _M_X64
#if _M_X64 && _WIN32
uint homingAreaSize = 0;
#endif

Expand All @@ -3019,7 +3019,7 @@ namespace Js
uintptr_t argAddress = (uintptr_t)m_inParams;
for (ArgSlot i = 0; i < argCount; i++)
{
#if _M_X64
#if _M_X64 && _WIN32
// 3rd Argument should be at the end of the homing area.
Assert(i != 3 || argAddress == (uintptr_t)m_inParams + homingAreaSize);
if (i < 3)
Expand All @@ -3040,12 +3040,7 @@ namespace Js
// IAT xmm2 spill
// IAT xmm1 spill <- floatSpillAddress for arg1

#ifdef _WIN32
#define FLOAT_SPILL_ADDRESS_OFFSET_WORDS 15
#else
// On Sys V x64 we have 4 words less (4 reg shadow)
#define FLOAT_SPILL_ADDRESS_OFFSET_WORDS 11
#endif
// floats are spilled as xmmwords
uintptr_t floatSpillAddress = (uintptr_t)m_inParams - MachPtr * (FLOAT_SPILL_ADDRESS_OFFSET_WORDS - 2*i);

Expand Down Expand Up @@ -3730,17 +3725,17 @@ namespace Js
AsmJsScriptFunction* scriptFunc = AsmJsScriptFunction::FromVar(function);
AsmJsFunctionInfo* asmInfo = scriptFunc->GetFunctionBody()->GetAsmJsFunctionInfo();
uint alignedArgsSize = ::Math::Align<uint32>(asmInfo->GetArgByteSize(), 16);
#if _M_X64
#if _M_X64 && _WIN32
// convention is to always allocate spill space for rcx,rdx,r8,r9
if (alignedArgsSize < 0x20) alignedArgsSize = 0x20;

// Prepare in advance the possible arguments that will need to be put in register
byte _declspec(align(16)) reg[3 * 16];
uint* argSizes = asmInfo->GetArgsSizesArray();
Assert(asmInfo->GetArgSizeArrayLength() >= 2);
CompileAssert((FunctionBody::MinAsmJsOutParams() * sizeof(Var)) == (sizeof(Var) * 2 + sizeof(reg)));
byte* curOutParams = (byte*)m_outParams + sizeof(Var);
Assert(curOutParams + argSizes[0] + argSizes[1] + 16 <= (byte*)this->m_outParamsEnd);

// Prepare in advance the possible arguments that will need to be put in register
byte _declspec(align(16)) reg[3 * 16];
CompileAssert((FunctionBody::MinAsmJsOutParams() * sizeof(Var)) == (sizeof(Var) * 2 + sizeof(reg)));
js_memcpy_s(reg, 16, curOutParams, 16);
js_memcpy_s(reg + 16, 16, curOutParams + argSizes[0], 16);
js_memcpy_s(reg + 32, 16, curOutParams + argSizes[0] + argSizes[1], 16);
Expand Down
78 changes: 0 additions & 78 deletions lib/Runtime/Language/amd64/amd64_Thunks.S
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,7 @@ NESTED_ENTRY _ZN2Js21InterpreterStackFrame33AsmJsDelayDynamicInterpreterThunkEPN
push r8
push r9

sub rsp, 40h

// spill potential floating point arguments to stack
movaps xmmword ptr [rsp + 00h], xmm0
movaps xmmword ptr [rsp + 10h], xmm1
movaps xmmword ptr [rsp + 20h], xmm2
movaps xmmword ptr [rsp + 30h], xmm3
call C_FUNC(_ZN2Js21InterpreterStackFrame29EnsureDynamicInterpreterThunkEPNS_14ScriptFunctionE)
// restore potential floating point arguments from stack
movaps xmm0, xmmword ptr [rsp + 00h]
movaps xmm1, xmmword ptr [rsp + 10h]
movaps xmm2, xmmword ptr [rsp + 20h]
movaps xmm3, xmmword ptr [rsp + 30h]

add rsp, 40h

pop r9
pop r8
Expand Down Expand Up @@ -190,13 +176,6 @@ NESTED_ENTRY _ZN2Js21InterpreterStackFrame19InterpreterAsmThunkEPNS_20AsmJsCallS

set_cfa_register rbp, (2*8) // Set to compute CFA as: rbp + 16 (sizeof: [rbp] [ReturnAddress])

sub rsp, 40h

// spill potential floating point arguments to stack
movaps xmmword ptr [rsp + 00h], xmm0
movaps xmmword ptr [rsp + 10h], xmm1
movaps xmmword ptr [rsp + 20h], xmm2
movaps xmmword ptr [rsp + 30h], xmm3

// save argument registers used by custom calling convention
push rdi
Expand All @@ -210,7 +189,6 @@ NESTED_ENTRY _ZN2Js21InterpreterStackFrame19InterpreterAsmThunkEPNS_20AsmJsCallS

call rax // call appropriate template

add rsp, 40h
pop_nonvol_reg rbp
ret
NESTED_END _ZN2Js21InterpreterStackFrame19InterpreterAsmThunkEPNS_20AsmJsCallStackLayoutE, _TEXT
Expand Down Expand Up @@ -260,64 +238,8 @@ NESTED_ENTRY _ZN2Js23AsmJsExternalEntryPointEPNS_16RecyclableObjectENS_8CallInfo
call C_FUNC(_ZN2Js19UnboxAsmJsArgumentsEPNS_14ScriptFunctionEPPvPcNS_8CallInfoE)
// rax = target function address

// move first 4 arguments into registers.
// don't know types other than arg0 (which is ScriptFunction *), so put in both xmm and general purpose registers
mov rdi, r12 // arg0: func

// int GetArgsSizesArray(ScriptFunction* func)
// get args sizes of target asmjs function
// rdi has ScriptFunction*
push r13
push rax
push rdi
sub rsp, 8h
call C_FUNC(_ZN2Js17GetArgsSizesArrayEPNS_14ScriptFunctionE)
mov r13, rax // r13: arg size
add rsp, 8h
pop rdi
pop rax

// NOTE: Below xmm usage is non-standard.

// Move 3 args to regs per convention. rdi already has first arg: ScriptFunction*
push r12
// r12->unboxed args
lea r12, [rsp + 18h] // rsp + size of(r12 + r13 + ScriptFunction*)

// r13 is arg size
cmp dword ptr [r13], 10h
je SIMDArg2
mov rsi, [r12] // arg1
movq xmm1, qword ptr [r12] // arg1
add r12, 8h
jmp Arg3
SIMDArg2:
movups xmm1, xmmword ptr[r12]
add r12, 10h
Arg3:
cmp dword ptr [r13 + 4h], 10h
je SIMDArg3
mov rdx, [r12] // arg2
movq xmm2, qword ptr [r12] // arg2
add r12, 8h
jmp Arg4
SIMDArg3:
movups xmm2, xmmword ptr[r12]
add r12, 10h
Arg4:
cmp dword ptr [r13 + 8h], 10h
je SIMDArg4
mov rcx, [r12] // arg3
movq xmm3, qword ptr [r12] // arg3
jmp ArgsDone
SIMDArg4:
movups xmm3, xmmword ptr [r12]

ArgsDone:
pop r12 // r12: func
pop r13 // r13: orig stack pointer

// "home" arg0. other args were read from stack and already homed.
mov [rsp + 00h], rdi

// call entry point
Expand Down
12 changes: 0 additions & 12 deletions lib/Runtime/Library/amd64/JavascriptFunctionA.S
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,7 @@ NESTED_ENTRY _ZN2Js18JavascriptFunction17CallAsmJsFunctionIiEET_PNS_16Recyclable
mov rdi, rsp // rdi = arguments destination
rep movsq

// Load 4 first arguments
// First Argument
mov rdi, qword ptr [rsp]
// Review:: Is this really our calling convention on xplat ?
// Second Argument
mov rsi, qword ptr [r8]
movaps xmm1, xmmword ptr [r8]
// Third Argument
mov rdx, qword ptr [r8 + 10h]
movaps xmm2, xmmword ptr [r8 + 10h]
// Fourth Argument
mov rcx, qword ptr [r8 + 20h]
movaps xmm3, xmmword ptr [r8 + 20h]

xor rax, rax // Zero out rax in case r11 expects varags
call r11
Expand Down
2 changes: 2 additions & 0 deletions pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6358,7 +6358,9 @@ PALIMPORT double __cdecl tanh(double);
PALIMPORT double __cdecl fmod(double, double);
PALIMPORT float __cdecl fmodf(float, float);
PALIMPORT double __cdecl floor(double);
PALIMPORT float __cdecl floorf(float);
PALIMPORT double __cdecl ceil(double);
PALIMPORT float __cdecl ceilf(float);
PALIMPORT float __cdecl fabsf(float);
PALIMPORT double __cdecl modf(double, double *);
PALIMPORT float __cdecl modff(float, float *);
Expand Down
7 changes: 2 additions & 5 deletions test/AsmJs/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,13 @@
<default>
<files>MathBuiltinsCall.js</files>
<baseline>MathBuiltinsCall.baseline</baseline>
<tags>exclude_xplat</tags>
<compile-flags>-testtrace:asmjs</compile-flags>
</default>
</test>
<test>
<default>
<files>MathBuiltinsCall.js</files>
<baseline>MathBuiltinsCall.baseline</baseline>
<tags>exclude_xplat</tags>
<compile-flags>-testtrace:asmjs -maic:1 -sse:3</compile-flags>
</default>
</test>
Expand Down Expand Up @@ -351,7 +349,7 @@
<default>
<files>MathBuiltinsCall.js</files>
<baseline>MathBuiltinsCall.baseline</baseline>
<tags>exclude_amd64,exclude_xplat</tags>
<tags>exclude_amd64</tags>
<!-- After removing -simdjs this test fail with -on:asmjsjittemplate. Investigate and enable
<compile-flags>-testtrace:asmjs -oopjit- -on:asmjsjittemplate -off:fulljit</compile-flags>
-->
Expand Down Expand Up @@ -524,7 +522,6 @@
<default>
<files>MathBuiltinsCall.js</files>
<baseline>MathBuiltinsCall.baseline</baseline>
<tags>exclude_xplat</tags>
<compile-flags>-testtrace:asmjs -nonative</compile-flags>
</default>
</test>
Expand Down Expand Up @@ -977,7 +974,7 @@
<compile-flags>-testtrace:asmjs -args 14000 -endargs -EnableFatalErrorOnOOM-</compile-flags>
<!-- todo:: On unix platforms there is more stack available,
so we need to find the right limit to test in order to not timeout -->
<tags>exclude_dynapogo,exclude_xplat</tags>
<tags>exclude_dynapogo</tags>
</default>
</test>
<test>
Expand Down
2 changes: 1 addition & 1 deletion test/rlexedirs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
<dir>
<default>
<files>WasmSpec</files>
<tags>exclude_serialized,exclude_arm,exclude_arm64,require_backend,exclude_jshost,exclude_win7,require_wasm,exclude_xplat</tags>
<tags>exclude_serialized,exclude_arm,exclude_arm64,require_backend,exclude_jshost,exclude_win7,require_wasm</tags>
</default>
</dir>
<dir>
Expand Down
Loading

0 comments on commit b05cfa6

Please sign in to comment.