[all-commits] [llvm/llvm-project] 582643: [libc][math] Adding LIBC_MATH_ASSUME_ROUND_NEAREST...

Hoàng Minh Thiên via All-commits all-commits at lists.llvm.org
Thu Jun 11 10:42:51 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 582643f1ec62d0c81d97afcf1b741babb3152728
      https://github.com/llvm/llvm-project/commit/582643f1ec62d0c81d97afcf1b741babb3152728
  Author: Hoàng Minh Thiên <hoangminhthien05022009 at gmail.com>
  Date:   2026-06-11 (Thu, 11 Jun 2026)

  Changed paths:
    M libc/config/config.json
    M libc/src/__support/FPUtil/Hypot.h
    M libc/src/__support/FPUtil/ManipulationFunctions.h
    M libc/src/__support/FPUtil/NearestIntegerOperations.h
    M libc/src/__support/FPUtil/dyadic_float.h
    M libc/src/__support/FPUtil/except_value_utils.h
    M libc/src/__support/FPUtil/generic/FMA.h
    M libc/src/__support/FPUtil/generic/add_sub.h
    M libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
    M libc/src/__support/FPUtil/rounding_mode.h
    M libc/src/__support/macros/optimization.h
    M libc/src/__support/math/asinbf16.h
    M libc/src/__support/math/asinf16.h
    M libc/src/__support/math/asinhf16.h
    M libc/src/__support/math/asinpi.h
    M libc/src/__support/math/coshf.h
    M libc/src/__support/math/coshf16.h
    M libc/src/__support/math/erfcf16.h
    M libc/src/__support/math/exp.h
    M libc/src/__support/math/exp10.h
    M libc/src/__support/math/exp10f.h
    M libc/src/__support/math/exp10f16.h
    M libc/src/__support/math/exp10m1f.h
    M libc/src/__support/math/exp10m1f16.h
    M libc/src/__support/math/exp2.h
    M libc/src/__support/math/exp2f.h
    M libc/src/__support/math/exp2f16.h
    M libc/src/__support/math/exp2m1f.h
    M libc/src/__support/math/exp2m1f16.h
    M libc/src/__support/math/expf.h
    M libc/src/__support/math/expf16.h
    M libc/src/__support/math/expm1.h
    M libc/src/__support/math/expm1f.h
    M libc/src/__support/math/expm1f16.h
    M libc/src/__support/math/sin.h
    M libc/src/__support/math/sincos.h
    M libc/src/__support/math/sincosf.h
    M libc/src/__support/math/sinf.h
    M libc/src/__support/math/sinf16.h
    M libc/src/__support/math/sinhf.h
    M libc/src/__support/math/sinhf16.h
    M libc/src/__support/math/tan.h
    M libc/src/__support/math/tanf16.h
    M libc/src/__support/math/tanhf16.h
    M libc/src/__support/str_to_float.h
    M libc/src/stdio/printf_core/float_dec_converter.h
    M libc/src/stdio/printf_core/float_hex_converter.h
    M libc/test/UnitTest/FPMatcher.h
    M libc/test/UnitTest/RoundingModeUtils.cpp
    M libc/test/src/math/RIntTest.h
    M libc/test/src/math/RoundToIntegerTest.h
    M libc/test/src/math/smoke/NearbyIntTest.h
    M libc/test/src/math/smoke/RIntTest.h
    M libc/test/src/math/smoke/RoundToIntegerTest.h
    M libc/utils/MPFRWrapper/MPFRUtils.h

  Log Message:
  -----------
  [libc][math] Adding LIBC_MATH_ASSUME_ROUND_NEAREST_ONLY option (#201154)

This PR adds a new option ~~`LIBC_MATH_ALWAYS_ROUND_NEAREST`~~
`LIBC_MATH_ASSUME_ROUND_NEAREST_ONLY` to LLVM libm.

There are some UBs that I kept as-is from the original code to keep the
changes non-disruptive (which I've marked with TODO comments)

Benchmarks (from `files.zip` in the comment
https://github.com/llvm/llvm-project/issues/198276#issue-4468816457):
- System libm:
```
overflow (>710)                1.55 ns/call  (644M ops/sec)
underflow to 0 (<-746)         1.34 ns/call  (747M ops/sec)
normal [-10,10]                4.41 ns/call  (227M ops/sec)
denormals [-740,-735]          2.25 ns/call  (444M ops/sec)
near-uflow [-700,-690]         2.25 ns/call  (444M ops/sec)
```
- LLVM libm (without the option being set):
```
overflow (>710)                5.21 ns/call  (192M ops/sec)
underflow to 0 (<-746)         7.20 ns/call  (139M ops/sec)
normal [-10,10]                4.06 ns/call  (246M ops/sec)
denormals [-740,-735]          5.85 ns/call  (171M ops/sec)
near-uflow [-700,-690]         4.06 ns/call  (246M ops/sec)
```
- LLVM libm (with the option being **set**, `bench-exp-paths-inc.cc`)
```
overflow (>710)                1.95 ns/call  (514M ops/sec)
underflow to 0 (<-746)         2.23 ns/call  (449M ops/sec)
normal [-10,10]                3.43 ns/call  (292M ops/sec)
denormals [-740,-735]          5.19 ns/call  (193M ops/sec)
near-uflow [-700,-690]         3.43 ns/call  (292M ops/sec)
```

Notice that in the `bench-exp-paths-inc.cc` file, I've changed the
option name from `LIBC_MATH_ROUND_NEAREST` to
`LIBC_MATH_ASSUME_ROUND_NEAREST_ONLY`

Benchmark system: macOS 26.5, Apple M3.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list