| commit | 46dbe23922d2f68acf6638846c68716fcec3e8fa | [log] [tgz] |
|---|---|---|
| author | Xin Li <delphij@google.com> | Mon Apr 29 22:16:25 2024 +0000 |
| committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Mon Apr 29 22:16:25 2024 +0000 |
| tree | 726fe230524fb1ddb9efdd65d7dda0910035f996 | |
| parent | acbb172367cb377f04686a2a8f8a9a2c894b2f7e [diff] | |
| parent | d913399cc8e019d1818465d6919813fcc08a5400 [diff] |
[automerger skipped] Empty merge of Android 24Q2 Release (ab/11526283) to aosp-main-future am: d913399cc8 -s ours am skip reason: Merged-In I721bd79c318834988b2e23c82362f76a4a21d0aa with SHA-1 74bef47419 is already in history Original change: https://googleplex-android-review.googlesource.com/c/platform/external/FXdiv/+/27144063 Change-Id: Ic2078304a79dfaff35de5f3d80e88073ff818bb1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
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); } }
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