All Projects → Maratyszcza → FXdiv

Maratyszcza / FXdiv

Licence: MIT license
C99/C++ header-only library for division via fixed-point multiplication by inverse

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects
Starlark
911 projects
python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to FXdiv

FixedPoint-Sharp
Fixed point math with 48.16 precision (based on lib by https://github.com/fholm)
Stars: ✭ 114 (+322.22%)
Mutual labels:  fixed-point
rouziclib
This is my personal library of code that is common to my different projects (Photosounder, SplineEQ, Spiral and others)
Stars: ✭ 38 (+40.74%)
Mutual labels:  fixed-point
Binary-Calculator-JavaScript
📱 A handy Calculator for Binary operations, that works on all Devices 📱 💻 🖥 | ⛓ https://play.google.com/store/apps/details?id=com.binarycalculator.ayidouble.binarycalculator.app ⛓
Stars: ✭ 45 (+66.67%)
Mutual labels:  division
libfixmath
Cross Platform Fixed Point Maths Library - mirror of https://code.google.com/p/libfixmath/
Stars: ✭ 16 (-40.74%)
Mutual labels:  fixed-point
as-bignum
Fixed length big numbers for AssemblyScript 🚀
Stars: ✭ 49 (+81.48%)
Mutual labels:  fixed-point
libdivide4j
Optimized integer division for Java
Stars: ✭ 18 (-33.33%)
Mutual labels:  division
abacus
📐 C# cross precision 3D maths library.
Stars: ✭ 35 (+29.63%)
Mutual labels:  fixed-point
FixedPointsArduino
A fixed point arithmetic library for Arduino
Stars: ✭ 68 (+151.85%)
Mutual labels:  fixed-point
spfpm
Package for performing fixed-point, arbitrary-precision arithmetic in Python.
Stars: ✭ 61 (+125.93%)
Mutual labels:  fixed-point
fpbinary
Fixed point package for Python.
Stars: ✭ 30 (+11.11%)
Mutual labels:  fixed-point
Pyt
A Static Analysis Tool for Detecting Security Vulnerabilities in Python Web Applications
Stars: ✭ 2,061 (+7533.33%)
Mutual labels:  fixed-point
fphdl
VHDL-2008 Support Library
Stars: ✭ 36 (+33.33%)
Mutual labels:  fixed-point

FXdiv

MIT License Build Status

Header-only library for division via fixed-point multiplication by inverse

On modern CPUs and GPUs integer division is several times slower than multiplication. FXdiv implements an algorithm to replace an integer division with a multiplication and two shifts. This algorithm improves performance when an application performs repeated divisions by the same divisor.

Features

  • Integer division for uint32_t, uint64_t, and size_t
  • Header-only library, no installation or build required
  • Compatible with C99, C++, OpenCL, and CUDA
  • Uses platform-specific compiler intrinsics for optimal performance
  • Covered with unit tests and microbenchmarks

Example

#include <fxdiv.h>

/* Division of array by a constant: reference implementation */
void divide_array_c(size_t length, uint32_t array[], uint32_t divisor) {
  for (size_t i = 0; i < length; i++) {
    array[i] /= divisor;
  }
}

/* Division of array by a constant: implementation with FXdiv */
void divide_array_fxdiv(size_t length, uint32_t array[], uint32_t divisor) {
  const struct fxdiv_divisor_uint32_t precomputed_divisor =
    fxdiv_init_uint32_t(divisor);
  for (size_t i = 0; i < length; i++) {
    array[i] = fxdiv_quotient_uint32_t(array[i], precomputed_divisor);
  }
}

Status

Currently working features:

Platform uint32_t uint64_t size_t
x86-64 gcc Works Works Works
x86-64 clang Works Works Works
x86-64 MSVC Works Works Works
x86 gcc Works Works Works
x86 clang Works Works Works
x86 MSVC Works Works Works
ARMv7 gcc Works Works Works
ARMv7 clang Works Works Works
ARMv7 MSVC* Compiles Compiles Compiles
ARM64 gcc Works Works Works
ARM64 clang Works Works Works
ARM64 MSVC* Compiles Compiles Compiles
PPC64 gcc Works Works Works
WAsm clang Works Works Works
Asm.js clang Works Works Works
PNaCl clang Works Works Works
CUDA Untested Untested Untested
OpenCL Untested Untested Untested

*ARMv7 and ARM64 builds with MSVC are presumed to work, but were only verified to compile successfully

References

  • Granlund, Torbjörn, and Peter L. Montgomery. "Division by invariant integers using multiplication." In ACM SIGPLAN Notices, vol. 29, no. 6, pp. 61-72. ACM, 1994. Available: gmplib.org/~tege/divcnst-pldi94.pdf
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].