Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 318
Angelicos Phosphoros Avatar asked Dec 05 '20 12:12

Angelicos Phosphoros


Video Answer


2 Answers

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.

like image 132
Angelicos Phosphoros Avatar answered Oct 23 '22 22:10

Angelicos Phosphoros


I did some research and it looks like default features are saved at TargetOption::features which is available as part of Target::option.

I'm not sure if you can ask compiler to print it somehow but you can lookup for default features via github serach (probably it doesn't cover all the places but I believe it gives a good hint for future).

Or you can start from another end and check your architecture's spec file here.

P.S. Default features for some platforms:

  • aarch64_linux_android
  • x86_64_linux_android
  • x86_64_linux_kernel
like image 4
MaxV Avatar answered Oct 23 '22 21:10

MaxV