默认情况下,rustc 使用哪些目标特性?

8

有一些 目标特性 可以通过将参数 -C target-feature=+sse,+avx 添加到编译器中进行使用。可以使用 rustc --print target-features 命令查看可用的特性。此外,还有一些默认激活的特性,例如在 AMDx64 目标上激活了 SSE。

我该如何查看默认激活了哪些特性?我无法在任何地方找到它们,并且当我运行 cargo build --release --verbose 命令时不会打印出来。

2个回答

9
编辑: Matěj Laitl在GitHub联系我并告诉我更好的做法。您需要运行命令rustc --print=cfg -C target-cpu=skylake,您可以将skylake替换为您的目标CPU或native

旧版本的答案:

我发现rustc --print target-features打印llc -march=x86-64 -mcpu=x86-64 -mattr=help的结果(如果您需要其他-march,可以使用llc --version)。

我放弃查找文档,并编写了一个简单的脚本,显示启用的属性。

使用脚本有3个步骤:

  1. 使用rustc --print target-features获取功能列表
  2. 将其放入脚本中(它具有2020-12-06 x86-64目标的实际值)。
  3. 运行脚本。

因此,我当前默认启用了以下功能:

feature fxsr
feature sse
feature sse2

使用 RUSTFLAGS='-C target-cpu=native' cargo run 命令,我得到了以下列表:

feature aes
feature avx
feature avx2
feature bmi2
feature fma
feature fxsr
feature lzcnt
feature popcnt
feature rdseed
feature sha
feature sse
feature sse2
feature sse3
feature sse4.1
feature sse4.2
feature ssse3
feature xsave
feature xsavec
feature xsaveopt
feature xsaves

脚本可以通过gist获取。

5
我进行了一些研究,似乎默认功能保存在TargetOption::features中,该选项作为Target::option的一部分可用。
我不确定是否可以要求编译器以某种方式将其打印出来,但您可以通过GitHub搜索查找默认功能(可能不涵盖所有位置,但我相信它为未来提供了良好的提示)。
或者,您可以从另一个端开始,并检查您架构的规格文件这里
P.S. 一些平台的默认功能:

谢谢!这非常有用。 我发现有这个查看llc选项的可能性:https://github.com/rust-lang/rust/blob/f2ea2f648e117013b0217f001088ae89e0f163ca/compiler/rustc_target/src/spec/mod.rs#L759 - Angelicos Phosphoros
我最终用了一些笨拙的解决方案 :) - Angelicos Phosphoros

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接