Skip to content

Commit

Permalink
Add 32 bit versions of MSVC intrinsics (#2463)
Browse files Browse the repository at this point in the history
In some cases, this is enough to make Souffle work on Windows on 32 bit
machines.
  • Loading branch information
Xazax-hun committed Dec 24, 2023
1 parent 4b4a255 commit 42e432b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/include/souffle/datastructure/PiggyList.h
Expand Up @@ -16,7 +16,11 @@
*/
#if defined(_MSC_VER)
int __inline __builtin_clzll(unsigned long long value) {
#if _WIN64
return static_cast<int>(__lzcnt64(value));
#else
return static_cast<int>(__lzcnt(value));
#endif
}
#endif // _MSC_VER
#endif // _WIN32
Expand Down
8 changes: 8 additions & 0 deletions src/include/souffle/utility/MiscUtil.h
Expand Up @@ -47,7 +47,11 @@
* windows equivalents. However ctz is used in a constexpr context, and we can't
* use BitScanForward, so we implement it ourselves.
*/
#if _WIN64
#define __builtin_popcountll __popcnt64
#else
#define __builtin_popcountll __popcnt
#endif

#if defined(_MSC_VER)
// return the number of trailing zeroes in value, or 32 if value is zero.
Expand All @@ -74,7 +78,11 @@ inline constexpr int __builtin_ctzll_constexpr(unsigned long long value) {
inline int __builtin_ctzll(unsigned long long value) {
unsigned long trailing_zeroes = 0;

#if _WIN64
if (_BitScanForward64(&trailing_zeroes, value)) {
#else
if (_BitScanForward(&trailing_zeroes, value)) {
#endif
return static_cast<int>(trailing_zeroes);
} else {
return 64; // return 64 like GCC would when value == 0
Expand Down

0 comments on commit 42e432b

Please sign in to comment.