[all-commits] [llvm/llvm-project] b8e801: [libc][math] fmod/fmodf implementation.

orex via All-commits all-commits at lists.llvm.org
Fri Jun 24 14:09:52 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b8e8012aa2ede55be77173b918b4d6363b55c9d1
      https://github.com/llvm/llvm-project/commit/b8e8012aa2ede55be77173b918b4d6363b55c9d1
  Author: Kirill Okhotnikov <okir at google.com>
  Date:   2022-06-24 (Fri, 24 Jun 2022)

  Changed paths:
    M libc/config/darwin/arm/entrypoints.txt
    M libc/config/linux/aarch64/entrypoints.txt
    M libc/config/linux/x86_64/entrypoints.txt
    M libc/config/windows/entrypoints.txt
    M libc/docs/math.rst
    M libc/spec/stdc.td
    M libc/src/__support/FPUtil/FPBits.h
    M libc/src/__support/FPUtil/Hypot.h
    M libc/src/__support/FPUtil/builtin_wrappers.h
    M libc/src/__support/FPUtil/generic/CMakeLists.txt
    M libc/src/__support/FPUtil/generic/FMA.h
    A libc/src/__support/FPUtil/generic/FMod.h
    M libc/src/__support/FPUtil/generic/sqrt.h
    M libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
    M libc/src/__support/str_to_float.h
    M libc/src/math/CMakeLists.txt
    A libc/src/math/fmod.h
    A libc/src/math/fmodf.h
    M libc/src/math/generic/CMakeLists.txt
    A libc/src/math/generic/fmod.cpp
    A libc/src/math/generic/fmodf.cpp
    M libc/test/src/math/CMakeLists.txt
    A libc/test/src/math/FModTest.h
    M libc/test/src/math/differential_testing/CMakeLists.txt
    A libc/test/src/math/differential_testing/fmod_diff.cpp
    A libc/test/src/math/differential_testing/fmod_perf.cpp
    A libc/test/src/math/differential_testing/fmodf_diff.cpp
    A libc/test/src/math/differential_testing/fmodf_perf.cpp
    M libc/test/src/math/exhaustive/CMakeLists.txt
    A libc/test/src/math/exhaustive/fmod_generic_impl_test.cpp
    A libc/test/src/math/fmod_test.cpp
    A libc/test/src/math/fmodf_test.cpp
    M libc/utils/MPFRWrapper/MPFRUtils.cpp
    M libc/utils/MPFRWrapper/MPFRUtils.h

  Log Message:
  -----------
  [libc][math] fmod/fmodf implementation.

This is a implementation of find remainder fmod function from standard libm.
The underline algorithm is developed by myself, but probably it was first
invented before.
Some features of the implementation:
1. The code is written on more-or-less modern C++.
2. One general implementation for both float and double precision numbers.
3. Spitted platform/architecture dependent and independent code and tests.
4. Tests covers 100% of the code for both float and double numbers. Tests cases with NaN/Inf etc is copied from glibc.
5. The new implementation in general 2-4 times faster for “regular” x,y values. It can be 20 times faster for x/y huge value, but can also be 2 times slower for double denormalized range (according to perf tests provided).
6. Two different implementation of division loop are provided. In some platforms division can be very time consuming operation. Depend on platform it can be 3-10 times slower than multiplication.

Performance tests:

The test is based on core-math project (https://gitlab.inria.fr/core-math/core-math). By Tue Ly suggestion I took hypot function and use it as template for fmod. Preserving all test cases.

`./check.sh <--special|--worst> fmodf` passed.
`CORE_MATH_PERF_MODE=rdtsc ./perf.sh fmodf` results are

```
GNU libc version: 2.35
GNU libc release: stable
21.166 <-- FPU
51.031 <-- current glibc
37.659 <-- this fmod version.
```




More information about the All-commits mailing list