2026-04-16 16:15 UTC
A silly but straightforward way to get there would be: put that function in its own Rust library, compile it with all the different feature sets you want, link to the resulting binaries, then generate an ifunc-style wrapper. You could generate dylibs and only load the needed ones; you could even merge dylibs for the same feature set across different functions. This lets you use Rust's existing cfg machinery (plus cfg_select!).
Replies (1)
-
@bal4e@tech.lgbt 2026-04-16 16:24
With Rust today, you can partially approach this with generics; I have an unpublished proof-of-concept of this somewhere. Utility functions would be generic over a type describing the selected feature set. That type can only be constructed when the feature set is available on the current CPU, and this is used as a zero-sized proof object. where clauses can establish that certain features (e.g. AVX2) are available and then use their operations (through safe #[inline] functions to which you pass the proof object; they wrap unsafe #[inline] #[target_feature] impls). Your top-level function can be instantiated with different feature sets using regular generics and an ifunc can be built around them.