Skip to content

Commit 544ac4d

Browse files
committed
[libc][math] Refactor ldexpf implementation to header-only in src/__support/math folder
1 parent 5a70a99 commit 544ac4d

File tree

7 files changed

+77
-6
lines changed

7 files changed

+77
-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/ldexpf.h"
1516

1617
#endif // LLVM_LIBC_SHARED_MATH_H

libc/shared/math/ldexpf.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Shared ldexpf 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_LDEXPF_H
10+
#define LLVM_LIBC_SHARED_MATH_LDEXPF_H
11+
12+
#include "shared/libc_common.h"
13+
#include "src/__support/math/ldexpf.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
namespace shared {
17+
18+
using math::ldexpf;
19+
20+
} // namespace shared
21+
} // namespace LIBC_NAMESPACE_DECL
22+
23+
#endif // LLVM_LIBC_SHARED_MATH_LDEXPF_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+
ldexpf
28+
HDRS
29+
ldexpf.h
30+
DEPENDS
31+
libc.src.__support.FPUtil.manipulation_functions
32+
)

libc/src/__support/math/ldexpf.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===-- Implementation header for ldexpf ------------------------*- 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_LDEXPF_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_LDEXPF_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 ldexpf(float x, int exp) {
21+
return fputil::ldexp(x, exp);
22+
}
23+
24+
} // namespace math
25+
26+
} // namespace LIBC_NAMESPACE_DECL
27+
28+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LDEXPF_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,7 @@ add_entrypoint_object(
19111911
HDRS
19121912
../ldexpf.h
19131913
DEPENDS
1914-
libc.src.__support.FPUtil.manipulation_functions
1914+
libc.src.__support.math.ldexpf
19151915
)
19161916

19171917
add_entrypoint_object(

libc/src/math/generic/ldexpf.cpp

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

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

1412
namespace LIBC_NAMESPACE_DECL {
1513

1614
LLVM_LIBC_FUNCTION(float, ldexpf, (float x, int exp)) {
17-
return fputil::ldexp(x, exp);
15+
return math::ldexpf(x, exp);
1816
}
1917

2018
} // 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_ldexpf",
2101+
hdrs = ["src/__support/math/ldexpf.h"],
2102+
deps = [
2103+
":__support_fputil_manipulation_functions",
2104+
],
2105+
)
2106+
20992107
############################### complex targets ################################
21002108

21012109
libc_function(
@@ -3229,7 +3237,12 @@ libc_math_function(name = "ilogbf16")
32293237

32303238
libc_math_function(name = "ldexp")
32313239

3232-
libc_math_function(name = "ldexpf")
3240+
libc_math_function(
3241+
name = "ldexpf",
3242+
additional_deps = [
3243+
":__support_math_ldexpf",
3244+
]
3245+
)
32333246

32343247
libc_math_function(name = "ldexpl")
32353248

0 commit comments

Comments
 (0)