From b05cfa60d2655b4681a182c94bee2a2cf61159f9 Mon Sep 17 00:00:00 2001 From: Michael Holman Date: Wed, 10 Jan 2018 19:28:56 -0800 Subject: [PATCH] fix wasm on xplat --- lib/Backend/JnHelperMethod.cpp | 4 +- lib/Common/CommonDefines.h | 3 - lib/Common/ConfigFlagsList.h | 5 -- .../Language/InterpreterStackFrame.cpp | 19 ++--- lib/Runtime/Language/amd64/amd64_Thunks.S | 78 ------------------- .../Library/amd64/JavascriptFunctionA.S | 12 --- pal/inc/pal.h | 2 + test/AsmJs/rlexe.xml | 7 +- test/rlexedirs.xml | 2 +- test/wasm/rlexe.xml | 50 +++++------- test/wasm/signextend.js | 4 +- 11 files changed, 37 insertions(+), 149 deletions(-) diff --git a/lib/Backend/JnHelperMethod.cpp b/lib/Backend/JnHelperMethod.cpp index 7d6d676b653..23ceefc0a39 100644 --- a/lib/Backend/JnHelperMethod.cpp +++ b/lib/Backend/JnHelperMethod.cpp @@ -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: diff --git a/lib/Common/CommonDefines.h b/lib/Common/CommonDefines.h index 55b04b67eb2..a85c5262f13 100644 --- a/lib/Common/CommonDefines.h +++ b/lib/Common/CommonDefines.h @@ -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 diff --git a/lib/Common/ConfigFlagsList.h b/lib/Common/ConfigFlagsList.h index b81dfd70a04..7d72fca49d3 100644 --- a/lib/Common/ConfigFlagsList.h +++ b/lib/Common/ConfigFlagsList.h @@ -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) diff --git a/lib/Runtime/Language/InterpreterStackFrame.cpp b/lib/Runtime/Language/InterpreterStackFrame.cpp index d50034e918c..afc5a2a9f42 100644 --- a/lib/Runtime/Language/InterpreterStackFrame.cpp +++ b/lib/Runtime/Language/InterpreterStackFrame.cpp @@ -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 @@ -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) @@ -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); @@ -3730,17 +3725,17 @@ namespace Js AsmJsScriptFunction* scriptFunc = AsmJsScriptFunction::FromVar(function); AsmJsFunctionInfo* asmInfo = scriptFunc->GetFunctionBody()->GetAsmJsFunctionInfo(); uint alignedArgsSize = ::Math::Align(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); diff --git a/lib/Runtime/Language/amd64/amd64_Thunks.S b/lib/Runtime/Language/amd64/amd64_Thunks.S index 12109dc65b7..e2e3e414640 100644 --- a/lib/Runtime/Language/amd64/amd64_Thunks.S +++ b/lib/Runtime/Language/amd64/amd64_Thunks.S @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/lib/Runtime/Library/amd64/JavascriptFunctionA.S b/lib/Runtime/Library/amd64/JavascriptFunctionA.S index 17edad70ced..33d4f19f034 100644 --- a/lib/Runtime/Library/amd64/JavascriptFunctionA.S +++ b/lib/Runtime/Library/amd64/JavascriptFunctionA.S @@ -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 diff --git a/pal/inc/pal.h b/pal/inc/pal.h index d33e0987676..71d8e5abb41 100644 --- a/pal/inc/pal.h +++ b/pal/inc/pal.h @@ -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 *); diff --git a/test/AsmJs/rlexe.xml b/test/AsmJs/rlexe.xml index 22b92a644c9..2edbdc72c10 100644 --- a/test/AsmJs/rlexe.xml +++ b/test/AsmJs/rlexe.xml @@ -120,7 +120,6 @@ MathBuiltinsCall.js MathBuiltinsCall.baseline - exclude_xplat -testtrace:asmjs @@ -128,7 +127,6 @@ MathBuiltinsCall.js MathBuiltinsCall.baseline - exclude_xplat -testtrace:asmjs -maic:1 -sse:3 @@ -351,7 +349,7 @@ MathBuiltinsCall.js MathBuiltinsCall.baseline - exclude_amd64,exclude_xplat + exclude_amd64 @@ -524,7 +522,6 @@ MathBuiltinsCall.js MathBuiltinsCall.baseline - exclude_xplat -testtrace:asmjs -nonative @@ -977,7 +974,7 @@ -testtrace:asmjs -args 14000 -endargs -EnableFatalErrorOnOOM- - exclude_dynapogo,exclude_xplat + exclude_dynapogo diff --git a/test/rlexedirs.xml b/test/rlexedirs.xml index 5c90f814421..822ebba5154 100644 --- a/test/rlexedirs.xml +++ b/test/rlexedirs.xml @@ -288,7 +288,7 @@ WasmSpec - exclude_serialized,exclude_arm,exclude_arm64,require_backend,exclude_jshost,exclude_win7,require_wasm,exclude_xplat + exclude_serialized,exclude_arm,exclude_arm64,require_backend,exclude_jshost,exclude_win7,require_wasm diff --git a/test/wasm/rlexe.xml b/test/wasm/rlexe.xml index 892e10f7d0d..5be1d22ea7c 100644 --- a/test/wasm/rlexe.xml +++ b/test/wasm/rlexe.xml @@ -59,7 +59,6 @@ math.js - exclude_xplat -wasm -wasmi64 @@ -87,7 +86,6 @@ global.js baselines/global.baseline - exclude_xplat -wasm -wasmi64 @@ -96,7 +94,6 @@ basic.js basic.baseline -wasm - exclude_xplat @@ -117,7 +114,6 @@ table_imports.js baselines/table_imports.baseline - exclude_xplat -wasm -wasmi64 @@ -126,14 +122,12 @@ call.js baselines/call.baseline -wasm - exclude_xplat array.js array.baseline - exclude_xplat -wasm @@ -141,7 +135,6 @@ trunc.js -wasm - exclude_xplat @@ -149,7 +142,6 @@ api.js baselines/api.baseline -wasm - exclude_xplat @@ -177,7 +169,7 @@ inlining.js inlining.baseline - exclude_jshost,exclude_win7,exclude_xplat + exclude_jshost,exclude_win7 @@ -185,35 +177,35 @@ params.js baselines/params.baseline -wasm -args 14000 -endargs - exclude_jshost,exclude_win7,exclude_dynapogo,exclude_xplat + exclude_jshost,exclude_win7,exclude_dynapogo debugger_basic.js -wasm -dbgbaseline:debugger_basic.js.dbg.baseline - exclude_jshost,exclude_win7,exclude_drt,exclude_snap,require_debugger,exclude_xplat + exclude_jshost,exclude_win7,exclude_drt,exclude_snap,require_debugger debugger_basic.js -wasm -maic:1 -dbgbaseline:debugger_basic.js.dbg.baseline - exclude_jshost,exclude_win7,exclude_drt,exclude_snap,require_debugger,exclude_xplat + exclude_jshost,exclude_win7,exclude_drt,exclude_snap,require_debugger debugger_basic.js -wasm -debuglaunch -args debuglaunch -endargs -dbgbaseline:debugger_basic_launch.js.dbg.baseline - exclude_jshost,exclude_win7,exclude_drt,exclude_snap,require_debugger,exclude_xplat + exclude_jshost,exclude_win7,exclude_drt,exclude_snap,require_debugger wasmcctx.js -wasm -dbgbaseline:wasmcctx.js.dbg.baseline -InspectMaxStringLength:50 - exclude_jshost,exclude_win7,exclude_drt,exclude_snap,require_debugger,exclude_xplat + exclude_jshost,exclude_win7,exclude_drt,exclude_snap,require_debugger @@ -271,7 +263,7 @@ nestedblocks.js -wasm - exclude_jshost,exclude_drt,exclude_win7,exclude_dynapogo,exclude_xplat + exclude_jshost,exclude_drt,exclude_win7,exclude_dynapogo @@ -286,7 +278,7 @@ signextend.js -wasm -args --no-verbose -endargs - exclude_jshost,exclude_win7,exclude_xplat + exclude_jshost,exclude_win7 @@ -294,28 +286,28 @@ unsigned.js baselines/unsigned.baseline -wasm - exclude_jshost,exclude_drt,exclude_win7,exclude_xplat + exclude_jshost,exclude_drt,exclude_win7 memory.js -wasm - exclude_jshost,exclude_drt,exclude_win7,exclude_xplat + exclude_jshost,exclude_drt,exclude_win7 memory.js -wasm -wasmfastarray- - exclude_jshost,exclude_drt,exclude_win7,exclude_xplat + exclude_jshost,exclude_drt,exclude_win7 superlongsignaturemismatch.js -wasm - exclude_xplat,exclude_jshost,exclude_drt,exclude_win7 + exclude_jshost,exclude_drt,exclude_win7 @@ -336,7 +328,7 @@ polyinline.js -maxinterpretcount:2 -off:simplejit - exclude_xplat,exclude_jshost,exclude_win7 + exclude_jshost,exclude_win7 @@ -344,7 +336,7 @@ limits.js -wasm -args --no-verbose --end 4 -endargs 300 - exclude_xplat,exclude_jshost,exclude_drt,exclude_win7,exclude_chk,exclude_dynapogo,exclude_x86,Slow + exclude_jshost,exclude_drt,exclude_win7,exclude_chk,exclude_dynapogo,exclude_x86,Slow @@ -352,7 +344,7 @@ limits.js -wasm -args --no-verbose --start 4 --end 12 -endargs 300 - exclude_xplat,exclude_jshost,exclude_drt,exclude_win7,exclude_chk,exclude_dynapogo,exclude_x86,Slow + exclude_jshost,exclude_drt,exclude_win7,exclude_chk,exclude_dynapogo,exclude_x86,Slow @@ -360,42 +352,42 @@ limits.js -wasm -args --no-verbose --start 12 -endargs 300 - exclude_xplat,exclude_jshost,exclude_drt,exclude_win7,exclude_chk,exclude_dynapogo,exclude_x86,Slow + exclude_jshost,exclude_drt,exclude_win7,exclude_chk,exclude_dynapogo,exclude_x86,Slow loopstslot.js -forcejitloopbody - exclude_jshost,exclude_win7,exclude_xplat + exclude_jshost,exclude_win7 loopyield.js -forcejitloopbody - exclude_jshost,exclude_win7,exclude_xplat + exclude_jshost,exclude_win7 loopyieldnested.js -lic:10 -bgjit- - exclude_jshost,exclude_win7,exclude_xplat + exclude_jshost,exclude_win7 loopyieldtypes.js -forcejitloopbody - exclude_jshost,exclude_win7,exclude_xplat + exclude_jshost,exclude_win7 loopyieldregress.js -lic:0 -bgjit- - exclude_win7,exclude_xplat + exclude_win7 diff --git a/test/wasm/signextend.js b/test/wasm/signextend.js index 4b8c85c822b..13ca863a43c 100644 --- a/test/wasm/signextend.js +++ b/test/wasm/signextend.js @@ -6,7 +6,7 @@ /* global assert,testRunner */ // eslint rule WScript.Flag("-WasmSignExtends"); WScript.Flag("-WasmI64"); -WScript.LoadScriptFile("../UnitTestFrameWork/UnitTestFrameWork.js"); +WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); function makeCSETest(type, op1, op2, tests) { return { @@ -60,7 +60,7 @@ const tests = [ makeCSETest("i64", "extend32_s", "extend16_s", [0xFF4F, 0xFFF4FFFF, {low: 0x4FFFFFFF, high: 1}]), ]; -WScript.LoadScriptFile("../UnitTestFrameWork/yargs.js"); +WScript.LoadScriptFile("..\\UnitTestFramework\\yargs.js"); const argv = yargsParse(WScript.Arguments, { boolean: ["verbose"], number: ["start", "end"],