Skip to content

Commit 7db2f39

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

File tree

7 files changed

+96
-7
lines changed

7 files changed

+96
-7
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/ldexpf16.h"
1516

1617
#endif // LLVM_LIBC_SHARED_MATH_H

libc/shared/math/ldexpf16.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===-- Shared ldexpf16 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_ldexpf16_H
10+
#define LLVM_LIBC_SHARED_MATH_ldexpf16_H
11+
12+
#include "include/llvm-libc-macros/float16-macros.h"
13+
14+
#ifdef LIBC_TYPES_HAS_FLOAT16
15+
16+
#include "shared/libc_common.h"
17+
#include "src/__support/math/ldexpf16.h"
18+
19+
namespace LIBC_NAMESPACE_DECL {
20+
21+
namespace shared {
22+
23+
using math::ldexpf16;
24+
25+
} // namespace shared
26+
27+
} // namespace LIBC_NAMESPACE_DECL
28+
29+
#endif // LIBC_TYPES_HAS_FLOAT16
30+
31+
#endif // LLVM_LIBC_SHARED_MATH_ldexpf16_H

libc/src/__support/math/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,13 @@ add_header_library(
2222
libc.src.__support.macros.config
2323
libc.src.__support.macros.optimization
2424
)
25+
26+
add_header_library(
27+
ldexpf16
28+
HDRS
29+
ldexpf16.h
30+
DEPENDS
31+
libc.src.__support.macros.properties.types
32+
libc.src.__support.FPUtil.manipulation_functions
33+
libc.include.llvm-libc-macros.float16_macros
34+
)

libc/src/__support/math/ldexpf16.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===-- Implementation header for ldexpf16 ----------------------*- 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_LDEXPF16_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_LDEXPF16_H
11+
12+
#include "include/llvm-libc-macros/float16-macros.h"
13+
14+
#ifdef LIBC_TYPES_HAS_FLOAT16
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 float16 ldexpf16(float16 x, int exp) {
25+
return fputil::ldexp(x, exp);
26+
}
27+
28+
} // namespace math
29+
30+
} // namespace LIBC_NAMESPACE_DECL
31+
32+
#endif // LIBC_TYPES_HAS_FLOAT16
33+
34+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LDEXPF16_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,8 +1931,7 @@ add_entrypoint_object(
19311931
HDRS
19321932
../ldexpf16.h
19331933
DEPENDS
1934-
libc.src.__support.macros.properties.types
1935-
libc.src.__support.FPUtil.manipulation_functions
1934+
libc.src.__support.math.ldexpf16
19361935
)
19371936

19381937
add_entrypoint_object(

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

1413
namespace LIBC_NAMESPACE_DECL {
1514

1615
LLVM_LIBC_FUNCTION(float16, ldexpf16, (float16 x, int exp)) {
17-
return fputil::ldexp(x, exp);
16+
return math::ldexpf16(x, exp);
1817
}
1918

2019
} // namespace LIBC_NAMESPACE_DECL

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,16 @@ libc_support_library(
20962096
],
20972097
)
20982098

2099+
libc_support_library(
2100+
name = "__support_math_ldexpf16",
2101+
hdrs = ["src/__support/math/ldexpf16.h"],
2102+
deps = [
2103+
":__support_macros_properties_types",
2104+
":__support_fputil_manipulation_functions",
2105+
":llvm_libc_macros_float16_macros"
2106+
],
2107+
)
2108+
20992109
############################### complex targets ################################
21002110

21012111
libc_function(
@@ -3235,7 +3245,12 @@ libc_math_function(name = "ldexpl")
32353245

32363246
libc_math_function(name = "ldexpf128")
32373247

3238-
libc_math_function(name = "ldexpf16")
3248+
libc_math_function(
3249+
name = "ldexpf16",
3250+
additional_deps = [
3251+
":__support_math_ldexpf16",
3252+
],
3253+
)
32393254

32403255
libc_math_function(name = "llogb")
32413256

0 commit comments

Comments
 (0)