diff options
| author | Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com> | 2025-07-12 07:48:01 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-12 00:48:01 -0400 |
| commit | 395643e60b5d4e07c20a25db943a72d25fcba857 (patch) | |
| tree | 35fc7169b6844a729c55b50839db727aea3dfbd7 /libc | |
| parent | c3abe3ff22635172aea5162929433c55909822af (diff) | |
[libc][math] Refactor frexpf16 implementation to header-only in src/__support/math folder. (#147889)
Part of #147386
in preparation for:
https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
Diffstat (limited to 'libc')
| -rw-r--r-- | libc/shared/math.h | 1 | ||||
| -rw-r--r-- | libc/shared/math/frexpf16.h | 29 | ||||
| -rw-r--r-- | libc/src/__support/math/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | libc/src/__support/math/frexpf16.h | 34 | ||||
| -rw-r--r-- | libc/src/math/generic/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | libc/src/math/generic/frexpf16.cpp | 7 |
6 files changed, 78 insertions, 6 deletions
diff --git a/libc/shared/math.h b/libc/shared/math.h index d42b8d60a117..13c0f9abcdbd 100644 --- a/libc/shared/math.h +++ b/libc/shared/math.h @@ -14,5 +14,6 @@ #include "math/expf.h" #include "math/expf16.h" #include "math/frexpf128.h" +#include "math/frexpf16.h" #endif // LLVM_LIBC_SHARED_MATH_H diff --git a/libc/shared/math/frexpf16.h b/libc/shared/math/frexpf16.h new file mode 100644 index 000000000000..24b2883a6f91 --- /dev/null +++ b/libc/shared/math/frexpf16.h @@ -0,0 +1,29 @@ +//===-- Shared frexpf16 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_FREXPF16_H +#define LLVM_LIBC_SHARED_MATH_FREXPF16_H + +#include "include/llvm-libc-macros/float16-macros.h" +#include "shared/libc_common.h" + +#ifdef LIBC_TYPES_HAS_FLOAT16 + +#include "src/__support/math/frexpf16.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::frexpf16; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_HAS_FLOAT16 + +#endif // LLVM_LIBC_SHARED_MATH_FREXPF16_H diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt index 0090a0e12f7f..e745c07529ac 100644 --- a/libc/src/__support/math/CMakeLists.txt +++ b/libc/src/__support/math/CMakeLists.txt @@ -64,3 +64,13 @@ add_header_library( libc.src.__support.macros.properties.types libc.src.__support.FPUtil.manipulation_functions ) + +add_header_library( + frexpf16 + HDRS + frexpf16.h + DEPENDS + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.manipulation_functions +) diff --git a/libc/src/__support/math/frexpf16.h b/libc/src/__support/math/frexpf16.h new file mode 100644 index 000000000000..8deeba0f43e3 --- /dev/null +++ b/libc/src/__support/math/frexpf16.h @@ -0,0 +1,34 @@ +//===-- Implementation header for frexpf16 ----------------------*- 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_FREXPF16_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_FREXPF16_H + +#include "include/llvm-libc-macros/float16-macros.h" + +#ifdef LIBC_TYPES_HAS_FLOAT16 + +#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 float16 frexpf16(float16 x, int *exp) { + return fputil::frexp(x, *exp); +} + +} // namespace math + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_HAS_FLOAT16 + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FREXPF16_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 8b1fa9b4f434..6b540b2aafc9 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -1779,8 +1779,7 @@ add_entrypoint_object( HDRS ../frexpf16.h DEPENDS - libc.src.__support.macros.properties.types - libc.src.__support.FPUtil.manipulation_functions + libc.src.__support.math.frexpf16 ) add_entrypoint_object( diff --git a/libc/src/math/generic/frexpf16.cpp b/libc/src/math/generic/frexpf16.cpp index 4571b0d0ea38..fa918fd7ffc3 100644 --- a/libc/src/math/generic/frexpf16.cpp +++ b/libc/src/math/generic/frexpf16.cpp @@ -7,14 +7,13 @@ //===----------------------------------------------------------------------===// #include "src/math/frexpf16.h" -#include "src/__support/FPUtil/ManipulationFunctions.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" + +#include "src/__support/math/frexpf16.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(float16, frexpf16, (float16 x, int *exp)) { - return fputil::frexp(x, *exp); + return math::frexpf16(x, exp); } } // namespace LIBC_NAMESPACE_DECL |
