From: Jacek Blaszczynski Date: Wed, 28 Feb 2018 05:11:12 +0000 (+0100) Subject: Add Shuffle* Sse2 hardware intrinsics tests X-Git-Tag: accepted/tizen/unified/20190422.045933~2784^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0dfb89283bd666388990c2e60f8032bed3ebea88;p=platform%2Fupstream%2Fcoreclr.git Add Shuffle* Sse2 hardware intrinsics tests --- diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.cs new file mode 100644 index 0000000..59ac723 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.cs @@ -0,0 +1,297 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// + +using System; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace IntelHardwareIntrinsicTest +{ + internal static partial class Program + { + const int Pass = 100; + const int Fail = 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.Create(permuteDouble.Length)) + using (var intTable = TestTableTuvImmSse2.Create(permuteData.Length)) + using (var uintTable = TestTableTuvImmSse2.Create(permuteData.Length)) + { + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + doubleTable.inArray1, 16, (int i, int elNo) => + { + return (uint) i % 2; + }); + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + doubleTable.inArray2, 16, (int i, int elNo) => + { + return (uint) i % 2 + 10; + }); + + (Vector128, Vector128) valueDouble_0 = doubleTable[0]; + Vector128 resultDouble_0 = Sse2.Shuffle(valueDouble_0.Item1, valueDouble_0.Item2, (byte) 0b00); + doubleTable.SetOutArray(resultDouble_0, 0, (byte) 0b00); + + (Vector128, Vector128) valueDouble_1 = doubleTable[1]; + Vector128 resultDouble_1 = Sse2.Shuffle(valueDouble_1.Item1, valueDouble_1.Item2, (byte) 0b01); + doubleTable.SetOutArray(resultDouble_1, 1, (byte) 0b01); + + (Vector128, Vector128) valueDouble_2 = doubleTable[2]; + Vector128 resultDouble_2 = Sse2.Shuffle(valueDouble_2.Item1, valueDouble_2.Item2, (byte) 0b10); + doubleTable.SetOutArray(resultDouble_2, 2, (byte) 0b10); + + (Vector128, Vector128) valueDouble_3 = doubleTable[3]; + Vector128 resultDouble_3 = Sse2.Shuffle(valueDouble_3.Item1, valueDouble_3.Item2, (byte) 0b11); + doubleTable.SetOutArray(resultDouble_3, 3, (byte) 0b11); + + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + uintTable.inArray1, 16, (int i, int elNo) => + { + return (uint) i % 4; + }); + + (Vector128, Vector128) valueInt32_0 = intTable[0]; + Vector128 resultInt32_0 = Sse2.Shuffle(valueInt32_0.Item1, (byte) 0b11100100); + intTable.SetOutArray(resultInt32_0, 0, (byte) 0b11100100); + + (Vector128, Vector128) valueInt32_1 = intTable[1]; + Vector128 resultInt32_1 = Sse2.Shuffle(valueInt32_1.Item1, (byte) 0b00011011); + intTable.SetOutArray(resultInt32_1, 1, (byte) 0b00011011); + + (Vector128, Vector128) valueInt32_2 = intTable[2]; + Vector128 resultInt32_2 = Sse2.Shuffle(valueInt32_2.Item1, (byte) 0b00000000); + intTable.SetOutArray(resultInt32_2, 2, (byte) 0b00000000); + + (Vector128, Vector128) valueInt32_3 = intTable[3]; + Vector128 resultInt32_3 = Sse2.Shuffle(valueInt32_3.Item1, (byte) 0b11111111); + intTable.SetOutArray(resultInt32_3, 3, (byte) 0b11111111); + + (Vector128, Vector128) valueInt32_4 = intTable[4]; + Vector128 resultInt32_4 = Sse2.Shuffle(valueInt32_4.Item1, (byte) 0b01010101); + intTable.SetOutArray(resultInt32_4, 4, (byte) 0b01010101); + + (Vector128, Vector128) valueInt32_5 = intTable[5]; + Vector128 resultInt32_5 = Sse2.Shuffle(valueInt32_5.Item1, (byte) 0b10101010); + intTable.SetOutArray(resultInt32_5, 5, (byte) 0b10101010); + + (Vector128, Vector128) valueInt32_6 = intTable[6]; + Vector128 resultInt32_6 = Sse2.Shuffle(valueInt32_6.Item1, (byte) 0b11011000); + intTable.SetOutArray(resultInt32_6, 6, (byte) 0b11011000); + + (Vector128, Vector128) valueInt32_7 = intTable[7]; + Vector128 resultInt32_7 = Sse2.Shuffle(valueInt32_7.Item1, (byte) 0b00100111); + intTable.SetOutArray(resultInt32_7, 7, (byte) 0b00100111); + + (Vector128, Vector128) valueInt32_8 = intTable[8]; + Vector128 resultInt32_8 = Sse2.Shuffle(valueInt32_8.Item1, (byte) 0b10110001); + intTable.SetOutArray(resultInt32_8, 8, (byte) 0b10110001); + + (Vector128, Vector128) valueInt32_9 = intTable[9]; + Vector128 resultInt32_9 = Sse2.Shuffle(valueInt32_9.Item1, (byte) 0b11110000); + intTable.SetOutArray(resultInt32_9, 9, (byte) 0b11110000); + + (Vector128, Vector128) valueInt32_10 = intTable[10]; + Vector128 resultInt32_10 = Sse2.Shuffle(valueInt32_10.Item1, (byte) 0b10100101); + intTable.SetOutArray(resultInt32_10, 10, (byte) 0b10100101); + + (Vector128, Vector128) valueInt32_11 = intTable[11]; + Vector128 resultInt32_11 = Sse2.Shuffle(valueInt32_11.Item1, (byte) 0b00010100); + intTable.SetOutArray(resultInt32_11, 11, (byte) 0b00010100); + + (Vector128, Vector128) valueInt32_12 = intTable[12]; + Vector128 resultInt32_12 = Sse2.Shuffle(valueInt32_12.Item1, (byte) 0b10000010); + intTable.SetOutArray(resultInt32_12, 12, (byte) 0b10000010); + + (Vector128, Vector128) valueInt32_13 = intTable[13]; + Vector128 resultInt32_13 = Sse2.Shuffle(valueInt32_13.Item1, (byte) 0b11001100); + intTable.SetOutArray(resultInt32_13, 13, (byte) 0b11001100); + + (Vector128, Vector128) valueInt32_14 = intTable[14]; + Vector128 resultInt32_14 = Sse2.Shuffle(valueInt32_14.Item1, (byte) 0b01100110); + intTable.SetOutArray(resultInt32_14, 14, (byte) 0b01100110); + + (Vector128, Vector128) valueInt32_15 = intTable[15]; + Vector128 resultInt32_15 = Sse2.Shuffle(valueInt32_15.Item1, (byte) 0b10011001); + intTable.SetOutArray(resultInt32_15, 15, (byte) 0b10011001); + + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + uintTable.inArray1, 16, (int i, int elNo) => + { + return (uint) i % 4; + }); + + (Vector128, Vector128) valueUInt32_0 = uintTable[0]; + Vector128 resultUInt32_0 = Sse2.Shuffle(valueUInt32_0.Item1, (byte) 0b11100100); + uintTable.SetOutArray(resultUInt32_0, 0, (byte) 0b11100100); + + (Vector128, Vector128) valueUInt32_1 = uintTable[1]; + Vector128 resultUInt32_1 = Sse2.Shuffle(valueUInt32_1.Item1, (byte) 0b00011011); + uintTable.SetOutArray(resultUInt32_1, 1, (byte) 0b00011011); + + (Vector128, Vector128) valueUInt32_2 = uintTable[2]; + Vector128 resultUInt32_2 = Sse2.Shuffle(valueUInt32_2.Item1, (byte) 0b00000000); + uintTable.SetOutArray(resultUInt32_2, 2, (byte) 0b00000000); + + (Vector128, Vector128) valueUInt32_3 = uintTable[3]; + Vector128 resultUInt32_3 = Sse2.Shuffle(valueUInt32_3.Item1, (byte) 0b11111111); + uintTable.SetOutArray(resultUInt32_3, 3, (byte) 0b11111111); + + (Vector128, Vector128) valueUInt32_4 = uintTable[4]; + Vector128 resultUInt32_4 = Sse2.Shuffle(valueUInt32_4.Item1, (byte) 0b01010101); + uintTable.SetOutArray(resultUInt32_4, 4, (byte) 0b01010101); + + (Vector128, Vector128) valueUInt32_5 = uintTable[5]; + Vector128 resultUInt32_5 = Sse2.Shuffle(valueUInt32_5.Item1, (byte) 0b10101010); + uintTable.SetOutArray(resultUInt32_5, 5, (byte) 0b10101010); + + (Vector128, Vector128) valueUInt32_6 = uintTable[6]; + Vector128 resultUInt32_6 = Sse2.Shuffle(valueUInt32_6.Item1, (byte) 0b11011000); + uintTable.SetOutArray(resultUInt32_6, 6, (byte) 0b11011000); + + (Vector128, Vector128) valueUInt32_7 = uintTable[7]; + Vector128 resultUInt32_7 = Sse2.Shuffle(valueUInt32_7.Item1, (byte) 0b00100111); + uintTable.SetOutArray(resultUInt32_7, 7, (byte) 0b00100111); + + (Vector128, Vector128) valueUInt32_8 = uintTable[8]; + Vector128 resultUInt32_8 = Sse2.Shuffle(valueUInt32_8.Item1, (byte) 0b10110001); + uintTable.SetOutArray(resultUInt32_8, 8, (byte) 0b10110001); + + (Vector128, Vector128) valueUInt32_9 = uintTable[9]; + Vector128 resultUInt32_9 = Sse2.Shuffle(valueUInt32_9.Item1, (byte) 0b11110000); + uintTable.SetOutArray(resultUInt32_9, 9, (byte) 0b11110000); + + (Vector128, Vector128) valueUInt32_10 = uintTable[10]; + Vector128 resultUInt32_10 = Sse2.Shuffle(valueUInt32_10.Item1, (byte) 0b10100101); + uintTable.SetOutArray(resultUInt32_10, 10, (byte) 0b10100101); + + (Vector128, Vector128) valueUInt32_11 = uintTable[11]; + Vector128 resultUInt32_11 = Sse2.Shuffle(valueUInt32_11.Item1, (byte) 0b00010100); + uintTable.SetOutArray(resultUInt32_11, 11, (byte) 0b00010100); + + (Vector128, Vector128) valueUInt32_12 = uintTable[12]; + Vector128 resultUInt32_12 = Sse2.Shuffle(valueUInt32_12.Item1, (byte) 0b10000010); + uintTable.SetOutArray(resultUInt32_12, 12, (byte) 0b10000010); + + (Vector128, Vector128) valueUInt32_13 = uintTable[13]; + Vector128 resultUInt32_13 = Sse2.Shuffle(valueUInt32_13.Item1, (byte) 0b11001100); + uintTable.SetOutArray(resultUInt32_13, 13, (byte) 0b11001100); + + (Vector128, Vector128) valueUInt32_14 = uintTable[14]; + Vector128 resultUInt32_14 = Sse2.Shuffle(valueUInt32_14.Item1, (byte) 0b01100110); + uintTable.SetOutArray(resultUInt32_14, 14, (byte) 0b01100110); + + (Vector128, Vector128) valueUInt32_15 = uintTable[15]; + Vector128 resultUInt32_15 = Sse2.Shuffle(valueUInt32_15.Item1, (byte) 0b10011001); + uintTable.SetOutArray(resultUInt32_15, 15, (byte) 0b10011001); + + + CheckMethodFiveDouble checkDouble = + (Span x, Span y, byte imm, Span z, Span 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 checkInt32 = (Span x, byte imm, Span z, Span 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 checkUInt32 = (Span x, byte imm, Span z, Span 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; + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.tt b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.tt new file mode 100644 index 0000000..8922e3f --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.tt @@ -0,0 +1,225 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".cs" encoding="utf-8" #> +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// + +using System; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace IntelHardwareIntrinsicTest +{ + internal static partial class Program + { + const int Pass = 100; + const int Fail = 0; + + static unsafe int Main(string[] args) + { + int testResult = Pass; + int testCount = 16; + string methodUnderTestName = nameof(Sse2.Shuffle); + +<# + 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", + }; + +#> + + 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.Create(permuteDouble.Length)) + using (var intTable = TestTableTuvImmSse2.Create(permuteData.Length)) + using (var uintTable = TestTableTuvImmSse2.Create(permuteData.Length)) + { + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + doubleTable.inArray1, 16, (int i, int elNo) => + { + return (uint) i % 2; + }); + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + doubleTable.inArray2, 16, (int i, int elNo) => + { + return (uint) i % 2 + 10; + }); + +<# + for (int i = 0; i < permuteDouble.Length; i++) + { +#> + (Vector128, Vector128) valueDouble_<#= i #> = doubleTable[<#= i #>]; + Vector128 resultDouble_<#= i #> = Sse2.Shuffle(valueDouble_<#= i #>.Item1, valueDouble_<#= i #>.Item2, (byte) <#= permuteDouble[i] #>); + doubleTable.SetOutArray(resultDouble_<#= i #>, <#= i #>, (byte) <#= permuteDouble[i] #>); + +<# + + } +#> + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + uintTable.inArray1, 16, (int i, int elNo) => + { + return (uint) i % 4; + }); + +<# + for (int i = 0; i < permuteData.Length; i++) + { +#> + (Vector128, Vector128) valueInt32_<#= i #> = intTable[<#= i #>]; + Vector128 resultInt32_<#= i #> = Sse2.Shuffle(valueInt32_<#= i #>.Item1, (byte) <#= permuteData[i] #>); + intTable.SetOutArray(resultInt32_<#= i #>, <#= i #>, (byte) <#= permuteData[i] #>); + +<# + + } +#> + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + uintTable.inArray1, 16, (int i, int elNo) => + { + return (uint) i % 4; + }); + +<# + for (int i = 0; i < permuteData.Length; i++) + { +#> + (Vector128, Vector128) valueUInt32_<#= i #> = uintTable[<#= i #>]; + Vector128 resultUInt32_<#= i #> = Sse2.Shuffle(valueUInt32_<#= i #>.Item1, (byte) <#= permuteData[i] #>); + uintTable.SetOutArray(resultUInt32_<#= i #>, <#= i #>, (byte) <#= permuteData[i] #>); + +<# + + } +#> + + CheckMethodFiveDouble checkDouble = + (Span x, Span y, byte imm, Span z, Span 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 checkInt32 = (Span x, byte imm, Span z, Span 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 checkUInt32 = (Span x, byte imm, Span z, Span 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; + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.cs new file mode 100644 index 0000000..2bc3d0f --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.cs @@ -0,0 +1,266 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// + +using System; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace IntelHardwareIntrinsicTest +{ + internal static partial class Program + { + const short Pass = 100; + const short Fail = 0; + + static unsafe int Main(string[] args) + { + short testResult = Pass; + short testsCount = 16; + string methodUnderTestName = nameof(Sse2.ShuffleHigh); + + + + 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.Create(testsCount)) + using (var ushortTable = TestTableTuvImmSse2.Create(testsCount)) + { + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + shortTable.inArray1, 16, (int i, int elNo) => + { + return (short)(i % 8); + }); + + TestUtilities.InitializeWithConstValue(0, shortTable.inArray2); + + (Vector128, Vector128) valueInt16_0 = shortTable[0]; + Vector128 resultInt16_0 = Sse2.ShuffleHigh(valueInt16_0.Item1, (byte) 0b11100100); + shortTable.SetOutArray(resultInt16_0, 0, (byte) 0b11100100); + + (Vector128, Vector128) valueInt16_1 = shortTable[1]; + Vector128 resultInt16_1 = Sse2.ShuffleHigh(valueInt16_1.Item1, (byte) 0b00011011); + shortTable.SetOutArray(resultInt16_1, 1, (byte) 0b00011011); + + (Vector128, Vector128) valueInt16_2 = shortTable[2]; + Vector128 resultInt16_2 = Sse2.ShuffleHigh(valueInt16_2.Item1, (byte) 0b00000000); + shortTable.SetOutArray(resultInt16_2, 2, (byte) 0b00000000); + + (Vector128, Vector128) valueInt16_3 = shortTable[3]; + Vector128 resultInt16_3 = Sse2.ShuffleHigh(valueInt16_3.Item1, (byte) 0b11111111); + shortTable.SetOutArray(resultInt16_3, 3, (byte) 0b11111111); + + (Vector128, Vector128) valueInt16_4 = shortTable[4]; + Vector128 resultInt16_4 = Sse2.ShuffleHigh(valueInt16_4.Item1, (byte) 0b01010101); + shortTable.SetOutArray(resultInt16_4, 4, (byte) 0b01010101); + + (Vector128, Vector128) valueInt16_5 = shortTable[5]; + Vector128 resultInt16_5 = Sse2.ShuffleHigh(valueInt16_5.Item1, (byte) 0b10101010); + shortTable.SetOutArray(resultInt16_5, 5, (byte) 0b10101010); + + (Vector128, Vector128) valueInt16_6 = shortTable[6]; + Vector128 resultInt16_6 = Sse2.ShuffleHigh(valueInt16_6.Item1, (byte) 0b11011000); + shortTable.SetOutArray(resultInt16_6, 6, (byte) 0b11011000); + + (Vector128, Vector128) valueInt16_7 = shortTable[7]; + Vector128 resultInt16_7 = Sse2.ShuffleHigh(valueInt16_7.Item1, (byte) 0b00100111); + shortTable.SetOutArray(resultInt16_7, 7, (byte) 0b00100111); + + (Vector128, Vector128) valueInt16_8 = shortTable[8]; + Vector128 resultInt16_8 = Sse2.ShuffleHigh(valueInt16_8.Item1, (byte) 0b10110001); + shortTable.SetOutArray(resultInt16_8, 8, (byte) 0b10110001); + + (Vector128, Vector128) valueInt16_9 = shortTable[9]; + Vector128 resultInt16_9 = Sse2.ShuffleHigh(valueInt16_9.Item1, (byte) 0b11110000); + shortTable.SetOutArray(resultInt16_9, 9, (byte) 0b11110000); + + (Vector128, Vector128) valueInt16_10 = shortTable[10]; + Vector128 resultInt16_10 = Sse2.ShuffleHigh(valueInt16_10.Item1, (byte) 0b10100101); + shortTable.SetOutArray(resultInt16_10, 10, (byte) 0b10100101); + + (Vector128, Vector128) valueInt16_11 = shortTable[11]; + Vector128 resultInt16_11 = Sse2.ShuffleHigh(valueInt16_11.Item1, (byte) 0b00010100); + shortTable.SetOutArray(resultInt16_11, 11, (byte) 0b00010100); + + (Vector128, Vector128) valueInt16_12 = shortTable[12]; + Vector128 resultInt16_12 = Sse2.ShuffleHigh(valueInt16_12.Item1, (byte) 0b10000010); + shortTable.SetOutArray(resultInt16_12, 12, (byte) 0b10000010); + + (Vector128, Vector128) valueInt16_13 = shortTable[13]; + Vector128 resultInt16_13 = Sse2.ShuffleHigh(valueInt16_13.Item1, (byte) 0b11001100); + shortTable.SetOutArray(resultInt16_13, 13, (byte) 0b11001100); + + (Vector128, Vector128) valueInt16_14 = shortTable[14]; + Vector128 resultInt16_14 = Sse2.ShuffleHigh(valueInt16_14.Item1, (byte) 0b01100110); + shortTable.SetOutArray(resultInt16_14, 14, (byte) 0b01100110); + + (Vector128, Vector128) valueInt16_15 = shortTable[15]; + Vector128 resultInt16_15 = Sse2.ShuffleHigh(valueInt16_15.Item1, (byte) 0b10011001); + shortTable.SetOutArray(resultInt16_15, 15, (byte) 0b10011001); + + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + ushortTable.inArray1, 16, (int i, int elNo) => + { + return (ushort)(i % 8); + }); + + TestUtilities.InitializeWithConstValue(0, ushortTable.inArray2); + + + (Vector128, Vector128) valueUInt16_0 = ushortTable[0]; + Vector128 resultUInt16_0 = Sse2.ShuffleHigh(valueUInt16_0.Item1, (byte) 0b11100100); + ushortTable.SetOutArray(resultUInt16_0, 0, (byte) 0b11100100); + + (Vector128, Vector128) valueUInt16_1 = ushortTable[1]; + Vector128 resultUInt16_1 = Sse2.ShuffleHigh(valueUInt16_1.Item1, (byte) 0b00011011); + ushortTable.SetOutArray(resultUInt16_1, 1, (byte) 0b00011011); + + (Vector128, Vector128) valueUInt16_2 = ushortTable[2]; + Vector128 resultUInt16_2 = Sse2.ShuffleHigh(valueUInt16_2.Item1, (byte) 0b00000000); + ushortTable.SetOutArray(resultUInt16_2, 2, (byte) 0b00000000); + + (Vector128, Vector128) valueUInt16_3 = ushortTable[3]; + Vector128 resultUInt16_3 = Sse2.ShuffleHigh(valueUInt16_3.Item1, (byte) 0b11111111); + ushortTable.SetOutArray(resultUInt16_3, 3, (byte) 0b11111111); + + (Vector128, Vector128) valueUInt16_4 = ushortTable[4]; + Vector128 resultUInt16_4 = Sse2.ShuffleHigh(valueUInt16_4.Item1, (byte) 0b01010101); + ushortTable.SetOutArray(resultUInt16_4, 4, (byte) 0b01010101); + + (Vector128, Vector128) valueUInt16_5 = ushortTable[5]; + Vector128 resultUInt16_5 = Sse2.ShuffleHigh(valueUInt16_5.Item1, (byte) 0b10101010); + ushortTable.SetOutArray(resultUInt16_5, 5, (byte) 0b10101010); + + (Vector128, Vector128) valueUInt16_6 = ushortTable[6]; + Vector128 resultUInt16_6 = Sse2.ShuffleHigh(valueUInt16_6.Item1, (byte) 0b11011000); + ushortTable.SetOutArray(resultUInt16_6, 6, (byte) 0b11011000); + + (Vector128, Vector128) valueUInt16_7 = ushortTable[7]; + Vector128 resultUInt16_7 = Sse2.ShuffleHigh(valueUInt16_7.Item1, (byte) 0b00100111); + ushortTable.SetOutArray(resultUInt16_7, 7, (byte) 0b00100111); + + (Vector128, Vector128) valueUInt16_8 = ushortTable[8]; + Vector128 resultUInt16_8 = Sse2.ShuffleHigh(valueUInt16_8.Item1, (byte) 0b10110001); + ushortTable.SetOutArray(resultUInt16_8, 8, (byte) 0b10110001); + + (Vector128, Vector128) valueUInt16_9 = ushortTable[9]; + Vector128 resultUInt16_9 = Sse2.ShuffleHigh(valueUInt16_9.Item1, (byte) 0b11110000); + ushortTable.SetOutArray(resultUInt16_9, 9, (byte) 0b11110000); + + (Vector128, Vector128) valueUInt16_10 = ushortTable[10]; + Vector128 resultUInt16_10 = Sse2.ShuffleHigh(valueUInt16_10.Item1, (byte) 0b10100101); + ushortTable.SetOutArray(resultUInt16_10, 10, (byte) 0b10100101); + + (Vector128, Vector128) valueUInt16_11 = ushortTable[11]; + Vector128 resultUInt16_11 = Sse2.ShuffleHigh(valueUInt16_11.Item1, (byte) 0b00010100); + ushortTable.SetOutArray(resultUInt16_11, 11, (byte) 0b00010100); + + (Vector128, Vector128) valueUInt16_12 = ushortTable[12]; + Vector128 resultUInt16_12 = Sse2.ShuffleHigh(valueUInt16_12.Item1, (byte) 0b10000010); + ushortTable.SetOutArray(resultUInt16_12, 12, (byte) 0b10000010); + + (Vector128, Vector128) valueUInt16_13 = ushortTable[13]; + Vector128 resultUInt16_13 = Sse2.ShuffleHigh(valueUInt16_13.Item1, (byte) 0b11001100); + ushortTable.SetOutArray(resultUInt16_13, 13, (byte) 0b11001100); + + (Vector128, Vector128) valueUInt16_14 = ushortTable[14]; + Vector128 resultUInt16_14 = Sse2.ShuffleHigh(valueUInt16_14.Item1, (byte) 0b01100110); + ushortTable.SetOutArray(resultUInt16_14, 14, (byte) 0b01100110); + + (Vector128, Vector128) valueUInt16_15 = ushortTable[15]; + Vector128 resultUInt16_15 = Sse2.ShuffleHigh(valueUInt16_15.Item1, (byte) 0b10011001); + ushortTable.SetOutArray(resultUInt16_15, 15, (byte) 0b10011001); + + + CheckMethodFive checkInt16 = (Span x, byte imm, Span z, Span 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) + 4]; + 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 checkUInt16 = (Span x, byte imm, Span z, Span 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) + 4]; + 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; + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.tt b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.tt new file mode 100644 index 0000000..b94c24c --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.tt @@ -0,0 +1,190 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".cs" encoding="utf-8" #> +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// + +using System; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace IntelHardwareIntrinsicTest +{ + internal static partial class Program + { + const short Pass = 100; + const short Fail = 0; + + static unsafe int Main(string[] args) + { + short testResult = Pass; + short testsCount = 16; + string methodUnderTestName = nameof(Sse2.ShuffleHigh); + +<# + 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) + }; + +#> + + + 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.Create(testsCount)) + using (var ushortTable = TestTableTuvImmSse2.Create(testsCount)) + { + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + shortTable.inArray1, 16, (int i, int elNo) => + { + return (short)(i % 8); + }); + + TestUtilities.InitializeWithConstValue(0, shortTable.inArray2); + +<# + for (int i = 0; i < permuteData.Length; i++) + { +#> + (Vector128, Vector128) valueInt16_<#= i #> = shortTable[<#= i #>]; + Vector128 resultInt16_<#= i #> = Sse2.ShuffleHigh(valueInt16_<#= i #>.Item1, (byte) <#= permuteData[i] #>); + shortTable.SetOutArray(resultInt16_<#= i #>, <#= i #>, (byte) <#= permuteData[i] #>); + +<# + + } +#> + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + ushortTable.inArray1, 16, (int i, int elNo) => + { + return (ushort)(i % 8); + }); + + TestUtilities.InitializeWithConstValue(0, ushortTable.inArray2); + + +<# + for (int i = 0; i < permuteData.Length; i++) + { +#> + (Vector128, Vector128) valueUInt16_<#= i #> = ushortTable[<#= i #>]; + Vector128 resultUInt16_<#= i #> = Sse2.ShuffleHigh(valueUInt16_<#= i #>.Item1, (byte) <#= permuteData[i] #>); + ushortTable.SetOutArray(resultUInt16_<#= i #>, <#= i #>, (byte) <#= permuteData[i] #>); + +<# + + } +#> + + CheckMethodFive checkInt16 = (Span x, byte imm, Span z, Span 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) + 4]; + 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 checkUInt16 = (Span x, byte imm, Span z, Span 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) + 4]; + 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; + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh_r.csproj new file mode 100644 index 0000000..208548c --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh_r.csproj @@ -0,0 +1,49 @@ + + + + + Debug + AnyCPU + 2.0 + {5B060A38-515A-4C2C-9DFB-2EC23B20FCA1} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + + False + + + + None + + + + + + + + + + True + True + ShuffleHigh.tt + + + + + + TextTemplatingFileGenerator + ShuffleHigh.cs + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh_ro.csproj new file mode 100644 index 0000000..a9a3a47 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh_ro.csproj @@ -0,0 +1,48 @@ + + + + + Debug + AnyCPU + 2.0 + {47111150-B83B-44A1-AB94-807BEF42E5E0} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + + False + + + + None + True + + + + + + + + True + True + ShuffleHigh.tt + + + + + + TextTemplatingFileGenerator + ShuffleHigh.cs + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.cs new file mode 100644 index 0000000..cfbf02b --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.cs @@ -0,0 +1,266 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// + +using System; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace IntelHardwareIntrinsicTest +{ + internal static partial class Program + { + const short Pass = 100; + const short Fail = 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.Create(testsCount)) + using (var ushortTable = TestTableTuvImmSse2.Create(testsCount)) + { + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + shortTable.inArray1, 16, (int i, int elNo) => + { + return (short)(i % 8); + }); + + TestUtilities.InitializeWithConstValue(0, shortTable.inArray2); + + (Vector128, Vector128) valueInt16_0 = shortTable[0]; + Vector128 resultInt16_0 = Sse2.ShuffleLow(valueInt16_0.Item1, (byte) 0b11100100); + shortTable.SetOutArray(resultInt16_0, 0, (byte) 0b11100100); + + (Vector128, Vector128) valueInt16_1 = shortTable[1]; + Vector128 resultInt16_1 = Sse2.ShuffleLow(valueInt16_1.Item1, (byte) 0b00011011); + shortTable.SetOutArray(resultInt16_1, 1, (byte) 0b00011011); + + (Vector128, Vector128) valueInt16_2 = shortTable[2]; + Vector128 resultInt16_2 = Sse2.ShuffleLow(valueInt16_2.Item1, (byte) 0b00000000); + shortTable.SetOutArray(resultInt16_2, 2, (byte) 0b00000000); + + (Vector128, Vector128) valueInt16_3 = shortTable[3]; + Vector128 resultInt16_3 = Sse2.ShuffleLow(valueInt16_3.Item1, (byte) 0b11111111); + shortTable.SetOutArray(resultInt16_3, 3, (byte) 0b11111111); + + (Vector128, Vector128) valueInt16_4 = shortTable[4]; + Vector128 resultInt16_4 = Sse2.ShuffleLow(valueInt16_4.Item1, (byte) 0b01010101); + shortTable.SetOutArray(resultInt16_4, 4, (byte) 0b01010101); + + (Vector128, Vector128) valueInt16_5 = shortTable[5]; + Vector128 resultInt16_5 = Sse2.ShuffleLow(valueInt16_5.Item1, (byte) 0b10101010); + shortTable.SetOutArray(resultInt16_5, 5, (byte) 0b10101010); + + (Vector128, Vector128) valueInt16_6 = shortTable[6]; + Vector128 resultInt16_6 = Sse2.ShuffleLow(valueInt16_6.Item1, (byte) 0b11011000); + shortTable.SetOutArray(resultInt16_6, 6, (byte) 0b11011000); + + (Vector128, Vector128) valueInt16_7 = shortTable[7]; + Vector128 resultInt16_7 = Sse2.ShuffleLow(valueInt16_7.Item1, (byte) 0b00100111); + shortTable.SetOutArray(resultInt16_7, 7, (byte) 0b00100111); + + (Vector128, Vector128) valueInt16_8 = shortTable[8]; + Vector128 resultInt16_8 = Sse2.ShuffleLow(valueInt16_8.Item1, (byte) 0b10110001); + shortTable.SetOutArray(resultInt16_8, 8, (byte) 0b10110001); + + (Vector128, Vector128) valueInt16_9 = shortTable[9]; + Vector128 resultInt16_9 = Sse2.ShuffleLow(valueInt16_9.Item1, (byte) 0b11110000); + shortTable.SetOutArray(resultInt16_9, 9, (byte) 0b11110000); + + (Vector128, Vector128) valueInt16_10 = shortTable[10]; + Vector128 resultInt16_10 = Sse2.ShuffleLow(valueInt16_10.Item1, (byte) 0b10100101); + shortTable.SetOutArray(resultInt16_10, 10, (byte) 0b10100101); + + (Vector128, Vector128) valueInt16_11 = shortTable[11]; + Vector128 resultInt16_11 = Sse2.ShuffleLow(valueInt16_11.Item1, (byte) 0b00010100); + shortTable.SetOutArray(resultInt16_11, 11, (byte) 0b00010100); + + (Vector128, Vector128) valueInt16_12 = shortTable[12]; + Vector128 resultInt16_12 = Sse2.ShuffleLow(valueInt16_12.Item1, (byte) 0b10000010); + shortTable.SetOutArray(resultInt16_12, 12, (byte) 0b10000010); + + (Vector128, Vector128) valueInt16_13 = shortTable[13]; + Vector128 resultInt16_13 = Sse2.ShuffleLow(valueInt16_13.Item1, (byte) 0b11001100); + shortTable.SetOutArray(resultInt16_13, 13, (byte) 0b11001100); + + (Vector128, Vector128) valueInt16_14 = shortTable[14]; + Vector128 resultInt16_14 = Sse2.ShuffleLow(valueInt16_14.Item1, (byte) 0b01100110); + shortTable.SetOutArray(resultInt16_14, 14, (byte) 0b01100110); + + (Vector128, Vector128) valueInt16_15 = shortTable[15]; + Vector128 resultInt16_15 = Sse2.ShuffleLow(valueInt16_15.Item1, (byte) 0b10011001); + shortTable.SetOutArray(resultInt16_15, 15, (byte) 0b10011001); + + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + ushortTable.inArray1, 16, (int i, int elNo) => + { + return (ushort)(i % 8); + }); + + TestUtilities.InitializeWithConstValue(0, ushortTable.inArray2); + + + (Vector128, Vector128) valueUInt16_0 = ushortTable[0]; + Vector128 resultUInt16_0 = Sse2.ShuffleLow(valueUInt16_0.Item1, (byte) 0b11100100); + ushortTable.SetOutArray(resultUInt16_0, 0, (byte) 0b11100100); + + (Vector128, Vector128) valueUInt16_1 = ushortTable[1]; + Vector128 resultUInt16_1 = Sse2.ShuffleLow(valueUInt16_1.Item1, (byte) 0b00011011); + ushortTable.SetOutArray(resultUInt16_1, 1, (byte) 0b00011011); + + (Vector128, Vector128) valueUInt16_2 = ushortTable[2]; + Vector128 resultUInt16_2 = Sse2.ShuffleLow(valueUInt16_2.Item1, (byte) 0b00000000); + ushortTable.SetOutArray(resultUInt16_2, 2, (byte) 0b00000000); + + (Vector128, Vector128) valueUInt16_3 = ushortTable[3]; + Vector128 resultUInt16_3 = Sse2.ShuffleLow(valueUInt16_3.Item1, (byte) 0b11111111); + ushortTable.SetOutArray(resultUInt16_3, 3, (byte) 0b11111111); + + (Vector128, Vector128) valueUInt16_4 = ushortTable[4]; + Vector128 resultUInt16_4 = Sse2.ShuffleLow(valueUInt16_4.Item1, (byte) 0b01010101); + ushortTable.SetOutArray(resultUInt16_4, 4, (byte) 0b01010101); + + (Vector128, Vector128) valueUInt16_5 = ushortTable[5]; + Vector128 resultUInt16_5 = Sse2.ShuffleLow(valueUInt16_5.Item1, (byte) 0b10101010); + ushortTable.SetOutArray(resultUInt16_5, 5, (byte) 0b10101010); + + (Vector128, Vector128) valueUInt16_6 = ushortTable[6]; + Vector128 resultUInt16_6 = Sse2.ShuffleLow(valueUInt16_6.Item1, (byte) 0b11011000); + ushortTable.SetOutArray(resultUInt16_6, 6, (byte) 0b11011000); + + (Vector128, Vector128) valueUInt16_7 = ushortTable[7]; + Vector128 resultUInt16_7 = Sse2.ShuffleLow(valueUInt16_7.Item1, (byte) 0b00100111); + ushortTable.SetOutArray(resultUInt16_7, 7, (byte) 0b00100111); + + (Vector128, Vector128) valueUInt16_8 = ushortTable[8]; + Vector128 resultUInt16_8 = Sse2.ShuffleLow(valueUInt16_8.Item1, (byte) 0b10110001); + ushortTable.SetOutArray(resultUInt16_8, 8, (byte) 0b10110001); + + (Vector128, Vector128) valueUInt16_9 = ushortTable[9]; + Vector128 resultUInt16_9 = Sse2.ShuffleLow(valueUInt16_9.Item1, (byte) 0b11110000); + ushortTable.SetOutArray(resultUInt16_9, 9, (byte) 0b11110000); + + (Vector128, Vector128) valueUInt16_10 = ushortTable[10]; + Vector128 resultUInt16_10 = Sse2.ShuffleLow(valueUInt16_10.Item1, (byte) 0b10100101); + ushortTable.SetOutArray(resultUInt16_10, 10, (byte) 0b10100101); + + (Vector128, Vector128) valueUInt16_11 = ushortTable[11]; + Vector128 resultUInt16_11 = Sse2.ShuffleLow(valueUInt16_11.Item1, (byte) 0b00010100); + ushortTable.SetOutArray(resultUInt16_11, 11, (byte) 0b00010100); + + (Vector128, Vector128) valueUInt16_12 = ushortTable[12]; + Vector128 resultUInt16_12 = Sse2.ShuffleLow(valueUInt16_12.Item1, (byte) 0b10000010); + ushortTable.SetOutArray(resultUInt16_12, 12, (byte) 0b10000010); + + (Vector128, Vector128) valueUInt16_13 = ushortTable[13]; + Vector128 resultUInt16_13 = Sse2.ShuffleLow(valueUInt16_13.Item1, (byte) 0b11001100); + ushortTable.SetOutArray(resultUInt16_13, 13, (byte) 0b11001100); + + (Vector128, Vector128) valueUInt16_14 = ushortTable[14]; + Vector128 resultUInt16_14 = Sse2.ShuffleLow(valueUInt16_14.Item1, (byte) 0b01100110); + ushortTable.SetOutArray(resultUInt16_14, 14, (byte) 0b01100110); + + (Vector128, Vector128) valueUInt16_15 = ushortTable[15]; + Vector128 resultUInt16_15 = Sse2.ShuffleLow(valueUInt16_15.Item1, (byte) 0b10011001); + ushortTable.SetOutArray(resultUInt16_15, 15, (byte) 0b10011001); + + + CheckMethodFive checkInt16 = (Span x, byte imm, Span z, Span 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 checkUInt16 = (Span x, byte imm, Span z, Span 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; + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.tt b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.tt new file mode 100644 index 0000000..04327da --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.tt @@ -0,0 +1,190 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".cs" encoding="utf-8" #> +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// + +using System; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace IntelHardwareIntrinsicTest +{ + internal static partial class Program + { + const short Pass = 100; + const short Fail = 0; + + static unsafe int Main(string[] args) + { + short testResult = Pass; + short testsCount = 16; + string methodUnderTestName = nameof(Sse2.ShuffleLow); + +<# + 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) + }; + +#> + + + 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.Create(testsCount)) + using (var ushortTable = TestTableTuvImmSse2.Create(testsCount)) + { + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + shortTable.inArray1, 16, (int i, int elNo) => + { + return (short)(i % 8); + }); + + TestUtilities.InitializeWithConstValue(0, shortTable.inArray2); + +<# + for (int i = 0; i < permuteData.Length; i++) + { +#> + (Vector128, Vector128) valueInt16_<#= i #> = shortTable[<#= i #>]; + Vector128 resultInt16_<#= i #> = Sse2.ShuffleLow(valueInt16_<#= i #>.Item1, (byte) <#= permuteData[i] #>); + shortTable.SetOutArray(resultInt16_<#= i #>, <#= i #>, (byte) <#= permuteData[i] #>); + +<# + + } +#> + + // Vector128 tests + + TestUtilities.InitializeWithElementNumberingModuloVectorLength( + ushortTable.inArray1, 16, (int i, int elNo) => + { + return (ushort)(i % 8); + }); + + TestUtilities.InitializeWithConstValue(0, ushortTable.inArray2); + + +<# + for (int i = 0; i < permuteData.Length; i++) + { +#> + (Vector128, Vector128) valueUInt16_<#= i #> = ushortTable[<#= i #>]; + Vector128 resultUInt16_<#= i #> = Sse2.ShuffleLow(valueUInt16_<#= i #>.Item1, (byte) <#= permuteData[i] #>); + ushortTable.SetOutArray(resultUInt16_<#= i #>, <#= i #>, (byte) <#= permuteData[i] #>); + +<# + + } +#> + + CheckMethodFive checkInt16 = (Span x, byte imm, Span z, Span 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 checkUInt16 = (Span x, byte imm, Span z, Span 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; + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow_r.csproj new file mode 100644 index 0000000..8369d6a --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow_r.csproj @@ -0,0 +1,49 @@ + + + + + Debug + AnyCPU + 2.0 + {3DCFB777-8A32-443E-ABD9-4636600D2B4F} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + + False + + + + None + + + + + + + + + + True + True + ShuffleLow.tt + + + + + + TextTemplatingFileGenerator + ShuffleLow.cs + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow_ro.csproj new file mode 100644 index 0000000..721cd05 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow_ro.csproj @@ -0,0 +1,48 @@ + + + + + Debug + AnyCPU + 2.0 + {A9DAC473-F5CB-4DA9-ADE4-2F9EB53FC4A8} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + + False + + + + None + True + + + + + + + + True + True + ShuffleLow.tt + + + + + + TextTemplatingFileGenerator + ShuffleLow.cs + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle_r.csproj new file mode 100644 index 0000000..6cfebb7 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle_r.csproj @@ -0,0 +1,49 @@ + + + + + Debug + AnyCPU + 2.0 + {D25DF7E1-96B0-454A-A5BE-70C26BE49559} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + + False + + + + None + + + + + + + + + + True + True + Shuffle.tt + + + + + + TextTemplatingFileGenerator + Shuffle.cs + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle_ro.csproj new file mode 100644 index 0000000..46f64bc --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle_ro.csproj @@ -0,0 +1,48 @@ + + + + + Debug + AnyCPU + 2.0 + {695760F3-DA13-4227-9ED6-AD8C5E5D88C6} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + + False + + + + None + True + + + + + + + + True + True + Shuffle.tt + + + + + + TextTemplatingFileGenerator + Shuffle.cs + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/TestTableSse2.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/TestTableSse2.cs index e3fc3e8..00b7e00 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/TestTableSse2.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/TestTableSse2.cs @@ -14,16 +14,24 @@ namespace IntelHardwareIntrinsicTest { public delegate bool CheckMethod(T x, T y, T z, ref T c); + public delegate bool CheckMethodSpan(Span x, Span y, Span z, Span a); + public delegate bool CheckMethodTwo(T x, T y, U z, ref U c); public delegate bool CheckMethodTwo(T x, V y, U z, ref U c); + public delegate bool CheckMethodTwoSpan(Span x, V y, U z, ref U c); + public delegate bool CheckMethodThree(T x1, T x2, T y1, T y2, U z, ref U c); public delegate bool CheckMethodFour(T x1, T x2, U z1, U z2, ref U c1, ref U c2); public delegate bool CheckMethodFive(T x1, T x2, T y1, T y2, U z1, U z2, ref U c1, ref U c2); + public delegate bool CheckMethodFive(Span x, V imm, Span z, Span a); + + public delegate bool CheckMethodFiveDouble(Span x, Span y, V imm, Span z, Span a); + public delegate bool CheckMethodFourTFourU( ValueTuple x, ValueTuple y, @@ -51,6 +59,9 @@ namespace IntelHardwareIntrinsicTest public delegate bool CheckMethodEightImm( Span x, T value, V i, Span z, Span a); + public delegate bool CheckMethodEightInsert( + Span x, T value, V i, Span z, Span a); + public delegate bool CheckMethodSixteen( ValueTuple> x, ValueTuple> y, @@ -73,7 +84,9 @@ namespace IntelHardwareIntrinsicTest public enum InitMode { Undefined = 0, - NumberFirstVectors = 0b00000001 + NumberFirstVectors = 0b00000001, + NumberAllVectors = 0b00000010, + UseConstValue = 0b00000100, } public unsafe struct TestTableSse2 : IDisposable where T : struct @@ -129,6 +142,18 @@ namespace IntelHardwareIntrinsicTest return (inArray1[index], inArray2[index], outArray[index], checkArray[index]); } + public Memory GetAssignmentData(int index) + { + _index = index; + return new Memory(inArray2, index * _stepSize, _stepSize); + } + + public ValueTuple, Memory, Memory, Memory> GetAssignmentDataPoint(int index) + { + return (new Memory(inArray1, index, _stepSize), new Memory(inArray2, index, _stepSize), + new Memory(outArray, index, _stepSize), new Memory(outArray, index, _stepSize)); + } + public static TestTableSse2 Create(int lengthInVectors) { int length = _stepSize / Marshal.SizeOf() * lengthInVectors; @@ -195,6 +220,24 @@ namespace IntelHardwareIntrinsicTest return result; } + public bool CheckResult(CheckMethodSpan check) + { + bool result = true; + for (int i = 0; i < inArray1.Length; i += _stepSize) + { + var x = new Span(inArray1, i, _stepSize); + var y = new Span(inArray2, i, _stepSize); + var z = new Span(inArray2, i, _stepSize); + var a = new Span(inArray2, i, _stepSize); + + if (!check(x, y, z, a)) + { + result = false; + } + } + return result; + } + public void Dispose() { _inHandle1.Free(); @@ -802,6 +845,12 @@ namespace IntelHardwareIntrinsicTest Unsafe.Write((byte*)OutArrayPtr + (_index * _stepSize), value); } + public void SetOutArray(U value, int index = -1) + { + index = index < 0 ? _index : index; + outArray[_index] = value; + } + public Vector128 this[int index] { get @@ -1050,7 +1099,8 @@ namespace IntelHardwareIntrinsicTest { private const int _stepSize = 16; private static int s_tSize; - private static int s_ElementCount; + public static int ElementCount; + private int _lengthInVectors; private GCHandle _inHandle1; private GCHandle _inHandle2; @@ -1073,12 +1123,26 @@ namespace IntelHardwareIntrinsicTest public void* CheckArrayPtr => _checkHandle.AddrOfPinnedObject().ToPointer(); public Vector128 Vector1 => Unsafe.Read>((byte*)InArray1Ptr + (_index * _stepSize)); - public T Value => Unsafe.Read((byte*)InArray2Ptr + (_index)); - public V Immediate => Unsafe.Read((byte*)ImmArrayPtr + (_index)); + public T Value => inArray2[_index]; + public V Immediate => immArray[_index]; public Vector128 Vector3 => Unsafe.Read>((byte*)OutArrayPtr + (_index * _stepSize)); public Vector128 Vector4 => Unsafe.Read>((byte*)CheckArrayPtr + (_index * _stepSize)); - public int Index { get => _index; set => _index = value; } + public int Index + { + get => _index; + set + { + if (value < 0 || value >= _lengthInVectors) + { + throw new IndexOutOfRangeException(); + } + else + { + _index = value; + } + } + } public void SetOutArray(Vector128 value, int index = -1) { @@ -1086,12 +1150,26 @@ namespace IntelHardwareIntrinsicTest Unsafe.Write((byte*)OutArrayPtr + (_index * _stepSize), value); } + public void SetOutArray(U value, V imm, int index = -1) + { + index = index < 0 ? _index : index; + outArray[_index] = value; + immArray[_index] = imm; + } + + public void SetOutArray(Vector128 value1, int index, V value2) + { + Index = index; + Unsafe.Write((byte*)OutArrayPtr + (index * _stepSize), value1); + immArray[index] = value2; + } + public (Vector128, T) this[int index] { get { - _index = index; - return (Vector1, Value); + Index = index; + return (Vector1, inArray2[index]); } } @@ -1103,6 +1181,12 @@ namespace IntelHardwareIntrinsicTest (checkArray[index], checkArray[index + 1], checkArray[index + 2], checkArray[index + 3], checkArray[index + 4], checkArray[index + 5], checkArray[index + 6], checkArray[index + 7])); } + public (Memory, V, U, U) GetExtractDataPoint(int index) + { + int ii = index / ElementCount; + return (new Memory(inArray1, index, ElementCount), immArray[ii], outArray[ii], checkArray[ii]); + } + public static TestTableImmSse2 Create(int lengthInVectors, double tSizeMultiplier = 1.0) { return new TestTableImmSse2(lengthInVectors, tSizeMultiplier); @@ -1111,8 +1195,9 @@ namespace IntelHardwareIntrinsicTest public TestTableImmSse2(int lengthInVectors, double tSizeMultiplier = 1.0, bool initialize = true) { s_tSize = Marshal.SizeOf(); - s_ElementCount = _stepSize / s_tSize; - int length = s_ElementCount * lengthInVectors; + ElementCount = _stepSize / s_tSize; + _lengthInVectors = lengthInVectors; + int length = ElementCount * lengthInVectors; inArray1 = new T[length]; inArray2 = new T[lengthInVectors]; immArray = new V[lengthInVectors]; @@ -1243,12 +1328,46 @@ namespace IntelHardwareIntrinsicTest } } + public bool CheckResultExtract(CheckMethodTwoSpan check) + { + int topIndex = inArray1.Length - ElementCount + 1; + bool result = true; + for (int i = 0; i < topIndex; i += ElementCount) + { + int ii = i / ElementCount; + var x = new Span(inArray1, i, ElementCount); + if (!check(x, immArray[ii], outArray[ii], ref checkArray[ii])) + { + result = false; + } + } + return result; + } + + public bool CheckResultInsert(CheckMethodEightInsert check) + { + bool result = true; + for (int i = 0; i < inArray1.Length - 1; i+= ElementCount) + { + var x = new Span(inArray1, i, ElementCount); + var z = new Span(outArray, i, ElementCount); + var a = new Span(checkArray, i, ElementCount); + int ii = i / ElementCount; + + if (!check(x, inArray2[ii], immArray[ii], z, a)) + { + result = false; + } + } + return result; + } + public bool CheckResultImm(CheckMethodEightImm check) { bool result = true; + int elNo = _stepSize / s_tSize; for (int i = 0; i < inArray1.Length; i++) { - int elNo = _stepSize / s_tSize; if (!check( new Span(inArray1, Index * elNo, elNo), inArray2[i], immArray[i], @@ -1522,6 +1641,398 @@ namespace IntelHardwareIntrinsicTest } } + public unsafe struct TestTableTuvImmSse2 : IDisposable + where T : struct + where U : struct + where V : struct + { + private const int _vectorSize = 16; + private static int _tSize; + private static int _elementsNo; + private static int _lengthInVectors; + + private GCHandle _inHandle1; + private GCHandle _inHandle2; + private GCHandle _immHandle; + private GCHandle _outHandle; + private GCHandle _checkHandle; + + private int _index; + + public T[] inArray1; + public T[] inArray2; + public V[] immArray; + public U[] outArray; + public U[] checkArray; + + public void* InArray1Ptr => _inHandle1.AddrOfPinnedObject().ToPointer(); + public void* InArray2Ptr => _inHandle2.AddrOfPinnedObject().ToPointer(); + public void* ImmArrayPtr => _inHandle2.AddrOfPinnedObject().ToPointer(); + public void* OutArrayPtr => _outHandle.AddrOfPinnedObject().ToPointer(); + public void* CheckArrayPtr => _checkHandle.AddrOfPinnedObject().ToPointer(); + + public Vector128 Vector1 => Unsafe.Read>((byte*)InArray1Ptr + (_index * _vectorSize)); + public Vector128 Vector2 => Unsafe.Read>((byte*)InArray2Ptr + (_index * _vectorSize)); + public V Immediate => Unsafe.Read((byte*)ImmArrayPtr + (_index)); + public Vector128 Vector3 => Unsafe.Read>((byte*)OutArrayPtr + (_index * _vectorSize)); + public Vector128 Vector4 => Unsafe.Read>((byte*)CheckArrayPtr + (_index * _vectorSize)); + + public int Index + { + get => _index; + set + { + if (value < 0 || value >= _lengthInVectors) + { + throw new IndexOutOfRangeException(); + } + else + { + _index = value; + } + } + } + + public void SetOutArray(Vector128 value, int index = -1) + { + index = index < 0 ? _index : index; + Unsafe.Write((byte*)OutArrayPtr + (_index * _vectorSize), value); + } + + public void SetOutArray(Vector128 value1, int index, V value2) + { + Index = index; + Unsafe.Write((byte*)OutArrayPtr + (Index * _vectorSize), value1); + immArray[Index] = value2; + } + + public (Vector128, Vector128) this[int index] + { + get + { + _index = index; + return (Vector1, Vector2); + } + } + + public unsafe ValueTuple GetQuad22DataPoint(int index) + { + return (inArray1[index], immArray[index / (_vectorSize / _tSize)], outArray[index], checkArray[index]); + } + + public ((T, T), (T, T), V, (U, U), (U, U)) GetDoubleImmDataPoint(int index) + { + return ((inArray1[index], inArray1[index + 1]), + (inArray2[index], inArray2[index + 1]), + immArray[index / 2], + (outArray[index], outArray[index + 1]), + (checkArray[index], checkArray[index + 1])); + } + + public ((T, T, T, T), V, (U, U, U, U), (U, U, U, U)) GetQuadImmDataPoint(int index) + { + return ((inArray1[index], inArray1[index + 1], inArray1[index + 2], inArray1[index + 3]), + immArray[index / 4], + (outArray[index], outArray[index + 1], outArray[index + 2], outArray[index + 3]), + (checkArray[index], checkArray[index + 1], checkArray[index + 2], checkArray[index + 3])); + + } + + public ((T, T, T, T, T, T, T, T), T, V, (U, U, U, U, U, U, U, U), (U, U, U, U, U, U, U, U)) GetOctaImmDataPoint(int index) + { + return ((inArray1[index], inArray1[index + 1], inArray1[index + 2], inArray1[index + 3], inArray1[index + 4], inArray1[index + 5], inArray1[index + 6], inArray1[index + 7]), + inArray2[index / 8], immArray[index / 8], + (outArray[index], outArray[index + 1], outArray[index + 2], outArray[index + 3], outArray[index + 4], outArray[index + 5], outArray[index + 6], outArray[index + 7]), + (checkArray[index], checkArray[index + 1], checkArray[index + 2], checkArray[index + 3], checkArray[index + 4], checkArray[index + 5], checkArray[index + 6], checkArray[index + 7])); + } + + public static TestTableTuvImmSse2 Create(int lengthInVectors, double tSizeMultiplier = 1.0) + { + return new TestTableTuvImmSse2(lengthInVectors, tSizeMultiplier); + } + + public TestTableTuvImmSse2(int lengthInVectors, double tSizeMultiplier = 1.0, bool initialize = true) + { + _lengthInVectors = lengthInVectors; + _tSize = Marshal.SizeOf(); + _elementsNo = _vectorSize / _tSize; + int length = _elementsNo * lengthInVectors; + inArray1 = new T[length]; + inArray2 = new T[length]; + immArray = new V[lengthInVectors]; + outArray = new U[(int)(length * (1 / tSizeMultiplier))]; + checkArray = new U[(int)(length * (1 / tSizeMultiplier))]; + _index = 0; + _inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned); + _inHandle2 = GCHandle.Alloc(inArray2, GCHandleType.Pinned); + _immHandle = GCHandle.Alloc(inArray2, GCHandleType.Pinned); + _outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned); + _checkHandle = GCHandle.Alloc(checkArray, GCHandleType.Pinned); + if (initialize) + { + Initialize(); + } + } + + public void Initialize(InitMode mode = InitMode.Undefined) + { + TestUtilities.InitializeData(inArray1, inArray2, mode, InArray1Ptr, InArray2Ptr); + } + + public bool CheckResultImm(CheckMethodTwo check) + { + bool result = true; + for (int i = 0; i < inArray1.Length; i++) + { + int elNo = _vectorSize / _tSize; + if (!check( + inArray1[i], immArray[i / elNo], + outArray[i], ref checkArray[i])) + { + result = false; + } + } + return result; + } + + public bool CheckResultImm(CheckMethodEightImm check) + { + bool result = true; + for (int i = 0; i < inArray1.Length; i++) + { + if (!check( + new Span(inArray1, Index * _elementsNo, _elementsNo), + inArray2[i], immArray[i], + new Span(outArray, Index * _elementsNo, _elementsNo), + new Span(checkArray, Index * _elementsNo, _elementsNo))) + { + result = false; + } + } + return result; + } + + public bool CheckResultShuffle(CheckMethodFive check) + { + bool result = true; + for (int i = 0; i < inArray1.Length; i += _elementsNo) + { + if (!check( + new Span(inArray1, i, _elementsNo), + immArray[i / _elementsNo], + new Span(outArray, i, _elementsNo), + new Span(checkArray, i, _elementsNo))) + { + result = false; + } + } + return result; + } + + public bool CheckResultShuffle(CheckMethodFiveDouble check) + { + bool result = true; + for (int i = 0; i < inArray1.Length; i += _elementsNo) + { + if (!check( + new Span(inArray1, i, _elementsNo), + new Span(inArray2, i, _elementsNo), + immArray[i / _elementsNo], + new Span(outArray, i, _elementsNo), + new Span(checkArray, i, _elementsNo))) + { + result = false; + } + } + return result; + } + + public void Dispose() + { + _inHandle1.Free(); + _inHandle2.Free(); + _immHandle.Free(); + _outHandle.Free(); + _checkHandle.Free(); + } + } + + public static class TestUtilities + { + public static unsafe void InitializeData( + T[] inArray1, T[] inArray2, InitMode mode = InitMode.Undefined, + void* InArray1Ptr = null, void* InArray2Ptr = null, T value = default(T)) + { + if (mode == InitMode.Undefined) + { + InitializeWithRandomData(inArray1, inArray2, InArray1Ptr, InArray2Ptr); + } + else if (mode == InitMode.NumberFirstVectors) + { + InitializeWithContinuosIndependentNumbering(inArray1, inArray2); + } + else if (mode == InitMode.UseConstValue) + { + InitializeWithConstValue(value, inArray1); + } + else if (mode == InitMode.NumberAllVectors) + { + } + } + + public static unsafe void InitializeWithRandomData( + T[] inArray1, T[] inArray2, void* InArray1Ptr = null, void* InArray2Ptr = null) + { + InitializeWithRandomData(inArray1, InArray1Ptr); + InitializeWithRandomData(inArray2, InArray2Ptr); + } + + public static unsafe void InitializeWithRandomData( + T[] array, void* arrayPtr = null) + { + Random random = new Random(unchecked((int)(DateTime.UtcNow.Ticks & 0x00000000ffffffffl))); + if (array is double[]) + { + var array1 = array as double[]; + for (int i = 0; i < array1.Length; i++) + { + array1[i] = random.NextDouble() * random.Next(); + } + } + else if (array is float[]) + { + var arrayFloat1 = array as float[]; + for (int i = 0; i < arrayFloat1.Length; i++) + { + arrayFloat1[i] = (float)(random.NextDouble() * random.Next(ushort.MaxValue)); + } + } + else + { + if (arrayPtr == null) + throw new ArgumentNullException(nameof(arrayPtr)); + + int tSize = Marshal.SizeOf(); + random.NextBytes(new Span(((byte*)arrayPtr), array.Length * tSize)); + } + } + + public static void InitializeWithContinuosIndependentNumbering(T[] array1, T[] array2) + { + if (array1 is double[] doubleArray1) + { + double[] doubleArray2 = array2 as double[]; + for (double i = 0.0, j = 10000.0; i < doubleArray1.Length; i++, j++) + { + doubleArray1[(int)i] = i; + doubleArray2[(int)i] = j; + } + } + else if (array1 is float[] floatArray1) + { + float[] floatArray2 = array2 as float[]; + for (float i = 0.0f, j = 10000.0f; i < floatArray1.Length; i++, j++) + { + floatArray1[(int)i] = i; + floatArray2[(int)i] = j; + } + } + else if (array1 is byte[] byteArray1) + { + byte[] byteArray2 = array2 as byte[]; + for (byte i = 0, j = 100; i < byteArray1.Length; i++, j++) + { + byteArray1[i] = i; + byteArray2[i] = j; + } + } + else if (array1 is sbyte[] sbyteArray1) + { + sbyte[] sbyteArray2 = array2 as sbyte[]; + for (sbyte i = 0, j = 100; i < sbyteArray1.Length; i++, j++) + { + sbyteArray1[i] = i; + sbyteArray2[i] = j; + } + } + else if (array1 is short[] shortArray1) + { + short[] shortArray2 = array2 as short[]; + for (short i = 0, j = 10000; i < shortArray1.Length; i++, j++) + { + shortArray1[i] = i; + shortArray2[i] = j; + } + + } + else if (array1 is ushort[] ushortArray1) + { + ushort[] ushortArray2 = array2 as ushort[]; + for (ushort i = 0, j = 10000; i < ushortArray1.Length; i++, j++) + { + ushortArray1[i] = i; + ushortArray2[i] = j; + } + } + else if (array1 is int[] intArray1) + { + int[] intArray2 = array2 as int[]; + for (int i = 0, j = 10000; i < intArray1.Length; i++, j++) + { + intArray1[i] = i; + intArray2[i] = j; + } + } + else if (array1 is uint[] uintArray1) + { + uint[] uintArray2 = array2 as uint[]; + for (uint i = 0, j = 10000; i < uintArray1.Length; i++, j++) + { + uintArray1[i] = i; + uintArray2[i] = j; + } + } + else if (array1 is long[] longArray1) + { + long[] longArray2 = array2 as long[]; + for (long i = 0, j = 10000; i < longArray1.Length; i++, j++) + { + longArray1[i] = i; + longArray2[i] = j; + } + } + else if (array1 is ulong[] ulongArray1) + { + ulong[] ulongArray2 = array2 as ulong[]; + for (uint i = 0, j = 10000; i < ulongArray1.Length; i++, j++) + { + ulongArray1[i] = i; + ulongArray2[i] = j; + } + } + } + + public static void InitializeWithConstValue(T value, T[] array) + { + if (array == null) + throw new ArgumentNullException(nameof(array)); + + for (int i = 0; i < array.Length; i++) + { + array[i] = value; + } + } + + public static void InitializeWithElementNumberingModuloVectorLength(T[] array, int vectorSize, Func function) + { + int elNo = vectorSize / Marshal.SizeOf(); + for (int i = 0; i < array.Length; i++) + { + array[i] = function(i, elNo); + } + } + } + public enum SpecialCheck { Undefined = 0, @@ -1571,6 +2082,20 @@ namespace IntelHardwareIntrinsicTest Console.WriteLine("\n"); } + private static void PrintError(TestTableSse2 testTable, string functionName = "", string testFuncString = "", + CheckMethodSpan check = null) where T : struct + { + PrintErrorHeaderTu(functionName, testFuncString); + for (int i = 0; i < testTable.outArray.Length; i++) + { + (Memory, Memory, Memory, Memory) item = testTable.GetAssignmentDataPoint(i); + Console.Write( + $"({(PrintMemory(item.Item1), PrintMemory(item.Item2), PrintMemory(item.Item3), PrintMemory(item.Item4))})" + + (check != null ? $"->{check(item.Item1.Span, item.Item2.Span, item.Item3.Span, item.Item4.Span)}, " : ", ")); + } + Console.WriteLine("\n"); + } + private static void PrintError(TestTableSse2 testTable, string functionName = "", string testFuncString = "", CheckMethodTwo check = null) where T : struct where U : struct { @@ -1595,6 +2120,18 @@ namespace IntelHardwareIntrinsicTest Console.WriteLine(); } + private static void PrintError(TestTableImmSse2 testTable, string functionName = "", string testFuncString = "", + CheckMethodTwoSpan check = null) where T : struct where U : struct where V : struct + { + PrintErrorHeaderTuv(functionName, testFuncString); + for (int i = 0; i < testTable.inArray1.Length; i+= TestTableImmSse2.ElementCount) + { + (Memory, V, U, U) item = testTable.GetExtractDataPoint(i); + Console.Write($"({item})" + (check != null ? $"->{check(item.Item1.Span, item.Item2, item.Item3, ref item.Item4)}, " : ", ")); + } + Console.WriteLine(); + } + private static void PrintError(TestTableSse2 testTable, string functionName = "", string testFuncString = "", CheckMethodThree check = null) where T : struct where U : struct { @@ -1653,6 +2190,61 @@ namespace IntelHardwareIntrinsicTest Console.WriteLine(); } + private static void PrintError(TestTableTuvImmSse2 testTable, string functionName = "", string testFuncString = "", + CheckMethodFive check = null) where T : struct where U : struct where V : struct + { + PrintErrorHeaderTu(functionName, testFuncString); + for (int i = 0; i < testTable.inArray1.Length - 3; i += 4) + { + // (T, T, T, T, U, U, U, U) + var item = testTable.GetQuadImmDataPoint(i); + Console.Write($"({item}), "); + } + Console.WriteLine(); + } + + private static void PrintError8(TestTableTuvImmSse2 testTable, string functionName = "", string testFuncString = "", + CheckMethodFive check = null) where T : struct where U : struct where V : struct + { + byte ConvertToByte(V value) + { + if (value is byte result) + return result; + else + return 0; + } + + PrintErrorHeaderTu(functionName, testFuncString); + for (int i = 0; i < testTable.inArray1.Length - 7; i += 8) + { + // ((T, T, T, T, T, T, T, T), T, V, (U, U, U, U, U, U, U, U), (U, U, U, U, U, U, U, U)) + var item = testTable.GetOctaImmDataPoint(i); + Console.Write($"((x{item.Item1}, y({item.Item2}), imm({Convert.ToString(ConvertToByte(item.Item3), 2)}), z{item.Item4}, a{item.Item5})), "); + } + Console.WriteLine(); + } + + private static void PrintError8(TestTableTuvImmSse2 testTable, string functionName = "", string testFuncString = "", + CheckMethodFiveDouble check = null) where T : struct where U : struct where V : struct + { + byte ConvertToByte(V value) + { + if (value is byte result) + return result; + else + return 0; + } + + PrintErrorHeaderTu(functionName, testFuncString); + for (int i = 0; i < testTable.inArray1.Length - 7; i += 8) + { + // ((T, T), (T, T), V, (U, U), (U, U)) + var item = testTable.GetDoubleImmDataPoint(i); + Console.Write($"((x{item.Item1}, y({item.Item2}), imm({Convert.ToString(ConvertToByte(item.Item3), 2)}), z{item.Item4}, a{item.Item5})), "); + } + Console.WriteLine(); + } + private static void PrintError(TestTableSse2 testTable, string functionName = "", string testFuncString = "", CheckMethodSix check = null) where T : struct where U : struct { @@ -1716,6 +2308,19 @@ namespace IntelHardwareIntrinsicTest Console.WriteLine(); } + private static void PrintError(TestTableImmSse2 testTable, string functionName = "", string testFuncString = "", + CheckMethodEightInsert check = null) where T : struct where U : struct where V : struct + { + PrintErrorHeaderTu(functionName, testFuncString); + for (int i = 0, j = 0; i < testTable.inArray1.Length - 7 && j < testTable.inArray2.Length; i += 8, j += 1) + { + // ((T, T, T, T, T, T, T, T), T, V, (U, U, U, U, U, U, U, U), (U, U, U, U, U, U, U, U)) + var item = testTable.GetOctaImmDataPoint(i); + Console.Write($"({item})"); + } + Console.WriteLine(); + } + private static void PrintError(TestTableSse2 testTable, string functionName = "", string testFuncString = "", CheckMethodEightOfTEightOfU check = null) where T : struct where U : struct {