commit | 83eeb2b98745bf4a548e49d79ae2f9ae55f7a405 | [log] [tgz] |
---|---|---|
author | Xin Li <delphij@google.com> | Fri Apr 10 03:35:16 2020 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Fri Apr 10 03:35:16 2020 +0000 |
tree | 0ef1dc1b680fcb94028e5fa274c41efab1b40cc1 | |
parent | 6331b5cd38225e079d2bebb0a49956b669ae3041 [diff] | |
parent | d1dcb1cce50ba5dc0d9642988ba839a04aa54e6a [diff] |
[automerger skipped] DO NOT MERGE - Empty merge qt-qpr1-dev-plus-aosp into stag-aosp-master am: 80f3373a22 -s ours am: c15502b9b4 am: d1dcb1cce5 Change-Id: I05948c05ce536eb1bd9f912de969741ad6b62a0e
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 |