Clone this repo:
  1. 74bef47 Update OWNERS file am: fb604db06c by Sadaf Ebrahimi · 10 weeks ago main master
  2. fb604db Update OWNERS file by Sadaf Ebrahimi · 10 weeks ago
  3. a555e78 Change OWNERS. am: 92dd970528 am: be0c2744b5 am: e139508b6f am: 6d5a6d8633 am: 2cc0161e9b by Xusong Wang · 1 year, 10 months ago android14-dev android14-mainline-healthfitness-release android14-qpr1-release android14-qpr1-s2-release android14-qpr2-release android14-qpr2-s1-release android14-qpr2-s2-release android14-qpr2-s3-release aml_cfg_341510000 aml_hef_341114030 aml_hef_341311010 aml_hef_341415040 aml_hef_341512030 aml_hef_341613000 aml_rkp_341012000 aml_rkp_341015010 aml_rkp_341114000 aml_rkp_341311000 aml_rkp_341510000 android-14.0.0_r16 android-14.0.0_r17 android-14.0.0_r18 android-14.0.0_r19 android-14.0.0_r20 android-14.0.0_r21 android-14.0.0_r22 android-14.0.0_r23 android-14.0.0_r24 android-14.0.0_r25 android-14.0.0_r26 android-14.0.0_r27 android-14.0.0_r29 android-14.0.0_r30 android-14.0.0_r31 android-14.0.0_r32 android-14.0.0_r33
  4. 2cc0161 Change OWNERS. am: 92dd970528 am: be0c2744b5 am: e139508b6f am: 6d5a6d8633 by Xusong Wang · 1 year, 10 months ago main-16k-with-phones android-u-beta-1-gpl
  5. 6d5a6d8 Change OWNERS. am: 92dd970528 am: be0c2744b5 am: e139508b6f by Xusong Wang · 1 year, 10 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