diff --git a/libc/shared/math.h b/libc/shared/math.h index 01233cb6ef30..ef006c668f3a 100644 --- a/libc/shared/math.h +++ b/libc/shared/math.h @@ -75,6 +75,8 @@ #include "math/coshf16.h" #include "math/cospif.h" #include "math/cospif16.h" +#include "math/daddf128.h" +#include "math/daddl.h" #include "math/dfmaf128.h" #include "math/dfmal.h" #include "math/dsqrtl.h" diff --git a/libc/shared/math/daddf128.h b/libc/shared/math/daddf128.h new file mode 100644 index 000000000000..ae0fd22e6f8e --- /dev/null +++ b/libc/shared/math/daddf128.h @@ -0,0 +1,29 @@ +//===-- Shared daddf128 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_DADDF128_H +#define LLVM_LIBC_SHARED_MATH_DADDF128_H + +#include "include/llvm-libc-types/float128.h" + +#ifdef LIBC_TYPES_HAS_FLOAT128 + +#include "shared/libc_common.h" +#include "src/__support/math/daddf128.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::daddf128; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_HAS_FLOAT128 + +#endif // LLVM_LIBC_SHARED_MATH_DADDF128_H diff --git a/libc/shared/math/daddl.h b/libc/shared/math/daddl.h new file mode 100644 index 000000000000..4ad4444e06fb --- /dev/null +++ b/libc/shared/math/daddl.h @@ -0,0 +1,23 @@ +//===-- Shared daddl 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_DADDL_H +#define LLVM_LIBC_SHARED_MATH_DADDL_H + +#include "shared/libc_common.h" +#include "src/__support/math/daddl.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::daddl; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SHARED_MATH_DADDL_H diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt index 4fe6232e8a8c..abac483e40fa 100644 --- a/libc/src/__support/math/CMakeLists.txt +++ b/libc/src/__support/math/CMakeLists.txt @@ -881,6 +881,25 @@ add_header_library( libc.src.__support.macros.optimization ) +add_header_library( + daddf128 + HDRS + daddf128.h + DEPENDS + libc.include.llvm-libc-types.float128 + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.config +) + +add_header_library( + daddl + HDRS + daddl.h + DEPENDS + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.config +) + add_header_library( dsqrtl HDRS diff --git a/libc/src/__support/math/daddf128.h b/libc/src/__support/math/daddf128.h new file mode 100644 index 000000000000..3937250e5c6b --- /dev/null +++ b/libc/src/__support/math/daddf128.h @@ -0,0 +1,31 @@ +//===-- Implementation header for daddf128 ----------------------*- 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_DADDF128_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_DADDF128_H + +#include "include/llvm-libc-types/float128.h" + +#ifdef LIBC_TYPES_HAS_FLOAT128 + +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace math { + +LIBC_INLINE double daddf128(float128 x, float128 y) { + return fputil::generic::add(x, y); +} + +} // namespace math +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_HAS_FLOAT128 + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DADDF128_H diff --git a/libc/src/__support/math/daddl.h b/libc/src/__support/math/daddl.h new file mode 100644 index 000000000000..e8bec7b975fb --- /dev/null +++ b/libc/src/__support/math/daddl.h @@ -0,0 +1,25 @@ +//===-- Implementation header for daddl -------------------------*- 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_DADDL_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_DADDL_H + +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace math { + +LIBC_INLINE double daddl(long double x, long double y) { + return fputil::generic::add(x, y); +} + +} // namespace math +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DADDL_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 9b3c6814a223..8aaeea0565ee 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -185,7 +185,7 @@ add_entrypoint_object( HDRS ../daddl.h DEPENDS - libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.math.daddl ) add_entrypoint_object( @@ -195,8 +195,7 @@ add_entrypoint_object( HDRS ../daddf128.h DEPENDS - libc.src.__support.macros.properties.types - libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.math.daddf128 ) add_entrypoint_object( diff --git a/libc/src/math/generic/daddf128.cpp b/libc/src/math/generic/daddf128.cpp index 6edba3b8f5e4..10b3ec6c30c6 100644 --- a/libc/src/math/generic/daddf128.cpp +++ b/libc/src/math/generic/daddf128.cpp @@ -7,14 +7,12 @@ //===----------------------------------------------------------------------===// #include "src/math/daddf128.h" -#include "src/__support/FPUtil/generic/add_sub.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" +#include "src/__support/math/daddf128.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(double, daddf128, (float128 x, float128 y)) { - return fputil::generic::add(x, y); + return math::daddf128(x, y); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/daddl.cpp b/libc/src/math/generic/daddl.cpp index 708de3833869..3bafa1ee301e 100644 --- a/libc/src/math/generic/daddl.cpp +++ b/libc/src/math/generic/daddl.cpp @@ -7,14 +7,12 @@ //===----------------------------------------------------------------------===// #include "src/math/daddl.h" -#include "src/__support/FPUtil/generic/add_sub.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" +#include "src/__support/math/daddl.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(double, daddl, (long double x, long double y)) { - return fputil::generic::add(x, y); + return math::daddl(x, y); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt index 2777c2dddfd7..bfacee9cecac 100644 --- a/libc/test/shared/CMakeLists.txt +++ b/libc/test/shared/CMakeLists.txt @@ -72,6 +72,8 @@ add_fp_unittest( libc.src.__support.math.coshf16 libc.src.__support.math.cospif libc.src.__support.math.cospif16 + libc.src.__support.math.daddf128 + libc.src.__support.math.daddl libc.src.__support.math.dfmaf128 libc.src.__support.math.dfmal libc.src.__support.math.dsqrtl diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp index 0bbf8aa15338..d958529d04fb 100644 --- a/libc/test/shared/shared_math_test.cpp +++ b/libc/test/shared/shared_math_test.cpp @@ -316,6 +316,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) { EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::bf16mull(0.0L, 0.0L)); EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::ceill(0.0L)); + EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::daddl(0.0L, 0.0L)); EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::faddl(0.0L, 0.0L)); EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fdiml(0.0L, 0.0L)); EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::floorl(0.0L)); @@ -375,6 +376,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) { EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef128(&canonicalizef128_cx, &canonicalizef128_x)); EXPECT_FP_EQ(float128(0.0), canonicalizef128_cx); + EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::bf16subf128( float128(0.0), float128(0.0))); EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::bf16fmaf128( @@ -384,6 +386,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) { EXPECT_FP_EQ(bfloat16(2.0), LIBC_NAMESPACE::shared::bf16divf128( float128(4.0), float128(2.0))); EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::ceilf128(float128(0.0))); + EXPECT_FP_EQ(float128(0.0), + LIBC_NAMESPACE::shared::daddf128(float128(0.0), float128(0.0))); EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::faddf128(float128(0.0), float128(0.0))); EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::floorf128(float128(0.0))); diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 852481640124..b90b37429b12 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -3716,6 +3716,25 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_math_daddf128", + hdrs = ["src/__support/math/daddf128.h"], + deps = [ + ":__support_fputil_basic_operations", + ":__support_macros_config", + ":llvm_libc_types_float128", + ], +) + +libc_support_library( + name = "__support_math_daddl", + hdrs = ["src/__support/math/daddl.h"], + deps = [ + ":__support_fputil_basic_operations", + ":__support_macros_config", + ], +) + libc_support_library( name = "__support_math_dsqrtl", hdrs = ["src/__support/math/dsqrtl.h"], @@ -6646,10 +6665,18 @@ libc_math_function( ], ) -libc_math_function(name = "daddl") +libc_math_function( + name = "daddl", + additional_deps = [ + ":__support_math_daddl", + ], +) libc_math_function( name = "daddf128", + additional_deps = [ + ":__support_math_daddf128", + ], ) libc_math_function(name = "ddivl")