multiversion icon indicating copy to clipboard operation
multiversion copied to clipboard

Trouble using x86-64-v4, clarifying current support (nightly)

Open sammysheep opened this issue 8 months ago • 3 comments

Sorry if this is because the flags are not supported in Rust, but I am trying to use multiversion on our Xeons with AV512 and the special "simd" target didn't work (only dispatches to AVX2 unless I compile the whole binary for the AVX512 target), so I tried it manually:

error: unknown x86 target feature: lahfsahf
   --> src/path/to/mod.rs:435:38
    |
435 | #[cfg_attr(feature = "multiversion", multiversion::multiversion(targets("x86_64+avx2","x86_64/x86-64-v4")))]
    |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in the macro `std::arch::is_x86_feature_detected` which comes from the expansion of the attribute macro `multiversion::multiversion` (in Nightly builds, run with -Z macro-backtrace for more info)

I'm on nightly, so adding an extra, contingent compiler feature is not a problem, albeit I'm not sure what I would add to fix this.

sammysheep avatar Aug 07 '25 18:08 sammysheep

Also: rustc 1.91.0-nightly (7d82b83ed 2025-08-06), multiversion v0.8.0

sammysheep avatar Aug 07 '25 18:08 sammysheep

This also affects "x86_64/x86-64-v2" level on stable, rustc v1.90.0, multiversion v0.8.0:

error: unknown x86 target feature: lahfsahf
   --> src/twiddles.rs:189:1
    |
189 | / #[multiversion::multiversion(
190 | |                             targets("x86_64+avx512f+avx512bw+avx512cd+avx512dq+avx512vl", // x86_64-v4
191 | |                                     "x86_64/x86-64-v2", // x86_64-v2
...   |
198 | | ))]
    | |___^
    |
    = note: this error originates in the macro `std::arch::is_x86_feature_detected` which comes from the expansion of the attribute macro `multiversion::multiversion` (in Nightly builds, run with -Z macro-backtrace for more info)

Shnatsel avatar Oct 20 '25 15:10 Shnatsel

I'm not totally sure what the best way to handle this is. Specifying a CPU is a convenient shortcut but simply filtering out unsupported features could result in undefined behavior. It's unlikely, but for example you could use asm! or call an external function that uses the filtered out feature.

calebzulawski avatar Oct 20 '25 16:10 calebzulawski