Skip to content

Commit

Permalink
Place WebAssembly fast array under a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Cellule committed Jan 27, 2017
1 parent 6a7a303 commit f48d1f5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
11 changes: 8 additions & 3 deletions lib/Backend/IRBuilderAsmJs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1445,8 +1445,10 @@ void
IRBuilderAsmJs::BuildAsmTypedArr(Js::OpCodeAsmJs newOpcode, uint32 offset, uint32 slotIndex, Js::RegSlot value, int8 viewType)
{
IRType type = TyInt32;
bool isWasm = this->m_func->GetJITFunctionBody()->IsWasmFunction();
bool isLd = newOpcode == Js::OpCodeAsmJs::LdArr || newOpcode == Js::OpCodeAsmJs::LdArrWasm || newOpcode == Js::OpCodeAsmJs::LdArrConst;
Js::OpCode op = isLd ? (this->m_func->GetJITFunctionBody()->IsWasmFunction() ?

Js::OpCode op = isLd ? (isWasm ?
Js::OpCode::LdArrViewElemWasm : Js::OpCode::LdArrViewElem) : Js::OpCode::StArrViewElem;
ValueType arrayType;
WAsmJs::Types valueRegType = WAsmJs::INT32;
Expand Down Expand Up @@ -1578,9 +1580,12 @@ IRBuilderAsmJs::BuildAsmTypedArr(Js::OpCodeAsmJs newOpcode, uint32 offset, uint3
instr = IR::Instr::New(op, indirOpnd, regOpnd, m_func);
}

#if !_WIN64
instr->SetSrc2(BuildSrcOpnd(AsmJsRegSlots::LengthReg, TyUint32));
#if ENABLE_FAST_ARRAYBUFFER
if (isWasm && !PHASE_ON1(Js::WasmFastArrayPhase))
#endif
{
instr->SetSrc2(BuildSrcOpnd(AsmJsRegSlots::LengthReg, TyUint32));
}
AddInstr(instr, offset);
}

Expand Down
13 changes: 8 additions & 5 deletions lib/Backend/amd64/LowererMDArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,9 +1118,13 @@ LowererMDArch::LowerAsmJsCallI(IR::Instr * callInstr)
IR::Instr *
LowererMDArch::LowerWasmMemOp(IR::Instr * instr, IR::Opnd *addrOpnd)
{
#if _WIN64
return instr;
#else
#if ENABLE_FAST_ARRAYBUFFER
if (PHASE_ON1(Js::WasmFastArrayPhase))
{
return instr;
}
#endif

Assert(instr->GetSrc2());
IR::LabelInstr * helperLabel = Lowerer::InsertLabel(true, instr);
IR::LabelInstr * loadLabel = Lowerer::InsertLabel(false, instr);
Expand All @@ -1137,8 +1141,7 @@ LowererMDArch::LowerWasmMemOp(IR::Instr * instr, IR::Opnd *addrOpnd)

lowererMD->m_lowerer->GenerateThrow(IR::IntConstOpnd::New(WASMERR_ArrayIndexOutOfRange, TyInt32, m_func), loadLabel);
Lowerer::InsertBranch(Js::OpCode::Br, loadLabel, helperLabel);
return done;
#endif
return doneLabel;
}

IR::Instr*
Expand Down
1 change: 1 addition & 0 deletions lib/Common/ConfigFlagsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ PHASE(All)
PHASE(WasmFunctionBody)
PHASE(WasmDeferred)
PHASE(WasmValidatePrejit)
PHASE(WasmFastArray)
PHASE(Asmjs)
PHASE(AsmjsTmpRegisterAllocation)
PHASE(AsmjsEncoder)
Expand Down
12 changes: 11 additions & 1 deletion lib/Runtime/Library/WebAssemblyMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,17 @@ WebAssemblyMemory *
WebAssemblyMemory::CreateMemoryObject(uint32 initial, uint32 maximum, ScriptContext * scriptContext)
{
uint32 byteLength = UInt32Math::Mul<WebAssembly::PageSize>(initial);
ArrayBuffer * buffer = scriptContext->GetLibrary()->CreateWebAssemblyArrayBuffer(byteLength);
ArrayBuffer* buffer;
#if ENABLE_FAST_ARRAYBUFFER
if (PHASE_ON1(Js::WasmFastArrayPhase))
{
buffer = scriptContext->GetLibrary()->CreateWebAssemblyArrayBuffer(byteLength);
}
else
#endif
{
buffer = scriptContext->GetLibrary()->CreateArrayBuffer(byteLength);
}
return RecyclerNewFinalized(scriptContext->GetRecycler(), WebAssemblyMemory, buffer, initial, maximum, scriptContext->GetLibrary()->GetWebAssemblyMemoryType());
}

Expand Down
8 changes: 7 additions & 1 deletion test/wasm/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
<test>
<default>
<files>fastarray.js</files>
<compile-flags>-wasm </compile-flags>
<compile-flags>-wasm</compile-flags>
</default>
</test>
<test>
<default>
<files>fastarray.js</files>
<compile-flags>-wasm -on:WasmFastArray</compile-flags>
</default>
</test>
<test>
Expand Down

0 comments on commit f48d1f5

Please sign in to comment.