コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testCount           = 16;
            string methodUnderTestName = nameof(Sse2.Shuffle);


            if (Sse2.IsSupported)
            {
                string[] permuteData = new string[]
                {
                    "0b11100100",         // identity
                    "0b00011011",         // invert
                    "0b00000000",         // broadcast element 0
                    "0b11111111",         // broadcast element 3
                    "0b01010101",         // broadcast element 1
                    "0b10101010",         // broadcast element 2
                    "0b11011000",         // swap middle elements
                    "0b00100111",         // swap external elements
                    "0b10110001",         // swap internal with external elements
                    "0b11110000",         // divide everything between external elements
                    "0b10100101",         // divide everything between internal elements
                    "0b00010100",         // pattern (0, 1, 1, 0)
                    "0b10000010",         // pattern (2, 0, 0, 2)
                    "0b11001100",         // pattern (3, 0, 3, 0)
                    "0b01100110",         // pattern (1, 2, 1, 2)
                    "0b10011001"          // pattern (2, 1, 2, 1)
                };

                string[] permuteDouble = new string[]
                {
                    "0b00",
                    "0b01",
                    "0b10",
                    "0b11",
                };

                using (var doubleTable = TestTableTuvImmSse2 <double, double, byte> .Create(permuteDouble.Length))
                    using (var intTable = TestTableTuvImmSse2 <int, int, byte> .Create(permuteData.Length))
                        using (var uintTable = TestTableTuvImmSse2 <uint, uint, byte> .Create(permuteData.Length))
                        {
                            // Vector128<double> tests

                            TestUtilities.InitializeWithElementNumberingModuloVectorLength <double>(
                                doubleTable.inArray1, 16, (int i, int elNo) =>
                            {
                                return((uint)i % 2);
                            });

                            TestUtilities.InitializeWithElementNumberingModuloVectorLength <double>(
                                doubleTable.inArray2, 16, (int i, int elNo) =>
                            {
                                return((uint)i % 2 + 10);
                            });

                            (Vector128 <double>, Vector128 <double>)valueDouble_0 = doubleTable[0];
                            Vector128 <double> resultDouble_0 = Sse2.Shuffle(valueDouble_0.Item1, valueDouble_0.Item2, (byte)0b00);
                            doubleTable.SetOutArray(resultDouble_0, 0, (byte)0b00);

                            (Vector128 <double>, Vector128 <double>)valueDouble_1 = doubleTable[1];
                            Vector128 <double> resultDouble_1 = Sse2.Shuffle(valueDouble_1.Item1, valueDouble_1.Item2, (byte)0b01);
                            doubleTable.SetOutArray(resultDouble_1, 1, (byte)0b01);

                            (Vector128 <double>, Vector128 <double>)valueDouble_2 = doubleTable[2];
                            Vector128 <double> resultDouble_2 = Sse2.Shuffle(valueDouble_2.Item1, valueDouble_2.Item2, (byte)0b10);
                            doubleTable.SetOutArray(resultDouble_2, 2, (byte)0b10);

                            (Vector128 <double>, Vector128 <double>)valueDouble_3 = doubleTable[3];
                            Vector128 <double> resultDouble_3 = Sse2.Shuffle(valueDouble_3.Item1, valueDouble_3.Item2, (byte)0b11);
                            doubleTable.SetOutArray(resultDouble_3, 3, (byte)0b11);


                            // Vector128<int> tests

                            TestUtilities.InitializeWithElementNumberingModuloVectorLength <uint>(
                                uintTable.inArray1, 16, (int i, int elNo) =>
                            {
                                return((uint)i % 4);
                            });

                            (Vector128 <int>, Vector128 <int>)valueInt32_0 = intTable[0];
                            Vector128 <int> resultInt32_0 = Sse2.Shuffle(valueInt32_0.Item1, (byte)0b11100100);
                            intTable.SetOutArray(resultInt32_0, 0, (byte)0b11100100);

                            (Vector128 <int>, Vector128 <int>)valueInt32_1 = intTable[1];
                            Vector128 <int> resultInt32_1 = Sse2.Shuffle(valueInt32_1.Item1, (byte)0b00011011);
                            intTable.SetOutArray(resultInt32_1, 1, (byte)0b00011011);

                            (Vector128 <int>, Vector128 <int>)valueInt32_2 = intTable[2];
                            Vector128 <int> resultInt32_2 = Sse2.Shuffle(valueInt32_2.Item1, (byte)0b00000000);
                            intTable.SetOutArray(resultInt32_2, 2, (byte)0b00000000);

                            (Vector128 <int>, Vector128 <int>)valueInt32_3 = intTable[3];
                            Vector128 <int> resultInt32_3 = Sse2.Shuffle(valueInt32_3.Item1, (byte)0b11111111);
                            intTable.SetOutArray(resultInt32_3, 3, (byte)0b11111111);

                            (Vector128 <int>, Vector128 <int>)valueInt32_4 = intTable[4];
                            Vector128 <int> resultInt32_4 = Sse2.Shuffle(valueInt32_4.Item1, (byte)0b01010101);
                            intTable.SetOutArray(resultInt32_4, 4, (byte)0b01010101);

                            (Vector128 <int>, Vector128 <int>)valueInt32_5 = intTable[5];
                            Vector128 <int> resultInt32_5 = Sse2.Shuffle(valueInt32_5.Item1, (byte)0b10101010);
                            intTable.SetOutArray(resultInt32_5, 5, (byte)0b10101010);

                            (Vector128 <int>, Vector128 <int>)valueInt32_6 = intTable[6];
                            Vector128 <int> resultInt32_6 = Sse2.Shuffle(valueInt32_6.Item1, (byte)0b11011000);
                            intTable.SetOutArray(resultInt32_6, 6, (byte)0b11011000);

                            (Vector128 <int>, Vector128 <int>)valueInt32_7 = intTable[7];
                            Vector128 <int> resultInt32_7 = Sse2.Shuffle(valueInt32_7.Item1, (byte)0b00100111);
                            intTable.SetOutArray(resultInt32_7, 7, (byte)0b00100111);

                            (Vector128 <int>, Vector128 <int>)valueInt32_8 = intTable[8];
                            Vector128 <int> resultInt32_8 = Sse2.Shuffle(valueInt32_8.Item1, (byte)0b10110001);
                            intTable.SetOutArray(resultInt32_8, 8, (byte)0b10110001);

                            (Vector128 <int>, Vector128 <int>)valueInt32_9 = intTable[9];
                            Vector128 <int> resultInt32_9 = Sse2.Shuffle(valueInt32_9.Item1, (byte)0b11110000);
                            intTable.SetOutArray(resultInt32_9, 9, (byte)0b11110000);

                            (Vector128 <int>, Vector128 <int>)valueInt32_10 = intTable[10];
                            Vector128 <int> resultInt32_10 = Sse2.Shuffle(valueInt32_10.Item1, (byte)0b10100101);
                            intTable.SetOutArray(resultInt32_10, 10, (byte)0b10100101);

                            (Vector128 <int>, Vector128 <int>)valueInt32_11 = intTable[11];
                            Vector128 <int> resultInt32_11 = Sse2.Shuffle(valueInt32_11.Item1, (byte)0b00010100);
                            intTable.SetOutArray(resultInt32_11, 11, (byte)0b00010100);

                            (Vector128 <int>, Vector128 <int>)valueInt32_12 = intTable[12];
                            Vector128 <int> resultInt32_12 = Sse2.Shuffle(valueInt32_12.Item1, (byte)0b10000010);
                            intTable.SetOutArray(resultInt32_12, 12, (byte)0b10000010);

                            (Vector128 <int>, Vector128 <int>)valueInt32_13 = intTable[13];
                            Vector128 <int> resultInt32_13 = Sse2.Shuffle(valueInt32_13.Item1, (byte)0b11001100);
                            intTable.SetOutArray(resultInt32_13, 13, (byte)0b11001100);

                            (Vector128 <int>, Vector128 <int>)valueInt32_14 = intTable[14];
                            Vector128 <int> resultInt32_14 = Sse2.Shuffle(valueInt32_14.Item1, (byte)0b01100110);
                            intTable.SetOutArray(resultInt32_14, 14, (byte)0b01100110);

                            (Vector128 <int>, Vector128 <int>)valueInt32_15 = intTable[15];
                            Vector128 <int> resultInt32_15 = Sse2.Shuffle(valueInt32_15.Item1, (byte)0b10011001);
                            intTable.SetOutArray(resultInt32_15, 15, (byte)0b10011001);


                            // Vector128<uint> tests

                            TestUtilities.InitializeWithElementNumberingModuloVectorLength <uint>(
                                uintTable.inArray1, 16, (int i, int elNo) =>
                            {
                                return((uint)i % 4);
                            });

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_0 = uintTable[0];
                            Vector128 <uint> resultUInt32_0 = Sse2.Shuffle(valueUInt32_0.Item1, (byte)0b11100100);
                            uintTable.SetOutArray(resultUInt32_0, 0, (byte)0b11100100);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_1 = uintTable[1];
                            Vector128 <uint> resultUInt32_1 = Sse2.Shuffle(valueUInt32_1.Item1, (byte)0b00011011);
                            uintTable.SetOutArray(resultUInt32_1, 1, (byte)0b00011011);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_2 = uintTable[2];
                            Vector128 <uint> resultUInt32_2 = Sse2.Shuffle(valueUInt32_2.Item1, (byte)0b00000000);
                            uintTable.SetOutArray(resultUInt32_2, 2, (byte)0b00000000);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_3 = uintTable[3];
                            Vector128 <uint> resultUInt32_3 = Sse2.Shuffle(valueUInt32_3.Item1, (byte)0b11111111);
                            uintTable.SetOutArray(resultUInt32_3, 3, (byte)0b11111111);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_4 = uintTable[4];
                            Vector128 <uint> resultUInt32_4 = Sse2.Shuffle(valueUInt32_4.Item1, (byte)0b01010101);
                            uintTable.SetOutArray(resultUInt32_4, 4, (byte)0b01010101);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_5 = uintTable[5];
                            Vector128 <uint> resultUInt32_5 = Sse2.Shuffle(valueUInt32_5.Item1, (byte)0b10101010);
                            uintTable.SetOutArray(resultUInt32_5, 5, (byte)0b10101010);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_6 = uintTable[6];
                            Vector128 <uint> resultUInt32_6 = Sse2.Shuffle(valueUInt32_6.Item1, (byte)0b11011000);
                            uintTable.SetOutArray(resultUInt32_6, 6, (byte)0b11011000);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_7 = uintTable[7];
                            Vector128 <uint> resultUInt32_7 = Sse2.Shuffle(valueUInt32_7.Item1, (byte)0b00100111);
                            uintTable.SetOutArray(resultUInt32_7, 7, (byte)0b00100111);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_8 = uintTable[8];
                            Vector128 <uint> resultUInt32_8 = Sse2.Shuffle(valueUInt32_8.Item1, (byte)0b10110001);
                            uintTable.SetOutArray(resultUInt32_8, 8, (byte)0b10110001);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_9 = uintTable[9];
                            Vector128 <uint> resultUInt32_9 = Sse2.Shuffle(valueUInt32_9.Item1, (byte)0b11110000);
                            uintTable.SetOutArray(resultUInt32_9, 9, (byte)0b11110000);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_10 = uintTable[10];
                            Vector128 <uint> resultUInt32_10 = Sse2.Shuffle(valueUInt32_10.Item1, (byte)0b10100101);
                            uintTable.SetOutArray(resultUInt32_10, 10, (byte)0b10100101);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_11 = uintTable[11];
                            Vector128 <uint> resultUInt32_11 = Sse2.Shuffle(valueUInt32_11.Item1, (byte)0b00010100);
                            uintTable.SetOutArray(resultUInt32_11, 11, (byte)0b00010100);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_12 = uintTable[12];
                            Vector128 <uint> resultUInt32_12 = Sse2.Shuffle(valueUInt32_12.Item1, (byte)0b10000010);
                            uintTable.SetOutArray(resultUInt32_12, 12, (byte)0b10000010);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_13 = uintTable[13];
                            Vector128 <uint> resultUInt32_13 = Sse2.Shuffle(valueUInt32_13.Item1, (byte)0b11001100);
                            uintTable.SetOutArray(resultUInt32_13, 13, (byte)0b11001100);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_14 = uintTable[14];
                            Vector128 <uint> resultUInt32_14 = Sse2.Shuffle(valueUInt32_14.Item1, (byte)0b01100110);
                            uintTable.SetOutArray(resultUInt32_14, 14, (byte)0b01100110);

                            (Vector128 <uint>, Vector128 <uint>)valueUInt32_15 = uintTable[15];
                            Vector128 <uint> resultUInt32_15 = Sse2.Shuffle(valueUInt32_15.Item1, (byte)0b10011001);
                            uintTable.SetOutArray(resultUInt32_15, 15, (byte)0b10011001);


                            CheckMethodFiveDouble <double, double, byte> checkDouble =
                                (Span <double> x, Span <double> y, byte imm, Span <double> z, Span <double> a) =>
                            {
                                a[0] = (0x01 & imm) > 0 ? x[1] : x[0];
                                a[1] = (0x02 & imm) > 0 ? y[1] : y[0];
                                return(a[0] == z[0] && a[1] == z[1]);
                            };

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

                            CheckMethodFive <int, int, byte> checkInt32 = (Span <int> x, byte imm, Span <int> z, Span <int> a) =>
                            {
                                bool result = true;
                                for (int i = 0; i < x.Length; i++)
                                {
                                    a[i] = x[imm & 0x03];
                                    if (z[i] != a[i])
                                    {
                                        result = false;
                                    }
                                    imm = (byte)(imm >> 2);
                                }
                                return(result);
                            };

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

                            CheckMethodFive <uint, uint, byte> checkUInt32 = (Span <uint> x, byte imm, Span <uint> z, Span <uint> a) =>
                            {
                                bool result = true;
                                for (int i = 0; i < x.Length; i++)
                                {
                                    a[i] = x[imm & 0x03];
                                    if (z[i] != a[i])
                                    {
                                        result = false;
                                    }
                                    imm = (byte)(imm >> 2);
                                }
                                return(result);
                            };

                            if (!uintTable.CheckResultShuffle(checkUInt32))
                            {
                                PrintError(uintTable, methodUnderTestName, "(uint x, byte y, uint z, ref uint a) => (a = x << y) == z", checkUInt32);
                                testResult = Fail;
                            }
                        }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }
            return(testResult);
        }
コード例 #4
0
        static unsafe int Main(string[] args)
        {
            short  testResult          = Pass;
            short  testsCount          = 16;
            string methodUnderTestName = nameof(Sse2.ShuffleLow);



            if (Sse2.IsSupported)
            {
                string[] permuteData = new string[]
                {
                    "0b11100100",         // identity
                    "0b00011011",         // invert
                    "0b00000000",         // broadcast element 0
                    "0b11111111",         // broadcast element 3
                    "0b01010101",         // broadcast element 1
                    "0b10101010",         // broadcast element 2
                    "0b11011000",         // swap middle elements
                    "0b00100111",         // swap external elements
                    "0b10110001",         // swap internal with external elements
                    "0b11110000",         // divide everything between external elements
                    "0b10100101",         // divide everything between internal elements
                    "0b00010100",         // pattern (0, 1, 1, 0)
                    "0b10000010",         // pattern (2, 0, 0, 2)
                    "0b11001100",         // pattern (3, 0, 3, 0)
                    "0b01100110",         // pattern (1, 2, 1, 2)
                    "0b10011001"          // pattern (2, 1, 2, 1)
                };

                using (var shortTable = TestTableTuvImmSse2 <short, short, byte> .Create(testsCount))
                    using (var ushortTable = TestTableTuvImmSse2 <ushort, ushort, byte> .Create(testsCount))
                    {
                        // Vector128<short> tests

                        TestUtilities.InitializeWithElementNumberingModuloVectorLength <short>(
                            shortTable.inArray1, 16, (int i, int elNo) =>
                        {
                            return((short)(i % 8));
                        });

                        TestUtilities.InitializeWithConstValue <short>(0, shortTable.inArray2);

                        (Vector128 <short>, Vector128 <short>)valueInt16_0 = shortTable[0];
                        Vector128 <short> resultInt16_0 = Sse2.ShuffleLow(valueInt16_0.Item1, (byte)0b11100100);
                        shortTable.SetOutArray(resultInt16_0, 0, (byte)0b11100100);

                        (Vector128 <short>, Vector128 <short>)valueInt16_1 = shortTable[1];
                        Vector128 <short> resultInt16_1 = Sse2.ShuffleLow(valueInt16_1.Item1, (byte)0b00011011);
                        shortTable.SetOutArray(resultInt16_1, 1, (byte)0b00011011);

                        (Vector128 <short>, Vector128 <short>)valueInt16_2 = shortTable[2];
                        Vector128 <short> resultInt16_2 = Sse2.ShuffleLow(valueInt16_2.Item1, (byte)0b00000000);
                        shortTable.SetOutArray(resultInt16_2, 2, (byte)0b00000000);

                        (Vector128 <short>, Vector128 <short>)valueInt16_3 = shortTable[3];
                        Vector128 <short> resultInt16_3 = Sse2.ShuffleLow(valueInt16_3.Item1, (byte)0b11111111);
                        shortTable.SetOutArray(resultInt16_3, 3, (byte)0b11111111);

                        (Vector128 <short>, Vector128 <short>)valueInt16_4 = shortTable[4];
                        Vector128 <short> resultInt16_4 = Sse2.ShuffleLow(valueInt16_4.Item1, (byte)0b01010101);
                        shortTable.SetOutArray(resultInt16_4, 4, (byte)0b01010101);

                        (Vector128 <short>, Vector128 <short>)valueInt16_5 = shortTable[5];
                        Vector128 <short> resultInt16_5 = Sse2.ShuffleLow(valueInt16_5.Item1, (byte)0b10101010);
                        shortTable.SetOutArray(resultInt16_5, 5, (byte)0b10101010);

                        (Vector128 <short>, Vector128 <short>)valueInt16_6 = shortTable[6];
                        Vector128 <short> resultInt16_6 = Sse2.ShuffleLow(valueInt16_6.Item1, (byte)0b11011000);
                        shortTable.SetOutArray(resultInt16_6, 6, (byte)0b11011000);

                        (Vector128 <short>, Vector128 <short>)valueInt16_7 = shortTable[7];
                        Vector128 <short> resultInt16_7 = Sse2.ShuffleLow(valueInt16_7.Item1, (byte)0b00100111);
                        shortTable.SetOutArray(resultInt16_7, 7, (byte)0b00100111);

                        (Vector128 <short>, Vector128 <short>)valueInt16_8 = shortTable[8];
                        Vector128 <short> resultInt16_8 = Sse2.ShuffleLow(valueInt16_8.Item1, (byte)0b10110001);
                        shortTable.SetOutArray(resultInt16_8, 8, (byte)0b10110001);

                        (Vector128 <short>, Vector128 <short>)valueInt16_9 = shortTable[9];
                        Vector128 <short> resultInt16_9 = Sse2.ShuffleLow(valueInt16_9.Item1, (byte)0b11110000);
                        shortTable.SetOutArray(resultInt16_9, 9, (byte)0b11110000);

                        (Vector128 <short>, Vector128 <short>)valueInt16_10 = shortTable[10];
                        Vector128 <short> resultInt16_10 = Sse2.ShuffleLow(valueInt16_10.Item1, (byte)0b10100101);
                        shortTable.SetOutArray(resultInt16_10, 10, (byte)0b10100101);

                        (Vector128 <short>, Vector128 <short>)valueInt16_11 = shortTable[11];
                        Vector128 <short> resultInt16_11 = Sse2.ShuffleLow(valueInt16_11.Item1, (byte)0b00010100);
                        shortTable.SetOutArray(resultInt16_11, 11, (byte)0b00010100);

                        (Vector128 <short>, Vector128 <short>)valueInt16_12 = shortTable[12];
                        Vector128 <short> resultInt16_12 = Sse2.ShuffleLow(valueInt16_12.Item1, (byte)0b10000010);
                        shortTable.SetOutArray(resultInt16_12, 12, (byte)0b10000010);

                        (Vector128 <short>, Vector128 <short>)valueInt16_13 = shortTable[13];
                        Vector128 <short> resultInt16_13 = Sse2.ShuffleLow(valueInt16_13.Item1, (byte)0b11001100);
                        shortTable.SetOutArray(resultInt16_13, 13, (byte)0b11001100);

                        (Vector128 <short>, Vector128 <short>)valueInt16_14 = shortTable[14];
                        Vector128 <short> resultInt16_14 = Sse2.ShuffleLow(valueInt16_14.Item1, (byte)0b01100110);
                        shortTable.SetOutArray(resultInt16_14, 14, (byte)0b01100110);

                        (Vector128 <short>, Vector128 <short>)valueInt16_15 = shortTable[15];
                        Vector128 <short> resultInt16_15 = Sse2.ShuffleLow(valueInt16_15.Item1, (byte)0b10011001);
                        shortTable.SetOutArray(resultInt16_15, 15, (byte)0b10011001);


                        // Vector128<ushort> tests

                        TestUtilities.InitializeWithElementNumberingModuloVectorLength <ushort>(
                            ushortTable.inArray1, 16, (int i, int elNo) =>
                        {
                            return((ushort)(i % 8));
                        });

                        TestUtilities.InitializeWithConstValue <ushort>(0, ushortTable.inArray2);


                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_0 = ushortTable[0];
                        Vector128 <ushort> resultUInt16_0 = Sse2.ShuffleLow(valueUInt16_0.Item1, (byte)0b11100100);
                        ushortTable.SetOutArray(resultUInt16_0, 0, (byte)0b11100100);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_1 = ushortTable[1];
                        Vector128 <ushort> resultUInt16_1 = Sse2.ShuffleLow(valueUInt16_1.Item1, (byte)0b00011011);
                        ushortTable.SetOutArray(resultUInt16_1, 1, (byte)0b00011011);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_2 = ushortTable[2];
                        Vector128 <ushort> resultUInt16_2 = Sse2.ShuffleLow(valueUInt16_2.Item1, (byte)0b00000000);
                        ushortTable.SetOutArray(resultUInt16_2, 2, (byte)0b00000000);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_3 = ushortTable[3];
                        Vector128 <ushort> resultUInt16_3 = Sse2.ShuffleLow(valueUInt16_3.Item1, (byte)0b11111111);
                        ushortTable.SetOutArray(resultUInt16_3, 3, (byte)0b11111111);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_4 = ushortTable[4];
                        Vector128 <ushort> resultUInt16_4 = Sse2.ShuffleLow(valueUInt16_4.Item1, (byte)0b01010101);
                        ushortTable.SetOutArray(resultUInt16_4, 4, (byte)0b01010101);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_5 = ushortTable[5];
                        Vector128 <ushort> resultUInt16_5 = Sse2.ShuffleLow(valueUInt16_5.Item1, (byte)0b10101010);
                        ushortTable.SetOutArray(resultUInt16_5, 5, (byte)0b10101010);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_6 = ushortTable[6];
                        Vector128 <ushort> resultUInt16_6 = Sse2.ShuffleLow(valueUInt16_6.Item1, (byte)0b11011000);
                        ushortTable.SetOutArray(resultUInt16_6, 6, (byte)0b11011000);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_7 = ushortTable[7];
                        Vector128 <ushort> resultUInt16_7 = Sse2.ShuffleLow(valueUInt16_7.Item1, (byte)0b00100111);
                        ushortTable.SetOutArray(resultUInt16_7, 7, (byte)0b00100111);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_8 = ushortTable[8];
                        Vector128 <ushort> resultUInt16_8 = Sse2.ShuffleLow(valueUInt16_8.Item1, (byte)0b10110001);
                        ushortTable.SetOutArray(resultUInt16_8, 8, (byte)0b10110001);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_9 = ushortTable[9];
                        Vector128 <ushort> resultUInt16_9 = Sse2.ShuffleLow(valueUInt16_9.Item1, (byte)0b11110000);
                        ushortTable.SetOutArray(resultUInt16_9, 9, (byte)0b11110000);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_10 = ushortTable[10];
                        Vector128 <ushort> resultUInt16_10 = Sse2.ShuffleLow(valueUInt16_10.Item1, (byte)0b10100101);
                        ushortTable.SetOutArray(resultUInt16_10, 10, (byte)0b10100101);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_11 = ushortTable[11];
                        Vector128 <ushort> resultUInt16_11 = Sse2.ShuffleLow(valueUInt16_11.Item1, (byte)0b00010100);
                        ushortTable.SetOutArray(resultUInt16_11, 11, (byte)0b00010100);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_12 = ushortTable[12];
                        Vector128 <ushort> resultUInt16_12 = Sse2.ShuffleLow(valueUInt16_12.Item1, (byte)0b10000010);
                        ushortTable.SetOutArray(resultUInt16_12, 12, (byte)0b10000010);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_13 = ushortTable[13];
                        Vector128 <ushort> resultUInt16_13 = Sse2.ShuffleLow(valueUInt16_13.Item1, (byte)0b11001100);
                        ushortTable.SetOutArray(resultUInt16_13, 13, (byte)0b11001100);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_14 = ushortTable[14];
                        Vector128 <ushort> resultUInt16_14 = Sse2.ShuffleLow(valueUInt16_14.Item1, (byte)0b01100110);
                        ushortTable.SetOutArray(resultUInt16_14, 14, (byte)0b01100110);

                        (Vector128 <ushort>, Vector128 <ushort>)valueUInt16_15 = ushortTable[15];
                        Vector128 <ushort> resultUInt16_15 = Sse2.ShuffleLow(valueUInt16_15.Item1, (byte)0b10011001);
                        ushortTable.SetOutArray(resultUInt16_15, 15, (byte)0b10011001);


                        CheckMethodFive <short, short, byte> checkInt16 = (Span <short> x, byte imm, Span <short> z, Span <short> a) =>
                        {
                            bool result     = true;
                            int  halfLength = x.Length / 2;
                            for (int i = 0; i < x.Length; i++)
                            {
                                if (i >= halfLength)
                                {
                                    a[i] = x[i];
                                }
                                else
                                {
                                    a[i] = x[(imm & 0x03)];
                                    imm  = (byte)(imm >> 2);
                                }

                                if (z[i] != a[i])
                                {
                                    result = false;
                                }
                            }
                            return(result);
                        };

                        if (!shortTable.CheckResultShuffle(checkInt16))
                        {
                            PrintError8(shortTable, methodUnderTestName, "CheckResultShuffleHigh", checkInt16);
                            testResult = Fail;
                        }

                        CheckMethodFive <ushort, ushort, byte> checkUInt16 = (Span <ushort> x, byte imm, Span <ushort> z, Span <ushort> a) =>
                        {
                            bool result     = true;
                            int  halfLength = x.Length / 2;
                            for (int i = 0; i < x.Length; i++)
                            {
                                if (i >= halfLength)
                                {
                                    a[i] = x[i];
                                }
                                else
                                {
                                    a[i] = x[(imm & 0x03)];
                                    imm  = (byte)(imm >> 2);
                                }

                                if (z[i] != a[i])
                                {
                                    result = false;
                                }
                            }
                            return(result);
                        };

                        if (!ushortTable.CheckResultShuffle(checkUInt16))
                        {
                            PrintError8(ushortTable, methodUnderTestName, "CheckResultShuffleHigh", checkUInt16);
                            testResult = Fail;
                        }
                    }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }
            return(testResult);
        }