Skip to content
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

Compile error with stdarch_x86_avx512 feature not enable #1550

Closed
serendipity-crypto opened this issue Jan 14, 2025 · 4 comments
Closed

Compile error with stdarch_x86_avx512 feature not enable #1550

serendipity-crypto opened this issue Jan 14, 2025 · 4 comments

Comments

@serendipity-crypto
Copy link
Contributor

When I compile my codes with rand v0.9.0-beta.1 and a computer has avx512, the compiler return following error. It seems like that the attribute #![feature(stdarch_x86_avx512)] is not enabled correctly in rand.

   Compiling rand_chacha v0.9.0-beta.1
   Compiling rand v0.9.0-beta.1
error[E0658]: use of unstable library feature `stdarch_x86_avx512`
   --> E:\packages\rust\cargo\registry\src\rsproxy.cn-e3de039b2554c837\rand-0.9.0-beta.1\src\distr\utils.rs:183:39
    |
183 |                     let hi = unsafe { $mulhi(self.into(), x.into()) }.into();
    |                                       ^
...
196 |     wmul_impl_16! { u16x32, _mm512_mulhi_epu16, _mm512_mullo_epi16 }
    |     ---------------------------------------------------------------- in this macro invocation
    |
    = note: see issue #111137 <https://github.com/rust-lang/rust/issues/111137> for more information
    = help: add `#![feature(stdarch_x86_avx512)]` to the crate attributes to enable
    = note: this compiler was built on 2025-01-12; consider upgrading it if it is out of date
    = note: this error originates in the macro `wmul_impl_16` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: use of unstable library feature `stdarch_x86_avx512`
   --> E:\packages\rust\cargo\registry\src\rsproxy.cn-e3de039b2554c837\rand-0.9.0-beta.1\src\distr\utils.rs:184:39
    |
184 |                     let lo = unsafe { $mullo(self.into(), x.into()) }.into();
    |                                       ^
...
196 |     wmul_impl_16! { u16x32, _mm512_mulhi_epu16, _mm512_mullo_epi16 }
    |     ---------------------------------------------------------------- in this macro invocation
    |
    = note: see issue #111137 <https://github.com/rust-lang/rust/issues/111137> for more information
    = help: add `#![feature(stdarch_x86_avx512)]` to the crate attributes to enable
    = note: this compiler was built on 2025-01-12; consider upgrading it if it is out of date
    = note: this error originates in the macro `wmul_impl_16` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0658`.
error: could not compile `rand` (lib) due to 2 previous errors
@dhardy
Copy link
Member

dhardy commented Jan 14, 2025

Thanks for the report.

I think all we need to "fix" this for your CPU is to enable the feature flag:

diff --git a/src/lib.rs b/src/lib.rs
index 54ae884025..623637f1ef 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -49,6 +49,7 @@
 #![doc(test(attr(allow(unused_variables), deny(warnings))))]
 #![no_std]
 #![cfg_attr(feature = "simd_support", feature(portable_simd))]
+#![cfg_attr(all(feature = "simd_support", target_feature = "avx512bw"), feature(stdarch_x86_avx512))]
 #![cfg_attr(docsrs, feature(doc_auto_cfg))]
 #![allow(
     clippy::float_cmp,

Can you test this?

Aside: simd_support as a whole is experimental and unstable. We could add an stdarch_x86_avx512 feature flag to rand, but I don't think there's much point.

@serendipity-crypto
Copy link
Contributor Author

Thank you, this fix has allowed my code to compile successfully without encountering the previous errors.

@dhardy
Copy link
Member

dhardy commented Jan 14, 2025

Cool. Send a PR and I'll merge it. We don't need a CHANGELOG entry.

I'm investigating whether or not we should use run-time detection for CPU features, but that's another matter.

@dhardy
Copy link
Member

dhardy commented Jan 14, 2025

(Fixed in #1551.)

@dhardy dhardy closed this as completed Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants