[libc][math] Refactor bf16addf to header only (#181230)
Resolves #181017 Part of #147386
This commit is contained in:
parent
581eb22265
commit
550c48b02e
@ -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"
|
||||
|
||||
23
libc/shared/math/bf16addf.h
Normal file
23
libc/shared/math/bf16addf.h
Normal 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
|
||||
@ -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
|
||||
|
||||
26
libc/src/__support/math/bf16addf.h
Normal file
26
libc/src/__support/math/bf16addf.h
Normal 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
|
||||
@ -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(
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
@ -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"],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user