Skip to content

Rustc doesn't detect target_feature=aes with -C target-cpu=native (broadwell) #67836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gendx opened this issue Jan 3, 2020 · 4 comments
Closed
Labels
C-bug Category: This is a bug. O-x86_64 Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@gendx
Copy link

gendx commented Jan 3, 2020

I tried to compile my code with -C target-cpu=native, some of it being gated by cfg(target_feature = "aes"). I was expecting the AES code to be compiled as my CPU supports it, but rustc didn't enable target_feature = "aes".

According to /proc/cpuinfo, my CPU supports AES-NI.

$ cat /proc/cpuinfo | grep -q aes && echo "aes found"
aes found

With the latest Rust nightly:

$ rustc -V
rustc 1.42.0-nightly (0a58f5864 2020-01-02)

Rustc detects a broadwell CPU:

$ rustc --print target-cpus
Available CPUs for this target:
    native         - Select the CPU of the current host (currently broadwell).
[...]

The features detected by -C target-cpu=native are the following (I get the same result with -C target-cpu=broadwell). I didn't check whether anything else was missing, but there is no mention of aes.

$ rustc --print cfg -C target-cpu=native
debug_assertions
target_arch="x86_64"
target_endian="little"
target_env="gnu"
target_family="unix"
target_feature="adx"
target_feature="avx"
target_feature="avx2"
target_feature="bmi1"
target_feature="bmi2"
target_feature="cmpxchg16b"
target_feature="f16c"
target_feature="fma"
target_feature="fxsr"
target_feature="lzcnt"
target_feature="mmx"
target_feature="movbe"
target_feature="pclmulqdq"
target_feature="popcnt"
target_feature="rdrand"
target_feature="rdseed"
target_feature="sse"
target_feature="sse2"
target_feature="sse3"
target_feature="sse4.1"
target_feature="sse4.2"
target_feature="ssse3"
target_feature="xsave"
target_feature="xsaveopt"
target_has_atomic="16"
target_has_atomic="32"
target_has_atomic="64"
target_has_atomic="8"
target_has_atomic="ptr"
target_has_atomic_load_store="16"
target_has_atomic_load_store="32"
target_has_atomic_load_store="64"
target_has_atomic_load_store="8"
target_has_atomic_load_store="ptr"
target_os="linux"
target_pointer_width="64"
target_thread_local
target_vendor="unknown"
unix
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. O-x86_64 Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 3, 2020
@ehuss
Copy link
Contributor

ehuss commented Jan 3, 2020

It looks like LLVM intentionally removed it from Broadwell (to Skylake) because it wasn't available on all SKUs of that series: llvm/llvm-project@7582222

@jonas-schievink
Copy link
Contributor

Closing as working as intended then.

@gendx
Copy link
Author

gendx commented Jan 3, 2020

Shouldn't target-cpu=native detect features directly with something like cpuid (at rustc's level, not LLVM) to enable all features actually available on the current SKU?

I find it very confusing that "native" would resolve to a whole family and then enable only the common denominator of that family - potentially a small subset of natively supported features on my specific CPU.

@ehuss
Copy link
Contributor

ehuss commented Jan 3, 2020

See #54688 for more detail on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-x86_64 Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants