[libc][math] Refactor ilogb implementation to header-only in src/__support/math folder. (#175504)
closes #175348
This commit is contained in:
parent
f92948fa9b
commit
69e855bb1b
@ -68,6 +68,7 @@
|
||||
#include "math/fsqrt.h"
|
||||
#include "math/fsqrtf128.h"
|
||||
#include "math/hypotf.h"
|
||||
#include "math/ilogb.h"
|
||||
#include "math/ilogbf.h"
|
||||
#include "math/ilogbf128.h"
|
||||
#include "math/ilogbf16.h"
|
||||
|
||||
23
libc/shared/math/ilogb.h
Normal file
23
libc/shared/math/ilogb.h
Normal file
@ -0,0 +1,23 @@
|
||||
//===-- Shared ilogb 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_ILOGB_H
|
||||
#define LLVM_LIBC_SHARED_MATH_ILOGB_H
|
||||
|
||||
#include "shared/libc_common.h"
|
||||
#include "src/__support/math/ilogb.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
namespace shared {
|
||||
|
||||
using math::ilogb;
|
||||
|
||||
} // namespace shared
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SHARED_MATH_ILOGB_H
|
||||
@ -667,6 +667,16 @@ add_header_library(
|
||||
libc.include.llvm-libc-macros.float16_macros
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
ilogb
|
||||
HDRS
|
||||
ilogb.h
|
||||
DEPENDS
|
||||
libc.src.__support.common
|
||||
libc.src.__support.macros.config
|
||||
libc.src.__support.FPUtil.manipulation_functions
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
ilogbf16
|
||||
HDRS
|
||||
|
||||
27
libc/src/__support/math/ilogb.h
Normal file
27
libc/src/__support/math/ilogb.h
Normal file
@ -0,0 +1,27 @@
|
||||
//===-- Implementation header for ilogb -------------------------*- 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_ILOGB_H
|
||||
#define LLVM_LIBC_SRC___SUPPORT_MATH_ILOGB_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 static constexpr int ilogb(double x) {
|
||||
return fputil::intlogb<int>(x);
|
||||
}
|
||||
} // namespace math
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ILOGB_H
|
||||
@ -1720,7 +1720,7 @@ add_entrypoint_object(
|
||||
HDRS
|
||||
../ilogb.h
|
||||
DEPENDS
|
||||
libc.src.__support.FPUtil.manipulation_functions
|
||||
libc.src.__support.math.ilogb
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
|
||||
@ -7,12 +7,10 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/math/ilogb.h"
|
||||
#include "src/__support/FPUtil/ManipulationFunctions.h"
|
||||
#include "src/__support/common.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
#include "src/__support/math/ilogb.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, ilogb, (double x)) { return fputil::intlogb<int>(x); }
|
||||
LLVM_LIBC_FUNCTION(int, ilogb, (double x)) { return math::ilogb(x); }
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
@ -64,6 +64,7 @@ add_fp_unittest(
|
||||
libc.src.__support.math.fsqrt
|
||||
libc.src.__support.math.fsqrtf128
|
||||
libc.src.__support.math.hypotf
|
||||
libc.src.__support.math.ilogb
|
||||
libc.src.__support.math.ilogbf
|
||||
libc.src.__support.math.ilogbf16
|
||||
libc.src.__support.math.ilogbf128
|
||||
|
||||
@ -119,8 +119,9 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
|
||||
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::log1p(0.0));
|
||||
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::log2(1.0));
|
||||
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::sin(0.0));
|
||||
EXPECT_EQ(0L, LIBC_NAMESPACE::shared::llogb(1.0));
|
||||
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::tan(0.0));
|
||||
EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogb(1.0));
|
||||
EXPECT_EQ(0L, LIBC_NAMESPACE::shared::llogb(1.0));
|
||||
}
|
||||
|
||||
TEST(LlvmLibcSharedMathTest, AllLongDouble) {
|
||||
|
||||
@ -2974,6 +2974,16 @@ libc_support_library(
|
||||
],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "__support_math_ilogb",
|
||||
hdrs = ["src/__support/math/ilogb.h"],
|
||||
deps = [
|
||||
":__support_common",
|
||||
":__support_fputil_manipulation_functions",
|
||||
":__support_macros_config",
|
||||
],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "__support_math_ilogbf16",
|
||||
hdrs = ["src/__support/math/ilogbf16.h"],
|
||||
@ -4745,7 +4755,12 @@ libc_math_function(
|
||||
],
|
||||
)
|
||||
|
||||
libc_math_function(name = "ilogb")
|
||||
libc_math_function(
|
||||
name = "ilogb",
|
||||
additional_deps = [
|
||||
":__support_math_ilogb",
|
||||
],
|
||||
)
|
||||
|
||||
libc_math_function(
|
||||
name = "ilogbf",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user