Skip to content

Commit 7ad2a63

Browse files
1 parent 79f8eba commit 7ad2a63

File tree

9 files changed

+80
-10
lines changed

9 files changed

+80
-10
lines changed

libc/shared/math.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "math/bf16addf.h"
3535
#include "math/bf16addf128.h"
3636
#include "math/bf16divf.h"
37+
#include "math/bf16divl.h"
3738
#include "math/bf16fmaf.h"
3839
#include "math/canonicalize.h"
3940
#include "math/canonicalizebf16.h"

libc/shared/math/bf16divl.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Shared bf16divl function --------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SHARED_MATH_BF16DIVL_H
10+
#define LLVM_LIBC_SHARED_MATH_BF16DIVL_H
11+
12+
#include "shared/libc_common.h"
13+
#include "src/__support/math/bf16divl.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
namespace shared {
17+
18+
using math::bf16divl;
19+
20+
} // namespace shared
21+
} // namespace LIBC_NAMESPACE_DECL
22+
23+
#endif // LLVM_LIBC_SHARED_MATH_BF16DIVL_H

libc/src/__support/math/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,16 @@ add_header_library(
440440
)
441441

442442

443+
add_header_library(
444+
bf16divl
445+
HDRS
446+
bf16divl.h
447+
DEPENDS
448+
libc.src.__support.FPUtil.bfloat16
449+
libc.src.__support.FPUtil.generic.div
450+
libc.src.__support.macros.config
451+
)
452+
443453
add_header_library(
444454
cbrt
445455
HDRS

libc/src/__support/math/bf16divl.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- Implementation header for bf16divl ----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_BF16DIVL_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_BF16DIVL_H
11+
12+
#include "src/__support/FPUtil/bfloat16.h"
13+
#include "src/__support/FPUtil/generic/div.h"
14+
#include "src/__support/macros/config.h"
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
namespace math {
18+
19+
LIBC_INLINE bfloat16 bf16divl(long double x, long double y) {
20+
return fputil::generic::div<bfloat16>(x, y);
21+
}
22+
23+
} // namespace math
24+
} // namespace LIBC_NAMESPACE_DECL
25+
26+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_BF16DIVL_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5171,11 +5171,7 @@ add_entrypoint_object(
51715171
HDRS
51725172
../bf16divl.h
51735173
DEPENDS
5174-
libc.src.__support.common
5175-
libc.src.__support.FPUtil.bfloat16
5176-
libc.src.__support.FPUtil.generic.div
5177-
libc.src.__support.macros.config
5178-
libc.src.__support.macros.properties.types
5174+
libc.src.__support.math.bf16divl
51795175
)
51805176

51815177
add_entrypoint_object(

libc/src/math/generic/bf16divl.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/math/bf16divl.h"
10-
#include "src/__support/FPUtil/bfloat16.h"
11-
#include "src/__support/FPUtil/generic/div.h"
12-
#include "src/__support/common.h"
13-
#include "src/__support/macros/config.h"
10+
#include "src/__support/math/bf16divl.h"
1411

1512
namespace LIBC_NAMESPACE_DECL {
1613

1714
LLVM_LIBC_FUNCTION(bfloat16, bf16divl, (long double x, long double y)) {
18-
return fputil::generic::div<bfloat16>(x, y);
15+
return math::bf16divl(x, y);
1916
}
2017

2118
} // namespace LIBC_NAMESPACE_DECL

libc/test/shared/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ add_fp_unittest(
3030
libc.src.__support.math.bf16addf
3131
libc.src.__support.math.bf16addf128
3232
libc.src.__support.math.bf16divf
33+
libc.src.__support.math.bf16divl
3334
libc.src.__support.math.bf16fmaf
3435
libc.src.__support.math.canonicalize
3536
libc.src.__support.math.canonicalizebf16

libc/test/shared/shared_math_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
245245
TEST(LlvmLibcSharedMathTest, AllBFloat16) {
246246
EXPECT_FP_EQ(bfloat16(5.0), LIBC_NAMESPACE::shared::bf16add(2.0, 3.0));
247247
EXPECT_FP_EQ(bfloat16(2.0f), LIBC_NAMESPACE::shared::bf16divf(4.0f, 2.0f));
248+
EXPECT_FP_EQ(bfloat16(2.0), LIBC_NAMESPACE::shared::bf16divl(6.0L, 3.0L));
248249

249250
bfloat16 canonicalizebf16_cx = bfloat16(0.0);
250251
bfloat16 canonicalizebf16_x = bfloat16(0.0);

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,6 +2675,16 @@ libc_support_library(
26752675
],
26762676
)
26772677

2678+
libc_support_library(
2679+
name = "__support_math_bf16divl",
2680+
hdrs = ["src/__support/math/bf16divl.h"],
2681+
deps = [
2682+
":__support_fputil_basic_operations",
2683+
":__support_fputil_bfloat16",
2684+
":__support_macros_config",
2685+
],
2686+
)
2687+
26782688
libc_support_library(
26792689
name = "__support_math_bf16fmaf",
26802690
hdrs = ["src/__support/math/bf16fmaf.h"],
@@ -4568,6 +4578,11 @@ libc_math_function(
45684578
additional_deps = [":__support_math_bf16addf128"],
45694579
)
45704580

4581+
libc_math_function(
4582+
name = "bf16divl",
4583+
additional_deps = [":__support_math_bf16divl"],
4584+
)
4585+
45714586
libc_math_function(
45724587
name = "bf16fmaf",
45734588
additional_deps = [":__support_math_bf16fmaf"],

0 commit comments

Comments
 (0)