Skip to content

Commit

Permalink
Fix: Missing __builtin_clzll symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Oct 10, 2023
1 parent a878eba commit 5d333d5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions stringzilla/stringzilla.h
Original file line number Diff line number Diff line change
Expand Up @@ -806,14 +806,26 @@ inline static void sz_sort_insertion(sz_sequence_t *sequence, sz_sequence_compar
}
}

// Utility functions
inline static sz_size_t _sz_log2i(sz_size_t n) {
if (n == 0) return 0; // to avoid undefined behavior with __builtin_clz
if (n == 0) return 0;

#if defined(__LP64__) || defined(_WIN64) // 64-bit
#ifdef _MSC_VER
unsigned long index;
_BitScanReverse64(&index, n);
return index;
#else
return 63 - __builtin_clzll(n);
#endif
#else // 32-bit
#ifdef _MSC_VER
unsigned long index;
_BitScanReverse(&index, n);
return index;
#else
return 31 - __builtin_clz(n);
#endif
#endif
}

inline static void _sz_sift_down(
Expand Down

0 comments on commit 5d333d5

Please sign in to comment.