Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. C/C++
  3. libpopcnt

libpopcnt

BSD-2-ClauseC++v4.2

A fast, header-only C/C++ library for counting 1 bits in arrays using optimized CPU instructions like POPCNT, AVX2, AVX512, NEON, and SVE.

GitHubGitHub
369 stars44 forks0 contributors

What is libpopcnt?

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.

Target Audience

C/C++ developers working on performance-critical applications that involve bit-level operations, such as cryptography, data compression, database systems, or scientific computing.

Value Proposition

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.

Overview

🚀 Fast C/C++ bit population count library

Use Cases

Best For

  • Accelerating bitwise operations in high-performance computing applications
  • Optimizing database query engines that rely on bitmap indexes
  • Improving speed in cryptographic algorithms that process bit arrays
  • Enhancing data compression utilities that count set bits
  • Boosting performance in machine learning frameworks that use bit vectors
  • Writing cross-platform C/C++ code that needs fast popcount on x86, ARM, or PPC

Not Ideal For

  • Applications that only need to count bits in individual integers rather than large arrays
  • Embedded systems with severe memory or code size constraints where header-only inclusion might be prohibitive
  • Real-time systems that cannot tolerate any runtime variability or overhead from CPU feature detection
  • Projects requiring a comprehensive bit manipulation library beyond just population count

Pros & Cons

Pros

Automatic CPU Optimization

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.

Cross-Architecture Support

Provides hardware-accelerated popcount on x86, ARM, PPC, and fallback on others, ensuring portability across CPUs without special flags, per the CPU architectures table.

Header-Only Simplicity

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.

No Compiler Flag Hassles

Unlike some libraries, it doesn't need special flags like -mavx2; standard optimizations (-O3) suffice for acceleration, simplifying compilation.

Cons

ARM SVE Requires Manual Flags

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.

Narrow Functional Scope

Only implements popcount for arrays; lacks other bit operations like bit shifts or masks, which might necessitate additional libraries for full bit manipulation needs.

Sparse Documentation

The README provides basic usage but lacks extensive examples, API details, or troubleshooting guides, potentially slowing adoption for complex use cases.

Frequently Asked Questions

Quick Stats

Stars369
Forks44
Contributors0
Open Issues0
Last commit1 month ago
CreatedSince 2016

Tags

#c-library#simd#cpu-optimization#hardware-acceleration#c#c-plus-plus#avx2#bit-manipulation#neon#avx512#cpp#header-only#performance

Built With

C
C++

Included in

C/C++70.6k
Auto-fetched 9 hours ago

Related Projects

stbstb

stb single-file public domain libraries for C/C++

Stars34,612
Forks8,088
Last commit1 month ago
{fmt}{fmt}

A modern formatting library

Stars25,655
Forks3,045
Last commit13 hours ago
xxHashxxHash

Extremely fast non-cryptographic hash algorithm

Stars11,242
Forks914
Last commit1 month ago
single_file_libssingle_file_libs

List of single-file C/C++ libraries, with emphasis on clause-less licenses.

Stars9,997
Forks650
Last commit20 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub