Skip to content

Instantly share code, notes, and snippets.

@gfoidl
Last active November 27, 2018 09:38
Show Gist options
  • Save gfoidl/4c273132cfe8b86e288fa006d714c995 to your computer and use it in GitHub Desktop.
Save gfoidl/4c273132cfe8b86e288fa006d714c995 to your computer and use it in GitHub Desktop.
HW-Info
//#define REFLECTION_SCAN
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
#if REFLECTION_SCAN
using System.Linq;
#endif
namespace HW_Intrin_Info
{
static class Program
{
static void Main()
{
Console.WriteLine($"{nameof(Environment.Is64BitOperatingSystem),-25}: {Environment.Is64BitOperatingSystem}");
Console.WriteLine($"{nameof(Environment.Is64BitProcess),-25}: {Environment.Is64BitProcess}");
Console.WriteLine($"{nameof(Environment.MachineName),-25}: {Environment.MachineName}");
Console.WriteLine($"{nameof(Environment.OSVersion),-25}: {Environment.OSVersion}");
Console.WriteLine($"{nameof(Environment.ProcessorCount),-25}: {Environment.ProcessorCount}");
Console.WriteLine($"{nameof(RuntimeInformation.FrameworkDescription),-25}: {RuntimeInformation.FrameworkDescription}");
Console.WriteLine($"{nameof(RuntimeInformation.OSDescription),-25}: {RuntimeInformation.OSDescription}");
Console.WriteLine($"{nameof(RuntimeInformation.ProcessArchitecture),-25}: {RuntimeInformation.ProcessArchitecture}");
Console.WriteLine();
Console.WriteLine("x86");
Console.WriteLine("===");
PrintIntrinsicsSupport("System.Runtime.Intrinsics.X86");
Console.WriteLine();
Console.WriteLine("arm");
Console.WriteLine("===");
PrintIntrinsicsSupport("System.Runtime.Intrinsics.Arm.Arm64");
}
//---------------------------------------------------------------------
private static void PrintIntrinsicsSupport(string ns)
{
var types = GetTypes(ns);
foreach (Type type in types)
{
PropertyInfo pi = type.GetProperty("IsSupported", BindingFlags.Static | BindingFlags.Public);
object value = pi.GetValue(null);
Print(type.Name, (bool)value);
}
}
//---------------------------------------------------------------------
private static IEnumerable<Type> GetTypes(string ns)
{
#if REFLECTION_SCAN
return typeof(Sse).Assembly.ExportedTypes
.Where(t => t.IsClass && t.Namespace == ns)
.OrderBy(t => t.Name);
#else
if (ns == "System.Runtime.Intrinsics.X86")
{
yield return typeof(System.Runtime.Intrinsics.X86.Aes);
yield return typeof(System.Runtime.Intrinsics.X86.Avx);
yield return typeof(System.Runtime.Intrinsics.X86.Avx2);
yield return typeof(System.Runtime.Intrinsics.X86.Bmi1);
yield return typeof(System.Runtime.Intrinsics.X86.Bmi2);
yield return typeof(System.Runtime.Intrinsics.X86.Fma);
yield return typeof(System.Runtime.Intrinsics.X86.Lzcnt);
yield return typeof(System.Runtime.Intrinsics.X86.Pclmulqdq);
yield return typeof(System.Runtime.Intrinsics.X86.Popcnt);
yield return typeof(System.Runtime.Intrinsics.X86.Sse);
yield return typeof(System.Runtime.Intrinsics.X86.Sse2);
yield return typeof(System.Runtime.Intrinsics.X86.Sse3);
yield return typeof(System.Runtime.Intrinsics.X86.Sse41);
yield return typeof(System.Runtime.Intrinsics.X86.Sse42);
yield return typeof(System.Runtime.Intrinsics.X86.Ssse3);
}
else if (ns == "System.Runtime.Intrinsics.Arm.Arm64")
{
yield return typeof(System.Runtime.Intrinsics.Arm.Arm64.Aes);
yield return typeof(System.Runtime.Intrinsics.Arm.Arm64.Base);
yield return typeof(System.Runtime.Intrinsics.Arm.Arm64.Sha1);
yield return typeof(System.Runtime.Intrinsics.Arm.Arm64.Sha256);
yield return typeof(System.Runtime.Intrinsics.Arm.Arm64.Simd);
}
#endif
}
//---------------------------------------------------------------------
private static void Print(string title, bool value)
{
Console.ForegroundColor = value ? ConsoleColor.Green : ConsoleColor.Red;
Console.WriteLine($"{title,-10}: {value}");
Console.ResetColor();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment