本文介绍了从C#检查CPU Popcount的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 有人知道如何在C#中检查cpu是否支持popcount(人口计数)吗? C ++很简单,但是尝试使用一些国际象棋代码将C ++转换为C#。Does anyone know how to check the cpu in C# if it supports popcount(population count)? C++ is easy but trying to do some C++ to C# conversion with some chess code.非常感谢。推荐答案我还没有找到一种简单的方法来检测和使用C#中的特殊CPU指令。有几种选择,没有一个很好; I have yet to find an easy way to detect and use special CPU instructions in C#. There are several options, none of them nice; asmjit一个执行popcount的函数 C#中的x86 / x64 CPUID mono有一个支持数据类型的simd库(我猜不是popcount) 使用C ++ DLL(由于开销可能会变慢) 。 asmjit a function that does popcountx86/x64 CPUID in C#mono has a simd library with datatype support (not popcount I guess)Use a C++ DLL (probably way slower because of overhead)..我从来没有那样去实现C#popcount; I never went that way and implemented a C# popcount; /// <summary> /// Count the number of bits set to 1 in a ulong /// </summary> public static byte BitCount(this ulong value) { ulong result = value - ((value >> 1) & 0x5555555555555555UL); result = (result & 0x3333333333333333UL) + ((result >> 2) & 0x3333333333333333UL); return (byte)(unchecked(((result + (result >> 4)) & 0xF0F0F0F0F0F0F0FUL) * 0x101010101010101UL) >> 56); } 这篇关于从C#检查CPU Popcount的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-27 10:48