[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:03:32 PST 2026
https://github.com/bala-bhargav created https://github.com/llvm/llvm-project/pull/181086
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.
>From 7e2cf9484c4d913e0a82ec7a219f3d146bbc2940 Mon Sep 17 00:00:00 2001
From: bhargav <penugondabalabharghav at gmail.com>
Date: Thu, 12 Feb 2026 07:33:03 +0530
Subject: [PATCH] [libc][math] Refactor bf16divf implementation to header-only
in src/__support/math folder.
Move bf16divf implementation from src/math/generic/bf16divf.cpp to a
header-only LIBC_INLINE constexpr function in
src/__support/math/bf16divf.h, following the established pattern for
shared math functions.
Part of #147386.
Fixes #181023.
---
libc/src/__support/math/CMakeLists.txt | 10 +++++++++
libc/src/__support/math/bf16divf.h | 28 ++++++++++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 6 +-----
libc/src/math/generic/bf16divf.cpp | 7 ++-----
4 files changed, 41 insertions(+), 10 deletions(-)
create mode 100644 libc/src/__support/math/bf16divf.h
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
More information about the libc-commits
mailing list