Elektrine lite

← Feed

@bal4e@tech.lgbt

2026-04-16 16:24 UTC

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.

Replies (1)

  • @bal4e@tech.lgbt 2026-04-16 16:27

    The main problem I encountered with this approach was that Rust would not always inline everything; the generics, the safe functions forwarding to #[target_feature] and the necessary overhead of building a "nice" API left LLVM dissatisfied. Furthermore, it was hard to replicate cfg! / cfg_select! in this model. I looked into type system abuse (e.g. https://docs.rs/frunk) but I didn't find a satisfying solution. auto traits (given their limited specialization capabilities) might help.

    Open ##1411455