builtins: __builtin_clzll for x86 on MSVC

Add an implementation for __builtin_clzll on MSVC even when _BitScanForward4 is
unavailable.

Patch by Tee Hao Wei!

llvm-svn: 250359
This commit is contained in:
Saleem Abdulrasool 2015-10-15 02:46:37 +00:00
parent 55c3f89edb
commit 956365ef7f
1 changed files with 12 additions and 2 deletions

View File

@ -115,9 +115,19 @@ uint32_t __inline __builtin_clzll(uint64_t value) {
return 63 - leading_zero;
return 64;
}
#else
uint32_t __inline __builtin_clzll(uint64_t value) {
if (value == 0)
return 64;
uint32_t msh = (uint32_t)(value >> 32);
uint32_t lsh = (uint32_t)(value & 0xFFFFFFFF);
if (msh != 0)
return __builtin_clz(msh);
return 32 + __builtin_clz(lsh);
}
#endif
#define __builtin_clzl __builtin_clzll
#endif
#endif
#endif // defined(_MSC_VER) && !defined(__clang__)
#endif /* INT_LIB_H */