Skip to content

Commit f70f51c

Browse files
committed
[MERGE #4074 @arunetm] WASM.SIMD: Trunc & Conv ops for 64x2 types
Merge pull request #4074 from arunetm:arunetm/wasm.simd.trunc64x2 Truncation & conversion operstions for 64x2 types. Xplat link error fixes
2 parents 66bb1a9 + e12dac3 commit f70f51c

17 files changed

+198
-11
lines changed

lib/Backend/IRBuilderAsmJs.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4672,7 +4672,11 @@ IRBuilderAsmJs::BuildInt64x2_3(Js::OpCodeAsmJs newOpcode, uint32 offset, BUILD_S
46724672
void
46734673
IRBuilderAsmJs::BuildInt64x2_2(Js::OpCodeAsmJs newOpcode, uint32 offset, BUILD_SIMD_ARGS_REG2)
46744674
{
4675-
Assert(newOpcode == Js::OpCodeAsmJs::Simd128_Neg_I2);
4675+
Assert(newOpcode == Js::OpCodeAsmJs::Simd128_Neg_I2 ||
4676+
newOpcode == Js::OpCodeAsmJs::Simd128_FromUint64x2_D2 ||
4677+
newOpcode == Js::OpCodeAsmJs::Simd128_FromInt64x2_D2 ||
4678+
newOpcode == Js::OpCodeAsmJs::Simd128_FromFloat64x2_I2 ||
4679+
newOpcode == Js::OpCodeAsmJs::Simd128_FromFloat64x2_U2);
46764680
BuildSimd_2(newOpcode, offset, dstRegSlot, src1RegSlot, TySimd128I2);
46774681
}
46784682

lib/Backend/JnHelperMethodList.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ HELPERCALL(Simd128ShRtByScalarU2, Js::SIMDInt64x2Operation::OpShiftRightByScalar
355355
HELPERCALL(Simd128ShRtByScalarI2, Js::SIMDInt64x2Operation::OpShiftRightByScalar, 0)
356356
HELPERCALL(Simd128ShLtByScalarI2, Js::SIMDInt64x2Operation::OpShiftLeftByScalar, 0)
357357
HELPERCALL(Simd128ReplaceLaneI2, Js::SIMDInt64x2Operation::OpReplaceLane, 0)
358+
HELPERCALL(Simd128TruncateI2, (void(*)(SIMDValue*, SIMDValue*))&Js::SIMDInt64x2Operation::OpTrunc<int64>, AttrCanThrow)
359+
HELPERCALL(Simd128TruncateU2, (void(*)(SIMDValue*, SIMDValue*))&Js::SIMDInt64x2Operation::OpTrunc<uint64>, AttrCanThrow)
360+
HELPERCALL(Simd128ConvertSD2, (void(*)(SIMDValue*, SIMDValue*))&Js::SIMDFloat64x2Operation::OpConv<int64>, 0)
361+
HELPERCALL(Simd128ConvertUD2, (void(*)(SIMDValue*, SIMDValue*))&Js::SIMDFloat64x2Operation::OpConv<uint64>, 0)
358362
#endif
359363

360364
HELPERCALL(Op_TryCatch, nullptr, 0)

lib/Backend/LowerMDShared.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ class LowererMD
347347
void EmitExtractInt64(IR::Opnd* dst, IR::Opnd* src, uint index, IR::Instr *instr);
348348
void EmitInsertInt64(IR::Opnd* dst, uint index, IR::Instr *instr);
349349
void EmitShiftByScalarI2(IR::Instr *instr, IR::JnHelperMethod helper);
350+
IR::Instr* EmitSimdConversion(IR::Instr *instr, IR::JnHelperMethod helper);
350351
IR::Instr* SIMD128LowerReplaceLane_4(IR::Instr *instr);
351352
IR::Instr* SIMD128LowerReplaceLane_8(IR::Instr *instr);
352353
IR::Instr* SIMD128LowerReplaceLane_16(IR::Instr *instr);

lib/Backend/LowerMDSharedSimd128.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,14 @@ IR::Instr* LowererMD::Simd128LowerUnMappedInstruction(IR::Instr *instr)
772772
case Js::OpCode::Simd128_FromFloat32x4_U4:
773773
return Simd128LowerUint32x4FromFloat32x4(instr);
774774

775+
case Js::OpCode::Simd128_FromInt64x2_D2:
776+
return EmitSimdConversion(instr, IR::HelperSimd128ConvertSD2);
777+
case Js::OpCode::Simd128_FromUint64x2_D2:
778+
return EmitSimdConversion(instr, IR::HelperSimd128ConvertUD2);
779+
case Js::OpCode::Simd128_FromFloat64x2_I2:
780+
return EmitSimdConversion(instr, IR::HelperSimd128TruncateI2);
781+
case Js::OpCode::Simd128_FromFloat64x2_U2:
782+
return EmitSimdConversion(instr, IR::HelperSimd128TruncateU2);
775783
case Js::OpCode::Simd128_Neq_I4:
776784
case Js::OpCode::Simd128_Neq_I8:
777785
case Js::OpCode::Simd128_Neq_I16:
@@ -901,6 +909,20 @@ IR::Instr* LowererMD::Simd128CanonicalizeToBools(IR::Instr* instr, const Js::OpC
901909
return instr;
902910
}
903911

912+
IR::Instr* LowererMD::EmitSimdConversion(IR::Instr *instr, IR::JnHelperMethod helper)
913+
{
914+
IR::MemRefOpnd* srcMemRef = LoadSimdHelperArgument(instr, 0);
915+
IR::MemRefOpnd* dstMemRef = LoadSimdHelperArgument(instr, 1);
916+
m_lowerer->InsertMove(srcMemRef, instr->UnlinkSrc1(), instr);
917+
918+
IR::Instr * helperCall = IR::Instr::New(Js::OpCode::CALL, this->m_func);
919+
instr->InsertBefore(helperCall);
920+
this->ChangeToHelperCall(helperCall, helper);
921+
922+
m_lowerer->InsertMove(instr->UnlinkDst(), dstMemRef, instr);
923+
return removeInstr(instr);
924+
}
925+
904926
void LowererMD::EmitShiftByScalarI2(IR::Instr *instr, IR::JnHelperMethod helper)
905927
{
906928
IR::Opnd* src2 = instr->GetSrc2();

lib/Runtime/ByteCode/OpCodesSimd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ MACRO_SIMD_EXTEND_WMS(Simd128_ShRtByScalar_I2, Int64x2_2Int1, None, None, 0)
144144
MACRO_SIMD_EXTEND_WMS(Simd128_ShRtByScalar_U2, Int64x2_2Int1, None, None, 0)
145145
MACRO_SIMD_EXTEND_WMS(Simd128_AnyTrue_B2, Int1Bool64x2_1, None, None, 0)
146146
MACRO_SIMD_EXTEND_WMS(Simd128_AllTrue_B2, Int1Bool64x2_1, None, None, 0)
147+
MACRO_SIMD_EXTEND_WMS(Simd128_FromFloat64x2_I2, Int64x2_2, None, None, 0)
148+
MACRO_SIMD_EXTEND_WMS(Simd128_FromFloat64x2_U2, Int64x2_2, None, None, 0)
147149

148150
// Float64x2
149151
MACRO_SIMD_EXTEND_WMS(Simd128_Splat_D2, Float64x2_1Double1, None, None, 0)
@@ -164,6 +166,8 @@ MACRO_SIMD_EXTEND_WMS(Simd128_Sub_D2, Float64x2_3, None, None, 0)
164166
MACRO_SIMD_EXTEND_WMS(Simd128_Mul_D2, Float64x2_3, None, None, 0)
165167
MACRO_SIMD_EXTEND_WMS(Simd128_Div_D2, Float64x2_3, None, None, 0)
166168
MACRO_SIMD_EXTEND_WMS(Simd128_Sqrt_D2, Float64x2_2, None, None, 0)
169+
MACRO_SIMD_EXTEND_WMS(Simd128_FromInt64x2_D2, Int64x2_2, None, None, 0) //Int64x2_2 is intentional
170+
MACRO_SIMD_EXTEND_WMS(Simd128_FromUint64x2_D2, Int64x2_2, None, None, 0)
167171
// Float64x2
168172
#if 0 //Disabling this type until the specification decides to include or not.
169173
MACRO_SIMD_EXTEND_WMS(Simd128_DoublesToD2, Float64x2_1Double2, None, None, 0)

lib/Runtime/Language/InterpreterHandlerAsmJs.inl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,10 @@ EXDEF2_WMS(SIMD_D2_2toD2_1, Simd128_Neq_D2, Js::SIMDFloat64x2Operation::OpNotEqu
723723
EXDEF2_WMS(SIMD_D2_2toD2_1, Simd128_GtEq_D2, Js::SIMDFloat64x2Operation::OpGreaterThanOrEqual)
724724
EXDEF2_WMS(SIMD_D2_2toD2_1, Simd128_Gt_D2, Js::SIMDFloat64x2Operation::OpGreaterThan)
725725
EXDEF2_WMS(SIMD_D2_1toD2_1, Simd128_Sqrt_D2, SIMDFloat64x2Operation::OpSqrt)
726+
EXDEF2_WMS(SIMD_I2_1toI2_P, Simd128_FromInt64x2_D2, SIMDFloat64x2Operation::OpConv<int64>)
727+
EXDEF2_WMS(SIMD_I2_1toI2_P, Simd128_FromUint64x2_D2, SIMDFloat64x2Operation::OpConv<uint64>)
728+
EXDEF2_WMS(SIMD_I2_1toI2_P, Simd128_FromFloat64x2_I2, SIMDInt64x2Operation::OpTrunc<int64>)
729+
EXDEF2_WMS(SIMD_I2_1toI2_P, Simd128_FromFloat64x2_U2, SIMDInt64x2Operation::OpTrunc<uint64>)
726730

727731
#if 0
728732
EXDEF2_WMS(SIMD_D2toD2_1, Simd128_DoublesToD2, SIMDFloat64x2Operation::OpFloat64x2)

lib/Runtime/Language/InterpreterProcessOpCodeAsmJs.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
#define PROCESS_FUNCtoA1Mem(name, func) PROCESS_FUNCtoA1Mem_COMMON(name, func,)
4444

45-
4645
#define PROCESS_CUSTOM_ASMJS_COMMON(name, func, layout, suffix) \
4746
case OpCodeAsmJs::name: \
4847
{ \
@@ -873,6 +872,18 @@ if (switchProfileMode) \
873872
}
874873
#define PROCESS_SIMD_I2_1toI2_1 (name, func) PROCESS_SIMD_I2_1toI2_1_COMMON(name, func,)
875874

875+
#define PROCESS_SIMD_I2_1toI2_P_COMMON(name, func, suffix) \
876+
case OpCodeAsmJs::name: \
877+
{ \
878+
PROCESS_READ_LAYOUT_ASMJS(name, Int64x2_2, suffix); \
879+
SIMDValue result {0}; \
880+
SIMDValue src = GetRegRawSimd(playout->I2_1); \
881+
func(&result, &src); \
882+
SetRegRawSimd(playout->I2_0, result); \
883+
break; \
884+
}
885+
#define PROCESS_SIMD_I2_1toI2_P(name, func) PROCESS_SIMD_I2_1toI2_P_COMMON(name, func,)
886+
876887
#define PROCESS_SIMD_I2_1I1toI2_1_COMMON(name, func, suffix) \
877888
case OpCodeAsmJs::name: \
878889
{ \

lib/Runtime/Language/InterpreterStackFrame.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3803,12 +3803,14 @@ namespace Js
38033803
case AsmJsRetType::Uint32x4:
38043804
case AsmJsRetType::Uint16x8:
38053805
case AsmJsRetType::Uint8x16:
3806+
#if _WIN32 //WASM.SIMD ToDo: Enable thunk for Xplat
38063807
#if _M_X64
38073808
X86SIMDValue simdVal;
38083809
simdVal.m128_value = JavascriptFunction::CallAsmJsFunction<__m128>(function, entrypointInfo->jsMethod, m_outParams, alignedArgsSize, reg);
38093810
m_localSimdSlots[returnReg] = X86SIMDValue::ToSIMDValue(simdVal);
38103811
#else
38113812
m_localSimdSlots[returnReg] = JavascriptFunction::CallAsmJsFunction<AsmJsSIMDValue>(function, entrypointInfo->jsMethod, m_outParams, alignedArgsSize, reg);
3813+
#endif
38123814
#endif
38133815
break;
38143816
#endif

lib/Runtime/Language/SimdFloat64x2Operation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace Js {
4343
static SIMDValue OpGreaterThan(const SIMDValue& aValue, const SIMDValue& bValue);
4444
static SIMDValue OpGreaterThanOrEqual(const SIMDValue& aValue, const SIMDValue& bValue);
4545
static SIMDValue OpSelect(const SIMDValue& mV, const SIMDValue& tV, const SIMDValue& fV);
46+
template<typename T> static void OpConv(SIMDValue* dst, SIMDValue* src);
4647
};
4748

4849
} // namespace Js

lib/Runtime/Language/SimdFloat64x2OperationX86X64.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,16 @@ namespace Js
318318
return X86SIMDValue::ToSIMDValue(x86Result);
319319
}
320320

321+
template<typename T>
322+
void SIMDFloat64x2Operation::OpConv(SIMDValue* dst, SIMDValue* src)
323+
{
324+
dst->f64[0] = (double) (T)src->i64[0];
325+
dst->f64[1] = (double) (T)src->i64[1];
326+
}
327+
328+
template void SIMDFloat64x2Operation::OpConv<int64>(SIMDValue* dst, SIMDValue* src);
329+
template void SIMDFloat64x2Operation::OpConv<uint64>(SIMDValue* dst, SIMDValue* src);
330+
321331
}
322332

323333
#endif

0 commit comments

Comments
 (0)