[libc-commits] [libc] [libc][math][c++23] Add bf16mul{, f, l, f128} math functions (PR #152847)

Krishna Pandey via libc-commits libc-commits at lists.llvm.org
Sat Aug 9 05:22:07 PDT 2025


https://github.com/krishna2803 updated https://github.com/llvm/llvm-project/pull/152847

>From 5efb6e46785f2ea2de147be0b2aa0167b6ab4f0f Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 9 Aug 2025 01:19:15 +0530
Subject: [PATCH 01/12] chore: update entrypoints for bf16{add,sub}{,f,l,f128}
 math functions

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
 libc/config/baremetal/aarch64/entrypoints.txt | 14 ++++++++++++++
 libc/config/baremetal/arm/entrypoints.txt     | 14 ++++++++++++++
 libc/config/baremetal/riscv/entrypoints.txt   | 14 ++++++++++++++
 libc/config/darwin/aarch64/entrypoints.txt    | 14 ++++++++++++++
 libc/config/darwin/x86_64/entrypoints.txt     |  6 ++++++
 libc/config/gpu/amdgpu/entrypoints.txt        |  6 ++++++
 libc/config/gpu/nvptx/entrypoints.txt         |  6 ++++++
 libc/config/linux/aarch64/entrypoints.txt     | 14 ++++++++++++++
 libc/config/linux/arm/entrypoints.txt         |  6 ++++++
 libc/config/linux/riscv/entrypoints.txt       | 14 ++++++++++++++
 libc/config/linux/x86_64/entrypoints.txt      |  2 +-
 libc/config/windows/entrypoints.txt           |  6 ++++++
 12 files changed, 115 insertions(+), 1 deletion(-)

diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 683c7464abde9..af9f687e8fcd8 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -757,6 +757,12 @@ endif()
 
 list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
+  libc.src.math.bf16add
+  libc.src.math.bf16addf
+  libc.src.math.bf16addl
+  libc.src.math.bf16sub
+  libc.src.math.bf16subf
+  libc.src.math.bf16subl
   libc.src.math.ceilbf16
   libc.src.math.fabsbf16
   libc.src.math.floorbf16
@@ -765,6 +771,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.truncbf16
 )
 
+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.bf16subf128
+  )
+endif()
+
 if(LIBC_COMPILER_HAS_FIXED_POINT)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # stdfix.h _Fract and _Accum entrypoints
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index f8ecc2ea8a3a4..ce8d7c0d13b76 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -760,6 +760,12 @@ endif()
 
 list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
+  libc.src.math.bf16add
+  libc.src.math.bf16addf
+  libc.src.math.bf16addl
+  libc.src.math.bf16sub
+  libc.src.math.bf16subf
+  libc.src.math.bf16subl
   libc.src.math.ceilbf16
   libc.src.math.fabsbf16
   libc.src.math.floorbf16
@@ -768,6 +774,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.truncbf16
 )
 
+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.bf16subf128
+  )
+endif()
+
 if(LIBC_COMPILER_HAS_FIXED_POINT)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # stdfix.h _Fract and _Accum entrypoints
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 679bfb3803686..7eeec245a31dd 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -760,6 +760,12 @@ endif()
 
 list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
+  libc.src.math.bf16add
+  libc.src.math.bf16addf
+  libc.src.math.bf16addl
+  libc.src.math.bf16sub
+  libc.src.math.bf16subf
+  libc.src.math.bf16subl
   libc.src.math.ceilbf16
   libc.src.math.fabsbf16
   libc.src.math.floorbf16
@@ -768,6 +774,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.truncbf16
 )
 
+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.bf16subf128
+  )
+endif()
+
 if(LIBC_COMPILER_HAS_FIXED_POINT)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # stdfix.h _Fract and _Accum entrypoints
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 72b0265552ab8..de4b4df024ca1 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -590,6 +590,12 @@ endif()
 
 list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
+  libc.src.math.bf16add
+  libc.src.math.bf16addf
+  libc.src.math.bf16addl
+  libc.src.math.bf16sub
+  libc.src.math.bf16subf
+  libc.src.math.bf16subl
   libc.src.math.ceilbf16
   libc.src.math.fabsbf16
   libc.src.math.floorbf16
@@ -598,6 +604,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.truncbf16
 )
 
+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.bf16subf128
+  )
+endif()
+
 if(LIBC_COMPILER_HAS_FIXED_POINT)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # stdfix.h _Fract and _Accum entrypoints
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index b5ab1ee26a867..f668e8a6ebff3 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -233,6 +233,12 @@ set(TARGET_LIBM_ENTRYPOINTS
 
 list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
+  libc.src.math.bf16add
+  libc.src.math.bf16addf
+  libc.src.math.bf16addl
+  libc.src.math.bf16sub
+  libc.src.math.bf16subf
+  libc.src.math.bf16subl
   libc.src.math.ceilbf16
   libc.src.math.fabsbf16
   libc.src.math.floorbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 77a13a66da545..f7b8b2f66c230 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -616,6 +616,12 @@ endif()
 
 list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
+  libc.src.math.bf16add
+  libc.src.math.bf16addf
+  libc.src.math.bf16addl
+  libc.src.math.bf16sub
+  libc.src.math.bf16subf
+  libc.src.math.bf16subl
   libc.src.math.ceilbf16
   libc.src.math.fabsbf16
   libc.src.math.floorbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 61c9c717d37ef..23afb40904836 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -617,6 +617,12 @@ endif()
 
 list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
+  libc.src.math.bf16add
+  libc.src.math.bf16addf
+  libc.src.math.bf16addl
+  libc.src.math.bf16sub
+  libc.src.math.bf16subf
+  libc.src.math.bf16subl
   libc.src.math.ceilbf16
   libc.src.math.fabsbf16
   libc.src.math.floorbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index fbdf8fb621b0f..62a3ae9b2fa96 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -844,6 +844,12 @@ endif()
 
 list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
+  libc.src.math.bf16add
+  libc.src.math.bf16addf
+  libc.src.math.bf16addl
+  libc.src.math.bf16sub
+  libc.src.math.bf16subf
+  libc.src.math.bf16subl
   libc.src.math.ceilbf16
   libc.src.math.fabsbf16
   libc.src.math.floorbf16
@@ -852,6 +858,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.truncbf16
 )
 
+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.bf16subf128
+  )
+endif()
+
 if(LLVM_LIBC_FULL_BUILD)
   list(APPEND TARGET_LIBC_ENTRYPOINTS
     # assert.h entrypoints
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index e3f5feecc896a..eedf184384c19 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -460,6 +460,12 @@ set(TARGET_LIBM_ENTRYPOINTS
 
 list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
+  libc.src.math.bf16add
+  libc.src.math.bf16addf
+  libc.src.math.bf16addl
+  libc.src.math.bf16sub
+  libc.src.math.bf16subf
+  libc.src.math.bf16subl
   libc.src.math.ceilbf16
   libc.src.math.fabsbf16
   libc.src.math.floorbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index ba67dddbe8b98..cd569795ce438 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -863,6 +863,12 @@ endif()
 
 list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
+  libc.src.math.bf16add
+  libc.src.math.bf16addf
+  libc.src.math.bf16addl
+  libc.src.math.bf16sub
+  libc.src.math.bf16subf
+  libc.src.math.bf16subl
   libc.src.math.ceilbf16
   libc.src.math.fabsbf16
   libc.src.math.floorbf16
@@ -871,6 +877,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.truncbf16
 )
 
+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.bf16subf128
+  )
+endif()
+
 if(LIBC_COMPILER_HAS_FIXED_POINT)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # stdfix.h _Fract and _Accum entrypoints
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 0a2b24b420ac2..2b0cf33dd67f4 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -895,13 +895,13 @@ endif()
 
 list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
-  libc.src.math.ceilbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
+  libc.src.math.ceilbf16
   libc.src.math.fabsbf16
   libc.src.math.floorbf16
   libc.src.math.roundbf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 994078c0ed274..1b1db5e5076b4 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -306,6 +306,12 @@ set(TARGET_LIBM_ENTRYPOINTS
 
 list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
+  libc.src.math.bf16add
+  libc.src.math.bf16addf
+  libc.src.math.bf16addl
+  libc.src.math.bf16sub
+  libc.src.math.bf16subf
+  libc.src.math.bf16subl
   libc.src.math.ceilbf16
   libc.src.math.fabsbf16
   libc.src.math.floorbf16

>From 4fc8ccffca66b7801bb11a12c9e0ebdc2d70be2a Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 9 Aug 2025 01:39:05 +0530
Subject: [PATCH 02/12] feat: implement bf16mul{,f,l,f128} math function

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
 libc/src/math/bf16mul.h               | 21 +++++++++++++++++++++
 libc/src/math/bf16mulf.h              | 21 +++++++++++++++++++++
 libc/src/math/bf16mulf128.h           | 21 +++++++++++++++++++++
 libc/src/math/bf16mull.h              | 21 +++++++++++++++++++++
 libc/src/math/generic/bf16mul.cpp     | 22 ++++++++++++++++++++++
 libc/src/math/generic/bf16mulf.cpp    | 22 ++++++++++++++++++++++
 libc/src/math/generic/bf16mulf128.cpp | 22 ++++++++++++++++++++++
 libc/src/math/generic/bf16mull.cpp    | 22 ++++++++++++++++++++++
 8 files changed, 172 insertions(+)
 create mode 100644 libc/src/math/bf16mul.h
 create mode 100644 libc/src/math/bf16mulf.h
 create mode 100644 libc/src/math/bf16mulf128.h
 create mode 100644 libc/src/math/bf16mull.h
 create mode 100644 libc/src/math/generic/bf16mul.cpp
 create mode 100644 libc/src/math/generic/bf16mulf.cpp
 create mode 100644 libc/src/math/generic/bf16mulf128.cpp
 create mode 100644 libc/src/math/generic/bf16mull.cpp

diff --git a/libc/src/math/bf16mul.h b/libc/src/math/bf16mul.h
new file mode 100644
index 0000000000000..14e8a304c2b6c
--- /dev/null
+++ b/libc/src/math/bf16mul.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for bf16mul -----------------------*- 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_BF16MUL_H
+#define LLVM_LIBC_SRC_MATH_BF16MUL_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 bf16mul(double x, double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_BF16MUL_H
diff --git a/libc/src/math/bf16mulf.h b/libc/src/math/bf16mulf.h
new file mode 100644
index 0000000000000..1d02c8e796b17
--- /dev/null
+++ b/libc/src/math/bf16mulf.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for bf16mulf ----------------------*- 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_BF16MULF_H
+#define LLVM_LIBC_SRC_MATH_BF16MULF_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 bf16mulf(float x, float y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_BF16MULF_H
diff --git a/libc/src/math/bf16mulf128.h b/libc/src/math/bf16mulf128.h
new file mode 100644
index 0000000000000..6ba7cefb2ee8e
--- /dev/null
+++ b/libc/src/math/bf16mulf128.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for bf16mulf128 -------------------*- 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_BF16MULF128_H
+#define LLVM_LIBC_SRC_MATH_BF16MULF128_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 bf16mulf128(float128 x, float128 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_BF16MULF128_H
diff --git a/libc/src/math/bf16mull.h b/libc/src/math/bf16mull.h
new file mode 100644
index 0000000000000..dad65236ce05d
--- /dev/null
+++ b/libc/src/math/bf16mull.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for bf16mull ----------------------*- 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_BF16MULL_H
+#define LLVM_LIBC_SRC_MATH_BF16MULL_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 bf16mull(long double x, long double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_BF16MULL_H
diff --git a/libc/src/math/generic/bf16mul.cpp b/libc/src/math/generic/bf16mul.cpp
new file mode 100644
index 0000000000000..92e057e9920e6
--- /dev/null
+++ b/libc/src/math/generic/bf16mul.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of bf16mul 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/bf16mul.h"
+
+#include "src/__support/common.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, bf16mul, (double x, double y)) {
+  return fputil::generic::mul<bfloat16>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/bf16mulf.cpp b/libc/src/math/generic/bf16mulf.cpp
new file mode 100644
index 0000000000000..2c94cb8755d7f
--- /dev/null
+++ b/libc/src/math/generic/bf16mulf.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of bf16mulf 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/bf16mulf.h"
+
+#include "src/__support/common.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, bf16mulf, (float x, float y)) {
+  return fputil::generic::mul<bfloat16>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/bf16mulf128.cpp b/libc/src/math/generic/bf16mulf128.cpp
new file mode 100644
index 0000000000000..e9b685946fc7b
--- /dev/null
+++ b/libc/src/math/generic/bf16mulf128.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of bf16mulf128 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/bf16mulf128.h"
+
+#include "src/__support/common.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, bf16mulf128, (float128 x, float128 y)) {
+  return fputil::generic::mul<bfloat16>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/bf16mull.cpp b/libc/src/math/generic/bf16mull.cpp
new file mode 100644
index 0000000000000..d91dc4a671db3
--- /dev/null
+++ b/libc/src/math/generic/bf16mull.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of bf16mull 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/bf16mull.h"
+
+#include "src/__support/common.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, bf16mull, (long double x, long double y)) {
+  return fputil::generic::mul<bfloat16>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL

>From 502a50931d484c85f032110a7ea658d23fd1a25a Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 9 Aug 2025 01:39:33 +0530
Subject: [PATCH 03/12] add: smoke tests for bf16mul

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
 libc/test/src/math/smoke/bf16mul_test.cpp     | 15 +++++++++++++++
 libc/test/src/math/smoke/bf16mulf128_test.cpp | 15 +++++++++++++++
 libc/test/src/math/smoke/bf16mulf_test.cpp    | 15 +++++++++++++++
 libc/test/src/math/smoke/bf16mull_test.cpp    | 15 +++++++++++++++
 4 files changed, 60 insertions(+)
 create mode 100644 libc/test/src/math/smoke/bf16mul_test.cpp
 create mode 100644 libc/test/src/math/smoke/bf16mulf128_test.cpp
 create mode 100644 libc/test/src/math/smoke/bf16mulf_test.cpp
 create mode 100644 libc/test/src/math/smoke/bf16mull_test.cpp

diff --git a/libc/test/src/math/smoke/bf16mul_test.cpp b/libc/test/src/math/smoke/bf16mul_test.cpp
new file mode 100644
index 0000000000000..3682705556b0a
--- /dev/null
+++ b/libc/test/src/math/smoke/bf16mul_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for bf16mul ---------------------------------------------===//
+//
+// 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 "MulTest.h"
+
+#include "src/math/bf16mul.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+
+LIST_MUL_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16mul)
diff --git a/libc/test/src/math/smoke/bf16mulf128_test.cpp b/libc/test/src/math/smoke/bf16mulf128_test.cpp
new file mode 100644
index 0000000000000..6aee2687ae67a
--- /dev/null
+++ b/libc/test/src/math/smoke/bf16mulf128_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for bf16mulf128 -----------------------------------------===//
+//
+// 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 "MulTest.h"
+
+#include "src/math/bf16mulf128.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+
+LIST_MUL_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16mulf128)
diff --git a/libc/test/src/math/smoke/bf16mulf_test.cpp b/libc/test/src/math/smoke/bf16mulf_test.cpp
new file mode 100644
index 0000000000000..048b60f8e85cf
--- /dev/null
+++ b/libc/test/src/math/smoke/bf16mulf_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for bf16mulf --------------------------------------------===//
+//
+// 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 "MulTest.h"
+
+#include "src/math/bf16mulf.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+
+LIST_MUL_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16mulf)
diff --git a/libc/test/src/math/smoke/bf16mull_test.cpp b/libc/test/src/math/smoke/bf16mull_test.cpp
new file mode 100644
index 0000000000000..b8439b245c261
--- /dev/null
+++ b/libc/test/src/math/smoke/bf16mull_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for bf16mull --------------------------------------------===//
+//
+// 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 "MulTest.h"
+
+#include "src/math/bf16mull.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+
+LIST_MUL_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16mull)

>From 2055a061ac0c9cb446c123110897e6f75480b872 Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 9 Aug 2025 01:39:44 +0530
Subject: [PATCH 04/12] chore: update CMakeLists

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
 libc/src/math/CMakeLists.txt         |  5 +++
 libc/src/math/generic/CMakeLists.txt | 56 ++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 660c3681717c8..6a5ff065ea222 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -569,6 +569,11 @@ add_math_entrypoint_object(bf16addf)
 add_math_entrypoint_object(bf16addl)
 add_math_entrypoint_object(bf16addf128)
 
+add_math_entrypoint_object(bf16mul)
+add_math_entrypoint_object(bf16mulf)
+add_math_entrypoint_object(bf16mull)
+add_math_entrypoint_object(bf16mulf128)
+
 add_math_entrypoint_object(bf16sub)
 add_math_entrypoint_object(bf16subf)
 add_math_entrypoint_object(bf16subl)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 5aeacc85d4d5e..09067402d5557 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4983,6 +4983,62 @@ add_entrypoint_object(
     libc.src.__support.macros.properties.types
 )
 
+add_entrypoint_object(
+  bf16mul
+  SRCS
+    bf16mul.cpp
+  HDRS
+    ../bf16mul.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
+
+add_entrypoint_object(
+  bf16mulf
+  SRCS
+    bf16mulf.cpp
+  HDRS
+    ../bf16mulf.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
+
+add_entrypoint_object(
+  bf16mull
+  SRCS
+    bf16mull.cpp
+  HDRS
+    ../bf16mull.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
+
+add_entrypoint_object(
+  bf16mulf128
+  SRCS
+    bf16mulf128.cpp
+  HDRS
+    ../bf16mulf128.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
+
 add_entrypoint_object(
   bf16subf
   SRCS

>From 89a433b4a7473f7dffa3447ccfd71bfcd2b4595e Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 9 Aug 2025 02:10:45 +0530
Subject: [PATCH 05/12] add: general tests for bf16mul{,f,l,f128}

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
 libc/test/src/math/bf16mul_test.cpp     | 15 +++++++++++++++
 libc/test/src/math/bf16mulf128_test.cpp | 15 +++++++++++++++
 libc/test/src/math/bf16mulf_test.cpp    | 15 +++++++++++++++
 libc/test/src/math/bf16mull_test.cpp    | 15 +++++++++++++++
 4 files changed, 60 insertions(+)
 create mode 100644 libc/test/src/math/bf16mul_test.cpp
 create mode 100644 libc/test/src/math/bf16mulf128_test.cpp
 create mode 100644 libc/test/src/math/bf16mulf_test.cpp
 create mode 100644 libc/test/src/math/bf16mull_test.cpp

diff --git a/libc/test/src/math/bf16mul_test.cpp b/libc/test/src/math/bf16mul_test.cpp
new file mode 100644
index 0000000000000..3682705556b0a
--- /dev/null
+++ b/libc/test/src/math/bf16mul_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for bf16mul ---------------------------------------------===//
+//
+// 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 "MulTest.h"
+
+#include "src/math/bf16mul.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+
+LIST_MUL_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16mul)
diff --git a/libc/test/src/math/bf16mulf128_test.cpp b/libc/test/src/math/bf16mulf128_test.cpp
new file mode 100644
index 0000000000000..6aee2687ae67a
--- /dev/null
+++ b/libc/test/src/math/bf16mulf128_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for bf16mulf128 -----------------------------------------===//
+//
+// 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 "MulTest.h"
+
+#include "src/math/bf16mulf128.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+
+LIST_MUL_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16mulf128)
diff --git a/libc/test/src/math/bf16mulf_test.cpp b/libc/test/src/math/bf16mulf_test.cpp
new file mode 100644
index 0000000000000..048b60f8e85cf
--- /dev/null
+++ b/libc/test/src/math/bf16mulf_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for bf16mulf --------------------------------------------===//
+//
+// 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 "MulTest.h"
+
+#include "src/math/bf16mulf.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+
+LIST_MUL_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16mulf)
diff --git a/libc/test/src/math/bf16mull_test.cpp b/libc/test/src/math/bf16mull_test.cpp
new file mode 100644
index 0000000000000..b8439b245c261
--- /dev/null
+++ b/libc/test/src/math/bf16mull_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for bf16mull --------------------------------------------===//
+//
+// 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 "MulTest.h"
+
+#include "src/math/bf16mull.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+
+LIST_MUL_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16mull)

>From df3bf2ebe9ff07978954f210f1d0ba62f6fa33f9 Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 9 Aug 2025 02:11:17 +0530
Subject: [PATCH 06/12] fix: InType -> OutType in MulTest.h

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
 libc/test/src/math/smoke/MulTest.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/test/src/math/smoke/MulTest.h b/libc/test/src/math/smoke/MulTest.h
index a45f422416f68..5020067d433a7 100644
--- a/libc/test/src/math/smoke/MulTest.h
+++ b/libc/test/src/math/smoke/MulTest.h
@@ -53,8 +53,8 @@ class MulTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
     EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, func(in.zero, in.neg_zero));
     EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, func(in.neg_zero, in.zero));
 
-    EXPECT_FP_EQ_ALL_ROUNDING(InType(1.0), func(InType(1.0), InType(1.0)));
-    EXPECT_FP_EQ_ALL_ROUNDING(InType(15.0), func(InType(3.0), InType(5.0)));
+    EXPECT_FP_EQ_ALL_ROUNDING(OutType(1.0), func(InType(1.0), InType(1.0)));
+    EXPECT_FP_EQ_ALL_ROUNDING(OutType(15.0), func(InType(3.0), InType(5.0)));
     EXPECT_FP_EQ_ALL_ROUNDING(OutType(0x1.0p-13),
                               func(InType(0x1.0p+1), InType(0x1.0p-14)));
     EXPECT_FP_EQ_ALL_ROUNDING(OutType(0x1.0p-10),

>From eac84e70f14164322b9b6f60c72e80b0f82495cf Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 9 Aug 2025 02:11:38 +0530
Subject: [PATCH 07/12] chore: update CMakeLists

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
 libc/test/src/math/CMakeLists.txt       | 64 +++++++++++++++++++++++++
 libc/test/src/math/smoke/CMakeLists.txt | 61 +++++++++++++++++++++++
 2 files changed, 125 insertions(+)

diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index a74f9fe471963..899d54dd3108c 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -3028,6 +3028,70 @@ add_fp_unittest(
     libc.src.__support.FPUtil.bfloat16
 )
 
+add_fp_unittest(
+  bf16mul_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    bf16mul_test.cpp
+  HDRS
+    MulTest.h
+  DEPENDS
+    libc.src.math.bf16mul
+    libc.src.stdlib.rand
+    libc.src.stdlib.srand
+    libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
+  bf16mulf_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    bf16mulf_test.cpp
+  HDRS
+    MulTest.h
+  DEPENDS
+    libc.src.math.bf16mulf
+    libc.src.stdlib.rand
+    libc.src.stdlib.srand
+    libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
+  bf16mull_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    bf16mull_test.cpp
+  HDRS
+    MulTest.h
+  DEPENDS
+    libc.src.math.bf16mull
+    libc.src.stdlib.rand
+    libc.src.stdlib.srand
+    libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
+  bf16mulf128_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    bf16mulf128_test.cpp
+  HDRS
+    MulTest.h
+  DEPENDS
+    libc.src.math.bf16mulf128
+    libc.src.stdlib.rand
+    libc.src.stdlib.srand
+    libc.src.__support.FPUtil.bfloat16
+)
+
 add_fp_unittest(
   bf16sub_test
   NEED_MPFR
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index dc1850aaa68e2..a1883d7a76f8f 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -5530,6 +5530,67 @@ add_fp_unittest(
     libc.src.__support.macros.properties.os
 )
 
+add_fp_unittest(
+  bf16mul_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    bf16mul_test.cpp
+  HDRS
+    AddTest.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.math.bf16mul
+    libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
+  bf16mulf_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    bf16mulf_test.cpp
+  HDRS
+    MulTest.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.math.bf16mulf
+    libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
+  bf16mull_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    bf16mull_test.cpp
+  HDRS
+    MulTest.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.math.bf16mull
+    libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
+  bf16mulf128_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    bf16mulf128_test.cpp
+  HDRS
+    MulTest.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.math.bf16mulf128
+    libc.src.__support.FPUtil.bfloat16
+)
+
+
 add_fp_unittest(
   bf16sub_test
   SUITE

>From 89705e64d32e4c5cd0828c366621d0589867e1ca Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 9 Aug 2025 02:12:33 +0530
Subject: [PATCH 08/12] fix: use FPBits<T> sign comparison instead of
 multiplication

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
 libc/utils/MPFRWrapper/MPCommon.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 8bcc69c247a34..bce29b4ee8751 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -284,7 +284,8 @@ class MPFRNumber {
     if (FPBits<T>(input).is_subnormal())
       ++inputExponent;
 
-    if (thisAsT * input < 0 || thisExponent == inputExponent) {
+    if (FPBits<T>(thisAsT).sign() != FPBits<T>(input).sign() ||
+        thisExponent == inputExponent) {
       MPFRNumber inputMPFR(input);
       mpfr_sub(inputMPFR.value, value, inputMPFR.value, MPFR_RNDN);
       mpfr_abs(inputMPFR.value, inputMPFR.value, MPFR_RNDN);

>From 94ae0232defc207225932773c4dfcce866a06063 Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 9 Aug 2025 02:24:05 +0530
Subject: [PATCH 09/12] chore: update entrypoints

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
 libc/config/baremetal/aarch64/entrypoints.txt | 4 ++++
 libc/config/baremetal/arm/entrypoints.txt     | 4 ++++
 libc/config/baremetal/riscv/entrypoints.txt   | 4 ++++
 libc/config/darwin/aarch64/entrypoints.txt    | 4 ++++
 libc/config/darwin/x86_64/entrypoints.txt     | 3 +++
 libc/config/gpu/amdgpu/entrypoints.txt        | 3 +++
 libc/config/gpu/nvptx/entrypoints.txt         | 3 +++
 libc/config/linux/aarch64/entrypoints.txt     | 4 ++++
 libc/config/linux/arm/entrypoints.txt         | 3 +++
 libc/config/linux/riscv/entrypoints.txt       | 4 ++++
 libc/config/linux/x86_64/entrypoints.txt      | 4 ++++
 libc/config/windows/entrypoints.txt           | 3 +++
 12 files changed, 43 insertions(+)

diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index af9f687e8fcd8..493e69127217b 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
@@ -775,6 +778,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.bf16mulf128
     libc.src.math.bf16subf128
   )
 endif()
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index ce8d7c0d13b76..2c4f1ee733565 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
@@ -778,6 +781,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.bf16mulf128
     libc.src.math.bf16subf128
   )
 endif()
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 7eeec245a31dd..9c88184e427b2 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
@@ -778,6 +781,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.bf16mulf128
     libc.src.math.bf16subf128
   )
 endif()
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index de4b4df024ca1..ab73fa47487df 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
@@ -608,6 +611,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.bf16mulf128
     libc.src.math.bf16subf128
   )
 endif()
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index f668e8a6ebff3..504d33942942e 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index f7b8b2f66c230..d021ddea386bd 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 23afb40904836..258e75ed29095 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 62a3ae9b2fa96..8fcf7e371a6b5 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
@@ -862,6 +865,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.bf16mulf128
     libc.src.math.bf16subf128
   )
 endif()
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index eedf184384c19..df36508b6ae89 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index cd569795ce438..7ed377627e5b2 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
@@ -881,6 +884,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.bf16mulf128
     libc.src.math.bf16subf128
   )
 endif()
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 2b0cf33dd67f4..088be7d61110b 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
@@ -913,6 +916,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.bf16mulf128
     libc.src.math.bf16subf128
   )
 endif()
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 1b1db5e5076b4..f99e694a85793 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl

>From 45f67cbca78eed1562e7a249c5011f6e8b962395 Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 9 Aug 2025 16:14:18 +0530
Subject: [PATCH 10/12] style: remove empty line and rearrange includes

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
 libc/src/math/generic/bf16mul.cpp     | 3 +--
 libc/src/math/generic/bf16mulf.cpp    | 3 +--
 libc/src/math/generic/bf16mulf128.cpp | 3 +--
 libc/src/math/generic/bf16mull.cpp    | 3 +--
 4 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/libc/src/math/generic/bf16mul.cpp b/libc/src/math/generic/bf16mul.cpp
index 92e057e9920e6..c50eec2b52e5c 100644
--- a/libc/src/math/generic/bf16mul.cpp
+++ b/libc/src/math/generic/bf16mul.cpp
@@ -7,10 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/bf16mul.h"
-
-#include "src/__support/common.h"
 #include "src/__support/FPUtil/bfloat16.h"
 #include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/math/generic/bf16mulf.cpp b/libc/src/math/generic/bf16mulf.cpp
index 2c94cb8755d7f..117fcd1d661ab 100644
--- a/libc/src/math/generic/bf16mulf.cpp
+++ b/libc/src/math/generic/bf16mulf.cpp
@@ -7,10 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/bf16mulf.h"
-
-#include "src/__support/common.h"
 #include "src/__support/FPUtil/bfloat16.h"
 #include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/math/generic/bf16mulf128.cpp b/libc/src/math/generic/bf16mulf128.cpp
index e9b685946fc7b..ff2a081d82e6b 100644
--- a/libc/src/math/generic/bf16mulf128.cpp
+++ b/libc/src/math/generic/bf16mulf128.cpp
@@ -7,10 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/bf16mulf128.h"
-
-#include "src/__support/common.h"
 #include "src/__support/FPUtil/bfloat16.h"
 #include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/math/generic/bf16mull.cpp b/libc/src/math/generic/bf16mull.cpp
index d91dc4a671db3..e7c4fc085a3cd 100644
--- a/libc/src/math/generic/bf16mull.cpp
+++ b/libc/src/math/generic/bf16mull.cpp
@@ -7,10 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/bf16mull.h"
-
-#include "src/__support/common.h"
 #include "src/__support/FPUtil/bfloat16.h"
 #include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {

>From 9747e5674b712ad29d9772505e848f3c70168948 Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 9 Aug 2025 17:15:36 +0530
Subject: [PATCH 11/12] revert: "fix: use FPBits<T> sign comparison instead of
 multiplication"

This reverts commit 89705e64d32e4c5cd0828c366621d0589867e1ca.
---
 libc/utils/MPFRWrapper/MPCommon.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index bce29b4ee8751..8bcc69c247a34 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -284,8 +284,7 @@ class MPFRNumber {
     if (FPBits<T>(input).is_subnormal())
       ++inputExponent;
 
-    if (FPBits<T>(thisAsT).sign() != FPBits<T>(input).sign() ||
-        thisExponent == inputExponent) {
+    if (thisAsT * input < 0 || thisExponent == inputExponent) {
       MPFRNumber inputMPFR(input);
       mpfr_sub(inputMPFR.value, value, inputMPFR.value, MPFR_RNDN);
       mpfr_abs(inputMPFR.value, inputMPFR.value, MPFR_RNDN);

>From 37c88d4066537818777bd36c7835aac0f8ddc89a Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 9 Aug 2025 17:51:43 +0530
Subject: [PATCH 12/12] nit: add missing entrypoints and remove empty lines

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
 libc/config/baremetal/arm/entrypoints.txt     | 3 +++
 libc/test/src/math/smoke/bf16mul_test.cpp     | 3 +--
 libc/test/src/math/smoke/bf16mulf128_test.cpp | 3 +--
 libc/test/src/math/smoke/bf16mulf_test.cpp    | 3 +--
 libc/test/src/math/smoke/bf16mull_test.cpp    | 3 +--
 5 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index badeacc66f8cd..08d0292760540 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.bf16mul
+  libc.src.math.bf16mulf
+  libc.src.math.bf16mull
   libc.src.math.bf16sub
   libc.src.math.bf16subf
   libc.src.math.bf16subl
diff --git a/libc/test/src/math/smoke/bf16mul_test.cpp b/libc/test/src/math/smoke/bf16mul_test.cpp
index 3682705556b0a..db6f0cb7844db 100644
--- a/libc/test/src/math/smoke/bf16mul_test.cpp
+++ b/libc/test/src/math/smoke/bf16mul_test.cpp
@@ -8,8 +8,7 @@
 
 #include "MulTest.h"
 
-#include "src/math/bf16mul.h"
-
 #include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/bf16mul.h"
 
 LIST_MUL_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16mul)
diff --git a/libc/test/src/math/smoke/bf16mulf128_test.cpp b/libc/test/src/math/smoke/bf16mulf128_test.cpp
index 6aee2687ae67a..03cb9f24228ba 100644
--- a/libc/test/src/math/smoke/bf16mulf128_test.cpp
+++ b/libc/test/src/math/smoke/bf16mulf128_test.cpp
@@ -8,8 +8,7 @@
 
 #include "MulTest.h"
 
-#include "src/math/bf16mulf128.h"
-
 #include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/bf16mulf128.h"
 
 LIST_MUL_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16mulf128)
diff --git a/libc/test/src/math/smoke/bf16mulf_test.cpp b/libc/test/src/math/smoke/bf16mulf_test.cpp
index 048b60f8e85cf..ec40e98b20475 100644
--- a/libc/test/src/math/smoke/bf16mulf_test.cpp
+++ b/libc/test/src/math/smoke/bf16mulf_test.cpp
@@ -8,8 +8,7 @@
 
 #include "MulTest.h"
 
-#include "src/math/bf16mulf.h"
-
 #include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/bf16mulf.h"
 
 LIST_MUL_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16mulf)
diff --git a/libc/test/src/math/smoke/bf16mull_test.cpp b/libc/test/src/math/smoke/bf16mull_test.cpp
index b8439b245c261..4cb9c9c730aae 100644
--- a/libc/test/src/math/smoke/bf16mull_test.cpp
+++ b/libc/test/src/math/smoke/bf16mull_test.cpp
@@ -8,8 +8,7 @@
 
 #include "MulTest.h"
 
-#include "src/math/bf16mull.h"
-
 #include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/bf16mull.h"
 
 LIST_MUL_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16mull)



More information about the libc-commits mailing list