Skip to content

Commit

Permalink
[MERGE #2716 @obastemur] xplat: use xmm for float args
Browse files Browse the repository at this point in the history
Merge pull request #2716 from obastemur:fix_xplat_args

Previously xplat LowerCall args were limited to REG_INT_ARG... Adding XMM* support and a test case to make sure we don't break.

This PR also improves performance on xplat jetstream

Disabling couple of additional wasm tests on xplat with a note.

edit: added another test case
  • Loading branch information
obastemur committed Mar 25, 2017
2 parents e8328c0 + 2c749f5 commit e2c7ad8
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 38 deletions.
97 changes: 59 additions & 38 deletions lib/Backend/amd64/LowererMDArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ LowererMDArch::LoadHeapArguments(IR::Instr *instrArgs)
// s2 = actual argument count (without counting "this")
instr = this->lowererMD->LoadInputParamCount(instrArgs, -1);
IR::Opnd * opndInputParamCount = instr->GetDst();

this->LoadHelperArgument(instrArgs, opndInputParamCount);

// s1 = current function
Expand Down Expand Up @@ -466,6 +466,40 @@ LowererMDArch::LoadNewScObjFirstArg(IR::Instr * instr, IR::Opnd * dst, ushort ex
return argInstr;
}

inline static RegNum GetRegFromArgPosition(const bool isFloatArg, const uint16 argPosition)
{
RegNum reg = RegNOREG;

if (!isFloatArg && argPosition <= IntArgRegsCount)
{
switch (argPosition)
{
#define REG_INT_ARG(Index, Name) \
case ((Index) + 1): \
reg = Reg ## Name; \
break;
#include "RegList.h"
default:
Assume(UNREACHED);
}
}
else if (isFloatArg && argPosition <= XmmArgRegsCount)
{
switch (argPosition)
{
#define REG_XMM_ARG(Index, Name) \
case ((Index) + 1): \
reg = Reg ## Name; \
break;
#include "RegList.h"
default:
Assume(UNREACHED);
}
}

return reg;
}

int32
LowererMDArch::LowerCallArgs(IR::Instr *callInstr, ushort callFlags, Js::ArgSlot extraParams, IR::IntConstOpnd **callInfoOpndRef /* = nullptr */)
{
Expand Down Expand Up @@ -957,23 +991,31 @@ LowererMDArch::LowerCall(IR::Instr * callInstr, uint32 argCount)
// Manually home args
if (shouldHomeParams)
{
static const RegNum s_argRegs[IntArgRegsCount] = {
#define REG_INT_ARG(Index, Name) Reg ## Name,
#include "RegList.h"
};

const int callArgCount = this->helperCallArgsCount + static_cast<int>(argCount);
const int argRegs = min(callArgCount, static_cast<int>(IntArgRegsCount));
for (int i = argRegs - 1; i >= 0; i--)

int argRegs = min(callArgCount, static_cast<int>(XmmArgRegsCount));

for (int i = argRegs; i > 0; i--)
{
StackSym * sym = this->m_func->m_symTable->GetArgSlotSym(static_cast<uint16>(i + 1));
IRType type = this->xplatCallArgs.args[i];
bool isFloatArg = this->xplatCallArgs.IsFloat(i);

if ( i > IntArgRegsCount && !isFloatArg ) continue;

StackSym * sym = this->m_func->m_symTable->GetArgSlotSym(static_cast<uint16>(i));
RegNum reg = GetRegFromArgPosition(isFloatArg, i);

IR::RegOpnd *regOpnd = IR::RegOpnd::New(nullptr, reg, type, this->m_func);
regOpnd->m_isCallArg = true;

Lowerer::InsertMove(
IR::SymOpnd::New(sym, TyMachReg, this->m_func),
IR::RegOpnd::New(nullptr, s_argRegs[i], TyMachReg, this->m_func),
IR::SymOpnd::New(sym, type, this->m_func),
regOpnd,
callInstr, false);
}
}
#endif
this->xplatCallArgs.Reset();
#endif // !_WIN32

//
// load the address into a register because we cannot directly access 64 bit constants
Expand Down Expand Up @@ -1036,34 +1078,13 @@ LowererMDArch::GetArgSlotOpnd(uint16 index, StackSym * argSym, bool isHelper /*=

IRType type = argSym ? argSym->GetType() : TyMachReg;
const bool isFloatArg = IRType_IsFloat(type) || IRType_IsSimd128(type);
RegNum reg = RegNOREG;

if (!isFloatArg && argPosition <= IntArgRegsCount)
{
switch (argPosition)
{
#define REG_INT_ARG(Index, Name) \
case ((Index) + 1): \
reg = Reg ## Name; \
break;
#include "RegList.h"
default:
Assume(UNREACHED);
}
}
else if (isFloatArg && argPosition <= XmmArgRegsCount)
RegNum reg = GetRegFromArgPosition(isFloatArg, argPosition);
#ifndef _WIN32
if (isFloatArg && argPosition <= XmmArgRegsCount)
{
switch (argPosition)
{
#define REG_XMM_ARG(Index, Name) \
case ((Index) + 1): \
reg = Reg ## Name; \
break;
#include "RegList.h"
default:
Assume(UNREACHED);
}
this->xplatCallArgs.SetFloat(argPosition);
}
#endif

if (reg != RegNOREG)
{
Expand Down
23 changes: 23 additions & 0 deletions lib/Backend/amd64/LowererMDArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,30 @@ class LowererMDArch
int helperCallArgsCount;
IR::Opnd * helperCallArgs[MaxArgumentsToHelper];

#ifndef _WIN32
class XPlatRegArgList
{
public:
XPlatRegArgList() { Reset(); }
inline void Reset()
{
for (int i = 0; i <= XmmArgRegsCount; i++) args[i] = TyMachPtr;
}

inline bool IsFloat(uint16 position) { return args[position] == TyFloat64; }

void SetFloat(uint16 regPosition)
{
Assert(regPosition != 0 && regPosition <= XmmArgRegsCount);
args[regPosition] = TyFloat64;
}

static_assert(static_cast<int>(XmmArgRegsCount) >= static_cast<int>(IntArgRegsCount),
"Unexpected register count");
IRType args [XmmArgRegsCount + 1];
};
XPlatRegArgList xplatCallArgs;
#endif
public:

LowererMDArch(Func* function):
Expand Down
138 changes: 138 additions & 0 deletions test/AsmJs/argTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

var tests = [
function()
{
function AsmModuleDouble() {
"use asm";

function test0(x) { x = +x; return +test0sub(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 10.5); }
function test0sub(a,b,c,d,e,f,g,h,j,i,k) {
a = +a; b = +b;
c = +c; d = +d;
e = +e; f = +f;
g = +g; h = +h;
j = +j; i = +i;
k = +k; return +(a); }

function test1(x) { x = +x; return +test1sub(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 10.5); }
function test1sub(a,b,c,d,e,f,g,h,j,i,k) {
a = +a; b = +b;
c = +c; d = +d;
e = +e; f = +f;
g = +g; h = +h;
j = +j; i = +i;
k = +k; return +(f); }

function test2(x) { x = +x; return +test2sub(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 10.5); }
function test2sub(a,b,c,d,e,f,g,h,j,i,k) {
a = +a; b = +b;
c = +c; d = +d;
e = +e; f = +f;
g = +g; h = +h;
j = +j; i = +i;
k = +k; return +(g); }

function test3(x) { x = +x; return +test3sub(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 10.5); }
function test3sub(a,b,c,d,e,f,g,h,j,i,k) {
a = +a; b = +b;
c = +c; d = +d;
e = +e; f = +f;
g = +g; h = +h;
j = +j; i = +i;
k = +k; return +(h); }

function test4(x) { x = +x; return +test4sub(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 10.5); }
function test4sub(a,b,c,d,e,f,g,h,j,i,k) {
a = +a; b = +b;
c = +c; d = +d;
e = +e; f = +f;
g = +g; h = +h;
j = +j; i = +i;
k = +k; return +(k); }

return { test0: test0, test1: test1, test2: test2, test3: test3, test4: test4 };
}

var asmModuleDouble = AsmModuleDouble();
if (asmModuleDouble.test0(2, 3, 4) != 1.5) throw ('a - 1st arg. storage has failed.');
if (asmModuleDouble.test1(2, 3, 4) != 6.5) throw ('f - 6th arg. storage has failed.');
if (asmModuleDouble.test2(2, 3, 4) != 7.5) throw ('g - 7th arg. storage has failed.');
if (asmModuleDouble.test3(2, 3, 4) != 8.5) throw ('h - 8th arg. storage has failed.');
if (asmModuleDouble.test4(2, 3, 4) != 10.5) throw ('k - 11th arg. storage has failed.');
},
function()
{
function asm() {
"use asm"
function SubCount(a,b,c,d,e,f,g,h,j,k,l) {
a = +a;
b = +b;
c = c | 0;
d = d | 0;
e = +e;
f = +f;
g = +g;
h = +h;
j = +j;
k = +k;
l = +l;

return +(l);
}

function Count(a) {
a = +a;
return +SubCount(3.2, 1.2, 2, 5, 6.33, 4.88, 1.2, 2.6, 3.99, 1.2, 2.6);
}

return { Count: Count };
}

var total = 0;
var fnc = asm ();
for(var i = 0;i < 1e6; i++) {
total += fnc.Count(1, 2);
}

if (parseInt(total) != parseInt(1e6 * 2.6)) throw new Error('Test Failed -> ' + total);
},
function() {
function asm() {
"use asm"
function SubCount(a,b,c,d,e,f,g) {
a = a | 0;
b = b | 0;
c = c | 0;
d = d | 0;
e = e | 0;
f = f | 0;
g = +g;

return +(g);
}

function Count(a) {
a = +a;
return +SubCount(1, 2, 3, 4, 5, 6, 1.3);
}

return { Count: Count };
}

var total = 0;
var fnc = asm ();
for(var i = 0;i < 1e6; i++) {
total += fnc.Count(1, 2);
}

if (parseInt(total) != parseInt(1e6 * 1.3)) throw new Error('Test Failed -> ' + total);
}];

for(var i = 0; i < tests.length; i++)
tests[i]();

print('PASS')
6 changes: 6 additions & 0 deletions test/AsmJs/rlexe.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<regress-exe>
<test>
<default>
<files>argTest.js</files>
<compile-flags>-maic:0 -maxInterpretCount:0</compile-flags>
</default>
</test>
<test>
<default>
<files>ArrayView.js</files>
Expand Down
3 changes: 3 additions & 0 deletions test/WasmSpec/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@
<files>spec.js</files>
<baseline>baselines/func.baseline</baseline>
<compile-flags>-wasm -args testsuite-bin/func.json -endargs</compile-flags>
<!-- xplat-todo: implement xmm.. with wasm related asm. -->
<tags>exclude_xplat</tags>
</default>
</test>
<test>
Expand Down Expand Up @@ -543,6 +545,7 @@
<files>spec.js</files>
<baseline>baselines/left-to-right.baseline</baseline>
<compile-flags>-wasm -args testsuite-bin/left-to-right.json -endargs</compile-flags>
<tags>exclude_xplat</tags>
</default>
</test>
<test>
Expand Down

0 comments on commit e2c7ad8

Please sign in to comment.