【问题标题】:What target-features uses rustc by default?哪些目标功能默认使用 rustc?
【发布时间】:2020-12-05 12:08:29
【问题描述】:

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

如何查看默认激活了哪些功能?我在任何地方都找不到它,并且当我运行 cargo build --release --verbose 时它们没有打印出来。

【问题讨论】:

    标签: rust rust-cargo


    【解决方案1】:

    编辑: 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
    

    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 的形式提供。

    【讨论】:

      【解决方案2】:

      我做了一些研究,看起来默认功能保存在TargetOption::features,这是Target::option 的一部分。

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

      或者您可以从另一端开始检查您的架构规范文件here

      附: 某些平台的默认功能:

      【讨论】:

      • 谢谢!这是非常有用的。我发现有这种可能性来查看 llc 选项:github.com/rust-lang/rust/blob/…
      • 好吧,我以一些 hacky 解决方案结束了 :)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 2013-06-03
      • 1970-01-01
      相关资源
      最近更新 更多