A cross-platform C99 library to detect CPU features and microarchitecture at runtime.
cpu_features is a cross-platform C library that allows software to query CPU capabilities—like supported instruction sets (e.g., AVX, AES, NEON)—at runtime. It solves the problem of writing portable, optimized code by enabling dynamic feature detection, so applications can adapt to the underlying hardware without relying solely on compile-time flags.
System programmers, compiler engineers, and developers of performance-critical applications (e.g., cryptography libraries, game engines, scientific computing) who need to write hardware-aware, portable C/C++ code.
Developers choose cpu_features for its reliability, sandbox compatibility, and zero-overhead design. It provides a simple, thread-safe API with microarchitecture detection, making it a trusted solution for both Google projects and the wider open-source community.
A cross platform C99 library to get cpu features at runtime.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Works across Linux, macOS, Windows, Android, and FreeBSD on architectures from x86 to RISC-V, as evidenced by the comprehensive CI badge matrix and support table in the README.
Uses multiple fallback strategies like parsing /proc/cpuinfo and getauxval to function in restricted environments where cpuid is unavailable, ensuring reliability in hermetic testing or containerized setups.
Detects specific CPU uarch (e.g., Intel Sandy Bridge) to avoid inefficient early implementations of features like AVX, a unique advantage for performance-critical code.
Thread-safe with no memory allocation or exceptions, making it suitable for low-level libc functions and minimizing impact on application performance.
Combines compile-time macros (e.g., CPU_FEATURES_COMPILED_X86_AVX) with runtime checks, allowing developers to leverage both static and dynamic feature knowledge seamlessly.
The support table shows gaps, such as no AArch64 support on Windows and limited FreeBSD coverage, which may hinder use in emerging or niche environments.
Direct usage requires C or C++ integration, creating a barrier for projects in other languages that must rely on community-maintained bindings, which can vary in quality and maintenance.
Focuses solely on instruction set and microarchitecture detection, lacking support for other hardware details like cache topology or performance counters that might be needed for advanced optimizations.
While it supports CMake, Bazel, and Zig, integrating into non-standard or legacy build environments may require additional configuration effort, especially for cross-compilation scenarios.