[libc-commits] [libc] [llvm] [libc][math] Refactor bf16divl to header-only (#181025) (PR #181535)

via libc-commits libc-commits at lists.llvm.org
Sun Feb 15 00:53:41 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: AbdallahRashed (AbdallahRashed)

<details>
<summary>Changes</summary>

Move implementation inline to make it header-only. Remove the .cpp file and update build files accordingly. Also add bf16 narrow math functions to Bazel build.
I dont think it is possible to make it constexpr as it will require a lot of refactoring for div.h 

Part of https://github.com/llvm/llvm-project/issues/147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
Closes #<!-- -->181025

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


4 Files Affected:

- (modified) libc/src/math/bf16divl.h (+6-1) 
- (modified) libc/src/math/generic/CMakeLists.txt (+1-3) 
- (removed) libc/src/math/generic/bf16divl.cpp (-21) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+10) 


``````````diff
diff --git a/libc/src/math/bf16divl.h b/libc/src/math/bf16divl.h
index b19ac873af3f0..f8c6eb8abc7b6 100644
--- a/libc/src/math/bf16divl.h
+++ b/libc/src/math/bf16divl.h
@@ -9,12 +9,17 @@
 #ifndef LLVM_LIBC_SRC_MATH_BF16DIVL_H
 #define LLVM_LIBC_SRC_MATH_BF16DIVL_H
 
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/attributes.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);
+LIBC_INLINE bfloat16 bf16divl(long double x, long double y) {
+  return fputil::generic::div<bfloat16>(x, y);
+}
 
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 98d79e3b3826d..cafd515bee5eb 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5244,14 +5244,12 @@ add_entrypoint_object(
 
 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.attributes
     libc.src.__support.macros.config
     libc.src.__support.macros.properties.types
 )
diff --git a/libc/src/math/generic/bf16divl.cpp b/libc/src/math/generic/bf16divl.cpp
deleted file mode 100644
index 21dd6b150e07a..0000000000000
--- a/libc/src/math/generic/bf16divl.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-//===-- 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/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index e08d759f063b0..18a767f42bf77 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4253,6 +4253,16 @@ libc_math_function(
     additional_deps = [":__support_math_atanhf16"],
 )
 
+libc_math_function(name = "bf16addl")
+
+libc_math_function(name = "bf16divl")
+
+libc_math_function(name = "bf16fmal")
+
+libc_math_function(name = "bf16mull")
+
+libc_math_function(name = "bf16subl")
+
 libc_math_function(name = "canonicalize")
 
 libc_math_function(name = "canonicalizef")

``````````

</details>


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


More information about the libc-commits mailing list