Skip to content

Commit 79f8eba

Browse files
authored
[libc][math] Refactor logbl to header only (llvm#181659)
Closes llvm#175366
1 parent 0c91bc6 commit 79f8eba

File tree

9 files changed

+79
-6
lines changed

9 files changed

+79
-6
lines changed

libc/shared/math.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
#include "math/logbf.h"
118118
#include "math/logbf128.h"
119119
#include "math/logbf16.h"
120+
#include "math/logbl.h"
120121
#include "math/logf.h"
121122
#include "math/logf16.h"
122123
#include "math/pow.h"

libc/shared/math/logbl.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Shared logbl 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_LOGBL_H
10+
#define LLVM_LIBC_SHARED_MATH_LOGBL_H
11+
12+
#include "shared/libc_common.h"
13+
#include "src/__support/math/logbl.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
namespace shared {
17+
18+
using math::logbl;
19+
20+
} // namespace shared
21+
} // namespace LIBC_NAMESPACE_DECL
22+
23+
#endif // LLVM_LIBC_SHARED_MATH_LOGBL_H

libc/src/__support/math/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,16 @@ add_header_library(
17161716
libc.src.__support.macros.properties.cpu_features
17171717
)
17181718

1719+
add_header_library(
1720+
logbl
1721+
HDRS
1722+
logbl.h
1723+
DEPENDS
1724+
libc.src.__support.FPUtil.manipulation_functions
1725+
libc.src.__support.common
1726+
libc.src.__support.macros.config
1727+
)
1728+
17191729
add_header_library(
17201730
log_range_reduction
17211731
HDRS

libc/src/__support/math/logbl.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- Implementation header for logbl -------------------------*- 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_LOGBL_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_LOGBL_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+
namespace math {
18+
19+
LIBC_INLINE constexpr long double logbl(long double x) {
20+
return fputil::logb(x);
21+
}
22+
23+
} // namespace math
24+
} // namespace LIBC_NAMESPACE_DECL
25+
26+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOGBL_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,7 @@ add_entrypoint_object(
19991999
HDRS
20002000
../logbl.h
20012001
DEPENDS
2002-
libc.src.__support.FPUtil.manipulation_functions
2002+
libc.src.__support.math.logbl
20032003
)
20042004

20052005
add_entrypoint_object(

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

1412
namespace LIBC_NAMESPACE_DECL {
1513

1614
LLVM_LIBC_FUNCTION(long double, logbl, (long double x)) {
17-
return fputil::logb(x);
15+
return math::logbl(x);
1816
}
1917

2018
} // namespace LIBC_NAMESPACE_DECL

libc/test/shared/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ add_fp_unittest(
114114
libc.src.__support.math.llogbf
115115
libc.src.__support.math.llogbf128
116116
libc.src.__support.math.llogbf16
117+
libc.src.__support.math.logbl
117118
libc.src.__support.math.logf16
118119
libc.src.__support.math.llogbl
119120
libc.src.__support.math.pow

libc/test/shared/shared_math_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
195195
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fsqrtl(0.0L));
196196
EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogbl(0x1.p+0L));
197197
EXPECT_EQ(0L, LIBC_NAMESPACE::shared::llogbl(1.0L));
198+
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::logbl(1.0L));
198199
EXPECT_FP_EQ(10.0f, LIBC_NAMESPACE::shared::ffmal(2.0L, 3.0, 4.0L));
199200

200201
long double canonicalizel_cx = 0.0L;

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3305,6 +3305,16 @@ libc_support_library(
33053305
],
33063306
)
33073307

3308+
libc_support_library(
3309+
name = "__support_math_logbl",
3310+
hdrs = ["src/__support/math/logbl.h"],
3311+
deps = [
3312+
":__support_common",
3313+
":__support_fputil_manipulation_functions",
3314+
":__support_macros_config",
3315+
],
3316+
)
3317+
33083318
libc_support_library(
33093319
name = "__support_math_log10",
33103320
hdrs = ["src/__support/math/log10.h"],
@@ -5399,7 +5409,10 @@ libc_math_function(
53995409
additional_deps = [":__support_math_logbf"],
54005410
)
54015411

5402-
libc_math_function(name = "logbl")
5412+
libc_math_function(
5413+
name = "logbl",
5414+
additional_deps = [":__support_math_logbl"],
5415+
)
54035416

54045417
libc_math_function(
54055418
name = "logbf128",

0 commit comments

Comments
 (0)