Skip to content

Commit

Permalink
wasm popcnt32 + tests
Browse files Browse the repository at this point in the history
refining asserts, removing nop

fixing whitespace

adding a copyright header

popcnt32 rename

 remove extern

moving popcnt32 to math

removing codegen test
  • Loading branch information
Krovatkin committed Aug 18, 2016
1 parent 2ed28dc commit e51083a
Show file tree
Hide file tree
Showing 24 changed files with 135 additions and 182 deletions.
66 changes: 11 additions & 55 deletions lib/Backend/IRBuilderAsmJs.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/Backend/JnHelperMethodList.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ HELPERCALL_FULL_OR_INPLACE_MATH(Op_Multiply, Js::JavascriptMath::Multiply, Js::S
HELPERCALL_FULL_OR_INPLACE_MATH(Op_Subtract, Js::JavascriptMath::Subtract, Js::SSE2::JavascriptMath::Subtract, AttrCanThrow)
HELPERCALL_FULL_OR_INPLACE_MATH(Op_Exponentiation, Js::JavascriptMath::Exponentiation, Js::SSE2::JavascriptMath::Exponentiation, AttrCanThrow)


HELPERCALL_FULL_OR_INPLACE_MATH(Op_And, Js::JavascriptMath::And, Js::SSE2::JavascriptMath::And, AttrCanThrow)
HELPERCALL_FULL_OR_INPLACE_MATH(Op_Or, Js::JavascriptMath::Or, Js::SSE2::JavascriptMath::Or, AttrCanThrow)
HELPERCALL_FULL_OR_INPLACE_MATH(Op_Xor, Js::JavascriptMath::Xor, Js::SSE2::JavascriptMath::Xor, AttrCanThrow)
Expand Down Expand Up @@ -510,7 +509,6 @@ HELPERCALL(DirectMath_PowDoubleInt, (double(*)(double, int32))Js::JavascriptNumb
HELPERCALL(DirectMath_Pow, (double(*)(double, double))Js::JavascriptNumber::DirectPow, 0)
HELPERCALL_MATH(DirectMath_Random, (double(*)(Js::ScriptContext*))Js::JavascriptMath::Random, (double(*)(Js::ScriptContext*))Js::SSE2::JavascriptMath::Random, 0)


//
// Putting dllimport function ptr in JnHelperMethodAddresses will cause the table to be allocated in read-write memory
// as dynamic initialization is require to load these addresses. Use nullptr instead and handle these function in GetNonTableMethodAddress().
Expand All @@ -529,6 +527,8 @@ HELPERCALL(DirectMath_TruncFlt, nullptr, 0)
HELPERCALL(DirectMath_NearestDb, nullptr, 0)
HELPERCALL(DirectMath_NearestFlt, nullptr, 0)

HELPERCALL(PopCnt32, Math::PopCnt32, 0)

#ifdef _M_IX86
HELPERCALL(DirectMath_Acos, nullptr, 0)
HELPERCALL(DirectMath_Asin, nullptr, 0)
Expand Down
45 changes: 19 additions & 26 deletions lib/Backend/Lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Lowerer::LowerRange(IR::Instr *instrStart, IR::Instr *instrEnd, bool defaultDoFa
case Js::OpCode::InvalCachedScope:
this->LowerBinaryHelper(instr, IR::HelperOP_InvalidateCachedScope);
break;

case Js::OpCode::InitCachedScope:
instrPrev = this->LowerInitCachedScope(instr);
break;
Expand Down Expand Up @@ -624,6 +624,10 @@ Lowerer::LowerRange(IR::Instr *instrStart, IR::Instr *instrEnd, bool defaultDoFa
GenerateCtz(instr);
break;

case Js::OpCode::PopCnt32:
GeneratePopCnt32(instr);
break;

case Js::OpCode::InlineMathClz32:
GenerateFastInlineMathClz32(instr);
break;
Expand Down Expand Up @@ -3589,11 +3593,9 @@ Lowerer::LowerNewScArray(IR::Instr *arrInstr)
return LowerProfiledNewScArray(arrInstr->AsJitProfilingInstr());
}


IR::Instr *instrPrev = arrInstr->m_prev;
IR::JnHelperMethod helperMethod = IR::HelperScrArr_OP_NewScArray;


if (arrInstr->IsProfiledInstr() && arrInstr->m_func->HasProfileInfo())
{
RecyclerWeakReference<Js::FunctionBody> *weakFuncRef = arrInstr->m_func->GetWeakFuncRef();
Expand All @@ -3604,7 +3606,6 @@ Lowerer::LowerNewScArray(IR::Instr *arrInstr)
Js::DynamicProfileInfo *profileInfo = functionBody->GetAnyDynamicProfileInfo();
Js::ArrayCallSiteInfo *arrayInfo = profileInfo->GetArrayCallSiteInfo(functionBody, profileId);


Assert(arrInstr->GetSrc1()->IsConstOpnd());
GenerateProfiledNewScArrayFastPath(arrInstr, arrayInfo, weakFuncRef, arrInstr->GetSrc1()->AsIntConstOpnd()->AsUint32());

Expand Down Expand Up @@ -7937,7 +7938,6 @@ Lowerer::LowerAddLeftDeadForString(IR::Instr *instr)
IR::IntConstOpnd::New(1, TyUint32, m_func),
Js::OpCode::BrNeq_A, labelHelper, insertBeforeInstr);


// if left->m_directCharLength == -1
InsertCompareBranch(IR::IndirOpnd::New(opndLeft->AsRegOpnd(), (int32)Js::CompoundString::GetOffsetOfDirectCharLength(), TyUint32, m_func),
IR::IntConstOpnd::New(UINT32_MAX, TyUint32, m_func),
Expand All @@ -7956,21 +7956,18 @@ Lowerer::LowerAddLeftDeadForString(IR::Instr *instr)
IR::RegOpnd *charResultOpnd = IR::RegOpnd::New(TyUint16, this->m_func);
InsertMove(charResultOpnd, IR::IndirOpnd::New(pszValue0Opnd, 0, TyUint16, this->m_func), insertBeforeInstr);


// lastBlockInfo.buffer[blockCharLength] = c;
IR::RegOpnd *baseOpnd = IR::RegOpnd::New(TyMachPtr, this->m_func);
InsertMove(baseOpnd, IR::IndirOpnd::New(opndLeft->AsRegOpnd(), (int32)Js::CompoundString::GetOffsetOfLastBlockInfo() + (int32)Js::CompoundString::GetOffsetOfLastBlockInfoBuffer(), TyMachPtr, m_func), insertBeforeInstr);
IR::IndirOpnd *indirBufferToStore = IR::IndirOpnd::New(baseOpnd, charLengthOpnd, (byte)Math::Log2(sizeof(char16)), TyUint16, m_func);
InsertMove(indirBufferToStore, charResultOpnd, insertBeforeInstr);


// left->m_charLength++
InsertAdd(false, indirLeftCharLengthOpnd, regLeftCharLengthOpnd, IR::IntConstOpnd::New(1, TyUint32, this->m_func), insertBeforeInstr);

// lastBlockInfo.charLength++
InsertAdd(false, indirCharLength, indirCharLength, IR::IntConstOpnd::New(1, TyUint32, this->m_func), insertBeforeInstr);


InsertBranch(Js::OpCode::Br, labelFallThrough, insertBeforeInstr);

return this->LowerBinaryHelperMemWithTemp(instr, IR::HelperOp_AddLeftDead);
Expand Down Expand Up @@ -8505,7 +8502,7 @@ Lowerer::LowerMemset(IR::Instr * instr, IR::RegOpnd * helperRet)
m_lowererMD.LoadHelperArgument(instr, baseOpnd);
m_lowererMD.ChangeToHelperCall(instr, helperMethod);
dst->Free(m_func);

return instrPrev;
}

Expand Down Expand Up @@ -9461,7 +9458,6 @@ Lowerer::LowerStElemC(IR::Instr * stElem)
return instrPrev;
}


IntConstType base;
IR::RegOpnd *baseOpnd = indirOpnd->GetBaseOpnd();
const ValueType baseValueType(baseOpnd->GetValueType());
Expand Down Expand Up @@ -9715,7 +9711,7 @@ Lowerer::LowerArgIn(IR::Instr *instrArgIn)
// ...
// s2 = assign param2
// $done:

AnalysisAssert(instrArgIn);

IR::Opnd *restDst = nullptr;
Expand Down Expand Up @@ -9850,7 +9846,6 @@ Lowerer::LowerArgIn(IR::Instr *instrArgIn)
instrInsert->InsertBefore(labelUndef);
instrInsert->InsertBefore(labelNormal);


//Adjustment for deadstore of ArgIn_A
Js::ArgSlot highestSlotNum = instrArgIn->GetSrc1()->AsSymOpnd()->m_sym->AsStackSym()->GetParamSlotNum();
Js::ArgSlot missingSlotNums = this->m_func->GetInParamsCount() - highestSlotNum;
Expand All @@ -9867,9 +9862,8 @@ Lowerer::LowerArgIn(IR::Instr *instrArgIn)
opndUndef = IR::RegOpnd::New(TyMachPtr, this->m_func);
LowererMD::CreateAssign(opndUndef, opndUndefAddress, labelNormal);


BVSparse<JitArenaAllocator> *formalsBv = JitAnew(this->m_func->m_alloc, BVSparse<JitArenaAllocator>, this->m_func->m_alloc);

while (currArgInCount > 0)
{
dstOpnd = instrArgIn->GetDst();
Expand All @@ -9887,9 +9881,8 @@ Lowerer::LowerArgIn(IR::Instr *instrArgIn)
// BrEq_A $Ln-1

currArgInCount--;

labelInitNext = IR::LabelInstr::New(Js::OpCode::Label, this->m_func);


// And insert the "normal" initialization before the "done" label

Expand Down Expand Up @@ -12655,7 +12648,6 @@ Lowerer::LowerInlineeStart(IR::Instr * inlineeStartInstr)
return false;
});


IR::Instr *argInsertInstr = inlineeStartInstr;
uint i = 0;
inlineeStartInstr->IterateMetaArgs( [&] (IR::Instr* metaArg)
Expand Down Expand Up @@ -14470,7 +14462,7 @@ Lowerer::GenerateFastElemIIntIndexCommon(
const bool needBailOutOnInvalidLength = !!(bailOutKind & (IR::BailOutOnInvalidatedArrayHeadSegment));
const bool needBailOutToHelper = !!(bailOutKind & (IR::BailOutOnArrayAccessHelperCall | IR::BailOutOnInvalidatedArrayLength));
const bool needBailOutOnSegmentLengthCompare = needBailOutToHelper || needBailOutOnInvalidLength;

if(indexIsLessThanHeadSegmentLength || needBailOutOnSegmentLengthCompare)
{
if (needBailOutOnSegmentLengthCompare)
Expand Down Expand Up @@ -15757,7 +15749,6 @@ Lowerer::GenerateFastStElemI(IR::Instr *& stElem, bool *instrIsInHelperBlockRef)
m_lowererMD.EmitLoadFloat(indirOpnd, reg, stElem);
}


}
}
else if (objectType == ObjectType::Uint8ClampedArray || objectType == ObjectType::Uint8ClampedVirtualArray || objectType == ObjectType::Uint8ClampedMixedArray)
Expand Down Expand Up @@ -17374,6 +17365,14 @@ Lowerer::GenerateCtz(IR::Instr* instr)
m_lowererMD.GenerateCtz(instr);
}

void
Lowerer::GeneratePopCnt32(IR::Instr* instr)
{
Assert(instr->GetSrc1()->IsInt32() || instr->GetSrc1()->IsUInt32());
Assert(instr->GetDst()->IsInt32() || instr->GetDst()->IsUInt32());
m_lowererMD.GeneratePopCnt32(instr);
}

void
Lowerer::GenerateFastInlineMathClz32(IR::Instr* instr)
{
Expand Down Expand Up @@ -18318,7 +18317,7 @@ Lowerer::GenerateFastArgumentsLdElemI(IR::Instr* ldElem, IR::LabelInstr *labelFa
ldElem->InsertBefore(labelCreateHeapArgs);
emittedFastPath = true;
}

if (!emittedFastPath)
{
throw Js::RejitException(RejitReason::DisableStackArgOpt);
Expand Down Expand Up @@ -18611,7 +18610,6 @@ Lowerer::GenerateFastLdFld(IR::Instr * const instrLdFld, IR::JnHelperMethod help
IR::RegOpnd * opndBase = propertySymOpnd->CreatePropertyOwnerOpnd(m_func);
bool usePolymorphicInlineCache = !!propertySymOpnd->m_runtimePolymorphicInlineCache;


IR::RegOpnd * opndInlineCache = IR::RegOpnd::New(TyMachPtr, this->m_func);
if (usePolymorphicInlineCache)
{
Expand Down Expand Up @@ -20019,7 +20017,6 @@ Lowerer::GenerateFastCmTypeOf(IR::Instr *compare, IR::RegOpnd *object, IR::IntCo

m_lowererMD.GenerateObjectTest(object, compare, target);


// MOV typeRegOpnd, [object + offset(Type)]
InsertMove(typeRegOpnd,
IR::IndirOpnd::New(object, Js::RecyclableObject::GetOffsetOfType(), TyMachReg, m_func),
Expand Down Expand Up @@ -20468,7 +20465,6 @@ Lowerer::GenerateLoadNewTarget(IR::Instr* instrInsert)
instrInsert->Remove();
}


void
Lowerer::GenerateGetCurrentFunctionObject(IR::Instr * instr)
{
Expand Down Expand Up @@ -21048,7 +21044,6 @@ Lowerer::GenerateSimplifiedInt4Rem(
return true;
}


#if DBG
bool
Lowerer::ValidOpcodeAfterLower(IR::Instr* instr, Func * func)
Expand Down Expand Up @@ -21362,7 +21357,6 @@ Lowerer::LowerDivI4Common(IR::Instr * instr)
// dst = IDIV src2, src1
// $done:


IR::LabelInstr * div0Label = InsertLabel(true, instr);
IR::LabelInstr * divLabel = InsertLabel(false, instr);
IR::LabelInstr * doneLabel = InsertLabel(false, instr->m_next);
Expand Down Expand Up @@ -21886,7 +21880,6 @@ void Lowerer::LowerBrFncCachedScopeEq(IR::Instr *instr)
instr->Remove();
}


IR::Instr* Lowerer::InsertLoweredRegionStartMarker(IR::Instr* instrToInsertBefore)
{
AssertMsg(instrToInsertBefore->m_prev != nullptr, "Can't insert lowered region start marker as the first instr in the func.");
Expand Down
2 changes: 1 addition & 1 deletion lib/Backend/Lower.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ class Lowerer
void GenerateFastInlineMathImul(IR::Instr* instr);
void GenerateFastInlineMathClz32(IR::Instr* instr);
void GenerateCtz(IR::Instr* instr);
void GeneratePopCnt32(IR::Instr* instr);
void GenerateFastInlineMathFround(IR::Instr* instr);
void GenerateFastInlineRegExpExec(IR::Instr * instr);
bool GenerateFastPush(IR::Opnd *baseOpndParam, IR::Opnd *src, IR::Instr *callInstr, IR::Instr *insertInstr, IR::LabelInstr *labelHelper, IR::LabelInstr *doneLabel, IR::LabelInstr * bailOutLabelHelper, bool returnLength = false);
Expand Down Expand Up @@ -532,7 +533,6 @@ class Lowerer
IR::AddrOpnd * CreateFunctionBodyOpnd(Func *const func) const;
IR::AddrOpnd * CreateFunctionBodyOpnd(Js::FunctionBody *const functionBody) const;


bool GenerateRecyclerOrMarkTempAlloc(IR::Instr * instr, IR::RegOpnd * dstOpnd, IR::JnHelperMethod allocHelper, size_t allocSize, IR::SymOpnd ** tempObjectSymOpnd);
IR::SymOpnd * GenerateMarkTempAlloc(IR::RegOpnd *const dstOpnd, const size_t allocSize, IR::Instr *const insertBeforeInstr);
void LowerBrFncCachedScopeEq(IR::Instr *instr);
Expand Down

0 comments on commit e51083a

Please sign in to comment.