コード例 #1
0
ファイル: Divide.cs プロジェクト: vehar/coreclr
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.Divide);

            if (Sse2.IsSupported)
            {
                using (var doubleTable = TestTableSse2 <double> .Create(testsCount))
                {
                    for (int i = 0; i < testsCount; i++)
                    {
                        (Vector128 <double>, Vector128 <double>, Vector128 <double>)value = doubleTable[i];
                        var result = Sse2.Divide(value.Item1, value.Item2);
                        doubleTable.SetOutArray(result);
                    }

                    CheckMethod <double> checkDouble = (double x, double y, double z, ref double a) => (a = x / y) == z;

                    if (!doubleTable.CheckResult(checkDouble))
                    {
                        PrintError(doubleTable, methodUnderTestName, "(double x, double y, double z, ref double a) => (a = x / y) == z", checkDouble);
                        testResult = Fail;
                    }
                }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #2
0
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.ConvertToVector128Int32);

            if (Sse2.IsSupported)
            {
                using (var doubleTable = TestTableSse2 <double, int> .Create(testsCount, 0.5))
                    using (var floatTable = TestTableSse2 <float, int> .Create(testsCount))
                    {
                        for (int i = 0; i < testsCount; i++)
                        {
                            (Vector128 <double>, Vector128 <double>)value = doubleTable[i];
                            Vector128 <int> result = Sse2.ConvertToVector128Int32(value.Item1);
                            doubleTable.SetOutArrayU(result);
                        }

                        for (int i = 0; i < testsCount; i++)
                        {
                            (Vector128 <float>, Vector128 <float>)value = floatTable[i];
                            Vector128 <int> result = Sse2.ConvertToVector128Int32(value.Item1);
                            floatTable.SetOutArrayU(result);
                        }

                        CheckMethodFour <double, int> checkDouble = (double x1, double x2, int z1, int z2, ref int a1, ref int a2) =>
                        {
                            a1 = (int)Math.Round(x1, 0, MidpointRounding.ToEven);
                            a2 = (int)Math.Round(x2, 0, MidpointRounding.ToEven);
                            return(a1 == z1 && a2 == z2);
                        };

                        if (!doubleTable.CheckConvertDoubleToVector128Int32(checkDouble))
                        {
                            PrintError(doubleTable, methodUnderTestName, "(double x, double y, int z, ref int a) => (a = (int)x) == z", checkDouble);
                            testResult = Fail;
                        }

                        CheckMethodTwo <float, int> checkFloat = (float x, float y, int z, ref int a) => (a = (int)MathF.Round(x, 0, MidpointRounding.ToEven)) == z;

                        if (!floatTable.CheckResult(checkFloat))
                        {
                            PrintError(floatTable, methodUnderTestName, "(float x, float y, int z, ref int a) =>  (a = (int)x) == z", checkFloat);
                            testResult = Fail;
                        }
                    }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #3
0
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.ConvertToVector128Single);

            if (Sse2.IsSupported)
            {
                using (var doubleTable = TestTableSse2 <double, float> .Create(testsCount, 0.5))
                    using (var intTable = TestTableSse2 <int, float> .Create(testsCount))
                    {
                        for (int i = 0; i < testsCount; i++)
                        {
                            (Vector128 <double>, Vector128 <double>)value = doubleTable[i];
                            Vector128 <float> result = Sse2.ConvertToVector128Single(value.Item1);
                            doubleTable.SetOutArrayU(result);
                        }

                        for (int i = 0; i < testsCount; i++)
                        {
                            (Vector128 <int>, Vector128 <int>)value = intTable[i];
                            Vector128 <float> result = Sse2.ConvertToVector128Single(value.Item1);
                            intTable.SetOutArrayU(result);
                        }

                        CheckMethodFour <double, float> checkDouble = (double x1, double x2, float z1, float z2, ref float a1, ref float a2) =>
                        {
                            return((a1 = (float)x1) == z1 && (a2 = (float)x2) == z2);
                        };

                        if (!doubleTable.CheckConvertDoubleToVector128Single(checkDouble))
                        {
                            PrintError(doubleTable, methodUnderTestName, "(double x1, double x2, float z1, float z2, ref float a1, ref float a2) => (a = (float)x) == z", checkDouble);
                            testResult = Fail;
                        }

                        CheckMethodFour <int, float> checkInt32 = (int x1, int x2, float z1, float z2, ref float a1, ref float a2) =>
                        {
                            return((a1 = (float)x1) == z1 && (a2 = (float)x2) == z2);
                        };

                        if (!intTable.CheckConvertInt32ToVector128Single(checkInt32))
                        {
                            PrintError(intTable, methodUnderTestName, "(int x1, int x2, float z1, float z2, ref float a1, ref float a2) => (a = (float)x) == z", checkInt32);
                            testResult = Fail;
                        }
                    }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }
            return(testResult);
        }
コード例 #4
0
ファイル: Multiply.cs プロジェクト: vehar/coreclr
        internal static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.Multiply);

            if (Sse2.IsSupported)
            {
                using (var doubleTable = TestTableSse2 <double> .Create(testsCount))
                    using (var uintTable = TestTableSse2 <uint, ulong> .Create(testsCount, 2.0))
                    {
                        for (int i = 0; i < testsCount; i++)
                        {
                            (Vector128 <double>, Vector128 <double>, Vector128 <double>)value = doubleTable[i];
                            Vector128 <double> result = Sse2.Multiply(value.Item1, value.Item2);
                            doubleTable.SetOutArray(result);
                        }

                        for (int i = 0; i < testsCount; i++)
                        {
                            (Vector128 <uint>, Vector128 <uint>)value = uintTable[i];
                            Vector128 <ulong> result = Sse2.Multiply(value.Item1, value.Item2);
                            uintTable.SetOutArrayU(result);
                        }

                        CheckMethod <double> checkDouble = (double x, double y, double z, ref double a) => (a = x * y) == z;

                        if (!doubleTable.CheckResult(checkDouble))
                        {
                            PrintError(doubleTable, methodUnderTestName, "(double x, double y, double z, ref double a) => (a = x * y) == z", checkDouble);
                            testResult = Fail;
                        }

                        CheckMethodFive <uint, ulong> checkUInt32 = (uint x1, uint x2, uint y1, uint y2, ulong z1, ulong z2, ref ulong a1, ref ulong a2) =>
                        {
                            a1 = (ulong)x1 * y1;
                            a2 = (ulong)x2 * y2;
                            return(a1 == z1 && a2 == z2);
                        };

                        if (!uintTable.CheckMultiplyUInt32ToUInt64(checkUInt32))
                        {
                            PrintError(uintTable, methodUnderTestName, "(uint x1, uint x2, uint y1, uint y2, ulong z1, ulong z2, ref ulong a1, ref ulong a2) => (a1 = (ulong)x1 * y1) == z1 && (a2 = (ulong)x2 * y2) == z2", checkUInt32);
                            testResult = Fail;
                        }
                    }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }
            return(testResult);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        internal static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.MultiplyHigh);

            if (Sse2.IsSupported)
            {
                using (var shortTable = TestTableSse2 <short> .Create(testsCount))
                    using (var ushortTable = TestTableSse2 <ushort> .Create(testsCount))
                    {
                        for (int i = 0; i < testsCount; i++)
                        {
                            (Vector128 <short>, Vector128 <short>, Vector128 <short>)value = shortTable[i];
                            Vector128 <short> result = Sse2.MultiplyHigh(value.Item1, value.Item2);
                            shortTable.SetOutArray(result);
                        }

                        for (int i = 0; i < testsCount; i++)
                        {
                            (Vector128 <ushort>, Vector128 <ushort>, Vector128 <ushort>)value = ushortTable[i];
                            Vector128 <ushort> result = Sse2.MultiplyHigh(value.Item1, value.Item2);
                            ushortTable.SetOutArray(result);
                        }

                        CheckMethod <short> checkInt16 = (short x, short y, short z, ref short a) => (a = (short)((x * y) >> 16)) == z;

                        if (!shortTable.CheckResult(checkInt16))
                        {
                            PrintError(shortTable, methodUnderTestName, "(short x, short y, short z, ref short a) => (a = (short)((x * y) >> 16)) == z", checkInt16);
                            testResult = Fail;
                        }

                        CheckMethod <ushort> checkUInt16 = (ushort x, ushort y, ushort z, ref ushort a) => (a = (ushort)((x * y) >> 16)) == z;

                        if (!ushortTable.CheckResult(checkUInt16))
                        {
                            PrintError(ushortTable, methodUnderTestName, "(ushort x, ushort y, ushort z, ref ushort a) => (a = (ushort)((x * y) >> 16)) == z", checkUInt16);
                            testResult = Fail;
                        }
                    }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #7
0
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.SumAbsoluteDifferences);

            if (Sse2.IsSupported)
            {
                using (var byteTable = TestTableSse2 <byte, long> .Create(testsCount, 8.0))
                {
                    for (int i = 0; i < testsCount; i++)
                    {
                        (Vector128 <byte>, Vector128 <byte>)value = byteTable[i];
                        var result = Sse2.SumAbsoluteDifferences(value.Item1, value.Item2);
                        byteTable.SetOutArrayU(result);
                    }

                    CheckMethodEightOne <byte, long> checkByte = (Span <byte> x, Span <byte> y, long z, ref long a) =>
                    {
                        short[] tmpArray = new short[8];
                        for (int i = 0; i < 8; i++)
                        {
                            tmpArray[i] = (short)Math.Abs(x[i] - y[i]);
                        }

                        foreach (short s in tmpArray)
                        {
                            a += s;
                        }
                        return(a == z);
                    };

                    if (!byteTable.CheckResult(checkByte))
                    {
                        PrintError(byteTable, methodUnderTestName, "(Span<byte> x, Span<byte> y, long z, ref long a) => SumAbsoluteDifferences", checkByte);
                        testResult = Fail;
                    }
                }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #8
0
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.CompareUnordered);

            if (Sse2.IsSupported)
            {
                using (var doubleTable = TestTableSse2 <double> .Create(testsCount))
                {
                    for (int i = 0; i < testsCount; i++)
                    {
                        (Vector128 <double>, Vector128 <double>, Vector128 <double>)value = doubleTable[i];
                        var result = Sse2.CompareUnordered(value.Item1, value.Item2);
                        doubleTable.SetOutArray(result);
                    }

                    CheckMethod <double> checkDouble = (double x, double y, double z, ref double a) =>
                    {
                        if (double.IsNaN(x) || double.IsNaN(y))
                        {
                            a = BitConverter.Int64BitsToDouble(-1);
                        }
                        else
                        {
                            a = 0;
                        }
                        return(BitConverter.DoubleToInt64Bits(a) == BitConverter.DoubleToInt64Bits(z));
                    };

                    if (!doubleTable.CheckResult(checkDouble))
                    {
                        PrintError(doubleTable, methodUnderTestName, "(x, y, z, ref a) => (a = (double.IsNaN(x) || double.IsNaN(y)) ? double.NaN : 0) == z", checkDouble);
                        testResult = Fail;
                    }
                }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #9
0
ファイル: MultiplyLow.cs プロジェクト: vehar/coreclr
        internal static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.MultiplyLow);

            if (Sse2.IsSupported)
            {
                using (var shortTable = TestTableSse2 <short> .Create(testsCount))
                {
                    for (int i = 0; i < testsCount; i++)
                    {
                        (Vector128 <short>, Vector128 <short>, Vector128 <short>)value = shortTable[i];
                        Vector128 <short> result = Sse2.MultiplyLow(value.Item1, value.Item2);
                        shortTable.SetOutArray(result);
                    }

                    CheckMethod <short> checkInt16 = (short x, short y, short z, ref short a) =>
                    {
                        var tmp = ((int)x * y) * 0x0000ffff;
                        a = unchecked ((short)tmp);
                        return(-a == z);
                    };

                    if (!shortTable.CheckResult(checkInt16))
                    {
                        PrintError(shortTable, methodUnderTestName, "(short x, short y, int z, ref int a) => (a = (int)x * y >> 16 | sign) == z", checkInt16);
                        testResult = Fail;
                    }
                }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #10
0
        internal static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.MultiplyHorizontalAdd);

            if (Sse2.IsSupported)
            {
                Console.WriteLine($"Test started");

                using (var shortTable = TestTableSse2 <short, int> .Create(testsCount))
                {
                    for (int i = 0; i < testsCount; i++)
                    {
                        (Vector128 <short>, Vector128 <short>)value = shortTable[i];
                        var result = Sse2.MultiplyHorizontalAdd(value.Item1, value.Item2);
                        shortTable.SetOutArrayU(result);
                    }

                    CheckMethodThree <short, int> checkInt16 = (short x1, short x2, short y1, short y2, int z, ref int a) =>
                                                               (a = (int)x1 * y1 + (int)x2 * y2) == z;

                    if (!shortTable.CheckMultiplyHorizontalAdd(checkInt16))
                    {
                        PrintError(shortTable, methodUnderTestName, "(short x1, short x2, short y1, short y2, int z, ref int a) => (a = (int)x1 * y1 + (int)x2 * y2) == z", checkInt16);
                        testResult = Fail;
                    }
                }

                Console.WriteLine($"Test finished with result: {testResult}");
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #11
0
ファイル: SubtractSaturate.cs プロジェクト: yizhang82/coreclr
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.SubtractSaturate);

            if (Sse2.IsSupported)
            {
                using (var shortTable = TestTableSse2 <short> .Create(testsCount))
                    using (var ushortTable = TestTableSse2 <ushort> .Create(testsCount))
                        using (var sbyteTable = TestTableSse2 <sbyte> .Create(testsCount))
                            using (var byteTable = TestTableSse2 <byte> .Create(testsCount))
                            {
                                for (int i = 0; i < testsCount; i++)
                                {
                                    (Vector128 <short>, Vector128 <short>, Vector128 <short>)value = shortTable[i];
                                    var result = Sse2.SubtractSaturate(value.Item1, value.Item2);
                                    shortTable.SetOutArray(result);
                                }

                                for (int i = 0; i < testsCount; i++)
                                {
                                    (Vector128 <ushort>, Vector128 <ushort>, Vector128 <ushort>)value = ushortTable[i];
                                    var result = Sse2.SubtractSaturate(value.Item1, value.Item2);
                                    ushortTable.SetOutArray(result);
                                }

                                for (int i = 0; i < testsCount; i++)
                                {
                                    (Vector128 <sbyte>, Vector128 <sbyte>, Vector128 <sbyte>)value = sbyteTable[i];
                                    var result = Sse2.SubtractSaturate(value.Item1, value.Item2);
                                    sbyteTable.SetOutArray(result);
                                }

                                for (int i = 0; i < testsCount; i++)
                                {
                                    (Vector128 <byte>, Vector128 <byte>, Vector128 <byte>)value = byteTable[i];
                                    var result = Sse2.SubtractSaturate(value.Item1, value.Item2);
                                    byteTable.SetOutArray(result);
                                }

                                CheckMethod <short> checkInt16 = (short x, short y, short z, ref short a) =>
                                {
                                    int value = (int)x - y;
                                    value = Math.Max(value, short.MinValue);
                                    value = Math.Min(value, short.MaxValue);
                                    a     = (short)value;
                                    return(a == z);
                                };

                                if (!shortTable.CheckResult(checkInt16))
                                {
                                    PrintError(shortTable, methodUnderTestName, "(short x, short y, short z, ref short a) => (a = (short)(x - y)) == z", checkInt16);
                                    testResult = Fail;
                                }

                                CheckMethod <ushort> checkUInt16 = (ushort x, ushort y, ushort z, ref ushort a) =>
                                {
                                    int value = (int)x - y;
                                    value = Math.Max(value, 0);
                                    value = Math.Min(value, ushort.MaxValue);
                                    a     = (ushort)value;
                                    return(a == z);
                                };

                                if (!ushortTable.CheckResult(checkUInt16))
                                {
                                    PrintError(ushortTable, methodUnderTestName, "(ushort x, ushort y, ushort z, ref ushort a) => (a = (ushort)(x & y)) == z", checkUInt16);
                                    testResult = Fail;
                                }

                                CheckMethod <sbyte> checkSByte = (sbyte x, sbyte y, sbyte z, ref sbyte a) =>
                                {
                                    int value = (int)x - y;
                                    value = Math.Max(value, sbyte.MinValue);
                                    value = Math.Min(value, sbyte.MaxValue);
                                    a     = (sbyte)value;
                                    return(a == z);
                                };

                                if (!sbyteTable.CheckResult(checkSByte))
                                {
                                    PrintError(sbyteTable, methodUnderTestName, "(sbyte x, sbyte y, sbyte z, ref sbyte a) => (a = (sbyte)(x & y)) == z", checkSByte);
                                    testResult = Fail;
                                }

                                CheckMethod <byte> checkByte = (byte x, byte y, byte z, ref byte a) =>
                                {
                                    int value = (int)x - y;
                                    value = Math.Max(value, 0);
                                    value = Math.Min(value, byte.MaxValue);
                                    a     = (byte)value;
                                    return(a == z);
                                };

                                if (!byteTable.CheckResult(checkByte))
                                {
                                    PrintError(byteTable, methodUnderTestName, "(byte x, byte y, byte z, ref byte a) => (a = (byte)(x & y)) == z", checkByte);
                                    testResult = Fail;
                                }
                            }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #12
0
ファイル: Subtract.cs プロジェクト: vehar/coreclr
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.Subtract);

            if (Sse2.IsSupported)
            {
                using (var doubleTable = TestTableSse2 <double> .Create(testsCount))
                    using (var longTable = TestTableSse2 <long> .Create(testsCount))
                        using (var ulongTable = TestTableSse2 <ulong> .Create(testsCount))
                            using (var intTable = TestTableSse2 <int> .Create(testsCount))
                                using (var uintTable = TestTableSse2 <uint> .Create(testsCount))
                                    using (var shortTable = TestTableSse2 <short> .Create(testsCount))
                                        using (var ushortTable = TestTableSse2 <ushort> .Create(testsCount))
                                            using (var sbyteTable = TestTableSse2 <sbyte> .Create(testsCount))
                                                using (var byteTable = TestTableSse2 <byte> .Create(testsCount))
                                                {
                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <double>, Vector128 <double>, Vector128 <double>)value = doubleTable[i];
                                                        var result = Sse2.Subtract(value.Item1, value.Item2);
                                                        doubleTable.SetOutArray(result);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <long>, Vector128 <long>, Vector128 <long>)value = longTable[i];
                                                        var result = Sse2.Subtract(value.Item1, value.Item2);
                                                        longTable.SetOutArray(result);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <ulong>, Vector128 <ulong>, Vector128 <ulong>)value = ulongTable[i];
                                                        var result = Sse2.Subtract(value.Item1, value.Item2);
                                                        ulongTable.SetOutArray(result);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <int>, Vector128 <int>, Vector128 <int>)value = intTable[i];
                                                        var result = Sse2.Subtract(value.Item1, value.Item2);
                                                        intTable.SetOutArray(result);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <uint>, Vector128 <uint>, Vector128 <uint>)value = uintTable[i];
                                                        var result = Sse2.Subtract(value.Item1, value.Item2);
                                                        uintTable.SetOutArray(result);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <short>, Vector128 <short>, Vector128 <short>)value = shortTable[i];
                                                        var result = Sse2.Subtract(value.Item1, value.Item2);
                                                        shortTable.SetOutArray(result);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <ushort>, Vector128 <ushort>, Vector128 <ushort>)value = ushortTable[i];
                                                        var result = Sse2.Subtract(value.Item1, value.Item2);
                                                        ushortTable.SetOutArray(result);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <sbyte>, Vector128 <sbyte>, Vector128 <sbyte>)value = sbyteTable[i];
                                                        var result = Sse2.Subtract(value.Item1, value.Item2);
                                                        sbyteTable.SetOutArray(result);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <byte>, Vector128 <byte>, Vector128 <byte>)value = byteTable[i];
                                                        var result = Sse2.Subtract(value.Item1, value.Item2);
                                                        byteTable.SetOutArray(result);
                                                    }

                                                    CheckMethod <double> checkDouble = (double x, double y, double z, ref double a) => (a = x - y) == z;

                                                    if (!doubleTable.CheckResult(checkDouble))
                                                    {
                                                        PrintError(doubleTable, methodUnderTestName, "(double x, double y, double z, ref double a) => (a = x - y) == z", checkDouble);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethod <long> checkLong = (long x, long y, long z, ref long a) => (a = x - y) == z;

                                                    if (!longTable.CheckResult(checkLong))
                                                    {
                                                        PrintError(longTable, methodUnderTestName, "(long x, long y, long z, ref long a) => (a = x - y) == z", checkLong);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethod <ulong> checkUlong = (ulong x, ulong y, ulong z, ref ulong a) => (a = x - y) == z;

                                                    if (!longTable.CheckResult(checkLong))
                                                    {
                                                        PrintError(ulongTable, methodUnderTestName, "(ulong x, ulong y, ulong z, ref ulong a) => (a = x - y) == z", checkUlong);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethod <int> checkInt32 = (int x, int y, int z, ref int a) => (a = x - y) == z;

                                                    if (!intTable.CheckResult(checkInt32))
                                                    {
                                                        PrintError(intTable, methodUnderTestName, "(int x, int y, int z, ref int a) => (a = x - y) == z", checkInt32);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethod <uint> checkUInt32 = (uint x, uint y, uint z, ref uint a) => (a = x - y) == z;

                                                    if (!uintTable.CheckResult(checkUInt32))
                                                    {
                                                        PrintError(uintTable, methodUnderTestName, "(uint x, uint y, uint z, ref uint a) => (a = x - y) == z", checkUInt32);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethod <short> checkInt16 = (short x, short y, short z, ref short a) => (a = (short)(x - y)) == z;

                                                    if (!shortTable.CheckResult(checkInt16))
                                                    {
                                                        PrintError(shortTable, methodUnderTestName, "(short x, short y, short z, ref short a) => (a = (short)(x - y)) == z", checkInt16);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethod <ushort> checkUInt16 = (ushort x, ushort y, ushort z, ref ushort a) => (a = (ushort)(x - y)) == z;

                                                    if (!ushortTable.CheckResult(checkUInt16))
                                                    {
                                                        PrintError(ushortTable, methodUnderTestName, "(ushort x, ushort y, ushort z, ref ushort a) => (a = (ushort)(x - y)) == z", checkUInt16);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethod <sbyte> checkSByte = (sbyte x, sbyte y, sbyte z, ref sbyte a) => (a = (sbyte)(x - y)) == z;

                                                    if (!sbyteTable.CheckResult(checkSByte))
                                                    {
                                                        PrintError(sbyteTable, methodUnderTestName, "(sbyte x, sbyte y, sbyte z, ref sbyte a) => (a = (sbyte)(x - y)) == z", checkSByte);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethod <byte> checkByte = (byte x, byte y, byte z, ref byte a) => (a = (byte)(x - y)) == z;

                                                    if (!byteTable.CheckResult(checkByte))
                                                    {
                                                        PrintError(byteTable, methodUnderTestName, "(byte x, byte y, byte z, ref byte a) => (a = (byte)(x - y)) == z", checkByte);
                                                        testResult = Fail;
                                                    }
                                                }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #13
0
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.Min);

            if (Sse2.IsSupported)
            {
                using (var doubleTable = TestTableSse2 <double> .Create(testsCount))
                    using (var shortTable = TestTableSse2 <short> .Create(testsCount))
                        using (var byteTable = TestTableSse2 <byte> .Create(testsCount))
                        {
                            for (int i = 0; i < testsCount; i++)
                            {
                                (Vector128 <double>, Vector128 <double>, Vector128 <double>)value = doubleTable[i];
                                var result = Sse2.Min(value.Item1, value.Item2);
                                doubleTable.SetOutArray(result);
                            }

                            for (int i = 0; i < testsCount; i++)
                            {
                                (Vector128 <short>, Vector128 <short>, Vector128 <short>)value = shortTable[i];
                                var result = Sse2.Min(value.Item1, value.Item2);
                                shortTable.SetOutArray(result);
                            }

                            for (int i = 0; i < testsCount; i++)
                            {
                                (Vector128 <byte>, Vector128 <byte>, Vector128 <byte>)value = byteTable[i];
                                var result = Sse2.Min(value.Item1, value.Item2);
                                byteTable.SetOutArray(result);
                            }

                            CheckMethod <double> checkDouble = (double x, double y, double z, ref double a) => (a = x > y ? y : x) == z;

                            if (!doubleTable.CheckResult(checkDouble))
                            {
                                PrintError(doubleTable, methodUnderTestName, "(double x, double y, double z, ref double a) => (a = BitwiseOr(x, y)) == z", checkDouble);
                                testResult = Fail;
                            }

                            CheckMethod <short> checkInt16 = (short x, short y, short z, ref short a) => (a = x > y ? y : x) == z;

                            if (!shortTable.CheckResult(checkInt16))
                            {
                                PrintError(shortTable, methodUnderTestName, "(short x, short y, short z, ref short a) => (a = (short)(x | y)) == z", checkInt16);
                                testResult = Fail;
                            }

                            CheckMethod <byte> checkByte = (byte x, byte y, byte z, ref byte a) => (a = x > y ? y : x) == z;

                            if (!byteTable.CheckResult(checkByte))
                            {
                                PrintError(byteTable, methodUnderTestName, "(byte x, byte y, byte z, ref byte a) => (a = (byte)(x | y)) == z", checkByte);
                                testResult = Fail;
                            }
                        }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #14
0
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.SetVector128);

            if (Sse2.IsSupported)
            {
                using (var doubleTable = TestTableSse2 <double> .Create(testsCount))
                    using (var longTable = TestTableSse2 <long> .Create(testsCount))
                        using (var ulongTable = TestTableSse2 <ulong> .Create(testsCount))
                            using (var intTable = TestTableSse2 <int> .Create(testsCount))
                                using (var uintTable = TestTableSse2 <uint> .Create(testsCount))
                                    using (var shortTable = TestTableSse2 <short> .Create(testsCount))
                                        using (var ushortTable = TestTableSse2 <ushort> .Create(testsCount))
                                            using (var sbyteTable = TestTableSse2 <sbyte> .Create(testsCount))
                                                using (var byteTable = TestTableSse2 <byte> .Create(testsCount))
                                                {
                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        Span <double>      value  = doubleTable.GetAssignmentData(i).Span;
                                                        Vector128 <double> result = Sse2.SetVector128(value[1], value[0]);
                                                        doubleTable.SetOutArray(result, i);
                                                    }

                                                    if (Environment.Is64BitProcess)
                                                    {
                                                        for (int i = 0; i < testsCount; i++)
                                                        {
                                                            Span <long>      value  = longTable.GetAssignmentData(i).Span;
                                                            Vector128 <long> result = Sse2.SetVector128(value[1], value[0]);
                                                            longTable.SetOutArray(result, i);
                                                        }

                                                        for (int i = 0; i < testsCount; i++)
                                                        {
                                                            Span <ulong>      value  = ulongTable.GetAssignmentData(i).Span;
                                                            Vector128 <ulong> result = Sse2.SetVector128(value[1], value[0]);
                                                            ulongTable.SetOutArray(result, i);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        try
                                                        {
                                                            for (int i = 0; i < testsCount; i++)
                                                            {
                                                                Span <long>      value  = longTable.GetAssignmentData(i).Span;
                                                                Vector128 <long> result = Sse2.SetVector128(value[1], value[0]);
                                                                longTable.SetOutArray(result, i);
                                                            }
                                                            testResult = Fail;
                                                            Console.WriteLine($"{nameof(Sse2)}.{nameof(Sse2.SetVector128)} failed on long: expected PlatformNotSupportedException exception.");
                                                        }
                                                        catch (PlatformNotSupportedException)
                                                        {
                                                            // We expect PlatformNotSupportedException
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            testResult = Fail;
                                                            Console.WriteLine($"{nameof(Sse2)}.{nameof(Sse2.SetVector128)}-{ex} failed on long: expected PlatformNotSupportedException exception.");
                                                        }

                                                        try
                                                        {
                                                            for (int i = 0; i < testsCount; i++)
                                                            {
                                                                Span <ulong>      value  = ulongTable.GetAssignmentData(i).Span;
                                                                Vector128 <ulong> result = Sse2.SetVector128(value[1], value[0]);
                                                                ulongTable.SetOutArray(result, i);
                                                            }
                                                            testResult = Fail;
                                                            Console.WriteLine($"{nameof(Sse2)}.{nameof(Sse2.SetVector128)} failed on ulong: expected PlatformNotSupportedException exception.");
                                                        }
                                                        catch (PlatformNotSupportedException)
                                                        {
                                                            // We expect PlatformNotSupportedException
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            testResult = Fail;
                                                            Console.WriteLine($"{nameof(Sse2)}.{nameof(Sse2.SetVector128)}-{ex} failed on ulong: expected PlatformNotSupportedException exception.");
                                                        }
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        Span <int>      value  = intTable.GetAssignmentData(i).Span;
                                                        Vector128 <int> result = Sse2.SetVector128(value[3], value[2], value[1], value[0]);
                                                        intTable.SetOutArray(result, i);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        Span <uint>      value  = uintTable.GetAssignmentData(i).Span;
                                                        Vector128 <uint> result = Sse2.SetVector128(value[3], value[2], value[1], value[0]);
                                                        uintTable.SetOutArray(result, i);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        Span <short>      value  = shortTable.GetAssignmentData(i).Span;
                                                        Vector128 <short> result = Sse2.SetVector128(value[7], value[6], value[5], value[4], value[3], value[2], value[1], value[0]);
                                                        shortTable.SetOutArray(result, i);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        Span <ushort>      value  = ushortTable.GetAssignmentData(i).Span;
                                                        Vector128 <ushort> result = Sse2.SetVector128(value[7], value[6], value[5], value[4], value[3], value[2], value[1], value[0]);
                                                        ushortTable.SetOutArray(result, i);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        Span <sbyte>      value  = sbyteTable.GetAssignmentData(i).Span;
                                                        Vector128 <sbyte> result = Sse2.SetVector128(value[15], value[14], value[13], value[12], value[11], value[10], value[9],
                                                                                                     value[8], value[7], value[6], value[5], value[4], value[3], value[2], value[1], value[0]);
                                                        sbyteTable.SetOutArray(result, i);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        Span <byte>      value  = byteTable.GetAssignmentData(i).Span;
                                                        Vector128 <byte> result = Sse2.SetVector128(value[15], value[14], value[13], value[12], value[11], value[10], value[9],
                                                                                                    value[8], value[7], value[6], value[5], value[4], value[3], value[2], value[1], value[0]);
                                                        byteTable.SetOutArray(result, i);
                                                    }

                                                    CheckMethodSpan <double> checkDouble = (Span <double> x, Span <double> y, Span <double> z, Span <double> a) =>
                                                    {
                                                        bool result = true;
                                                        for (int i = 0; i < x.Length; i++)
                                                        {
                                                            if (BitConverter.DoubleToInt64Bits(z[i]) != BitConverter.DoubleToInt64Bits(x[i]))
                                                            {
                                                                result = false;
                                                            }
                                                        }
                                                        return(result);
                                                    };

                                                    if (!doubleTable.CheckResult(checkDouble))
                                                    {
                                                        PrintError(doubleTable, methodUnderTestName, "(double x, double y, double z, ref double a) => (a = BitwiseXor(x, y)) == z", checkDouble);
                                                        testResult = Fail;
                                                    }

                                                    if (Environment.Is64BitProcess)
                                                    {
                                                        CheckMethodSpan <long> checkLong = (Span <long> x, Span <long> y, Span <long> z, Span <long> a) =>
                                                        {
                                                            bool result = true;
                                                            for (int i = 0; i < x.Length; i++)
                                                            {
                                                                if (x[i] != z[i])
                                                                {
                                                                    result = false;
                                                                }
                                                            }
                                                            return(result);
                                                        };

                                                        if (!longTable.CheckResult(checkLong))
                                                        {
                                                            PrintError(longTable, methodUnderTestName, "(long x, long y, long z, ref long a) => (a = x ^ y) == z", checkLong);
                                                            testResult = Fail;
                                                        }

                                                        CheckMethodSpan <ulong> checkUlong = (Span <ulong> x, Span <ulong> y, Span <ulong> z, Span <ulong> a) =>
                                                        {
                                                            bool result = true;
                                                            for (int i = 0; i < x.Length; i++)
                                                            {
                                                                if (x[i] != z[i])
                                                                {
                                                                    result = false;
                                                                }
                                                            }
                                                            return(result);
                                                        };

                                                        if (!longTable.CheckResult(checkLong))
                                                        {
                                                            PrintError(ulongTable, methodUnderTestName, "(ulong x, ulong y, ulong z, ref ulong a) => (a = x ^ y) == z", checkUlong);
                                                            testResult = Fail;
                                                        }
                                                    }

                                                    CheckMethodSpan <int> checkInt32 = (Span <int> x, Span <int> y, Span <int> z, Span <int> a) =>
                                                    {
                                                        bool result = true;
                                                        for (int i = 0; i < x.Length; i++)
                                                        {
                                                            if (x[i] != z[i])
                                                            {
                                                                result = false;
                                                            }
                                                        }
                                                        return(result);
                                                    };

                                                    if (!intTable.CheckResult(checkInt32))
                                                    {
                                                        PrintError(intTable, methodUnderTestName, "(int x, int y, int z, ref int a) => (a = x ^ y) == z", checkInt32);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodSpan <uint> checkUInt32 = (Span <uint> x, Span <uint> y, Span <uint> z, Span <uint> a) =>
                                                    {
                                                        bool result = true;
                                                        for (int i = 0; i < x.Length; i++)
                                                        {
                                                            if (x[i] != z[i])
                                                            {
                                                                result = false;
                                                            }
                                                        }
                                                        return(result);
                                                    };

                                                    if (!uintTable.CheckResult(checkUInt32))
                                                    {
                                                        PrintError(uintTable, methodUnderTestName, "(uint x, uint y, uint z, ref uint a) => (a = x ^ y) == z", checkUInt32);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodSpan <short> checkInt16 = (Span <short> x, Span <short> y, Span <short> z, Span <short> a) =>
                                                    {
                                                        bool result = true;
                                                        for (int i = 0; i < x.Length; i++)
                                                        {
                                                            if (x[i] != z[i])
                                                            {
                                                                result = false;
                                                            }
                                                        }
                                                        return(result);
                                                    };

                                                    if (!shortTable.CheckResult(checkInt16))
                                                    {
                                                        PrintError(shortTable, methodUnderTestName, "(short x, short y, short z, ref short a) => (a = (short)(x ^ y)) == z", checkInt16);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodSpan <ushort> checkUInt16 = (Span <ushort> x, Span <ushort> y, Span <ushort> z, Span <ushort> a) =>
                                                    {
                                                        bool result = true;
                                                        for (int i = 0; i < x.Length; i++)
                                                        {
                                                            if (x[i] != z[i])
                                                            {
                                                                result = false;
                                                            }
                                                        }
                                                        return(result);
                                                    };

                                                    if (!ushortTable.CheckResult(checkUInt16))
                                                    {
                                                        PrintError(ushortTable, methodUnderTestName, "(ushort x, ushort y, ushort z, ref ushort a) => (a = (ushort)(x ^ y)) == z", checkUInt16);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodSpan <sbyte> checkSByte = (Span <sbyte> x, Span <sbyte> y, Span <sbyte> z, Span <sbyte> a) =>
                                                    {
                                                        bool result = true;
                                                        for (int i = 0; i < x.Length; i++)
                                                        {
                                                            if (x[i] != z[i])
                                                            {
                                                                result = false;
                                                            }
                                                        }
                                                        return(result);
                                                    };

                                                    if (!sbyteTable.CheckResult(checkSByte))
                                                    {
                                                        PrintError(sbyteTable, methodUnderTestName, "(sbyte x, sbyte y, sbyte z, ref sbyte a) => (a = (sbyte)(x ^ y)) == z", checkSByte);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodSpan <byte> checkByte = (Span <byte> x, Span <byte> y, Span <byte> z, Span <byte> a) =>
                                                    {
                                                        bool result = true;
                                                        for (int i = 0; i < x.Length; i++)
                                                        {
                                                            if (x[i] != z[i])
                                                            {
                                                                result = false;
                                                            }
                                                        }
                                                        return(result);
                                                    };

                                                    if (!byteTable.CheckResult(checkByte))
                                                    {
                                                        PrintError(byteTable, methodUnderTestName, "(byte x, byte y, byte z, ref byte a) => (a = (byte)(x ^ y)) == z", checkByte);
                                                        testResult = Fail;
                                                    }
                                                }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #15
0
        internal static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.PackUnsignedSaturate);

            if (Sse2.IsSupported)
            {
                using (var shortTable = TestTableSse2 <short, byte> .Create(testsCount, 0.5))
                {
                    for (int i = 0; i < testsCount; i++)
                    {
                        (Vector128 <short>, Vector128 <short>)value = shortTable[i];
                        Vector128 <byte> result = Sse2.PackUnsignedSaturate(value.Item1, value.Item2);
                        shortTable.SetOutArrayU(result);
                    }

                    CheckMethodSixteen <short, byte> checkInt16 =
                        (ValueTuple <short, short, short, short, short, short, short, ValueTuple <short> > x,
                         ValueTuple <short, short, short, short, short, short, short, ValueTuple <short> > y,
                         ValueTuple <byte, byte, byte, byte, byte, byte, byte, ValueTuple <byte> > z1,
                         ValueTuple <byte, byte, byte, byte, byte, byte, byte, ValueTuple <byte> > z2,
                         ref byte a1, ref byte a2, ref byte a3, ref byte a4, ref byte a5, ref byte a6, ref byte a7, ref byte a8,
                         ref byte a9, ref byte a10, ref byte a11, ref byte a12, ref byte a13, ref byte a14, ref byte a15, ref byte a16) =>
                    {
                        a1  = ToByteSaturate(x.Item1);
                        a2  = ToByteSaturate(x.Item2);
                        a3  = ToByteSaturate(x.Item3);
                        a4  = ToByteSaturate(x.Item4);
                        a5  = ToByteSaturate(x.Item5);
                        a6  = ToByteSaturate(x.Item6);
                        a7  = ToByteSaturate(x.Item7);
                        a8  = ToByteSaturate(x.Item8);
                        a9  = ToByteSaturate(y.Item1);
                        a10 = ToByteSaturate(y.Item2);
                        a11 = ToByteSaturate(y.Item3);
                        a12 = ToByteSaturate(y.Item4);
                        a13 = ToByteSaturate(y.Item5);
                        a14 = ToByteSaturate(y.Item6);
                        a15 = ToByteSaturate(y.Item7);
                        a16 = ToByteSaturate(y.Item8);

                        return(a1 == z1.Item1 && a2 == z1.Item2 && a3 == z1.Item3 && a4 == z1.Item4 &&
                               a5 == z1.Item5 && a6 == z1.Item6 && a7 == z1.Item7 && a8 == z1.Item8 &&
                               a9 == z2.Item1 && a10 == z2.Item2 && a11 == z2.Item3 && a12 == z2.Item4 &&
                               a13 == z2.Item5 && a14 == z2.Item6 && a15 == z2.Item7 && a16 == z2.Item8);
                    };

                    if (!shortTable.CheckPackSaturate(checkInt16))
                    {
                        PrintError(shortTable, methodUnderTestName, "CheckPackSaturate", checkInt16);
                        testResult = Fail;
                    }
                }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #16
0
ファイル: UnpackHigh.cs プロジェクト: omajid/coreclr
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.UnpackHigh);

            if (Sse2.IsSupported)
            {
                using (var doubleTable = TestTableSse2 <double, double> .Create(testsCount, 1.0))
                    using (var longTable = TestTableSse2 <long, long> .Create(testsCount, 1.0))
                        using (var ulongTable = TestTableSse2 <ulong, ulong> .Create(testsCount, 1.0))
                            using (var intTable = TestTableSse2 <int, int> .Create(testsCount, 1.0))
                                using (var uintTable = TestTableSse2 <uint, uint> .Create(testsCount, 1.0))
                                    using (var shortTable = TestTableSse2 <short, short> .Create(testsCount, 1.0))
                                        using (var ushortTable = TestTableSse2 <ushort, ushort> .Create(testsCount, 1.0))
                                            using (var sbyteTable = TestTableSse2 <sbyte, sbyte> .Create(testsCount, 1.0))
                                                using (var byteTable = TestTableSse2 <byte, byte> .Create(testsCount, 1.0))
                                                {
                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <double>, Vector128 <double>)value = doubleTable[i];
                                                        Vector128 <double> result = Sse2.UnpackHigh(value.Item1, value.Item2);
                                                        doubleTable.SetOutArray(result, i);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <long>, Vector128 <long>)value = longTable[i];
                                                        Vector128 <long> result = Sse2.UnpackHigh(value.Item1, value.Item2);
                                                        longTable.SetOutArray(result, i);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <ulong>, Vector128 <ulong>)value = ulongTable[i];
                                                        Vector128 <ulong> result = Sse2.UnpackHigh(value.Item1, value.Item2);
                                                        ulongTable.SetOutArray(result, i);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <int>, Vector128 <int>)value = intTable[i];
                                                        Vector128 <int> result = Sse2.UnpackHigh(value.Item1, value.Item2);
                                                        intTable.SetOutArray(result, i);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <uint>, Vector128 <uint>)value = uintTable[i];
                                                        Vector128 <uint> result = Sse2.UnpackHigh(value.Item1, value.Item2);
                                                        uintTable.SetOutArray(result, i);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <short>, Vector128 <short>)value = shortTable[i];
                                                        Vector128 <short> result = Sse2.UnpackHigh(value.Item1, value.Item2);
                                                        shortTable.SetOutArray(result);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <ushort>, Vector128 <ushort>)value = ushortTable[i];
                                                        Vector128 <ushort> result = Sse2.UnpackHigh(value.Item1, value.Item2);
                                                        ushortTable.SetOutArray(result);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <sbyte>, Vector128 <sbyte>)value = sbyteTable[i];
                                                        Vector128 <sbyte> result = Sse2.UnpackHigh(value.Item1, value.Item2);
                                                        sbyteTable.SetOutArray(result, i);
                                                    }

                                                    for (int i = 0; i < testsCount; i++)
                                                    {
                                                        (Vector128 <byte>, Vector128 <byte>)value = byteTable[i];
                                                        Vector128 <byte> result = Sse2.UnpackHigh(value.Item1, value.Item2);
                                                        byteTable.SetOutArray(result, i);
                                                    }

                                                    CheckMethodFive <double, double> checkDouble = (double x1, double x2, double y1, double y2, double z1, double z2, ref double a1, ref double a2) =>
                                                    {
                                                        return((a1 = x2) == z1 && (a2 = y2) == z2);
                                                    };

                                                    if (!doubleTable.CheckUnpackHiDouble(checkDouble))
                                                    {
                                                        PrintError(doubleTable, methodUnderTestName, "(double x, double y, double z, ref double a) => (a = BitwiseXor(x, y)) == z", checkDouble);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodFive <long, long> checkLong = (long x1, long x2, long y1, long y2, long z1, long z2, ref long a1, ref long a2) =>
                                                    {
                                                        return((a1 = x2) == z1 && (a2 = y2) == z2);
                                                    };

                                                    if (!longTable.CheckUnpackHiDouble(checkLong))
                                                    {
                                                        PrintError(longTable, methodUnderTestName, "(long x, long y, long z, ref long a) => (a = x ^ y) == z", checkLong);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodFive <ulong, ulong> checkUlong = (ulong x1, ulong x2, ulong y1, ulong y2, ulong z1, ulong z2, ref ulong a1, ref ulong a2) =>
                                                    {
                                                        return((a1 = x2) == z1 && (a2 = y2) == z2);
                                                    };

                                                    if (!longTable.CheckUnpackHiDouble(checkLong))
                                                    {
                                                        PrintError(ulongTable, methodUnderTestName, "(ulong x1, ulong x2, ulong y1, ulong y2, ulong z1, ulong z2, ref ulong a1, ref ulong a2) => (a1 = x2) == z1 && (a2 = y2) == z2", checkUlong);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodFourTFourU <int, int> checkInt32 =
                                                        (ValueTuple <int, int, int, int> x, ValueTuple <int, int, int, int> y,
                                                         ValueTuple <int, int, int, int> z,
                                                         ref int a1, ref int a2, ref int a3, ref int a4) =>
                                                    {
                                                        a1 = x.Item3;
                                                        a2 = y.Item3;
                                                        a3 = x.Item4;
                                                        a4 = y.Item4;
                                                        return(a1 == z.Item1 && a2 == z.Item2 && a3 == z.Item3 && a4 == z.Item4);
                                                    };

                                                    if (!intTable.CheckUnpack(checkInt32))
                                                    {
                                                        PrintError(intTable, methodUnderTestName, "(int x, int y, int z, ref int a) => (a = x ^ y) == z", checkInt32);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodFourTFourU <uint, uint> checkUInt32 =
                                                        (ValueTuple <uint, uint, uint, uint> x, ValueTuple <uint, uint, uint, uint> y,
                                                         ValueTuple <uint, uint, uint, uint> z,
                                                         ref uint a1, ref uint a2, ref uint a3, ref uint a4) =>
                                                    {
                                                        a1 = x.Item3;
                                                        a2 = y.Item3;
                                                        a3 = x.Item4;
                                                        a4 = y.Item4;
                                                        return(a1 == z.Item1 && a2 == z.Item2 && a3 == z.Item3 && a4 == z.Item4);
                                                    };

                                                    if (!uintTable.CheckUnpack(checkUInt32))
                                                    {
                                                        PrintError(uintTable, methodUnderTestName, "(uint x, uint y, uint z, ref uint a) => (a = x ^ y) == z", checkUInt32);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodEightOfTEightOfU <short, short> checkInt16 =
                                                        (ValueTuple <short, short, short, short, short, short, short, ValueTuple <short> > x,
                                                         ValueTuple <short, short, short, short, short, short, short, ValueTuple <short> > y,
                                                         ValueTuple <short, short, short, short, short, short, short, ValueTuple <short> > z,
                                                         ref short a1, ref short a2, ref short a3, ref short a4, ref short a5, ref short a6, ref short a7, ref short a8) =>
                                                    {
                                                        a1 = x.Item5;
                                                        a2 = y.Item5;
                                                        a3 = x.Item6;
                                                        a4 = y.Item6;
                                                        a5 = x.Item7;
                                                        a6 = y.Item7;
                                                        a7 = x.Item8;
                                                        a8 = y.Item8;
                                                        return(a1 == z.Item1 && a2 == z.Item2 && a3 == z.Item3 && a4 == z.Item4 &&
                                                               a5 == z.Item5 && a6 == z.Item6 && a7 == z.Item7 && a8 == z.Item8);
                                                    };

                                                    if (!shortTable.CheckUnpack(checkInt16))
                                                    {
                                                        PrintError(shortTable, methodUnderTestName, "CheckUnpack(CheckMethodEightOfTEightOfU<short, short>)", checkInt16);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodEightOfTEightOfU <ushort, ushort> checkUInt16 =
                                                        (ValueTuple <ushort, ushort, ushort, ushort, ushort, ushort, ushort, ValueTuple <ushort> > x,
                                                         ValueTuple <ushort, ushort, ushort, ushort, ushort, ushort, ushort, ValueTuple <ushort> > y,
                                                         ValueTuple <ushort, ushort, ushort, ushort, ushort, ushort, ushort, ValueTuple <ushort> > z,
                                                         ref ushort a1, ref ushort a2, ref ushort a3, ref ushort a4, ref ushort a5, ref ushort a6, ref ushort a7, ref ushort a8) =>
                                                    {
                                                        a1 = x.Item5;
                                                        a2 = y.Item5;
                                                        a3 = x.Item6;
                                                        a4 = y.Item6;
                                                        a5 = x.Item7;
                                                        a6 = y.Item7;
                                                        a7 = x.Item8;
                                                        a8 = y.Item8;
                                                        return(a1 == z.Item1 && a2 == z.Item2 && a3 == z.Item3 && a4 == z.Item4 &&
                                                               a5 == z.Item5 && a6 == z.Item6 && a7 == z.Item7 && a8 == z.Item8);
                                                    };

                                                    if (!ushortTable.CheckUnpack(checkUInt16))
                                                    {
                                                        PrintError(ushortTable, methodUnderTestName, "(ushort x, ushort y, ushort z, ref ushort a) => (a = (ushort)(x ^ y)) == z", checkUInt16);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodSixteenOfAll <sbyte, sbyte> checkSByte =
                                                        (ValueTuple <sbyte, sbyte, sbyte, sbyte, sbyte, sbyte, sbyte, ValueTuple <sbyte> > x1,
                                                         ValueTuple <sbyte, sbyte, sbyte, sbyte, sbyte, sbyte, sbyte, ValueTuple <sbyte> > x,
                                                         ValueTuple <sbyte, sbyte, sbyte, sbyte, sbyte, sbyte, sbyte, ValueTuple <sbyte> > y1,
                                                         ValueTuple <sbyte, sbyte, sbyte, sbyte, sbyte, sbyte, sbyte, ValueTuple <sbyte> > y,
                                                         ValueTuple <sbyte, sbyte, sbyte, sbyte, sbyte, sbyte, sbyte, ValueTuple <sbyte> > z1,
                                                         ValueTuple <sbyte, sbyte, sbyte, sbyte, sbyte, sbyte, sbyte, ValueTuple <sbyte> > z2,
                                                         ref sbyte a1, ref sbyte a2, ref sbyte a3, ref sbyte a4, ref sbyte a5, ref sbyte a6, ref sbyte a7, ref sbyte a8,
                                                         ref sbyte a9, ref sbyte a10, ref sbyte a11, ref sbyte a12, ref sbyte a13, ref sbyte a14, ref sbyte a15, ref sbyte a16) =>
                                                    {
                                                        a1  = x.Item1;
                                                        a2  = y.Item1;
                                                        a3  = x.Item2;
                                                        a4  = y.Item2;
                                                        a5  = x.Item3;
                                                        a6  = y.Item3;
                                                        a7  = x.Item4;
                                                        a8  = y.Item4;
                                                        a9  = x.Item5;
                                                        a10 = y.Item5;
                                                        a11 = x.Item6;
                                                        a12 = y.Item6;
                                                        a13 = x.Item7;
                                                        a14 = y.Item7;
                                                        a15 = x.Item8;
                                                        a16 = y.Item8;

                                                        return(a1 == z1.Item1 && a2 == z1.Item2 && a3 == z1.Item3 && a4 == z1.Item4 &&
                                                               a5 == z1.Item5 && a6 == z1.Item6 && a7 == z1.Item7 && a8 == z1.Item8 &&
                                                               a9 == z2.Item1 && a10 == z2.Item2 && a11 == z2.Item3 && a12 == z2.Item4 &&
                                                               a13 == z2.Item5 && a14 == z2.Item6 && a15 == z2.Item7 && a16 == z2.Item8);
                                                    };

                                                    if (!sbyteTable.CheckUnpack(checkSByte))
                                                    {
                                                        PrintError(sbyteTable, methodUnderTestName, "(sbyte x, sbyte y, sbyte z, ref sbyte a) => (a = (sbyte)(x ^ y)) == z", checkSByte);
                                                        testResult = Fail;
                                                    }

                                                    CheckMethodSixteenOfAll <byte, byte> checkByte =
                                                        (ValueTuple <byte, byte, byte, byte, byte, byte, byte, ValueTuple <byte> > x1,
                                                         ValueTuple <byte, byte, byte, byte, byte, byte, byte, ValueTuple <byte> > x,
                                                         ValueTuple <byte, byte, byte, byte, byte, byte, byte, ValueTuple <byte> > y1,
                                                         ValueTuple <byte, byte, byte, byte, byte, byte, byte, ValueTuple <byte> > y,
                                                         ValueTuple <byte, byte, byte, byte, byte, byte, byte, ValueTuple <byte> > z1,
                                                         ValueTuple <byte, byte, byte, byte, byte, byte, byte, ValueTuple <byte> > z2,
                                                         ref byte a1, ref byte a2, ref byte a3, ref byte a4, ref byte a5, ref byte a6, ref byte a7, ref byte a8,
                                                         ref byte a9, ref byte a10, ref byte a11, ref byte a12, ref byte a13, ref byte a14, ref byte a15, ref byte a16) =>
                                                    {
                                                        a1  = x.Item1;
                                                        a2  = y.Item1;
                                                        a3  = x.Item2;
                                                        a4  = y.Item2;
                                                        a5  = x.Item3;
                                                        a6  = y.Item3;
                                                        a7  = x.Item4;
                                                        a8  = y.Item4;
                                                        a9  = x.Item5;
                                                        a10 = y.Item5;
                                                        a11 = x.Item6;
                                                        a12 = y.Item6;
                                                        a13 = x.Item7;
                                                        a14 = y.Item7;
                                                        a15 = x.Item8;
                                                        a16 = y.Item8;

                                                        return(a1 == z1.Item1 && a2 == z1.Item2 && a3 == z1.Item3 && a4 == z1.Item4 &&
                                                               a5 == z1.Item5 && a6 == z1.Item6 && a7 == z1.Item7 && a8 == z1.Item8 &&
                                                               a9 == z2.Item1 && a10 == z2.Item2 && a11 == z2.Item3 && a12 == z2.Item4 &&
                                                               a13 == z2.Item5 && a14 == z2.Item6 && a15 == z2.Item7 && a16 == z2.Item8);
                                                    };

                                                    if (!byteTable.CheckUnpack(checkByte))
                                                    {
                                                        PrintError(byteTable, methodUnderTestName, "(byte x, byte y, byte z, ref byte a) => (a = (byte)(x ^ y)) == z", checkByte);
                                                        testResult = Fail;
                                                    }
                                                }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }
コード例 #17
0
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.CompareGreaterThan);

            if (Sse2.IsSupported)
            {
                using (var doubleTable = TestTableSse2 <double> .Create(testsCount))
                    using (var intTable = TestTableSse2 <int> .Create(testsCount))
                        using (var shortTable = TestTableSse2 <short> .Create(testsCount))
                            using (var sbyteTable = TestTableSse2 <sbyte> .Create(testsCount))
                            {
                                for (int i = 0; i < testsCount; i++)
                                {
                                    (Vector128 <double>, Vector128 <double>, Vector128 <double>)value = doubleTable[i];
                                    var result = Sse2.CompareGreaterThan(value.Item1, value.Item2);
                                    doubleTable.SetOutArray(result);
                                }

                                for (int i = 0; i < testsCount; i++)
                                {
                                    (Vector128 <int>, Vector128 <int>, Vector128 <int>)value = intTable[i];
                                    var result = Sse2.CompareGreaterThan(value.Item1, value.Item2);
                                    intTable.SetOutArray(result);
                                }

                                for (int i = 0; i < testsCount; i++)
                                {
                                    (Vector128 <short>, Vector128 <short>, Vector128 <short>)value = shortTable[i];
                                    var result = Sse2.CompareGreaterThan(value.Item1, value.Item2);
                                    shortTable.SetOutArray(result);
                                }

                                for (int i = 0; i < testsCount; i++)
                                {
                                    (Vector128 <sbyte>, Vector128 <sbyte>, Vector128 <sbyte>)value = sbyteTable[i];
                                    var result = Sse2.CompareGreaterThan(value.Item1, value.Item2);
                                    sbyteTable.SetOutArray(result);
                                }

                                CheckMethod <double> checkDouble = (double x, double y, double z, ref double a) =>
                                {
                                    a = x > y?BitConverter.Int64BitsToDouble(-1) : 0;

                                    return(BitConverter.DoubleToInt64Bits(a) == BitConverter.DoubleToInt64Bits(z));
                                };

                                if (!doubleTable.CheckResult(checkDouble))
                                {
                                    PrintError(doubleTable, methodUnderTestName, "(x, y, z, ref a) => (a = x > y ? double.NaN : 0) == z", checkDouble);
                                    testResult = Fail;
                                }

                                CheckMethod <int> checkInt32 = (int x, int y, int z, ref int a) => (a = x > y ? -1 : 0) == z;

                                if (!intTable.CheckResult(checkInt32))
                                {
                                    PrintError(intTable, methodUnderTestName, "(x, y, z, a) => (a = x > y ? -1 : 0) == z", checkInt32);
                                    testResult = Fail;
                                }

                                CheckMethod <short> checkInt16 = (short x, short y, short z, ref short a)
                                                                 => (a = (short)(x > y ? -1 : 0)) == z;

                                if (!shortTable.CheckResult(checkInt16))
                                {
                                    PrintError(shortTable, methodUnderTestName, "(x, y, z) => (x > y ? -1 : 0) == z", checkInt16);
                                    testResult = Fail;
                                }

                                CheckMethod <sbyte> checkSByte = (sbyte x, sbyte y, sbyte z, ref sbyte a)
                                                                 => (a = (sbyte)(x > y ? -1 : 0)) == z;

                                if (!sbyteTable.CheckResult(checkSByte))
                                {
                                    PrintError(sbyteTable, methodUnderTestName, "(x, y, z) => (x > y ? -1 : 0) == z", checkSByte);
                                    testResult = Fail;
                                }
                            }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }

            return(testResult);
        }