llo*_*giq 6 cpu performance rust
我有两个版本的快速换行计数例程.一个运行在较旧的硬件上,而另一个通过使用POPCNT指令运行得更快,该指令可用于较新的硬件(例如第6代Intel CPU).
现在我想为每个CPU使用最好的版本 - 我怎样才能知道它是否具有高性能的POPCNT实现?
你可以像@kobrien那样说,或者你可以采取更文明的方法 - cpuid箱子.
为此,请将其添加到您的Cargo.toml,然后检查POPCNT的可用性
extern crate cpuid;
fn have_popcnt() -> Option<bool> {
cpuid::identify().ok().map(|ci| ci.has_feature(cpuid::CpuFeature::POPCNT))
}
Run Code Online (Sandbox Code Playgroud)
如果CPU不支持CPUID指令,或者在其中确定POPCNT的可用性,则该have_popcnt()函数将返回.NoneSome(hp)hp