From 6e911b83561bdc3dfb55ca5fa0e026e30801cae1 Mon Sep 17 00:00:00 2001 From: bassiounix Date: Wed, 9 Jul 2025 23:32:52 +0300 Subject: [PATCH 1/3] [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 Date: Thu, 10 Jul 2025 06:38:46 +0300 Subject: [PATCH 2/3] 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 Date: Sat, 12 Jul 2025 05:24:05 +0300 Subject: [PATCH 3/3] 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 {