diff --git a/libc/shared/math.h b/libc/shared/math.h index 98f011dc0db07..1d6c3325b94ce 100644 --- a/libc/shared/math.h +++ b/libc/shared/math.h @@ -197,6 +197,7 @@ #include "math/hypotf.h" #include "math/hypotf16.h" #include "math/ilogb.h" +#include "math/ilogbbf16.h" #include "math/ilogbf.h" #include "math/ilogbf128.h" #include "math/ilogbf16.h" diff --git a/libc/shared/math/ilogbbf16.h b/libc/shared/math/ilogbbf16.h new file mode 100644 index 0000000000000..d559977318d33 --- /dev/null +++ b/libc/shared/math/ilogbbf16.h @@ -0,0 +1,23 @@ +//===-- Shared ilogbbf16 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_ILOGBBF16_H +#define LLVM_LIBC_SHARED_MATH_ILOGBBF16_H + +#include "shared/libc_common.h" +#include "src/__support/math/ilogbbf16.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::ilogbbf16; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SHARED_MATH_ILOGBBF16_H diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt index 9c61f6322c128..877271d5a915a 100644 --- a/libc/src/__support/math/CMakeLists.txt +++ b/libc/src/__support/math/CMakeLists.txt @@ -819,6 +819,15 @@ add_header_library( libc.src.__support.macros.config libc.src.__support.number_pair ) +add_header_library( + ilogbbf16 + HDRS + ilogbbf16.h + DEPENDS + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.manipulation_functions + libc.src.__support.macros.config +) add_header_library( sincos_integer_utils diff --git a/libc/src/__support/math/ilogbbf16.h b/libc/src/__support/math/ilogbbf16.h new file mode 100644 index 0000000000000..1b94717d79684 --- /dev/null +++ b/libc/src/__support/math/ilogbbf16.h @@ -0,0 +1,26 @@ +//===-- Implementation header for ilogbbf16 ---------------------*- 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_ILOGBBF16_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_ILOGBBF16_H + +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace math { + +LIBC_INLINE constexpr int ilogbbf16(bfloat16 x) { + return fputil::intlogb(x); +} + +} // namespace math +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ILOGBBF16_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index fec77a8fcaf98..8f28d1da590f2 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -1659,11 +1659,7 @@ add_entrypoint_object( HDRS ../ilogbbf16.h DEPENDS - libc.src.__support.common - libc.src.__support.FPUtil.bfloat16 - libc.src.__support.FPUtil.manipulation_functions - libc.src.__support.macros.config - libc.src.__support.macros.properties.types + libc.src.__support.math.ilogbbf16 ) add_entrypoint_object( diff --git a/libc/src/math/generic/ilogbbf16.cpp b/libc/src/math/generic/ilogbbf16.cpp index 6811139c6dcfd..584a5bfaadc09 100644 --- a/libc/src/math/generic/ilogbbf16.cpp +++ b/libc/src/math/generic/ilogbbf16.cpp @@ -7,15 +7,10 @@ //===----------------------------------------------------------------------===// #include "src/math/ilogbbf16.h" -#include "src/__support/FPUtil/ManipulationFunctions.h" -#include "src/__support/FPUtil/bfloat16.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" +#include "src/__support/math/ilogbbf16.h" namespace LIBC_NAMESPACE_DECL { -LLVM_LIBC_FUNCTION(int, ilogbbf16, (bfloat16 x)) { - return fputil::intlogb(x); -} +LLVM_LIBC_FUNCTION(int, ilogbbf16, (bfloat16 x)) { return math::ilogbbf16(x); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt index f39a904c7484f..b2917d7695088 100644 --- a/libc/test/shared/CMakeLists.txt +++ b/libc/test/shared/CMakeLists.txt @@ -194,6 +194,7 @@ add_fp_unittest( libc.src.__support.math.hypotbf16 libc.src.__support.math.hypotf16 libc.src.__support.math.ilogb + libc.src.__support.math.ilogbbf16 libc.src.__support.math.ilogbf libc.src.__support.math.ilogbf16 libc.src.__support.math.ilogbf128 @@ -340,6 +341,7 @@ add_fp_unittest( libc.src.__support.math.fmaximum_mag_numf libc.src.__support.math.log libc.src.__support.math.logbbf16 + libc.src.__support.math.ilogbbf16 ) add_fp_unittest( diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp index 747a63b1a9471..c9a7c6bc94a12 100644 --- a/libc/test/shared/shared_math_constexpr_test.cpp +++ b/libc/test/shared/shared_math_constexpr_test.cpp @@ -113,5 +113,6 @@ static_assert(bfloat16(0.0) == LIBC_NAMESPACE::shared::floorbf16(bfloat16(0.0f))); static_assert(bfloat16(0.0) == LIBC_NAMESPACE::shared::logbbf16(bfloat16(1.0f))); +static_assert(0 == LIBC_NAMESPACE::shared::ilogbbf16(bfloat16(1.0))); TEST(LlvmLibcSharedMathTest, ConstantEvaluation) {} diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp index bbda53faf353b..06f3c4021dca5 100644 --- a/libc/test/shared/shared_math_test.cpp +++ b/libc/test/shared/shared_math_test.cpp @@ -537,4 +537,6 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) { EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::nexttowardbf16(bfloat16(0.0), 0.0L)); #endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE + + EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogbbf16(bfloat16(1.0))); } diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index edd3eb1878fc9..ff2efb61cd13a 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -3946,6 +3946,16 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_math_ilogbbf16", + hdrs = ["src/__support/math/ilogbbf16.h"], + deps = [ + ":__support_fputil_bfloat16", + ":__support_fputil_manipulation_functions", + ":__support_macros_config", + ], +) + libc_support_library( name = "__support_math_sincos_integer_utils", hdrs = ["src/__support/math/sincos_integer_utils.h"], @@ -7194,6 +7204,13 @@ libc_math_function( ], ) +libc_math_function( + name = "ilogbbf16", + additional_deps = [ + ":__support_math_ilogbbf16", + ], +) + libc_math_function(name = "iscanonical") libc_math_function(name = "iscanonicalf")