public void RunBasicScenario_UnsafeRead() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); var result = Sse2.Average( Unsafe.Read <Vector128 <UInt16> >(_dataTable.inArray1Ptr), Unsafe.Read <Vector128 <UInt16> >(_dataTable.inArray2Ptr) ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); }
public void RunStructLclFldScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); var test = TestStruct.Create(); var result = Sse2.Average( Sse2.LoadVector128((UInt16 *)(&test._fld1)), Sse2.LoadVector128((UInt16 *)(&test._fld2)) ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); }
static unsafe int Main(string[] args) { int testResult = Pass; int testsCount = 21; string methodUnderTestName = nameof(Sse2.Average); if (Sse2.IsSupported) { using (var ushortTable = TestTableSse2 <ushort> .Create(testsCount)) using (var byteTable = TestTableSse2 <byte> .Create(testsCount)) { for (int i = 0; i < testsCount; i++) { (Vector128 <ushort>, Vector128 <ushort>, Vector128 <ushort>)value = ushortTable[i]; Vector128 <ushort> result = Sse2.Average(value.Item1, value.Item2); ushortTable.SetOutArray(result); } for (int i = 0; i < testsCount; i++) { (Vector128 <byte>, Vector128 <byte>, Vector128 <byte>)value = byteTable[i]; Vector128 <byte> result = Sse2.Average(value.Item1, value.Item2); byteTable.SetOutArray(result); } CheckMethod <ushort> checkUshort = (ushort x, ushort y, ushort z, ref ushort a) => (a = (ushort)((x + y + 1) >> 1)) == z; if (!ushortTable.CheckResult(checkUshort)) { PrintError(ushortTable, methodUnderTestName, "(x, y, z, ref a) => (a = (x + y + 1) >> 1) == z", checkUshort); testResult = Fail; } CheckMethod <byte> checkByte = (byte x, byte y, byte z, ref byte a) => (a = (byte)((x + y + 1) >> 1)) == z; if (!byteTable.CheckResult(checkByte)) { PrintError(byteTable, methodUnderTestName, "(x, y, z, ref a) => (a = (x + y + 1) >> 1) == z", checkByte); testResult = Fail; } } } else { Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}"); } return(testResult); }
public void RunStructFldScenario_Load(SimpleBinaryOpTest__AverageUInt16 testClass) { fixed(Vector128 <UInt16> *pFld1 = &_fld1) fixed(Vector128 <UInt16> *pFld2 = &_fld2) { var result = Sse2.Average( Sse2.LoadVector128((UInt16 *)(pFld1)), Sse2.LoadVector128((UInt16 *)(pFld2)) ); Unsafe.Write(testClass._dataTable.outArrayPtr, result); testClass.ValidateResult(_fld1, _fld2, testClass._dataTable.outArrayPtr); } }
unsafe private static void denoiseLineSse2(byte *pcurr, byte *pprev, byte *pnext, int cb) { byte *ip = pcurr, pp = pprev, np = pnext; nuint cnt = 0, end = (nuint)cb - (nuint)Vector128 <byte> .Count; var voffset = Vector128.Create((byte)0x80); var vthresh = Vector128.Create(denoiseThreshold); LoopTop: do { var vcurr = Sse2.LoadVector128(ip + cnt); var vprev = Sse2.LoadVector128(pp + cnt); var vnext = Sse2.LoadVector128(np + cnt); var vdiffp = Sse2.Or(Sse2.SubtractSaturate(vcurr, vprev), Sse2.SubtractSaturate(vprev, vcurr)); var vmaskp = Sse2.CompareEqual(Sse2.Max(vdiffp, vthresh), vthresh); var vdiffn = Sse2.Or(Sse2.SubtractSaturate(vcurr, vnext), Sse2.SubtractSaturate(vnext, vcurr)); var vmaskn = Sse2.CompareEqual(Sse2.Max(vdiffn, vthresh), vthresh); var vavgp = Sse2.Average(vcurr, vprev); var vavgn = Sse2.Average(vcurr, vnext); var voutval = Sse2.Average(HWIntrinsics.BlendVariable(vavgn, vavgp, vmaskp), HWIntrinsics.BlendVariable(vavgp, vavgn, vmaskn)); var voutmsk = Sse2.Or(vmaskp, vmaskn); voutval = Sse2.Average(voutval, HWIntrinsics.BlendVariable(voutval, Sse2.Average(vprev, vnext), Sse2.And(vmaskp, vmaskn))); var vcurrs = Sse2.Xor(vcurr, voffset).AsSByte(); var vprevs = Sse2.Xor(vprev, voffset).AsSByte(); var vnexts = Sse2.Xor(vnext, voffset).AsSByte(); var vsurlt = Sse2.And(Sse2.CompareGreaterThan(vcurrs, vprevs), Sse2.CompareGreaterThan(vcurrs, vnexts)); var vsurgt = Sse2.And(Sse2.CompareGreaterThan(vprevs, vcurrs), Sse2.CompareGreaterThan(vnexts, vcurrs)); voutmsk = Sse2.And(voutmsk, Sse2.Or(vsurlt, vsurgt).AsByte()); voutval = HWIntrinsics.BlendVariable(vcurr, voutval, voutmsk); Sse2.Store(ip + cnt, voutval); cnt += (nuint)Vector128 <byte> .Count; } while (cnt <= end); if (cnt < end + (nuint)Vector128 <byte> .Count) { cnt = end; goto LoopTop; } }
public void RunClassFldScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); fixed(Vector128 <UInt16> *pFld1 = &_fld1) fixed(Vector128 <UInt16> *pFld2 = &_fld2) { var result = Sse2.Average( Sse2.LoadVector128((UInt16 *)(pFld1)), Sse2.LoadVector128((UInt16 *)(pFld2)) ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } }
public void RunClsVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); fixed(Vector128 <Byte> *pClsVar1 = &_clsVar1) fixed(Vector128 <Byte> *pClsVar2 = &_clsVar2) { var result = Sse2.Average( Sse2.LoadVector128((Byte *)(pClsVar1)), Sse2.LoadVector128((Byte *)(pClsVar2)) ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } }
public void RunClassLclFldScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); var test = new SimpleBinaryOpTest__AverageByte(); fixed(Vector128 <Byte> *pFld1 = &test._fld1) fixed(Vector128 <Byte> *pFld2 = &test._fld2) { var result = Sse2.Average( Sse2.LoadVector128((Byte *)(pFld1)), Sse2.LoadVector128((Byte *)(pFld2)) ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } }