gpt4 book ai didi

performance - 如何检测 CPU 是否具有良好的 POPCNT 支持?

转载 作者:行者123 更新时间:2023-11-29 07:47:46 24 4
gpt4 key购买 nike

我有两个版本的 fast newline-counting routine .一个在较旧的硬件上运行,而另一个通过使用 POPCNT 指令运行得更快,该指令可在较新的硬件(例如第 6 代 Intel CPU)上使用。

现在我想为每个 CPU 使用最佳版本——我如何才能确定它是否具有高性能 POPCNT 实现?

最佳答案

你可以做 like @kobrien said ,或者您可以采取更文明的方法 - cpuid crate .

为此,将其添加到您的Cargo.toml,然后检查 POPCNT do 的可用性

extern crate cpuid;

fn have_popcnt() -> Option<bool> {
cpuid::identify().ok().map(|ci| ci.has_feature(cpuid::CpuFeature::POPCNT))
}

如果 CPU 不支持 CPUID 指令或 Some(hp)have_popcnt() 函数将返回 None,其中 hp 确定 POPCNT 在其上的可用性。

关于performance - 如何检测 CPU 是否具有良好的 POPCNT 支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39670781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com