Skip to content

Commit

Permalink
Fix building on NetBSD
Browse files Browse the repository at this point in the history
The static inline function popcount64() conflicts with a function
with NetBSD's libc.

https://man.netbsd.org/popcount.3
  • Loading branch information
brad0 committed Mar 17, 2024
1 parent 49c4961 commit ff89711
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions libpopcnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ extern "C" {
* It uses 12 arithmetic operations, one of which is a multiply.
* http://en.wikipedia.org/wiki/Hamming_weight#Efficient_implementation
*/
static inline uint64_t popcount64(uint64_t x)
static inline uint64_t libpopcount64(uint64_t x)
{
uint64_t m1 = 0x5555555555555555ll;
uint64_t m2 = 0x3333333333333333ll;
Expand Down Expand Up @@ -222,7 +222,7 @@ static inline uint64_t popcnt64(uint64_t x)

static inline uint64_t popcnt64(uint64_t x)
{
return popcount64(x);
return libpopcount64(x);
}

#endif
Expand Down Expand Up @@ -645,14 +645,14 @@ static inline uint64_t popcnt(const void* data, uint64_t size)
* We use unaligned memory accesses here to improve performance.
*/
for (; i < size - size % 8; i += 8)
cnt += popcount64(*(const uint64_t*)(ptr + i));
cnt += libpopcount64(*(const uint64_t*)(ptr + i));

if (i < size)
{
uint64_t val = 0;
size_t bytes = (size_t)(size - i);
memcpy(&val, &ptr[i], bytes);
cnt += popcount64(val);
cnt += libpopcount64(val);
}

return cnt;
Expand Down Expand Up @@ -750,7 +750,7 @@ static inline uint64_t popcnt(const void* data, uint64_t size)
uint64_t val = 0;
size_t bytes = (size_t)(size - i);
memcpy(&val, &ptr[i], bytes);
cnt += popcount64(val);
cnt += libpopcount64(val);
}

return cnt;
Expand Down

0 comments on commit ff89711

Please sign in to comment.