[libc-commits] [libc] 27905b1 - [libc][math] Refactor f16sqrtf128 to Header Only. (#183542)
via libc-commits
libc-commits at lists.llvm.org
Thu Feb 26 10:49:01 PST 2026
Author: Zorojuro
Date: 2026-02-26T20:48:56+02:00
New Revision: 27905b119669d257a67e9312c1de46edb33b7e44
URL: https://github.com/llvm/llvm-project/commit/27905b119669d257a67e9312c1de46edb33b7e44
DIFF: https://github.com/llvm/llvm-project/commit/27905b119669d257a67e9312c1de46edb33b7e44.diff
LOG: [libc][math] Refactor f16sqrtf128 to Header Only. (#183542)
closes #175328
part of https://github.com/llvm/llvm-project/issues/147386
Added:
libc/shared/math/f16sqrtf128.h
libc/src/__support/math/f16sqrtf128.h
Modified:
libc/shared/math.h
libc/src/__support/math/CMakeLists.txt
libc/src/math/generic/CMakeLists.txt
libc/src/math/generic/f16sqrtf128.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 346fa477f08c8..c1cf20ac25f96 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..bd04940b4bca2
--- /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_F16SQRTF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 66a17071920f5..75a55c2939e19 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..3ef74136cba94
--- /dev/null
+++ b/libc/src/__support/math/f16sqrtf128.h
@@ -0,0 +1,33 @@
+//===-- 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 float16 f16sqrtf128(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 a2fbd844e9b39..f8834c5c12705 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4892,8 +4892,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 08bfccadc7682..490e498aaf9e8 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -101,6 +101,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 7bf7409293db1..43ff7610e384b 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 48823b1983ec1..c31c1e18f1deb 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"],
@@ -6336,7 +6348,7 @@ libc_math_function(
libc_math_function(
name = "f16sqrtf128",
additional_deps = [
- ":__support_fputil_sqrt",
+ ":__support_math_f16sqrtf128",
],
)
More information about the libc-commits
mailing list