diff options
author | Fei Peng <fei.peng@intel.com> | 2019-01-16 09:48:43 -0800 |
---|---|---|
committer | Carol Eidt <carol.eidt@microsoft.com> | 2019-01-16 09:48:43 -0800 |
commit | 3e47f4dcc66d013daf9ac1ede15eaf0d8fac7c69 (patch) | |
tree | 891bfa58aacf5c6d3621ae1839ac1a32f368da3f /tests | |
parent | 5a81049245062814e3581b763c89c8a49058c8f5 (diff) | |
download | coreclr-3e47f4dcc66d013daf9ac1ede15eaf0d8fac7c69.tar.gz coreclr-3e47f4dcc66d013daf9ac1ede15eaf0d8fac7c69.tar.bz2 coreclr-3e47f4dcc66d013daf9ac1ede15eaf0d8fac7c69.zip |
Fix imm-operand encoding for SSE/AVX instructions (#21999)
* Move more SSE2 tests to the template
* Improve Insert test template to involve more codegen situations
* Fix imm-operand encoding for SSE/AVX instructions
Diffstat (limited to 'tests')
54 files changed, 7719 insertions, 2557 deletions
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_21855/GitHub_21855.cs b/tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_21855/GitHub_21855.cs new file mode 100644 index 0000000000..eda63172d2 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_21855/GitHub_21855.cs @@ -0,0 +1,30 @@ +using System; +using System.Runtime.Intrinsics.X86; +using System.Runtime.Intrinsics; +using System.Runtime.CompilerServices; + +namespace GitHub_21855 +{ + class GitHub_21855 + { + + static int Main(string[] args) + { + bool pass =true; + if (Sse2.IsSupported) + { + Vector128<byte> src = Vector128.Create((byte)1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); + Vector128<uint> srcAsUInt32 = src.AsUInt32(); + Vector128<uint> result = Sse2.Shuffle(srcAsUInt32, _MM_SHUFFLE(0, 1, 2, 3)); + pass = result.Equals(Sse2.Shuffle(srcAsUInt32, (byte)(0 << 6 | 1 << 4 | 2 << 2 | 3))); + } + return pass ? 100 : 0; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static byte _MM_SHUFFLE(int a, int b, int c, int d) + { + return (byte)(a << 6 | b << 4 | c << 2 | d); + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_21855/GitHub_21855_r.csproj index 86ccf0d498..5275f6c929 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask_r.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_21855/GitHub_21855_r.csproj @@ -1,19 +1,18 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{EC7AD883-41EA-4BDC-BFBE-77A78B727D76}</ProjectGuid> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> <OutputType>Exe</OutputType> <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> <AllowUnsafeBlocks>true</AllowUnsafeBlocks> </PropertyGroup> <!-- Default configurations to help VS understand the configurations --> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> <ItemGroup> <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> @@ -28,9 +27,8 @@ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> </ItemGroup> <ItemGroup> - <Compile Include="MoveMask.cs" /> + <Compile Include="GitHub_21855.cs" /> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> - <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> - </PropertyGroup> -</Project>
\ No newline at end of file + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> +</Project> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_21855/GitHub_21855_ro.csproj index 33b1ce1804..f9f31fcebc 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask_ro.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_21855/GitHub_21855_ro.csproj @@ -1,19 +1,18 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{4D4CC0B8-3894-4F6F-868B-C93A7B722B5C}</ProjectGuid> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> <OutputType>Exe</OutputType> <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> <AllowUnsafeBlocks>true</AllowUnsafeBlocks> </PropertyGroup> <!-- Default configurations to help VS understand the configurations --> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> <ItemGroup> <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> @@ -28,9 +27,8 @@ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> </ItemGroup> <ItemGroup> - <Compile Include="MoveMask.cs" /> + <Compile Include="GitHub_21855.cs" /> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> - <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> - </PropertyGroup> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> </Project> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx b/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx index 2b5ecfa1f8..df7cd05883 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx +++ b/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx @@ -188,10 +188,10 @@ private static readonly (string templateFileName, Dictionary<string, string> tem ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "DivideScalar", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Double", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Double", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["NextValueOp2"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(left[0] / right[0]) != BitConverter.DoubleToInt64Bits(result[0])", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(left[i]) != BitConverter.DoubleToInt64Bits(result[i])"}), ("ExtractScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Extract", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "(result[0] != firstOp[1])"}), ("ExtractScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Extract", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "(result[0] != firstOp[1])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Data"] = "(short)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(short)0", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != 0)"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Data"] = "(ushort)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(ushort)0", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != 0)"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Data"] = "(short)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(short)0", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != 0)"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Data"] = "(ushort)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(ushort)0", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != 0)"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Data"] = "(short)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(short)0", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != 0)"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Data"] = "(ushort)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(ushort)0", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != 0)"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Data"] = "(short)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(short)0", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != 0)"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Data"] = "(ushort)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(ushort)0", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != 0)"}), ("LoadUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["Method"] = "LoadVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Double", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(firstOp[0]) != BitConverter.DoubleToInt64Bits(result[0])", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(firstOp[i]) != BitConverter.DoubleToInt64Bits(result[i])"}), ("LoadUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["Method"] = "LoadVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Byte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "firstOp[0] != result[0]", ["ValidateRemainingResults"] = "firstOp[i] != result[i]"}), ("LoadUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["Method"] = "LoadVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "SByte", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "SByte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "firstOp[0] != result[0]", ["ValidateRemainingResults"] = "firstOp[i] != result[i]"}), @@ -219,6 +219,9 @@ private static readonly (string templateFileName, Dictionary<string, string> tem ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "MultiplyAddAdjacent", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "result[0] != Math.Clamp(((right[1] * left[1]) + (right[0] * left[0])), int.MinValue, int.MaxValue)", ["ValidateRemainingResults"] = "result[i] != Math.Clamp(((right[(i * 2) + 1] * left[(i * 2) + 1]) + (right[i * 2] * left[i * 2])), int.MinValue, int.MaxValue)"}), ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "MultiplyLow", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "result[0] != BitConverter.ToInt16(BitConverter.GetBytes(((int)(left[0])) * right[0]), 0)", ["ValidateRemainingResults"] = "result[i] != BitConverter.ToInt16(BitConverter.GetBytes(((int)(left[i])) * right[i]), 0)"}), ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "MultiplyLow", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "result[0] != BitConverter.ToUInt16(BitConverter.GetBytes(((uint)(left[0])) * right[0]), 0)", ["ValidateRemainingResults"] = "result[i] != BitConverter.ToUInt16(BitConverter.GetBytes(((uint)(left[i])) * right[i]), 0)"}), + ("SimdScalarUnOpConvTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "MoveMask", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Byte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "((firstOp[0] & 128) == 0) != ((result & 1) == 0)"}), + ("SimdScalarUnOpConvTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "MoveMask", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "SByte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "(firstOp[0] >= 0) != ((result & 1) == 0)"}), + ("SimdScalarUnOpConvTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "MoveMask", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Double", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "(BitConverter.DoubleToInt64Bits(firstOp[0]) >= 0) != ((result & 1) == 0)"}), ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Or", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Double", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Double", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["NextValueOp2"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "(BitConverter.DoubleToInt64Bits(left[0]) | BitConverter.DoubleToInt64Bits(right[0])) != BitConverter.DoubleToInt64Bits(result[0])", ["ValidateRemainingResults"] = "(BitConverter.DoubleToInt64Bits(left[i]) | BitConverter.DoubleToInt64Bits(right[i])) != BitConverter.DoubleToInt64Bits(result[i])"}), ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Or", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Byte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Byte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "(byte)(left[0] | right[0]) != result[0]", ["ValidateRemainingResults"] = "(byte)(left[i] | right[i]) != result[i]"}), ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Or", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "(short)(left[0] | right[0]) != result[0]", ["ValidateRemainingResults"] = "(short)(left[i] | right[i]) != result[i]"}), @@ -275,6 +278,20 @@ private static readonly (string templateFileName, Dictionary<string, string> tem ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShiftRightLogical128BitLane", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt32", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(uint)8", ["ValidateFirstResult"] = "result[0] != 134217728", ["ValidateRemainingResults"] = "(i == 3 ? result[i] != 0 : result[i] != 134217728)"}), ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShiftRightLogical128BitLane", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int64", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(long)8", ["ValidateFirstResult"] = "result[0] != 576460752303423488L", ["ValidateRemainingResults"] = "(result[i] != 0)"}), ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShiftRightLogical128BitLane", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt64", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(ulong)8", ["ValidateFirstResult"] = "result[0] != 576460752303423488UL", ["ValidateRemainingResults"] = "(result[i] != 0)"}), + ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Shuffle", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int32", ["Imm"] = "0", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "firstOp[0] != result[0]", ["ValidateRemainingResults"] = "firstOp[0] != result[i]"}), + ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Shuffle", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt32", ["Imm"] = "0", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "firstOp[0] != result[0]", ["ValidateRemainingResults"] = "firstOp[0] != result[i]"}), + ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Shuffle", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int32", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "firstOp[1] != result[0]", ["ValidateRemainingResults"] = "firstOp[0] != result[i]"}), + ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Shuffle", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt32", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "firstOp[1] != result[0]", ["ValidateRemainingResults"] = "firstOp[0] != result[i]"}), + ("ImmBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Shuffle", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Double", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Double", ["Imm"] = "0", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["NextValueOp2"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(left[0])", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(right[0])"}), + ("ImmBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Shuffle", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Double", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Double", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["NextValueOp2"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(left[1])", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(right[0])"}), + ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShuffleHigh", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Imm"] = "0", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "firstOp[0] != result[0]", ["ValidateRemainingResults"] = "(i <= 3 ? (firstOp[i] != result[i]) : (firstOp[4] != result[i]))"}), + ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShuffleHigh", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Imm"] = "0", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "firstOp[0] != result[0]", ["ValidateRemainingResults"] = "(i <= 3 ? (firstOp[i] != result[i]) : (firstOp[4] != result[i]))"}), + ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShuffleLow", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Imm"] = "0", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "firstOp[0] != result[0]", ["ValidateRemainingResults"] = "(i <= 3 ? (firstOp[0] != result[i]) : (firstOp[i] != result[i]))"}), + ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShuffleLow", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Imm"] = "0", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "firstOp[0] != result[0]", ["ValidateRemainingResults"] = "(i <= 3 ? (firstOp[0] != result[i]) : (firstOp[i] != result[i]))"}), + ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShuffleHigh", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "firstOp[0] != result[0]", ["ValidateRemainingResults"] = "(i <= 3 ? (firstOp[i] != result[i]) : (firstOp[5] != result[4]))"}), + ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShuffleHigh", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "firstOp[0] != result[0]", ["ValidateRemainingResults"] = "(i <= 3 ? (firstOp[i] != result[i]) : (firstOp[5] != result[4]))"}), + ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShuffleLow", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "firstOp[1] != result[0]", ["ValidateRemainingResults"] = "(i <= 3 ? (firstOp[0] != result[i]) : (firstOp[i] != result[i]))"}), + ("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShuffleLow", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "firstOp[1] != result[0]", ["ValidateRemainingResults"] = "(i <= 3 ? (firstOp[0] != result[i]) : (firstOp[i] != result[i]))"}), ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Subtract", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Double", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Double", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["NextValueOp2"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(left[0] - right[0]) != BitConverter.DoubleToInt64Bits(result[0])", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(left[i] - right[i]) != BitConverter.DoubleToInt64Bits(result[i])"}), ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Subtract", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Byte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Byte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "(byte)(left[0] - right[0]) != result[0]", ["ValidateRemainingResults"] = "(byte)(left[i] - right[i]) != result[i]"}), ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Subtract", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "(short)(left[0] - right[0]) != result[0]", ["ValidateRemainingResults"] = "(short)(left[i] - right[i]) != result[i]"}), @@ -407,10 +424,10 @@ private static readonly (string templateFileName, Dictionary<string, string> tem ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "FloorScalar", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Double", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Double", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Double", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["NextValueOp2"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(Math.Floor(right[0]))", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(left[i])"}), ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse", ["Method"] = "FloorScalar", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(MathF.Floor(right[0]))", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i])"}), ("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["Imm"] = "0", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(right[0])", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Byte", ["Data"] = "(byte)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != firstOp[i])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "SByte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "SByte", ["Data"] = "(sbyte)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != firstOp[i])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int32", ["Data"] = "(int)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != firstOp[i])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt32", ["Data"] = "(uint)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != firstOp[i])"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Byte", ["Data"] = "(byte)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != firstOp[i])"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "SByte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "SByte", ["Data"] = "(sbyte)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != firstOp[i])"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int32", ["Data"] = "(int)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != firstOp[i])"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt32", ["Data"] = "(uint)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != firstOp[i])"}), ("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(0.0f)", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i])"}), ("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["Imm"] = "2", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(right[0])", ["ValidateRemainingResults"] = "i == 1 ? BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(0.0f) : BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i])"}), ("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["Imm"] = "4", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(right[0])", ["ValidateRemainingResults"] = "i == 2 ? BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(0.0f) : BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i])"}), @@ -420,10 +437,10 @@ private static readonly (string templateFileName, Dictionary<string, string> tem ("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["Imm"] = "48", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(left[0])", ["ValidateRemainingResults"] = "i == 3 ? BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(right[0]) : BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i])"}), ("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["Imm"] = "64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(right[1])", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i])"}), ("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["Imm"] = "128", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(right[2])", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Byte", ["Data"] = "(byte)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != firstOp[i])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "SByte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "SByte", ["Data"] = "(sbyte)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != firstOp[i])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int32", ["Data"] = "(int)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != firstOp[i])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt32", ["Data"] = "(uint)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != firstOp[i])"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Byte", ["Data"] = "(byte)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != firstOp[i])"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "SByte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "SByte", ["Data"] = "(sbyte)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != firstOp[i])"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int32", ["Data"] = "(int)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != firstOp[i])"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt32", ["Data"] = "(uint)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != firstOp[i])"}), ("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(0.0f)", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i])"}), ("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["Imm"] = "192", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(right[3])", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i])"}), ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "Max", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "result[0] != Math.Max(left[0], right[0])", ["ValidateRemainingResults"] = "result[i] != Math.Max(left[i], right[i])"}), @@ -513,10 +530,10 @@ private static readonly (string templateFileName, Dictionary<string, string> tem ("ExtractScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41.X64", ["LoadIsa"] = "Sse2", ["Method"] = "Extract", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt64", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "(result[0] != firstOp[1])"}), ("ExtractScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41.X64", ["LoadIsa"] = "Sse2", ["Method"] = "Extract", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int64", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "(result[0] != firstOp[1])"}), ("ExtractScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41.X64", ["LoadIsa"] = "Sse2", ["Method"] = "Extract", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt64", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "(result[0] != firstOp[1])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41.X64", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int64", ["Data"] = "(long)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != firstOp[i])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41.X64", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt64", ["Data"] = "(ulong)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != firstOp[i])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41.X64", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int64", ["Data"] = "(long)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != firstOp[i])"}), - ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41.X64", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt64", ["Data"] = "(ulong)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != 2 : result[i] != firstOp[i])"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41.X64", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int64", ["Data"] = "(long)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != firstOp[i])"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41.X64", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt64", ["Data"] = "(ulong)2", ["Imm"] = "129", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != firstOp[i])"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41.X64", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int64", ["Data"] = "(long)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != firstOp[i])"}), + ("InsertScalarTest.template", new Dictionary<string, string> { ["Isa"] = "Sse41.X64", ["LoadIsa"] = "Sse2", ["Method"] = "Insert", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt64", ["Data"] = "(ulong)2", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "(i == 1 ? result[i] != scalarData : result[i] != firstOp[i])"}), }; private static readonly (string templateFileName, Dictionary<string, string> templateData)[] Sse42Inputs = new [] diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Shared/InsertScalarTest.template b/tests/src/JIT/HardwareIntrinsics/X86/Shared/InsertScalarTest.template index 38db52458c..685b498e58 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Shared/InsertScalarTest.template +++ b/tests/src/JIT/HardwareIntrinsics/X86/Shared/InsertScalarTest.template @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if ({LoadIsa}.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if ({LoadIsa}.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if ({LoadIsa}.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public {Op1VectorType}<{Op1BaseType}> _fld; + public {Op1BaseType} _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = {NextValueOp1}; } Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref testStruct._fld), ref Unsafe.As<{Op1BaseType}, byte>(ref _data[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>()); + testStruct._scalarFldData = {Data}; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__{Method}{RetBaseType}{Imm} testClass) { - var result = {Isa}.{Method}(_fld, {Data}, {Imm}); + var result = {Isa}.{Method}(_fld, _scalarFldData, {Imm}); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>() / sizeof({RetBaseType}); private static {Op1BaseType}[] _data = new {Op1BaseType}[Op1ElementCount]; + private static {Op1BaseType} _scalarClsData = {Data}; private static {Op1VectorType}<{Op1BaseType}> _clsVar; private {Op1VectorType}<{Op1BaseType}> _fld; + private {Op1BaseType} _scalarFldData = {Data}; private SimpleUnaryOpTest__DataTable<{RetBaseType}, {Op1BaseType}> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = {Isa}.{Method}( Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, {Data}, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + {Op1BaseType} localData = {Data}; + {Op1BaseType}* ptr = &localData; + var result = {Isa}.{Method}( {LoadIsa}.Load{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArrayPtr)), - {Data}, + *ptr, {Imm} ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + {Op1BaseType} localData = {Data}; + {Op1BaseType}* ptr = &localData; + var result = {Isa}.{Method}( {LoadIsa}.LoadAligned{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArrayPtr)), - {Data}, + *ptr, {Imm} ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof({Isa}).GetMethod(nameof({Isa}.{Method}), new Type[] { typeof({Op1VectorType}<{Op1BaseType}>), typeof({RetBaseType}), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, ({RetVectorType}<{RetBaseType}>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, {Data}, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, ({RetVectorType}<{RetBaseType}>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, {Data}, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, ({RetVectorType}<{RetBaseType}>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, {Data}, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = {Isa}.{Method}( _clsVar, - {Data}, + _scalarClsData, {Imm} ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + {Op1BaseType} localData = {Data}; var firstOp = Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArrayPtr); - var result = {Isa}.{Method}(firstOp, {Data}, {Imm}); + var result = {Isa}.{Method}(firstOp, localData, {Imm}); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + {Op1BaseType} localData = {Data}; + var firstOp = {LoadIsa}.Load{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArrayPtr)); - var result = {Isa}.{Method}(firstOp, {Data}, {Imm}); + var result = {Isa}.{Method}(firstOp, localData, {Imm}); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + {Op1BaseType} localData = {Data}; + var firstOp = {LoadIsa}.LoadAligned{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArrayPtr)); - var result = {Isa}.{Method}(firstOp, {Data}, {Imm}); + var result = {Isa}.{Method}(firstOp, localData, {Imm}); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__{Method}{RetBaseType}{Imm}(); - var result = {Isa}.{Method}(test._fld, {Data}, {Imm}); + var result = {Isa}.{Method}(test._fld, test._scalarFldData, {Imm}); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = {Isa}.{Method}(_fld, {Data}, {Imm}); + var result = {Isa}.{Method}(_fld, _scalarFldData, {Imm}); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = {Isa}.{Method}(test._fld, {Data}, {Imm}); + var result = {Isa}.{Method}(test._fld, test._scalarFldData, {Imm}); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult({Op1VectorType}<{Op1BaseType}> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult({Op1VectorType}<{Op1BaseType}> firstOp, {Op1BaseType} scalarData, void* result, [CallerMemberName] string method = "") { {Op1BaseType}[] inArray = new {Op1BaseType}[Op1ElementCount]; {RetBaseType}[] outArray = new {RetBaseType}[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, {Op1BaseType} scalarData, void* result, [CallerMemberName] string method = "") { {Op1BaseType}[] inArray = new {Op1BaseType}[Op1ElementCount]; {RetBaseType}[] outArray = new {RetBaseType}[RetElementCount]; @@ -362,10 +379,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult({Op1BaseType}[] firstOp, {RetBaseType}[] result, [CallerMemberName] string method = "") + private void ValidateResult({Op1BaseType}[] firstOp, {Op1BaseType} scalarData, {RetBaseType}[] result, [CallerMemberName] string method = "") { bool succeeded = true; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.Int16.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.Int16.1.cs index 8f9331fab2..d1c31f5554 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.Int16.1.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.Int16.1.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<Int16> _fld; + public Int16 _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = (short)0; } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref testStruct._fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + testStruct._scalarFldData = (short)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertInt161 testClass) { - var result = Sse2.Insert(_fld, (short)2, 1); + var result = Sse2.Insert(_fld, _scalarFldData, 1); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16); private static Int16[] _data = new Int16[Op1ElementCount]; + private static Int16 _scalarClsData = (short)2; private static Vector128<Int16> _clsVar; private Vector128<Int16> _fld; + private Int16 _scalarFldData = (short)2; private SimpleUnaryOpTest__DataTable<Int16, Int16> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse2.Insert( Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (short)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + Int16 localData = (short)2; + Int16* ptr = &localData; + var result = Sse2.Insert( Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)), - (short)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + Int16 localData = (short)2; + Int16* ptr = &localData; + var result = Sse2.Insert( Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)), - (short)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse2).GetMethod(nameof(Sse2.Insert), new Type[] { typeof(Vector128<Int16>), typeof(Int16), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (short)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (short)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (short)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse2.Insert( _clsVar, - (short)2, + _scalarClsData, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + Int16 localData = (short)2; var firstOp = Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr); - var result = Sse2.Insert(firstOp, (short)2, 1); + var result = Sse2.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + Int16 localData = (short)2; + var firstOp = Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)); - var result = Sse2.Insert(firstOp, (short)2, 1); + var result = Sse2.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + Int16 localData = (short)2; + var firstOp = Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)); - var result = Sse2.Insert(firstOp, (short)2, 1); + var result = Sse2.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertInt161(); - var result = Sse2.Insert(test._fld, (short)2, 1); + var result = Sse2.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse2.Insert(_fld, (short)2, 1); + var result = Sse2.Insert(_fld, _scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse2.Insert(test._fld, (short)2, 1); + var result = Sse2.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Int16> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Int16> firstOp, Int16 scalarData, void* result, [CallerMemberName] string method = "") { Int16[] inArray = new Int16[Op1ElementCount]; Int16[] outArray = new Int16[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, Int16 scalarData, void* result, [CallerMemberName] string method = "") { Int16[] inArray = new Int16[Op1ElementCount]; Int16[] outArray = new Int16[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int16>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(Int16[] firstOp, Int16[] result, [CallerMemberName] string method = "") + private void ValidateResult(Int16[] firstOp, Int16 scalarData, Int16[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != 0)) + if ((i == 1 ? result[i] != scalarData : result[i] != 0)) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.Int16.129.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.Int16.129.cs index f2a3506fc1..4908bf9c93 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.Int16.129.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.Int16.129.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<Int16> _fld; + public Int16 _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = (short)0; } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref testStruct._fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + testStruct._scalarFldData = (short)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertInt16129 testClass) { - var result = Sse2.Insert(_fld, (short)2, 129); + var result = Sse2.Insert(_fld, _scalarFldData, 129); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16); private static Int16[] _data = new Int16[Op1ElementCount]; + private static Int16 _scalarClsData = (short)2; private static Vector128<Int16> _clsVar; private Vector128<Int16> _fld; + private Int16 _scalarFldData = (short)2; private SimpleUnaryOpTest__DataTable<Int16, Int16> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse2.Insert( Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (short)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + Int16 localData = (short)2; + Int16* ptr = &localData; + var result = Sse2.Insert( Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)), - (short)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + Int16 localData = (short)2; + Int16* ptr = &localData; + var result = Sse2.Insert( Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)), - (short)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse2).GetMethod(nameof(Sse2.Insert), new Type[] { typeof(Vector128<Int16>), typeof(Int16), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (short)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (short)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (short)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse2.Insert( _clsVar, - (short)2, + _scalarClsData, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + Int16 localData = (short)2; var firstOp = Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr); - var result = Sse2.Insert(firstOp, (short)2, 129); + var result = Sse2.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + Int16 localData = (short)2; + var firstOp = Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)); - var result = Sse2.Insert(firstOp, (short)2, 129); + var result = Sse2.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + Int16 localData = (short)2; + var firstOp = Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)); - var result = Sse2.Insert(firstOp, (short)2, 129); + var result = Sse2.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertInt16129(); - var result = Sse2.Insert(test._fld, (short)2, 129); + var result = Sse2.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse2.Insert(_fld, (short)2, 129); + var result = Sse2.Insert(_fld, _scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse2.Insert(test._fld, (short)2, 129); + var result = Sse2.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Int16> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Int16> firstOp, Int16 scalarData, void* result, [CallerMemberName] string method = "") { Int16[] inArray = new Int16[Op1ElementCount]; Int16[] outArray = new Int16[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, Int16 scalarData, void* result, [CallerMemberName] string method = "") { Int16[] inArray = new Int16[Op1ElementCount]; Int16[] outArray = new Int16[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int16>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(Int16[] firstOp, Int16[] result, [CallerMemberName] string method = "") + private void ValidateResult(Int16[] firstOp, Int16 scalarData, Int16[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != 0)) + if ((i == 1 ? result[i] != scalarData : result[i] != 0)) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.UInt16.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.UInt16.1.cs index 28613a5743..b0e282267c 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.UInt16.1.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.UInt16.1.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<UInt16> _fld; + public UInt16 _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = (ushort)0; } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref testStruct._fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + testStruct._scalarFldData = (ushort)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertUInt161 testClass) { - var result = Sse2.Insert(_fld, (ushort)2, 1); + var result = Sse2.Insert(_fld, _scalarFldData, 1); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16); private static UInt16[] _data = new UInt16[Op1ElementCount]; + private static UInt16 _scalarClsData = (ushort)2; private static Vector128<UInt16> _clsVar; private Vector128<UInt16> _fld; + private UInt16 _scalarFldData = (ushort)2; private SimpleUnaryOpTest__DataTable<UInt16, UInt16> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse2.Insert( Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ushort)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + UInt16 localData = (ushort)2; + UInt16* ptr = &localData; + var result = Sse2.Insert( Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)), - (ushort)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + UInt16 localData = (ushort)2; + UInt16* ptr = &localData; + var result = Sse2.Insert( Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)), - (ushort)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse2).GetMethod(nameof(Sse2.Insert), new Type[] { typeof(Vector128<UInt16>), typeof(UInt16), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ushort)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ushort)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ushort)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse2.Insert( _clsVar, - (ushort)2, + _scalarClsData, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + UInt16 localData = (ushort)2; var firstOp = Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr); - var result = Sse2.Insert(firstOp, (ushort)2, 1); + var result = Sse2.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + UInt16 localData = (ushort)2; + var firstOp = Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)); - var result = Sse2.Insert(firstOp, (ushort)2, 1); + var result = Sse2.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + UInt16 localData = (ushort)2; + var firstOp = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)); - var result = Sse2.Insert(firstOp, (ushort)2, 1); + var result = Sse2.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertUInt161(); - var result = Sse2.Insert(test._fld, (ushort)2, 1); + var result = Sse2.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse2.Insert(_fld, (ushort)2, 1); + var result = Sse2.Insert(_fld, _scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse2.Insert(test._fld, (ushort)2, 1); + var result = Sse2.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<UInt16> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<UInt16> firstOp, UInt16 scalarData, void* result, [CallerMemberName] string method = "") { UInt16[] inArray = new UInt16[Op1ElementCount]; UInt16[] outArray = new UInt16[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, UInt16 scalarData, void* result, [CallerMemberName] string method = "") { UInt16[] inArray = new UInt16[Op1ElementCount]; UInt16[] outArray = new UInt16[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(UInt16[] firstOp, UInt16[] result, [CallerMemberName] string method = "") + private void ValidateResult(UInt16[] firstOp, UInt16 scalarData, UInt16[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != 0)) + if ((i == 1 ? result[i] != scalarData : result[i] != 0)) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.UInt16.129.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.UInt16.129.cs index 050fe748ea..7a5a4e706c 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.UInt16.129.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Insert.UInt16.129.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<UInt16> _fld; + public UInt16 _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = (ushort)0; } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref testStruct._fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + testStruct._scalarFldData = (ushort)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertUInt16129 testClass) { - var result = Sse2.Insert(_fld, (ushort)2, 129); + var result = Sse2.Insert(_fld, _scalarFldData, 129); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16); private static UInt16[] _data = new UInt16[Op1ElementCount]; + private static UInt16 _scalarClsData = (ushort)2; private static Vector128<UInt16> _clsVar; private Vector128<UInt16> _fld; + private UInt16 _scalarFldData = (ushort)2; private SimpleUnaryOpTest__DataTable<UInt16, UInt16> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse2.Insert( Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ushort)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + UInt16 localData = (ushort)2; + UInt16* ptr = &localData; + var result = Sse2.Insert( Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)), - (ushort)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + UInt16 localData = (ushort)2; + UInt16* ptr = &localData; + var result = Sse2.Insert( Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)), - (ushort)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse2).GetMethod(nameof(Sse2.Insert), new Type[] { typeof(Vector128<UInt16>), typeof(UInt16), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ushort)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ushort)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ushort)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse2.Insert( _clsVar, - (ushort)2, + _scalarClsData, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + UInt16 localData = (ushort)2; var firstOp = Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr); - var result = Sse2.Insert(firstOp, (ushort)2, 129); + var result = Sse2.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + UInt16 localData = (ushort)2; + var firstOp = Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)); - var result = Sse2.Insert(firstOp, (ushort)2, 129); + var result = Sse2.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + UInt16 localData = (ushort)2; + var firstOp = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)); - var result = Sse2.Insert(firstOp, (ushort)2, 129); + var result = Sse2.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertUInt16129(); - var result = Sse2.Insert(test._fld, (ushort)2, 129); + var result = Sse2.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse2.Insert(_fld, (ushort)2, 129); + var result = Sse2.Insert(_fld, _scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse2.Insert(test._fld, (ushort)2, 129); + var result = Sse2.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<UInt16> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<UInt16> firstOp, UInt16 scalarData, void* result, [CallerMemberName] string method = "") { UInt16[] inArray = new UInt16[Op1ElementCount]; UInt16[] outArray = new UInt16[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, UInt16 scalarData, void* result, [CallerMemberName] string method = "") { UInt16[] inArray = new UInt16[Op1ElementCount]; UInt16[] outArray = new UInt16[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(UInt16[] firstOp, UInt16[] result, [CallerMemberName] string method = "") + private void ValidateResult(UInt16[] firstOp, UInt16 scalarData, UInt16[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != 0)) + if ((i == 1 ? result[i] != scalarData : result[i] != 0)) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask.Vector128Byte.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask.Vector128Byte.cs new file mode 100644 index 0000000000..90545ebc27 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask.Vector128Byte.cs @@ -0,0 +1,350 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void MoveMaskVector128Byte() + { + var test = new SimdScalarUnaryOpConvertTest__MoveMaskVector128Byte(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class SimdScalarUnaryOpConvertTest__MoveMaskVector128Byte + { + private struct TestStruct + { + public Vector128<Byte> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Byte>, byte>(ref testStruct._fld), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Byte>>()); + + return testStruct; + } + + public void RunStructFldScenario(SimdScalarUnaryOpConvertTest__MoveMaskVector128Byte testClass) + { + var result = Sse2.MoveMask(_fld); + testClass.ValidateResult(_fld, result); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<Byte>>() / sizeof(Byte); + + private static Byte[] _data = new Byte[Op1ElementCount]; + + private static Vector128<Byte> _clsVar; + + private Vector128<Byte> _fld; + + private SimdScalarUnaryOpTest__DataTable<Byte> _dataTable; + + static SimdScalarUnaryOpConvertTest__MoveMaskVector128Byte() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Byte>, byte>(ref _clsVar), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Byte>>()); + } + + public SimdScalarUnaryOpConvertTest__MoveMaskVector128Byte() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Byte>, byte>(ref _fld), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Byte>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); } + _dataTable = new SimdScalarUnaryOpTest__DataTable<Byte>(_data, LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.MoveMask( + Unsafe.Read<Vector128<Byte>>(_dataTable.inArrayPtr) + ); + + ValidateResult(_dataTable.inArrayPtr, result); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.MoveMask( + Sse2.LoadVector128((Byte*)(_dataTable.inArrayPtr)) + ); + + ValidateResult(_dataTable.inArrayPtr, result); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.MoveMask( + Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArrayPtr)) + ); + + ValidateResult(_dataTable.inArrayPtr, result); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.MoveMask), new Type[] { typeof(Vector128<Byte>) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<Byte>>(_dataTable.inArrayPtr) + }); + + ValidateResult(_dataTable.inArrayPtr, (Int32)(result)); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.MoveMask), new Type[] { typeof(Vector128<Byte>) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((Byte*)(_dataTable.inArrayPtr)) + }); + + ValidateResult(_dataTable.inArrayPtr, (Int32)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.MoveMask), new Type[] { typeof(Vector128<Byte>) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArrayPtr)) + }); + + ValidateResult(_dataTable.inArrayPtr, (Int32)(result)); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.MoveMask( + _clsVar + ); + + ValidateResult(_clsVar, result); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<Byte>>(_dataTable.inArrayPtr); + var result = Sse2.MoveMask(firstOp); + + ValidateResult(firstOp, result); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((Byte*)(_dataTable.inArrayPtr)); + var result = Sse2.MoveMask(firstOp); + + ValidateResult(firstOp, result); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArrayPtr)); + var result = Sse2.MoveMask(firstOp); + + ValidateResult(firstOp, result); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new SimdScalarUnaryOpConvertTest__MoveMaskVector128Byte(); + var result = Sse2.MoveMask(test._fld); + + ValidateResult(test._fld, result); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.MoveMask(_fld); + + ValidateResult(_fld, result); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.MoveMask(test._fld); + + ValidateResult(test._fld, result); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<Byte> firstOp, Int32 result, [CallerMemberName] string method = "") + { + Byte[] inArray = new Byte[Op1ElementCount]; + Unsafe.WriteUnaligned(ref Unsafe.As<Byte, byte>(ref inArray[0]), firstOp); + ValidateResult(inArray, result, method); + } + + private void ValidateResult(void* firstOp, Int32 result, [CallerMemberName] string method = "") + { + Byte[] inArray = new Byte[Op1ElementCount]; + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Byte>>()); + ValidateResult(inArray, result, method); + } + + private void ValidateResult(Byte[] firstOp, Int32 result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (((firstOp[0] & 128) == 0) != ((result & 1) == 0)) + { + succeeded = false; + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.MoveMask)}<Int32>(Vector128<Byte>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: result"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask.Vector128Double.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask.Vector128Double.cs new file mode 100644 index 0000000000..e2b96d2a0f --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask.Vector128Double.cs @@ -0,0 +1,350 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void MoveMaskVector128Double() + { + var test = new SimdScalarUnaryOpConvertTest__MoveMaskVector128Double(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class SimdScalarUnaryOpConvertTest__MoveMaskVector128Double + { + private struct TestStruct + { + public Vector128<Double> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref testStruct._fld), ref Unsafe.As<Double, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + + return testStruct; + } + + public void RunStructFldScenario(SimdScalarUnaryOpConvertTest__MoveMaskVector128Double testClass) + { + var result = Sse2.MoveMask(_fld); + testClass.ValidateResult(_fld, result); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<Double>>() / sizeof(Double); + + private static Double[] _data = new Double[Op1ElementCount]; + + private static Vector128<Double> _clsVar; + + private Vector128<Double> _fld; + + private SimdScalarUnaryOpTest__DataTable<Double> _dataTable; + + static SimdScalarUnaryOpConvertTest__MoveMaskVector128Double() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _clsVar), ref Unsafe.As<Double, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + } + + public SimdScalarUnaryOpConvertTest__MoveMaskVector128Double() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _fld), ref Unsafe.As<Double, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetDouble(); } + _dataTable = new SimdScalarUnaryOpTest__DataTable<Double>(_data, LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.MoveMask( + Unsafe.Read<Vector128<Double>>(_dataTable.inArrayPtr) + ); + + ValidateResult(_dataTable.inArrayPtr, result); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.MoveMask( + Sse2.LoadVector128((Double*)(_dataTable.inArrayPtr)) + ); + + ValidateResult(_dataTable.inArrayPtr, result); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.MoveMask( + Sse2.LoadAlignedVector128((Double*)(_dataTable.inArrayPtr)) + ); + + ValidateResult(_dataTable.inArrayPtr, result); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.MoveMask), new Type[] { typeof(Vector128<Double>) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<Double>>(_dataTable.inArrayPtr) + }); + + ValidateResult(_dataTable.inArrayPtr, (Int32)(result)); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.MoveMask), new Type[] { typeof(Vector128<Double>) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((Double*)(_dataTable.inArrayPtr)) + }); + + ValidateResult(_dataTable.inArrayPtr, (Int32)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.MoveMask), new Type[] { typeof(Vector128<Double>) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((Double*)(_dataTable.inArrayPtr)) + }); + + ValidateResult(_dataTable.inArrayPtr, (Int32)(result)); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.MoveMask( + _clsVar + ); + + ValidateResult(_clsVar, result); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<Double>>(_dataTable.inArrayPtr); + var result = Sse2.MoveMask(firstOp); + + ValidateResult(firstOp, result); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((Double*)(_dataTable.inArrayPtr)); + var result = Sse2.MoveMask(firstOp); + + ValidateResult(firstOp, result); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((Double*)(_dataTable.inArrayPtr)); + var result = Sse2.MoveMask(firstOp); + + ValidateResult(firstOp, result); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new SimdScalarUnaryOpConvertTest__MoveMaskVector128Double(); + var result = Sse2.MoveMask(test._fld); + + ValidateResult(test._fld, result); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.MoveMask(_fld); + + ValidateResult(_fld, result); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.MoveMask(test._fld); + + ValidateResult(test._fld, result); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<Double> firstOp, Int32 result, [CallerMemberName] string method = "") + { + Double[] inArray = new Double[Op1ElementCount]; + Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray[0]), firstOp); + ValidateResult(inArray, result, method); + } + + private void ValidateResult(void* firstOp, Int32 result, [CallerMemberName] string method = "") + { + Double[] inArray = new Double[Op1ElementCount]; + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Double>>()); + ValidateResult(inArray, result, method); + } + + private void ValidateResult(Double[] firstOp, Int32 result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if ((BitConverter.DoubleToInt64Bits(firstOp[0]) >= 0) != ((result & 1) == 0)) + { + succeeded = false; + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.MoveMask)}<Int32>(Vector128<Double>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: result"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask.Vector128SByte.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask.Vector128SByte.cs new file mode 100644 index 0000000000..d9fa08971b --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask.Vector128SByte.cs @@ -0,0 +1,350 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void MoveMaskVector128SByte() + { + var test = new SimdScalarUnaryOpConvertTest__MoveMaskVector128SByte(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class SimdScalarUnaryOpConvertTest__MoveMaskVector128SByte + { + private struct TestStruct + { + public Vector128<SByte> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<SByte>, byte>(ref testStruct._fld), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<SByte>>()); + + return testStruct; + } + + public void RunStructFldScenario(SimdScalarUnaryOpConvertTest__MoveMaskVector128SByte testClass) + { + var result = Sse2.MoveMask(_fld); + testClass.ValidateResult(_fld, result); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<SByte>>() / sizeof(SByte); + + private static SByte[] _data = new SByte[Op1ElementCount]; + + private static Vector128<SByte> _clsVar; + + private Vector128<SByte> _fld; + + private SimdScalarUnaryOpTest__DataTable<SByte> _dataTable; + + static SimdScalarUnaryOpConvertTest__MoveMaskVector128SByte() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<SByte>, byte>(ref _clsVar), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<SByte>>()); + } + + public SimdScalarUnaryOpConvertTest__MoveMaskVector128SByte() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<SByte>, byte>(ref _fld), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<SByte>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); } + _dataTable = new SimdScalarUnaryOpTest__DataTable<SByte>(_data, LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.MoveMask( + Unsafe.Read<Vector128<SByte>>(_dataTable.inArrayPtr) + ); + + ValidateResult(_dataTable.inArrayPtr, result); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.MoveMask( + Sse2.LoadVector128((SByte*)(_dataTable.inArrayPtr)) + ); + + ValidateResult(_dataTable.inArrayPtr, result); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.MoveMask( + Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArrayPtr)) + ); + + ValidateResult(_dataTable.inArrayPtr, result); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.MoveMask), new Type[] { typeof(Vector128<SByte>) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<SByte>>(_dataTable.inArrayPtr) + }); + + ValidateResult(_dataTable.inArrayPtr, (Int32)(result)); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.MoveMask), new Type[] { typeof(Vector128<SByte>) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((SByte*)(_dataTable.inArrayPtr)) + }); + + ValidateResult(_dataTable.inArrayPtr, (Int32)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.MoveMask), new Type[] { typeof(Vector128<SByte>) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArrayPtr)) + }); + + ValidateResult(_dataTable.inArrayPtr, (Int32)(result)); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.MoveMask( + _clsVar + ); + + ValidateResult(_clsVar, result); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<SByte>>(_dataTable.inArrayPtr); + var result = Sse2.MoveMask(firstOp); + + ValidateResult(firstOp, result); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((SByte*)(_dataTable.inArrayPtr)); + var result = Sse2.MoveMask(firstOp); + + ValidateResult(firstOp, result); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArrayPtr)); + var result = Sse2.MoveMask(firstOp); + + ValidateResult(firstOp, result); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new SimdScalarUnaryOpConvertTest__MoveMaskVector128SByte(); + var result = Sse2.MoveMask(test._fld); + + ValidateResult(test._fld, result); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.MoveMask(_fld); + + ValidateResult(_fld, result); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.MoveMask(test._fld); + + ValidateResult(test._fld, result); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<SByte> firstOp, Int32 result, [CallerMemberName] string method = "") + { + SByte[] inArray = new SByte[Op1ElementCount]; + Unsafe.WriteUnaligned(ref Unsafe.As<SByte, byte>(ref inArray[0]), firstOp); + ValidateResult(inArray, result, method); + } + + private void ValidateResult(void* firstOp, Int32 result, [CallerMemberName] string method = "") + { + SByte[] inArray = new SByte[Op1ElementCount]; + Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<SByte>>()); + ValidateResult(inArray, result, method); + } + + private void ValidateResult(SByte[] firstOp, Int32 result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if ((firstOp[0] >= 0) != ((result & 1) == 0)) + { + succeeded = false; + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.MoveMask)}<Int32>(Vector128<SByte>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: result"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask.cs deleted file mode 100644 index 770b32517a..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/MoveMask.cs +++ /dev/null @@ -1,91 +0,0 @@ -// 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.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics.X86; -using System.Runtime.Intrinsics; - -namespace IntelHardwareIntrinsicTest -{ - class Program - { - const int Pass = 100; - const int Fail = 0; - - static unsafe int Main(string[] args) - { - int testResult = Pass; - - if (Sse2.IsSupported) - { - using (TestTable<double> doubleTable = new TestTable<double>(new double[2] { 1, -5 })) - { - - var vf1 = Unsafe.Read<Vector128<double>>(doubleTable.inArray1Ptr); - var res = Sse2.MoveMask(vf1); - - if (res != 0b0010) - { - Console.WriteLine("SSE MoveMask failed on double:"); - Console.WriteLine(res); - testResult = Fail; - } - } - - using (TestTable<byte> byteTable = new TestTable<byte>(new byte[16] { 255, 2, 0, 80, 0, 7, 0, 1, 2, 7, 80, 0, 123, 127, 5, 255 })) - { - - var vf1 = Unsafe.Read<Vector128<byte>>(byteTable.inArray1Ptr); - var res = Sse2.MoveMask(vf1); - - if (res != 0b1000000000000001) - { - Console.WriteLine("SSE MoveMask failed on byte:"); - Console.WriteLine(res); - testResult = Fail; - } - } - - using (TestTable<sbyte> sbyteTable = new TestTable<sbyte>(new sbyte[16] { -1, 2, 0, 6, 0, 7, 111, 1, 2, 55, 80, 0, 11, 127, 5, -9 })) - { - - var vf1 = Unsafe.Read<Vector128<sbyte>>(sbyteTable.inArray1Ptr); - var res = Sse2.MoveMask(vf1); - - if (res != 0b1000000000000001) - { - Console.WriteLine("SSE MoveMask failed on sbyte:"); - Console.WriteLine(res); - testResult = Fail; - } - } - } - - - return testResult; - } - - public unsafe struct TestTable<T> : IDisposable where T : struct - { - public T[] inArray1; - public void* inArray1Ptr => inHandle1.AddrOfPinnedObject().ToPointer(); - GCHandle inHandle1; - - public TestTable(T[] a) - { - this.inArray1 = a; - inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned); - } - - public void Dispose() - { - inHandle1.Free(); - } - } - - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Program.Sse2.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Program.Sse2.cs index 2bdcf190fa..a61a8cd992 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Program.Sse2.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Program.Sse2.cs @@ -144,6 +144,9 @@ namespace JIT.HardwareIntrinsics.X86 ["MultiplyAddAdjacent.Int32"] = MultiplyAddAdjacentInt32, ["MultiplyLow.Int16"] = MultiplyLowInt16, ["MultiplyLow.UInt16"] = MultiplyLowUInt16, + ["MoveMask.Vector128Byte"] = MoveMaskVector128Byte, + ["MoveMask.Vector128SByte"] = MoveMaskVector128SByte, + ["MoveMask.Vector128Double"] = MoveMaskVector128Double, ["Or.Double"] = OrDouble, ["Or.Byte"] = OrByte, ["Or.Int16"] = OrInt16, @@ -200,6 +203,20 @@ namespace JIT.HardwareIntrinsics.X86 ["ShiftRightLogical128BitLane.UInt32.1"] = ShiftRightLogical128BitLaneUInt321, ["ShiftRightLogical128BitLane.Int64.1"] = ShiftRightLogical128BitLaneInt641, ["ShiftRightLogical128BitLane.UInt64.1"] = ShiftRightLogical128BitLaneUInt641, + ["Shuffle.Int32.0"] = ShuffleInt320, + ["Shuffle.UInt32.0"] = ShuffleUInt320, + ["Shuffle.Int32.1"] = ShuffleInt321, + ["Shuffle.UInt32.1"] = ShuffleUInt321, + ["Shuffle.Double.0"] = ShuffleDouble0, + ["Shuffle.Double.1"] = ShuffleDouble1, + ["ShuffleHigh.Int16.0"] = ShuffleHighInt160, + ["ShuffleHigh.UInt16.0"] = ShuffleHighUInt160, + ["ShuffleLow.Int16.0"] = ShuffleLowInt160, + ["ShuffleLow.UInt16.0"] = ShuffleLowUInt160, + ["ShuffleHigh.Int16.1"] = ShuffleHighInt161, + ["ShuffleHigh.UInt16.1"] = ShuffleHighUInt161, + ["ShuffleLow.Int16.1"] = ShuffleLowInt161, + ["ShuffleLow.UInt16.1"] = ShuffleLowUInt161, ["Subtract.Double"] = SubtractDouble, ["Subtract.Byte"] = SubtractByte, ["Subtract.Int16"] = SubtractInt16, diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.Double.0.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.Double.0.cs new file mode 100644 index 0000000000..f651d74f2e --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.Double.0.cs @@ -0,0 +1,419 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleDouble0() + { + var test = new ImmBinaryOpTest__ShuffleDouble0(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmBinaryOpTest__ShuffleDouble0 + { + private struct TestStruct + { + public Vector128<Double> _fld1; + public Vector128<Double> _fld2; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref testStruct._fld1), ref Unsafe.As<Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref testStruct._fld2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmBinaryOpTest__ShuffleDouble0 testClass) + { + var result = Sse2.Shuffle(_fld1, _fld2, 0); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld1, _fld2, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<Double>>() / sizeof(Double); + private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Double>>() / sizeof(Double); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Double>>() / sizeof(Double); + + private static Double[] _data1 = new Double[Op1ElementCount]; + private static Double[] _data2 = new Double[Op2ElementCount]; + + private static Vector128<Double> _clsVar1; + private static Vector128<Double> _clsVar2; + + private Vector128<Double> _fld1; + private Vector128<Double> _fld2; + + private SimpleBinaryOpTest__DataTable<Double, Double, Double> _dataTable; + + static ImmBinaryOpTest__ShuffleDouble0() + { + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _clsVar1), ref Unsafe.As<Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _clsVar2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + } + + public ImmBinaryOpTest__ShuffleDouble0() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _fld1), ref Unsafe.As<Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _fld2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); } + for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); } + _dataTable = new SimpleBinaryOpTest__DataTable<Double, Double, Double>(_data1, _data2, new Double[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.Shuffle( + Unsafe.Read<Vector128<Double>>(_dataTable.inArray1Ptr), + Unsafe.Read<Vector128<Double>>(_dataTable.inArray2Ptr), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.Shuffle( + Sse2.LoadVector128((Double*)(_dataTable.inArray1Ptr)), + Sse2.LoadVector128((Double*)(_dataTable.inArray2Ptr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.Shuffle( + Sse2.LoadAlignedVector128((Double*)(_dataTable.inArray1Ptr)), + Sse2.LoadAlignedVector128((Double*)(_dataTable.inArray2Ptr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<Double>), typeof(Vector128<Double>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<Double>>(_dataTable.inArray1Ptr), + Unsafe.Read<Vector128<Double>>(_dataTable.inArray2Ptr), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Double>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<Double>), typeof(Vector128<Double>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((Double*)(_dataTable.inArray1Ptr)), + Sse2.LoadVector128((Double*)(_dataTable.inArray2Ptr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Double>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<Double>), typeof(Vector128<Double>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((Double*)(_dataTable.inArray1Ptr)), + Sse2.LoadAlignedVector128((Double*)(_dataTable.inArray2Ptr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Double>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.Shuffle( + _clsVar1, + _clsVar2, + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var left = Unsafe.Read<Vector128<Double>>(_dataTable.inArray1Ptr); + var right = Unsafe.Read<Vector128<Double>>(_dataTable.inArray2Ptr); + var result = Sse2.Shuffle(left, right, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var left = Sse2.LoadVector128((Double*)(_dataTable.inArray1Ptr)); + var right = Sse2.LoadVector128((Double*)(_dataTable.inArray2Ptr)); + var result = Sse2.Shuffle(left, right, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var left = Sse2.LoadAlignedVector128((Double*)(_dataTable.inArray1Ptr)); + var right = Sse2.LoadAlignedVector128((Double*)(_dataTable.inArray2Ptr)); + var result = Sse2.Shuffle(left, right, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmBinaryOpTest__ShuffleDouble0(); + var result = Sse2.Shuffle(test._fld1, test._fld2, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.Shuffle(_fld1, _fld2, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.Shuffle(test._fld1, test._fld2, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<Double> left, Vector128<Double> right, void* result, [CallerMemberName] string method = "") + { + Double[] inArray1 = new Double[Op1ElementCount]; + Double[] inArray2 = new Double[Op2ElementCount]; + Double[] outArray = new Double[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray1[0]), left); + Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Double>>()); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Double[] inArray1 = new Double[Op1ElementCount]; + Double[] inArray2 = new Double[Op2ElementCount]; + Double[] outArray = new Double[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector128<Double>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Double>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Double>>()); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(Double[] left, Double[] right, Double[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(left[0])) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if (BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(right[0])) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.Shuffle)}<Double>(Vector128<Double>.0, Vector128<Double>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); + TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.Double.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.Double.1.cs new file mode 100644 index 0000000000..46f341c783 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.Double.1.cs @@ -0,0 +1,419 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleDouble1() + { + var test = new ImmBinaryOpTest__ShuffleDouble1(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmBinaryOpTest__ShuffleDouble1 + { + private struct TestStruct + { + public Vector128<Double> _fld1; + public Vector128<Double> _fld2; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref testStruct._fld1), ref Unsafe.As<Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref testStruct._fld2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmBinaryOpTest__ShuffleDouble1 testClass) + { + var result = Sse2.Shuffle(_fld1, _fld2, 1); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld1, _fld2, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<Double>>() / sizeof(Double); + private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Double>>() / sizeof(Double); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Double>>() / sizeof(Double); + + private static Double[] _data1 = new Double[Op1ElementCount]; + private static Double[] _data2 = new Double[Op2ElementCount]; + + private static Vector128<Double> _clsVar1; + private static Vector128<Double> _clsVar2; + + private Vector128<Double> _fld1; + private Vector128<Double> _fld2; + + private SimpleBinaryOpTest__DataTable<Double, Double, Double> _dataTable; + + static ImmBinaryOpTest__ShuffleDouble1() + { + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _clsVar1), ref Unsafe.As<Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _clsVar2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + } + + public ImmBinaryOpTest__ShuffleDouble1() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _fld1), ref Unsafe.As<Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _fld2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); } + for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); } + _dataTable = new SimpleBinaryOpTest__DataTable<Double, Double, Double>(_data1, _data2, new Double[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.Shuffle( + Unsafe.Read<Vector128<Double>>(_dataTable.inArray1Ptr), + Unsafe.Read<Vector128<Double>>(_dataTable.inArray2Ptr), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.Shuffle( + Sse2.LoadVector128((Double*)(_dataTable.inArray1Ptr)), + Sse2.LoadVector128((Double*)(_dataTable.inArray2Ptr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.Shuffle( + Sse2.LoadAlignedVector128((Double*)(_dataTable.inArray1Ptr)), + Sse2.LoadAlignedVector128((Double*)(_dataTable.inArray2Ptr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<Double>), typeof(Vector128<Double>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<Double>>(_dataTable.inArray1Ptr), + Unsafe.Read<Vector128<Double>>(_dataTable.inArray2Ptr), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Double>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<Double>), typeof(Vector128<Double>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((Double*)(_dataTable.inArray1Ptr)), + Sse2.LoadVector128((Double*)(_dataTable.inArray2Ptr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Double>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<Double>), typeof(Vector128<Double>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((Double*)(_dataTable.inArray1Ptr)), + Sse2.LoadAlignedVector128((Double*)(_dataTable.inArray2Ptr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Double>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.Shuffle( + _clsVar1, + _clsVar2, + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var left = Unsafe.Read<Vector128<Double>>(_dataTable.inArray1Ptr); + var right = Unsafe.Read<Vector128<Double>>(_dataTable.inArray2Ptr); + var result = Sse2.Shuffle(left, right, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var left = Sse2.LoadVector128((Double*)(_dataTable.inArray1Ptr)); + var right = Sse2.LoadVector128((Double*)(_dataTable.inArray2Ptr)); + var result = Sse2.Shuffle(left, right, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var left = Sse2.LoadAlignedVector128((Double*)(_dataTable.inArray1Ptr)); + var right = Sse2.LoadAlignedVector128((Double*)(_dataTable.inArray2Ptr)); + var result = Sse2.Shuffle(left, right, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmBinaryOpTest__ShuffleDouble1(); + var result = Sse2.Shuffle(test._fld1, test._fld2, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.Shuffle(_fld1, _fld2, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.Shuffle(test._fld1, test._fld2, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<Double> left, Vector128<Double> right, void* result, [CallerMemberName] string method = "") + { + Double[] inArray1 = new Double[Op1ElementCount]; + Double[] inArray2 = new Double[Op2ElementCount]; + Double[] outArray = new Double[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray1[0]), left); + Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Double>>()); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Double[] inArray1 = new Double[Op1ElementCount]; + Double[] inArray2 = new Double[Op2ElementCount]; + Double[] outArray = new Double[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector128<Double>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Double>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Double>>()); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(Double[] left, Double[] right, Double[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(left[1])) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if (BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(right[0])) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.Shuffle)}<Double>(Vector128<Double>.1, Vector128<Double>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); + TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.Int32.0.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.Int32.0.cs new file mode 100644 index 0000000000..31e7b4c323 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.Int32.0.cs @@ -0,0 +1,392 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleInt320() + { + var test = new ImmUnaryOpTest__ShuffleInt320(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmUnaryOpTest__ShuffleInt320 + { + private struct TestStruct + { + public Vector128<Int32> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref testStruct._fld), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmUnaryOpTest__ShuffleInt320 testClass) + { + var result = Sse2.Shuffle(_fld, 0); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<Int32>>() / sizeof(Int32); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int32>>() / sizeof(Int32); + + private static Int32[] _data = new Int32[Op1ElementCount]; + + private static Vector128<Int32> _clsVar; + + private Vector128<Int32> _fld; + + private SimpleUnaryOpTest__DataTable<Int32, Int32> _dataTable; + + static ImmUnaryOpTest__ShuffleInt320() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref _clsVar), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + } + + public ImmUnaryOpTest__ShuffleInt320() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref _fld), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); } + _dataTable = new SimpleUnaryOpTest__DataTable<Int32, Int32>(_data, new Int32[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.Shuffle( + Unsafe.Read<Vector128<Int32>>(_dataTable.inArrayPtr), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.Shuffle( + Sse2.LoadVector128((Int32*)(_dataTable.inArrayPtr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.Shuffle( + Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArrayPtr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<Int32>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<Int32>>(_dataTable.inArrayPtr), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<Int32>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((Int32*)(_dataTable.inArrayPtr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<Int32>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArrayPtr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.Shuffle( + _clsVar, + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<Int32>>(_dataTable.inArrayPtr); + var result = Sse2.Shuffle(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((Int32*)(_dataTable.inArrayPtr)); + var result = Sse2.Shuffle(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArrayPtr)); + var result = Sse2.Shuffle(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmUnaryOpTest__ShuffleInt320(); + var result = Sse2.Shuffle(test._fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.Shuffle(_fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.Shuffle(test._fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<Int32> firstOp, void* result, [CallerMemberName] string method = "") + { + Int32[] inArray = new Int32[Op1ElementCount]; + Int32[] outArray = new Int32[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), firstOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + { + Int32[] inArray = new Int32[Op1ElementCount]; + Int32[] outArray = new Int32[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(Int32[] firstOp, Int32[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (firstOp[0] != result[0]) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if (firstOp[0] != result[i]) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.Shuffle)}<Int32>(Vector128<Int32><9>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.Int32.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.Int32.1.cs new file mode 100644 index 0000000000..9698f1dc9b --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.Int32.1.cs @@ -0,0 +1,392 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleInt321() + { + var test = new ImmUnaryOpTest__ShuffleInt321(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmUnaryOpTest__ShuffleInt321 + { + private struct TestStruct + { + public Vector128<Int32> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref testStruct._fld), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmUnaryOpTest__ShuffleInt321 testClass) + { + var result = Sse2.Shuffle(_fld, 1); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<Int32>>() / sizeof(Int32); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int32>>() / sizeof(Int32); + + private static Int32[] _data = new Int32[Op1ElementCount]; + + private static Vector128<Int32> _clsVar; + + private Vector128<Int32> _fld; + + private SimpleUnaryOpTest__DataTable<Int32, Int32> _dataTable; + + static ImmUnaryOpTest__ShuffleInt321() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref _clsVar), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + } + + public ImmUnaryOpTest__ShuffleInt321() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref _fld), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); } + _dataTable = new SimpleUnaryOpTest__DataTable<Int32, Int32>(_data, new Int32[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.Shuffle( + Unsafe.Read<Vector128<Int32>>(_dataTable.inArrayPtr), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.Shuffle( + Sse2.LoadVector128((Int32*)(_dataTable.inArrayPtr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.Shuffle( + Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArrayPtr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<Int32>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<Int32>>(_dataTable.inArrayPtr), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<Int32>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((Int32*)(_dataTable.inArrayPtr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<Int32>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArrayPtr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.Shuffle( + _clsVar, + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<Int32>>(_dataTable.inArrayPtr); + var result = Sse2.Shuffle(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((Int32*)(_dataTable.inArrayPtr)); + var result = Sse2.Shuffle(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArrayPtr)); + var result = Sse2.Shuffle(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmUnaryOpTest__ShuffleInt321(); + var result = Sse2.Shuffle(test._fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.Shuffle(_fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.Shuffle(test._fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<Int32> firstOp, void* result, [CallerMemberName] string method = "") + { + Int32[] inArray = new Int32[Op1ElementCount]; + Int32[] outArray = new Int32[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), firstOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + { + Int32[] inArray = new Int32[Op1ElementCount]; + Int32[] outArray = new Int32[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(Int32[] firstOp, Int32[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (firstOp[1] != result[0]) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if (firstOp[0] != result[i]) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.Shuffle)}<Int32>(Vector128<Int32><9>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.UInt32.0.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.UInt32.0.cs new file mode 100644 index 0000000000..7f909416cf --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.UInt32.0.cs @@ -0,0 +1,392 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleUInt320() + { + var test = new ImmUnaryOpTest__ShuffleUInt320(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmUnaryOpTest__ShuffleUInt320 + { + private struct TestStruct + { + public Vector128<UInt32> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref testStruct._fld), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmUnaryOpTest__ShuffleUInt320 testClass) + { + var result = Sse2.Shuffle(_fld, 0); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<UInt32>>() / sizeof(UInt32); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt32>>() / sizeof(UInt32); + + private static UInt32[] _data = new UInt32[Op1ElementCount]; + + private static Vector128<UInt32> _clsVar; + + private Vector128<UInt32> _fld; + + private SimpleUnaryOpTest__DataTable<UInt32, UInt32> _dataTable; + + static ImmUnaryOpTest__ShuffleUInt320() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref _clsVar), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + } + + public ImmUnaryOpTest__ShuffleUInt320() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref _fld), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); } + _dataTable = new SimpleUnaryOpTest__DataTable<UInt32, UInt32>(_data, new UInt32[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.Shuffle( + Unsafe.Read<Vector128<UInt32>>(_dataTable.inArrayPtr), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.Shuffle( + Sse2.LoadVector128((UInt32*)(_dataTable.inArrayPtr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.Shuffle( + Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArrayPtr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<UInt32>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<UInt32>>(_dataTable.inArrayPtr), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<UInt32>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((UInt32*)(_dataTable.inArrayPtr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<UInt32>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArrayPtr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.Shuffle( + _clsVar, + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<UInt32>>(_dataTable.inArrayPtr); + var result = Sse2.Shuffle(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((UInt32*)(_dataTable.inArrayPtr)); + var result = Sse2.Shuffle(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArrayPtr)); + var result = Sse2.Shuffle(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmUnaryOpTest__ShuffleUInt320(); + var result = Sse2.Shuffle(test._fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.Shuffle(_fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.Shuffle(test._fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<UInt32> firstOp, void* result, [CallerMemberName] string method = "") + { + UInt32[] inArray = new UInt32[Op1ElementCount]; + UInt32[] outArray = new UInt32[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), firstOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + { + UInt32[] inArray = new UInt32[Op1ElementCount]; + UInt32[] outArray = new UInt32[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(UInt32[] firstOp, UInt32[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (firstOp[0] != result[0]) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if (firstOp[0] != result[i]) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.Shuffle)}<UInt32>(Vector128<UInt32><9>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.UInt32.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.UInt32.1.cs new file mode 100644 index 0000000000..db0cf33fbb --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.UInt32.1.cs @@ -0,0 +1,392 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleUInt321() + { + var test = new ImmUnaryOpTest__ShuffleUInt321(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmUnaryOpTest__ShuffleUInt321 + { + private struct TestStruct + { + public Vector128<UInt32> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref testStruct._fld), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmUnaryOpTest__ShuffleUInt321 testClass) + { + var result = Sse2.Shuffle(_fld, 1); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<UInt32>>() / sizeof(UInt32); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt32>>() / sizeof(UInt32); + + private static UInt32[] _data = new UInt32[Op1ElementCount]; + + private static Vector128<UInt32> _clsVar; + + private Vector128<UInt32> _fld; + + private SimpleUnaryOpTest__DataTable<UInt32, UInt32> _dataTable; + + static ImmUnaryOpTest__ShuffleUInt321() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref _clsVar), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + } + + public ImmUnaryOpTest__ShuffleUInt321() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref _fld), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); } + _dataTable = new SimpleUnaryOpTest__DataTable<UInt32, UInt32>(_data, new UInt32[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.Shuffle( + Unsafe.Read<Vector128<UInt32>>(_dataTable.inArrayPtr), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.Shuffle( + Sse2.LoadVector128((UInt32*)(_dataTable.inArrayPtr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.Shuffle( + Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArrayPtr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<UInt32>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<UInt32>>(_dataTable.inArrayPtr), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<UInt32>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((UInt32*)(_dataTable.inArrayPtr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.Shuffle), new Type[] { typeof(Vector128<UInt32>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArrayPtr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.Shuffle( + _clsVar, + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<UInt32>>(_dataTable.inArrayPtr); + var result = Sse2.Shuffle(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((UInt32*)(_dataTable.inArrayPtr)); + var result = Sse2.Shuffle(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArrayPtr)); + var result = Sse2.Shuffle(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmUnaryOpTest__ShuffleUInt321(); + var result = Sse2.Shuffle(test._fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.Shuffle(_fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.Shuffle(test._fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<UInt32> firstOp, void* result, [CallerMemberName] string method = "") + { + UInt32[] inArray = new UInt32[Op1ElementCount]; + UInt32[] outArray = new UInt32[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), firstOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + { + UInt32[] inArray = new UInt32[Op1ElementCount]; + UInt32[] outArray = new UInt32[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(UInt32[] firstOp, UInt32[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (firstOp[1] != result[0]) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if (firstOp[0] != result[i]) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.Shuffle)}<UInt32>(Vector128<UInt32><9>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.cs deleted file mode 100644 index 59ac72312e..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.cs +++ /dev/null @@ -1,297 +0,0 @@ -// 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<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; - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.tt b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.tt deleted file mode 100644 index 8922e3ff48..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle.tt +++ /dev/null @@ -1,225 +0,0 @@ -<#@ 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<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; - }); - -<# - for (int i = 0; i < permuteDouble.Length; i++) - { -#> - (Vector128<double>, Vector128<double>) valueDouble_<#= i #> = doubleTable[<#= i #>]; - Vector128<double> resultDouble_<#= i #> = Sse2.Shuffle(valueDouble_<#= i #>.Item1, valueDouble_<#= i #>.Item2, (byte) <#= permuteDouble[i] #>); - doubleTable.SetOutArray(resultDouble_<#= i #>, <#= i #>, (byte) <#= permuteDouble[i] #>); - -<# - - } -#> - - // Vector128<int> tests - - TestUtilities.InitializeWithElementNumberingModuloVectorLength<uint>( - uintTable.inArray1, 16, (int i, int elNo) => - { - return (uint) i % 4; - }); - -<# - for (int i = 0; i < permuteData.Length; i++) - { -#> - (Vector128<int>, Vector128<int>) valueInt32_<#= i #> = intTable[<#= i #>]; - Vector128<int> resultInt32_<#= i #> = Sse2.Shuffle(valueInt32_<#= i #>.Item1, (byte) <#= permuteData[i] #>); - intTable.SetOutArray(resultInt32_<#= i #>, <#= i #>, (byte) <#= permuteData[i] #>); - -<# - - } -#> - - // Vector128<uint> tests - - TestUtilities.InitializeWithElementNumberingModuloVectorLength<uint>( - uintTable.inArray1, 16, (int i, int elNo) => - { - return (uint) i % 4; - }); - -<# - for (int i = 0; i < permuteData.Length; i++) - { -#> - (Vector128<uint>, Vector128<uint>) valueUInt32_<#= i #> = uintTable[<#= i #>]; - Vector128<uint> resultUInt32_<#= i #> = Sse2.Shuffle(valueUInt32_<#= i #>.Item1, (byte) <#= permuteData[i] #>); - uintTable.SetOutArray(resultUInt32_<#= i #>, <#= i #>, (byte) <#= permuteData[i] #>); - -<# - - } -#> - - 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; - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.Int16.0.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.Int16.0.cs new file mode 100644 index 0000000000..54b5227589 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.Int16.0.cs @@ -0,0 +1,392 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleHighInt160() + { + var test = new ImmUnaryOpTest__ShuffleHighInt160(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmUnaryOpTest__ShuffleHighInt160 + { + private struct TestStruct + { + public Vector128<Int16> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref testStruct._fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmUnaryOpTest__ShuffleHighInt160 testClass) + { + var result = Sse2.ShuffleHigh(_fld, 0); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16); + + private static Int16[] _data = new Int16[Op1ElementCount]; + + private static Vector128<Int16> _clsVar; + + private Vector128<Int16> _fld; + + private SimpleUnaryOpTest__DataTable<Int16, Int16> _dataTable; + + static ImmUnaryOpTest__ShuffleHighInt160() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref _clsVar), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + } + + public ImmUnaryOpTest__ShuffleHighInt160() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref _fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + _dataTable = new SimpleUnaryOpTest__DataTable<Int16, Int16>(_data, new Int16[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.ShuffleHigh( + Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.ShuffleHigh( + Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.ShuffleHigh( + Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleHigh), new Type[] { typeof(Vector128<Int16>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleHigh), new Type[] { typeof(Vector128<Int16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleHigh), new Type[] { typeof(Vector128<Int16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.ShuffleHigh( + _clsVar, + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr); + var result = Sse2.ShuffleHigh(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleHigh(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleHigh(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmUnaryOpTest__ShuffleHighInt160(); + var result = Sse2.ShuffleHigh(test._fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.ShuffleHigh(_fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.ShuffleHigh(test._fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<Int16> firstOp, void* result, [CallerMemberName] string method = "") + { + Int16[] inArray = new Int16[Op1ElementCount]; + Int16[] outArray = new Int16[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), firstOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + { + Int16[] inArray = new Int16[Op1ElementCount]; + Int16[] outArray = new Int16[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(Int16[] firstOp, Int16[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (firstOp[0] != result[0]) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if ((i <= 3 ? (firstOp[i] != result[i]) : (firstOp[4] != result[i]))) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.ShuffleHigh)}<Int16>(Vector128<Int16><9>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.Int16.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.Int16.1.cs new file mode 100644 index 0000000000..3604cf8410 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.Int16.1.cs @@ -0,0 +1,392 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleHighInt161() + { + var test = new ImmUnaryOpTest__ShuffleHighInt161(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmUnaryOpTest__ShuffleHighInt161 + { + private struct TestStruct + { + public Vector128<Int16> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref testStruct._fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmUnaryOpTest__ShuffleHighInt161 testClass) + { + var result = Sse2.ShuffleHigh(_fld, 1); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16); + + private static Int16[] _data = new Int16[Op1ElementCount]; + + private static Vector128<Int16> _clsVar; + + private Vector128<Int16> _fld; + + private SimpleUnaryOpTest__DataTable<Int16, Int16> _dataTable; + + static ImmUnaryOpTest__ShuffleHighInt161() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref _clsVar), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + } + + public ImmUnaryOpTest__ShuffleHighInt161() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref _fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + _dataTable = new SimpleUnaryOpTest__DataTable<Int16, Int16>(_data, new Int16[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.ShuffleHigh( + Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.ShuffleHigh( + Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.ShuffleHigh( + Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleHigh), new Type[] { typeof(Vector128<Int16>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleHigh), new Type[] { typeof(Vector128<Int16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleHigh), new Type[] { typeof(Vector128<Int16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.ShuffleHigh( + _clsVar, + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr); + var result = Sse2.ShuffleHigh(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleHigh(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleHigh(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmUnaryOpTest__ShuffleHighInt161(); + var result = Sse2.ShuffleHigh(test._fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.ShuffleHigh(_fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.ShuffleHigh(test._fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<Int16> firstOp, void* result, [CallerMemberName] string method = "") + { + Int16[] inArray = new Int16[Op1ElementCount]; + Int16[] outArray = new Int16[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), firstOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + { + Int16[] inArray = new Int16[Op1ElementCount]; + Int16[] outArray = new Int16[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(Int16[] firstOp, Int16[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (firstOp[0] != result[0]) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if ((i <= 3 ? (firstOp[i] != result[i]) : (firstOp[5] != result[4]))) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.ShuffleHigh)}<Int16>(Vector128<Int16><9>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.UInt16.0.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.UInt16.0.cs new file mode 100644 index 0000000000..69f86e535b --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.UInt16.0.cs @@ -0,0 +1,392 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleHighUInt160() + { + var test = new ImmUnaryOpTest__ShuffleHighUInt160(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmUnaryOpTest__ShuffleHighUInt160 + { + private struct TestStruct + { + public Vector128<UInt16> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref testStruct._fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmUnaryOpTest__ShuffleHighUInt160 testClass) + { + var result = Sse2.ShuffleHigh(_fld, 0); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16); + + private static UInt16[] _data = new UInt16[Op1ElementCount]; + + private static Vector128<UInt16> _clsVar; + + private Vector128<UInt16> _fld; + + private SimpleUnaryOpTest__DataTable<UInt16, UInt16> _dataTable; + + static ImmUnaryOpTest__ShuffleHighUInt160() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _clsVar), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + } + + public ImmUnaryOpTest__ShuffleHighUInt160() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + _dataTable = new SimpleUnaryOpTest__DataTable<UInt16, UInt16>(_data, new UInt16[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.ShuffleHigh( + Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.ShuffleHigh( + Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.ShuffleHigh( + Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleHigh), new Type[] { typeof(Vector128<UInt16>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleHigh), new Type[] { typeof(Vector128<UInt16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleHigh), new Type[] { typeof(Vector128<UInt16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.ShuffleHigh( + _clsVar, + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr); + var result = Sse2.ShuffleHigh(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleHigh(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleHigh(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmUnaryOpTest__ShuffleHighUInt160(); + var result = Sse2.ShuffleHigh(test._fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.ShuffleHigh(_fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.ShuffleHigh(test._fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<UInt16> firstOp, void* result, [CallerMemberName] string method = "") + { + UInt16[] inArray = new UInt16[Op1ElementCount]; + UInt16[] outArray = new UInt16[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), firstOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + { + UInt16[] inArray = new UInt16[Op1ElementCount]; + UInt16[] outArray = new UInt16[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(UInt16[] firstOp, UInt16[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (firstOp[0] != result[0]) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if ((i <= 3 ? (firstOp[i] != result[i]) : (firstOp[4] != result[i]))) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.ShuffleHigh)}<UInt16>(Vector128<UInt16><9>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.UInt16.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.UInt16.1.cs new file mode 100644 index 0000000000..2b50a7e5ad --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.UInt16.1.cs @@ -0,0 +1,392 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleHighUInt161() + { + var test = new ImmUnaryOpTest__ShuffleHighUInt161(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmUnaryOpTest__ShuffleHighUInt161 + { + private struct TestStruct + { + public Vector128<UInt16> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref testStruct._fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmUnaryOpTest__ShuffleHighUInt161 testClass) + { + var result = Sse2.ShuffleHigh(_fld, 1); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16); + + private static UInt16[] _data = new UInt16[Op1ElementCount]; + + private static Vector128<UInt16> _clsVar; + + private Vector128<UInt16> _fld; + + private SimpleUnaryOpTest__DataTable<UInt16, UInt16> _dataTable; + + static ImmUnaryOpTest__ShuffleHighUInt161() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _clsVar), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + } + + public ImmUnaryOpTest__ShuffleHighUInt161() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + _dataTable = new SimpleUnaryOpTest__DataTable<UInt16, UInt16>(_data, new UInt16[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.ShuffleHigh( + Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.ShuffleHigh( + Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.ShuffleHigh( + Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleHigh), new Type[] { typeof(Vector128<UInt16>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleHigh), new Type[] { typeof(Vector128<UInt16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleHigh), new Type[] { typeof(Vector128<UInt16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.ShuffleHigh( + _clsVar, + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr); + var result = Sse2.ShuffleHigh(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleHigh(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleHigh(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmUnaryOpTest__ShuffleHighUInt161(); + var result = Sse2.ShuffleHigh(test._fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.ShuffleHigh(_fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.ShuffleHigh(test._fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<UInt16> firstOp, void* result, [CallerMemberName] string method = "") + { + UInt16[] inArray = new UInt16[Op1ElementCount]; + UInt16[] outArray = new UInt16[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), firstOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + { + UInt16[] inArray = new UInt16[Op1ElementCount]; + UInt16[] outArray = new UInt16[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(UInt16[] firstOp, UInt16[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (firstOp[0] != result[0]) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if ((i <= 3 ? (firstOp[i] != result[i]) : (firstOp[5] != result[4]))) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.ShuffleHigh)}<UInt16>(Vector128<UInt16><9>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.cs deleted file mode 100644 index 2bc3d0f992..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.cs +++ /dev/null @@ -1,266 +0,0 @@ -// 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<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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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.ShuffleHigh(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) + 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<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) + 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 deleted file mode 100644 index b94c24c242..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh.tt +++ /dev/null @@ -1,190 +0,0 @@ -<#@ 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<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); - -<# - for (int i = 0; i < permuteData.Length; i++) - { -#> - (Vector128<short>, Vector128<short>) valueInt16_<#= i #> = shortTable[<#= i #>]; - Vector128<short> resultInt16_<#= i #> = Sse2.ShuffleHigh(valueInt16_<#= i #>.Item1, (byte) <#= permuteData[i] #>); - shortTable.SetOutArray(resultInt16_<#= i #>, <#= i #>, (byte) <#= permuteData[i] #>); - -<# - - } -#> - - // Vector128<ushort> tests - - TestUtilities.InitializeWithElementNumberingModuloVectorLength<ushort>( - ushortTable.inArray1, 16, (int i, int elNo) => - { - return (ushort)(i % 8); - }); - - TestUtilities.InitializeWithConstValue<ushort>(0, ushortTable.inArray2); - - -<# - for (int i = 0; i < permuteData.Length; i++) - { -#> - (Vector128<ushort>, Vector128<ushort>) valueUInt16_<#= i #> = ushortTable[<#= i #>]; - Vector128<ushort> resultUInt16_<#= i #> = Sse2.ShuffleHigh(valueUInt16_<#= i #>.Item1, (byte) <#= permuteData[i] #>); - ushortTable.SetOutArray(resultUInt16_<#= i #>, <#= i #>, (byte) <#= permuteData[i] #>); - -<# - - } -#> - - 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) + 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<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) + 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 deleted file mode 100644 index addfc90d8e..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh_r.csproj +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{5B060A38-515A-4C2C-9DFB-2EC23B20FCA1}</ProjectGuid> - <OutputType>Exe</OutputType> - <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> - <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> - <AllowUnsafeBlocks>true</AllowUnsafeBlocks> - </PropertyGroup> - <!-- Default configurations to help VS understand the configurations --> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> - <ItemGroup> - <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> - <Visible>False</Visible> - </CodeAnalysisDependentAssemblyPaths> - </ItemGroup> - <PropertyGroup> - <DebugType>Embedded</DebugType> - <Optimize></Optimize> - </PropertyGroup> - <ItemGroup> - <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> - <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> - </ItemGroup> - <ItemGroup> - <Compile Include="ShuffleHigh.cs"> - <AutoGen>True</AutoGen> - <DesignTime>True</DesignTime> - <DependentUpon>ShuffleHigh.tt</DependentUpon> - </Compile> - <Compile Include="TestTableSse2.cs" /> - </ItemGroup> - <ItemGroup> - <Content Include="ShuffleHigh.tt"> - <Generator>TextTemplatingFileGenerator</Generator> - <LastGenOutput>ShuffleHigh.cs</LastGenOutput> - </Content> - </ItemGroup> - <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> - <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> - </PropertyGroup> -</Project>
\ 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 deleted file mode 100644 index 21af86716d..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleHigh_ro.csproj +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{47111150-B83B-44A1-AB94-807BEF42E5E0}</ProjectGuid> - <OutputType>Exe</OutputType> - <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> - <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> - <AllowUnsafeBlocks>true</AllowUnsafeBlocks> - </PropertyGroup> - <!-- Default configurations to help VS understand the configurations --> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> - <ItemGroup> - <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> - <Visible>False</Visible> - </CodeAnalysisDependentAssemblyPaths> - </ItemGroup> - <PropertyGroup> - <DebugType>Embedded</DebugType> - <Optimize>True</Optimize> - </PropertyGroup> - <ItemGroup> - <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> - <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> - </ItemGroup> - <ItemGroup> - <Compile Include="ShuffleHigh.cs"> - <AutoGen>True</AutoGen> - <DesignTime>True</DesignTime> - <DependentUpon>ShuffleHigh.tt</DependentUpon> - </Compile> - <Compile Include="TestTableSse2.cs" /> - </ItemGroup> - <ItemGroup> - <Content Include="ShuffleHigh.tt"> - <Generator>TextTemplatingFileGenerator</Generator> - <LastGenOutput>ShuffleHigh.cs</LastGenOutput> - </Content> - </ItemGroup> - <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> - <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> - </PropertyGroup> -</Project>
\ No newline at end of file diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.Int16.0.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.Int16.0.cs new file mode 100644 index 0000000000..77621bc8dc --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.Int16.0.cs @@ -0,0 +1,392 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleLowInt160() + { + var test = new ImmUnaryOpTest__ShuffleLowInt160(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmUnaryOpTest__ShuffleLowInt160 + { + private struct TestStruct + { + public Vector128<Int16> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref testStruct._fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmUnaryOpTest__ShuffleLowInt160 testClass) + { + var result = Sse2.ShuffleLow(_fld, 0); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16); + + private static Int16[] _data = new Int16[Op1ElementCount]; + + private static Vector128<Int16> _clsVar; + + private Vector128<Int16> _fld; + + private SimpleUnaryOpTest__DataTable<Int16, Int16> _dataTable; + + static ImmUnaryOpTest__ShuffleLowInt160() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref _clsVar), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + } + + public ImmUnaryOpTest__ShuffleLowInt160() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref _fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + _dataTable = new SimpleUnaryOpTest__DataTable<Int16, Int16>(_data, new Int16[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.ShuffleLow( + Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.ShuffleLow( + Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.ShuffleLow( + Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleLow), new Type[] { typeof(Vector128<Int16>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleLow), new Type[] { typeof(Vector128<Int16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleLow), new Type[] { typeof(Vector128<Int16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.ShuffleLow( + _clsVar, + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr); + var result = Sse2.ShuffleLow(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleLow(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleLow(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmUnaryOpTest__ShuffleLowInt160(); + var result = Sse2.ShuffleLow(test._fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.ShuffleLow(_fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.ShuffleLow(test._fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<Int16> firstOp, void* result, [CallerMemberName] string method = "") + { + Int16[] inArray = new Int16[Op1ElementCount]; + Int16[] outArray = new Int16[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), firstOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + { + Int16[] inArray = new Int16[Op1ElementCount]; + Int16[] outArray = new Int16[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(Int16[] firstOp, Int16[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (firstOp[0] != result[0]) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if ((i <= 3 ? (firstOp[0] != result[i]) : (firstOp[i] != result[i]))) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.ShuffleLow)}<Int16>(Vector128<Int16><9>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.Int16.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.Int16.1.cs new file mode 100644 index 0000000000..46caa050c5 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.Int16.1.cs @@ -0,0 +1,392 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleLowInt161() + { + var test = new ImmUnaryOpTest__ShuffleLowInt161(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmUnaryOpTest__ShuffleLowInt161 + { + private struct TestStruct + { + public Vector128<Int16> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref testStruct._fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmUnaryOpTest__ShuffleLowInt161 testClass) + { + var result = Sse2.ShuffleLow(_fld, 1); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16); + + private static Int16[] _data = new Int16[Op1ElementCount]; + + private static Vector128<Int16> _clsVar; + + private Vector128<Int16> _fld; + + private SimpleUnaryOpTest__DataTable<Int16, Int16> _dataTable; + + static ImmUnaryOpTest__ShuffleLowInt161() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref _clsVar), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + } + + public ImmUnaryOpTest__ShuffleLowInt161() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref _fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); } + _dataTable = new SimpleUnaryOpTest__DataTable<Int16, Int16>(_data, new Int16[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.ShuffleLow( + Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.ShuffleLow( + Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.ShuffleLow( + Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleLow), new Type[] { typeof(Vector128<Int16>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleLow), new Type[] { typeof(Vector128<Int16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleLow), new Type[] { typeof(Vector128<Int16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.ShuffleLow( + _clsVar, + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<Int16>>(_dataTable.inArrayPtr); + var result = Sse2.ShuffleLow(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((Int16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleLow(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleLow(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmUnaryOpTest__ShuffleLowInt161(); + var result = Sse2.ShuffleLow(test._fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.ShuffleLow(_fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.ShuffleLow(test._fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<Int16> firstOp, void* result, [CallerMemberName] string method = "") + { + Int16[] inArray = new Int16[Op1ElementCount]; + Int16[] outArray = new Int16[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), firstOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + { + Int16[] inArray = new Int16[Op1ElementCount]; + Int16[] outArray = new Int16[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(Int16[] firstOp, Int16[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (firstOp[1] != result[0]) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if ((i <= 3 ? (firstOp[0] != result[i]) : (firstOp[i] != result[i]))) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.ShuffleLow)}<Int16>(Vector128<Int16><9>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.UInt16.0.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.UInt16.0.cs new file mode 100644 index 0000000000..fd86dd7676 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.UInt16.0.cs @@ -0,0 +1,392 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleLowUInt160() + { + var test = new ImmUnaryOpTest__ShuffleLowUInt160(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmUnaryOpTest__ShuffleLowUInt160 + { + private struct TestStruct + { + public Vector128<UInt16> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref testStruct._fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmUnaryOpTest__ShuffleLowUInt160 testClass) + { + var result = Sse2.ShuffleLow(_fld, 0); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16); + + private static UInt16[] _data = new UInt16[Op1ElementCount]; + + private static Vector128<UInt16> _clsVar; + + private Vector128<UInt16> _fld; + + private SimpleUnaryOpTest__DataTable<UInt16, UInt16> _dataTable; + + static ImmUnaryOpTest__ShuffleLowUInt160() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _clsVar), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + } + + public ImmUnaryOpTest__ShuffleLowUInt160() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + _dataTable = new SimpleUnaryOpTest__DataTable<UInt16, UInt16>(_data, new UInt16[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.ShuffleLow( + Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.ShuffleLow( + Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.ShuffleLow( + Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)), + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleLow), new Type[] { typeof(Vector128<UInt16>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleLow), new Type[] { typeof(Vector128<UInt16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleLow), new Type[] { typeof(Vector128<UInt16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)), + (byte)0 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.ShuffleLow( + _clsVar, + 0 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr); + var result = Sse2.ShuffleLow(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleLow(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleLow(firstOp, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmUnaryOpTest__ShuffleLowUInt160(); + var result = Sse2.ShuffleLow(test._fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.ShuffleLow(_fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.ShuffleLow(test._fld, 0); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<UInt16> firstOp, void* result, [CallerMemberName] string method = "") + { + UInt16[] inArray = new UInt16[Op1ElementCount]; + UInt16[] outArray = new UInt16[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), firstOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + { + UInt16[] inArray = new UInt16[Op1ElementCount]; + UInt16[] outArray = new UInt16[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(UInt16[] firstOp, UInt16[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (firstOp[0] != result[0]) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if ((i <= 3 ? (firstOp[0] != result[i]) : (firstOp[i] != result[i]))) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.ShuffleLow)}<UInt16>(Vector128<UInt16><9>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.UInt16.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.UInt16.1.cs new file mode 100644 index 0000000000..9a85ea6ade --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.UInt16.1.cs @@ -0,0 +1,392 @@ +// 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. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void ShuffleLowUInt161() + { + var test = new ImmUnaryOpTest__ShuffleLowUInt161(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + } + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); + } + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + if (Sse2.IsSupported) + { + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); + } + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ImmUnaryOpTest__ShuffleLowUInt161 + { + private struct TestStruct + { + public Vector128<UInt16> _fld; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref testStruct._fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + return testStruct; + } + + public void RunStructFldScenario(ImmUnaryOpTest__ShuffleLowUInt161 testClass) + { + var result = Sse2.ShuffleLow(_fld, 1); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16); + private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16); + + private static UInt16[] _data = new UInt16[Op1ElementCount]; + + private static Vector128<UInt16> _clsVar; + + private Vector128<UInt16> _fld; + + private SimpleUnaryOpTest__DataTable<UInt16, UInt16> _dataTable; + + static ImmUnaryOpTest__ShuffleLowUInt161() + { + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _clsVar), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + } + + public ImmUnaryOpTest__ShuffleLowUInt161() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); } + _dataTable = new SimpleUnaryOpTest__DataTable<UInt16, UInt16>(_data, new UInt16[RetElementCount], LargestVectorSize); + } + + public bool IsSupported => Sse2.IsSupported; + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Sse2.ShuffleLow( + Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + + var result = Sse2.ShuffleLow( + Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + + var result = Sse2.ShuffleLow( + Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)), + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleLow), new Type[] { typeof(Vector128<UInt16>), typeof(byte) }) + .Invoke(null, new object[] { + Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleLow), new Type[] { typeof(Vector128<UInt16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); + + var result = typeof(Sse2).GetMethod(nameof(Sse2.ShuffleLow), new Type[] { typeof(Vector128<UInt16>), typeof(byte) }) + .Invoke(null, new object[] { + Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)), + (byte)1 + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result)); + ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Sse2.ShuffleLow( + _clsVar, + 1 + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var firstOp = Unsafe.Read<Vector128<UInt16>>(_dataTable.inArrayPtr); + var result = Sse2.ShuffleLow(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + + var firstOp = Sse2.LoadVector128((UInt16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleLow(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + + var firstOp = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArrayPtr)); + var result = Sse2.ShuffleLow(firstOp, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(firstOp, _dataTable.outArrayPtr); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ImmUnaryOpTest__ShuffleLowUInt161(); + var result = Sse2.ShuffleLow(test._fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Sse2.ShuffleLow(_fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld, _dataTable.outArrayPtr); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Sse2.ShuffleLow(test._fld, 1); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld, _dataTable.outArrayPtr); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(Vector128<UInt16> firstOp, void* result, [CallerMemberName] string method = "") + { + UInt16[] inArray = new UInt16[Op1ElementCount]; + UInt16[] outArray = new UInt16[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), firstOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + { + UInt16[] inArray = new UInt16[Op1ElementCount]; + UInt16[] outArray = new UInt16[RetElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>()); + + ValidateResult(inArray, outArray, method); + } + + private void ValidateResult(UInt16[] firstOp, UInt16[] result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + if (firstOp[1] != result[0]) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + if ((i <= 3 ? (firstOp[0] != result[i]) : (firstOp[i] != result[i]))) + { + succeeded = false; + break; + } + } + } + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sse2)}.{nameof(Sse2.ShuffleLow)}<UInt16>(Vector128<UInt16><9>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.cs deleted file mode 100644 index cfbf02b052..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.cs +++ /dev/null @@ -1,266 +0,0 @@ -// 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<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; - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.tt b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.tt deleted file mode 100644 index 04327da50e..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow.tt +++ /dev/null @@ -1,190 +0,0 @@ -<#@ 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<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); - -<# - for (int i = 0; i < permuteData.Length; i++) - { -#> - (Vector128<short>, Vector128<short>) valueInt16_<#= i #> = shortTable[<#= i #>]; - Vector128<short> resultInt16_<#= i #> = Sse2.ShuffleLow(valueInt16_<#= i #>.Item1, (byte) <#= permuteData[i] #>); - shortTable.SetOutArray(resultInt16_<#= i #>, <#= i #>, (byte) <#= permuteData[i] #>); - -<# - - } -#> - - // Vector128<ushort> tests - - TestUtilities.InitializeWithElementNumberingModuloVectorLength<ushort>( - ushortTable.inArray1, 16, (int i, int elNo) => - { - return (ushort)(i % 8); - }); - - TestUtilities.InitializeWithConstValue<ushort>(0, ushortTable.inArray2); - - -<# - for (int i = 0; i < permuteData.Length; i++) - { -#> - (Vector128<ushort>, Vector128<ushort>) valueUInt16_<#= i #> = ushortTable[<#= i #>]; - Vector128<ushort> resultUInt16_<#= i #> = Sse2.ShuffleLow(valueUInt16_<#= i #>.Item1, (byte) <#= permuteData[i] #>); - ushortTable.SetOutArray(resultUInt16_<#= i #>, <#= i #>, (byte) <#= permuteData[i] #>); - -<# - - } -#> - - 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; - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow_r.csproj deleted file mode 100644 index 702ad23c47..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow_r.csproj +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{3DCFB777-8A32-443E-ABD9-4636600D2B4F}</ProjectGuid> - <OutputType>Exe</OutputType> - <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> - <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> - <AllowUnsafeBlocks>true</AllowUnsafeBlocks> - </PropertyGroup> - <!-- Default configurations to help VS understand the configurations --> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> - <ItemGroup> - <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> - <Visible>False</Visible> - </CodeAnalysisDependentAssemblyPaths> - </ItemGroup> - <PropertyGroup> - <DebugType>Embedded</DebugType> - <Optimize></Optimize> - </PropertyGroup> - <ItemGroup> - <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> - <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> - </ItemGroup> - <ItemGroup> - <Compile Include="ShuffleLow.cs"> - <AutoGen>True</AutoGen> - <DesignTime>True</DesignTime> - <DependentUpon>ShuffleLow.tt</DependentUpon> - </Compile> - <Compile Include="TestTableSse2.cs" /> - </ItemGroup> - <ItemGroup> - <Content Include="ShuffleLow.tt"> - <Generator>TextTemplatingFileGenerator</Generator> - <LastGenOutput>ShuffleLow.cs</LastGenOutput> - </Content> - </ItemGroup> - <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> - <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> - </PropertyGroup> -</Project>
\ 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 deleted file mode 100644 index 2929d51ee1..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/ShuffleLow_ro.csproj +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{A9DAC473-F5CB-4DA9-ADE4-2F9EB53FC4A8}</ProjectGuid> - <OutputType>Exe</OutputType> - <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> - <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> - <AllowUnsafeBlocks>true</AllowUnsafeBlocks> - </PropertyGroup> - <!-- Default configurations to help VS understand the configurations --> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> - <ItemGroup> - <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> - <Visible>False</Visible> - </CodeAnalysisDependentAssemblyPaths> - </ItemGroup> - <PropertyGroup> - <DebugType>Embedded</DebugType> - <Optimize>True</Optimize> - </PropertyGroup> - <ItemGroup> - <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> - <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> - </ItemGroup> - <ItemGroup> - <Compile Include="ShuffleLow.cs"> - <AutoGen>True</AutoGen> - <DesignTime>True</DesignTime> - <DependentUpon>ShuffleLow.tt</DependentUpon> - </Compile> - <Compile Include="TestTableSse2.cs" /> - </ItemGroup> - <ItemGroup> - <Content Include="ShuffleLow.tt"> - <Generator>TextTemplatingFileGenerator</Generator> - <LastGenOutput>ShuffleLow.cs</LastGenOutput> - </Content> - </ItemGroup> - <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> - <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> - </PropertyGroup> -</Project>
\ 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 deleted file mode 100644 index cac561b2be..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle_r.csproj +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{D25DF7E1-96B0-454A-A5BE-70C26BE49559}</ProjectGuid> - <OutputType>Exe</OutputType> - <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> - <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> - <AllowUnsafeBlocks>true</AllowUnsafeBlocks> - </PropertyGroup> - <!-- Default configurations to help VS understand the configurations --> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> - <ItemGroup> - <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> - <Visible>False</Visible> - </CodeAnalysisDependentAssemblyPaths> - </ItemGroup> - <PropertyGroup> - <DebugType>Embedded</DebugType> - <Optimize></Optimize> - </PropertyGroup> - <ItemGroup> - <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> - <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> - </ItemGroup> - <ItemGroup> - <Compile Include="Shuffle.cs"> - <AutoGen>True</AutoGen> - <DesignTime>True</DesignTime> - <DependentUpon>Shuffle.tt</DependentUpon> - </Compile> - <Compile Include="TestTableSse2.cs" /> - </ItemGroup> - <ItemGroup> - <Content Include="Shuffle.tt"> - <Generator>TextTemplatingFileGenerator</Generator> - <LastGenOutput>Shuffle.cs</LastGenOutput> - </Content> - </ItemGroup> - <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> - <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> - </PropertyGroup> -</Project>
\ 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 deleted file mode 100644 index 0569985a67..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Shuffle_ro.csproj +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{695760F3-DA13-4227-9ED6-AD8C5E5D88C6}</ProjectGuid> - <OutputType>Exe</OutputType> - <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> - <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> - <AllowUnsafeBlocks>true</AllowUnsafeBlocks> - </PropertyGroup> - <!-- Default configurations to help VS understand the configurations --> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> - <ItemGroup> - <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> - <Visible>False</Visible> - </CodeAnalysisDependentAssemblyPaths> - </ItemGroup> - <PropertyGroup> - <DebugType>Embedded</DebugType> - <Optimize>True</Optimize> - </PropertyGroup> - <ItemGroup> - <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> - <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> - </ItemGroup> - <ItemGroup> - <Compile Include="Shuffle.cs"> - <AutoGen>True</AutoGen> - <DesignTime>True</DesignTime> - <DependentUpon>Shuffle.tt</DependentUpon> - </Compile> - <Compile Include="TestTableSse2.cs" /> - </ItemGroup> - <ItemGroup> - <Content Include="Shuffle.tt"> - <Generator>TextTemplatingFileGenerator</Generator> - <LastGenOutput>Shuffle.cs</LastGenOutput> - </Content> - </ItemGroup> - <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> - <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> - </PropertyGroup> -</Project>
\ No newline at end of file diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Sse2_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Sse2_r.csproj index fa9f5969ce..900e2a11e2 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Sse2_r.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Sse2_r.csproj @@ -159,6 +159,9 @@ <Compile Include="MultiplyAddAdjacent.Int32.cs" /> <Compile Include="MultiplyLow.Int16.cs" /> <Compile Include="MultiplyLow.UInt16.cs" /> + <Compile Include="MoveMask.Vector128Byte.cs" /> + <Compile Include="MoveMask.Vector128SByte.cs" /> + <Compile Include="MoveMask.Vector128Double.cs" /> <Compile Include="Or.Double.cs" /> <Compile Include="Or.Byte.cs" /> <Compile Include="Or.Int16.cs" /> @@ -215,6 +218,20 @@ <Compile Include="ShiftRightLogical128BitLane.UInt32.1.cs" /> <Compile Include="ShiftRightLogical128BitLane.Int64.1.cs" /> <Compile Include="ShiftRightLogical128BitLane.UInt64.1.cs" /> + <Compile Include="Shuffle.Int32.0.cs" /> + <Compile Include="Shuffle.UInt32.0.cs" /> + <Compile Include="Shuffle.Int32.1.cs" /> + <Compile Include="Shuffle.UInt32.1.cs" /> + <Compile Include="Shuffle.Double.0.cs" /> + <Compile Include="Shuffle.Double.1.cs" /> + <Compile Include="ShuffleHigh.Int16.0.cs" /> + <Compile Include="ShuffleHigh.UInt16.0.cs" /> + <Compile Include="ShuffleHigh.Int16.1.cs" /> + <Compile Include="ShuffleHigh.UInt16.1.cs" /> + <Compile Include="ShuffleLow.Int16.0.cs" /> + <Compile Include="ShuffleLow.UInt16.0.cs" /> + <Compile Include="ShuffleLow.Int16.1.cs" /> + <Compile Include="ShuffleLow.UInt16.1.cs" /> <Compile Include="Subtract.Double.cs" /> <Compile Include="Subtract.Byte.cs" /> <Compile Include="Subtract.Int16.cs" /> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Sse2_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Sse2_ro.csproj index f0331c69e4..9ad362660b 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Sse2_ro.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Sse2_ro.csproj @@ -159,6 +159,9 @@ <Compile Include="MultiplyAddAdjacent.Int32.cs" /> <Compile Include="MultiplyLow.Int16.cs" /> <Compile Include="MultiplyLow.UInt16.cs" /> + <Compile Include="MoveMask.Vector128Byte.cs" /> + <Compile Include="MoveMask.Vector128SByte.cs" /> + <Compile Include="MoveMask.Vector128Double.cs" /> <Compile Include="Or.Byte.cs" /> <Compile Include="Or.Double.cs" /> <Compile Include="Or.Int16.cs" /> @@ -216,6 +219,20 @@ <Compile Include="ShiftRightLogical128BitLane.UInt16.1.cs" /> <Compile Include="ShiftRightLogical128BitLane.UInt32.1.cs" /> <Compile Include="ShiftRightLogical128BitLane.UInt64.1.cs" /> + <Compile Include="Shuffle.Int32.0.cs" /> + <Compile Include="Shuffle.UInt32.0.cs" /> + <Compile Include="Shuffle.Int32.1.cs" /> + <Compile Include="Shuffle.UInt32.1.cs" /> + <Compile Include="Shuffle.Double.0.cs" /> + <Compile Include="Shuffle.Double.1.cs" /> + <Compile Include="ShuffleHigh.Int16.0.cs" /> + <Compile Include="ShuffleHigh.UInt16.0.cs" /> + <Compile Include="ShuffleHigh.Int16.1.cs" /> + <Compile Include="ShuffleHigh.UInt16.1.cs" /> + <Compile Include="ShuffleLow.Int16.0.cs" /> + <Compile Include="ShuffleLow.UInt16.0.cs" /> + <Compile Include="ShuffleLow.Int16.1.cs" /> + <Compile Include="ShuffleLow.UInt16.1.cs" /> <Compile Include="Subtract.Byte.cs" /> <Compile Include="Subtract.Double.cs" /> <Compile Include="Subtract.Int16.cs" /> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.Int64.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.Int64.1.cs index c3639cfd0e..39e7db9fe8 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.Int64.1.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.Int64.1.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<Int64> _fld; + public Int64 _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt64(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int64>, byte>(ref testStruct._fld), ref Unsafe.As<Int64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int64>>()); + testStruct._scalarFldData = (long)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertInt641 testClass) { - var result = Sse41.X64.Insert(_fld, (long)2, 1); + var result = Sse41.X64.Insert(_fld, _scalarFldData, 1); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int64>>() / sizeof(Int64); private static Int64[] _data = new Int64[Op1ElementCount]; + private static Int64 _scalarClsData = (long)2; private static Vector128<Int64> _clsVar; private Vector128<Int64> _fld; + private Int64 _scalarFldData = (long)2; private SimpleUnaryOpTest__DataTable<Int64, Int64> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse41.X64.Insert( Unsafe.Read<Vector128<Int64>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (long)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + Int64 localData = (long)2; + Int64* ptr = &localData; + var result = Sse41.X64.Insert( Sse2.LoadVector128((Int64*)(_dataTable.inArrayPtr)), - (long)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + Int64 localData = (long)2; + Int64* ptr = &localData; + var result = Sse41.X64.Insert( Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArrayPtr)), - (long)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse41.X64).GetMethod(nameof(Sse41.X64.Insert), new Type[] { typeof(Vector128<Int64>), typeof(Int64), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int64>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (long)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int64>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (long)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int64>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (long)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse41.X64.Insert( _clsVar, - (long)2, + _scalarClsData, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + Int64 localData = (long)2; var firstOp = Unsafe.Read<Vector128<Int64>>(_dataTable.inArrayPtr); - var result = Sse41.X64.Insert(firstOp, (long)2, 1); + var result = Sse41.X64.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + Int64 localData = (long)2; + var firstOp = Sse2.LoadVector128((Int64*)(_dataTable.inArrayPtr)); - var result = Sse41.X64.Insert(firstOp, (long)2, 1); + var result = Sse41.X64.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + Int64 localData = (long)2; + var firstOp = Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArrayPtr)); - var result = Sse41.X64.Insert(firstOp, (long)2, 1); + var result = Sse41.X64.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertInt641(); - var result = Sse41.X64.Insert(test._fld, (long)2, 1); + var result = Sse41.X64.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse41.X64.Insert(_fld, (long)2, 1); + var result = Sse41.X64.Insert(_fld, _scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse41.X64.Insert(test._fld, (long)2, 1); + var result = Sse41.X64.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Int64> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Int64> firstOp, Int64 scalarData, void* result, [CallerMemberName] string method = "") { Int64[] inArray = new Int64[Op1ElementCount]; Int64[] outArray = new Int64[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<Int64, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int64>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, Int64 scalarData, void* result, [CallerMemberName] string method = "") { Int64[] inArray = new Int64[Op1ElementCount]; Int64[] outArray = new Int64[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int64>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int64>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(Int64[] firstOp, Int64[] result, [CallerMemberName] string method = "") + private void ValidateResult(Int64[] firstOp, Int64 scalarData, Int64[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != firstOp[i])) + if ((i == 1 ? result[i] != scalarData : result[i] != firstOp[i])) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.Int64.129.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.Int64.129.cs index e3f790148a..e7f5e2fcb7 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.Int64.129.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.Int64.129.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<Int64> _fld; + public Int64 _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt64(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int64>, byte>(ref testStruct._fld), ref Unsafe.As<Int64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int64>>()); + testStruct._scalarFldData = (long)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertInt64129 testClass) { - var result = Sse41.X64.Insert(_fld, (long)2, 129); + var result = Sse41.X64.Insert(_fld, _scalarFldData, 129); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int64>>() / sizeof(Int64); private static Int64[] _data = new Int64[Op1ElementCount]; + private static Int64 _scalarClsData = (long)2; private static Vector128<Int64> _clsVar; private Vector128<Int64> _fld; + private Int64 _scalarFldData = (long)2; private SimpleUnaryOpTest__DataTable<Int64, Int64> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse41.X64.Insert( Unsafe.Read<Vector128<Int64>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (long)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + Int64 localData = (long)2; + Int64* ptr = &localData; + var result = Sse41.X64.Insert( Sse2.LoadVector128((Int64*)(_dataTable.inArrayPtr)), - (long)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + Int64 localData = (long)2; + Int64* ptr = &localData; + var result = Sse41.X64.Insert( Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArrayPtr)), - (long)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse41.X64).GetMethod(nameof(Sse41.X64.Insert), new Type[] { typeof(Vector128<Int64>), typeof(Int64), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int64>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (long)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int64>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (long)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int64>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (long)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse41.X64.Insert( _clsVar, - (long)2, + _scalarClsData, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + Int64 localData = (long)2; var firstOp = Unsafe.Read<Vector128<Int64>>(_dataTable.inArrayPtr); - var result = Sse41.X64.Insert(firstOp, (long)2, 129); + var result = Sse41.X64.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + Int64 localData = (long)2; + var firstOp = Sse2.LoadVector128((Int64*)(_dataTable.inArrayPtr)); - var result = Sse41.X64.Insert(firstOp, (long)2, 129); + var result = Sse41.X64.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + Int64 localData = (long)2; + var firstOp = Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArrayPtr)); - var result = Sse41.X64.Insert(firstOp, (long)2, 129); + var result = Sse41.X64.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertInt64129(); - var result = Sse41.X64.Insert(test._fld, (long)2, 129); + var result = Sse41.X64.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse41.X64.Insert(_fld, (long)2, 129); + var result = Sse41.X64.Insert(_fld, _scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse41.X64.Insert(test._fld, (long)2, 129); + var result = Sse41.X64.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Int64> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Int64> firstOp, Int64 scalarData, void* result, [CallerMemberName] string method = "") { Int64[] inArray = new Int64[Op1ElementCount]; Int64[] outArray = new Int64[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<Int64, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int64>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, Int64 scalarData, void* result, [CallerMemberName] string method = "") { Int64[] inArray = new Int64[Op1ElementCount]; Int64[] outArray = new Int64[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int64>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int64>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(Int64[] firstOp, Int64[] result, [CallerMemberName] string method = "") + private void ValidateResult(Int64[] firstOp, Int64 scalarData, Int64[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != firstOp[i])) + if ((i == 1 ? result[i] != scalarData : result[i] != firstOp[i])) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.UInt64.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.UInt64.1.cs index 4e9641d677..096b0e2a0e 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.UInt64.1.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.UInt64.1.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<UInt64> _fld; + public UInt64 _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt64(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt64>, byte>(ref testStruct._fld), ref Unsafe.As<UInt64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt64>>()); + testStruct._scalarFldData = (ulong)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertUInt641 testClass) { - var result = Sse41.X64.Insert(_fld, (ulong)2, 1); + var result = Sse41.X64.Insert(_fld, _scalarFldData, 1); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt64>>() / sizeof(UInt64); private static UInt64[] _data = new UInt64[Op1ElementCount]; + private static UInt64 _scalarClsData = (ulong)2; private static Vector128<UInt64> _clsVar; private Vector128<UInt64> _fld; + private UInt64 _scalarFldData = (ulong)2; private SimpleUnaryOpTest__DataTable<UInt64, UInt64> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse41.X64.Insert( Unsafe.Read<Vector128<UInt64>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ulong)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + UInt64 localData = (ulong)2; + UInt64* ptr = &localData; + var result = Sse41.X64.Insert( Sse2.LoadVector128((UInt64*)(_dataTable.inArrayPtr)), - (ulong)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + UInt64 localData = (ulong)2; + UInt64* ptr = &localData; + var result = Sse41.X64.Insert( Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArrayPtr)), - (ulong)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse41.X64).GetMethod(nameof(Sse41.X64.Insert), new Type[] { typeof(Vector128<UInt64>), typeof(UInt64), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt64>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ulong)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt64>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ulong)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt64>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ulong)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse41.X64.Insert( _clsVar, - (ulong)2, + _scalarClsData, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + UInt64 localData = (ulong)2; var firstOp = Unsafe.Read<Vector128<UInt64>>(_dataTable.inArrayPtr); - var result = Sse41.X64.Insert(firstOp, (ulong)2, 1); + var result = Sse41.X64.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + UInt64 localData = (ulong)2; + var firstOp = Sse2.LoadVector128((UInt64*)(_dataTable.inArrayPtr)); - var result = Sse41.X64.Insert(firstOp, (ulong)2, 1); + var result = Sse41.X64.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + UInt64 localData = (ulong)2; + var firstOp = Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArrayPtr)); - var result = Sse41.X64.Insert(firstOp, (ulong)2, 1); + var result = Sse41.X64.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertUInt641(); - var result = Sse41.X64.Insert(test._fld, (ulong)2, 1); + var result = Sse41.X64.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse41.X64.Insert(_fld, (ulong)2, 1); + var result = Sse41.X64.Insert(_fld, _scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse41.X64.Insert(test._fld, (ulong)2, 1); + var result = Sse41.X64.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<UInt64> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<UInt64> firstOp, UInt64 scalarData, void* result, [CallerMemberName] string method = "") { UInt64[] inArray = new UInt64[Op1ElementCount]; UInt64[] outArray = new UInt64[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt64>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, UInt64 scalarData, void* result, [CallerMemberName] string method = "") { UInt64[] inArray = new UInt64[Op1ElementCount]; UInt64[] outArray = new UInt64[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt64>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt64>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(UInt64[] firstOp, UInt64[] result, [CallerMemberName] string method = "") + private void ValidateResult(UInt64[] firstOp, UInt64 scalarData, UInt64[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != firstOp[i])) + if ((i == 1 ? result[i] != scalarData : result[i] != firstOp[i])) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.UInt64.129.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.UInt64.129.cs index c359e7beda..9b7bba3947 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.UInt64.129.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41.X64/Insert.UInt64.129.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<UInt64> _fld; + public UInt64 _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt64(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt64>, byte>(ref testStruct._fld), ref Unsafe.As<UInt64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt64>>()); + testStruct._scalarFldData = (ulong)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertUInt64129 testClass) { - var result = Sse41.X64.Insert(_fld, (ulong)2, 129); + var result = Sse41.X64.Insert(_fld, _scalarFldData, 129); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt64>>() / sizeof(UInt64); private static UInt64[] _data = new UInt64[Op1ElementCount]; + private static UInt64 _scalarClsData = (ulong)2; private static Vector128<UInt64> _clsVar; private Vector128<UInt64> _fld; + private UInt64 _scalarFldData = (ulong)2; private SimpleUnaryOpTest__DataTable<UInt64, UInt64> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse41.X64.Insert( Unsafe.Read<Vector128<UInt64>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ulong)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + UInt64 localData = (ulong)2; + UInt64* ptr = &localData; + var result = Sse41.X64.Insert( Sse2.LoadVector128((UInt64*)(_dataTable.inArrayPtr)), - (ulong)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + UInt64 localData = (ulong)2; + UInt64* ptr = &localData; + var result = Sse41.X64.Insert( Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArrayPtr)), - (ulong)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse41.X64).GetMethod(nameof(Sse41.X64.Insert), new Type[] { typeof(Vector128<UInt64>), typeof(UInt64), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt64>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ulong)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt64>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ulong)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt64>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (ulong)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse41.X64.Insert( _clsVar, - (ulong)2, + _scalarClsData, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + UInt64 localData = (ulong)2; var firstOp = Unsafe.Read<Vector128<UInt64>>(_dataTable.inArrayPtr); - var result = Sse41.X64.Insert(firstOp, (ulong)2, 129); + var result = Sse41.X64.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + UInt64 localData = (ulong)2; + var firstOp = Sse2.LoadVector128((UInt64*)(_dataTable.inArrayPtr)); - var result = Sse41.X64.Insert(firstOp, (ulong)2, 129); + var result = Sse41.X64.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + UInt64 localData = (ulong)2; + var firstOp = Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArrayPtr)); - var result = Sse41.X64.Insert(firstOp, (ulong)2, 129); + var result = Sse41.X64.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertUInt64129(); - var result = Sse41.X64.Insert(test._fld, (ulong)2, 129); + var result = Sse41.X64.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse41.X64.Insert(_fld, (ulong)2, 129); + var result = Sse41.X64.Insert(_fld, _scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse41.X64.Insert(test._fld, (ulong)2, 129); + var result = Sse41.X64.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<UInt64> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<UInt64> firstOp, UInt64 scalarData, void* result, [CallerMemberName] string method = "") { UInt64[] inArray = new UInt64[Op1ElementCount]; UInt64[] outArray = new UInt64[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt64>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, UInt64 scalarData, void* result, [CallerMemberName] string method = "") { UInt64[] inArray = new UInt64[Op1ElementCount]; UInt64[] outArray = new UInt64[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt64>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt64>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(UInt64[] firstOp, UInt64[] result, [CallerMemberName] string method = "") + private void ValidateResult(UInt64[] firstOp, UInt64 scalarData, UInt64[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != firstOp[i])) + if ((i == 1 ? result[i] != scalarData : result[i] != firstOp[i])) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Byte.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Byte.1.cs index 50ea9f28c6..397d14db7d 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Byte.1.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Byte.1.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<Byte> _fld; + public Byte _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Byte>, byte>(ref testStruct._fld), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Byte>>()); + testStruct._scalarFldData = (byte)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertByte1 testClass) { - var result = Sse41.Insert(_fld, (byte)2, 1); + var result = Sse41.Insert(_fld, _scalarFldData, 1); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Byte>>() / sizeof(Byte); private static Byte[] _data = new Byte[Op1ElementCount]; + private static Byte _scalarClsData = (byte)2; private static Vector128<Byte> _clsVar; private Vector128<Byte> _fld; + private Byte _scalarFldData = (byte)2; private SimpleUnaryOpTest__DataTable<Byte, Byte> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse41.Insert( Unsafe.Read<Vector128<Byte>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (byte)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + Byte localData = (byte)2; + Byte* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadVector128((Byte*)(_dataTable.inArrayPtr)), - (byte)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + Byte localData = (byte)2; + Byte* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArrayPtr)), - (byte)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse41).GetMethod(nameof(Sse41.Insert), new Type[] { typeof(Vector128<Byte>), typeof(Byte), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Byte>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (byte)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Byte>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (byte)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Byte>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (byte)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse41.Insert( _clsVar, - (byte)2, + _scalarClsData, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + Byte localData = (byte)2; var firstOp = Unsafe.Read<Vector128<Byte>>(_dataTable.inArrayPtr); - var result = Sse41.Insert(firstOp, (byte)2, 1); + var result = Sse41.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + Byte localData = (byte)2; + var firstOp = Sse2.LoadVector128((Byte*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (byte)2, 1); + var result = Sse41.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + Byte localData = (byte)2; + var firstOp = Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (byte)2, 1); + var result = Sse41.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertByte1(); - var result = Sse41.Insert(test._fld, (byte)2, 1); + var result = Sse41.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse41.Insert(_fld, (byte)2, 1); + var result = Sse41.Insert(_fld, _scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse41.Insert(test._fld, (byte)2, 1); + var result = Sse41.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Byte> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Byte> firstOp, Byte scalarData, void* result, [CallerMemberName] string method = "") { Byte[] inArray = new Byte[Op1ElementCount]; Byte[] outArray = new Byte[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<Byte, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Byte>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, Byte scalarData, void* result, [CallerMemberName] string method = "") { Byte[] inArray = new Byte[Op1ElementCount]; Byte[] outArray = new Byte[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Byte>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Byte>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(Byte[] firstOp, Byte[] result, [CallerMemberName] string method = "") + private void ValidateResult(Byte[] firstOp, Byte scalarData, Byte[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != firstOp[i])) + if ((i == 1 ? result[i] != scalarData : result[i] != firstOp[i])) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Byte.129.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Byte.129.cs index 0deb791389..5f78a41a76 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Byte.129.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Byte.129.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<Byte> _fld; + public Byte _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Byte>, byte>(ref testStruct._fld), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Byte>>()); + testStruct._scalarFldData = (byte)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertByte129 testClass) { - var result = Sse41.Insert(_fld, (byte)2, 129); + var result = Sse41.Insert(_fld, _scalarFldData, 129); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Byte>>() / sizeof(Byte); private static Byte[] _data = new Byte[Op1ElementCount]; + private static Byte _scalarClsData = (byte)2; private static Vector128<Byte> _clsVar; private Vector128<Byte> _fld; + private Byte _scalarFldData = (byte)2; private SimpleUnaryOpTest__DataTable<Byte, Byte> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse41.Insert( Unsafe.Read<Vector128<Byte>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (byte)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + Byte localData = (byte)2; + Byte* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadVector128((Byte*)(_dataTable.inArrayPtr)), - (byte)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + Byte localData = (byte)2; + Byte* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArrayPtr)), - (byte)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse41).GetMethod(nameof(Sse41.Insert), new Type[] { typeof(Vector128<Byte>), typeof(Byte), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Byte>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (byte)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Byte>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (byte)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Byte>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (byte)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse41.Insert( _clsVar, - (byte)2, + _scalarClsData, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + Byte localData = (byte)2; var firstOp = Unsafe.Read<Vector128<Byte>>(_dataTable.inArrayPtr); - var result = Sse41.Insert(firstOp, (byte)2, 129); + var result = Sse41.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + Byte localData = (byte)2; + var firstOp = Sse2.LoadVector128((Byte*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (byte)2, 129); + var result = Sse41.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + Byte localData = (byte)2; + var firstOp = Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (byte)2, 129); + var result = Sse41.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertByte129(); - var result = Sse41.Insert(test._fld, (byte)2, 129); + var result = Sse41.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse41.Insert(_fld, (byte)2, 129); + var result = Sse41.Insert(_fld, _scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse41.Insert(test._fld, (byte)2, 129); + var result = Sse41.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Byte> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Byte> firstOp, Byte scalarData, void* result, [CallerMemberName] string method = "") { Byte[] inArray = new Byte[Op1ElementCount]; Byte[] outArray = new Byte[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<Byte, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Byte>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, Byte scalarData, void* result, [CallerMemberName] string method = "") { Byte[] inArray = new Byte[Op1ElementCount]; Byte[] outArray = new Byte[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Byte>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Byte>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(Byte[] firstOp, Byte[] result, [CallerMemberName] string method = "") + private void ValidateResult(Byte[] firstOp, Byte scalarData, Byte[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != firstOp[i])) + if ((i == 1 ? result[i] != scalarData : result[i] != firstOp[i])) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Int32.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Int32.1.cs index 0a4e9c7007..3ece48f9a3 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Int32.1.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Int32.1.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<Int32> _fld; + public Int32 _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref testStruct._fld), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + testStruct._scalarFldData = (int)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertInt321 testClass) { - var result = Sse41.Insert(_fld, (int)2, 1); + var result = Sse41.Insert(_fld, _scalarFldData, 1); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int32>>() / sizeof(Int32); private static Int32[] _data = new Int32[Op1ElementCount]; + private static Int32 _scalarClsData = (int)2; private static Vector128<Int32> _clsVar; private Vector128<Int32> _fld; + private Int32 _scalarFldData = (int)2; private SimpleUnaryOpTest__DataTable<Int32, Int32> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse41.Insert( Unsafe.Read<Vector128<Int32>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (int)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + Int32 localData = (int)2; + Int32* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadVector128((Int32*)(_dataTable.inArrayPtr)), - (int)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + Int32 localData = (int)2; + Int32* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArrayPtr)), - (int)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse41).GetMethod(nameof(Sse41.Insert), new Type[] { typeof(Vector128<Int32>), typeof(Int32), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (int)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (int)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (int)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse41.Insert( _clsVar, - (int)2, + _scalarClsData, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + Int32 localData = (int)2; var firstOp = Unsafe.Read<Vector128<Int32>>(_dataTable.inArrayPtr); - var result = Sse41.Insert(firstOp, (int)2, 1); + var result = Sse41.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + Int32 localData = (int)2; + var firstOp = Sse2.LoadVector128((Int32*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (int)2, 1); + var result = Sse41.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + Int32 localData = (int)2; + var firstOp = Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (int)2, 1); + var result = Sse41.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertInt321(); - var result = Sse41.Insert(test._fld, (int)2, 1); + var result = Sse41.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse41.Insert(_fld, (int)2, 1); + var result = Sse41.Insert(_fld, _scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse41.Insert(test._fld, (int)2, 1); + var result = Sse41.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Int32> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Int32> firstOp, Int32 scalarData, void* result, [CallerMemberName] string method = "") { Int32[] inArray = new Int32[Op1ElementCount]; Int32[] outArray = new Int32[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, Int32 scalarData, void* result, [CallerMemberName] string method = "") { Int32[] inArray = new Int32[Op1ElementCount]; Int32[] outArray = new Int32[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int32>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(Int32[] firstOp, Int32[] result, [CallerMemberName] string method = "") + private void ValidateResult(Int32[] firstOp, Int32 scalarData, Int32[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != firstOp[i])) + if ((i == 1 ? result[i] != scalarData : result[i] != firstOp[i])) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Int32.129.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Int32.129.cs index e738d77abb..710c7130bb 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Int32.129.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.Int32.129.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<Int32> _fld; + public Int32 _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref testStruct._fld), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>()); + testStruct._scalarFldData = (int)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertInt32129 testClass) { - var result = Sse41.Insert(_fld, (int)2, 129); + var result = Sse41.Insert(_fld, _scalarFldData, 129); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int32>>() / sizeof(Int32); private static Int32[] _data = new Int32[Op1ElementCount]; + private static Int32 _scalarClsData = (int)2; private static Vector128<Int32> _clsVar; private Vector128<Int32> _fld; + private Int32 _scalarFldData = (int)2; private SimpleUnaryOpTest__DataTable<Int32, Int32> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse41.Insert( Unsafe.Read<Vector128<Int32>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (int)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + Int32 localData = (int)2; + Int32* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadVector128((Int32*)(_dataTable.inArrayPtr)), - (int)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + Int32 localData = (int)2; + Int32* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArrayPtr)), - (int)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse41).GetMethod(nameof(Sse41.Insert), new Type[] { typeof(Vector128<Int32>), typeof(Int32), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (int)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (int)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (int)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse41.Insert( _clsVar, - (int)2, + _scalarClsData, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + Int32 localData = (int)2; var firstOp = Unsafe.Read<Vector128<Int32>>(_dataTable.inArrayPtr); - var result = Sse41.Insert(firstOp, (int)2, 129); + var result = Sse41.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + Int32 localData = (int)2; + var firstOp = Sse2.LoadVector128((Int32*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (int)2, 129); + var result = Sse41.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + Int32 localData = (int)2; + var firstOp = Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (int)2, 129); + var result = Sse41.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertInt32129(); - var result = Sse41.Insert(test._fld, (int)2, 129); + var result = Sse41.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse41.Insert(_fld, (int)2, 129); + var result = Sse41.Insert(_fld, _scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse41.Insert(test._fld, (int)2, 129); + var result = Sse41.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Int32> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Int32> firstOp, Int32 scalarData, void* result, [CallerMemberName] string method = "") { Int32[] inArray = new Int32[Op1ElementCount]; Int32[] outArray = new Int32[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, Int32 scalarData, void* result, [CallerMemberName] string method = "") { Int32[] inArray = new Int32[Op1ElementCount]; Int32[] outArray = new Int32[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int32>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(Int32[] firstOp, Int32[] result, [CallerMemberName] string method = "") + private void ValidateResult(Int32[] firstOp, Int32 scalarData, Int32[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != firstOp[i])) + if ((i == 1 ? result[i] != scalarData : result[i] != firstOp[i])) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.SByte.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.SByte.1.cs index 9bfebc4926..b9f69e9e66 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.SByte.1.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.SByte.1.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<SByte> _fld; + public SByte _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<SByte>, byte>(ref testStruct._fld), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<SByte>>()); + testStruct._scalarFldData = (sbyte)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertSByte1 testClass) { - var result = Sse41.Insert(_fld, (sbyte)2, 1); + var result = Sse41.Insert(_fld, _scalarFldData, 1); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<SByte>>() / sizeof(SByte); private static SByte[] _data = new SByte[Op1ElementCount]; + private static SByte _scalarClsData = (sbyte)2; private static Vector128<SByte> _clsVar; private Vector128<SByte> _fld; + private SByte _scalarFldData = (sbyte)2; private SimpleUnaryOpTest__DataTable<SByte, SByte> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse41.Insert( Unsafe.Read<Vector128<SByte>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (sbyte)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + SByte localData = (sbyte)2; + SByte* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadVector128((SByte*)(_dataTable.inArrayPtr)), - (sbyte)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + SByte localData = (sbyte)2; + SByte* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArrayPtr)), - (sbyte)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse41).GetMethod(nameof(Sse41.Insert), new Type[] { typeof(Vector128<SByte>), typeof(SByte), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<SByte>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (sbyte)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<SByte>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (sbyte)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<SByte>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (sbyte)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse41.Insert( _clsVar, - (sbyte)2, + _scalarClsData, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + SByte localData = (sbyte)2; var firstOp = Unsafe.Read<Vector128<SByte>>(_dataTable.inArrayPtr); - var result = Sse41.Insert(firstOp, (sbyte)2, 1); + var result = Sse41.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + SByte localData = (sbyte)2; + var firstOp = Sse2.LoadVector128((SByte*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (sbyte)2, 1); + var result = Sse41.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + SByte localData = (sbyte)2; + var firstOp = Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (sbyte)2, 1); + var result = Sse41.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertSByte1(); - var result = Sse41.Insert(test._fld, (sbyte)2, 1); + var result = Sse41.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse41.Insert(_fld, (sbyte)2, 1); + var result = Sse41.Insert(_fld, _scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse41.Insert(test._fld, (sbyte)2, 1); + var result = Sse41.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<SByte> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<SByte> firstOp, SByte scalarData, void* result, [CallerMemberName] string method = "") { SByte[] inArray = new SByte[Op1ElementCount]; SByte[] outArray = new SByte[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<SByte, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<SByte>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, SByte scalarData, void* result, [CallerMemberName] string method = "") { SByte[] inArray = new SByte[Op1ElementCount]; SByte[] outArray = new SByte[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<SByte>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<SByte>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(SByte[] firstOp, SByte[] result, [CallerMemberName] string method = "") + private void ValidateResult(SByte[] firstOp, SByte scalarData, SByte[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != firstOp[i])) + if ((i == 1 ? result[i] != scalarData : result[i] != firstOp[i])) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.SByte.129.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.SByte.129.cs index 23404c5631..d8f45dce08 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.SByte.129.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.SByte.129.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<SByte> _fld; + public SByte _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<SByte>, byte>(ref testStruct._fld), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<SByte>>()); + testStruct._scalarFldData = (sbyte)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertSByte129 testClass) { - var result = Sse41.Insert(_fld, (sbyte)2, 129); + var result = Sse41.Insert(_fld, _scalarFldData, 129); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<SByte>>() / sizeof(SByte); private static SByte[] _data = new SByte[Op1ElementCount]; + private static SByte _scalarClsData = (sbyte)2; private static Vector128<SByte> _clsVar; private Vector128<SByte> _fld; + private SByte _scalarFldData = (sbyte)2; private SimpleUnaryOpTest__DataTable<SByte, SByte> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse41.Insert( Unsafe.Read<Vector128<SByte>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (sbyte)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + SByte localData = (sbyte)2; + SByte* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadVector128((SByte*)(_dataTable.inArrayPtr)), - (sbyte)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + SByte localData = (sbyte)2; + SByte* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArrayPtr)), - (sbyte)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse41).GetMethod(nameof(Sse41.Insert), new Type[] { typeof(Vector128<SByte>), typeof(SByte), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<SByte>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (sbyte)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<SByte>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (sbyte)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<SByte>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (sbyte)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse41.Insert( _clsVar, - (sbyte)2, + _scalarClsData, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + SByte localData = (sbyte)2; var firstOp = Unsafe.Read<Vector128<SByte>>(_dataTable.inArrayPtr); - var result = Sse41.Insert(firstOp, (sbyte)2, 129); + var result = Sse41.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + SByte localData = (sbyte)2; + var firstOp = Sse2.LoadVector128((SByte*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (sbyte)2, 129); + var result = Sse41.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + SByte localData = (sbyte)2; + var firstOp = Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (sbyte)2, 129); + var result = Sse41.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertSByte129(); - var result = Sse41.Insert(test._fld, (sbyte)2, 129); + var result = Sse41.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse41.Insert(_fld, (sbyte)2, 129); + var result = Sse41.Insert(_fld, _scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse41.Insert(test._fld, (sbyte)2, 129); + var result = Sse41.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<SByte> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<SByte> firstOp, SByte scalarData, void* result, [CallerMemberName] string method = "") { SByte[] inArray = new SByte[Op1ElementCount]; SByte[] outArray = new SByte[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<SByte, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<SByte>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, SByte scalarData, void* result, [CallerMemberName] string method = "") { SByte[] inArray = new SByte[Op1ElementCount]; SByte[] outArray = new SByte[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<SByte>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<SByte>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(SByte[] firstOp, SByte[] result, [CallerMemberName] string method = "") + private void ValidateResult(SByte[] firstOp, SByte scalarData, SByte[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != firstOp[i])) + if ((i == 1 ? result[i] != scalarData : result[i] != firstOp[i])) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.UInt32.1.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.UInt32.1.cs index f3696c780f..fc9abac74a 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.UInt32.1.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.UInt32.1.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<UInt32> _fld; + public UInt32 _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref testStruct._fld), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + testStruct._scalarFldData = (uint)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertUInt321 testClass) { - var result = Sse41.Insert(_fld, (uint)2, 1); + var result = Sse41.Insert(_fld, _scalarFldData, 1); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt32>>() / sizeof(UInt32); private static UInt32[] _data = new UInt32[Op1ElementCount]; + private static UInt32 _scalarClsData = (uint)2; private static Vector128<UInt32> _clsVar; private Vector128<UInt32> _fld; + private UInt32 _scalarFldData = (uint)2; private SimpleUnaryOpTest__DataTable<UInt32, UInt32> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse41.Insert( Unsafe.Read<Vector128<UInt32>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (uint)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + UInt32 localData = (uint)2; + UInt32* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadVector128((UInt32*)(_dataTable.inArrayPtr)), - (uint)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + UInt32 localData = (uint)2; + UInt32* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArrayPtr)), - (uint)2, + *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse41).GetMethod(nameof(Sse41.Insert), new Type[] { typeof(Vector128<UInt32>), typeof(UInt32), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (uint)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (uint)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (uint)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse41.Insert( _clsVar, - (uint)2, + _scalarClsData, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + UInt32 localData = (uint)2; var firstOp = Unsafe.Read<Vector128<UInt32>>(_dataTable.inArrayPtr); - var result = Sse41.Insert(firstOp, (uint)2, 1); + var result = Sse41.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + UInt32 localData = (uint)2; + var firstOp = Sse2.LoadVector128((UInt32*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (uint)2, 1); + var result = Sse41.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + UInt32 localData = (uint)2; + var firstOp = Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (uint)2, 1); + var result = Sse41.Insert(firstOp, localData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertUInt321(); - var result = Sse41.Insert(test._fld, (uint)2, 1); + var result = Sse41.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse41.Insert(_fld, (uint)2, 1); + var result = Sse41.Insert(_fld, _scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse41.Insert(test._fld, (uint)2, 1); + var result = Sse41.Insert(test._fld, test._scalarFldData, 1); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<UInt32> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<UInt32> firstOp, UInt32 scalarData, void* result, [CallerMemberName] string method = "") { UInt32[] inArray = new UInt32[Op1ElementCount]; UInt32[] outArray = new UInt32[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, UInt32 scalarData, void* result, [CallerMemberName] string method = "") { UInt32[] inArray = new UInt32[Op1ElementCount]; UInt32[] outArray = new UInt32[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(UInt32[] firstOp, UInt32[] result, [CallerMemberName] string method = "") + private void ValidateResult(UInt32[] firstOp, UInt32 scalarData, UInt32[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != firstOp[i])) + if ((i == 1 ? result[i] != scalarData : result[i] != firstOp[i])) { succeeded = false; break; diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.UInt32.129.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.UInt32.129.cs index b5b00395ab..a5b62091e0 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.UInt32.129.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Insert.UInt32.129.cs @@ -26,7 +26,7 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); + test.RunBasicScenario(); if (Sse2.IsSupported) { @@ -38,7 +38,7 @@ namespace JIT.HardwareIntrinsics.X86 } // Validates calling via reflection works, using Unsafe.Read - test.RunReflectionScenario_UnsafeRead(); + test.RunReflectionScenario(); if (Sse2.IsSupported) { @@ -53,7 +53,7 @@ namespace JIT.HardwareIntrinsics.X86 test.RunClsVarScenario(); // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); + test.RunLclVarScenario(); if (Sse2.IsSupported) { @@ -94,6 +94,7 @@ namespace JIT.HardwareIntrinsics.X86 private struct TestStruct { public Vector128<UInt32> _fld; + public UInt32 _scalarFldData; public static TestStruct Create() { @@ -102,15 +103,17 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref testStruct._fld), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); + testStruct._scalarFldData = (uint)2; + return testStruct; } public void RunStructFldScenario(InsertScalarTest__InsertUInt32129 testClass) { - var result = Sse41.Insert(_fld, (uint)2, 129); + var result = Sse41.Insert(_fld, _scalarFldData, 129); Unsafe.Write(testClass._dataTable.outArrayPtr, result); - testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr); + testClass.ValidateResult(_fld, _scalarFldData, testClass._dataTable.outArrayPtr); } } @@ -120,10 +123,12 @@ namespace JIT.HardwareIntrinsics.X86 private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt32>>() / sizeof(UInt32); private static UInt32[] _data = new UInt32[Op1ElementCount]; + private static UInt32 _scalarClsData = (uint)2; private static Vector128<UInt32> _clsVar; private Vector128<UInt32> _fld; + private UInt32 _scalarFldData = (uint)2; private SimpleUnaryOpTest__DataTable<UInt32, UInt32> _dataTable; @@ -148,9 +153,9 @@ namespace JIT.HardwareIntrinsics.X86 public bool Succeeded { get; set; } - public void RunBasicScenario_UnsafeRead() + public void RunBasicScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); var result = Sse41.Insert( Unsafe.Read<Vector128<UInt32>>(_dataTable.inArrayPtr), @@ -159,40 +164,46 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (uint)2, _dataTable.outArrayPtr); } - public void RunBasicScenario_Load() + public unsafe void RunBasicScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); + UInt32 localData = (uint)2; + UInt32* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadVector128((UInt32*)(_dataTable.inArrayPtr)), - (uint)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunBasicScenario_LoadAligned() + public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); + UInt32 localData = (uint)2; + UInt32* ptr = &localData; + var result = Sse41.Insert( Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArrayPtr)), - (uint)2, + *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario_UnsafeRead() + public void RunReflectionScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario)); var result = typeof(Sse41).GetMethod(nameof(Sse41.Insert), new Type[] { typeof(Vector128<UInt32>), typeof(UInt32), typeof(byte) }) .Invoke(null, new object[] { @@ -202,7 +213,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (uint)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_Load() @@ -217,7 +228,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (uint)2, _dataTable.outArrayPtr); } public void RunReflectionScenario_LoadAligned() @@ -232,7 +243,7 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result)); - ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); + ValidateResult(_dataTable.inArrayPtr, (uint)2, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -241,45 +252,51 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse41.Insert( _clsVar, - (uint)2, + _scalarClsData, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar, _dataTable.outArrayPtr); + ValidateResult(_clsVar, _scalarClsData,_dataTable.outArrayPtr); } - public void RunLclVarScenario_UnsafeRead() + public void RunLclVarScenario() { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario)); + + UInt32 localData = (uint)2; var firstOp = Unsafe.Read<Vector128<UInt32>>(_dataTable.inArrayPtr); - var result = Sse41.Insert(firstOp, (uint)2, 129); + var result = Sse41.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); + UInt32 localData = (uint)2; + var firstOp = Sse2.LoadVector128((UInt32*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (uint)2, 129); + var result = Sse41.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); + UInt32 localData = (uint)2; + var firstOp = Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArrayPtr)); - var result = Sse41.Insert(firstOp, (uint)2, 129); + var result = Sse41.Insert(firstOp, localData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, _dataTable.outArrayPtr); + ValidateResult(firstOp, localData, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -287,20 +304,20 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new InsertScalarTest__InsertUInt32129(); - var result = Sse41.Insert(test._fld, (uint)2, 129); + var result = Sse41.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - var result = Sse41.Insert(_fld, (uint)2, 129); + var result = Sse41.Insert(_fld, _scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld, _dataTable.outArrayPtr); + ValidateResult(_fld, _scalarFldData, _dataTable.outArrayPtr); } public void RunStructLclFldScenario() @@ -308,10 +325,10 @@ namespace JIT.HardwareIntrinsics.X86 TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); - var result = Sse41.Insert(test._fld, (uint)2, 129); + var result = Sse41.Insert(test._fld, test._scalarFldData, 129); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld, _dataTable.outArrayPtr); + ValidateResult(test._fld, test._scalarFldData, _dataTable.outArrayPtr); } public void RunStructFldScenario() @@ -330,7 +347,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario_UnsafeRead(); + RunBasicScenario(); } catch (PlatformNotSupportedException) { @@ -343,7 +360,7 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<UInt32> firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<UInt32> firstOp, UInt32 scalarData, void* result, [CallerMemberName] string method = "") { UInt32[] inArray = new UInt32[Op1ElementCount]; UInt32[] outArray = new UInt32[RetElementCount]; @@ -351,10 +368,10 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.WriteUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), firstOp); Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* firstOp, UInt32 scalarData, void* result, [CallerMemberName] string method = "") { UInt32[] inArray = new UInt32[Op1ElementCount]; UInt32[] outArray = new UInt32[RetElementCount]; @@ -362,16 +379,16 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>()); - ValidateResult(inArray, outArray, method); + ValidateResult(inArray, scalarData, outArray, method); } - private void ValidateResult(UInt32[] firstOp, UInt32[] result, [CallerMemberName] string method = "") + private void ValidateResult(UInt32[] firstOp, UInt32 scalarData, UInt32[] result, [CallerMemberName] string method = "") { bool succeeded = true; for (var i = 0; i < RetElementCount; i++) { - if ((i == 1 ? result[i] != 2 : result[i] != firstOp[i])) + if ((i == 1 ? result[i] != scalarData : result[i] != firstOp[i])) { succeeded = false; break; |