Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Jun 26, 2024
1 parent 6df41a8 commit d1b04e0
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions libpopcnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,6 @@ static inline uint64_t popcnt_avx512(const uint64_t* ptr, const uint64_t size)
*/
static inline uint64_t popcnt(const void* data, uint64_t size)
{
uint64_t i = 0;
uint64_t cnt = 0;
const uint8_t* ptr = (const uint8_t*) data;

/*
* CPUID runtime checks are only enabled if this is needed.
* E.g. CPUID is disabled when a user compiles his
Expand All @@ -556,6 +552,10 @@ static inline uint64_t popcnt(const void* data, uint64_t size)
#endif
#endif

const uint8_t* ptr = (const uint8_t*) data;
uint64_t cnt = 0;
uint64_t i = 0;

#if defined(LIBPOPCNT_HAVE_AVX512)
#if defined(__AVX512__) || \
(defined(__AVX512F__) && defined(__AVX512VPOPCNTDQ__))
Expand All @@ -569,11 +569,8 @@ static inline uint64_t popcnt(const void* data, uint64_t size)
const uint64_t* ptr64 = (const uint64_t*)(ptr + i);
cnt += popcnt_avx512(ptr64, (size - i) / 8);
i = size - size % 8;

if (i == size)
return cnt;
else
goto trailing_bytes;
}
#endif

Expand All @@ -592,10 +589,6 @@ static inline uint64_t popcnt(const void* data, uint64_t size)
}
#endif

#if defined(LIBPOPCNT_HAVE_AVX512)
trailing_bytes:
#endif

#if defined(LIBPOPCNT_HAVE_POPCNT)
/*
* The user has compiled without -mpopcnt.
Expand Down

0 comments on commit d1b04e0

Please sign in to comment.