diff options
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 8 | ||||
-rw-r--r-- | config.h.in | 3 |
3 files changed, 14 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 29c0a3b7..8e3ee808 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -487,6 +487,13 @@ IF(HAVE_INTRIN_H) __cpuid(regs, 0); return regs[0]; }" HAVE_CPUID_INTRINSIC) + CHECK_C_SOURCE_COMPILES("#include <intrin.h> + int main() + { + unsigned long idx = 0; + _BitScanForward64(&idx, 1); + return idx; + }" HAVE_BITSCANFORWARD64_INTRINSIC) ENDIF() CHECK_SYMBOL_EXISTS(sysconf unistd.h HAVE_SYSCONF) diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index f3ffac29..afa3eee3 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -97,13 +97,13 @@ typedef ALuint64SOFT ALuint64; #define CTZ64(x) __builtin_ctzll(x) #endif -#elif defined(_MSC_VER) +#elif defined(HAVE_BITSCANFORWARD64_INTRINSIC) static inline int msvc_ctz64(ALuint64 v) { - unsigned long idx = 0; + unsigned long idx = 64; _BitScanForward64(&idx, v); - return idx; + return (int)idx; } #define CTZ64(x) msvc_ctz64(x) @@ -121,7 +121,7 @@ static inline int fallback_popcnt64(ALuint64 v) v = v - ((v >> 1) & U64(0x5555555555555555)); v = (v & U64(0x3333333333333333)) + ((v >> 2) & U64(0x3333333333333333)); v = (v + (v >> 4)) & U64(0x0f0f0f0f0f0f0f0f); - return (v * U64(0x0101010101010101)) >> 56; + return (int)((v * U64(0x0101010101010101)) >> 56); } static inline int fallback_ctz64(ALuint64 value) diff --git a/config.h.in b/config.h.in index bc4e6432..99be6a0b 100644 --- a/config.h.in +++ b/config.h.in @@ -179,6 +179,9 @@ /* Define if we have the __cpuid() intrinsic */ #cmakedefine HAVE_CPUID_INTRINSIC +/* Define if we have the _BitScanForward64() intrinsic */ +#cmakedefine HAVE_BITSCANFORWARD64_INTRINSIC + /* Define if we have _controlfp() */ #cmakedefine HAVE__CONTROLFP |