[libc][math] Refactor bf16addf to header only (#181230)

Resolves #181017 
Part of #147386
This commit is contained in:
Viktor Moros 2026-02-17 16:31:57 -05:00 committed by GitHub
parent 581eb22265
commit 550c48b02e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 80 additions and 10 deletions

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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<bfloat16>(x, y);
}
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_BF16ADDF_H

View File

@ -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(

View File

@ -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<bfloat16>(x, y);
return math::bf16addf(x, y);
}
} // namespace LIBC_NAMESPACE_DECL

View File

@ -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

View File

@ -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));
}

View File

@ -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"],