Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/shared/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "math/bf16addl.h"
#include "math/bf16div.h"
#include "math/bf16divf.h"
#include "math/bf16divf128.h"
#include "math/bf16divl.h"
#include "math/bf16fmaf.h"
#include "math/bf16fmaf128.h"
Expand Down
26 changes: 26 additions & 0 deletions libc/shared/math/bf16divf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===-- Shared bf16divf128 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_BF16DIVF128_H
#define LLVM_LIBC_SHARED_MATH_BF16DIVF128_H

#include "shared/libc_common.h"
#include "src/__support/math/bf16divf128.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

#ifdef LIBC_TYPES_HAS_FLOAT128
using math::bf16divf128;
#endif // LIBC_TYPES_HAS_FLOAT128

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_BF16DIVF128_H
12 changes: 12 additions & 0 deletions libc/src/__support/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,18 @@ add_header_library(
libc.src.__support.macros.config
)

add_header_library(
bf16divf128
HDRS
bf16divf128.h
DEPENDS
libc.include.llvm-libc-types.float128
libc.src.__support.FPUtil.bfloat16
libc.src.__support.FPUtil.generic.div
libc.src.__support.macros.config
libc.src.__support.macros.properties.types
)

add_header_library(
bf16fmaf
HDRS
Expand Down
27 changes: 27 additions & 0 deletions libc/src/__support/math/bf16divf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===-- Implementation header for bf16divf128 -------------------*- 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_BF16DIVF128_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_BF16DIVF128_H

#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/generic/div.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {
namespace math {

#ifdef LIBC_TYPES_HAS_FLOAT128
LIBC_INLINE constexpr bfloat16 bf16divf128(float128 x, float128 y) {
return fputil::generic::div<bfloat16>(x, y);
}
#endif // LIBC_TYPES_HAS_FLOAT128

} // namespace math
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC___SUPPORT_MATH_BF16DIVF128_H
6 changes: 3 additions & 3 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5140,12 +5140,12 @@ add_entrypoint_object(
bf16divf128.cpp
HDRS
../bf16divf128.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.common
libc.src.__support.FPUtil.bfloat16
libc.src.__support.FPUtil.generic.div
libc.src.__support.macros.config
libc.src.__support.macros.properties.types
libc.src.__support.math.bf16divf128
)

add_entrypoint_object(
Expand Down
5 changes: 2 additions & 3 deletions libc/src/math/generic/bf16divf128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
//===----------------------------------------------------------------------===//

#include "src/math/bf16divf128.h"
#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/generic/div.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/math/bf16divf128.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(bfloat16, bf16divf128, (float128 x, float128 y)) {
return fputil::generic::div<bfloat16>(x, y);
return math::bf16divf128(x, y);
}

} // namespace LIBC_NAMESPACE_DECL
1 change: 1 addition & 0 deletions libc/test/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ add_fp_unittest(
libc.src.__support.math.bf16addf128
libc.src.__support.math.bf16div
libc.src.__support.math.bf16divf
libc.src.__support.math.bf16divf128
libc.src.__support.math.bf16divl
libc.src.__support.math.bf16fmaf
libc.src.__support.math.bf16fmaf128
Expand Down
4 changes: 4 additions & 0 deletions libc/test/shared/shared_math_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
EXPECT_FP_EQ(bfloat16(2.0f), LIBC_NAMESPACE::shared::bf16divf(4.0f, 2.0f));
EXPECT_FP_EQ(bfloat16(2.0), LIBC_NAMESPACE::shared::bf16divl(6.0L, 3.0L));
EXPECT_FP_EQ(bfloat16(2.0), LIBC_NAMESPACE::shared::bf16div(4.0, 2.0));
#ifdef LIBC_TYPES_HAS_FLOAT128
EXPECT_FP_EQ(bfloat16(2.0), LIBC_NAMESPACE::shared::bf16divf128(
float128(4.0), float128(2.0)));
#endif
EXPECT_FP_EQ(bfloat16(10.0),
LIBC_NAMESPACE::shared::bf16fmal(2.0L, 3.0L, 4.0L));

Expand Down
18 changes: 18 additions & 0 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3178,6 +3178,17 @@ libc_support_library(
],
)

libc_support_library(
name = "__support_math_bf16divf128",
hdrs = ["src/__support/math/bf16divf128.h"],
deps = [
":__support_fputil_basic_operations",
":__support_fputil_bfloat16",
":__support_macros_config",
":llvm_libc_types_float128",
],
)

libc_support_library(
name = "__support_math_bf16fmaf",
hdrs = ["src/__support/math/bf16fmaf.h"],
Expand Down Expand Up @@ -6300,6 +6311,13 @@ libc_math_function(
],
)

libc_math_function(
name = "bf16divf128",
additional_deps = [
":__support_math_bf16divf128",
],
)

libc_math_function(
name = "canonicalizef",
additional_deps = [
Expand Down
Loading