[libc-commits] [libc] dde762a - [libc][math] Refactor `f16sqrtf` to Header Only. (#180749)

via libc-commits libc-commits at lists.llvm.org
Wed Feb 11 19:52:46 PST 2026


Author: iLeGend
Date: 2026-02-12T03:52:40Z
New Revision: dde762afb92be5206254af898558662ab9a55f7f

URL: https://github.com/llvm/llvm-project/commit/dde762afb92be5206254af898558662ab9a55f7f
DIFF: https://github.com/llvm/llvm-project/commit/dde762afb92be5206254af898558662ab9a55f7f.diff

LOG: [libc][math] Refactor `f16sqrtf` to Header Only. (#180749)

fix https://github.com/llvm/llvm-project/issues/175329

Added: 
    libc/shared/math/f16sqrtf.h
    libc/src/__support/math/f16sqrtf.h

Modified: 
    libc/shared/math.h
    libc/src/__support/math/CMakeLists.txt
    libc/src/math/generic/CMakeLists.txt
    libc/src/math/generic/f16sqrtf.cpp
    libc/test/shared/CMakeLists.txt
    libc/test/shared/shared_math_test.cpp
    utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Removed: 
    


################################################################################
diff  --git a/libc/shared/math.h b/libc/shared/math.h
index 4b0f2c67b0c86..eab584aea4e60 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -64,6 +64,7 @@
 #include "math/f16fmaf128.h"
 #include "math/f16fmal.h"
 #include "math/f16sqrt.h"
+#include "math/f16sqrtf.h"
 #include "math/f16sqrtl.h"
 #include "math/ffmal.h"
 #include "math/frexpf.h"

diff  --git a/libc/shared/math/f16sqrtf.h b/libc/shared/math/f16sqrtf.h
new file mode 100644
index 0000000000000..65f580cb3fed8
--- /dev/null
+++ b/libc/shared/math/f16sqrtf.h
@@ -0,0 +1,29 @@
+//===-- Shared f16sqrtf 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_F16SQRTF_H
+#define LLVM_LIBC_SHARED_MATH_F16SQRTF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/f16sqrtf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16sqrtf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16SQRTF_H

diff  --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 6705a2a08f3a7..4e6e9bd6233ec 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -613,6 +613,17 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  f16sqrtf
+  HDRS
+    f16sqrtf.h
+  DEPENDS
+    libc.src.__support.FPUtil.sqrt
+    libc.src.__support.common
+    libc.src.__support.macros.config
+    libc.include.llvm-libc-macros.float16_macros
+)
+
 add_header_library(
   f16sqrtl
   HDRS

diff  --git a/libc/src/__support/math/f16sqrtf.h b/libc/src/__support/math/f16sqrtf.h
new file mode 100644
index 0000000000000..e6b513cc8e617
--- /dev/null
+++ b/libc/src/__support/math/f16sqrtf.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16sqrtf ----------------------*- 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_F16SQRTF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16SQRTF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#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(float x) {
+  return fputil::sqrt<float16>(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16SQRTF_H

diff  --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 1a3588a71219b..98d79e3b3826d 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5017,8 +5017,7 @@ add_entrypoint_object(
   HDRS
     ../f16sqrtf.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.sqrt
+    libc.src.__support.math.f16sqrtf
 )
 
 add_entrypoint_object(

diff  --git a/libc/src/math/generic/f16sqrtf.cpp b/libc/src/math/generic/f16sqrtf.cpp
index be43a77787fae..6ac777d4dca9a 100644
--- a/libc/src/math/generic/f16sqrtf.cpp
+++ b/libc/src/math/generic/f16sqrtf.cpp
@@ -7,14 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16sqrtf.h"
-#include "src/__support/FPUtil/sqrt.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16sqrtf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(float16, f16sqrtf, (float x)) {
-  return fputil::sqrt<float16>(x);
-}
+LLVM_LIBC_FUNCTION(float16, f16sqrtf, (float x)) { return math::f16sqrtf(x); }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index ec117e317d9bf..ef4d78584ef77 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -60,6 +60,7 @@ add_fp_unittest(
     libc.src.__support.math.f16fmaf128
     libc.src.__support.math.f16fmal
     libc.src.__support.math.f16sqrt
+    libc.src.__support.math.f16sqrtf
     libc.src.__support.math.f16sqrtl
     libc.src.__support.math.ffmal
     libc.src.__support.math.frexpf

diff  --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index b3a7dff4b6c4f..1c8463d9321fc 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -50,6 +50,8 @@ 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));
+
   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 1c70361929887..e08d759f063b0 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -1421,6 +1421,17 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_f16sqrtf",
+    hdrs = ["src/__support/math/f16sqrtf.h"],
+    deps = [
+        ":__support_common",
+        ":__support_fputil_sqrt",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_f16sqrtl",
     hdrs = ["src/__support/math/f16sqrtl.h"],
@@ -4530,7 +4541,7 @@ libc_math_function(
 
 libc_math_function(
     name = "f16sqrtf",
-    additional_deps = [":__support_fputil_sqrt"],
+    additional_deps = [":__support_math_f16sqrtf"],
 )
 
 libc_math_function(


        


More information about the libc-commits mailing list