[all-commits] [llvm/llvm-project] a75246: [libc][math] Implement exp10f function correctly r...

lntue via All-commits all-commits at lists.llvm.org
Mon Sep 19 07:02:11 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a752460d73912b8f6759d10c78c48071dc128b8c
      https://github.com/llvm/llvm-project/commit/a752460d73912b8f6759d10c78c48071dc128b8c
  Author: Tue Ly <lntue at google.com>
  Date:   2022-09-19 (Mon, 19 Sep 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/gnu_ext.td
    M libc/src/math/CMakeLists.txt
    A libc/src/math/exp10f.h
    M libc/src/math/generic/CMakeLists.txt
    A libc/src/math/generic/exp10f.cpp
    M libc/src/math/generic/explogxf.h
    M libc/test/src/math/CMakeLists.txt
    M libc/test/src/math/exhaustive/CMakeLists.txt
    A libc/test/src/math/exhaustive/exp10f_test.cpp
    A libc/test/src/math/exp10f_test.cpp
    M libc/utils/MPFRWrapper/MPFRUtils.cpp
    M libc/utils/MPFRWrapper/MPFRUtils.h

  Log Message:
  -----------
  [libc][math] Implement exp10f function correctly rounded to all rounding modes.

Implement exp10f function correctly rounded to all rounding modes.

Algorithm: perform range reduction to reduce
```
  10^x = 2^(hi + mid) * 10^lo
```
where:
```
  hi is an integer,
  0 <= mid * 2^5 < 2^5
  -log10(2) / 2^6 <= lo <= log10(2) / 2^6
```
Then `2^mid` is stored in a table of 32 entries and the product `2^hi * 2^mid` is
performed by adding `hi` into the exponent field of `2^mid`.
`10^lo` is then approximated by a degree-5 minimax polynomials generated by Sollya with:
```
  > P = fpminimax((10^x - 1)/x, 4, [|D...|], [-log10(2)/64. log10(2)/64]);
```
Performance benchmark using perf tool from the CORE-MATH project on Ryzen 1700:
```
$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh exp10f
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH reciprocal throughput   : 10.215
System LIBC reciprocal throughput : 7.944

LIBC reciprocal throughput        : 38.538
LIBC reciprocal throughput        : 12.175   (with `-msse4.2` flag)
LIBC reciprocal throughput        : 9.862    (with `-mfma` flag)

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh exp10f --latency
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH latency   : 40.744
System LIBC latency : 37.546

BEFORE
LIBC latency        : 48.989
LIBC latency        : 44.486   (with `-msse4.2` flag)
LIBC latency        : 40.221   (with `-mfma` flag)
```
This patch relies on https://reviews.llvm.org/D134002

Reviewed By: orex, zimmermann6

Differential Revision: https://reviews.llvm.org/D134104




More information about the All-commits mailing list