I have some code that uses gcc intrinsics. I would like to include code in case the intrinsic is missing. How can I do this?
#ifdef __builtin_ctzll
does not work.
With recent versions of clang it is now possible to check if builtin intrinsics exist using the __has_builtin()
macro e.g.
int popcount(int x)
{
#if __has_builtin(__builtin_popcount)
return __builtin_popcount(x);
#else
int count = 0;
for (; x != 0; x &= x - 1)
count++;
return count;
#endif
}
Let's hope GCC will also support __has_builtin()
in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With