Skip to content

Commit a807ae1

Browse files
committed
[libc][math] Refactor frexpf implementation to header-only in src/__support/math folder.
1 parent 5a70a99 commit a807ae1

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
@@ -12,5 +12,6 @@
1212
#include "libc_common.h"
1313

1414
#include "math/expf.h"
15+
#include "math/frexpf.h"
1516

1617
#endif // LLVM_LIBC_SHARED_MATH_H

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
@@ -22,3 +22,11 @@ add_header_library(
2222
libc.src.__support.macros.config
2323
libc.src.__support.macros.optimization
2424
)
25+
26+
add_header_library(
27+
frexpf
28+
HDRS
29+
frexpf.h
30+
DEPENDS
31+
libc.src.__support.FPUtil.manipulation_functions
32+
)

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
@@ -1755,7 +1755,7 @@ add_entrypoint_object(
17551755
HDRS
17561756
../frexpf.h
17571757
DEPENDS
1758-
libc.src.__support.FPUtil.manipulation_functions
1758+
libc.src.__support.math.frexpf
17591759
)
17601760

17611761
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
@@ -2096,6 +2096,14 @@ libc_support_library(
20962096
],
20972097
)
20982098

2099+
libc_support_library(
2100+
name = "__support_math_frexpf",
2101+
hdrs = ["src/__support/math/frexpf.h"],
2102+
deps = [
2103+
":__support_fputil_manipulation_functions",
2104+
],
2105+
)
2106+
20992107
############################### complex targets ################################
21002108

21012109
libc_function(
@@ -3142,7 +3150,12 @@ libc_math_function(name = "fmulf128")
31423150

31433151
libc_math_function(name = "frexp")
31443152

3145-
libc_math_function(name = "frexpf")
3153+
libc_math_function(
3154+
name = "frexpf",
3155+
additional_deps = [
3156+
":__support_math_frexpf",
3157+
],
3158+
)
31463159

31473160
libc_math_function(name = "frexpl")
31483161

0 commit comments

Comments
 (0)