Beispiel #1
0
        public void RunLclVarScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));

            var op1    = Unsafe.Read <Vector64 <UInt16> >(_dataTable.inArray1Ptr);
            var op2    = Unsafe.Read <Vector64 <UInt16> >(_dataTable.inArray2Ptr);
            var result = AdvSimd.AddWideningLower(op1, op2);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(op1, op2, _dataTable.outArrayPtr);
        }
        public void RunLclVarScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));

            var op1    = AdvSimd.LoadVector128((Int64 *)(_dataTable.inArray1Ptr));
            var op2    = AdvSimd.LoadVector64((Int32 *)(_dataTable.inArray2Ptr));
            var result = AdvSimd.AddWideningLower(op1, op2);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(op1, op2, _dataTable.outArrayPtr);
        }
Beispiel #3
0
        public void RunClsVarScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));

            var result = AdvSimd.AddWideningLower(
                _clsVar1,
                _clsVar2
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr);
        }
Beispiel #4
0
        public void RunBasicScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));

            var result = AdvSimd.AddWideningLower(
                AdvSimd.LoadVector64((Int16 *)(_dataTable.inArray1Ptr)),
                AdvSimd.LoadVector64((Int16 *)(_dataTable.inArray2Ptr))
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
        public void RunBasicScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));

            var result = AdvSimd.AddWideningLower(
                Unsafe.Read <Vector64 <Int32> >(_dataTable.inArray1Ptr),
                Unsafe.Read <Vector64 <Int32> >(_dataTable.inArray2Ptr)
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
Beispiel #6
0
        public void RunStructLclFldScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load));

            var test   = TestStruct.Create();
            var result = AdvSimd.AddWideningLower(
                AdvSimd.LoadVector64((Int16 *)(&test._fld1)),
                AdvSimd.LoadVector64((Int16 *)(&test._fld2))
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr);
        }
Beispiel #7
0
            public void RunStructFldScenario_Load(SimpleBinaryOpTest__AddWideningLower_Vector64_Int16 testClass)
            {
                fixed(Vector64 <Int16> *pFld1 = &_fld1)
                fixed(Vector64 <Int16> *pFld2 = &_fld2)
                {
                    var result = AdvSimd.AddWideningLower(
                        AdvSimd.LoadVector64((Int16 *)(pFld1)),
                        AdvSimd.LoadVector64((Int16 *)(pFld2))
                        );

                    Unsafe.Write(testClass._dataTable.outArrayPtr, result);
                    testClass.ValidateResult(_fld1, _fld2, testClass._dataTable.outArrayPtr);
                }
            }
Beispiel #8
0
        public void RunClassFldScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load));

            fixed(Vector64 <Int16> *pFld1 = &_fld1)
            fixed(Vector64 <Int16> *pFld2 = &_fld2)
            {
                var result = AdvSimd.AddWideningLower(
                    AdvSimd.LoadVector64((Int16 *)(pFld1)),
                    AdvSimd.LoadVector64((Int16 *)(pFld2))
                    );

                Unsafe.Write(_dataTable.outArrayPtr, result);
                ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr);
            }
        }
        public void RunClsVarScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load));

            fixed(Vector64 <Int32> *pClsVar1 = &_clsVar1)
            fixed(Vector64 <Int32> *pClsVar2 = &_clsVar2)
            {
                var result = AdvSimd.AddWideningLower(
                    AdvSimd.LoadVector64((Int32 *)(pClsVar1)),
                    AdvSimd.LoadVector64((Int32 *)(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__AddWideningLower_Vector64_Int32();

            fixed(Vector64 <Int32> *pFld1 = &test._fld1)
            fixed(Vector64 <Int32> *pFld2 = &test._fld2)
            {
                var result = AdvSimd.AddWideningLower(
                    AdvSimd.LoadVector64((Int32 *)(pFld1)),
                    AdvSimd.LoadVector64((Int32 *)(pFld2))
                    );

                Unsafe.Write(_dataTable.outArrayPtr, result);
                ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr);
            }
        }
Beispiel #11
0
        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);
        }