Skip to content

Commit af6500d

Browse files
authored
[libc][math] Refactor frexpf128 implementation to header-only in src/… (#147822)
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
1 parent f03bcb7 commit af6500d

File tree

7 files changed

+91
-7
lines changed

7 files changed

+91
-7
lines changed

libc/shared/math.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313

1414
#include "math/expf.h"
1515
#include "math/expf16.h"
16+
#include "math/frexpf128.h"
1617

1718
#endif // LLVM_LIBC_SHARED_MATH_H

libc/shared/math/frexpf128.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===-- Shared frexpf128 function -------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SHARED_MATH_FREXPF128_H
10+
#define LLVM_LIBC_SHARED_MATH_FREXPF128_H
11+
12+
#include "include/llvm-libc-types/float128.h"
13+
14+
#ifdef LIBC_TYPES_HAS_FLOAT128
15+
16+
#include "shared/libc_common.h"
17+
18+
namespace LIBC_NAMESPACE_DECL {
19+
namespace shared {
20+
21+
using math::frexpf128;
22+
23+
} // namespace shared
24+
} // namespace LIBC_NAMESPACE_DECL
25+
26+
#endif // LIBC_TYPES_HAS_FLOAT128
27+
28+
#endif // LLVM_LIBC_SHARED_MATH_FREXPF128_H

libc/src/__support/math/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@ add_header_library(
5555
libc.src.__support.macros.optimization
5656
libc.include.llvm-libc-macros.float16_macros
5757
)
58+
59+
add_header_library(
60+
frexpf128
61+
HDRS
62+
frexpf128.h
63+
DEPENDS
64+
libc.src.__support.macros.properties.types
65+
libc.src.__support.FPUtil.manipulation_functions
66+
)

libc/src/__support/math/frexpf128.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===-- Implementation header for expf --------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FREXPF128_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_FREXPF128_H
11+
12+
#include "include/llvm-libc-types/float128.h"
13+
14+
#ifdef LIBC_TYPES_HAS_FLOAT128
15+
16+
#include "src/__support/FPUtil/ManipulationFunctions.h"
17+
#include "src/__support/common.h"
18+
#include "src/__support/macros/config.h"
19+
20+
namespace LIBC_NAMESPACE_DECL {
21+
22+
namespace math {
23+
24+
static constexpr float128 frexpf128(float128 x, int *exp) {
25+
return fputil::frexp(x, *exp);
26+
}
27+
28+
} // namespace math
29+
30+
} // namespace LIBC_NAMESPACE_DECL
31+
32+
#endif // LIBC_TYPES_HAS_FLOAT128
33+
34+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FREXPF128_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,8 +1775,7 @@ add_entrypoint_object(
17751775
HDRS
17761776
../frexpf128.h
17771777
DEPENDS
1778-
libc.src.__support.macros.properties.types
1779-
libc.src.__support.FPUtil.manipulation_functions
1778+
libc.src.__support.math.frexpf128
17801779
)
17811780

17821781
add_entrypoint_object(

libc/src/math/generic/frexpf128.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/math/frexpf128.h"
10-
#include "src/__support/FPUtil/ManipulationFunctions.h"
11-
#include "src/__support/common.h"
12-
#include "src/__support/macros/config.h"
10+
11+
#include "src/__support/math/frexpf128.h"
1312

1413
namespace LIBC_NAMESPACE_DECL {
1514

1615
LLVM_LIBC_FUNCTION(float128, frexpf128, (float128 x, int *exp)) {
17-
return fputil::frexp(x, *exp);
16+
return math::frexpf128(x, exp);
1817
}
1918

2019
} // namespace LIBC_NAMESPACE_DECL

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,15 @@ libc_support_library(
21492149
],
21502150
)
21512151

2152+
libc_support_library(
2153+
name = "__support_math_frexpf128",
2154+
hdrs = ["src/__support/math/frexpf128.h"],
2155+
deps = [
2156+
":__support_macros_properties_types",
2157+
":__support_fputil_manipulation_functions",
2158+
],
2159+
)
2160+
21522161
############################### complex targets ################################
21532162

21542163
libc_function(
@@ -3200,7 +3209,12 @@ libc_math_function(name = "frexpf")
32003209

32013210
libc_math_function(name = "frexpl")
32023211

3203-
libc_math_function(name = "frexpf128")
3212+
libc_math_function(
3213+
name = "frexpf128",
3214+
additional_deps = [
3215+
":__support_math_frexpf128",
3216+
]
3217+
)
32043218

32053219
libc_math_function(name = "frexpf16")
32063220

0 commit comments

Comments
 (0)