A fast, header-only C/C++ library for counting 1 bits in arrays using optimized CPU instructions like POPCNT, AVX2, AVX512, NEON, and SVE.
libpopcnt is a header-only C/C++ library that provides extremely fast functions for counting the number of set bits (1 bits) in arrays of data. It solves the performance problem of bit population counting by automatically utilizing the best available CPU instruction sets (like POPCNT, AVX2, AVX512, NEON, SVE) through runtime detection, delivering speeds up to hundreds of gigabytes per second.
C/C++ developers working on performance-critical applications that involve bit-level operations, such as cryptography, data compression, database systems, or scientific computing.
Developers choose libpopcnt because it offers the fastest possible popcount implementation for their specific CPU without any manual configuration, is entirely portable across architectures, and is trivial to integrate as a single header file with no dependencies.
🚀 Fast C/C++ bit population count library
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Dynamically selects the fastest algorithm (e.g., AVX512 on supported CPUs) via runtime CPUID checks, eliminating manual configuration, as detailed in the 'How it works' section.
Provides hardware-accelerated popcount on x86, ARM, PPC, and fallback on others, ensuring portability across CPUs without special flags, per the CPU architectures table.
Integration requires just including 'libpopcnt.h' with no build dependencies, making it trivial to add to any C/C++ project, as emphasized in the README.
Unlike some libraries, it doesn't need special flags like -mavx2; standard optimizations (-O3) suffice for acceleration, simplifying compilation.
For optimal ARM performance, users must compile with -march=armv8-a+sve, as automatic runtime dispatching isn't well supported, adding complexity for newer architectures.
Only implements popcount for arrays; lacks other bit operations like bit shifts or masks, which might necessitate additional libraries for full bit manipulation needs.
The README provides basic usage but lacks extensive examples, API details, or troubleshooting guides, potentially slowing adoption for complex use cases.