rustrust-cargo

What target-features uses rustc by default?


There are some target-features which can be used by adding parameter -C target-feature=+sse,+avx to compiler. Available features can be shown using rustc --print target-features. There are also some default activated features, for example, SSE on AMDx64 targets.

How can I look which features are activated by default? I cannot find this anywhere and they aren't printed when I run cargo build --release --verbose.


Solution

  • Edit: Matěj Laitl reached me in GitHub and told me better way to do this. You need run command rustc --print=cfg -C target-cpu=skylake You can replace skylake with your target CPU or native.

    Old version of answer:

    I found that rustc --print target-features prints results of llc -march=x86-64 -mcpu=x86-64 -mattr=help (if you need other -march, you can use llc --version).

    I gave up looking for docs and written simple script which shows which attributes enabled.

    There are 3 steps in usage of script:

    1. get list of features using rustc --print target-features
    2. put it into script (it has values actual for 2020-12-06 for x86-64 target).
    3. run script.

    So, I got this features enabled by default at this moment:

    feature fxsr
    feature sse
    feature sse2
    

    With RUSTFLAGS='-C target-cpu=native' cargo run I got this list:

    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
    

    Script is available as gist.