cpu_features.NET 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package cpu_features.NET --version 1.0.0
NuGet\Install-Package cpu_features.NET -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="cpu_features.NET" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add cpu_features.NET --version 1.0.0
#r "nuget: cpu_features.NET, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install cpu_features.NET as a Cake Addin
#addin nuget:?package=cpu_features.NET&version=1.0.0

// Install cpu_features.NET as a Cake Tool
#tool nuget:?package=cpu_features.NET&version=1.0.0

cpu_features.NET

NuGet Downloads Stars License

Tests Status

.NET version of google/cpu_features for getting cpu info at runtime.

Table of Contents

<a name="rationale"></a>

Design Rationale

  • .NET Standard 1.1
  • Simple to use. See the snippets below for examples.
  • cpu_features.NET is suitable for implementing lib functions.

<a name="codesample"></a>

Code samples

Checking features at runtime

Here's a simple example that executes a codepath if the CPU supports SSE4A instruction sets:

using System;
using CpuFeaturesDotNet.X86;

namespace CpuFeaturesDotNet.Samples
{
    public class Program
    {
        public static void Main(string[] args) 
        {
            X86Info x86Info = X86Info.GetX86Info();
            bool sse4a = x86Info.Features.IsSupportedSSE4A;
            if (sse4a) 
            {
                // Run optimized code.
            }
            else 
            {
                // Run standard code.
            }
        }
    }
}

Caching for faster evaluation of complex checks

If you wish, you can read all the features at once into a global variable, and then query for the specific features you care about.

using System;
using CpuFeaturesDotNet.X86;

namespace CpuFeaturesDotNet.Samples
{
    public class Program
    {
        public static X86Info X86Info = X86Info.GetX86Info();
        
        public static void Main(string[] args) 
        {
            X86Microarchitecture uarch = X86Info.GetX86Microarchitecture(info);
            bool hasFastAvx = info.Features.IsSupportedAVX && uarch != X86Microarchitecture.INTEL_SANDYBRIDGE;
        }
    }
}

Rejecting poor hardware implementations based on microarchitecture

On x86, the first incarnation of a feature in a microarchitecture might not be the most efficient (e.g. AVX on Sandy Bridge). We provide a function to retrieve the underlying microarchitecture so you can decide whether to use it.

Below, hasFastAvx is set to 1 if the CPU supports the AVX instruction set—but only if it's not Sandy Bridge.

using System;
using CpuFeaturesDotNet.X86;

namespace CpuFeaturesDotNet.Samples
{
    public class Program
    {
        public static void Main(string[] args) 
        {
            X86Info info = X86Info.GetX86Info();
            X86Microarchitecture uarch = X86Info.GetX86Microarchitecture(info);
            bool hasFastAvx = info.Features.IsSupportedAVX && uarch != X86Microarchitecture.INTEL_SANDYBRIDGE;
        }
    }
}

This feature is currently available only for x86 microarchitectures.

<a name="usagesample"></a>

Running sample code

Use CpuFeaturesDotNet.Samples for detection your CPU.

CpuFeaturesDotNet.Samples.CpuFeaturesListX64.StartRunner

{
  "Features": {
    "IsSupportedFPU": true,
    "IsSupportedTSC": true,
    "IsSupportedCX8": true,
    "IsSupportedCLFSH": true,
    "IsSupportedMMX": true,
    "IsSupportedAES": true,
    "IsSupportedERMS": true,
    "IsSupportedF16C": true,
    "IsSupportedFMA4": false,
    "IsSupportedFMA3": true,
    "IsSupportedVAES": false,
    "IsSupportedVPCLMULQDQ": false,
    "IsSupportedBMI1": true,
    "IsSupportedHLE": false,
    "IsSupportedBMI2": true,
    "IsSupportedRTM": false,
    "IsSupportedRDSEED": true,
    "IsSupportedCLFLUSHOPT": true,
    "IsSupportedCLWB": false,
    "IsSupportedSSE": true,
    "IsSupportedSSE2": true,
    "IsSupportedSSE3": true,
    "IsSupportedSSSE3": true,
    "IsSupportedSSE4_1": true,
    "IsSupportedSSE4_2": true,
    "IsSupportedSSE4A": false,
    "IsSupportedAVX": true,
    "IsSupportedAVX2": true,
    "IsSupportedAVX512F": false,
    "IsSupportedAVX512CD": false,
    "IsSupportedAVX512ER": false,
    "IsSupportedAVX512PF": false,
    "IsSupportedAVX512BW": false,
    "IsSupportedAVX512DQ": false,
    "IsSupportedAVX512VL": false,
    "IsSupportedAVX512IFMA": false,
    "IsSupportedAVX512VBMI": false,
    "IsSupportedAVX512VBMI2": false,
    "IsSupportedAVX512VNNI": false,
    "IsSupportedAVX512BITALG": false,
    "IsSupportedAVX512VPOPCNTDQ": false,
    "IsSupportedAVX512_4VNNIW": false,
    "IsSupportedAVX512_4VBMI2": false,
    "IsSupportedAVX512_SECOND_FMA": false,
    "IsSupportedAVX512_4FMAPS": false,
    "IsSupportedAVX512_BF16": false,
    "IsSupportedAVX512_VP2INTERSECT": false,
    "IsSupportedAMX_BF16": false,
    "IsSupportedAMX_TILE": false,
    "IsSupportedAMX_INT8": false,
    "IsSupportedPCLMULQDQ": true,
    "IsSupportedSMX": false,
    "IsSupportedSGX": false,
    "IsSupportedCX16": true,
    "IsSupportedSHA": false,
    "IsSupportedDPOPCNT": true,
    "IsSupportedDMOVBE": true,
    "IsSupportedDRDRND": true,
    "IsSupportedDCA": false,
    "IsSupportedSS": true,
    "IsSupportedADX": true
  },
  "Family": 6,
  "Model": 142,
  "Stepping": 10,
  "Vendor": "GenuineIntel",
  "BrandString": "Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz"
}
{
  "Size": 4,
  "Levels": [
    {
      "Level": 1,
      "CacheType": "CPU_FEATURE_CACHE_DATA",
      "CacheSize": 32768,
      "Ways": 8,
      "LineSize": 64,
      "TlbEntries": 64,
      "Partitioning": 1
    },
    {
      "Level": 1,
      "CacheType": "CPU_FEATURE_CACHE_INSTRUCTION",
      "CacheSize": 32768,
      "Ways": 8,
      "LineSize": 64,
      "TlbEntries": 64,
      "Partitioning": 1
    },
    {
      "Level": 2,
      "CacheType": "CPU_FEATURE_CACHE_UNIFIED",
      "CacheSize": 262144,
      "Ways": 4,
      "LineSize": 64,
      "TlbEntries": 1024,
      "Partitioning": 1
    },
    {
      "Level": 3,
      "CacheType": "CPU_FEATURE_CACHE_UNIFIED",
      "CacheSize": 6291456,
      "Ways": 12,
      "LineSize": 64,
      "TlbEntries": 8192,
      "Partitioning": 1
    },
    {
      "Level": 0,
      "CacheType": "CPU_FEATURE_CACHE_NULL",
      "CacheSize": 0,
      "Ways": 0,
      "LineSize": 0,
      "TlbEntries": 0,
      "Partitioning": 0
    },
    {
      "Level": 0,
      "CacheType": "CPU_FEATURE_CACHE_NULL",
      "CacheSize": 0,
      "Ways": 0,
      "LineSize": 0,
      "TlbEntries": 0,
      "Partitioning": 0
    },
    {
      "Level": 0,
      "CacheType": "CPU_FEATURE_CACHE_NULL",
      "CacheSize": 0,
      "Ways": 0,
      "LineSize": 0,
      "TlbEntries": 0,
      "Partitioning": 0
    },
    {
      "Level": 0,
      "CacheType": "CPU_FEATURE_CACHE_NULL",
      "CacheSize": 0,
      "Ways": 0,
      "LineSize": 0,
      "TlbEntries": 0,
      "Partitioning": 0
    },
    {
      "Level": 0,
      "CacheType": "CPU_FEATURE_CACHE_NULL",
      "CacheSize": 0,
      "Ways": 0,
      "LineSize": 0,
      "TlbEntries": 0,
      "Partitioning": 0
    },
    {
      "Level": 0,
      "CacheType": "CPU_FEATURE_CACHE_NULL",
      "CacheSize": 0,
      "Ways": 0,
      "LineSize": 0,
      "TlbEntries": 0,
      "Partitioning": 0
    }
  ]
}

Note: Before run CpuFeaturesDotNet.Samples you need build project through cmake.

cmake -S. -Bcmake-build-release -DCMAKE_BUILD_TYPE=Release
cmake --build cmake-build-release --target all -v

Detailed instruction see Local-Nuget-package-building

<a name="support"></a>

What's supported

Runtime / OS x86³ ARM AArch64
.NET Framework Windows in progress N/A N/A
.NET Core Windows yes² not yet not yet
.NET Core Linux yes² in progress in progress
.NET Core macOS yes² not yet not yet
.NET Core FreeBSD not yet not yet not yet
Mono Windows not yet not yet not yet
Mono Linux not yet not yet not yet
Mono macOS not yet N/A not yet
Mono FreeBSD not yet not yet not yet
Mono Android not yet not yet not yet
Mono iOS N/A N/A not yet
  1. Features revealed from Linux. We gather data from several sources depending on availability:
    • from glibc's getauxval
    • by parsing /proc/self/auxv
    • by parsing /proc/cpuinfo
  2. Features revealed from CPU. features are retrieved by using the cpuid instruction.
  3. Microarchitecture detection. On x86 some features are not always implemented efficiently in hardware (e.g. AVX on Sandybridge). Exposing the microarchitecture allows the client to reject particular microarchitectures.

<a name="license"></a>

License

The cpu_features.NET library is licensed under the terms of the Apache license. See LICENSE for more information.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.1 is compatible.  netstandard1.2 was computed.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated