[libc-commits] [libc] [llvm] [libc] Modify NaN/payload functions for emulated float128 type (#221574) (PR #221946)

via libc-commits libc-commits at lists.llvm.org
Fri Sep 18 22:09:24 PDT 2026


https://github.com/Popie52 updated https://github.com/llvm/llvm-project/pull/221946

>From 78f69b32abcbae70ed629ffd3790e25088add9f0 Mon Sep 17 00:00:00 2001
From: popie52 <popiesailor at gmail.com>
Date: Tue, 8 Sep 2026 15:20:32 +0530
Subject: [PATCH 1/8] [libc] Modify NaN/payload functions for emulated float128
 type

---
 libc/config/baremetal/aarch64/entrypoints.txt |  8 ++---
 libc/config/baremetal/arm/entrypoints.txt     |  8 ++---
 libc/config/baremetal/riscv/entrypoints.txt   |  8 ++---
 libc/config/darwin/aarch64/entrypoints.txt    |  8 ++---
 libc/config/freebsd/x86_64/entrypoints.txt    |  8 ++---
 libc/config/linux/aarch64/entrypoints.txt     |  8 ++---
 libc/config/linux/riscv/entrypoints.txt       |  8 ++---
 libc/config/linux/x86_64/entrypoints.txt      |  8 ++---
 libc/shared/math/getpayloadf128.h             |  6 ----
 libc/shared/math/nanf128.h                    |  6 ----
 libc/shared/math/setpayloadf128.h             |  6 ----
 libc/shared/math/setpayloadsigf128.h          |  6 ----
 libc/src/__support/math/CMakeLists.txt        |  8 ++---
 libc/src/__support/math/getpayloadf128.h      | 11 +++----
 libc/src/__support/math/nanf128.h             | 13 +++-----
 libc/src/__support/math/setpayloadf128.h      | 11 +++----
 libc/src/__support/math/setpayloadsigf128.h   | 25 ++++++++-------
 libc/src/math/generic/CMakeLists.txt          |  3 ++
 libc/src/math/generic/getpayloadf128.cpp      |  5 ++-
 libc/src/math/generic/setpayloadf128.cpp      |  5 ++-
 libc/src/math/generic/setpayloadsigf128.cpp   |  5 ++-
 libc/src/math/getpayloadf128.h                |  5 +++
 libc/src/math/nanf128.h                       |  5 +++
 libc/src/math/setpayloadf128.h                |  5 +++
 libc/src/math/setpayloadsigf128.h             |  5 +++
 .../shared/shared_math_constexpr_test.cpp     | 24 ++++++++------
 libc/test/shared/shared_math_test.cpp         | 31 ++++++++++---------
 libc/test/src/math/smoke/CMakeLists.txt       |  4 +++
 .../src/math/smoke/getpayloadf128_test.cpp    |  5 +++
 libc/test/src/math/smoke/nanf128_test.cpp     |  5 +++
 .../src/math/smoke/setpayloadf128_test.cpp    |  8 ++++-
 .../src/math/smoke/setpayloadsigf128_test.cpp |  5 +++
 .../llvm-project-overlay/libc/BUILD.bazel     | 15 ++++++---
 .../libc/test/src/math/smoke/BUILD.bazel      |  9 ++++++
 34 files changed, 174 insertions(+), 126 deletions(-)

diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 114534ce61ae6e..7cd741efe6b4af 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -486,6 +486,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fsubl
     libc.src.math.getpayload
     libc.src.math.getpayloadf
+    libc.src.math.getpayloadf128
     libc.src.math.getpayloadl
     libc.src.math.hypot
     libc.src.math.hypotf
@@ -543,6 +544,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.modfl
     libc.src.math.nan
     libc.src.math.nanf
+    libc.src.math.nanf128
     libc.src.math.nanl
     libc.src.math.nearbyint
     libc.src.math.nearbyintf
@@ -588,9 +590,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadf128
     libc.src.math.setpayloadl
     libc.src.math.setpayloadsig
     libc.src.math.setpayloadsigf
+    libc.src.math.setpayloadsigf128
     libc.src.math.setpayloadsigl
     libc.src.math.sin
     libc.src.math.sincos
@@ -782,13 +786,11 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fromfpxf128
     libc.src.math.fsqrtf128
     libc.src.math.fsubf128
-    libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
-    libc.src.math.nanf128
     libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
@@ -796,8 +798,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
-    libc.src.math.setpayloadf128
-    libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
     libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index c8148815c34e34..1cbdf8e60cd854 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -498,6 +498,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fsubl
     libc.src.math.getpayload
     libc.src.math.getpayloadf
+    libc.src.math.getpayloadf128
     libc.src.math.getpayloadl
     libc.src.math.hypot
     libc.src.math.hypotf
@@ -555,6 +556,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.modfl
     libc.src.math.nan
     libc.src.math.nanf
+    libc.src.math.nanf128
     libc.src.math.nanl
     libc.src.math.nearbyint
     libc.src.math.nearbyintf
@@ -600,9 +602,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadf128
     libc.src.math.setpayloadl
     libc.src.math.setpayloadsig
     libc.src.math.setpayloadsigf
+    libc.src.math.setpayloadsigf128
     libc.src.math.setpayloadsigl
     libc.src.math.sin
     libc.src.math.sincos
@@ -793,13 +797,11 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fromfpxf128
     libc.src.math.fsqrtf128
     libc.src.math.fsubf128
-    libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
-    libc.src.math.nanf128
     libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
@@ -807,8 +809,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
-    libc.src.math.setpayloadf128
-    libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
     libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 622d6156cff11d..70123b25805cf7 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -489,6 +489,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fsubl
     libc.src.math.getpayload
     libc.src.math.getpayloadf
+    libc.src.math.getpayloadf128
     libc.src.math.getpayloadl
     libc.src.math.hypot
     libc.src.math.hypotf
@@ -546,6 +547,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.modfl
     libc.src.math.nan
     libc.src.math.nanf
+    libc.src.math.nanf128
     libc.src.math.nanl
     libc.src.math.nearbyint
     libc.src.math.nearbyintf
@@ -591,9 +593,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadf128
     libc.src.math.setpayloadl
     libc.src.math.setpayloadsig
     libc.src.math.setpayloadsigf
+    libc.src.math.setpayloadsigf128
     libc.src.math.setpayloadsigl
     libc.src.math.sin
     libc.src.math.sincos
@@ -785,13 +789,11 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fromfpxf128
     libc.src.math.fsqrtf128
     libc.src.math.fsubf128
-    libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
-    libc.src.math.nanf128
     libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
@@ -799,8 +801,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
-    libc.src.math.setpayloadf128
-    libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
     libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index d702b2c5a65497..8689e42592ec1a 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -307,6 +307,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fsubl
     libc.src.math.getpayload
     libc.src.math.getpayloadf
+    libc.src.math.getpayloadf128
     libc.src.math.getpayloadl
     libc.src.math.hypot
     libc.src.math.hypotf
@@ -364,6 +365,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.modfl
     libc.src.math.nan
     libc.src.math.nanf
+    libc.src.math.nanf128
     libc.src.math.nanl
     libc.src.math.nearbyint
     libc.src.math.nearbyintf
@@ -409,9 +411,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadf128
     libc.src.math.setpayloadl
     libc.src.math.setpayloadsig
     libc.src.math.setpayloadsigf
+    libc.src.math.setpayloadsigf128
     libc.src.math.setpayloadsigl
     libc.src.math.sin
     libc.src.math.sincos
@@ -604,13 +608,11 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fromfpxf128
     libc.src.math.fsqrtf128
     libc.src.math.fsubf128
-    libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
-    libc.src.math.nanf128
     libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
@@ -618,8 +620,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
-    libc.src.math.setpayloadf128
-    libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
     libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 8f6c178301c2f2..42d52b3ebc6c2c 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -267,6 +267,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.modfl
     libc.src.math.nan
     libc.src.math.nanf
+    libc.src.math.nanf128
     libc.src.math.nanl
     libc.src.math.nearbyint
     libc.src.math.nearbyintf
@@ -347,6 +348,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fsqrtl
     libc.src.math.getpayload
     libc.src.math.getpayloadf
+    libc.src.math.getpayloadf128
     libc.src.math.getpayloadl
     libc.src.math.iscanonical
     libc.src.math.iscanonicalf
@@ -371,9 +373,11 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
     libc.src.math.roundevenl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadf128
     libc.src.math.setpayloadl
     libc.src.math.setpayloadsig
     libc.src.math.setpayloadsigf
+    libc.src.math.setpayloadsigf128
     libc.src.math.setpayloadsigl
     libc.src.math.sincos
     libc.src.math.sinpif
@@ -537,13 +541,11 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fromfpxf128
     libc.src.math.fsqrtf128
     libc.src.math.fsubf128
-    libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
-    libc.src.math.nanf128
     libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
@@ -551,8 +553,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
-    libc.src.math.setpayloadf128
-    libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
     libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index fe1c2965f778b7..d5f92bdd8d8a83 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -686,6 +686,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fsubl
     libc.src.math.getpayload
     libc.src.math.getpayloadf
+    libc.src.math.getpayloadf128
     libc.src.math.getpayloadl
     libc.src.math.hypot
     libc.src.math.hypotf
@@ -743,6 +744,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.modfl
     libc.src.math.nan
     libc.src.math.nanf
+    libc.src.math.nanf128
     libc.src.math.nanl
     libc.src.math.nearbyint
     libc.src.math.nearbyintf
@@ -788,9 +790,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadf128
     libc.src.math.setpayloadl
     libc.src.math.setpayloadsig
     libc.src.math.setpayloadsigf
+    libc.src.math.setpayloadsigf128
     libc.src.math.setpayloadsigl
     libc.src.math.sin
     libc.src.math.sincos
@@ -976,13 +980,11 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fromfpxf128
     libc.src.math.fsqrtf128
     libc.src.math.fsubf128
-    libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
-    libc.src.math.nanf128
     libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
@@ -990,8 +992,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
-    libc.src.math.setpayloadf128
-    libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
     libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 51587056fb02d6..0dca3ebe7f4156 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -748,6 +748,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fsubl
     libc.src.math.getpayload
     libc.src.math.getpayloadf
+    libc.src.math.getpayloadf128
     libc.src.math.getpayloadl
     libc.src.math.hypot
     libc.src.math.hypotf
@@ -805,6 +806,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.modfl
     libc.src.math.nan
     libc.src.math.nanf
+    libc.src.math.nanf128
     libc.src.math.nanl
     libc.src.math.nearbyint
     libc.src.math.nearbyintf
@@ -850,9 +852,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadf128
     libc.src.math.setpayloadl
     libc.src.math.setpayloadsig
     libc.src.math.setpayloadsigf
+    libc.src.math.setpayloadsigf128
     libc.src.math.setpayloadsigl
     libc.src.math.sin
     libc.src.math.sincos
@@ -1055,13 +1059,11 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fromfpxf128
     libc.src.math.fsqrtf128
     libc.src.math.fsubf128
-    libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
-    libc.src.math.nanf128
     libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
@@ -1069,8 +1071,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
-    libc.src.math.setpayloadf128
-    libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
     libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index f21d48d6ef9e7c..3431582656157b 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -764,6 +764,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fsubl
     libc.src.math.getpayload
     libc.src.math.getpayloadf
+    libc.src.math.getpayloadf128
     libc.src.math.getpayloadl
     libc.src.math.hypot
     libc.src.math.hypotf
@@ -821,6 +822,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.modfl
     libc.src.math.nan
     libc.src.math.nanf
+    libc.src.math.nanf128
     libc.src.math.nanl
     libc.src.math.nearbyint
     libc.src.math.nearbyintf
@@ -866,9 +868,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadf128
     libc.src.math.setpayloadl
     libc.src.math.setpayloadsig
     libc.src.math.setpayloadsigf
+    libc.src.math.setpayloadsigf128
     libc.src.math.setpayloadsigl
     libc.src.math.sin
     libc.src.math.sincos
@@ -1071,13 +1075,11 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fromfpxf128
     libc.src.math.fsqrtf128
     libc.src.math.fsubf128
-    libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
-    libc.src.math.nanf128
     libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
@@ -1085,8 +1087,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
-    libc.src.math.setpayloadf128
-    libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
     libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
diff --git a/libc/shared/math/getpayloadf128.h b/libc/shared/math/getpayloadf128.h
index 1a3845e631a8b6..199c9e5df084d6 100644
--- a/libc/shared/math/getpayloadf128.h
+++ b/libc/shared/math/getpayloadf128.h
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_GETPAYLOADF128_H
 #define LLVM_LIBC_SHARED_MATH_GETPAYLOADF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/getpayloadf128.h"
 
@@ -24,6 +20,4 @@ using math::getpayloadf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_GETPAYLOADF128_H
diff --git a/libc/shared/math/nanf128.h b/libc/shared/math/nanf128.h
index 313b6ed6234c52..f1dd96387680ec 100644
--- a/libc/shared/math/nanf128.h
+++ b/libc/shared/math/nanf128.h
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_NANF128_H
 #define LLVM_LIBC_SHARED_MATH_NANF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/nanf128.h"
 
@@ -24,6 +20,4 @@ using math::nanf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_NANF128_H
diff --git a/libc/shared/math/setpayloadf128.h b/libc/shared/math/setpayloadf128.h
index a1f889e89ed394..7efdc34dd15775 100644
--- a/libc/shared/math/setpayloadf128.h
+++ b/libc/shared/math/setpayloadf128.h
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_SETPAYLOADF128_H
 #define LLVM_LIBC_SHARED_MATH_SETPAYLOADF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/setpayloadf128.h"
 
@@ -24,6 +20,4 @@ using math::setpayloadf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADF128_H
diff --git a/libc/shared/math/setpayloadsigf128.h b/libc/shared/math/setpayloadsigf128.h
index 3169b610ccb4d5..a10e07124dad74 100644
--- a/libc/shared/math/setpayloadsigf128.h
+++ b/libc/shared/math/setpayloadsigf128.h
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGF128_H
 #define LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/setpayloadsigf128.h"
 
@@ -24,6 +20,4 @@ using math::setpayloadsigf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 0871a5bf229b63..93882290807db2 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -2181,7 +2181,7 @@ add_header_library(
   HDRS
     nanf128.h
   DEPENDS
-    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.float128
     libc.src.__support.macros.config
     libc.src.__support.str_to_float
     libc.src.__support.libc_errno
@@ -3852,7 +3852,7 @@ add_header_library(
   HDRS
     getpayloadf128.h
   DEPENDS
-    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.macros.config
 )
@@ -4771,7 +4771,7 @@ add_header_library(
   HDRS
     setpayloadf128.h
   DEPENDS
-    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.macros.config
 )
@@ -4828,7 +4828,7 @@ add_header_library(
   HDRS
     setpayloadsigf128.h
   DEPENDS
-    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.macros.config
 )
diff --git a/libc/src/__support/math/getpayloadf128.h b/libc/src/__support/math/getpayloadf128.h
index aed53ee4adbce9..98d4d529b0f312 100644
--- a/libc/src/__support/math/getpayloadf128.h
+++ b/libc/src/__support/math/getpayloadf128.h
@@ -9,24 +9,21 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_GETPAYLOADF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_GETPAYLOADF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE constexpr float128 getpayloadf128(const float128 *x) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr Float128 getpayloadf128(const Float128 *x) {
   return fputil::getpayload(*x);
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_GETPAYLOADF128_H
diff --git a/libc/src/__support/math/nanf128.h b/libc/src/__support/math/nanf128.h
index 5cc1010939d3c6..de445eeab900bc 100644
--- a/libc/src/__support/math/nanf128.h
+++ b/libc/src/__support/math/nanf128.h
@@ -9,19 +9,18 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NANF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_NANF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "src/__support/libc_errno.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/str_to_float.h"
 
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE constexpr float128 nanf128(const char *arg) {
-  auto result = internal::strtonan<float128>(arg);
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr Float128 nanf128(const char *arg) {
+  auto result = internal::strtonan<Float128>(arg);
   if (result.has_error())
     libc_errno = result.error;
   return result.value;
@@ -30,6 +29,4 @@ LIBC_INLINE constexpr float128 nanf128(const char *arg) {
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_NANF128_H
diff --git a/libc/src/__support/math/setpayloadf128.h b/libc/src/__support/math/setpayloadf128.h
index 4e022d8ec91d40..f2ed808866ada5 100644
--- a/libc/src/__support/math/setpayloadf128.h
+++ b/libc/src/__support/math/setpayloadf128.h
@@ -9,24 +9,21 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE constexpr int setpayloadf128(float128 *res, float128 pl) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr int setpayloadf128(Float128 *res, Float128 pl) {
   return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADF128_H
diff --git a/libc/src/__support/math/setpayloadsigf128.h b/libc/src/__support/math/setpayloadsigf128.h
index c9bd9498cfb744..0f41af7e9769bb 100644
--- a/libc/src/__support/math/setpayloadsigf128.h
+++ b/libc/src/__support/math/setpayloadsigf128.h
@@ -1,32 +1,35 @@
-//===-- Implementation header for setpayloadsigf128 -------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for setpayloadsigf128.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/FPUtil/float128.h"
+#include "src/__support/CPP/type_traits.h"
+#include "src/__support/common.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE constexpr int setpayloadsigf128(float128 *res, float128 pl) {
-  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr int setpayloadsigf128(Float128 *res, Float128 pl) {
+  return static_cast<int>(
+      fputil::setpayload</*IsSignaling=*/true>(*res, pl));
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 28b8e954530ddf..3cffe69f7ca5fe 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4409,6 +4409,7 @@ add_entrypoint_object(
   HDRS
     ../getpayloadf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.getpayloadf128
 )
 
@@ -4469,6 +4470,7 @@ add_entrypoint_object(
   HDRS
     ../setpayloadf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.setpayloadf128
 )
 
@@ -4529,6 +4531,7 @@ add_entrypoint_object(
   HDRS
     ../setpayloadsigf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.setpayloadsigf128
 )
 
diff --git a/libc/src/math/generic/getpayloadf128.cpp b/libc/src/math/generic/getpayloadf128.cpp
index ba2b1cf798f3b9..648acfd555f0c2 100644
--- a/libc/src/math/generic/getpayloadf128.cpp
+++ b/libc/src/math/generic/getpayloadf128.cpp
@@ -7,12 +7,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/getpayloadf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/getpayloadf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(float128, getpayloadf128, (const float128 *x)) {
-  return math::getpayloadf128(x);
+  return cpp::bit_cast<float128>(math::getpayloadf128(cpp::bit_cast<const Float128 *>(x)));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadf128.cpp b/libc/src/math/generic/setpayloadf128.cpp
index 83a3218688a999..fa71b46a8a89c4 100644
--- a/libc/src/math/generic/setpayloadf128.cpp
+++ b/libc/src/math/generic/setpayloadf128.cpp
@@ -7,12 +7,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/setpayloadf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/setpayloadf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(int, setpayloadf128, (float128 * res, float128 pl)) {
-  return math::setpayloadf128(res, pl);
+  return math::setpayloadf128(cpp::bit_cast<Float128 *>(res), cpp::bit_cast<Float128>(pl));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadsigf128.cpp b/libc/src/math/generic/setpayloadsigf128.cpp
index a3972286767b52..91dd561568d478 100644
--- a/libc/src/math/generic/setpayloadsigf128.cpp
+++ b/libc/src/math/generic/setpayloadsigf128.cpp
@@ -7,12 +7,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/setpayloadsigf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/setpayloadsigf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(int, setpayloadsigf128, (float128 * res, float128 pl)) {
-  return math::setpayloadsigf128(res, pl);
+  return math::setpayloadsigf128(cpp::bit_cast<Float128 *>(res), cpp::bit_cast<Float128>(pl));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/getpayloadf128.h b/libc/src/math/getpayloadf128.h
index 7ebb4290d4f8a3..383b03219203e5 100644
--- a/libc/src/math/getpayloadf128.h
+++ b/libc/src/math/getpayloadf128.h
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_GETPAYLOADF128_H
 #define LLVM_LIBC_SRC_MATH_GETPAYLOADF128_H
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/types.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 float128 getpayloadf128(const float128 *x);
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nanf128.h b/libc/src/math/nanf128.h
index 1c1323adcd7812..4bc24649f0e33c 100644
--- a/libc/src/math/nanf128.h
+++ b/libc/src/math/nanf128.h
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_NANF128_H
 #define LLVM_LIBC_SRC_MATH_NANF128_H
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/types.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 float128 nanf128(const char *arg);
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/setpayloadf128.h b/libc/src/math/setpayloadf128.h
index e46aef38256db6..d3f357bc6c49fe 100644
--- a/libc/src/math/setpayloadf128.h
+++ b/libc/src/math/setpayloadf128.h
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_SETPAYLOADF128_H
 #define LLVM_LIBC_SRC_MATH_SETPAYLOADF128_H
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/types.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 int setpayloadf128(float128 *res, float128 pl);
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/setpayloadsigf128.h b/libc/src/math/setpayloadsigf128.h
index 4e036b9c8ba007..80bc58c4998184 100644
--- a/libc/src/math/setpayloadsigf128.h
+++ b/libc/src/math/setpayloadsigf128.h
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_SETPAYLOADSIGF128_H
 #define LLVM_LIBC_SRC_MATH_SETPAYLOADSIGF128_H
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/types.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 int setpayloadsigf128(float128 *res, float128 pl);
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 370c31e193f5e7..74eb4293f93320 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -451,6 +451,20 @@ static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::roundf128(Float128(0.0)));
 static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::truncf128(Float128(0.0)));
+static_assert(Float128(-1.0) == [] {
+  Float128 getpayload_x = Float128(0.0);
+  return LIBC_NAMESPACE::shared::getpayloadf128(&getpayload_x);
+}());
+static_assert(1 == [] {
+  const char arg{};
+  return LIBC_NAMESPACE::fputil::FPBits<Float128>(
+             LIBC_NAMESPACE::shared::nanf128(&arg))
+      .is_nan();
+}());
+static_assert(0 == [] {
+  Float128 setpayload_x = Float128(0.0);
+  return LIBC_NAMESPACE::shared::setpayloadf128(&setpayload_x, Float128(0.0));
+}());
 
 //===----------------------------------------------------------------------===//
 //                       Native Float128 Tests
@@ -477,10 +491,6 @@ static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::fromfpf128(float128(0.0), 0, 32));
 static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::fromfpxf128(float128(0.0), 0, 32));
-static_assert(float128(-1.0) == [] {
-  float128 getpayload_x = float128(0.0);
-  return LIBC_NAMESPACE::shared::getpayloadf128(&getpayload_x);
-}());
 static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::ufromfpf128(float128(0.0), 0, 32));
 static_assert(float128(0.0) ==
@@ -527,12 +537,6 @@ static_assert(0.0f ==
 static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::nextafterf128(float128(0.0),
                                                     float128(0.0)));
-static_assert(1 == [] {
-  const char arg{};
-  return LIBC_NAMESPACE::fputil::FPBits<float128>(
-             LIBC_NAMESPACE::shared::nanf128(&arg))
-      .is_nan();
-}());
 
 #endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
 
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 7b785331f36c6a..cfae2a1ab48f51 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -581,6 +581,8 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
 
 // Emulated float128 tests
 TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
+  using FPBits = LIBC_NAMESPACE::fputil::FPBits<Float128>;
+
   EXPECT_FP_EQ(Float128(0.0),
                LIBC_NAMESPACE::shared::atan2f128(Float128(0.0), Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
@@ -625,6 +627,20 @@ TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::roundf128(Float128(0.0)));
   EXPECT_FP_EQ(Float128(1.0), LIBC_NAMESPACE::shared::sqrtf128(Float128(1.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::truncf128(Float128(0.0)));
+  EXPECT_TRUE(FPBits(LIBC_NAMESPACE::shared::nanf128("")).is_nan());
+
+  Float128 getpayloadf128_x = Float128(0.0);
+  EXPECT_FP_EQ(Float128(-1.0),
+               LIBC_NAMESPACE::shared::getpayloadf128(&getpayloadf128_x));
+
+  Float128 setpayloadf128_res = Float128(0.0);
+  EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadf128(&setpayloadf128_res,
+                                                      Float128(0.0)));
+
+  Float128 setpayloadsigf128_res = Float128(0.0);
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::setpayloadsigf128(&setpayloadsigf128_res,
+                                                         Float128(0.0)));
+  EXPECT_FP_EQ(Float128(0.0), setpayloadsigf128_res);
 }
 
 #ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
@@ -681,20 +697,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
                LIBC_NAMESPACE::shared::faddf128(float128(0.0), float128(0.0)));
   EXPECT_FP_EQ(1.0f,
                LIBC_NAMESPACE::shared::fdivf128(float128(1.0), float128(1.0)));
-
-  float128 getpayloadf128_x = float128(0.0);
-  EXPECT_FP_EQ(float128(-1.0),
-               LIBC_NAMESPACE::shared::getpayloadf128(&getpayloadf128_x));
-
-  float128 setpayloadf128_res = float128(0.0);
-  EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadf128(&setpayloadf128_res,
-                                                      float128(0.0)));
-
-  float128 setpayloadsigf128_res = float128(0.0);
-  EXPECT_EQ(1, LIBC_NAMESPACE::shared::setpayloadsigf128(&setpayloadsigf128_res,
-                                                         float128(0.0)));
-  EXPECT_FP_EQ(float128(0.0), setpayloadsigf128_res);
-
   float128 neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal,
                LIBC_NAMESPACE::shared::nextdownf128(float128(0.0)));
@@ -754,7 +756,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
                LIBC_NAMESPACE::shared::fsubf128(float128(0.0), float128(0.0)));
   EXPECT_FP_EQ(0x0p+0f,
                LIBC_NAMESPACE::shared::fmulf128(float128(0.0), float128(0.0)));
-  EXPECT_TRUE(FPBits(LIBC_NAMESPACE::shared::nanf128("")).is_nan());
 }
 
 #endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 603998cd1c41c9..1015b80172d66e 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3935,6 +3935,7 @@ add_fp_unittest(
   DEPENDS
     libc.hdr.signal_macros
     libc.src.math.nanf128
+    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.fp_bits
   # FIXME: The nan tests currently have death tests, which aren't supported for
   # hermetic tests.
@@ -5572,6 +5573,7 @@ add_fp_unittest(
     GetPayloadTest.h
   DEPENDS
     libc.src.math.getpayloadf128
+    libc.src.__support.FPUtil.float128
 )
 
 add_fp_unittest(
@@ -5645,6 +5647,7 @@ add_fp_unittest(
     SetPayloadTest.h
   DEPENDS
     libc.src.math.setpayloadf128
+    libc.src.__support.FPUtil.float128
 )
 
 add_fp_unittest(
@@ -5718,6 +5721,7 @@ add_fp_unittest(
     SetPayloadSigTest.h
   DEPENDS
     libc.src.math.setpayloadsigf128
+    libc.src.__support.FPUtil.float128
 )
 
 add_fp_unittest(
diff --git a/libc/test/src/math/smoke/getpayloadf128_test.cpp b/libc/test/src/math/smoke/getpayloadf128_test.cpp
index 77304abfbbc0a9..41af1066b11c71 100644
--- a/libc/test/src/math/smoke/getpayloadf128_test.cpp
+++ b/libc/test/src/math/smoke/getpayloadf128_test.cpp
@@ -8,6 +8,11 @@
 
 #include "GetPayloadTest.h"
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/math/getpayloadf128.h"
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 LIST_GETPAYLOAD_TESTS(Getpayloadf128, float128, LIBC_NAMESPACE::getpayloadf128)
diff --git a/libc/test/src/math/smoke/nanf128_test.cpp b/libc/test/src/math/smoke/nanf128_test.cpp
index 40b347de25f7a9..ef781cbdf1b9b6 100644
--- a/libc/test/src/math/smoke/nanf128_test.cpp
+++ b/libc/test/src/math/smoke/nanf128_test.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "hdr/signal_macros.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/uint128.h"
 #include "src/math/nanf128.h"
@@ -14,6 +15,10 @@
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif
+
 class LlvmLibcNanf128Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 public:
   using FPBits128 = LIBC_NAMESPACE::fputil::FPBits<float128>;
diff --git a/libc/test/src/math/smoke/setpayloadf128_test.cpp b/libc/test/src/math/smoke/setpayloadf128_test.cpp
index 3e386972980e13..0048827944be76 100644
--- a/libc/test/src/math/smoke/setpayloadf128_test.cpp
+++ b/libc/test/src/math/smoke/setpayloadf128_test.cpp
@@ -8,6 +8,12 @@
 
 #include "SetPayloadTest.h"
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/math/setpayloadf128.h"
 
-LIST_SETPAYLOAD_TESTS(Setpayloadf128, float128, LIBC_NAMESPACE::setpayloadf128)
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
+LIST_SETPAYLOAD_TESTS(Setpayloadf128, float128,
+                      LIBC_NAMESPACE::setpayloadf128)
diff --git a/libc/test/src/math/smoke/setpayloadsigf128_test.cpp b/libc/test/src/math/smoke/setpayloadsigf128_test.cpp
index 90f2a2aef9569f..575573306de4ad 100644
--- a/libc/test/src/math/smoke/setpayloadsigf128_test.cpp
+++ b/libc/test/src/math/smoke/setpayloadsigf128_test.cpp
@@ -8,7 +8,12 @@
 
 #include "SetPayloadSigTest.h"
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/math/setpayloadsigf128.h"
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 LIST_SETPAYLOADSIG_TESTS(Setpayloadsigf128, float128,
                          LIBC_NAMESPACE::setpayloadsigf128)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index cdbf40b3e81a24..a790601e58a9c2 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -5458,9 +5458,9 @@ libc_support_library(
     name = "__support_math_setpayloadf128",
     hdrs = ["src/__support/math/setpayloadf128.h"],
     deps = [
+        ":__support_fputil_float128",
         ":__support_fputil_basic_operations",
         ":__support_macros_config",
-        ":llvm_libc_types_float128",
     ],
 )
 
@@ -5516,8 +5516,8 @@ libc_support_library(
     hdrs = ["src/__support/math/setpayloadsigf128.h"],
     deps = [
         ":__support_fputil_basic_operations",
+        ":__support_fputil_float128",
         ":__support_macros_config",
-        ":llvm_libc_types_float128",
     ],
 )
 
@@ -7607,10 +7607,10 @@ libc_support_library(
     name = "__support_math_nanf128",
     hdrs = ["src/__support/math/nanf128.h"],
     deps = [
+        ":__support_fputil_float128",
         ":__support_libc_errno",
         ":__support_macros_config",
         ":__support_str_to_float",
-        ":llvm_libc_types_float128",
     ],
 )
 
@@ -9276,9 +9276,9 @@ libc_support_library(
     name = "__support_math_getpayloadf128",
     hdrs = ["src/__support/math/getpayloadf128.h"],
     deps = [
+        ":__support_fputil_float128",
         ":__support_fputil_basic_operations",
         ":__support_macros_config",
-        ":llvm_libc_types_float128",
     ],
 )
 
@@ -13416,6 +13416,8 @@ libc_math_function(
 libc_math_function(
     name = "getpayloadf128",
     additional_deps = [
+        ":__support_cpp_bit",
+        ":__support_fputil_float128",
         ":__support_math_getpayloadf128",
     ],
 )
@@ -13952,6 +13954,7 @@ libc_math_function(
 libc_math_function(
     name = "nanf128",
     additional_deps = [
+        ":__support_fputil_float128",
         ":__support_math_nanf128",
     ],
 )
@@ -14527,6 +14530,8 @@ libc_math_function(
 libc_math_function(
     name = "setpayloadf128",
     additional_deps = [
+        ":__support_cpp_bit",
+        ":__support_fputil_float128",
         ":__support_math_setpayloadf128",
     ],
 )
@@ -14569,6 +14574,8 @@ libc_math_function(
 libc_math_function(
     name = "setpayloadsigf128",
     additional_deps = [
+        ":__support_cpp_bit",
+        ":__support_fputil_float128",
         ":__support_math_setpayloadsigf128",
     ],
 )
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index e1d9305617303e..e7c2e531c22850 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -1232,6 +1232,9 @@ math_test(
 math_test(
     name = "getpayloadf128",
     hdrs = ["GetPayloadTest.h"],
+    deps = [
+        "//libc:__support_fputil_float128",
+    ],
 )
 
 math_test(
@@ -2051,6 +2054,9 @@ math_test(
 math_test(
     name = "setpayloadf128",
     hdrs = ["SetPayloadTest.h"],
+    deps = [
+        "//libc:__support_fputil_float128",
+    ],
 )
 
 math_test(
@@ -2084,6 +2090,9 @@ math_test(
 math_test(
     name = "setpayloadsigf128",
     hdrs = ["SetPayloadSigTest.h"],
+    deps = [
+        "//libc:__support_fputil_float128",
+    ]
 )
 
 math_test(

>From 5f9aa847cc4951ae797f85328c7c507385b947e4 Mon Sep 17 00:00:00 2001
From: popie52 <popiesailor at gmail.com>
Date: Tue, 8 Sep 2026 18:42:59 +0530
Subject: [PATCH 2/8] [libc] Fix emulated f128 NaN payload entrypoints

---
 libc/config/gpu/amdgpu/entrypoints.txt                       | 4 ++++
 libc/config/gpu/nvptx/entrypoints.txt                        | 4 ++++
 libc/config/linux/arm/entrypoints.txt                        | 4 ++++
 libc/config/windows/entrypoints.txt                          | 5 ++++-
 libc/src/math/generic/nanf128.cpp                            | 3 ++-
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel            | 4 ++--
 .../libc/test/src/math/smoke/BUILD.bazel                     | 2 +-
 7 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 5c5e5891da8227..0da982665cb96f 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -428,6 +428,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fsubl
     libc.src.math.getpayload
     libc.src.math.getpayloadf
+    libc.src.math.getpayloadf128
     libc.src.math.getpayloadl
     libc.src.math.hypot
     libc.src.math.hypotf
@@ -481,6 +482,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.modfl
     libc.src.math.nan
     libc.src.math.nanf
+    libc.src.math.nanf128
     libc.src.math.nanl
     libc.src.math.nearbyint
     libc.src.math.nearbyintf
@@ -526,9 +528,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadf128
     libc.src.math.setpayloadl
     libc.src.math.setpayloadsig
     libc.src.math.setpayloadsigf
+    libc.src.math.setpayloadsigf128
     libc.src.math.setpayloadsigl
     libc.src.math.sin
     libc.src.math.sincos
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index afae725484a891..0317e3839ad11f 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -425,6 +425,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fsubl
     libc.src.math.getpayload
     libc.src.math.getpayloadf
+    libc.src.math.getpayloadf128
     libc.src.math.getpayloadl
     libc.src.math.hypot
     libc.src.math.hypotf
@@ -478,6 +479,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.modfl
     libc.src.math.nan
     libc.src.math.nanf
+    libc.src.math.nanf128
     libc.src.math.nanl
     libc.src.math.nearbyint
     libc.src.math.nearbyintf
@@ -523,9 +525,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadf128
     libc.src.math.setpayloadl
     libc.src.math.setpayloadsig
     libc.src.math.setpayloadsigf
+    libc.src.math.setpayloadsigf128
     libc.src.math.setpayloadsigl
     libc.src.math.sin
     libc.src.math.sincos
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index f4347331d0b310..3ffa7ebfa7e414 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -493,6 +493,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fsubl
     libc.src.math.getpayload
     libc.src.math.getpayloadf
+    libc.src.math.getpayloadf128
     libc.src.math.getpayloadl
     libc.src.math.hypot
     libc.src.math.hypotf
@@ -541,6 +542,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.modfl
     libc.src.math.nan
     libc.src.math.nanf
+    libc.src.math.nanf128
     libc.src.math.nanl
     libc.src.math.nearbyint
     libc.src.math.nearbyintf
@@ -583,9 +585,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadf128
     libc.src.math.setpayloadl
     libc.src.math.setpayloadsig
     libc.src.math.setpayloadsigf
+    libc.src.math.setpayloadsigf128
     libc.src.math.setpayloadsigl
     libc.src.math.sin
     libc.src.math.sincos
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 3a48b49e169b3a..8cc4feaf96cc41 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -300,6 +300,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.modfl
     libc.src.math.nan
     libc.src.math.nanf
+    libc.src.math.nanf128
     libc.src.math.nanl
     libc.src.math.nearbyint
     libc.src.math.nearbyintf
@@ -395,6 +396,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fromfpbf16
   libc.src.math.fromfpxbf16
   libc.src.math.getpayloadbf16
+  libc.src.math.getpayloadf128
   libc.src.math.hypotbf16
   libc.src.math.ilogbbf16
   libc.src.math.iscanonicalbf16
@@ -422,7 +424,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalblnbf16
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
+  libc.src.math.setpayloadf128
   libc.src.math.setpayloadsigbf16
+  libc.src.math.setpayloadsigf128
   libc.src.math.sqrtbf16
   libc.src.math.tanbf16
   libc.src.math.truncbf16
@@ -436,4 +440,3 @@ set(TARGET_LLVMLIBC_ENTRYPOINTS
   ${TARGET_LIBC_ENTRYPOINTS}
   ${TARGET_LIBM_ENTRYPOINTS}
 )
-
diff --git a/libc/src/math/generic/nanf128.cpp b/libc/src/math/generic/nanf128.cpp
index 04cb5cf03cc745..abf2b83603ad70 100644
--- a/libc/src/math/generic/nanf128.cpp
+++ b/libc/src/math/generic/nanf128.cpp
@@ -7,12 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nanf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/nanf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float128, nanf128, (const char *arg)) {
-  return math::nanf128(arg);
+  return cpp::bit_cast<float128>(math::nanf128(arg));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index a790601e58a9c2..2149fc68863dae 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -5458,8 +5458,8 @@ libc_support_library(
     name = "__support_math_setpayloadf128",
     hdrs = ["src/__support/math/setpayloadf128.h"],
     deps = [
-        ":__support_fputil_float128",
         ":__support_fputil_basic_operations",
+        ":__support_fputil_float128",
         ":__support_macros_config",
     ],
 )
@@ -9276,8 +9276,8 @@ libc_support_library(
     name = "__support_math_getpayloadf128",
     hdrs = ["src/__support/math/getpayloadf128.h"],
     deps = [
-        ":__support_fputil_float128",
         ":__support_fputil_basic_operations",
+        ":__support_fputil_float128",
         ":__support_macros_config",
     ],
 )
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index e7c2e531c22850..0fe103f73207fa 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -2092,7 +2092,7 @@ math_test(
     hdrs = ["SetPayloadSigTest.h"],
     deps = [
         "//libc:__support_fputil_float128",
-    ]
+    ],
 )
 
 math_test(

>From faed5fc230cb8249c5c588bb9a3d9c8221beee0f Mon Sep 17 00:00:00 2001
From: popie52 <popiesailor at gmail.com>
Date: Tue, 8 Sep 2026 19:25:14 +0530
Subject: [PATCH 3/8] [libc] Fix emulated f128 NaN payload entrypoints

---
 libc/src/__support/math/CMakeLists.txt  |  8 ++++----
 libc/src/math/generic/CMakeLists.txt    |  1 +
 libc/test/src/math/smoke/CMakeLists.txt | 10 +++++-----
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 93882290807db2..9ba1fecbb0faea 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -2182,9 +2182,9 @@ add_header_library(
     nanf128.h
   DEPENDS
     libc.src.__support.FPUtil.float128
+    libc.src.__support.libc_errno
     libc.src.__support.macros.config
     libc.src.__support.str_to_float
-    libc.src.__support.libc_errno
 )
 
 add_header_library(
@@ -3852,8 +3852,8 @@ add_header_library(
   HDRS
     getpayloadf128.h
   DEPENDS
-    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.float128
     libc.src.__support.macros.config
 )
 
@@ -4771,8 +4771,8 @@ add_header_library(
   HDRS
     setpayloadf128.h
   DEPENDS
-    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.float128
     libc.src.__support.macros.config
 )
 
@@ -4828,8 +4828,8 @@ add_header_library(
   HDRS
     setpayloadsigf128.h
   DEPENDS
-    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.float128
     libc.src.__support.macros.config
 )
 
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 3cffe69f7ca5fe..3f87b1569218da 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3182,6 +3182,7 @@ add_entrypoint_object(
   HDRS
     ../nanf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.nanf128
 )
 
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 1015b80172d66e..bbc91857f05acb 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3933,10 +3933,10 @@ add_fp_unittest(
   SRCS
     nanf128_test.cpp
   DEPENDS
-    libc.hdr.signal_macros
-    libc.src.math.nanf128
     libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.fp_bits
+    libc.hdr.signal_macros
+    libc.src.math.nanf128
   # FIXME: The nan tests currently have death tests, which aren't supported for
   # hermetic tests.
 )
@@ -5572,8 +5572,8 @@ add_fp_unittest(
   HDRS
     GetPayloadTest.h
   DEPENDS
-    libc.src.math.getpayloadf128
     libc.src.__support.FPUtil.float128
+    libc.src.math.getpayloadf128
 )
 
 add_fp_unittest(
@@ -5646,8 +5646,8 @@ add_fp_unittest(
   HDRS
     SetPayloadTest.h
   DEPENDS
-    libc.src.math.setpayloadf128
     libc.src.__support.FPUtil.float128
+    libc.src.math.setpayloadf128
 )
 
 add_fp_unittest(
@@ -5720,8 +5720,8 @@ add_fp_unittest(
   HDRS
     SetPayloadSigTest.h
   DEPENDS
-    libc.src.math.setpayloadsigf128
     libc.src.__support.FPUtil.float128
+    libc.src.math.setpayloadsigf128
 )
 
 add_fp_unittest(

>From c1488ae926d908c540b17dc2aebf19dffa7674f8 Mon Sep 17 00:00:00 2001
From: popie52 <popiesailor at gmail.com>
Date: Sun, 13 Sep 2026 07:40:11 +0530
Subject: [PATCH 4/8] [libc] Fix formatting for emulated f128 NaN payload
 functions

---
 libc/src/__support/math/nanf128.h           | 2 +-
 libc/src/math/generic/getpayloadf128.cpp    | 3 ++-
 libc/src/math/generic/setpayloadf128.cpp    | 3 ++-
 libc/src/math/generic/setpayloadsigf128.cpp | 3 ++-
 libc/test/src/math/smoke/nanf128_test.cpp   | 2 +-
 5 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/libc/src/__support/math/nanf128.h b/libc/src/__support/math/nanf128.h
index de445eeab900bc..f57be9f31f7b91 100644
--- a/libc/src/__support/math/nanf128.h
+++ b/libc/src/__support/math/nanf128.h
@@ -9,8 +9,8 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NANF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_NANF128_H
 
-#include "src/__support/libc_errno.h"
 #include "src/__support/FPUtil/float128.h"
+#include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/str_to_float.h"
 
diff --git a/libc/src/math/generic/getpayloadf128.cpp b/libc/src/math/generic/getpayloadf128.cpp
index 648acfd555f0c2..069d374ba0cf41 100644
--- a/libc/src/math/generic/getpayloadf128.cpp
+++ b/libc/src/math/generic/getpayloadf128.cpp
@@ -15,7 +15,8 @@ namespace LIBC_NAMESPACE_DECL {
 using LIBC_NAMESPACE::fputil::Float128;
 
 LLVM_LIBC_FUNCTION(float128, getpayloadf128, (const float128 *x)) {
-  return cpp::bit_cast<float128>(math::getpayloadf128(cpp::bit_cast<const Float128 *>(x)));
+  return cpp::bit_cast<float128>(
+      math::getpayloadf128(cpp::bit_cast<const Float128 *>(x)));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadf128.cpp b/libc/src/math/generic/setpayloadf128.cpp
index fa71b46a8a89c4..faa1a08da7df92 100644
--- a/libc/src/math/generic/setpayloadf128.cpp
+++ b/libc/src/math/generic/setpayloadf128.cpp
@@ -15,7 +15,8 @@ namespace LIBC_NAMESPACE_DECL {
 using LIBC_NAMESPACE::fputil::Float128;
 
 LLVM_LIBC_FUNCTION(int, setpayloadf128, (float128 * res, float128 pl)) {
-  return math::setpayloadf128(cpp::bit_cast<Float128 *>(res), cpp::bit_cast<Float128>(pl));
+  return math::setpayloadf128(cpp::bit_cast<Float128 *>(res),
+                              cpp::bit_cast<Float128>(pl));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadsigf128.cpp b/libc/src/math/generic/setpayloadsigf128.cpp
index 91dd561568d478..fab5902222cf64 100644
--- a/libc/src/math/generic/setpayloadsigf128.cpp
+++ b/libc/src/math/generic/setpayloadsigf128.cpp
@@ -15,7 +15,8 @@ namespace LIBC_NAMESPACE_DECL {
 using LIBC_NAMESPACE::fputil::Float128;
 
 LLVM_LIBC_FUNCTION(int, setpayloadsigf128, (float128 * res, float128 pl)) {
-  return math::setpayloadsigf128(cpp::bit_cast<Float128 *>(res), cpp::bit_cast<Float128>(pl));
+  return math::setpayloadsigf128(cpp::bit_cast<Float128 *>(res),
+                                 cpp::bit_cast<Float128>(pl));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/smoke/nanf128_test.cpp b/libc/test/src/math/smoke/nanf128_test.cpp
index ef781cbdf1b9b6..1b8438aea79b9f 100644
--- a/libc/test/src/math/smoke/nanf128_test.cpp
+++ b/libc/test/src/math/smoke/nanf128_test.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "hdr/signal_macros.h"
-#include "src/__support/FPUtil/float128.h"
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/uint128.h"
 #include "src/math/nanf128.h"
 #include "test/UnitTest/FEnvSafeTest.h"

>From 48e1234a49299c4b457d8bca8adbc7eac6eb3c9c Mon Sep 17 00:00:00 2001
From: popie52 <popiesailor at gmail.com>
Date: Mon, 14 Sep 2026 00:45:14 +0530
Subject: [PATCH 5/8] [libc] Update f128 NaN payload file headers and tests

---
 libc/shared/math/getpayloadf128.h              |  7 ++++++-
 libc/shared/math/nanf128.h                     |  7 ++++++-
 libc/shared/math/setpayloadf128.h              |  7 ++++++-
 libc/shared/math/setpayloadsigf128.h           |  7 ++++++-
 libc/src/__support/math/getpayloadf128.h       |  7 ++++++-
 libc/src/__support/math/nanf128.h              |  7 ++++++-
 libc/src/__support/math/setpayloadf128.h       |  7 ++++++-
 libc/src/math/generic/getpayloadf128.cpp       |  7 ++++++-
 libc/src/math/generic/nanf128.cpp              |  7 ++++++-
 libc/src/math/generic/setpayloadf128.cpp       |  7 ++++++-
 libc/src/math/generic/setpayloadsigf128.cpp    |  7 ++++++-
 libc/src/math/getpayloadf128.h                 |  7 ++++++-
 libc/src/math/nanf128.h                        |  7 ++++++-
 libc/src/math/setpayloadf128.h                 |  7 ++++++-
 libc/src/math/setpayloadsigf128.h              |  7 ++++++-
 libc/test/shared/shared_math_test.cpp          | 18 +++++++++++-------
 .../src/math/smoke/getpayloadf128_test.cpp     |  7 ++++++-
 libc/test/src/math/smoke/nanf128_test.cpp      |  7 ++++++-
 .../src/math/smoke/setpayloadf128_test.cpp     |  7 ++++++-
 .../src/math/smoke/setpayloadsigf128_test.cpp  |  7 ++++++-
 .../libc/test/src/math/smoke/BUILD.bazel       |  8 +++++++-
 21 files changed, 132 insertions(+), 27 deletions(-)

diff --git a/libc/shared/math/getpayloadf128.h b/libc/shared/math/getpayloadf128.h
index 199c9e5df084d6..6d4ffacac5581d 100644
--- a/libc/shared/math/getpayloadf128.h
+++ b/libc/shared/math/getpayloadf128.h
@@ -1,10 +1,15 @@
-//===-- Shared getpayloadf128 function --------------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Shared getpayloadf128 function.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SHARED_MATH_GETPAYLOADF128_H
 #define LLVM_LIBC_SHARED_MATH_GETPAYLOADF128_H
diff --git a/libc/shared/math/nanf128.h b/libc/shared/math/nanf128.h
index f1dd96387680ec..266a1ae46de618 100644
--- a/libc/shared/math/nanf128.h
+++ b/libc/shared/math/nanf128.h
@@ -1,10 +1,15 @@
-//===-- Shared nanf128 function ---------------------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Shared nanf128 function.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SHARED_MATH_NANF128_H
 #define LLVM_LIBC_SHARED_MATH_NANF128_H
diff --git a/libc/shared/math/setpayloadf128.h b/libc/shared/math/setpayloadf128.h
index 7efdc34dd15775..7ecc1dac8e6131 100644
--- a/libc/shared/math/setpayloadf128.h
+++ b/libc/shared/math/setpayloadf128.h
@@ -1,10 +1,15 @@
-//===-- Shared setpayloadf128 function --------------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Shared setpayloadf128 function.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SHARED_MATH_SETPAYLOADF128_H
 #define LLVM_LIBC_SHARED_MATH_SETPAYLOADF128_H
diff --git a/libc/shared/math/setpayloadsigf128.h b/libc/shared/math/setpayloadsigf128.h
index a10e07124dad74..7038c3947cdb6e 100644
--- a/libc/shared/math/setpayloadsigf128.h
+++ b/libc/shared/math/setpayloadsigf128.h
@@ -1,10 +1,15 @@
-//===-- Shared setpayloadsigf128 function -----------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Shared setpayloadsigf128 function.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGF128_H
 #define LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGF128_H
diff --git a/libc/src/__support/math/getpayloadf128.h b/libc/src/__support/math/getpayloadf128.h
index 98d4d529b0f312..1d8cd547962e48 100644
--- a/libc/src/__support/math/getpayloadf128.h
+++ b/libc/src/__support/math/getpayloadf128.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for getpayloadf128 ----------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implementation header for getpayloadf128.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_GETPAYLOADF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_GETPAYLOADF128_H
diff --git a/libc/src/__support/math/nanf128.h b/libc/src/__support/math/nanf128.h
index f57be9f31f7b91..9ebf2ba1ed85bb 100644
--- a/libc/src/__support/math/nanf128.h
+++ b/libc/src/__support/math/nanf128.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for nanf128 -----------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implementation header for nanf128.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NANF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_NANF128_H
diff --git a/libc/src/__support/math/setpayloadf128.h b/libc/src/__support/math/setpayloadf128.h
index f2ed808866ada5..f97c11c64c0e4d 100644
--- a/libc/src/__support/math/setpayloadf128.h
+++ b/libc/src/__support/math/setpayloadf128.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for setpayloadf128 ----------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implementation header for setpayloadf128.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADF128_H
diff --git a/libc/src/math/generic/getpayloadf128.cpp b/libc/src/math/generic/getpayloadf128.cpp
index 069d374ba0cf41..8f44a54aabbab5 100644
--- a/libc/src/math/generic/getpayloadf128.cpp
+++ b/libc/src/math/generic/getpayloadf128.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of getpayloadf128 function -------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implementation of getpayloadf128 function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/math/getpayloadf128.h"
 #include "src/__support/CPP/bit.h"
diff --git a/libc/src/math/generic/nanf128.cpp b/libc/src/math/generic/nanf128.cpp
index abf2b83603ad70..02d4fadd5a412d 100644
--- a/libc/src/math/generic/nanf128.cpp
+++ b/libc/src/math/generic/nanf128.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of nanf128 function --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implementation of nanf128 function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/math/nanf128.h"
 #include "src/__support/CPP/bit.h"
diff --git a/libc/src/math/generic/setpayloadf128.cpp b/libc/src/math/generic/setpayloadf128.cpp
index faa1a08da7df92..a25be192e9c36d 100644
--- a/libc/src/math/generic/setpayloadf128.cpp
+++ b/libc/src/math/generic/setpayloadf128.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of setpayloadf128 function -------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implementation of setpayloadf128 function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/math/setpayloadf128.h"
 #include "src/__support/CPP/bit.h"
diff --git a/libc/src/math/generic/setpayloadsigf128.cpp b/libc/src/math/generic/setpayloadsigf128.cpp
index fab5902222cf64..b08aa8487907dd 100644
--- a/libc/src/math/generic/setpayloadsigf128.cpp
+++ b/libc/src/math/generic/setpayloadsigf128.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of setpayloadsigf128 function ----------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implementation of setpayloadsigf128 function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/math/setpayloadsigf128.h"
 #include "src/__support/CPP/bit.h"
diff --git a/libc/src/math/getpayloadf128.h b/libc/src/math/getpayloadf128.h
index 383b03219203e5..70adef8e23ce93 100644
--- a/libc/src/math/getpayloadf128.h
+++ b/libc/src/math/getpayloadf128.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for getpayloadf128 ----------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implementation header for getpayloadf128.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_MATH_GETPAYLOADF128_H
 #define LLVM_LIBC_SRC_MATH_GETPAYLOADF128_H
diff --git a/libc/src/math/nanf128.h b/libc/src/math/nanf128.h
index 4bc24649f0e33c..354c021d39d343 100644
--- a/libc/src/math/nanf128.h
+++ b/libc/src/math/nanf128.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for nanf128 -----------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implementation header for nanf128.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_MATH_NANF128_H
 #define LLVM_LIBC_SRC_MATH_NANF128_H
diff --git a/libc/src/math/setpayloadf128.h b/libc/src/math/setpayloadf128.h
index d3f357bc6c49fe..4e2737f86e6db5 100644
--- a/libc/src/math/setpayloadf128.h
+++ b/libc/src/math/setpayloadf128.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for setpayloadf128 ----------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implementation header for setpayloadf128.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_MATH_SETPAYLOADF128_H
 #define LLVM_LIBC_SRC_MATH_SETPAYLOADF128_H
diff --git a/libc/src/math/setpayloadsigf128.h b/libc/src/math/setpayloadsigf128.h
index 80bc58c4998184..729c7f701e9852 100644
--- a/libc/src/math/setpayloadsigf128.h
+++ b/libc/src/math/setpayloadsigf128.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for setpayloadsigf128 -------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implementation header for setpayloadsigf128.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_MATH_SETPAYLOADSIGF128_H
 #define LLVM_LIBC_SRC_MATH_SETPAYLOADSIGF128_H
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index cfae2a1ab48f51..ccde307e597a5e 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -612,6 +612,11 @@ TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
                                   Float128(0.0), Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::fminimum_numf128(
                                   Float128(0.0), Float128(0.0)));
+
+  Float128 getpayloadf128_x = Float128(0.0);
+  EXPECT_FP_EQ(Float128(-1.0),
+               LIBC_NAMESPACE::shared::getpayloadf128(&getpayloadf128_x));
+
   EXPECT_EQ(1, LIBC_NAMESPACE::shared::iscanonicalf128(Float128(0.0)));
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::isnanf128(Float128(0.0)));
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::issignalingf128(Float128(0.0)));
@@ -619,19 +624,15 @@ TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
   EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llroundf128(Float128(0.0)));
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lrintf128(Float128(0.0)));
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lroundf128(Float128(0.0)));
+
+  EXPECT_TRUE(FPBits(LIBC_NAMESPACE::shared::nanf128("")).is_nan());
+
   EXPECT_FP_EQ(Float128(0.0),
                LIBC_NAMESPACE::shared::nearbyintf128(Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::rintf128(Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0),
                LIBC_NAMESPACE::shared::roundevenf128(Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::roundf128(Float128(0.0)));
-  EXPECT_FP_EQ(Float128(1.0), LIBC_NAMESPACE::shared::sqrtf128(Float128(1.0)));
-  EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::truncf128(Float128(0.0)));
-  EXPECT_TRUE(FPBits(LIBC_NAMESPACE::shared::nanf128("")).is_nan());
-
-  Float128 getpayloadf128_x = Float128(0.0);
-  EXPECT_FP_EQ(Float128(-1.0),
-               LIBC_NAMESPACE::shared::getpayloadf128(&getpayloadf128_x));
 
   Float128 setpayloadf128_res = Float128(0.0);
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadf128(&setpayloadf128_res,
@@ -641,6 +642,9 @@ TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
   EXPECT_EQ(1, LIBC_NAMESPACE::shared::setpayloadsigf128(&setpayloadsigf128_res,
                                                          Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0), setpayloadsigf128_res);
+
+  EXPECT_FP_EQ(Float128(1.0), LIBC_NAMESPACE::shared::sqrtf128(Float128(1.0)));
+  EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::truncf128(Float128(0.0)));
 }
 
 #ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
diff --git a/libc/test/src/math/smoke/getpayloadf128_test.cpp b/libc/test/src/math/smoke/getpayloadf128_test.cpp
index 41af1066b11c71..3bd21762d62c55 100644
--- a/libc/test/src/math/smoke/getpayloadf128_test.cpp
+++ b/libc/test/src/math/smoke/getpayloadf128_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for getpayloadf128 --------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Unittests for getpayloadf128.
+///
+//===----------------------------------------------------------------------===//
 
 #include "GetPayloadTest.h"
 
diff --git a/libc/test/src/math/smoke/nanf128_test.cpp b/libc/test/src/math/smoke/nanf128_test.cpp
index 1b8438aea79b9f..bb866a50be3f95 100644
--- a/libc/test/src/math/smoke/nanf128_test.cpp
+++ b/libc/test/src/math/smoke/nanf128_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for nanf128 ---------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Unittests for nanf128.
+///
+//===----------------------------------------------------------------------===//
 
 #include "hdr/signal_macros.h"
 #include "src/__support/FPUtil/FPBits.h"
diff --git a/libc/test/src/math/smoke/setpayloadf128_test.cpp b/libc/test/src/math/smoke/setpayloadf128_test.cpp
index 0048827944be76..9c4e3b8b2b191a 100644
--- a/libc/test/src/math/smoke/setpayloadf128_test.cpp
+++ b/libc/test/src/math/smoke/setpayloadf128_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for setpayloadf128 --------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Unittests for setpayloadf128.
+///
+//===----------------------------------------------------------------------===//
 
 #include "SetPayloadTest.h"
 
diff --git a/libc/test/src/math/smoke/setpayloadsigf128_test.cpp b/libc/test/src/math/smoke/setpayloadsigf128_test.cpp
index 575573306de4ad..4f738a63b654b0 100644
--- a/libc/test/src/math/smoke/setpayloadsigf128_test.cpp
+++ b/libc/test/src/math/smoke/setpayloadsigf128_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for setpayloadsigf128 -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Unittests for setpayloadsigf128.
+///
+//===----------------------------------------------------------------------===//
 
 #include "SetPayloadSigTest.h"
 
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index 0fe103f73207fa..1a662985079057 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -1610,7 +1610,13 @@ math_test(
     hdrs = ["ModfTest.h"],
 )
 
-# TODO: add nan tests.
+math_test(
+    name = "nanf128",
+    deps = [
+        "//libc:__support_fputil_float128",
+        "//libc:hdr_signal_macros",
+    ],
+)
 
 math_test(
     name = "nearbyint",

>From 60990cb0b656f5fe31b5feaaf90bcce823503973 Mon Sep 17 00:00:00 2001
From: popie52 <popiesailor at gmail.com>
Date: Mon, 14 Sep 2026 18:46:15 +0530
Subject: [PATCH 6/8] [libc] Fix Bazel dependency for nanf128

---
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 1 +
 1 file changed, 1 insertion(+)

diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 2149fc68863dae..ca9140e6ad17cf 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -13954,6 +13954,7 @@ libc_math_function(
 libc_math_function(
     name = "nanf128",
     additional_deps = [
+        ":__support_cpp_bit",
         ":__support_fputil_float128",
         ":__support_math_nanf128",
     ],

>From a331f8bf2b84dd242b723493943931a3264788e0 Mon Sep 17 00:00:00 2001
From: popie52 <popiesailor at gmail.com>
Date: Mon, 14 Sep 2026 20:40:13 +0530
Subject: [PATCH 7/8] [libc] Fix review comments for emulated f128 NaN payload
 functions

---
 libc/config/windows/entrypoints.txt                 | 1 +
 libc/shared/math/getpayloadf128.h                   | 2 +-
 libc/shared/math/nanf128.h                          | 2 +-
 libc/shared/math/setpayloadf128.h                   | 2 +-
 libc/shared/math/setpayloadsigf128.h                | 2 +-
 libc/src/__support/math/getpayloadf128.h            | 2 +-
 libc/src/__support/math/nanf128.h                   | 2 +-
 libc/src/__support/math/setpayloadf128.h            | 2 +-
 libc/src/math/generic/getpayloadf128.cpp            | 2 +-
 libc/src/math/generic/nanf128.cpp                   | 2 +-
 libc/src/math/generic/setpayloadf128.cpp            | 2 +-
 libc/src/math/generic/setpayloadsigf128.cpp         | 2 +-
 libc/src/math/getpayloadf128.h                      | 2 +-
 libc/src/math/nanf128.h                             | 2 +-
 libc/src/math/setpayloadf128.h                      | 2 +-
 libc/src/math/setpayloadsigf128.h                   | 2 +-
 libc/test/src/math/smoke/getpayloadf128_test.cpp    | 2 +-
 libc/test/src/math/smoke/nanf128_test.cpp           | 4 ++--
 libc/test/src/math/smoke/setpayloadf128_test.cpp    | 2 +-
 libc/test/src/math/smoke/setpayloadsigf128_test.cpp | 2 +-
 20 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 8cc4feaf96cc41..257923af00e1f3 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -440,3 +440,4 @@ set(TARGET_LLVMLIBC_ENTRYPOINTS
   ${TARGET_LIBC_ENTRYPOINTS}
   ${TARGET_LIBM_ENTRYPOINTS}
 )
+
diff --git a/libc/shared/math/getpayloadf128.h b/libc/shared/math/getpayloadf128.h
index 6d4ffacac5581d..e1f2d0faedbcb2 100644
--- a/libc/shared/math/getpayloadf128.h
+++ b/libc/shared/math/getpayloadf128.h
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Shared getpayloadf128 function.
+/// Shared getpayloadf128 function.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/shared/math/nanf128.h b/libc/shared/math/nanf128.h
index 266a1ae46de618..9d80936c14c282 100644
--- a/libc/shared/math/nanf128.h
+++ b/libc/shared/math/nanf128.h
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Shared nanf128 function.
+/// Shared nanf128 function.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/shared/math/setpayloadf128.h b/libc/shared/math/setpayloadf128.h
index 7ecc1dac8e6131..ceb339e80ac4f7 100644
--- a/libc/shared/math/setpayloadf128.h
+++ b/libc/shared/math/setpayloadf128.h
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Shared setpayloadf128 function.
+/// Shared setpayloadf128 function.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/shared/math/setpayloadsigf128.h b/libc/shared/math/setpayloadsigf128.h
index 7038c3947cdb6e..92f17abd033a26 100644
--- a/libc/shared/math/setpayloadsigf128.h
+++ b/libc/shared/math/setpayloadsigf128.h
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Shared setpayloadsigf128 function.
+/// Shared setpayloadsigf128 function.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/src/__support/math/getpayloadf128.h b/libc/src/__support/math/getpayloadf128.h
index 1d8cd547962e48..b162f227b11cf6 100644
--- a/libc/src/__support/math/getpayloadf128.h
+++ b/libc/src/__support/math/getpayloadf128.h
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Implementation header for getpayloadf128.
+/// Implementation header for getpayloadf128.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/src/__support/math/nanf128.h b/libc/src/__support/math/nanf128.h
index 9ebf2ba1ed85bb..4aaad176059f9b 100644
--- a/libc/src/__support/math/nanf128.h
+++ b/libc/src/__support/math/nanf128.h
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Implementation header for nanf128.
+/// Implementation header for nanf128.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/src/__support/math/setpayloadf128.h b/libc/src/__support/math/setpayloadf128.h
index f97c11c64c0e4d..8feeef8b9fa9cc 100644
--- a/libc/src/__support/math/setpayloadf128.h
+++ b/libc/src/__support/math/setpayloadf128.h
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Implementation header for setpayloadf128.
+/// Implementation header for setpayloadf128.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/src/math/generic/getpayloadf128.cpp b/libc/src/math/generic/getpayloadf128.cpp
index 8f44a54aabbab5..f74d1529508fb5 100644
--- a/libc/src/math/generic/getpayloadf128.cpp
+++ b/libc/src/math/generic/getpayloadf128.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Implementation of getpayloadf128 function.
+/// Implementation of getpayloadf128 function.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/src/math/generic/nanf128.cpp b/libc/src/math/generic/nanf128.cpp
index 02d4fadd5a412d..6acf4fe8a08298 100644
--- a/libc/src/math/generic/nanf128.cpp
+++ b/libc/src/math/generic/nanf128.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Implementation of nanf128 function.
+/// Implementation of nanf128 function.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/src/math/generic/setpayloadf128.cpp b/libc/src/math/generic/setpayloadf128.cpp
index a25be192e9c36d..c8834261e58610 100644
--- a/libc/src/math/generic/setpayloadf128.cpp
+++ b/libc/src/math/generic/setpayloadf128.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Implementation of setpayloadf128 function.
+/// Implementation of setpayloadf128 function.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/src/math/generic/setpayloadsigf128.cpp b/libc/src/math/generic/setpayloadsigf128.cpp
index b08aa8487907dd..dd930ece97752e 100644
--- a/libc/src/math/generic/setpayloadsigf128.cpp
+++ b/libc/src/math/generic/setpayloadsigf128.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Implementation of setpayloadsigf128 function.
+/// Implementation of setpayloadsigf128 function.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/src/math/getpayloadf128.h b/libc/src/math/getpayloadf128.h
index 70adef8e23ce93..bed0870f74b95b 100644
--- a/libc/src/math/getpayloadf128.h
+++ b/libc/src/math/getpayloadf128.h
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Implementation header for getpayloadf128.
+/// Implementation header for getpayloadf128.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/src/math/nanf128.h b/libc/src/math/nanf128.h
index 354c021d39d343..13dc64c4d8afe5 100644
--- a/libc/src/math/nanf128.h
+++ b/libc/src/math/nanf128.h
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Implementation header for nanf128.
+/// Implementation header for nanf128.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/src/math/setpayloadf128.h b/libc/src/math/setpayloadf128.h
index 4e2737f86e6db5..4ade6153a29c55 100644
--- a/libc/src/math/setpayloadf128.h
+++ b/libc/src/math/setpayloadf128.h
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Implementation header for setpayloadf128.
+/// Implementation header for setpayloadf128.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/src/math/setpayloadsigf128.h b/libc/src/math/setpayloadsigf128.h
index 729c7f701e9852..eaf1a5d94dcead 100644
--- a/libc/src/math/setpayloadsigf128.h
+++ b/libc/src/math/setpayloadsigf128.h
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Implementation header for setpayloadsigf128.
+/// Implementation header for setpayloadsigf128.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/test/src/math/smoke/getpayloadf128_test.cpp b/libc/test/src/math/smoke/getpayloadf128_test.cpp
index 3bd21762d62c55..f6c7dddb5c3e2f 100644
--- a/libc/test/src/math/smoke/getpayloadf128_test.cpp
+++ b/libc/test/src/math/smoke/getpayloadf128_test.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Unittests for getpayloadf128.
+/// Unittests for getpayloadf128.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/test/src/math/smoke/nanf128_test.cpp b/libc/test/src/math/smoke/nanf128_test.cpp
index bb866a50be3f95..7c3fbafe2198ab 100644
--- a/libc/test/src/math/smoke/nanf128_test.cpp
+++ b/libc/test/src/math/smoke/nanf128_test.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Unittests for nanf128.
+/// Unittests for nanf128.
 ///
 //===----------------------------------------------------------------------===//
 
@@ -22,7 +22,7 @@
 
 #ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
 using float128 = LIBC_NAMESPACE::fputil::Float128;
-#endif
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
 
 class LlvmLibcNanf128Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 public:
diff --git a/libc/test/src/math/smoke/setpayloadf128_test.cpp b/libc/test/src/math/smoke/setpayloadf128_test.cpp
index 9c4e3b8b2b191a..c9f58b7f4cce38 100644
--- a/libc/test/src/math/smoke/setpayloadf128_test.cpp
+++ b/libc/test/src/math/smoke/setpayloadf128_test.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Unittests for setpayloadf128.
+/// Unittests for setpayloadf128.
 ///
 //===----------------------------------------------------------------------===//
 
diff --git a/libc/test/src/math/smoke/setpayloadsigf128_test.cpp b/libc/test/src/math/smoke/setpayloadsigf128_test.cpp
index 4f738a63b654b0..c623b45b4c3903 100644
--- a/libc/test/src/math/smoke/setpayloadsigf128_test.cpp
+++ b/libc/test/src/math/smoke/setpayloadsigf128_test.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief Unittests for setpayloadsigf128.
+/// Unittests for setpayloadsigf128.
 ///
 //===----------------------------------------------------------------------===//
 

>From c3259156f8d37c796f01fed33633173ebc21c765 Mon Sep 17 00:00:00 2001
From: popie52 <popiesailor at gmail.com>
Date: Tue, 15 Sep 2026 07:03:56 +0530
Subject: [PATCH 8/8] [libc] Make setpayloadsigf128 constexpr

---
 libc/test/shared/shared_math_constexpr_test.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 74eb4293f93320..9220d6e4a9d99c 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -465,6 +465,11 @@ static_assert(0 == [] {
   Float128 setpayload_x = Float128(0.0);
   return LIBC_NAMESPACE::shared::setpayloadf128(&setpayload_x, Float128(0.0));
 }());
+static_assert(1 == [] {
+  Float128 setpayloadsigf128_x = Float128(0.0);
+  return LIBC_NAMESPACE::shared::setpayloadsigf128(&setpayloadsigf128_x,
+                                                   Float128(0.0));
+}());
 
 //===----------------------------------------------------------------------===//
 //                       Native Float128 Tests



More information about the libc-commits mailing list