diff --git a/libc/shared/math.h b/libc/shared/math.h index 93f7d6a8156c..84ca04857311 100644 --- a/libc/shared/math.h +++ b/libc/shared/math.h @@ -31,6 +31,7 @@ #include "math/atanhf.h" #include "math/atanhf16.h" #include "math/bf16add.h" +#include "math/bf16addf.h" #include "math/bf16addf128.h" #include "math/canonicalize.h" #include "math/canonicalizebf16.h" diff --git a/libc/shared/math/bf16addf.h b/libc/shared/math/bf16addf.h new file mode 100644 index 000000000000..f952e83f01f5 --- /dev/null +++ b/libc/shared/math/bf16addf.h @@ -0,0 +1,23 @@ +//===-- Shared bf16addf 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_BF16ADDF_H +#define LLVM_LIBC_SHARED_MATH_BF16ADDF_H + +#include "shared/libc_common.h" +#include "src/__support/math/bf16addf.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::bf16addf; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SHARED_MATH_BF16ADDF_H diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt index aaab78c01a89..dbfd129ec773 100644 --- a/libc/src/__support/math/CMakeLists.txt +++ b/libc/src/__support/math/CMakeLists.txt @@ -342,6 +342,16 @@ add_header_library( libc.src.__support.macros.config ) +add_header_library( + bf16addf + HDRS + bf16addf.h + DEPENDS + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.config +) + add_header_library( bf16addf128 HDRS diff --git a/libc/src/__support/math/bf16addf.h b/libc/src/__support/math/bf16addf.h new file mode 100644 index 000000000000..28a836030d12 --- /dev/null +++ b/libc/src/__support/math/bf16addf.h @@ -0,0 +1,26 @@ +//===-- 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___SUPPORT_MATH_BF16ADDF_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_BF16ADDF_H + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace math { + +LIBC_INLINE bfloat16 bf16addf(float x, float y) { + return fputil::generic::add(x, y); +} + +} // namespace math +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_BF16ADDF_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 75b51b4587be..2af80fb7a564 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -5140,11 +5140,7 @@ add_entrypoint_object( 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 + libc.src.__support.math.bf16addf ) add_entrypoint_object( diff --git a/libc/src/math/generic/bf16addf.cpp b/libc/src/math/generic/bf16addf.cpp index 65e6cbf6b150..5447d947fd1a 100644 --- a/libc/src/math/generic/bf16addf.cpp +++ b/libc/src/math/generic/bf16addf.cpp @@ -7,15 +7,12 @@ //===----------------------------------------------------------------------===// #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" +#include "src/__support/math/bf16addf.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(bfloat16, bf16addf, (float x, float y)) { - return fputil::generic::add(x, y); + return math::bf16addf(x, y); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt index 9dfbedee66a3..6fc3b0475513 100644 --- a/libc/test/shared/CMakeLists.txt +++ b/libc/test/shared/CMakeLists.txt @@ -27,6 +27,7 @@ add_fp_unittest( libc.src.__support.math.atanhf libc.src.__support.math.atanhf16 libc.src.__support.math.bf16add + libc.src.__support.math.bf16addf libc.src.__support.math.bf16addf128 libc.src.__support.math.canonicalize libc.src.__support.math.canonicalizebf16 diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp index 2d7ee388f754..3d1d12899bc1 100644 --- a/libc/test/shared/shared_math_test.cpp +++ b/libc/test/shared/shared_math_test.cpp @@ -236,4 +236,5 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) { EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizebf16(&canonicalizebf16_cx, &canonicalizebf16_x)); EXPECT_FP_EQ(bfloat16(0.0), canonicalizebf16_cx); + EXPECT_FP_EQ(bfloat16(5.0), LIBC_NAMESPACE::shared::bf16addf(2.0f, 3.0f)); } diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 608180b90e87..925ecad897e0 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -2645,6 +2645,16 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_math_bf16addf", + hdrs = ["src/__support/math/bf16addf.h"], + deps = [ + ":__support_fputil_basic_operations", + ":__support_fputil_bfloat16", + ":__support_macros_config", + ], +) + libc_support_library( name = "__support_math_bf16addf128", hdrs = ["src/__support/math/bf16addf128.h"], @@ -4413,6 +4423,11 @@ libc_math_function( additional_deps = [":__support_math_bf16add"], ) +libc_math_function( + name = "bf16addf", + additional_deps = [":__support_math_bf16addf"], +) + libc_math_function( name = "bf16addf128", additional_deps = [":__support_math_bf16addf128"],