diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 066dc21497691..0a2b24b420ac2 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -896,6 +896,12 @@ endif() list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints libc.src.math.ceilbf16 + libc.src.math.bf16add + libc.src.math.bf16addf + libc.src.math.bf16addl + libc.src.math.bf16sub + libc.src.math.bf16subf + libc.src.math.bf16subl libc.src.math.fabsbf16 libc.src.math.floorbf16 libc.src.math.roundbf16 @@ -903,6 +909,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.truncbf16 ) +if(LIBC_TYPES_HAS_FLOAT128) + list(APPEND TARGET_LIBM_ENTRYPOINTS + # math.h C++23 mixed bfloat16 and _Float128 entrypoints + libc.src.math.bf16addf128 + libc.src.math.bf16subf128 + ) +endif() + if(LIBC_COMPILER_HAS_FIXED_POINT) list(APPEND TARGET_LIBM_ENTRYPOINTS # stdfix.h _Fract and _Accum entrypoints diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index c3840d3c4aa89..660c3681717c8 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -563,3 +563,13 @@ add_math_entrypoint_object(ufromfpxf) add_math_entrypoint_object(ufromfpxl) add_math_entrypoint_object(ufromfpxf16) add_math_entrypoint_object(ufromfpxf128) + +add_math_entrypoint_object(bf16add) +add_math_entrypoint_object(bf16addf) +add_math_entrypoint_object(bf16addl) +add_math_entrypoint_object(bf16addf128) + +add_math_entrypoint_object(bf16sub) +add_math_entrypoint_object(bf16subf) +add_math_entrypoint_object(bf16subl) +add_math_entrypoint_object(bf16subf128) diff --git a/libc/src/math/bf16add.h b/libc/src/math/bf16add.h new file mode 100644 index 0000000000000..a29970eb334fa --- /dev/null +++ b/libc/src/math/bf16add.h @@ -0,0 +1,21 @@ +//===-- Implementation header for bf16add -----------------------*- 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_MATH_BF16ADD_H +#define LLVM_LIBC_SRC_MATH_BF16ADD_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 bf16add(double x, double y); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_BF16ADD_H diff --git a/libc/src/math/bf16addf.h b/libc/src/math/bf16addf.h new file mode 100644 index 0000000000000..80a5e2a7640df --- /dev/null +++ b/libc/src/math/bf16addf.h @@ -0,0 +1,21 @@ +//===-- Implementation header for bf16addf ----------------------*- 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_MATH_BF16ADDF_H +#define LLVM_LIBC_SRC_MATH_BF16ADDF_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 bf16addf(float x, float y); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_BF16ADDF_H diff --git a/libc/src/math/bf16addf128.h b/libc/src/math/bf16addf128.h new file mode 100644 index 0000000000000..3c2f3a15eb39c --- /dev/null +++ b/libc/src/math/bf16addf128.h @@ -0,0 +1,21 @@ +//===-- Implementation header for bf16addf128 -------------------*- 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_MATH_BF16ADDF128_H +#define LLVM_LIBC_SRC_MATH_BF16ADDF128_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 bf16addf128(float128 x, float128 y); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_BF16ADDF128_H diff --git a/libc/src/math/bf16addl.h b/libc/src/math/bf16addl.h new file mode 100644 index 0000000000000..a9e7d68660728 --- /dev/null +++ b/libc/src/math/bf16addl.h @@ -0,0 +1,21 @@ +//===-- Implementation header for bf16addl ----------------------*- 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_MATH_BF16ADDL_H +#define LLVM_LIBC_SRC_MATH_BF16ADDL_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 bf16addl(long double x, long double y); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_BF16ADDL_H diff --git a/libc/src/math/bf16sub.h b/libc/src/math/bf16sub.h new file mode 100644 index 0000000000000..8108e9146859f --- /dev/null +++ b/libc/src/math/bf16sub.h @@ -0,0 +1,21 @@ +//===-- Implementation header for bf16sub -----------------------*- 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_MATH_BF16SUB_H +#define LLVM_LIBC_SRC_MATH_BF16SUB_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 bf16sub(double x, double y); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_BF16SUB_H diff --git a/libc/src/math/bf16subf.h b/libc/src/math/bf16subf.h new file mode 100644 index 0000000000000..1bd79bfe119ce --- /dev/null +++ b/libc/src/math/bf16subf.h @@ -0,0 +1,21 @@ +//===-- Implementation header for bf16subf ----------------------*- 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_MATH_BF16SUBF_H +#define LLVM_LIBC_SRC_MATH_BF16SUBF_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 bf16subf(float x, float y); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_BF16SUBF_H diff --git a/libc/src/math/bf16subf128.h b/libc/src/math/bf16subf128.h new file mode 100644 index 0000000000000..19590e8c67508 --- /dev/null +++ b/libc/src/math/bf16subf128.h @@ -0,0 +1,21 @@ +//===-- Implementation header for bf16subf128 -------------------*- 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_MATH_BF16SUBF128_H +#define LLVM_LIBC_SRC_MATH_BF16SUBF128_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 bf16subf128(float128 x, float128 y); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_BF16SUBF128_H diff --git a/libc/src/math/bf16subl.h b/libc/src/math/bf16subl.h new file mode 100644 index 0000000000000..13b2093a92ffa --- /dev/null +++ b/libc/src/math/bf16subl.h @@ -0,0 +1,21 @@ +//===-- Implementation header for bf16subl ----------------------*- 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_MATH_BF16SUBL_H +#define LLVM_LIBC_SRC_MATH_BF16SUBL_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 bf16subl(long double x, long double y); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_BF16SUBL_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 893606609dfc3..5aeacc85d4d5e 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -4911,3 +4911,116 @@ add_header_library( libc.src.__support.math.expf16_utils libc.src.__support.math.exp10_float16_constants ) + +add_entrypoint_object( + bf16add + SRCS + bf16add.cpp + HDRS + ../bf16add.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) + +add_entrypoint_object( + bf16addf + SRCS + bf16addf.cpp + HDRS + ../bf16addf.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) + +add_entrypoint_object( + bf16addl + SRCS + bf16addl.cpp + HDRS + ../bf16addl.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) + +add_entrypoint_object( + bf16addf128 + SRCS + bf16addf128.cpp + HDRS + ../bf16addf128.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) + + +add_entrypoint_object( + bf16sub + SRCS + bf16sub.cpp + HDRS + ../bf16sub.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) + +add_entrypoint_object( + bf16subf + SRCS + bf16subf.cpp + HDRS + ../bf16subf.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) + +add_entrypoint_object( + bf16subl + SRCS + bf16subl.cpp + HDRS + ../bf16subl.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) + +add_entrypoint_object( + bf16subf128 + SRCS + bf16subf128.cpp + HDRS + ../bf16subf128.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) diff --git a/libc/src/math/generic/bf16add.cpp b/libc/src/math/generic/bf16add.cpp new file mode 100644 index 0000000000000..257596afe66cf --- /dev/null +++ b/libc/src/math/generic/bf16add.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of bf16add function --------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "src/math/bf16add.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, bf16add, (double x, double y)) { + return fputil::generic::add(x, y); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/bf16addf.cpp b/libc/src/math/generic/bf16addf.cpp new file mode 100644 index 0000000000000..65e6cbf6b1507 --- /dev/null +++ b/libc/src/math/generic/bf16addf.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of bf16addf function -------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "src/math/bf16addf.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, bf16addf, (float x, float y)) { + return fputil::generic::add(x, y); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/bf16addf128.cpp b/libc/src/math/generic/bf16addf128.cpp new file mode 100644 index 0000000000000..03f70af82e892 --- /dev/null +++ b/libc/src/math/generic/bf16addf128.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of bf16addf128 function ----------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "src/math/bf16addf128.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, bf16addf128, (float128 x, float128 y)) { + return fputil::generic::add(x, y); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/bf16addl.cpp b/libc/src/math/generic/bf16addl.cpp new file mode 100644 index 0000000000000..c212195c2b7c8 --- /dev/null +++ b/libc/src/math/generic/bf16addl.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of bf16addl function -------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "src/math/bf16addl.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, bf16addl, (long double x, long double y)) { + return fputil::generic::add(x, y); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/bf16sub.cpp b/libc/src/math/generic/bf16sub.cpp new file mode 100644 index 0000000000000..65eb2095dd4e9 --- /dev/null +++ b/libc/src/math/generic/bf16sub.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of bf16sub function --------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "src/math/bf16sub.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, bf16sub, (double x, double y)) { + return fputil::generic::sub(x, y); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/bf16subf.cpp b/libc/src/math/generic/bf16subf.cpp new file mode 100644 index 0000000000000..6bba4be441be6 --- /dev/null +++ b/libc/src/math/generic/bf16subf.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of bf16subf function -------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "src/math/bf16subf.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, bf16subf, (float x, float y)) { + return fputil::generic::sub(x, y); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/bf16subf128.cpp b/libc/src/math/generic/bf16subf128.cpp new file mode 100644 index 0000000000000..e5fe1077f89a7 --- /dev/null +++ b/libc/src/math/generic/bf16subf128.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of bf16subf128 function ----------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "src/math/bf16subf128.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, bf16subf128, (float128 x, float128 y)) { + return fputil::generic::sub(x, y); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/bf16subl.cpp b/libc/src/math/generic/bf16subl.cpp new file mode 100644 index 0000000000000..d3a970cade922 --- /dev/null +++ b/libc/src/math/generic/bf16subl.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of bf16subl function -------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "src/math/bf16subl.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, bf16subl, (long double x, long double y)) { + return fputil::generic::sub(x, y); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index 43cde0d68873e..a74f9fe471963 100644 --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -2972,6 +2972,118 @@ add_fp_unittest( libc.src.__support.macros.properties.types ) +add_fp_unittest( + bf16add_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16add_test.cpp + HDRS + AddTest.h + DEPENDS + libc.src.math.bf16add + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16addf_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16addf_test.cpp + HDRS + AddTest.h + DEPENDS + libc.src.math.bf16addf + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16addl_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16addl_test.cpp + HDRS + AddTest.h + DEPENDS + libc.src.math.bf16addl + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16addf128_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16addf128_test.cpp + HDRS + AddTest.h + DEPENDS + libc.src.math.bf16addf128 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16sub_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16sub_test.cpp + HDRS + SubTest.h + DEPENDS + libc.src.math.bf16sub + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16subf_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16subf_test.cpp + HDRS + SubTest.h + DEPENDS + libc.src.math.bf16subf + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16subl_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16subl_test.cpp + HDRS + SubTest.h + DEPENDS + libc.src.math.bf16subl + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16subf128_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16subf128_test.cpp + HDRS + SubTest.h + DEPENDS + libc.src.math.bf16subf128 + libc.src.__support.FPUtil.bfloat16 +) + add_subdirectory(generic) add_subdirectory(smoke) diff --git a/libc/test/src/math/bf16add_test.cpp b/libc/test/src/math/bf16add_test.cpp new file mode 100644 index 0000000000000..9e9c594d7d7eb --- /dev/null +++ b/libc/test/src/math/bf16add_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16add ---------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "AddTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16add.h" + +LIST_ADD_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16add) diff --git a/libc/test/src/math/bf16addf128_test.cpp b/libc/test/src/math/bf16addf128_test.cpp new file mode 100644 index 0000000000000..46f7ad329f237 --- /dev/null +++ b/libc/test/src/math/bf16addf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16addf128 -----------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "AddTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16addf128.h" + +LIST_ADD_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16addf128) diff --git a/libc/test/src/math/bf16addf_test.cpp b/libc/test/src/math/bf16addf_test.cpp new file mode 100644 index 0000000000000..06d56cf21ebd2 --- /dev/null +++ b/libc/test/src/math/bf16addf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16addf --------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "AddTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16addf.h" + +LIST_ADD_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16addf) diff --git a/libc/test/src/math/bf16addl_test.cpp b/libc/test/src/math/bf16addl_test.cpp new file mode 100644 index 0000000000000..bf548272d31c1 --- /dev/null +++ b/libc/test/src/math/bf16addl_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16addl --------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "AddTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16addl.h" + +LIST_ADD_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16addl) diff --git a/libc/test/src/math/bf16sub_test.cpp b/libc/test/src/math/bf16sub_test.cpp new file mode 100644 index 0000000000000..4a793dc493891 --- /dev/null +++ b/libc/test/src/math/bf16sub_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16sub ---------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "SubTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16sub.h" + +LIST_SUB_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16sub) diff --git a/libc/test/src/math/bf16subf128_test.cpp b/libc/test/src/math/bf16subf128_test.cpp new file mode 100644 index 0000000000000..25d6711f71346 --- /dev/null +++ b/libc/test/src/math/bf16subf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16subf128 -----------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "SubTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16subf128.h" + +LIST_SUB_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16subf128) diff --git a/libc/test/src/math/bf16subf_test.cpp b/libc/test/src/math/bf16subf_test.cpp new file mode 100644 index 0000000000000..e8c7440230f1d --- /dev/null +++ b/libc/test/src/math/bf16subf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16subf --------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "SubTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16subf.h" + +LIST_SUB_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16subf) diff --git a/libc/test/src/math/bf16subl_test.cpp b/libc/test/src/math/bf16subl_test.cpp new file mode 100644 index 0000000000000..299736949d713 --- /dev/null +++ b/libc/test/src/math/bf16subl_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16subl --------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "SubTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16subl.h" + +LIST_SUB_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16subl) diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index 5f497c63759f4..dc1850aaa68e2 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -5465,3 +5465,131 @@ add_fp_unittest( libc.src.__support.macros.properties.os libc.src.__support.macros.properties.types ) + +add_fp_unittest( + bf16add_test + SUITE + libc-math-smoke-tests + SRCS + bf16add_test.cpp + HDRS + AddTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16add + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16addf_test + SUITE + libc-math-smoke-tests + SRCS + bf16addf_test.cpp + HDRS + AddTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16addf + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16addl_test + SUITE + libc-math-smoke-tests + SRCS + bf16addl_test.cpp + HDRS + AddTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16addl + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16addf128_test + SUITE + libc-math-smoke-tests + SRCS + bf16addf128_test.cpp + HDRS + AddTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16addf128 + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16sub_test + SUITE + libc-math-smoke-tests + SRCS + bf16sub_test.cpp + HDRS + SubTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16sub + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16subf_test + SUITE + libc-math-smoke-tests + SRCS + bf16subf_test.cpp + HDRS + SubTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16subf + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16subl_test + SUITE + libc-math-smoke-tests + SRCS + bf16subl_test.cpp + HDRS + SubTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16subl + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16subf128_test + SUITE + libc-math-smoke-tests + SRCS + bf16subf128_test.cpp + HDRS + SubTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16subf128 + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) diff --git a/libc/test/src/math/smoke/bf16add_test.cpp b/libc/test/src/math/smoke/bf16add_test.cpp new file mode 100644 index 0000000000000..9e9c594d7d7eb --- /dev/null +++ b/libc/test/src/math/smoke/bf16add_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16add ---------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "AddTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16add.h" + +LIST_ADD_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16add) diff --git a/libc/test/src/math/smoke/bf16addf128_test.cpp b/libc/test/src/math/smoke/bf16addf128_test.cpp new file mode 100644 index 0000000000000..46f7ad329f237 --- /dev/null +++ b/libc/test/src/math/smoke/bf16addf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16addf128 -----------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "AddTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16addf128.h" + +LIST_ADD_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16addf128) diff --git a/libc/test/src/math/smoke/bf16addf_test.cpp b/libc/test/src/math/smoke/bf16addf_test.cpp new file mode 100644 index 0000000000000..06d56cf21ebd2 --- /dev/null +++ b/libc/test/src/math/smoke/bf16addf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16addf --------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "AddTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16addf.h" + +LIST_ADD_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16addf) diff --git a/libc/test/src/math/smoke/bf16addl_test.cpp b/libc/test/src/math/smoke/bf16addl_test.cpp new file mode 100644 index 0000000000000..bf548272d31c1 --- /dev/null +++ b/libc/test/src/math/smoke/bf16addl_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16addl --------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "AddTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16addl.h" + +LIST_ADD_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16addl) diff --git a/libc/test/src/math/smoke/bf16sub_test.cpp b/libc/test/src/math/smoke/bf16sub_test.cpp new file mode 100644 index 0000000000000..4a793dc493891 --- /dev/null +++ b/libc/test/src/math/smoke/bf16sub_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16sub ---------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "SubTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16sub.h" + +LIST_SUB_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16sub) diff --git a/libc/test/src/math/smoke/bf16subf128_test.cpp b/libc/test/src/math/smoke/bf16subf128_test.cpp new file mode 100644 index 0000000000000..25d6711f71346 --- /dev/null +++ b/libc/test/src/math/smoke/bf16subf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16subf128 -----------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "SubTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16subf128.h" + +LIST_SUB_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16subf128) diff --git a/libc/test/src/math/smoke/bf16subf_test.cpp b/libc/test/src/math/smoke/bf16subf_test.cpp new file mode 100644 index 0000000000000..e8c7440230f1d --- /dev/null +++ b/libc/test/src/math/smoke/bf16subf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16subf --------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "SubTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16subf.h" + +LIST_SUB_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16subf) diff --git a/libc/test/src/math/smoke/bf16subl_test.cpp b/libc/test/src/math/smoke/bf16subl_test.cpp new file mode 100644 index 0000000000000..299736949d713 --- /dev/null +++ b/libc/test/src/math/smoke/bf16subl_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16subl --------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "SubTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16subl.h" + +LIST_SUB_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16subl) diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp index ae12a83e9faa1..57e818ca3d9c3 100644 --- a/libc/utils/MPFRWrapper/MPFRUtils.cpp +++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp @@ -411,6 +411,21 @@ template void explain_binary_operation_one_output_error( #endif template void explain_binary_operation_one_output_error( Operation, const BinaryInput &, bfloat16, double, RoundingMode); +template void +explain_binary_operation_one_output_error(Operation, const BinaryInput &, + bfloat16, double, RoundingMode); +template void explain_binary_operation_one_output_error( + Operation, const BinaryInput &, bfloat16, double, RoundingMode); +template void +explain_binary_operation_one_output_error(Operation, + const BinaryInput &, + bfloat16, double, RoundingMode); +#if defined(LIBC_TYPES_HAS_FLOAT128) && \ + defined(LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE) +template void explain_binary_operation_one_output_error( + Operation, const BinaryInput &, bfloat16, double, RoundingMode); +#endif // defined(LIBC_TYPES_HAS_FLOAT128) && + // defined(LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE) template void explain_ternary_operation_one_output_error( @@ -648,6 +663,26 @@ template bool compare_binary_operation_one_output(Operation, const BinaryInput &, bfloat16, double, RoundingMode); + +template bool compare_binary_operation_one_output(Operation, + const BinaryInput &, + bfloat16, double, + RoundingMode); +template bool compare_binary_operation_one_output(Operation, + const BinaryInput &, + bfloat16, double, + RoundingMode); +template bool +compare_binary_operation_one_output(Operation, const BinaryInput &, + bfloat16, double, RoundingMode); +#if defined(LIBC_TYPES_HAS_FLOAT128) && \ + defined(LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE) +template bool compare_binary_operation_one_output(Operation, + const BinaryInput &, + bfloat16, double, + RoundingMode); +#endif // defined(LIBC_TYPES_HAS_FLOAT128) && + // defined(LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE) template bool compare_ternary_operation_one_output(Operation op, const TernaryInput &input,