Bug: 148898578

Clone this repo:
  1. 761d983 Add janitors to the OWNERS file am: 5221aadff6 by Sadaf Ebrahimi · 5 months ago main master
  2. 5221aad Add janitors to the OWNERS file by Sadaf Ebrahimi · 5 months ago
  3. 46dbe23 [automerger skipped] Empty merge of Android 24Q2 Release (ab/11526283) to aosp-main-future am: d913399cc8 -s ours by Xin Li · 1 year, 1 month ago android15-automotiveos-dev android15-automotiveos-release android15-qpr1-release android15-qpr1-s3-release android15-qpr1-s4-release android15-qpr1-s5-release android15-qpr2-release android15-qpr2-s1-release android15-qpr2-s10-release android15-qpr2-s2-release android15-qpr2-s3-release android15-qpr2-s4-release android15-qpr2-s5-release android15-qpr2-s6-release android15-qpr2-s7-release android15-qpr2-s8-release android15-qpr2-s9-release android15-tests-dev aml_cfg_351010000 aml_hef_350921160 aml_hef_351016140 aml_hef_351120040 aml_hef_351314220 aml_hef_351420080 aml_rkp_350910000 aml_rkp_351011000 aml_rkp_351310000 android-15.0.0_r10 android-15.0.0_r11 android-15.0.0_r12 android-15.0.0_r13 android-15.0.0_r14 android-15.0.0_r15 android-15.0.0_r16 android-15.0.0_r17 android-15.0.0_r20 android-15.0.0_r21 android-15.0.0_r22 android-15.0.0_r23 android-15.0.0_r26 android-15.0.0_r27 android-15.0.0_r28 android-15.0.0_r29 android-15.0.0_r30 android-15.0.0_r32 android-15.0.0_r33 android-15.0.0_r34 android-15.0.0_r35 android-15.0.0_r36 android-15.0.0_r6 android-15.0.0_r7 android-15.0.0_r8 android-15.0.0_r9 android-automotiveos-15.0.0_lts1
  4. d913399 Empty merge of Android 24Q2 Release (ab/11526283) to aosp-main-future by Xin Li · 1 year, 1 month ago
  5. acbb172 Update OWNERS file am: fb604db06c am: 74bef47419 by Sadaf Ebrahimi · 1 year, 3 months ago

FXdiv

MIT License Build Status

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.

Features

  • Integer division for uint32_t, uint64_t, and size_t
  • Header-only library, no installation or build required
  • Compatible with C99, C++, OpenCL, and CUDA
  • Uses platform-specific compiler intrinsics for optimal performance
  • Covered with unit tests and microbenchmarks

Example

#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);
  }
}

Status

Currently working features:

Platformuint32_tuint64_tsize_t
x86-64 gccWorksWorksWorks
x86-64 clangWorksWorksWorks
x86-64 MSVCWorksWorksWorks
x86 gccWorksWorksWorks
x86 clangWorksWorksWorks
x86 MSVCWorksWorksWorks
ARMv7 gccWorksWorksWorks
ARMv7 clangWorksWorksWorks
ARMv7 MSVC*CompilesCompilesCompiles
ARM64 gccWorksWorksWorks
ARM64 clangWorksWorksWorks
ARM64 MSVC*CompilesCompilesCompiles
PPC64 gccWorksWorksWorks
WAsm clangWorksWorksWorks
Asm.js clangWorksWorksWorks
PNaCl clangWorksWorksWorks
CUDAUntestedUntestedUntested
OpenCLUntestedUntestedUntested

*ARMv7 and ARM64 builds with MSVC are presumed to work, but were only verified to compile successfully

References

  • Granlund, Torbjörn, and Peter L. Montgomery. “Division by invariant integers using multiplication.” In ACM SIGPLAN Notices, vol. 29, no. 6, pp. 61-72. ACM, 1994. Available: gmplib.org/~tege/divcnst-pldi94.pdf