[libc-commits] [libc] [llvm] [libc][math] Refactor f16sqrtf128 to Header Only. (PR #183542)

via libc-commits libc-commits at lists.llvm.org
Thu Feb 26 06:59:37 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Zorojuro (Sukumarsawant)

<details>
<summary>Changes</summary>

closes 
part of 

---
Full diff: https://github.com/llvm/llvm-project/pull/183542.diff


9 Files Affected:

- (modified) libc/shared/math.h (+1) 
- (added) libc/shared/math/f16sqrtf128.h (+32) 
- (modified) libc/src/__support/math/CMakeLists.txt (+12) 
- (added) libc/src/__support/math/f16sqrtf128.h (+35) 
- (modified) libc/src/math/generic/CMakeLists.txt (+1-2) 
- (modified) libc/src/math/generic/f16sqrtf128.cpp (+2-4) 
- (modified) libc/test/shared/CMakeLists.txt (+1) 
- (modified) libc/test/shared/shared_math_test.cpp (+7) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+13-1) 


``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 4ab336989f794..308e921009f98 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -104,6 +104,7 @@
 #include "math/f16mull.h"
 #include "math/f16sqrt.h"
 #include "math/f16sqrtf.h"
+#include "math/f16sqrtf128.h"
 #include "math/f16sqrtl.h"
 #include "math/f16sub.h"
 #include "math/f16subf.h"
diff --git a/libc/shared/math/f16sqrtf128.h b/libc/shared/math/f16sqrtf128.h
new file mode 100644
index 0000000000000..75f03b704602c
--- /dev/null
+++ b/libc/shared/math/f16sqrtf128.h
@@ -0,0 +1,32 @@
+//===-- Shared f16sqrtf128 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_F16SQRTF128_H
+#define LLVM_LIBC_SHARED_MATH_F16SQRTF128_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "include/llvm-libc-types/float128.h"
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16sqrtf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16sqrtf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_F16SQRTL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 4e7abd280bc4b..1b6a579053f48 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1149,6 +1149,18 @@ add_header_library(
     libc.include.llvm-libc-macros.float16_macros
 )
 
+add_header_library(
+  f16sqrtf128
+  HDRS
+    f16sqrtf128.h
+  DEPENDS
+    libc.src.__support.FPUtil.sqrt
+    libc.src.__support.common
+    libc.src.__support.macros.config
+    libc.include.llvm-libc-types.float128
+    libc.include.llvm-libc-macros.float16_macros
+)
+
 add_header_library(
   f16sqrtl
   HDRS
diff --git a/libc/src/__support/math/f16sqrtf128.h b/libc/src/__support/math/f16sqrtf128.h
new file mode 100644
index 0000000000000..d7fb51ccf8df6
--- /dev/null
+++ b/libc/src/__support/math/f16sqrtf128.h
@@ -0,0 +1,35 @@
+//===-- Implementation header for f16sqrtf128 -------------------*- 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_F16SQRTF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16SQRTF128_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float16 f16sqrtf(float128 x) {
+  return fputil::sqrt<float16>(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16SQRTF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index bb2c6f673f082..b2fa8a91dd18b 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4900,8 +4900,7 @@ add_entrypoint_object(
   HDRS
     ../f16sqrtf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.sqrt
+    libc.src.__support.math.f16sqrtf128
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/f16sqrtf128.cpp b/libc/src/math/generic/f16sqrtf128.cpp
index d33d6d2963fea..eca577091e0e9 100644
--- a/libc/src/math/generic/f16sqrtf128.cpp
+++ b/libc/src/math/generic/f16sqrtf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16sqrtf128.h"
-#include "src/__support/FPUtil/sqrt.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16sqrtf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16sqrtf128, (float128 x)) {
-  return fputil::sqrt<float16>(x);
+  return math::f16sqrtf128(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index fb26bb0e8ada6..87ff50acc46a1 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -103,6 +103,7 @@ add_fp_unittest(
     libc.src.__support.math.f16mull
     libc.src.__support.math.f16sqrt
     libc.src.__support.math.f16sqrtf
+    libc.src.__support.math.f16sqrtf128
     libc.src.__support.math.f16sqrtl
     libc.src.__support.math.f16sub
     libc.src.__support.math.f16subf
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 2758e3749910c..555a3743b1972 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -76,6 +76,13 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
   EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::f16sqrt(0.0));
 
   EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::f16sqrtf(0.0f));
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+  EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::f16sqrtf128(float128(0.0)));
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
   EXPECT_FP_EQ(float16(10.0),
                LIBC_NAMESPACE::shared::f16fmal(2.0L, 3.0L, 4.0L));
 
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 9f10754cddd9c..200172662748f 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -1546,6 +1546,18 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_f16sqrtf128",
+    hdrs = ["src/__support/math/f16sqrtf128.h"],
+    deps = [
+        ":__support_common",
+        ":__support_fputil_sqrt",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+        ":llvm_libc_types_float128",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_f16sqrtl",
     hdrs = ["src/__support/math/f16sqrtl.h"],
@@ -6319,7 +6331,7 @@ libc_math_function(
 libc_math_function(
     name = "f16sqrtf128",
     additional_deps = [
-        ":__support_fputil_sqrt",
+        ":__support_fputil_f16sqrtf128",
     ],
 )
 

``````````

</details>


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


More information about the libc-commits mailing list