public void RunStructFldScenario(SimpleBinaryOpTest__AddPairwiseWideningAndAdd_Vector128_Int32 testClass) { var result = AdvSimd.AddPairwiseWideningAndAdd(_fld1, _fld2); Unsafe.Write(testClass._dataTable.outArrayPtr, result); testClass.ValidateResult(_fld1, _fld2, testClass._dataTable.outArrayPtr); }
public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); var result = AdvSimd.AddPairwiseWideningAndAdd(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); }
public void RunStructLclFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); var result = AdvSimd.AddPairwiseWideningAndAdd(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); }
public void RunClassLclFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new SimpleBinaryOpTest__AddPairwiseWideningAndAdd_Vector128_Int32(); var result = AdvSimd.AddPairwiseWideningAndAdd(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); }
public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); var op1 = AdvSimd.LoadVector128((Int64 *)(_dataTable.inArray1Ptr)); var op2 = AdvSimd.LoadVector128((Int32 *)(_dataTable.inArray2Ptr)); var result = AdvSimd.AddPairwiseWideningAndAdd(op1, op2); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(op1, op2, _dataTable.outArrayPtr); }
public void RunLclVarScenario_UnsafeRead() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); var op1 = Unsafe.Read <Vector128 <Int16> >(_dataTable.inArray1Ptr); var op2 = Unsafe.Read <Vector128 <SByte> >(_dataTable.inArray2Ptr); var result = AdvSimd.AddPairwiseWideningAndAdd(op1, op2); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(op1, op2, _dataTable.outArrayPtr); }
public void RunBasicScenario_UnsafeRead() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); var result = AdvSimd.AddPairwiseWideningAndAdd( Unsafe.Read <Vector128 <Int64> >(_dataTable.inArray1Ptr), Unsafe.Read <Vector128 <Int32> >(_dataTable.inArray2Ptr) ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); }
public void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); var result = AdvSimd.AddPairwiseWideningAndAdd( AdvSimd.LoadVector128((Int16 *)(_dataTable.inArray1Ptr)), AdvSimd.LoadVector128((SByte *)(_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 = AdvSimd.AddPairwiseWideningAndAdd( AdvSimd.LoadVector128((Int64 *)(&test._fld1)), AdvSimd.LoadVector128((Int32 *)(&test._fld2)) ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); }
public void RunStructFldScenario_Load(SimpleBinaryOpTest__AddPairwiseWideningAndAdd_Vector128_Int32 testClass) { fixed(Vector128 <Int64> *pFld1 = &_fld1) fixed(Vector128 <Int32> *pFld2 = &_fld2) { var result = AdvSimd.AddPairwiseWideningAndAdd( AdvSimd.LoadVector128((Int64 *)(pFld1)), AdvSimd.LoadVector128((Int32 *)(pFld2)) ); Unsafe.Write(testClass._dataTable.outArrayPtr, result); testClass.ValidateResult(_fld1, _fld2, testClass._dataTable.outArrayPtr); } }
public void RunStructFldScenario_Load(SimpleBinaryOpTest__AddPairwiseWideningAndAdd_Vector64_Byte testClass) { fixed(Vector64 <UInt16> *pFld1 = &_fld1) fixed(Vector64 <Byte> *pFld2 = &_fld2) { var result = AdvSimd.AddPairwiseWideningAndAdd( AdvSimd.LoadVector64((UInt16 *)(pFld1)), AdvSimd.LoadVector64((Byte *)(pFld2)) ); Unsafe.Write(testClass._dataTable.outArrayPtr, result); testClass.ValidateResult(_fld1, _fld2, testClass._dataTable.outArrayPtr); } }
public void RunClassFldScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); fixed(Vector128 <Int64> *pFld1 = &_fld1) fixed(Vector128 <Int32> *pFld2 = &_fld2) { var result = AdvSimd.AddPairwiseWideningAndAdd( AdvSimd.LoadVector128((Int64 *)(pFld1)), AdvSimd.LoadVector128((Int32 *)(pFld2)) ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } }
public void RunClsVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); fixed(Vector128 <Int16> *pClsVar1 = &_clsVar1) fixed(Vector128 <SByte> *pClsVar2 = &_clsVar2) { var result = AdvSimd.AddPairwiseWideningAndAdd( AdvSimd.LoadVector128((Int16 *)(pClsVar1)), AdvSimd.LoadVector128((SByte *)(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__AddPairwiseWideningAndAdd_Vector128_SByte(); fixed(Vector128 <Int16> *pFld1 = &test._fld1) fixed(Vector128 <SByte> *pFld2 = &test._fld2) { var result = AdvSimd.AddPairwiseWideningAndAdd( AdvSimd.LoadVector128((Int16 *)(pFld1)), AdvSimd.LoadVector128((SByte *)(pFld2)) ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } }
internal static void Step(ref ushort preSum1, ref ushort preSum2, byte[] buf, uint len) { /* * Split Adler-32 into component sums. */ uint s1 = preSum1; uint s2 = preSum2; int bufPos = 0; /* * Process the data in blocks. */ uint BLOCK_SIZE = 1 << 5; uint blocks = len / BLOCK_SIZE; len -= blocks * BLOCK_SIZE; while (blocks != 0) { uint n = Adler32Context.NMAX / BLOCK_SIZE; /* The NMAX constraint. */ if (n > blocks) { n = blocks; } blocks -= n; /* * Process n blocks of data. At most NMAX data bytes can be * processed before s2 must be reduced modulo ADLER_MODULE. */ Vector128 <uint> v_s2 = Vector128.Create(s1 * n, 0, 0, 0); Vector128 <uint> v_s1 = Vector128.Create(0u, 0, 0, 0); Vector128 <ushort> v_column_sum_1 = AdvSimd.DuplicateToVector128((ushort)0); Vector128 <ushort> v_column_sum_2 = AdvSimd.DuplicateToVector128((ushort)0); Vector128 <ushort> v_column_sum_3 = AdvSimd.DuplicateToVector128((ushort)0); Vector128 <ushort> v_column_sum_4 = AdvSimd.DuplicateToVector128((ushort)0); do { /* * Load 32 input bytes. */ Vector128 <byte> bytes1 = Vector128.Create(buf[bufPos], buf[bufPos + 1], buf[bufPos + 2], buf[bufPos + 3], buf[bufPos + 4], buf[bufPos + 5], buf[bufPos + 6], buf[bufPos + 7], buf[bufPos + 8], buf[bufPos + 9], buf[bufPos + 10], buf[bufPos + 11], buf[bufPos + 12], buf[bufPos + 13], buf[bufPos + 14], buf[bufPos + 15]); bufPos += 16; Vector128 <byte> bytes2 = Vector128.Create(buf[bufPos], buf[bufPos + 1], buf[bufPos + 2], buf[bufPos + 3], buf[bufPos + 4], buf[bufPos + 5], buf[bufPos + 6], buf[bufPos + 7], buf[bufPos + 8], buf[bufPos + 9], buf[bufPos + 10], buf[bufPos + 11], buf[bufPos + 12], buf[bufPos + 13], buf[bufPos + 14], buf[bufPos + 15]); bufPos += 16; /* * Add previous block byte sum to v_s2. */ v_s2 = AdvSimd.Add(v_s2, v_s1); /* * Horizontally add the bytes for s1. */ v_s1 = AdvSimd.AddPairwiseWideningAndAdd(v_s1, AdvSimd. AddPairwiseWideningAndAdd(AdvSimd.AddPairwiseWidening(bytes1), bytes2)); /* * Vertically add the bytes for s2. */ v_column_sum_1 = AdvSimd.AddWideningLower(v_column_sum_1, bytes1.GetLower()); v_column_sum_2 = AdvSimd.AddWideningLower(v_column_sum_2, bytes1.GetUpper()); v_column_sum_3 = AdvSimd.AddWideningLower(v_column_sum_3, bytes2.GetLower()); v_column_sum_4 = AdvSimd.AddWideningLower(v_column_sum_4, bytes2.GetUpper()); } while(--n != 0); v_s2 = AdvSimd.ShiftLeftLogical(v_s2, 5); /* * Multiply-add bytes by [ 32, 31, 30, ... ] for s2. */ v_s2 = AdvSimd.MultiplyWideningLowerAndAdd(v_s2, v_column_sum_1.GetLower(), Vector64.Create((ushort)32, 31, 30, 29)); v_s2 = AdvSimd.MultiplyWideningLowerAndAdd(v_s2, v_column_sum_1.GetUpper(), Vector64.Create((ushort)28, 27, 26, 25)); v_s2 = AdvSimd.MultiplyWideningLowerAndAdd(v_s2, v_column_sum_2.GetLower(), Vector64.Create((ushort)24, 23, 22, 21)); v_s2 = AdvSimd.MultiplyWideningLowerAndAdd(v_s2, v_column_sum_2.GetUpper(), Vector64.Create((ushort)20, 19, 18, 17)); v_s2 = AdvSimd.MultiplyWideningLowerAndAdd(v_s2, v_column_sum_3.GetLower(), Vector64.Create((ushort)16, 15, 14, 13)); v_s2 = AdvSimd.MultiplyWideningLowerAndAdd(v_s2, v_column_sum_3.GetUpper(), Vector64.Create((ushort)12, 11, 10, 9)); v_s2 = AdvSimd.MultiplyWideningLowerAndAdd(v_s2, v_column_sum_4.GetLower(), Vector64.Create((ushort)8, 7, 6, 5)); v_s2 = AdvSimd.MultiplyWideningLowerAndAdd(v_s2, v_column_sum_4.GetUpper(), Vector64.Create((ushort)4, 3, 2, 1)); /* * Sum epi32 ints v_s1(s2) and accumulate in s1(s2). */ Vector64 <uint> sum1 = AdvSimd.AddPairwise(v_s1.GetLower(), v_s1.GetUpper()); Vector64 <uint> sum2 = AdvSimd.AddPairwise(v_s2.GetLower(), v_s2.GetUpper()); Vector64 <uint> s1s2 = AdvSimd.AddPairwise(sum1, sum2); s1 += AdvSimd.Extract(s1s2, 0); s2 += AdvSimd.Extract(s1s2, 1); /* * Reduce. */ s1 %= Adler32Context.ADLER_MODULE; s2 %= Adler32Context.ADLER_MODULE; } /* * Handle leftover data. */ if (len != 0) { if (len >= 16) { s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; s2 += s1 += buf[bufPos++]; len -= 16; } while (len-- != 0) { s2 += s1 += buf[bufPos++]; } if (s1 >= Adler32Context.ADLER_MODULE) { s1 -= Adler32Context.ADLER_MODULE; } s2 %= Adler32Context.ADLER_MODULE; } /* * Return the recombined sums. */ preSum1 = (ushort)(s1 & 0xFFFF); preSum2 = (ushort)(s2 & 0xFFFF); }