[libc-commits] [libc] c819c24 - [libc][math][c++23] Add bf16div{, f, l, f128} math functions (#153191)

via libc-commits libc-commits at lists.llvm.org
Tue Aug 12 09:16:25 PDT 2025


Author: Krishna Pandey
Date: 2025-08-12T21:46:22+05:30
New Revision: c819c246f3bb3acc6d3b79ca299a94b1d70c8ba6

URL: https://github.com/llvm/llvm-project/commit/c819c246f3bb3acc6d3b79ca299a94b1d70c8ba6
DIFF: https://github.com/llvm/llvm-project/commit/c819c246f3bb3acc6d3b79ca299a94b1d70c8ba6.diff

LOG: [libc][math][c++23] Add bf16div{,f,l,f128} math functions (#153191)

This PR adds the following basic math functions for BFloat16 type along
with the tests:
- bf16div
- bf16divf
- bf16divl
- bf16divf128

---------

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>

Added: 
    libc/src/math/bf16div.h
    libc/src/math/bf16divf.h
    libc/src/math/bf16divf128.h
    libc/src/math/bf16divl.h
    libc/src/math/generic/bf16div.cpp
    libc/src/math/generic/bf16divf.cpp
    libc/src/math/generic/bf16divf128.cpp
    libc/src/math/generic/bf16divl.cpp
    libc/test/src/math/bf16div_test.cpp
    libc/test/src/math/bf16divf128_test.cpp
    libc/test/src/math/bf16divf_test.cpp
    libc/test/src/math/bf16divl_test.cpp
    libc/test/src/math/smoke/bf16div_test.cpp
    libc/test/src/math/smoke/bf16divf128_test.cpp
    libc/test/src/math/smoke/bf16divf_test.cpp
    libc/test/src/math/smoke/bf16divl_test.cpp

Modified: 
    libc/config/baremetal/aarch64/entrypoints.txt
    libc/config/baremetal/arm/entrypoints.txt
    libc/config/baremetal/riscv/entrypoints.txt
    libc/config/darwin/aarch64/entrypoints.txt
    libc/config/darwin/x86_64/entrypoints.txt
    libc/config/gpu/amdgpu/entrypoints.txt
    libc/config/gpu/nvptx/entrypoints.txt
    libc/config/linux/aarch64/entrypoints.txt
    libc/config/linux/arm/entrypoints.txt
    libc/config/linux/riscv/entrypoints.txt
    libc/config/linux/x86_64/entrypoints.txt
    libc/config/windows/entrypoints.txt
    libc/src/math/CMakeLists.txt
    libc/src/math/generic/CMakeLists.txt
    libc/test/src/math/CMakeLists.txt
    libc/test/src/math/smoke/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index f32132a53fc4a..007d64d3fcd7c 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -760,6 +760,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
+  libc.src.math.bf16div
+  libc.src.math.bf16divf
+  libc.src.math.bf16divl
   libc.src.math.bf16mul
   libc.src.math.bf16mulf
   libc.src.math.bf16mull
@@ -788,6 +791,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # math.h C++23 mixed bfloat16 and _Float128 entrypoints
     libc.src.math.bf16addf128
+    libc.src.math.bf16divf128
     libc.src.math.bf16mulf128
     libc.src.math.bf16subf128
   )

diff  --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 1194f52a7f6b1..6c1f52a8f1ca2 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -763,6 +763,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
+  libc.src.math.bf16div
+  libc.src.math.bf16divf
+  libc.src.math.bf16divl
   libc.src.math.bf16mul
   libc.src.math.bf16mulf
   libc.src.math.bf16mull
@@ -791,6 +794,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # math.h C++23 mixed bfloat16 and _Float128 entrypoints
     libc.src.math.bf16addf128
+    libc.src.math.bf16divf128
     libc.src.math.bf16mulf128
     libc.src.math.bf16subf128
   )

diff  --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index c98d68a7a38cb..d1412762333de 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -763,6 +763,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
+  libc.src.math.bf16div
+  libc.src.math.bf16divf
+  libc.src.math.bf16divl
   libc.src.math.bf16mul
   libc.src.math.bf16mulf
   libc.src.math.bf16mull
@@ -791,6 +794,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # math.h C++23 mixed bfloat16 and _Float128 entrypoints
     libc.src.math.bf16addf128
+    libc.src.math.bf16divf128
     libc.src.math.bf16mulf128
     libc.src.math.bf16subf128
   )

diff  --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 99fe0cdd53f25..57c09f0725048 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -593,6 +593,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
+  libc.src.math.bf16div
+  libc.src.math.bf16divf
+  libc.src.math.bf16divl
   libc.src.math.bf16mul
   libc.src.math.bf16mulf
   libc.src.math.bf16mull

diff  --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 30a064ec57bb0..9b207fd734e99 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -236,6 +236,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
+  libc.src.math.bf16div
+  libc.src.math.bf16divf
+  libc.src.math.bf16divl
   libc.src.math.bf16mul
   libc.src.math.bf16mulf
   libc.src.math.bf16mull

diff  --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index bbba0c2160e13..8981190cfe1bc 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -619,6 +619,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
+  libc.src.math.bf16div
+  libc.src.math.bf16divf
+  libc.src.math.bf16divl
   libc.src.math.bf16mul
   libc.src.math.bf16mulf
   libc.src.math.bf16mull

diff  --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 8cc97e977de5a..dc23742652783 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -620,6 +620,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
+  libc.src.math.bf16div
+  libc.src.math.bf16divf
+  libc.src.math.bf16divl
   libc.src.math.bf16mul
   libc.src.math.bf16mulf
   libc.src.math.bf16mull

diff  --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index c537bd0959750..5f687525271ee 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -847,6 +847,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
+  libc.src.math.bf16div
+  libc.src.math.bf16divf
+  libc.src.math.bf16divl
   libc.src.math.bf16mul
   libc.src.math.bf16mulf
   libc.src.math.bf16mull
@@ -875,6 +878,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # math.h C++23 mixed bfloat16 and _Float128 entrypoints
     libc.src.math.bf16addf128
+    libc.src.math.bf16divf128
     libc.src.math.bf16mulf128
     libc.src.math.bf16subf128
   )

diff  --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 21c16403d6c01..47689a2234aca 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -463,6 +463,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
+  libc.src.math.bf16div
+  libc.src.math.bf16divf
+  libc.src.math.bf16divl
   libc.src.math.bf16mul
   libc.src.math.bf16mulf
   libc.src.math.bf16mull

diff  --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 7084582789203..b9efadc7deef2 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -866,6 +866,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
+  libc.src.math.bf16div
+  libc.src.math.bf16divf
+  libc.src.math.bf16divl
   libc.src.math.bf16mul
   libc.src.math.bf16mulf
   libc.src.math.bf16mull
@@ -894,6 +897,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # math.h C++23 mixed bfloat16 and _Float128 entrypoints
     libc.src.math.bf16addf128
+    libc.src.math.bf16divf128
     libc.src.math.bf16mulf128
     libc.src.math.bf16subf128
   )

diff  --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index dd57bcd874aab..458cb5999e403 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -898,6 +898,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
+  libc.src.math.bf16div
+  libc.src.math.bf16divf
+  libc.src.math.bf16divl
   libc.src.math.bf16mul
   libc.src.math.bf16mulf
   libc.src.math.bf16mull
@@ -926,6 +929,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # math.h C++23 mixed bfloat16 and _Float128 entrypoints
     libc.src.math.bf16addf128
+    libc.src.math.bf16divf128
     libc.src.math.bf16mulf128
     libc.src.math.bf16subf128
   )

diff  --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index b2c4bccb6ac8d..00104a31af44e 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -309,6 +309,9 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
+  libc.src.math.bf16div
+  libc.src.math.bf16divf
+  libc.src.math.bf16divl
   libc.src.math.bf16mul
   libc.src.math.bf16mulf
   libc.src.math.bf16mull

diff  --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index b6a9c14f98ea3..2cf5ae5eab726 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -579,6 +579,11 @@ add_math_entrypoint_object(bf16addf)
 add_math_entrypoint_object(bf16addl)
 add_math_entrypoint_object(bf16addf128)
 
+add_math_entrypoint_object(bf16div)
+add_math_entrypoint_object(bf16divf)
+add_math_entrypoint_object(bf16divl)
+add_math_entrypoint_object(bf16divf128)
+
 add_math_entrypoint_object(bf16mul)
 add_math_entrypoint_object(bf16mulf)
 add_math_entrypoint_object(bf16mull)

diff  --git a/libc/src/math/bf16div.h b/libc/src/math/bf16div.h
new file mode 100644
index 0000000000000..ade9c067d3c3a
--- /dev/null
+++ b/libc/src/math/bf16div.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for bf16div -----------------------*- 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_MATH_BF16DIV_H
+#define LLVM_LIBC_SRC_MATH_BF16DIV_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 bf16div(double x, double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_BF16DIV_H

diff  --git a/libc/src/math/bf16divf.h b/libc/src/math/bf16divf.h
new file mode 100644
index 0000000000000..481b176e01ea3
--- /dev/null
+++ b/libc/src/math/bf16divf.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for bf16divf ----------------------*- 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_MATH_BF16DIVF_H
+#define LLVM_LIBC_SRC_MATH_BF16DIVF_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 bf16divf(float x, float y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_BF16DIVF_H

diff  --git a/libc/src/math/bf16divf128.h b/libc/src/math/bf16divf128.h
new file mode 100644
index 0000000000000..d99006695d1d7
--- /dev/null
+++ b/libc/src/math/bf16divf128.h
@@ -0,0 +1,21 @@
+//===-- 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_MATH_BF16DIVF128_H
+#define LLVM_LIBC_SRC_MATH_BF16DIVF128_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 bf16divf128(float128 x, float128 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_BF16DIVF128_H

diff  --git a/libc/src/math/bf16divl.h b/libc/src/math/bf16divl.h
new file mode 100644
index 0000000000000..b19ac873af3f0
--- /dev/null
+++ b/libc/src/math/bf16divl.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for bf16divl ----------------------*- 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_MATH_BF16DIVL_H
+#define LLVM_LIBC_SRC_MATH_BF16DIVL_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 bf16divl(long double x, long double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_BF16DIVL_H

diff  --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 936c07045045c..70e5bf682ed9f 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5049,6 +5049,61 @@ add_entrypoint_object(
     libc.src.__support.macros.properties.types
 )
 
+add_entrypoint_object(
+  bf16div
+  SRCS
+    bf16div.cpp
+  HDRS
+    ../bf16div.h
+  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
+)
+
+add_entrypoint_object(
+  bf16divf
+  SRCS
+    bf16divf.cpp
+  HDRS
+    ../bf16divf.h
+  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
+)
+
+add_entrypoint_object(
+  bf16divl
+  SRCS
+    bf16divl.cpp
+  HDRS
+    ../bf16divl.h
+  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
+)
+
+add_entrypoint_object(
+  bf16divf128
+  SRCS
+    bf16divf128.cpp
+  HDRS
+    ../bf16divf128.h
+  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
+)
 
 add_entrypoint_object(
   bf16sub

diff  --git a/libc/src/math/generic/bf16div.cpp b/libc/src/math/generic/bf16div.cpp
new file mode 100644
index 0000000000000..5e9b1b42e27f4
--- /dev/null
+++ b/libc/src/math/generic/bf16div.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of bf16div function --------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/bf16div.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"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, bf16div, (double x, double y)) {
+  return fputil::generic::div<bfloat16>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/bf16divf.cpp b/libc/src/math/generic/bf16divf.cpp
new file mode 100644
index 0000000000000..2054a6417b078
--- /dev/null
+++ b/libc/src/math/generic/bf16divf.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of bf16divf function -------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/bf16divf.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"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, bf16divf, (float x, float y)) {
+  return fputil::generic::div<bfloat16>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/bf16divf128.cpp b/libc/src/math/generic/bf16divf128.cpp
new file mode 100644
index 0000000000000..fbe9775ce4046
--- /dev/null
+++ b/libc/src/math/generic/bf16divf128.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of bf16divf128 function ----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#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"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, bf16divf128, (float128 x, float128 y)) {
+  return fputil::generic::div<bfloat16>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/bf16divl.cpp b/libc/src/math/generic/bf16divl.cpp
new file mode 100644
index 0000000000000..21dd6b150e07a
--- /dev/null
+++ b/libc/src/math/generic/bf16divl.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of bf16divl function -------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/bf16divl.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"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, bf16divl, (long double x, long double y)) {
+  return fputil::generic::div<bfloat16>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 899d54dd3108c..85dddfb88d7e6 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -3028,6 +3028,62 @@ add_fp_unittest(
     libc.src.__support.FPUtil.bfloat16
 )
 
+add_fp_unittest(
+  bf16div_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    bf16div_test.cpp
+  HDRS
+    DivTest.h
+  DEPENDS
+    libc.src.math.bf16div
+    libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
+  bf16divf_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    bf16divf_test.cpp
+  HDRS
+    DivTest.h
+  DEPENDS
+    libc.src.math.bf16divf
+    libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
+  bf16divl_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    bf16divl_test.cpp
+  HDRS
+    DivTest.h
+  DEPENDS
+    libc.src.math.bf16divl
+    libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
+  bf16divf128_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    bf16divf128_test.cpp
+  HDRS
+    DivTest.h
+  DEPENDS
+    libc.src.math.bf16divf128
+    libc.src.__support.FPUtil.bfloat16
+)
+
 add_fp_unittest(
   bf16mul_test
   NEED_MPFR

diff  --git a/libc/test/src/math/bf16div_test.cpp b/libc/test/src/math/bf16div_test.cpp
new file mode 100644
index 0000000000000..4516351fb93a3
--- /dev/null
+++ b/libc/test/src/math/bf16div_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for bf16div ---------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "DivTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/bf16div.h"
+
+LIST_DIV_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16div)

diff  --git a/libc/test/src/math/bf16divf128_test.cpp b/libc/test/src/math/bf16divf128_test.cpp
new file mode 100644
index 0000000000000..c42c5bb067050
--- /dev/null
+++ b/libc/test/src/math/bf16divf128_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for bf16divf128 -----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "DivTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/bf16divf128.h"
+
+LIST_DIV_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16divf128)

diff  --git a/libc/test/src/math/bf16divf_test.cpp b/libc/test/src/math/bf16divf_test.cpp
new file mode 100644
index 0000000000000..873920b225a77
--- /dev/null
+++ b/libc/test/src/math/bf16divf_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for bf16divf --------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "DivTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/bf16divf.h"
+
+LIST_DIV_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16divf)

diff  --git a/libc/test/src/math/bf16divl_test.cpp b/libc/test/src/math/bf16divl_test.cpp
new file mode 100644
index 0000000000000..32ecd6228de0b
--- /dev/null
+++ b/libc/test/src/math/bf16divl_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for bf16divl --------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "DivTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/bf16divl.h"
+
+LIST_DIV_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16divl)

diff  --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index a529440752547..c3df8b1ff2c58 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -5680,6 +5680,66 @@ add_fp_unittest(
     libc.src.__support.macros.properties.os
 )
 
+add_fp_unittest(
+  bf16div_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    bf16div_test.cpp
+  HDRS
+    DivTest.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.math.bf16div
+    libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
+  bf16divf_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    bf16divf_test.cpp
+  HDRS
+    DivTest.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.math.bf16divf
+    libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
+  bf16divl_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    bf16divl_test.cpp
+  HDRS
+    DivTest.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.math.bf16divl
+    libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
+  bf16divf128_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    bf16divf128_test.cpp
+  HDRS
+    DivTest.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.math.bf16divf128
+    libc.src.__support.FPUtil.bfloat16
+)
+
 add_fp_unittest(
   bf16mul_test
   SUITE
@@ -5687,7 +5747,7 @@ add_fp_unittest(
   SRCS
     bf16mul_test.cpp
   HDRS
-    AddTest.h
+    MulTest.h
   DEPENDS
     libc.hdr.errno_macros
     libc.hdr.fenv_macros

diff  --git a/libc/test/src/math/smoke/bf16div_test.cpp b/libc/test/src/math/smoke/bf16div_test.cpp
new file mode 100644
index 0000000000000..4516351fb93a3
--- /dev/null
+++ b/libc/test/src/math/smoke/bf16div_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for bf16div ---------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "DivTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/bf16div.h"
+
+LIST_DIV_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16div)

diff  --git a/libc/test/src/math/smoke/bf16divf128_test.cpp b/libc/test/src/math/smoke/bf16divf128_test.cpp
new file mode 100644
index 0000000000000..c42c5bb067050
--- /dev/null
+++ b/libc/test/src/math/smoke/bf16divf128_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for bf16divf128 -----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "DivTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/bf16divf128.h"
+
+LIST_DIV_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16divf128)

diff  --git a/libc/test/src/math/smoke/bf16divf_test.cpp b/libc/test/src/math/smoke/bf16divf_test.cpp
new file mode 100644
index 0000000000000..873920b225a77
--- /dev/null
+++ b/libc/test/src/math/smoke/bf16divf_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for bf16divf --------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "DivTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/bf16divf.h"
+
+LIST_DIV_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16divf)

diff  --git a/libc/test/src/math/smoke/bf16divl_test.cpp b/libc/test/src/math/smoke/bf16divl_test.cpp
new file mode 100644
index 0000000000000..32ecd6228de0b
--- /dev/null
+++ b/libc/test/src/math/smoke/bf16divl_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for bf16divl --------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "DivTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/bf16divl.h"
+
+LIST_DIV_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16divl)


        


More information about the libc-commits mailing list