[libc][math] Refactor dsqrtl implementation to header-only in src/__support/math folder.
This commit is contained in:
parent
4d323206ed
commit
f81c15c57e
@ -39,6 +39,7 @@
|
||||
#include "math/coshf16.h"
|
||||
#include "math/cospif.h"
|
||||
#include "math/cospif16.h"
|
||||
#include "math/dsqrtl.h"
|
||||
#include "math/erff.h"
|
||||
#include "math/exp.h"
|
||||
#include "math/exp10.h"
|
||||
|
23
libc/shared/math/dsqrtl.h
Normal file
23
libc/shared/math/dsqrtl.h
Normal file
@ -0,0 +1,23 @@
|
||||
//===-- Shared dsqrtl 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_DSQRTL_H
|
||||
#define LLVM_LIBC_SHARED_MATH_DSQRTL_H
|
||||
|
||||
#include "shared/libc_common.h"
|
||||
#include "src/__support/math/dsqrtl.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
namespace shared {
|
||||
|
||||
using math::dsqrtl;
|
||||
|
||||
} // namespace shared
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SHARED_MATH_DSQRTL_H
|
@ -69,8 +69,8 @@ LIBC_INLINE void normalize<long double>(int &exponent, UInt128 &mantissa) {
|
||||
// Correctly rounded IEEE 754 SQRT for all rounding modes.
|
||||
// Shift-and-add algorithm.
|
||||
template <typename OutType, typename InType>
|
||||
LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
|
||||
cpp::is_floating_point_v<InType> &&
|
||||
LIBC_INLINE static constexpr cpp::enable_if_t<
|
||||
cpp::is_floating_point_v<OutType> && cpp::is_floating_point_v<InType> &&
|
||||
sizeof(OutType) <= sizeof(InType),
|
||||
OutType>
|
||||
sqrt(InType x) {
|
||||
|
@ -457,6 +457,14 @@ add_header_library(
|
||||
libc.src.__support.macros.optimization
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
dsqrtl
|
||||
HDRS
|
||||
dsqrtl.h
|
||||
DEPENDS
|
||||
libc.src.__support.FPUtil.generic.sqrt
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
erff
|
||||
HDRS
|
||||
|
26
libc/src/__support/math/dsqrtl.h
Normal file
26
libc/src/__support/math/dsqrtl.h
Normal file
@ -0,0 +1,26 @@
|
||||
//===-- Implementation header for dsqrtl ------------------------*- 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_DSQRTL_H
|
||||
#define LLVM_LIBC_SRC___SUPPORT_MATH_DSQRTL_H
|
||||
|
||||
#include "src/__support/FPUtil/generic/sqrt.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
namespace math {
|
||||
|
||||
LIBC_INLINE static constexpr double dsqrtl(long double x) {
|
||||
return fputil::sqrt<double>(x);
|
||||
}
|
||||
|
||||
} // namespace math
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DSQRTL_H
|
@ -242,7 +242,7 @@ add_entrypoint_object(
|
||||
HDRS
|
||||
../dsqrtl.h
|
||||
DEPENDS
|
||||
libc.src.__support.FPUtil.generic.sqrt
|
||||
libc.src.__support.math.dsqrtl
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
|
@ -7,14 +7,9 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/math/dsqrtl.h"
|
||||
#include "src/__support/FPUtil/generic/sqrt.h"
|
||||
#include "src/__support/common.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
|
||||
#include "src/__support/math/dsqrtl.h"
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
LLVM_LIBC_FUNCTION(double, dsqrtl, (long double x)) {
|
||||
return fputil::sqrt<double>(x);
|
||||
}
|
||||
LLVM_LIBC_FUNCTION(double, dsqrtl, (long double x)) { return math::dsqrtl(x); }
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
@ -35,6 +35,7 @@ add_fp_unittest(
|
||||
libc.src.__support.math.coshf16
|
||||
libc.src.__support.math.cospif
|
||||
libc.src.__support.math.cospif16
|
||||
libc.src.__support.math.dsqrtl
|
||||
libc.src.__support.math.erff
|
||||
libc.src.__support.math.exp
|
||||
libc.src.__support.math.exp10
|
||||
|
@ -55,6 +55,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
|
||||
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::cosf(0.0f));
|
||||
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::coshf(0.0f));
|
||||
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::cospif(0.0f));
|
||||
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::dsqrtl(0.0f));
|
||||
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::erff(0.0f));
|
||||
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::exp10f(0.0f));
|
||||
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::expf(0.0f));
|
||||
|
@ -2419,6 +2419,14 @@ libc_support_library(
|
||||
],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "__support_math_dsqrtl",
|
||||
hdrs = ["src/__support/math/dsqrtl.h"],
|
||||
deps = [
|
||||
":__support_fputil_sqrt",
|
||||
],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "__support_math_erff",
|
||||
hdrs = ["src/__support/math/erff.h"],
|
||||
@ -3287,7 +3295,7 @@ libc_math_function(name = "dmulf128")
|
||||
libc_math_function(
|
||||
name = "dsqrtl",
|
||||
additional_deps = [
|
||||
":__support_fputil_sqrt",
|
||||
":__support_math_dsqrtl",
|
||||
],
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user