[libc-commits] [libc] [libc][math] Refactor bf16divf implementation to header-only in src/__support/math folder. (PR #181086)

via libc-commits libc-commits at lists.llvm.org
Wed Feb 11 20:04:10 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: None (bala-bhargav)

<details>
<summary>Changes</summary>

Move bf16divf implementation to a LIBC_INLINE constexpr header-only function
in src/__support/math/bf16divf.h. The entrypoint in src/math/generic/bf16divf.cpp
now delegates to math::bf16divf(). CMake targets updated accordingly.

---
Full diff: https://github.com/llvm/llvm-project/pull/181086.diff


4 Files Affected:

- (modified) libc/src/__support/math/CMakeLists.txt (+10) 
- (added) libc/src/__support/math/bf16divf.h (+28) 
- (modified) libc/src/math/generic/CMakeLists.txt (+1-5) 
- (modified) libc/src/math/generic/bf16divf.cpp (+2-5) 


``````````diff
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 0fa48661e58e8..5554c9b976a9f 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -332,6 +332,16 @@ add_header_library(
     libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  bf16divf
+  HDRS
+    bf16divf.h
+  DEPENDS
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   cbrt
   HDRS
diff --git a/libc/src/__support/math/bf16divf.h b/libc/src/__support/math/bf16divf.h
new file mode 100644
index 0000000000000..ad5cb57aac828
--- /dev/null
+++ b/libc/src/__support/math/bf16divf.h
@@ -0,0 +1,28 @@
+//===-- 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___SUPPORT_MATH_BF16DIVF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_BF16DIVF_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 {
+
+LIBC_INLINE constexpr bfloat16 bf16divf(float x, float y) {
+  return fputil::generic::div<bfloat16>(x, y);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_BF16DIVF_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 2475aa52c3c0e..38d228c3177c1 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5320,11 +5320,7 @@ add_entrypoint_object(
   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
+    libc.src.__support.math.bf16divf
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/bf16divf.cpp b/libc/src/math/generic/bf16divf.cpp
index 2054a6417b078..767366a42d682 100644
--- a/libc/src/math/generic/bf16divf.cpp
+++ b/libc/src/math/generic/bf16divf.cpp
@@ -7,15 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #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"
+#include "src/__support/math/bf16divf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(bfloat16, bf16divf, (float x, float y)) {
-  return fputil::generic::div<bfloat16>(x, y);
+  return math::bf16divf(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

``````````

</details>


https://github.com/llvm/llvm-project/pull/181086


More information about the libc-commits mailing list