3 ms·
For C++ this goes to the question https://stackoverflow.com/questions/8936549/constexpr-overloading/22062918 https://stackoverflow.com/questions/8936549/constex
by Lockal 2y ago
For C++ this goes to the question https://stackoverflow.com/questions/8936549/constexpr-overloading/22062918 https://stackoverflow.com/questions/8936549/constexpr-overlo...
Back in the days the answer was `__builtin_constant_p`.
But with C++20 it is possible to use std::is_constant_evaluated, or `if consteval` with C++23.
But this is for scenario when you still want to keep high quality of code (maybe when you write multiprecision math library; not when you hack around compiler flag), which inline assembly violates for many reasons:
1) major issue: instead of dealing with `-ffast-math` with inline asm, just remove `-ffast-math`
2) randomly slapped inline asm inside normal fp32 computations breaks autovectorization
3) randomly slapped inline asm in example uses non-vex encoding, you will likely to forget to call vzeroupper on transition. Or in general, this limits code to x86 (forget about x86-64/arm)
4) provided example (best_always_inline) does not work in GCC as expected