[libc-commits] [libc] [llvm] [libc][math] Refactor fsqrtf128 to Header Only. (PR #175686)
via libc-commits
libc-commits at lists.llvm.org
Tue Jan 13 08:18:23 PST 2026
https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/175686
>From 938d53e571724b4c6084dc70020451aa6f841264 Mon Sep 17 00:00:00 2001
From: anonmiraj <nabilmalek48 at gmail.com>
Date: Tue, 13 Jan 2026 02:31:14 +0200
Subject: [PATCH] [libc][math] Refactor fsqrtf128 to Header Only.
---
libc/shared/math.h | 1 +
libc/shared/math/fsqrtf128.h | 30 ++++++++++++++++
libc/src/__support/math/CMakeLists.txt | 10 ++++++
libc/src/__support/math/fsqrtf128.h | 34 +++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 4 +--
libc/src/math/generic/fsqrtf128.cpp | 7 ++--
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_test.cpp | 1 +
.../llvm-project-overlay/clang/BUILD.bazel | 2 +-
.../llvm-project-overlay/libc/BUILD.bazel | 13 ++++++-
10 files changed, 94 insertions(+), 9 deletions(-)
create mode 100644 libc/shared/math/fsqrtf128.h
create mode 100644 libc/src/__support/math/fsqrtf128.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 287f3aea1565a..cc57570482e79 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -60,6 +60,7 @@
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
+#include "math/fsqrtf128.h"
#include "math/ilogbf16.h"
#include "math/ldexpf.h"
#include "math/ldexpf128.h"
diff --git a/libc/shared/math/fsqrtf128.h b/libc/shared/math/fsqrtf128.h
new file mode 100644
index 0000000000000..ee791c2404103
--- /dev/null
+++ b/libc/shared/math/fsqrtf128.h
@@ -0,0 +1,30 @@
+//===-- Shared fsqrtf128 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_FSQRTF128_H
+#define LLVM_LIBC_SHARED_MATH_FSQRTF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+
+#include "src/__support/math/fsqrtf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fsqrtf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+ //
+#endif // LLVM_LIBC_SHARED_MATH_FSQRTF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 4139a1b1d3444..b0e65194b7f5d 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1077,4 +1077,14 @@ add_header_library(
libc.src.__support.math.range_reduction_double
libc.src.__support.math.sincos_eval
libc.src.__support.macros.optimization
+
+)
+
+add_header_library(
+ fsqrtf128
+ HDRS
+ fsqrtf128.h
+ DEPENDS
+ libc.src.__support.FPUtil.generic.sqrt
+ libc.src.__support.macros.properties.types
)
diff --git a/libc/src/__support/math/fsqrtf128.h b/libc/src/__support/math/fsqrtf128.h
new file mode 100644
index 0000000000000..a62496e7ecd19
--- /dev/null
+++ b/libc/src/__support/math/fsqrtf128.h
@@ -0,0 +1,34 @@
+//===-- Implementation header for fsqrtf128 ------------------------*- 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_FSQRTF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FSQRTF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/sqrt.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr float fsqrtf128(float128 x) {
+ return fputil::sqrt<float>(x);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FSQRTF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 6de4cf376bf02..f1c11f466c540 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5244,8 +5244,8 @@ add_entrypoint_object(
HDRS
../fsqrtf128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.generic.sqrt
+ libc.src.__support.math.fsqrtf128
+ libc.src.errno.errno
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/fsqrtf128.cpp b/libc/src/math/generic/fsqrtf128.cpp
index f2c049529d6cd..1b2ba2fea0326 100644
--- a/libc/src/math/generic/fsqrtf128.cpp
+++ b/libc/src/math/generic/fsqrtf128.cpp
@@ -7,14 +7,11 @@
//===----------------------------------------------------------------------===//
#include "src/math/fsqrtf128.h"
-#include "src/__support/FPUtil/generic/sqrt.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
+#include "src/__support/math/fsqrtf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, fsqrtf128, (float128 x)) {
- return fputil::sqrt<float>(x);
+ return math::fsqrtf128(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index c5955ecfd54cb..5a1d87187a1df 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -64,4 +64,5 @@ add_fp_unittest(
libc.src.__support.math.rsqrtf
libc.src.__support.math.rsqrtf16
libc.src.__support.math.sin
+ libc.src.__support.math.fsqrtf128
)
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 20a98a1a9138c..67d7321073936 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -111,6 +111,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
LIBC_NAMESPACE::shared::ldexpf128(float128(8), 5));
ASSERT_FP_EQ(float128(-1 * (8 << 5)),
LIBC_NAMESPACE::shared::ldexpf128(float128(-8), 5));
+ EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::fsqrtf128(float128(1.0f)));
}
#endif // LIBC_TYPES_HAS_FLOAT128
diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
index 2b9c849e90c45..3016df209bdd0 100644
--- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -1798,8 +1798,8 @@ cc_library(
"//llvm:AllTargetsAsmParsers",
"//llvm:AllTargetsCodeGens",
"//llvm:Core",
- "//llvm:JITLink",
"//llvm:ExecutionEngine",
+ "//llvm:JITLink",
"//llvm:MC",
"//llvm:Option",
"//llvm:OrcDebugging",
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index c03c21b834895..d2d327f0086f1 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4292,7 +4292,8 @@ libc_math_function(
libc_math_function(
name = "fsqrtf128",
additional_deps = [
- ":__support_fputil_sqrt",
+ ":__support_math_fsqrtf128",
+ ":errno",
],
)
@@ -7860,3 +7861,13 @@ libc_function(
":types_wchar_t",
],
)
+
+libc_support_library(
+ name = "__support_math_fsqrtf128",
+ hdrs = ["src/__support/math/fsqrtf128.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_sqrt",
+ ":__support_macros_config",
+ ],
+)
More information about the libc-commits
mailing list