[libc] [llvm] fix frexpf128 build failure (PR #148332)

Muhammad Bassiouni via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 11 20:17:44 PDT 2025


https://github.com/bassiounix created https://github.com/llvm/llvm-project/pull/148332

@lntue 

>From 6e911b83561bdc3dfb55ca5fa0e026e30801cae1 Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Wed, 9 Jul 2025 23:32:52 +0300
Subject: [PATCH 1/5] [libc][math] Refactor frexpf128 implementation to
 header-only in src/__support/math folder.

---
 libc/shared/math.h                            |  1 +
 libc/shared/math/frexpf128.h                  | 30 ++++++++++++++++
 libc/src/__support/math/CMakeLists.txt        |  9 +++++
 libc/src/__support/math/frexpf128.h           | 36 +++++++++++++++++++
 libc/src/math/generic/CMakeLists.txt          |  3 +-
 libc/src/math/generic/frexpf128.cpp           |  7 ++--
 .../llvm-project-overlay/libc/BUILD.bazel     | 10 ++++++
 7 files changed, 90 insertions(+), 6 deletions(-)
 create mode 100644 libc/shared/math/frexpf128.h
 create mode 100644 libc/src/__support/math/frexpf128.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 9db53b69041d0..d42b8d60a117e 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -13,5 +13,6 @@
 
 #include "math/expf.h"
 #include "math/expf16.h"
+#include "math/frexpf128.h"
 
 #endif // LLVM_LIBC_SHARED_MATH_H
diff --git a/libc/shared/math/frexpf128.h b/libc/shared/math/frexpf128.h
new file mode 100644
index 0000000000000..0eea36e32ede1
--- /dev/null
+++ b/libc/shared/math/frexpf128.h
@@ -0,0 +1,30 @@
+//===-- Shared frexpf128 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_FREXPF128_H
+#define LLVM_LIBC_SHARED_MATH_FREXPF128_H
+
+#include "include/llvm-libc-types/float128.h"
+#include "shared/libc_common.h"
+#include "src/__support/macros/properties/complex_types.h"
+
+#ifndef LIBC_TYPES_HAS_FLOAT128
+#error unsupported
+#endif
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::frexpf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_FREXPF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 4c73fba6613fa..0090a0e12f7f4 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -55,3 +55,12 @@ add_header_library(
     libc.src.__support.macros.optimization
     libc.include.llvm-libc-macros.float16_macros
 )
+
+add_header_library(
+  frexpf128
+  HDRS
+    frexpf128.h
+  DEPENDS
+    libc.src.__support.macros.properties.types
+    libc.src.__support.FPUtil.manipulation_functions
+)
diff --git a/libc/src/__support/math/frexpf128.h b/libc/src/__support/math/frexpf128.h
new file mode 100644
index 0000000000000..795155f556602
--- /dev/null
+++ b/libc/src/__support/math/frexpf128.h
@@ -0,0 +1,36 @@
+//===-- Implementation header for expf --------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FREXPF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FREXPF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifndef LIBC_TYPES_HAS_FLOAT128
+#error unsupported
+#else
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+static constexpr float128 frexpf128(float128 x, int *exp) {
+  return fputil::frexp(x, *exp);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FREXPF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 6c3f28f423c7b..ff20dfaa898ca 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1775,8 +1775,7 @@ add_entrypoint_object(
   HDRS
     ../frexpf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.frexpf128
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/frexpf128.cpp b/libc/src/math/generic/frexpf128.cpp
index eb816c4769707..55f7afcf4aea5 100644
--- a/libc/src/math/generic/frexpf128.cpp
+++ b/libc/src/math/generic/frexpf128.cpp
@@ -7,14 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/frexpf128.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+
+#include "src/__support/math/frexpf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float128, frexpf128, (float128 x, int *exp)) {
-  return fputil::frexp(x, *exp);
+  return math::frexpf128(x, exp);
 }
 
 } // 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 d259f391069a4..6f9c85a8dbe9e 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2149,6 +2149,15 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_frexpf128",
+    hdrs = ["src/__support/math/frexpf128.h"],
+    deps = [
+        ":__support_macros_properties_types",
+        ":__support_fputil_manipulation_functions",
+    ],
+)
+
 ############################### complex targets ################################
 
 libc_function(
@@ -2747,6 +2756,7 @@ libc_math_function(
     name = "expf",
     additional_deps = [
         ":__support_math_expf",
+        ":__support_math_frexpf128",
         ":errno",
     ],
 )

>From 08b1592e435fc860065bc4d26068120c0ce4cd5f Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Thu, 10 Jul 2025 06:38:46 +0300
Subject: [PATCH 2/5] fix f128 check

---
 libc/shared/math/frexpf128.h                      | 7 +++----
 libc/src/__support/math/frexpf128.h               | 4 +---
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 8 ++++++--
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/libc/shared/math/frexpf128.h b/libc/shared/math/frexpf128.h
index 0eea36e32ede1..29d657d747348 100644
--- a/libc/shared/math/frexpf128.h
+++ b/libc/shared/math/frexpf128.h
@@ -10,13 +10,12 @@
 #define LLVM_LIBC_SHARED_MATH_FREXPF128_H
 
 #include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
 #include "shared/libc_common.h"
 #include "src/__support/macros/properties/complex_types.h"
 
-#ifndef LIBC_TYPES_HAS_FLOAT128
-#error unsupported
-#endif
-
 namespace LIBC_NAMESPACE_DECL {
 namespace shared {
 
diff --git a/libc/src/__support/math/frexpf128.h b/libc/src/__support/math/frexpf128.h
index 795155f556602..2fd5bc4318e28 100644
--- a/libc/src/__support/math/frexpf128.h
+++ b/libc/src/__support/math/frexpf128.h
@@ -11,9 +11,7 @@
 
 #include "include/llvm-libc-types/float128.h"
 
-#ifndef LIBC_TYPES_HAS_FLOAT128
-#error unsupported
-#else
+#ifdef LIBC_TYPES_HAS_FLOAT128
 
 #include "src/__support/FPUtil/ManipulationFunctions.h"
 #include "src/__support/common.h"
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 6f9c85a8dbe9e..e3b87e3b0527d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2756,7 +2756,6 @@ libc_math_function(
     name = "expf",
     additional_deps = [
         ":__support_math_expf",
-        ":__support_math_frexpf128",
         ":errno",
     ],
 )
@@ -3210,7 +3209,12 @@ libc_math_function(name = "frexpf")
 
 libc_math_function(name = "frexpl")
 
-libc_math_function(name = "frexpf128")
+libc_math_function(
+    name = "frexpf128",
+    additional_deps = [
+        ":__support_math_frexpf128",
+    ]
+)
 
 libc_math_function(name = "frexpf16")
 

>From efb6a282e49e9e5ab79dbfe8ac31ba2c8b68e25f Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Sat, 12 Jul 2025 05:24:05 +0300
Subject: [PATCH 3/5] remove unused include

---
 libc/shared/math/frexpf128.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libc/shared/math/frexpf128.h b/libc/shared/math/frexpf128.h
index 29d657d747348..14554c7cb33a8 100644
--- a/libc/shared/math/frexpf128.h
+++ b/libc/shared/math/frexpf128.h
@@ -14,7 +14,6 @@
 #ifdef LIBC_TYPES_HAS_FLOAT128
 
 #include "shared/libc_common.h"
-#include "src/__support/macros/properties/complex_types.h"
 
 namespace LIBC_NAMESPACE_DECL {
 namespace shared {

>From adce347094be822449a0356cd24540623657ea86 Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Sat, 12 Jul 2025 06:13:56 +0300
Subject: [PATCH 4/5] fix missing import

---
 libc/shared/math/frexpf128.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libc/shared/math/frexpf128.h b/libc/shared/math/frexpf128.h
index 14554c7cb33a8..6b922bd731295 100644
--- a/libc/shared/math/frexpf128.h
+++ b/libc/shared/math/frexpf128.h
@@ -14,6 +14,7 @@
 #ifdef LIBC_TYPES_HAS_FLOAT128
 
 #include "shared/libc_common.h"
+#include "src/__support/math/frexpf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 namespace shared {

>From 77a9d21dd7d54e8eb8414dfbb86266ff66c60d85 Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Sat, 12 Jul 2025 06:16:30 +0300
Subject: [PATCH 5/5] make fputil::frexp constexpr

---
 libc/src/__support/FPUtil/ManipulationFunctions.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/__support/FPUtil/ManipulationFunctions.h b/libc/src/__support/FPUtil/ManipulationFunctions.h
index 9c10011ccd203..ea9ee5a57c36d 100644
--- a/libc/src/__support/FPUtil/ManipulationFunctions.h
+++ b/libc/src/__support/FPUtil/ManipulationFunctions.h
@@ -29,7 +29,7 @@ namespace LIBC_NAMESPACE_DECL {
 namespace fputil {
 
 template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
-LIBC_INLINE T frexp(T x, int &exp) {
+LIBC_INLINE constexpr T frexp(T x, int &exp) {
   FPBits<T> bits(x);
   if (bits.is_inf_or_nan()) {
 #ifdef LIBC_FREXP_INF_NAN_EXPONENT



More information about the llvm-commits mailing list