哪些目标功能默认使用 rustc?

Ang*_*ros 6 rust rust-cargo

有一些target-features 可以通过向-C target-feature=+sse,+avx编译器添加参数来使用。可用功能可以使用 显示rustc --print target-features。还有一些默认激活的功能,例如 AMDx64 目标上的 SSE。

如何查看默认激活了哪些功能?我在任何地方都找不到它,并且当我运行cargo build --release --verbose.

Max*_*axV 5

我做了一些研究,看起来默认功能保存在TargetOption::features中,它作为Target::option的一部分提供。

我不确定你是否可以要求编译器以某种方式打印它,但你可以通过github serach查找默认功能(可能它没有涵盖所有地方,但我相信它为未来提供了一个很好的提示)。

或者您可以从另一端开始并在此处检查您的架构的规范文件。

PS 某些平台的默认功能:


Ang*_*ros 5

编辑: 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. 将其放入脚本中(对于 x86-64 目标,它具有 2020-12-06 的实际值)。
  3. 运行脚本。

因此,我此时默认启用了此功能:

feature fxsr
feature sse
feature sse2
Run Code Online (Sandbox Code Playgroud)

随着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
Run Code Online (Sandbox Code Playgroud)

脚本可作为gist 使用