commit | f549da13389ee5b5a05a5be843071d6b38e608a5 | [log] [tgz] |
---|---|---|
author | Steven Laver <lavers@google.com> | Fri Feb 14 13:17:41 2020 -0800 |
committer | Steven Laver <lavers@google.com> | Fri Feb 14 13:17:41 2020 -0800 |
tree | 7e85e45ccb22a7b95f1dd9df988edec9e6396799 | |
parent | 33a70410818d3156235081a932b85a1f8d821cfb [diff] | |
parent | e3d3a2eb281293de6b2f590899ef7df25a1e2226 [diff] |
Merge RP1A.200214.001 Change-Id: I402a83c56e1f64a87ca42e315d2c99cd1b7f862d
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_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); } }
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 | Works | Works |
x86 gcc | Works | Works | Works |
x86 MSVC | Works | Works | Works |
ARMv7 gcc | Works | Works | Works |
PPC64 gcc | Works | Works | Works |
PNaCl clang | Works | Works | Works |
Asm.js clang | Works | Works | Works |
CUDA | Untested | Untested | Untested |
OpenCL | Untested | Untested | Untested |