[llvm-branch-commits] [libc] [llvm] [libc] Make remainder functions use the emulated float128 type (PR #217578)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Sep 4 06:34:59 PDT 2026


https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/217578

>From 0e3d1021142b99c162315e786867769f259e539f Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 4 Sep 2026 18:43:24 +0530
Subject: [PATCH 1/2] intial commit

---
 libc/config/baremetal/aarch64/entrypoints.txt       |  4 ++--
 libc/config/baremetal/arm/entrypoints.txt           |  4 ++--
 libc/config/baremetal/riscv/entrypoints.txt         |  4 ++--
 libc/config/darwin/aarch64/entrypoints.txt          |  4 ++--
 libc/config/darwin/x86_64/entrypoints.txt           |  2 ++
 libc/config/freebsd/x86_64/entrypoints.txt          |  4 ++--
 libc/config/gpu/amdgpu/entrypoints.txt              |  2 ++
 libc/config/gpu/nvptx/entrypoints.txt               |  2 ++
 libc/config/linux/aarch64/entrypoints.txt           |  4 ++--
 libc/config/linux/arm/entrypoints.txt               |  2 ++
 libc/config/linux/riscv/entrypoints.txt             |  4 ++--
 libc/config/linux/x86_64/entrypoints.txt            |  4 ++--
 libc/config/windows/entrypoints.txt                 |  2 ++
 libc/shared/math/fmodf128.h                         |  6 ------
 libc/shared/math/remainderf128.h                    |  6 ------
 libc/src/__support/math/CMakeLists.txt              |  4 ++--
 libc/src/__support/math/fmodf128.h                  | 13 +++++--------
 libc/src/__support/math/remainderf128.h             | 11 ++++-------
 libc/src/math/fmodf128.h                            |  5 +++++
 libc/src/math/generic/CMakeLists.txt                |  2 ++
 libc/src/math/generic/fmodf128.cpp                  |  6 +++++-
 libc/src/math/generic/remainderf128.cpp             |  6 +++++-
 libc/src/math/remainderf128.h                       |  5 +++++
 libc/test/shared/shared_math_constexpr_test.cpp     | 10 +++++-----
 libc/test/shared/shared_math_test.cpp               |  6 +++---
 libc/test/src/math/smoke/CMakeLists.txt             |  3 ++-
 libc/test/src/math/smoke/fmodf128_test.cpp          |  5 +++++
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel   |  8 ++++++--
 .../libc/test/src/math/smoke/BUILD.bazel            |  3 +++
 29 files changed, 83 insertions(+), 58 deletions(-)

diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 66911050bbf4a..a00a7c5548ad0 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -463,6 +463,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fminl
     libc.src.math.fmod
     libc.src.math.fmodf
+    libc.src.math.fmodf128
     libc.src.math.fmodl
     libc.src.math.fmul
     libc.src.math.fmull
@@ -562,6 +563,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.powf
     libc.src.math.remainder
     libc.src.math.remainderf
+    libc.src.math.remainderf128
     libc.src.math.remainderl
     libc.src.math.remquo
     libc.src.math.remquof
@@ -773,7 +775,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.faddf128
     libc.src.math.fdivf128
     libc.src.math.ffmaf128
-    libc.src.math.fmodf128
     libc.src.math.fmulf128
     libc.src.math.frexpf128
     libc.src.math.fromfpf128
@@ -787,7 +788,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index ef01c5a9e07fb..a922cde401214 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -475,6 +475,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fminl
     libc.src.math.fmod
     libc.src.math.fmodf
+    libc.src.math.fmodf128
     libc.src.math.fmodl
     libc.src.math.fmul
     libc.src.math.fmull
@@ -574,6 +575,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.powf
     libc.src.math.remainder
     libc.src.math.remainderf
+    libc.src.math.remainderf128
     libc.src.math.remainderl
     libc.src.math.remquo
     libc.src.math.remquof
@@ -784,7 +786,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.faddf128
     libc.src.math.fdivf128
     libc.src.math.ffmaf128
-    libc.src.math.fmodf128
     libc.src.math.fmulf128
     libc.src.math.frexpf128
     libc.src.math.fromfpf128
@@ -798,7 +799,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 3313ac9b6be4c..8c87a84b0ac68 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -472,6 +472,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fmod
     libc.src.math.fmodf
     # libc.src.math.fmodl
+    libc.src.math.fmodf128
     libc.src.math.fmul
     libc.src.math.fmull
     libc.src.math.frexp
@@ -570,6 +571,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.powf
     libc.src.math.remainder
     libc.src.math.remainderf
+    libc.src.math.remainderf128
     libc.src.math.remainderl
     libc.src.math.remquo
     libc.src.math.remquof
@@ -781,7 +783,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.faddf128
     libc.src.math.fdivf128
     libc.src.math.ffmaf128
-    # libc.src.math.fmodf128
     libc.src.math.fmulf128
     libc.src.math.frexpf128
     libc.src.math.fromfpf128
@@ -795,7 +796,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index a7b95b744e960..22ab2bbaa7ce6 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -282,6 +282,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fminl
     libc.src.math.fmod
     libc.src.math.fmodf
+    libc.src.math.fmodf128
     libc.src.math.fmodl
     libc.src.math.fmul
     libc.src.math.fmull
@@ -381,6 +382,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.powf
     libc.src.math.remainder
     libc.src.math.remainderf
+    libc.src.math.remainderf128
     libc.src.math.remainderl
     libc.src.math.remquo
     libc.src.math.remquof
@@ -593,7 +595,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.faddf128
     libc.src.math.fdivf128
     libc.src.math.ffmaf128
-    libc.src.math.fmodf128
     libc.src.math.fmulf128
     libc.src.math.frexpf128
     libc.src.math.fromfpf128
@@ -607,7 +608,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 3e38ac38b3791..046c4bd4f7cf0 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -174,6 +174,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     #libc.src.math.fminl
     #libc.src.math.fmod
     #libc.src.math.fmodf
+    #libc.src.math.fmodf128
     #libc.src.math.frexp
     #libc.src.math.frexpf
     #libc.src.math.frexpl
@@ -234,6 +235,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     #libc.src.math.nextupf128
     #libc.src.math.remainderf
     #libc.src.math.remainder
+    #libc.src.math.remainderf128
     #libc.src.math.remainderl
     #libc.src.math.remquof
     #libc.src.math.remquo
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index f242f02e63125..175e32d77b434 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -214,6 +214,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fminimum_mag_num
     libc.src.math.fminimum_mag_numf
     libc.src.math.fminimum_mag_numl
+    libc.src.math.fmodf128
     libc.src.math.fmul
     libc.src.math.fmod
     libc.src.math.fmodf
@@ -285,6 +286,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.powf
     libc.src.math.remainderf
     libc.src.math.remainder
+    libc.src.math.remainderf128
     libc.src.math.remainderl
     libc.src.math.remquof
     libc.src.math.remquo
@@ -533,7 +535,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.faddf128
     libc.src.math.fdivf128
     libc.src.math.ffmaf128
-    libc.src.math.fmodf128
     libc.src.math.fmulf128
     libc.src.math.frexpf128
     libc.src.math.fromfpf128
@@ -547,7 +548,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index c28eab98db184..37deee09143f7 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -410,6 +410,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fminl
     libc.src.math.fmod
     libc.src.math.fmodf
+    libc.src.math.fmodf128
     libc.src.math.fmodl
     libc.src.math.fmul
     libc.src.math.fmull
@@ -505,6 +506,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.powf
     libc.src.math.remainder
     libc.src.math.remainderf
+    libc.src.math.remainderf128
     libc.src.math.remainderl
     libc.src.math.remquo
     libc.src.math.remquof
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 3dd0cebb4aaa7..99adce8d28962 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -406,6 +406,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fminl
     libc.src.math.fmod
     libc.src.math.fmodf
+    libc.src.math.fmodf128
     libc.src.math.fmodl
     libc.src.math.fmul
     libc.src.math.fmull
@@ -502,6 +503,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.powf
     libc.src.math.remainder
     libc.src.math.remainderf
+    libc.src.math.remainderf128
     libc.src.math.remainderl
     libc.src.math.remquo
     libc.src.math.remquof
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 54825e1d2428d..3168157fa3241 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -643,6 +643,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fminl
     libc.src.math.fmod
     libc.src.math.fmodf
+    libc.src.math.fmodf128
     libc.src.math.fmodl
     libc.src.math.fmul
     libc.src.math.fmull
@@ -742,6 +743,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.powf
     libc.src.math.remainder
     libc.src.math.remainderf
+    libc.src.math.remainderf128
     libc.src.math.remainderl
     libc.src.math.remquo
     libc.src.math.remquof
@@ -947,7 +949,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.faddf128
     libc.src.math.fdivf128
     libc.src.math.ffmaf128
-    libc.src.math.fmodf128
     libc.src.math.fmulf128
     libc.src.math.frexpf128
     libc.src.math.fromfpf128
@@ -961,7 +962,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 5a91d1569a2d8..23e00ff67d7e2 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -468,6 +468,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fminl
     libc.src.math.fmod
     libc.src.math.fmodf
+    libc.src.math.fmodf128
     libc.src.math.fmul
     libc.src.math.frexp
     libc.src.math.frexpf
@@ -554,6 +555,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.powf
     libc.src.math.remainder
     libc.src.math.remainderf
+    libc.src.math.remainderf128
     libc.src.math.remainderl
     libc.src.math.remquo
     libc.src.math.remquof
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 590f64bae3aa3..9da18d581519b 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -712,6 +712,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fminl
     libc.src.math.fmod
     libc.src.math.fmodf
+    libc.src.math.fmodf128
     libc.src.math.fmodl
     libc.src.math.fmul
     libc.src.math.fmull
@@ -811,6 +812,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.powf
     libc.src.math.remainder
     libc.src.math.remainderf
+    libc.src.math.remainderf128
     libc.src.math.remainderl
     libc.src.math.remquo
     libc.src.math.remquof
@@ -1033,7 +1035,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.faddf128
     libc.src.math.fdivf128
     libc.src.math.ffmaf128
-    libc.src.math.fmodf128
     libc.src.math.fmulf128
     libc.src.math.frexpf128
     libc.src.math.fromfpf128
@@ -1047,7 +1048,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 6cb5144f95fbb..9f0a5fc6736b6 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -721,6 +721,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fminl
     libc.src.math.fmod
     libc.src.math.fmodf
+    libc.src.math.fmodf128
     libc.src.math.fmodl
     libc.src.math.fmul
     libc.src.math.fmull
@@ -820,6 +821,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.powf
     libc.src.math.remainder
     libc.src.math.remainderf
+    libc.src.math.remainderf128
     libc.src.math.remainderl
     libc.src.math.remquo
     libc.src.math.remquof
@@ -1042,7 +1044,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.faddf128
     libc.src.math.fdivf128
     libc.src.math.ffmaf128
-    libc.src.math.fmodf128
     libc.src.math.fmulf128
     libc.src.math.frexpf128
     libc.src.math.fromfpf128
@@ -1056,7 +1057,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
     libc.src.math.scalbnf128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 9549c1485c831..9a57d3f5bd108 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -247,6 +247,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fminimum_mag_num
     libc.src.math.fminimum_mag_numf
     libc.src.math.fminimum_mag_numl
+    libc.src.math.fmodf128
     libc.src.math.fmul
     libc.src.math.fmod
     libc.src.math.fmodf
@@ -318,6 +319,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.powf
     libc.src.math.remainderf
     libc.src.math.remainder
+    libc.src.math.remainderf128
     libc.src.math.remainderl
     libc.src.math.remquof
     libc.src.math.remquo
diff --git a/libc/shared/math/fmodf128.h b/libc/shared/math/fmodf128.h
index 0000893546763..97bee8e09dca8 100644
--- a/libc/shared/math/fmodf128.h
+++ b/libc/shared/math/fmodf128.h
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_FMODF128_H
 #define LLVM_LIBC_SHARED_MATH_FMODF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/fmodf128.h"
 
@@ -24,6 +20,4 @@ using math::fmodf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_FMODF128_H
diff --git a/libc/shared/math/remainderf128.h b/libc/shared/math/remainderf128.h
index b1d02de64c20b..d0d598c0c9c73 100644
--- a/libc/shared/math/remainderf128.h
+++ b/libc/shared/math/remainderf128.h
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_REMAINDERF128_H
 #define LLVM_LIBC_SHARED_MATH_REMAINDERF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/remainderf128.h"
 
@@ -24,6 +20,4 @@ using math::remainderf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_REMAINDERF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index b80c67cb0848d..7e7ba7c6da043 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1426,7 +1426,7 @@ add_header_library(
   HDRS
     fmodf128.h
   DEPENDS
-    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.generic.fmod
     libc.src.__support.macros.config
 )
@@ -2298,8 +2298,8 @@ add_header_library(
   HDRS
     remainderf128.h
   DEPENDS
-    libc.include.llvm-libc-types.float128
     libc.src.__support.FPUtil.division_and_remainder_operations
+    libc.src.__support.FPUtil.float128
     libc.src.__support.macros.config
 )
 
diff --git a/libc/src/__support/math/fmodf128.h b/libc/src/__support/math/fmodf128.h
index 7ed105b81af48..5a1b29c1997bc 100644
--- a/libc/src/__support/math/fmodf128.h
+++ b/libc/src/__support/math/fmodf128.h
@@ -9,23 +9,20 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMODF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_FMODF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/FPUtil/generic/FMod.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE constexpr float128 fmodf128(float128 x, float128 y) {
-  return fputil::generic::FMod<float128>::eval(x, y);
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr Float128 fmodf128(Float128 x, Float128 y) {
+  return fputil::generic::FMod<Float128>::eval(x, y);
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMODF128_H
diff --git a/libc/src/__support/math/remainderf128.h b/libc/src/__support/math/remainderf128.h
index cd3ed15a7b1a2..3ef5d7e365caf 100644
--- a/libc/src/__support/math/remainderf128.h
+++ b/libc/src/__support/math/remainderf128.h
@@ -9,17 +9,16 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_REMAINDERF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_REMAINDERF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "src/__support/FPUtil/DivisionAndRemainderOperations.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE constexpr float128 remainderf128(float128 x, float128 y) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr Float128 remainderf128(Float128 x, Float128 y) {
   int quotient{};
   return fputil::remquo(x, y, quotient);
 }
@@ -27,6 +26,4 @@ LIBC_INLINE constexpr float128 remainderf128(float128 x, float128 y) {
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_REMAINDERF128_H
diff --git a/libc/src/math/fmodf128.h b/libc/src/math/fmodf128.h
index 908fc61a19497..4e18c34c5a83b 100644
--- a/libc/src/math/fmodf128.h
+++ b/libc/src/math/fmodf128.h
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_FMODF128_H
 #define LLVM_LIBC_SRC_MATH_FMODF128_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 fmodf128(float128 x, float128 y);
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 74f1c859d096b..3e2d2835eb3f4 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2854,6 +2854,7 @@ add_entrypoint_object(
   HDRS
     ../remainderf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.remainderf128
 )
 
@@ -3475,6 +3476,7 @@ add_entrypoint_object(
   HDRS
     ../fmodf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.fmodf128
 )
 
diff --git a/libc/src/math/generic/fmodf128.cpp b/libc/src/math/generic/fmodf128.cpp
index c72ec7ec1cdf5..fb22a165b2aa8 100644
--- a/libc/src/math/generic/fmodf128.cpp
+++ b/libc/src/math/generic/fmodf128.cpp
@@ -7,12 +7,16 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmodf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/fmodf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(float128, fmodf128, (float128 x, float128 y)) {
-  return math::fmodf128(x, y);
+  return cpp::bit_cast<float128>(
+      math::fmodf128(cpp::bit_cast<Float128>(x), cpp::bit_cast<Float128>(y)));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/remainderf128.cpp b/libc/src/math/generic/remainderf128.cpp
index 072d19737d382..47b265bb2f47c 100644
--- a/libc/src/math/generic/remainderf128.cpp
+++ b/libc/src/math/generic/remainderf128.cpp
@@ -7,12 +7,16 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/remainderf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/remainderf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(float128, remainderf128, (float128 x, float128 y)) {
-  return math::remainderf128(x, y);
+  return cpp::bit_cast<float128>(math::remainderf128(
+      cpp::bit_cast<Float128>(x), cpp::bit_cast<Float128>(y)));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/remainderf128.h b/libc/src/math/remainderf128.h
index 57f770a853d68..8f0e763a2d1ab 100644
--- a/libc/src/math/remainderf128.h
+++ b/libc/src/math/remainderf128.h
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_REMAINDERF128_H
 #define LLVM_LIBC_SRC_MATH_REMAINDERF128_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 remainderf128(float128 x, float128 y);
 
 } // 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 775a7fd001f0f..abdd31474dcaf 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -419,6 +419,8 @@ static_assert(Float128(0.0) ==
 static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::fminimum_numf128(Float128(0.0),
                                                        Float128(0.0)));
+static_assert(0 ==
+              LIBC_NAMESPACE::shared::fmodf128(Float128(4.0), Float128(2.0)));
 static_assert(1 == LIBC_NAMESPACE::shared::iscanonicalf128(Float128(0.0)));
 static_assert(0 == LIBC_NAMESPACE::shared::isnanf128(Float128(0.0)));
 static_assert(0.0 == LIBC_NAMESPACE::shared::issignalingf128(Float128(0.0)));
@@ -438,6 +440,9 @@ static_assert(LIBC_NAMESPACE::fputil::FPBits<Float128>::min_subnormal(
 static_assert(
     LIBC_NAMESPACE::fputil::FPBits<Float128>::min_subnormal().get_val() ==
     LIBC_NAMESPACE::shared::nextupf128(Float128(0.0)));
+static_assert(float128(0.0) ==
+              LIBC_NAMESPACE::shared::remainderf128(Float128(1.0),
+                                                    Float128(1.0)));
 static_assert(Float128(0.0) == LIBC_NAMESPACE::shared::rintf128(Float128(0.0)));
 static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::roundevenf128(Float128(0.0)));
@@ -488,15 +493,10 @@ constexpr float128 TOTALORDERMAGF128_Y = float128(0.0);
 static_assert(1 ==
               LIBC_NAMESPACE::shared::totalordermagf128(&TOTALORDERMAGF128_X,
                                                         &TOTALORDERMAGF128_Y));
-static_assert(0 ==
-              LIBC_NAMESPACE::shared::fmodf128(float128(4.0), float128(2.0)));
 static_assert(float128(0.0) == [] {
   float128 iptr{};
   return LIBC_NAMESPACE::shared::modff128(float128(0.0), &iptr);
 }());
-static_assert(float128(0.0) ==
-              LIBC_NAMESPACE::shared::remainderf128(float128(1.0),
-                                                    float128(1.0)));
 static_assert(float128(0.0) == [] {
   int exp{};
   return LIBC_NAMESPACE::shared::remquof128(float128(1.0), float128(1.0), &exp);
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index fe3c4f5b4abbd..2f17d1090d596 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -587,6 +587,7 @@ TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
   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)));
+  LIBC_NAMESPACE::shared::fmodf128(Float128(1.0), Float128(1.0));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::copysignf128(
                                   Float128(0.0), Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::fabsf128(Float128(0.0)));
@@ -627,6 +628,8 @@ TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
   EXPECT_FP_EQ(neg_min_denormal,
                LIBC_NAMESPACE::shared::nextdownf128(Float128(0.0)));
   EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupf128(Float128(0.0)));
+  EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::remainderf128(
+                                  Float128(1.0), Float128(1.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)));
@@ -737,13 +740,10 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   float128 totalordermagf128_y = float128(0.0);
   EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermagf128(&totalordermagf128_x,
                                                          &totalordermagf128_y));
-  LIBC_NAMESPACE::shared::fmodf128(float128(1.0), float128(1.0));
   float128 modff128_iptr = float128(0.0);
   EXPECT_FP_EQ(float128(0.0),
                LIBC_NAMESPACE::shared::modff128(float128(0.0), &modff128_iptr));
   EXPECT_FP_EQ(float128(0.0), modff128_iptr);
-  EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::remainderf128(
-                                  float128(1.0), float128(1.0)));
   int remquof128_exp = 0;
   EXPECT_FP_EQ(float128(0.0),
                LIBC_NAMESPACE::shared::remquof128(float128(1.0), float128(1.0),
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index d8d9644439983..05b4b830b5c25 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4704,10 +4704,11 @@ add_fp_unittest(
   HDRS
     FModTest.h
   DEPENDS
+    libc.src.math.fmodf128
     libc.hdr.errno_macros
     libc.hdr.fenv_macros
-    libc.src.math.fmodf128
     libc.src.__support.FPUtil.fenv_impl
+    libc.src.__support.FPUtil.float128
   # FIXME: Currently fails on the GPU build.
 )
 
diff --git a/libc/test/src/math/smoke/fmodf128_test.cpp b/libc/test/src/math/smoke/fmodf128_test.cpp
index f75aadac84386..5d9dcf9370378 100644
--- a/libc/test/src/math/smoke/fmodf128_test.cpp
+++ b/libc/test/src/math/smoke/fmodf128_test.cpp
@@ -8,6 +8,11 @@
 
 #include "FModTest.h"
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/math/fmodf128.h"
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 LIST_FMOD_TESTS(float128, LIBC_NAMESPACE::fmodf128)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 4b8374bcc62ba..14a3eefef9a1b 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -5973,9 +5973,9 @@ libc_support_library(
     name = "__support_math_fmodf128",
     hdrs = ["src/__support/math/fmodf128.h"],
     deps = [
+        ":__support_fputil_float128",
         ":__support_fputil_generic_fmod",
         ":__support_macros_config",
-        ":llvm_libc_types_float128",
     ],
 )
 
@@ -6836,8 +6836,8 @@ libc_support_library(
     hdrs = ["src/__support/math/remainderf128.h"],
     deps = [
         ":__support_fputil_division_and_remainder_operations",
+        ":__support_fputil_float128",
         ":__support_macros_config",
-        ":llvm_libc_types_float128",
     ],
 )
 
@@ -12301,6 +12301,8 @@ libc_math_function(
 libc_math_function(
     name = "fmodf128",
     additional_deps = [
+        ":__support_cpp_bit",
+        ":__support_fputil_float128",
         ":__support_math_fmodf128",
     ],
 )
@@ -13304,6 +13306,8 @@ libc_math_function(
 libc_math_function(
     name = "remainderf128",
     additional_deps = [
+        ":__support_cpp_bit",
+        ":__support_fputil_float128",
         ":__support_math_remainderf128",
     ],
 )
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 8c47fb7858e49..7ebd4955198cb 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
@@ -839,6 +839,9 @@ math_test(
 math_test(
     name = "fmodf128",
     hdrs = ["FModTest.h"],
+    deps = [
+        "//libc:__support_fputil_float128",
+    ],
 )
 
 math_test(

>From 7b3777b818c0991b375df1bde579d6a3ae69a0d0 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 4 Sep 2026 19:04:38 +0530
Subject: [PATCH 2/2] fix missing test enabling for fmodf128

---
 libc/test/shared/shared_math_constexpr_test.cpp | 2 +-
 libc/test/shared/shared_math_test.cpp           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index abdd31474dcaf..1e92903ad8859 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -419,7 +419,7 @@ static_assert(Float128(0.0) ==
 static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::fminimum_numf128(Float128(0.0),
                                                        Float128(0.0)));
-static_assert(0 ==
+static_assert(Float128(0) ==
               LIBC_NAMESPACE::shared::fmodf128(Float128(4.0), Float128(2.0)));
 static_assert(1 == LIBC_NAMESPACE::shared::iscanonicalf128(Float128(0.0)));
 static_assert(0 == LIBC_NAMESPACE::shared::isnanf128(Float128(0.0)));
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 2f17d1090d596..5f5db4fb8b5e0 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -587,7 +587,7 @@ TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
   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)));
-  LIBC_NAMESPACE::shared::fmodf128(Float128(1.0), Float128(1.0));
+  EXPECT_FP_EQ(Float128(0),LIBC_NAMESPACE::shared::fmodf128(Float128(1.0), Float128(1.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::copysignf128(
                                   Float128(0.0), Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::fabsf128(Float128(0.0)));



More information about the llvm-branch-commits mailing list