diff options
author | Fei Peng <fei.peng@intel.com> | 2017-10-10 10:19:17 -0700 |
---|---|---|
committer | Fei Peng <fei.peng@intel.com> | 2017-10-25 17:46:18 -0700 |
commit | 8a7e5c21540fef4e6cafec279711a1b9b94961b3 (patch) | |
tree | 6aacf52b996b992db821c1ce21655dfaee26400a /tests | |
parent | 5b99e1ac5765eb676f789514686059b1a66b233d (diff) | |
download | coreclr-8a7e5c21540fef4e6cafec279711a1b9b94961b3.tar.gz coreclr-8a7e5c21540fef4e6cafec279711a1b9b94961b3.tar.bz2 coreclr-8a7e5c21540fef4e6cafec279711a1b9b94961b3.zip |
Enable Crc32 , Popcnt, Lzcnt intrinsics
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/JIT/HardwareIntrinsics/Crc32.cs | 180 | ||||
-rw-r--r-- | tests/src/JIT/HardwareIntrinsics/Crc32_r.csproj | 33 | ||||
-rw-r--r-- | tests/src/JIT/HardwareIntrinsics/Crc32_ro.csproj | 33 | ||||
-rw-r--r-- | tests/src/JIT/HardwareIntrinsics/Lzcnt.cs | 99 | ||||
-rw-r--r-- | tests/src/JIT/HardwareIntrinsics/Lzcnt_r.csproj | 33 | ||||
-rw-r--r-- | tests/src/JIT/HardwareIntrinsics/Lzcnt_ro.csproj | 33 | ||||
-rw-r--r-- | tests/src/JIT/HardwareIntrinsics/Popcnt.cs | 101 | ||||
-rw-r--r-- | tests/src/JIT/HardwareIntrinsics/Popcnt_r.csproj | 33 | ||||
-rw-r--r-- | tests/src/JIT/HardwareIntrinsics/Popcnt_ro.csproj | 33 |
9 files changed, 578 insertions, 0 deletions
diff --git a/tests/src/JIT/HardwareIntrinsics/Crc32.cs b/tests/src/JIT/HardwareIntrinsics/Crc32.cs new file mode 100644 index 0000000000..27ea5a9bbf --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/Crc32.cs @@ -0,0 +1,180 @@ +// 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.X86; + +namespace IntelHardwareIntrinsicTest +{ + class Program + { + const int Pass = 100; + const int Fail = 0; + + static int Main(string[] args) + { + ulong s1l = 0, s2l = 0, resl; + int testResult = Pass; + + if (!Sse42.IsSupported || !Environment.Is64BitProcess) + { + try + { + resl = Sse42.Crc32(s1l, s2l); + Console.WriteLine("Intrinsic Sse42.Crc32 is called on non-supported hardware."); + Console.WriteLine("Sse42.IsSupported " + Sse42.IsSupported); + Console.WriteLine("Environment.Is64BitProcess " + Environment.Is64BitProcess); + return Fail; + } + catch (PlatformNotSupportedException) + { + testResult = Pass; + } + } + + + if (Sse42.IsSupported) + { + if (Environment.Is64BitProcess) + { + for (int i = 0; i < longCrcTable.Length; i++) + { + s1l = longCrcTable[i].s1; + s2l = longCrcTable[i].s2; + resl = Sse42.Crc32(s1l, s2l); + if (resl != longCrcTable[i].res) + { + Console.WriteLine("{0}: Inputs: 0x{1,16:x}, 0x{2,16:x} Expected: 0x{3,16:x} actual: 0x{4,16:x}", + i, s1l, s2l, longCrcTable[i].res, resl); + testResult = Fail; + } + } + } + + uint s1i, s2i, resi; + for (int i = 0; i < intCrcTable.Length; i++) + { + s1i = intCrcTable[i].s1; + s2i = intCrcTable[i].s2; + resi = Sse42.Crc32(s1i, s2i); + if (resi != intCrcTable[i].res) + { + Console.WriteLine("{0}: Inputs: 0x{1,8:x}, 0x{2,8:x} Expected: 0x{3,8:x} actual: 0x{4,8:x}", + i, s1i, s2i, intCrcTable[i].res, resi); + testResult = Fail; + } + } + + ushort s2s; + for (int i = 0; i < shortCrcTable.Length; i++) + { + s1i = shortCrcTable[i].s1; + s2s = shortCrcTable[i].s2; + resi = Sse42.Crc32(s1i, s2s); + if (resi != shortCrcTable[i].res) + { + Console.WriteLine("{0}: Inputs: 0x{1,8:x}, 0x{2,8:x} Expected: 0x{3,8:x} actual: 0x{4,8:x}", + i, s1i, s2s, shortCrcTable[i].res, resi); + testResult = Fail; + } + } + + byte s2b; + for (int i = 0; i < byteCrcTable.Length; i++) + { + s1i = byteCrcTable[i].s1; + s2b = byteCrcTable[i].s2; + resi = Sse42.Crc32(s1i, s2b); + if (resi != byteCrcTable[i].res) + { + Console.WriteLine("{0}: Inputs: 0x{1,8:x}, 0x{2,8:x} Expected: 0x{3,8:x} actual: 0x{4,8:x}", + i, s1i, s2b, byteCrcTable[i].res, resi); + testResult = Fail; + } + } + } + + return testResult; + } + + public struct Crc<T, U> where T : struct where U : struct + { + public T s1; + public U s2; + public T res; + public Crc(T a, U b, T c) + { + this.s1 = a; + this.s2 = b; + this.res = c; + } + } + + public static Crc<ulong, ulong>[] longCrcTable = { + new Crc<ulong, ulong>(0x0000000000000000UL, 0x0000000000000000UL, 0x0000000000000000UL), + new Crc<ulong, ulong>(0x0000000000000000UL, 0x0000000000000001UL, 0x00000000493c7d27UL), + new Crc<ulong, ulong>(0x0000000000000001UL, 0x0000000000000000UL, 0x00000000493c7d27UL), + new Crc<ulong, ulong>(0x0000000000000001UL, 0x0000000000000001UL, 0x0000000000000000UL), + new Crc<ulong, ulong>(0x0000000000000000UL, 0xffffffffffffffffUL, 0x00000000c44ff94dUL), + new Crc<ulong, ulong>(0xffffffffffffffffUL, 0x0000000000000000UL, 0x0000000073d74d75UL), + new Crc<ulong, ulong>(0xffffffffffffffffUL, 0xffffffffffffffffUL, 0x00000000b798b438UL), + new Crc<ulong, ulong>(0x0000000000000001UL, 0xffffffffffffffffUL, 0x000000008d73846aUL), + new Crc<ulong, ulong>(0xffffffffffffffffUL, 0x0000000000000001UL, 0x000000003aeb3052UL), + new Crc<ulong, ulong>(0xfffffffffffe1f0dUL, 0x00000000f5c1ddb3UL, 0x000000000504c066UL), + new Crc<ulong, ulong>(0x0000000000000005UL, 0x000000bce1263cffUL, 0x000000004ab954daUL), + new Crc<ulong, ulong>(0x0000000000000463UL, 0xffffffffff840d0dUL, 0x00000000797d59f3UL), + new Crc<ulong, ulong>(0x00000000000f423fUL, 0x000000000001e0f3UL, 0x000000005c6b8093UL) + }; + + public static Crc<uint, uint>[] intCrcTable = { + new Crc<uint, uint>(0x00000000U, 0x00000000U, 0x00000000U), + new Crc<uint, uint>(0x00000000U, 0x00000001U, 0xdd45aab8U), + new Crc<uint, uint>(0x00000001U, 0x00000000U, 0xdd45aab8U), + new Crc<uint, uint>(0x00000001U, 0x00000001U, 0x00000000U), + new Crc<uint, uint>(0x00000000U, 0xffffffffU, 0xb798b438U), + new Crc<uint, uint>(0xffffffffU, 0x00000000U, 0xb798b438U), + new Crc<uint, uint>(0xffffffffU, 0xffffffffU, 0x00000000U), + new Crc<uint, uint>(0x00000001U, 0xffffffffU, 0x6add1e80U), + new Crc<uint, uint>(0xffffffffU, 0x00000001U, 0x6add1e80U), + new Crc<uint, uint>(0xfffe1f0dU, 0xf5c1ddb3U, 0x911888ccU), + new Crc<uint, uint>(0x00000005U, 0xe1263cffU, 0xbe12f661U), + new Crc<uint, uint>(0x00000463U, 0xff840d0dU, 0xcba65e37U), + new Crc<uint, uint>(0x000f423fU, 0x0001e0f3U, 0xa5b7881dU) + }; + + public static Crc<uint, ushort>[] shortCrcTable = { + new Crc<uint, ushort>(0x00000000U, 0x0000, 0x00000000U), + new Crc<uint, ushort>(0x00000000U, 0x0001, 0x13a29877U), + new Crc<uint, ushort>(0x00000001U, 0x0000, 0x13a29877U), + new Crc<uint, ushort>(0x00000001U, 0x0001, 0x00000000U), + new Crc<uint, ushort>(0x00000000U, 0xffff, 0xe9e77d2U), + new Crc<uint, ushort>(0xffffffffU, 0x0000, 0xe9e882dU), + new Crc<uint, ushort>(0xffffffffU, 0xffff, 0x0000ffffU), + new Crc<uint, ushort>(0x00000001U, 0xffff, 0x1d3cefa5U), + new Crc<uint, ushort>(0xffffffffU, 0x0001, 0x1d3c105aU), + new Crc<uint, ushort>(0xfffe1f0dU, 0xddb3, 0x6de0d33dU), + new Crc<uint, ushort>(0x00000005U, 0x3cff, 0x836b5b49U), + new Crc<uint, ushort>(0x00000463U, 0x0d0d, 0x0cf56c40U), + new Crc<uint, ushort>(0x000f423fU, 0xe0f3, 0x943a5bc7U) + }; + + public static Crc<uint, byte>[] byteCrcTable = { + new Crc<uint, byte>(0x00000000U, 0x00, 0x00000000U), + new Crc<uint, byte>(0x00000000U, 0x01, 0xf26b8303U), + new Crc<uint, byte>(0x00000001U, 0x00, 0xf26b8303U), + new Crc<uint, byte>(0x00000001U, 0x01, 0x00000000U), + new Crc<uint, byte>(0x00000000U, 0xff, 0xad7d5351U), + new Crc<uint, byte>(0xffffffffU, 0x00, 0xad82acaeU), + new Crc<uint, byte>(0xffffffffU, 0xff, 0x00ffffffU), + new Crc<uint, byte>(0x00000001U, 0xff, 0x5f16d052U), + new Crc<uint, byte>(0xffffffffU, 0x01, 0x5fe92fadU), + new Crc<uint, byte>(0xfffe1f0dU, 0xb3, 0x1e9233f1U), + new Crc<uint, byte>(0x00000005U, 0xff, 0x988c474dU), + new Crc<uint, byte>(0x00000463U, 0x0d, 0xcdbe2c41U), + new Crc<uint, byte>(0x000f423fU, 0xf3, 0x8ecee656U) + }; + + } +}
\ No newline at end of file diff --git a/tests/src/JIT/HardwareIntrinsics/Crc32_r.csproj b/tests/src/JIT/HardwareIntrinsics/Crc32_r.csproj new file mode 100644 index 0000000000..e42eeb4f93 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/Crc32_r.csproj @@ -0,0 +1,33 @@ +<?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>{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> + </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>None</DebugType> + <Optimize></Optimize> + </PropertyGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Crc32.cs" /> + </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/Crc32_ro.csproj b/tests/src/JIT/HardwareIntrinsics/Crc32_ro.csproj new file mode 100644 index 0000000000..0dfe5e0930 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/Crc32_ro.csproj @@ -0,0 +1,33 @@ +<?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>{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> + </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>None</DebugType> + <Optimize>True</Optimize> + </PropertyGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Crc32.cs" /> + </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/Lzcnt.cs b/tests/src/JIT/HardwareIntrinsics/Lzcnt.cs new file mode 100644 index 0000000000..9d40c08c54 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/Lzcnt.cs @@ -0,0 +1,99 @@ +// 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.X86; + +namespace IntelHardwareIntrinsicTest +{ + class Program + { + const int Pass = 100; + const int Fail = 0; + + static int Main(string[] args) + { + ulong sl = 0, resl; + int testResult = Pass; + + if (!Lzcnt.IsSupported || !Environment.Is64BitProcess) + { + try + { + resl = Lzcnt.LeadingZeroCount(sl); + Console.WriteLine("Intrinsic Lzcnt.LeadingZeroCount is called on non-supported hardware."); + Console.WriteLine("Lzcnt.IsSupported " + Lzcnt.IsSupported); + Console.WriteLine("Environment.Is64BitProcess " + Environment.Is64BitProcess); + return Fail; + } + catch (PlatformNotSupportedException) + { + testResult = Pass; + } + } + + + if (Lzcnt.IsSupported) + { + if (Environment.Is64BitProcess) + { + for (int i = 0; i < longLzcntTable.Length; i++) + { + sl = longLzcntTable[i].s; + resl = Lzcnt.LeadingZeroCount(sl); + if (resl != longLzcntTable[i].res) + { + Console.WriteLine("{0}: Inputs: 0x{1,16:x} Expected: 0x{3,16:x} actual: 0x{4,16:x}", + i, sl, longLzcntTable[i].res, resl); + testResult = Fail; + } + } + } + + uint si, resi; + for (int i = 0; i < intLzcntTable.Length; i++) + { + si = intLzcntTable[i].s; + resi = Lzcnt.LeadingZeroCount(si); + if (resi != intLzcntTable[i].res) + { + Console.WriteLine("{0}: Inputs: 0x{1,16:x} Expected: 0x{3,16:x} actual: 0x{4,16:x}", + i, si, intLzcntTable[i].res, resi); + testResult = Fail; + } + } + } + + return testResult; + } + + public struct LZCNT<T> where T : struct + { + public T s; + public T res; + public LZCNT(T a, T r) + { + this.s = a; + this.res = r; + } + } + + public static LZCNT<ulong>[] longLzcntTable = { + new LZCNT<ulong>(0x0000000000000000UL, 64), + new LZCNT<ulong>(0x0000000000000001UL, 63), + new LZCNT<ulong>(0xffffffffffffffffUL, 0), + new LZCNT<ulong>(0xf000000000000000UL, 0), + new LZCNT<ulong>(0x00050000000f423fUL, 13) + }; + + public static LZCNT<uint>[] intLzcntTable = { + new LZCNT<uint>(0x00000000U, 32), + new LZCNT<uint>(0x00000001U, 31), + new LZCNT<uint>(0xffffffffU, 0), + new LZCNT<uint>(0xf0000000U, 0), + new LZCNT<uint>(0x0005423fU, 13) + }; + } +}
\ No newline at end of file diff --git a/tests/src/JIT/HardwareIntrinsics/Lzcnt_r.csproj b/tests/src/JIT/HardwareIntrinsics/Lzcnt_r.csproj new file mode 100644 index 0000000000..cc76545fcc --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/Lzcnt_r.csproj @@ -0,0 +1,33 @@ +<?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>{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> + </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>None</DebugType> + <Optimize></Optimize> + </PropertyGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Lzcnt.cs" /> + </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/Lzcnt_ro.csproj b/tests/src/JIT/HardwareIntrinsics/Lzcnt_ro.csproj new file mode 100644 index 0000000000..9bc71c3767 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/Lzcnt_ro.csproj @@ -0,0 +1,33 @@ +<?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>{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> + </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>None</DebugType> + <Optimize>True</Optimize> + </PropertyGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Lzcnt.cs" /> + </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/Popcnt.cs b/tests/src/JIT/HardwareIntrinsics/Popcnt.cs new file mode 100644 index 0000000000..20c443ba53 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/Popcnt.cs @@ -0,0 +1,101 @@ +// 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.X86; + +namespace IntelHardwareIntrinsicTest +{ + class Program + { + const int Pass = 100; + const int Fail = 0; + + static int Main(string[] args) + { + ulong sl = 0; + long resl; + int testResult = Pass; + + if (!Popcnt.IsSupported || !Environment.Is64BitProcess) + { + try + { + resl = Popcnt.PopCount(sl); + Console.WriteLine("Intrinsic Popcnt.PopCount is called on non-supported hardware"); + Console.WriteLine("Popcnt.IsSupported " + Popcnt.IsSupported); + Console.WriteLine("Environment.Is64BitProcess " + Environment.Is64BitProcess); + return Fail; + } + catch (PlatformNotSupportedException) + { + testResult = Pass; + } + } + + + if (Popcnt.IsSupported) + { + if (Environment.Is64BitProcess) + { + for (int i = 0; i < longPopcntTable.Length; i++) + { + sl = longPopcntTable[i].s; + resl = Popcnt.PopCount(sl); + if (resl != longPopcntTable[i].res) + { + Console.WriteLine("{0}: Inputs: 0x{1,16:x} Expected: 0x{3,16:x} actual: 0x{4,16:x}", + i, sl, longPopcntTable[i].res, resl); + testResult = Fail; + } + } + } + + uint si; + int resi; + for (int i = 0; i < intPopcntTable.Length; i++) + { + si = intPopcntTable[i].s; + resi = Popcnt.PopCount(si); + if (resi != intPopcntTable[i].res) + { + Console.WriteLine("{0}: Inputs: 0x{1,16:x} Expected: 0x{3,16:x} actual: 0x{4,16:x}", + i, si, intPopcntTable[i].res, resi); + testResult = Fail; + } + } + } + + return testResult; + } + + public struct POPCNT<T, U> where T : struct where U : struct + { + public T s; + public U res; + public POPCNT(T a, U r) + { + this.s = a; + this.res = r; + } + } + + public static POPCNT<ulong,long>[] longPopcntTable = { + new POPCNT<ulong,long>(0x0000000000000000UL, 0), + new POPCNT<ulong,long>(0x0000000000000001UL, 1), + new POPCNT<ulong,long>(0xffffffffffffffffUL, 64), + new POPCNT<ulong,long>(0x8000000000000000UL, 1), + new POPCNT<ulong,long>(0x00050000000f423fUL, 14) + }; + + public static POPCNT<uint,int>[] intPopcntTable = { + new POPCNT<uint,int>(0x00000000U, 0), + new POPCNT<uint,int>(0x00000001U, 1), + new POPCNT<uint,int>(0xffffffffU, 32), + new POPCNT<uint,int>(0x80000000U, 1), + new POPCNT<uint,int>(0x0005423fU, 10) + }; + } +}
\ No newline at end of file diff --git a/tests/src/JIT/HardwareIntrinsics/Popcnt_r.csproj b/tests/src/JIT/HardwareIntrinsics/Popcnt_r.csproj new file mode 100644 index 0000000000..2a0e814c3e --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/Popcnt_r.csproj @@ -0,0 +1,33 @@ +<?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>{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> + </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>None</DebugType> + <Optimize></Optimize> + </PropertyGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Popcnt.cs" /> + </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/Popcnt_ro.csproj b/tests/src/JIT/HardwareIntrinsics/Popcnt_ro.csproj new file mode 100644 index 0000000000..1a1414aecf --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/Popcnt_ro.csproj @@ -0,0 +1,33 @@ +<?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>{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> + </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>None</DebugType> + <Optimize>True</Optimize> + </PropertyGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Popcnt.cs" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> +</Project>
\ No newline at end of file |