[libc-commits] [libc] [libc][math] Integer-only, statically rounded implementation of exp (PR #225803)

Hoàng Minh Thiên via libc-commits libc-commits at lists.llvm.org
Sun Nov 15 08:30:18 PST 2026


hmthien050209 wrote:

> Could you share the exact CORE-MATH command, dataset/version, and commit tested so the accuracy claim is reproducible?

## Commits
CORE-MATH commit `018fa97cbdacf59924b899a9dfa422d532cb2bb7`
This PR's:
- Commit https://github.com/llvm/llvm-project/commit/8bc99fecd1b7bb61b1b9e7798d4156fe6990de46 (before the force push to merge `libc/shared/static_rounding_math.h`'s latest changes
- Latest commit

## Test setup
Given that local LLVM build outputs `libllvmlibc.a`. 
Additional changes are needed to be taken. Note that these changes **don't modify the accuracy tolerances or anything like that**, but only _disable exceptions checking_.

1. `mpfr`, `gmp` being installed
2. For Apple systems:
  - Homebrew's `llvm`: to avoid command line arguments hassle. I use Homebrew's LLVM most of the time. So using Apple's Clang is untested on my side.
  - Update `check.sh` at around line `112`:
  ```sh
  # BEFORE
  [ "$(nm "$LIBM" | while read a b c; do if [ "$c" = "$FUN_LIBM" ]; then echo OK; return; fi; done | wc -l)" -ge 1 ]

  # AFTER
  # Note the added `_` because of symbol mangling stuff (?)
  [ "$(nm "$LIBM" | while read a b c; do if [ "$c" = "_$FUN_LIBM" ]; then
    echo OK
    return
  fi; done | wc -l)" -ge 1 ]
  ```
3. As the current implementation doesn't raise exceptions like normal implementations do, we need to skip those exception checks by making these changes in `src/binary64/support/check_worst_uni.c`, at around line `240`:
```c
  if (is_equal (z1, z2) == 0) {
    printf("FAIL x=%la ref=%la z=%la\n", x, z1, z2);
    fflush(stdout);
    exit(1);
  }

  // ADD THIS: Skip floating-point exception checks
  return 0;

  /* When there is underflow ... */
```
and then the `main()` function (at around line `713`
```c
  doloop(rescale);

  // check_signaling_nan ();   // COMMENT THIS OUT: integer-only impl silences sNaN
}
```
4. Set the following environments
```sh
export CORE_MATH_CHECK_STD=true
export LIBM=/path/to/llvm-project/build/libc/lib/libllvmlibc.a
# On Apple system, we need to declare these extras to use Homebrew's LLVM
export CC="$(brew --prefix llvm)/bin/clang"
export EXTRA_CFLAGS="-I$(brew --prefix)/include"
export LDFLAGS="-L$(brew --prefix)/lib"
```
5. Run `./check.sh --worst exp` inside the CORE-MATH cloned repository.

## Expected result

All worst-case tests for all rounding modes to be passing. 
Note that there is no tests for double-precision routines.

> Also, are the benchmark results representative of the intended no-double-FPU targets?

Not yet. I have no true no-double-FPU targets. So the baseline version is the normal double-evaluated version running with Apple's M3 FPU; and the `static_rounding` version is our integer-only version, which is "forced" to take the integer-only path with our implementation.

The code size benchmark is **indeed representing** the no-double-FPU target of `armv8m.main-none-eabi` triple though. You can see that the `llvm-nm` output shows soft-float routines being lowered down when the baseline version is being compiled, and then none of them in our integer-only implementation.

https://github.com/llvm/llvm-project/pull/225803


More information about the libc-commits mailing list