Ejemplo n.º 1
0
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            typeof(Avx).GetMethod(nameof(Avx.MaskStore), new Type[] { typeof(Double *), typeof(Vector256 <Double>), typeof(Vector256 <Double>) })
            .Invoke(null, new object[] {
                Pointer.Box(_dataTable.outArrayPtr, typeof(Double *)),
                Avx.LoadAlignedVector256((Double *)(_dataTable.inArray1Ptr)),
                Avx.LoadAlignedVector256((Double *)(_dataTable.inArray2Ptr))
            });

            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
        public void RunBasicScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));

            var result = Avx.Permute2x128(
                Avx.LoadAlignedVector256((Double *)(_dataTable.inArray1Ptr)),
                Avx.LoadAlignedVector256((Double *)(_dataTable.inArray2Ptr)),
                2
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
Ejemplo n.º 3
0
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            var result = typeof(Avx2).GetMethod(nameof(Avx2.ShiftLeftLogical), new Type[] { typeof(Vector256 <Int64>), typeof(byte) })
                         .Invoke(null, new object[] {
                Avx.LoadAlignedVector256((Int64 *)(_dataTable.inArrayPtr)),
                (byte)64
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector256 <Int64>)(result));
            ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
        }
Ejemplo n.º 4
0
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            var result = typeof(Avx2).GetMethod(nameof(Avx2.Subtract), new Type[] { typeof(Vector256 <UInt32>), typeof(Vector256 <UInt32>) })
                         .Invoke(null, new object[] {
                Avx.LoadAlignedVector256((UInt32 *)(_dataTable.inArray1Ptr)),
                Avx.LoadAlignedVector256((UInt32 *)(_dataTable.inArray2Ptr))
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector256 <UInt32>)(result));
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
Ejemplo n.º 5
0
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            var result = typeof(Avx).GetMethod(nameof(Avx.CompareGreaterThanOrEqual), new Type[] { typeof(Vector256 <Single>), typeof(Vector256 <Single>) })
                         .Invoke(null, new object[] {
                Avx.LoadAlignedVector256((Single *)(_dataTable.inArray1Ptr)),
                Avx.LoadAlignedVector256((Single *)(_dataTable.inArray2Ptr))
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector256 <Single>)(result));
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
Ejemplo n.º 6
0
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Int32 *), typeof(Vector256 <Int32>), typeof(byte) })
            .Invoke(null, new object[] {
                Pointer.Box(_dataTable.outArrayPtr, typeof(Int32 *)),
                Avx.LoadAlignedVector256((Int32 *)(_dataTable.inArrayPtr)),
                (byte)1
            });

            ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
        }
Ejemplo n.º 7
0
        public void RunBasicScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));

            var result = Fma.MultiplySubtractNegated(
                Avx.LoadAlignedVector256((Double *)(_dataTable.inArray1Ptr)),
                Avx.LoadAlignedVector256((Double *)(_dataTable.inArray2Ptr)),
                Avx.LoadAlignedVector256((Double *)(_dataTable.inArray3Ptr))
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.inArray3Ptr, _dataTable.outArrayPtr);
        }
Ejemplo n.º 8
0
        public void RunReflectionScenario_LoadAligned()
        {
            var result = typeof(Avx).GetMethods(BindingFlags.Public | BindingFlags.Static)
                         .FirstOrDefault(mi => mi.Name == nameof(Avx.ExtractVector128) && mi.IsGenericMethod)
                         .MakeGenericMethod(new[] { typeof(Single) })
                         .Invoke(null, new object[] {
                Avx.LoadAlignedVector256((Single *)(_dataTable.inArrayPtr)),
                (byte)1
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector128 <Single>)(result));
            ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
        }
Ejemplo n.º 9
0
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            var result = typeof(Avx).GetMethod(nameof(Avx.GetLowerHalf))
                         .MakeGenericMethod(new Type[] { typeof(UInt16) })
                         .Invoke(null, new object[] {
                Avx.LoadAlignedVector256((UInt16 *)(_dataTable.inArrayPtr))
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector128 <UInt16>)(result));
            ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
        }
Ejemplo n.º 10
0
        public void RunBasicScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));

            var result = Avx2.BlendVariable(
                Avx.LoadAlignedVector256((Int32 *)(_dataTable.inArray1Ptr)),
                Avx.LoadAlignedVector256((Int32 *)(_dataTable.inArray2Ptr)),
                Avx.LoadAlignedVector256((Int32 *)(_dataTable.inArray3Ptr))
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.inArray3Ptr, _dataTable.outArrayPtr);
        }
Ejemplo n.º 11
0
        public void RunBasicScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));

            var result = Avx.Insert(
                Avx.LoadAlignedVector256((Byte *)(_dataTable.inArrayPtr)),
                (byte)2,
                1
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
        }
Ejemplo n.º 12
0
        public void RunBasicScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));

            var result = AvxVnni.MultiplyWideningAndAdd(
                Avx.LoadAlignedVector256((Int32 *)(_dataTable.inArray0Ptr)),
                Avx.LoadAlignedVector256((Int16 *)(_dataTable.inArray1Ptr)),
                Avx.LoadAlignedVector256((Int16 *)(_dataTable.inArray2Ptr))
                );

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

            var result = typeof(AvxVnni).GetMethod(nameof(AvxVnni.MultiplyWideningAndAddSaturate), new Type[] { typeof(Vector256 <Int32>), typeof(Vector256 <Int16>), typeof(Vector256 <Int16>) })
                         .Invoke(null, new object[] {
                Avx.LoadAlignedVector256((Int32 *)(_dataTable.inArray0Ptr)),
                Avx.LoadAlignedVector256((Int16 *)(_dataTable.inArray1Ptr)),
                Avx.LoadAlignedVector256((Int16 *)(_dataTable.inArray2Ptr))
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector256 <Int32>)(result));
            ValidateResult(_dataTable.inArray0Ptr, _dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
Ejemplo n.º 14
0
        public void RunReflectionScenario_LoadAligned()
        {
            var method = typeof(Avx).GetMethod(nameof(Avx.TestZ), new Type[] { typeof(Vector256 <UInt16>), typeof(Vector256 <UInt16>) });

            if (method != null)
            {
                var result = method.Invoke(null, new object[] {
                    Avx.LoadAlignedVector256((UInt16 *)(_dataTable.inArray1Ptr)),
                    Avx.LoadAlignedVector256((UInt16 *)(_dataTable.inArray2Ptr))
                });

                ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
            }
        }
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            var result = typeof(Avx).GetMethod(nameof(Avx.Insert), new Type[] { typeof(Vector256 <UInt16>), typeof(UInt16), typeof(byte) })
                         .Invoke(null, new object[] {
                Avx.LoadAlignedVector256((UInt16 *)(_dataTable.inArrayPtr)),
                (ushort)2,
                (byte)27
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector256 <UInt16>)(result));
            ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
        }
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256 <Byte>), typeof(Vector128 <Byte>), typeof(byte) })
                         .Invoke(null, new object[] {
                Avx.LoadAlignedVector256((Byte *)(_dataTable.inArray1Ptr)),
                LoadAlignedVector128((Byte *)(_dataTable.inArray2Ptr)),
                (byte)1
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector256 <Byte>)(result));
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
Ejemplo n.º 17
0
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            var method = typeof(Avx).GetMethod(nameof(Avx.TestNotZAndNotC), new Type[] { typeof(Vector256 <SByte>), typeof(Vector256 <SByte>) });

            if (method != null)
            {
                var result = method.Invoke(null, new object[] {
                    Avx.LoadAlignedVector256((SByte *)(_dataTable.inArray1Ptr)),
                    Avx.LoadAlignedVector256((SByte *)(_dataTable.inArray2Ptr))
                });

                ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
            }
        }
Ejemplo n.º 18
0
        public unsafe byte Run()
        {
            var  buffer = _buffer;
            byte value  = 0;

            // begin
            var i = 0;

            if (Avx2.IsSupported) // assume is true
            {
                const int vectorSize = 256 / 8;

                var tmp = Avx.SetZeroVector256 <byte>();

                fixed(byte *pBuf = &buffer[0])
                {
                    var n = buffer.Length / vectorSize * vectorSize;

                    for (; i < n; i += vectorSize)
                    {
                        tmp = Avx2.Xor(tmp, Avx.LoadAlignedVector256(pBuf + i));
                    }
                }

                var tmpResult = stackalloc byte[vectorSize];
                Avx.Store(tmpResult, tmp);

                for (var j = 0; j < vectorSize; ++j)
                {
                    value ^= tmpResult[j];
                }
            }

            for (; i < buffer.Length; i++)
            {
                value ^= buffer[i];
            }
            // end

            return(value);
        }
Ejemplo n.º 19
0
        public void RunLclVarScenario_LoadAligned()
        {
            var firstOp = Avx.LoadAlignedVector256((Byte *)(_dataTable.inArrayPtr));

            Avx2.ExtractVector128((Byte *)_dataTable.outArrayPtr, firstOp, 1);
        }
        public float SumUsingAvxAlignedPipelined()
        {
            var   values = this.values;
            float sum    = 0;

            if (Avx.IsSupported)
            {
                unsafe
                {
                    fixed(float *valuesPtr = values)
                    {
                        // Determine how many elements we need to sum sequential to reach 256 bit alignment
                        const int ElementsPerByte = sizeof(float) / sizeof(byte);
                        var       alignmentOffset = (long)(uint)(-(int)valuesPtr / ElementsPerByte) & (Vector256 <float> .Count - 1);

                        // handle first values sequentially until we hit the 256bit alignment boundary
                        for (long i = 0; i < alignmentOffset; i++)
                        {
                            sum += *(valuesPtr + i);
                        }

                        var remainingLength = values.Length - alignmentOffset;

                        var vectorizableLength = values.Length - remainingLength % (long)Vector256 <float> .Count;

                        // handle batches of 4 vectors for pipelining benefits
                        var pipelineVectorizableLength = values.Length - remainingLength % (4 * (long)Vector256 <float> .Count);

                        var tempVector1 = Vector256 <float> .Zero;
                        var tempVector2 = Vector256 <float> .Zero;
                        var tempVector3 = Vector256 <float> .Zero;
                        var tempVector4 = Vector256 <float> .Zero;

                        for (long i = alignmentOffset; i < pipelineVectorizableLength; i += 4 * (long)Vector256 <float> .Count)
                        {
                            var valuesVector1 = Avx.LoadAlignedVector256(valuesPtr + i);
                            tempVector1 = Avx.Add(tempVector1, valuesVector1);
                            var valuesVector2 = Avx.LoadAlignedVector256(valuesPtr + i + Vector256 <float> .Count);
                            tempVector2 = Avx.Add(tempVector2, valuesVector2);
                            var valuesVector3 = Avx.LoadAlignedVector256(valuesPtr + i + 2 * Vector256 <float> .Count);
                            tempVector3 = Avx.Add(tempVector3, valuesVector3);
                            var valuesVector4 = Avx.LoadAlignedVector256(valuesPtr + i + 3 * Vector256 <float> .Count);
                            tempVector4 = Avx.Add(tempVector4, valuesVector4);
                        }

                        var tempVector = Avx.Add(Avx.Add(Avx.Add(tempVector1, tempVector2), tempVector3), tempVector4);

                        // handle remaining vectors
                        for (long i = pipelineVectorizableLength; i < vectorizableLength; i += Vector256 <float> .Count)
                        {
                            var valuesVector = Avx.LoadAlignedVector256(valuesPtr + i);
                            tempVector = Avx.Add(tempVector, valuesVector);
                        }

                        // sum the temporary vector
                        for (int iVector = 0; iVector < Vector256 <float> .Count; iVector++)
                        {
                            sum += tempVector.GetElement(iVector);
                        }

                        // handle remaining items
                        for (int i = (int)vectorizableLength; i < values.Length; i++)
                        {
                            sum += values[i];
                        }
                    }
                }
            }
            else
            {
                // non-AVX capable machines
                for (int i = 0; i < values.Length; i++)
                {
                    sum += values[i];
                }
            }

            return(sum);
        }