[llvm-branch-commits] [libc] [llvm] [libc] Add fdim functions for float80 type (PR #236417)

Jay Foad via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Nov 9 00:56:07 PST 2026


jayfoad wrote:

>From Claude:

- Finding: `fdimf80` returns x87 unnormal or pseudo-infinity encodings (which read as NaN) when `x - y` rounds up across a binade. The root cause is `DyadicFloat::generic_as_bits`: it rounds with `++result` on packed bits, and the carry clears Float80's explicit integer bit. That code predates the PR (Float80 emulation, #214447). But fdimf80 is the first float80 entrypoint that does arithmetic, so this is newly shipped wrong output. It is enabled in linux x86_64 and amdgpu entrypoints, and always uses the soft Float80.
- Repro (origin/main libc headers, from `git archive`):
  ```
  $ /usr/bin/clang++ -std=c++17 -O2 -I src/libc -DLIBC_NAMESPACE=__llvm_libc_audit -DLIBC_ERRNO_MODE=6 fdim.cpp -o fdim && ./fdim
  fdim(1.0, 0x1p-70)           libc=3fff:0000000000000000 (nan)  ref fdiml=0x8p-3
  fdim(1.0, 0x1p-200)          libc=3fff:0000000000000000 (nan)  ref fdiml=0x8p-3
  fdim(LDBL_MAX,-LDBL_MAX*2^-64) libc=7fff:0000000000000000 (nan)  ref fdiml=inf
  fdim(3.0, 1.0) [sanity]      libc=4000:8000000000000000 (0x8p-2)  ref fdiml=0x8p-2
  ```
[fdim.cpp](https://github.com/user-attachments/files/34571045/fdim.cpp)


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


More information about the llvm-branch-commits mailing list