Use of undeclared identifier '_tzcnt_u64'

Hi Everyone,

We got a user report of a compile failure using Apple's Clang. I don't
know the exact Apple Clang version at the moment. Its on OS X 10.11,
and its probably the one bundled with the latest Xcode.

Here's the error report

    misc.h:675:23: error: use of undeclared identifier '_tzcnt_u64'
    misc.h:790:22: error: use of undeclared identifier '_blsr_u64';
did you mean '__blsr_u32'?

Here's the code in question from misc.h (from

#if defined(__GNUC__) && defined(__BMI__)
    return (unsigned int)_tzcnt_u64(v);
#elif defined(__GNUC__) && (GCC_VERSION >= 30400)
    return (unsigned int)__builtin_ctzll(v);
#elif ...

And from misc.h (from

#if defined(__GNUC__) && defined(__BMI__)
template <>
inline bool IsPowerOf2<word64>(const word64 &value)
    return value > 0 && _blsr_u64(value) == 0;

I believe both symbols are available in <immintrin.h>

#if defined(__GNUC__) && defined(__BMI__)
    #include <immintrin.h>

Given __BMI__ is defined, why are we catching the "undeclared identifier" error?

Thanlk in advance/

We needed this goodness for Clang. Its another case of Clang
pretending to be another compiler, but failing to consume a program.
The frustrating thing is, we have dedicated code paths for Clang,
including inline assembly that works around its integrated assembler
bugs. If Clang would stop pretending to be other compilers, then
things would "just work".

#if defined(__GNUC__) && defined(__BMI__)
# include <immintrin.h>
+# if defined(__clang__)
+# define _tzcnt_u32(x) __tzcnt_u32(x)
+# define _tzcnt_u64(x) __tzcnt_u64(x)
+# define _blsr_u32(x) __blsr_u32(x)
+# define _blsr_u64(x) __blsr_u64(x)
+# endif