Skip to content

Commit

Permalink
Revert "move x86 popcount.h implementations to util/arch/x86/popcount.h"
Browse files Browse the repository at this point in the history
This reverts commit 6581aae.
  • Loading branch information
markos committed Sep 24, 2020
1 parent 5333467 commit 04fbf24
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 135 deletions.
60 changes: 0 additions & 60 deletions src/util/arch/common/popcount.h

This file was deleted.

67 changes: 0 additions & 67 deletions src/util/arch/x86/popcount.h

This file was deleted.

35 changes: 27 additions & 8 deletions src/util/popcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,41 @@
#ifndef UTIL_POPCOUNT_H_
#define UTIL_POPCOUNT_H_

#include "config.h"
#include "ue2common.h"
#include "util/arch.h"

#if defined(ARCH_IA32) || defined(ARCH_X86_64)
#include "util/arch/x86/popcount.h"
#endif

static really_inline
u32 popcount32(u32 x) {
return popcount32_impl(x);
#if defined(HAVE_POPCOUNT_INSTR)
// Single-instruction builtin.
return _mm_popcnt_u32(x);
#else
// Fast branch-free version from bit-twiddling hacks as older Intel
// processors do not have a POPCNT instruction.
x -= (x >> 1) & 0x55555555;
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
return (((x + (x >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24;
#endif
}

static really_inline
u32 popcount64(u32 x) {
return popcount64_impl(x);
u32 popcount64(u64a x) {
#if defined(ARCH_X86_64)
# if defined(HAVE_POPCOUNT_INSTR)
// Single-instruction builtin.
return (u32)_mm_popcnt_u64(x);
# else
// Fast branch-free version from bit-twiddling hacks as older Intel
// processors do not have a POPCNT instruction.
x -= (x >> 1) & 0x5555555555555555;
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333);
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f;
return (x * 0x0101010101010101) >> 56;
# endif
#else
// Synthesise from two 32-bit cases.
return popcount32(x >> 32) + popcount32(x);
#endif
}

#endif /* UTIL_POPCOUNT_H_ */
Expand Down

0 comments on commit 04fbf24

Please sign in to comment.