Pre-RFC: stabilization of target_feature

How do you abstract this code between run-time and compile-time detection? You want to write this code once, but be able to select the proper branch at either compile-time or run-time.

Now obviously this case makes no sense as you already know the check works but if the target_feature check is somewhere inside a macro that gets expanded out it makes sense that it would evaluate to true when it's inside the runtime_target_feature true branch.

Can you maybe check the "How do we teach this?" section of the RFC and let me know what you think?

The only difference AFAIK is that instead of using if cfg!(runtime_target_feature it uses if std::cpuid::has_target_feature, but semantically it should be very similar to the point you are coming to.

It's basically a three layered approach:

  • compile-time detection is used to implement the algorithms

  • unconditional_target_feature is used to force code generation using particular features

  • some run-time detection library is used to dispatch on these unconditional_target_features

And then any kind of sugar that makes this easier can be provided as procedural macros.