commit | 130e0fba5d0f56ed0d3efba0d73de5d45c20e9a0 | [log] [tgz] |
---|---|---|
author | Xin Li <delphij@google.com> | Thu Mar 19 05:42:08 2020 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Thu Mar 19 05:42:08 2020 +0000 |
tree | 7e85e45ccb22a7b95f1dd9df988edec9e6396799 | |
parent | c577b94ed81e89bb905b7cbba8043480561afda6 [diff] | |
parent | c0cd948a77a3d22fe79d66aa85d0eb60d0bd3b15 [diff] |
[automerger skipped] DO NOT MERGE - Empty merge qt-qpr1-dev-plus-aosp@6304901 into stag-aosp-master am: d9905688eb -s ours am: a27665e1b3 am: 5023fc0059 am: c0cd948a77 -s ours am skip reason: subject contains skip directive Change-Id: Ibbbfc5a04ac3b1e0a5461f5cbeeb6a8c15a49297
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 |