using System.Diagnostics; namespace Unity.Burst.Intrinsics { public unsafe static partial class X86 { /// /// popcnt intrinsics /// public static class Popcnt { /// /// Evaluates to true at compile time if popcnt intrinsics are supported. /// /// Burst ties popcnt support to SSE4.2 support to simplify feature sets to support. /// public static bool IsPopcntSupported { get { return Sse4_2.IsSse42Supported; } } /// /// Count the number of bits set to 1 in unsigned 32-bit integer a, and return that count in dst. /// /// /// **** popcnt r32, r32 /// /// Integer to be counted in /// Count [DebuggerStepThrough] public static int popcnt_u32(uint v) { int result = 0; uint mask = 0x80000000u; while (mask != 0) { result += ((v & mask) != 0) ? 1 : 0; mask >>= 1; } return result; } /// /// Count the number of bits set to 1 in unsigned 64-bit integer a, and return that count in dst. /// /// /// **** popcnt r64, r64 /// /// Integer to be counted in /// Count [DebuggerStepThrough] public static int popcnt_u64(ulong v) { int result = 0; ulong mask = 0x8000000000000000u; while (mask != 0) { result += ((v & mask) != 0) ? 1 : 0; mask >>= 1; } return result; } } } }