A header-only C/C++ library for fast 32-bit division and remainder operations on 64-bit hardware.
fastmod is a header-only C/C++ library that provides fast implementations for 32-bit division and remainder operations on 64-bit hardware. It uses direct computation techniques to outperform compiler-generated code for constant divisors, solving performance bottlenecks in low-level arithmetic operations. The library is particularly useful for applications where division operations occur frequently with known divisors.
C and C++ developers working on performance-critical applications such as hashing algorithms, compilers, game engines, or low-level systems programming where division operations are a bottleneck.
Developers choose fastmod because it provides mathematically correct, header-only implementations that are significantly faster than compiler optimizations for constant divisors. Its cross-platform compatibility and comprehensive testing make it a reliable drop-in solution for performance-sensitive code.
A C/C++ header file for fast 32-bit division remainders (and divisibility tests) on 64-bit hardware.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Outperforms compiler-generated code for constant divisors, with benchmarks on Intel Skylake showing significant speedups in hashing applications, as documented in the README.
Easy to add to any C/C++ project by simply including the fastmod.h file, with no complex build steps required beyond cloning the repository.
Supports major compilers like Clang, GCC, and Visual Studio, ensuring it can be used in diverse development environments without major adjustments.
Includes exhaustive unit tests and an option for exhaustive testing via CMake flags, providing confidence in correctness for edge cases.
Limited to 32-bit division and remainder on 64-bit hardware, with 64-bit operations marked as experimental and less supported on platforms like Visual Studio.
Requires computing multipliers for each divisor upfront using functions like computeM_u32, which adds complexity and inefficiency if divisors are not constant or vary often.
The API reference warns against using certain divisors (e.g., {-1, 1, INT32_MIN} for signed operations), forcing developers to handle these cases manually and increasing error risk.