Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

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

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

libdivide

NOASSERTIONC++v5.3.0

A header-only C/C++ library that replaces slow integer division instructions with fast shift/add/multiply sequences.

Visit WebsiteGitHubGitHub
1.3k stars96 forks0 contributors

What is libdivide?

libdivide is a header-only C/C++ library that optimizes integer division by replacing slow CPU division instructions with faster sequences of shift, add, and multiply operations. It solves the performance bottleneck caused by integer division, which can be up to 90 times slower than multiplication on modern CPUs. The library is particularly useful when divisors are reused multiple times, such as in loops.

Target Audience

C and C++ developers working on performance-critical applications, including game engines, scientific computing, embedded systems, and data processing pipelines where integer division is a bottleneck.

Value Proposition

Developers choose libdivide for its substantial speed improvements (up to 10x), support for vectorized division, and compatibility with a wide range of hardware, from high-end x64 CPUs to 8-bit microcontrollers. Its header-only design and simple API make integration straightforward.

Overview

Official git repository for libdivide: optimized integer division

Use Cases

Best For

  • Optimizing loops that perform integer division with a reused divisor
  • Accelerating vectorized integer division in SIMD applications
  • Improving performance on microcontrollers without hardware dividers
  • Reducing latency in real-time systems where division is frequent
  • Benchmarking and comparing division algorithms across CPU architectures
  • Enabling branchfree division for arrays of varying divisors

Not Ideal For

  • Projects where integer division is infrequent or uses unique divisors every time, as divider generation overhead negates speed gains
  • Applications relying heavily on floating-point division, since libdivide is strictly for integer optimization
  • Codebases with extreme binary size constraints on microcontrollers, where libdivide's instruction sequences may bloat memory
  • Situations where divisors are compile-time constants and modern compilers already optimize them effectively

Pros & Cons

Pros

Substantial Speed Improvements

Achieves up to 10x faster 64-bit integer division by replacing slow CPU instructions with shift and multiply sequences, as shown in benchmark outputs.

SIMD Vector Division

Supports SSE2, AVX2, and AVX512 for vectorized integer division, enabling significant performance boosts in parallel computations on x86/x64 CPUs.

Embedded System Compatibility

Works on 8-bit microcontrollers like AVR without hardware dividers, making it crucial for resource-constrained embedded applications.

Dual API Flexibility

Provides both runtime C/C++ APIs for variable divisors and compile-time macros/templates for constant divisors, offering optimization versatility.

Cons

Integer-Only Limitation

Exclusively optimizes integer division, leaving floating-point division and other arithmetic operations unaddressed, which can limit its utility in mixed workloads.

Branchfree Divider Caveats

Unsigned branchfree dividers cannot be 1, and they perform worse for signed types, adding complexity and potential pitfalls in implementation.

Macro-Dependent Vector Setup

Requires manual definition of macros like LIBDIVIDE_SSE2 for vector division, introducing platform-specific configuration and build complexity.

Increased Code Size

The replacement of single division instructions with multiple operations can inflate binary size, a concern for memory-sensitive environments like embedded systems.

Frequently Asked Questions

Quick Stats

Stars1,335
Forks96
Contributors0
Open Issues3
Last commit1 month ago
CreatedSince 2011

Tags

#c-library#embedded-systems#simd#performance-optimization#low-latency#c-plus-plus#avr#header-only

Built With

A
AVX512
s
sse2
A
AVX2
C
CMake
C
C++

Links & Resources

Website

Included in

C/C++70.6k
Auto-fetched 1 day ago

Related Projects

DLIBDLIB

A toolkit for making real world machine learning and data analysis applications in C++

Stars14,398
Forks3,453
Last commit1 month ago
OpenGL MathematicsOpenGL Mathematics

OpenGL Mathematics (GLM)

Stars11,009
Forks2,379
Last commit2 months ago
OpenBLASOpenBLAS

OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

Stars7,458
Forks1,686
Last commit3 days ago
QuantLibQuantLib

The QuantLib C++ library

Stars7,234
Forks2,231
Last commit4 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