Exemplo n.º 1
0
        public void RunFldScenario()
        {
            var result = Avx.ConvertToVector128Int32WithTruncation(_fld);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_fld, _dataTable.outArrayPtr);
        }
Exemplo n.º 2
0
        public void RunLclFldScenario()
        {
            var test   = new SimpleUnaryOpTest__ConvertToVector128Int32WithTruncationDouble();
            var result = Avx.ConvertToVector128Int32WithTruncation(test._fld);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(test._fld, _dataTable.outArrayPtr);
        }
Exemplo n.º 3
0
        public void RunLclVarScenario_UnsafeRead()
        {
            var firstOp = Unsafe.Read <Vector256 <Double> >(_dataTable.inArrayPtr);
            var result  = Avx.ConvertToVector128Int32WithTruncation(firstOp);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(firstOp, _dataTable.outArrayPtr);
        }
Exemplo n.º 4
0
        public void RunLclVarScenario_LoadAligned()
        {
            var firstOp = Avx.LoadAlignedVector256((Double *)(_dataTable.inArrayPtr));
            var result  = Avx.ConvertToVector128Int32WithTruncation(firstOp);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(firstOp, _dataTable.outArrayPtr);
        }
Exemplo n.º 5
0
        // Used by trig. Low quality because it narrows to Int32.
        internal static Vector256 <long> ConvertToInt64(Vector256 <double> vector)
        {
            if (Avx2.IsSupported)
            {
                return(Avx2.ConvertToVector256Int64(Avx.ConvertToVector128Int32WithTruncation(vector)));
            }

            return(SoftwareFallback(vector));
Exemplo n.º 6
0
        public void RunBasicScenario_Load()
        {
            var result = Avx.ConvertToVector128Int32WithTruncation(
                Avx.LoadVector256((Double *)(_dataTable.inArrayPtr))
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
        }
Exemplo n.º 7
0
        public void RunBasicScenario_UnsafeRead()
        {
            var result = Avx.ConvertToVector128Int32WithTruncation(
                Unsafe.Read <Vector256 <Double> >(_dataTable.inArrayPtr)
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
        }
Exemplo n.º 8
0
    public void ResizeSIMD2(FastBitmap rtnImage)
    {
        float scaleX = (float)this.width / rtnImage.width;
        float scaleY = (float)this.height / rtnImage.height;

        if (rtnImage.width % 4 == 0)
        {
            Parallel.For(0, rtnImage.height, (y) =>
            {
                var basePos = (uint *)(rtnImage._ptr + (rtnImage._stride * y));
                var rtnPos  = (uint *)(this._ptr + (this._stride * (int)(y * scaleY)));

                Vector128 <float> indexf = Vector128.Create(0.0f, 1, 2, 3);
                Vector128 <float> iterf  = Vector128.Create(4f, 4, 4, 4);
                Vector128 <float> scalef = Vector128.Create(scaleX, scaleX, scaleX, scaleX);
                for (int x = 0; x < rtnImage.width; x += 4)
                {
                    Vector128 <int> index = Avx.ConvertToVector128Int32WithTruncation(Avx.Multiply(indexf, scalef));
                    Avx.Store(basePos, Avx2.GatherVector128(rtnPos, index, 4));
                    indexf   = Avx.Add(indexf, iterf);
                    basePos += 4;
                }
            });
        }
        else
        {
            Parallel.For(0, height, (y) =>
            {
                var basePos = (uint *)(rtnImage._ptr + (rtnImage._stride * y));
                var rtnPos  = (uint *)(this._ptr + (this._stride * (int)(y * scaleY)));

                for (int x = 0; x < width; x += 4)
                {
                    *(uint *)(basePos + x) = *(uint *)(rtnPos + ((int)(x * scaleX)));
                }
            });
        }
    }
Exemplo n.º 9
0
    private static unsafe double[] BilinearInterpol_AVX(
        double[] x,
        double[] A,
        double minXA,
        double maxXA,
        double[] B,
        double minXB,
        double maxXB,
        double weightB)
    {
        double[] z = new double[outputVectorSize];

        fixed(double *pX = &x[0], pA = &A[0], pB = &B[0], pZ = &z[0])
        {
            Vector256 <double> vWeightB = Vector256.Create(weightB);
            Vector256 <double> vWeightA = Vector256.Create(1 - weightB);

            Vector256 <double> vMinXA = Vector256.Create(minXA);
            Vector256 <double> vMaxXA = Vector256.Create(maxXA);
            Vector256 <double> vMinXB = Vector256.Create(minXB);
            Vector256 <double> vMaxXB = Vector256.Create(maxXB);

            double             deltaA  = (maxXA - minXA) / (double)(A.Length - 1);
            double             deltaB  = (maxXB - minXB) / (double)(B.Length - 1);
            Vector256 <double> vDeltaA = Vector256.Create(deltaA);
            Vector256 <double> vDeltaB = Vector256.Create(deltaB);

            double             invDeltaA  = 1.0 / deltaA;
            double             invDeltaB  = 1.0 / deltaB;
            Vector256 <double> vInvDeltaA = Vector256.Create(invDeltaA);
            Vector256 <double> vInvDeltaB = Vector256.Create(invDeltaB);

            Vector128 <int> ALengthMinusOne = Vector128.Create(A.Length - 1);
            Vector128 <int> BLengthMinusOne = Vector128.Create(B.Length - 1);
            Vector128 <int> One             = Vector128.Create(1);

            for (var i = 0; i < x.Length; i += Vector256 <double> .Count)
            {
                Vector256 <double> currentX = Avx.LoadVector256(pX + i);

                // Determine the largest a, such that A[i] = f(xA) and xA <= x[i].
                // This involves casting from double to int; here we use a Vector conversion.
                Vector256 <double> aDouble = Avx.Multiply(Avx.Subtract(currentX, vMinXA), vInvDeltaA);
                Vector128 <int>    a       = Avx.ConvertToVector128Int32WithTruncation(aDouble);
                a = Sse41.Min(Sse41.Max(a, Vector128 <int> .Zero), ALengthMinusOne);
                Vector128 <int> aPlusOne = Sse41.Min(Sse2.Add(a, One), ALengthMinusOne);

                // Now, get the reference input, xA, for our index a.
                // This involves casting from  int to double.
                Vector256 <double> xA = Avx.Add(Avx.Multiply(Avx.ConvertToVector256Double(a), vDeltaA), vMinXA);

                // Now, compute the lambda for our A reference point.
                Vector256 <double> currentXNormA = Avx.Max(vMinXA, Avx.Min(currentX, vMaxXA));
                Vector256 <double> lambdaA       = Avx.Multiply(Avx.Subtract(currentXNormA, xA), vInvDeltaA);

                // Now, we need to load up our reference points using Vector Gather operations.
                Vector256 <double> AVector        = Avx2.GatherVector256(pA, a, 8);
                Vector256 <double> AVectorPlusOne = Avx2.GatherVector256(pA, aPlusOne, 8);

                // Now, do the all of the above for our B reference point.
                Vector256 <double> bDouble = Avx.Multiply(Avx.Subtract(currentX, vMinXB), vInvDeltaB);
                Vector128 <int>    b       = Avx.ConvertToVector128Int32WithTruncation(bDouble);
                b = Sse41.Min(Sse41.Max(b, Vector128 <int> .Zero), BLengthMinusOne);
                Vector128 <int> bPlusOne = Sse41.Min(Sse2.Add(b, One), BLengthMinusOne);

                Vector256 <double> xB            = Avx.Add(Avx.Multiply(Avx.ConvertToVector256Double(b), vDeltaB), vMinXB);
                Vector256 <double> currentXNormB = Avx.Max(vMinXB, Avx.Min(currentX, vMaxXB));
                Vector256 <double> lambdaB       = Avx.Multiply(Avx.Subtract(currentXNormB, xB), vInvDeltaB);

                Vector256 <double> BVector        = Avx2.GatherVector256(pB, b, 8);
                Vector256 <double> BVectorPlusOne = Avx2.GatherVector256(pB, bPlusOne, 8);

                Vector256 <double> newZ = Avx.Add(Avx.Multiply(vWeightA, Avx.Add(AVector, Avx.Multiply(lambdaA, Avx.Subtract(AVectorPlusOne, AVector)))),
                                                  Avx.Multiply(vWeightB, Avx.Add(BVector, Avx.Multiply(lambdaB, Avx.Subtract(BVectorPlusOne, BVector)))));
                Avx.Store(pZ + i, newZ);
            }
        }

        return(z);
    }