[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
Sat Nov 14 20:50:27 PST 2026
hmthien050209 wrote:
# Code size
> [!NOTE]
> The report below are from the`armv8m.main-none-eabi` triple.
## Before the patch
```sh
$ ls -lB libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/
total 8
-rw-r-----@ 1 davidhoang staff 4096 Oct 28 15:01 exp.cpp.obj
$ llvm-nm --radix=d --print-size --size-sort --reverse-sort libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.obj
00000000 00000392 W _ZN22__llvm_libc_24_0_0_git4math11double_eval9exp2_evalEddijb
00000000 00000312 T exp
00000000 00000312 T _ZN22__llvm_libc_24_0_0_git3expEd
00000000 00000232 W _ZN22__llvm_libc_24_0_0_git4math11double_eval10exp_denormEdidb
00000000 00000168 W _ZN22__llvm_libc_24_0_0_git4math11double_eval15set_exceptionalEd
00000000 00000064 V _ZN22__llvm_libc_24_0_0_git4math11double_eval8EXP2_MIDE
U __aeabi_i2d
U __aeabi_dmul
U __aeabi_dcmplt
U __aeabi_dcmpeq
U __aeabi_dadd
```
## After the patch
```sh
$ ls -lB libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/
total 8
-rw-r-----@ 1 davidhoang staff 3696 Nov 13 23:51 exp.cpp.obj
$ llvm-nm --radix=d --print-size --size-sort --reverse-sort libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.obj
00000000 00001350 T exp
00000000 00001350 T _ZN22__llvm_libc_24_0_0_git3expEd
00000000 00000328 W _ZNK22__llvm_libc_24_0_0_git7Frac128mlERKS0_
00000000 00000128 V _ZN22__llvm_libc_24_0_0_git4math15static_rounding10EXP_MID_64E
00000000 00000056 V _ZN22__llvm_libc_24_0_0_git4math15static_rounding13EXP_COEFFS_64E
00000000 00000016 V _ZN22__llvm_libc_24_0_0_git4math15static_rounding10LOG2_E_128E
```
# Latency
[bench.zip](https://github.com/user-attachments/files/33930492/bench.zip), containing `bench.cc` with compilation instruction.
```sh
===================LIBC_MATH_FAST is OFF====================
==========================baseline==========================
overflow (>710) 3.13 ns/call (320M ops/sec)
underflow to 0 (<-746) 3.17 ns/call (316M ops/sec)
normal [-10,10] 3.18 ns/call (315M ops/sec)
denormals [-740,-735] 7.64 ns/call (131M ops/sec)
near-uflow [-700,-690] 3.18 ns/call (315M ops/sec)
======================static_rounding=======================
overflow (>710) 2.12 ns/call (471M ops/sec)
underflow to 0 (<-746) 2.12 ns/call (471M ops/sec)
normal [-10,10] 9.66 ns/call (104M ops/sec)
denormals [-740,-735] 6.84 ns/call (146M ops/sec)
near-uflow [-700,-690] 8.33 ns/call (120M ops/sec)
```
```sh
====================LIBC_MATH_FAST is ON====================
==========================baseline==========================
overflow (>710) 1.60 ns/call (626M ops/sec)
underflow to 0 (<-746) 1.60 ns/call (627M ops/sec)
normal [-10,10] 3.21 ns/call (311M ops/sec)
denormals [-740,-735] 4.59 ns/call (218M ops/sec)
near-uflow [-700,-690] 3.22 ns/call (311M ops/sec)
======================static_rounding=======================
overflow (>710) 1.87 ns/call (535M ops/sec)
underflow to 0 (<-746) 1.60 ns/call (624M ops/sec)
normal [-10,10] 7.91 ns/call (126M ops/sec)
denormals [-740,-735] 6.27 ns/call (160M ops/sec)
near-uflow [-700,-690] 6.31 ns/call (159M ops/sec)
```
Benchmarking system: MacBook Air M3, macOS 27.2
https://github.com/llvm/llvm-project/pull/225803
More information about the libc-commits
mailing list