commit | ee5e2d2b918136ebcbd35ee6f9170666f671d110 | [log] [tgz] |
---|---|---|
author | Marat Dukhan <maratek@gmail.com> | Sat Jul 02 20:36:54 2016 +0300 |
committer | Marat Dukhan <maratek@gmail.com> | Sat Jul 02 20:36:54 2016 +0300 |
tree | ba03222774c15955106f9bdb8259a0f2b0afdd0d |
Initial release
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.
uint32_t
, uint64_t
, and size_t
#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_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); } }
Project is in alpha stage. API is unstable. Currently working features:
Platform | uint32_t | uint64_t | size_t |
---|---|---|---|
x86-64 gcc | Works | Works | Works |
x86-64 MSVC | Works | Unimplemented | Fails |
x86 gcc | Works | Unimplemented | Works |
x86 MSVC | Works | Unimplemented | Works |
CUDA | Untested | Unimplemented | Untested |
OpenCL | Untested | Unimplemented | Untested |