diff --git a/libc/shared/math.h b/libc/shared/math.h index 66132326c2257..288a471b5d3a1 100644 --- a/libc/shared/math.h +++ b/libc/shared/math.h @@ -85,6 +85,7 @@ #include "math/llogbf.h" #include "math/llogbf128.h" #include "math/llogbf16.h" +#include "math/llogbl.h" #include "math/log.h" #include "math/log10.h" #include "math/log1p.h" diff --git a/libc/shared/math/llogbl.h b/libc/shared/math/llogbl.h new file mode 100644 index 0000000000000..3135787e08d2f --- /dev/null +++ b/libc/shared/math/llogbl.h @@ -0,0 +1,23 @@ +//===-- Shared llogbl function ----------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_MATH_LLOGBL_H +#define LLVM_LIBC_SHARED_MATH_LLOGBL_H + +#include "shared/libc_common.h" +#include "src/__support/math/llogbl.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::llogbl; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SHARED_MATH_LLOGBL_H diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt index c0293c0969217..79edba3e25227 100644 --- a/libc/src/__support/math/CMakeLists.txt +++ b/libc/src/__support/math/CMakeLists.txt @@ -816,6 +816,16 @@ add_header_library( libc.src.__support.macros.config ) +add_header_library( + llogbl + HDRS + llogbl.h + DEPENDS + libc.src.__support.FPUtil.manipulation_functions + libc.src.__support.common + libc.src.__support.macros.config +) + add_header_library( logf16 HDRS diff --git a/libc/src/__support/math/llogbl.h b/libc/src/__support/math/llogbl.h new file mode 100644 index 0000000000000..58c9770613cd5 --- /dev/null +++ b/libc/src/__support/math/llogbl.h @@ -0,0 +1,28 @@ +//===-- Implementation header for llogbl ------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LLOGBL_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_LLOGBL_H + +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +namespace math { + +LIBC_INLINE constexpr long llogbl(long double x) { + return fputil::intlogb(x); +} + +} // namespace math + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LLOGBL_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 96dc0e7ca4851..c491bbbab85b4 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -1798,7 +1798,7 @@ add_entrypoint_object( HDRS ../llogbl.h DEPENDS - libc.src.__support.FPUtil.manipulation_functions + libc.src.__support.math.llogbl ) add_entrypoint_object( diff --git a/libc/src/math/generic/llogbl.cpp b/libc/src/math/generic/llogbl.cpp index 7ee3ac55653b6..5c5e15ae19455 100644 --- a/libc/src/math/generic/llogbl.cpp +++ b/libc/src/math/generic/llogbl.cpp @@ -7,14 +7,10 @@ //===----------------------------------------------------------------------===// #include "src/math/llogbl.h" -#include "src/__support/FPUtil/ManipulationFunctions.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" +#include "src/__support/math/llogbl.h" namespace LIBC_NAMESPACE_DECL { -LLVM_LIBC_FUNCTION(long, llogbl, (long double x)) { - return fputil::intlogb(x); -} +LLVM_LIBC_FUNCTION(long, llogbl, (long double x)) { return math::llogbl(x); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt index 7d72ced3e057c..edb98e3b83c03 100644 --- a/libc/test/shared/CMakeLists.txt +++ b/libc/test/shared/CMakeLists.txt @@ -91,6 +91,7 @@ add_fp_unittest( libc.src.__support.math.llogbf128 libc.src.__support.math.llogbf16 libc.src.__support.math.logf16 + libc.src.__support.math.llogbl libc.src.__support.math.rsqrtf libc.src.__support.math.rsqrtf16 libc.src.__support.math.sqrtf16 diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp index 9e024387efbfa..97e1d0d4426cd 100644 --- a/libc/test/shared/shared_math_test.cpp +++ b/libc/test/shared/shared_math_test.cpp @@ -149,6 +149,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) { LIBC_NAMESPACE::shared::dfmal(0x0.p+0L, 0x0.p+0L, 0x0.p+0L)); EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fsqrtl(0.0L)); EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogbl(0x1.p+0L)); + EXPECT_EQ(0L, LIBC_NAMESPACE::shared::llogbl(1.0L)); EXPECT_FP_EQ(10.0f, LIBC_NAMESPACE::shared::ffmal(2.0L, 3.0, 4.0L)); } diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index ae7228c52d3c0..3d4f66fb10c7a 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -3105,11 +3105,23 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_math_llogbl", + hdrs = ["src/__support/math/llogbl.h"], + deps = [ + ":__support_common", + ":__support_fputil_manipulation_functions", + ":__support_macros_config", + ], +) + libc_support_library( name = "__support_math_llogbf", hdrs = ["src/__support/math/llogbf.h"], deps = [ + ":__support_common", ":__support_fputil_manipulation_functions", + ":__support_macros_config", ], ) @@ -4960,7 +4972,12 @@ libc_math_function( additional_deps = [":__support_math_llogbf"], ) -libc_math_function(name = "llogbl") +libc_math_function( + name = "llogbl", + additional_deps = [ + ":__support_math_llogbl", + ], +) libc_math_function( name = "llogbf128",