Skip to content

Commit

Permalink
Define ctz builtins only on some versions of MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
bfairservice-gt committed Sep 14, 2020
1 parent 33eea51 commit 5ca2fdb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/include/souffle/datastructure/PiggyList.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

#ifdef _WIN32
/**
* MSVC does not provide a builtin for counting leading zeroes like gcc,
* so we have to implement it ourselves.
* Some versions of MSVC do not provide a builtin for counting leading zeroes
* like gcc, so we have to implement it ourselves.
*/
#if _MSC_VER < 1924
unsigned long __inline __builtin_clzll(unsigned long long value) {
unsigned long msb = 0;

Expand All @@ -20,7 +21,8 @@ unsigned long __inline __builtin_clzll(unsigned long long value) {
else
return 64;
}
#endif // _WIN32
#endif // _MSC_VER < 1924
#endif // _WIN32

using std::size_t;
namespace souffle {
Expand Down
2 changes: 2 additions & 0 deletions src/include/souffle/utility/MiscUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
*/
#define __builtin_popcountll __popcnt64

#if _MSC_VER < 1924
constexpr unsigned long __builtin_ctz(unsigned long value) {
unsigned long trailing_zeroes = 0;
while ((value = value >> 1) ^ 1) {
Expand All @@ -65,6 +66,7 @@ inline unsigned long __builtin_ctzll(unsigned long long value) {
return 64;
}
}
#endif // _MSC_VER < 1924
#endif

// -------------------------------------------------------------------------------
Expand Down

0 comments on commit 5ca2fdb

Please sign in to comment.