Skip to content

Commit d06e9ce

Browse files
authored
[libc][math] Refactor frexpf implementation to header-only in src/__support/math folder. (#147893)
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 67db348 commit d06e9ce

File tree

7 files changed

+79
-6
lines changed

7 files changed

+79
-6
lines changed

libc/shared/math.h

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

1414
#include "math/expf.h"
1515
#include "math/expf16.h"
16+
#include "math/frexpf.h"
1617
#include "math/frexpf128.h"
1718
#include "math/frexpf16.h"
1819

libc/shared/math/frexpf.h

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

libc/src/__support/math/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,11 @@ add_header_library(
7474
libc.src.__support.macros.properties.types
7575
libc.src.__support.FPUtil.manipulation_functions
7676
)
77+
78+
add_header_library(
79+
frexpf
80+
HDRS
81+
frexpf.h
82+
DEPENDS
83+
libc.src.__support.FPUtil.manipulation_functions
84+
)

libc/src/__support/math/frexpf.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===-- Implementation header for frexpf ------------------------*- 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_FREXPF_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_FREXPF_H
11+
12+
#include "src/__support/FPUtil/ManipulationFunctions.h"
13+
#include "src/__support/common.h"
14+
#include "src/__support/macros/config.h"
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
namespace math {
19+
20+
static constexpr float frexpf(float x, int *exp) {
21+
return fputil::frexp(x, *exp);
22+
}
23+
24+
} // namespace math
25+
26+
} // namespace LIBC_NAMESPACE_DECL
27+
28+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FREXPF_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,7 @@ add_entrypoint_object(
17591759
HDRS
17601760
../frexpf.h
17611761
DEPENDS
1762-
libc.src.__support.FPUtil.manipulation_functions
1762+
libc.src.__support.math.frexpf
17631763
)
17641764

17651765
add_entrypoint_object(

libc/src/math/generic/frexpf.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/frexpf.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/frexpf.h"
1312

1413
namespace LIBC_NAMESPACE_DECL {
1514

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

2019
} // namespace LIBC_NAMESPACE_DECL

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,14 @@ libc_support_library(
21692169
],
21702170
)
21712171

2172+
libc_support_library(
2173+
name = "__support_math_frexpf",
2174+
hdrs = ["src/__support/math/frexpf.h"],
2175+
deps = [
2176+
":__support_fputil_manipulation_functions",
2177+
],
2178+
)
2179+
21722180
############################### complex targets ################################
21732181

21742182
libc_function(
@@ -3216,7 +3224,12 @@ libc_math_function(name = "fmulf128")
32163224

32173225
libc_math_function(name = "frexp")
32183226

3219-
libc_math_function(name = "frexpf")
3227+
libc_math_function(
3228+
name = "frexpf",
3229+
additional_deps = [
3230+
":__support_math_frexpf",
3231+
],
3232+
)
32203233

32213234
libc_math_function(name = "frexpl")
32223235

0 commit comments

Comments
 (0)