[libc-commits] [libc] [llvm] [libc][math] change bf16fmal to be header-only and constexpr-compat (PR #181666)

via libc-commits libc-commits at lists.llvm.org
Mon Feb 16 06:03:32 PST 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- libc/shared/math/bf16fmal.h libc/src/__support/math/bf16fmal.h libc/src/__support/FPUtil/BasicOperations.h libc/src/__support/FPUtil/FMA.h libc/src/__support/FPUtil/bfloat16.h libc/src/__support/FPUtil/comparison_operations.h libc/src/__support/FPUtil/generic/FMA.h libc/src/__support/FPUtil/generic/add_sub.h libc/src/__support/FPUtil/generic/div.h libc/src/__support/FPUtil/generic/mul.h libc/src/math/bf16fmal.h libc/src/math/generic/bf16fmal.cpp libc/test/src/math/smoke/bf16fmal_test.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index f57336c44..1ddcbd13f 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -33,7 +33,8 @@ LIBC_INLINE constexpr T abs(T x) {
 namespace internal {
 
 template <typename T>
-LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, T> max(T x, T y) {
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, T>
+max(T x, T y) {
   FPBits<T> x_bits(x);
   FPBits<T> y_bits(y);
 
@@ -73,7 +74,8 @@ template <> LIBC_INLINE constexpr double max(double x, double y) {
 #endif
 
 template <typename T>
-LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, T> min(T x, T y) {
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, T>
+min(T x, T y) {
   FPBits<T> x_bits(x);
   FPBits<T> y_bits(y);
 
diff --git a/libc/src/__support/FPUtil/comparison_operations.h b/libc/src/__support/FPUtil/comparison_operations.h
index 71c0d9963..01092b4ae 100644
--- a/libc/src/__support/FPUtil/comparison_operations.h
+++ b/libc/src/__support/FPUtil/comparison_operations.h
@@ -26,8 +26,8 @@ namespace fputil {
 //    (iii) -inf != +inf
 // 3. Any comparison with NaN returns false
 template <typename T>
-LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, bool> equals(T x,
-                                                                       T y) {
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, bool>
+equals(T x, T y) {
   using FPBits = FPBits<T>;
   FPBits x_bits(x);
   FPBits y_bits(y);
@@ -52,8 +52,8 @@ LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, bool> equals
 // 2. x < +inf (x != +inf)
 // 3. Any comparison with NaN return false
 template <typename T>
-LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, bool> less_than(T x,
-                                                                          T y) {
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, bool>
+less_than(T x, T y) {
   using FPBits = FPBits<T>;
   FPBits x_bits(x);
   FPBits y_bits(y);
diff --git a/libc/src/__support/FPUtil/generic/FMA.h b/libc/src/__support/FPUtil/generic/FMA.h
index dd102c3fb..d55f87971 100644
--- a/libc/src/__support/FPUtil/generic/FMA.h
+++ b/libc/src/__support/FPUtil/generic/FMA.h
@@ -30,9 +30,9 @@ namespace generic {
 
 template <typename OutType, typename InType>
 LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
-                                 cpp::is_floating_point_v<InType> &&
-                                 sizeof(OutType) <= sizeof(InType),
-                             OutType>
+                                           cpp::is_floating_point_v<InType> &&
+                                           sizeof(OutType) <= sizeof(InType),
+                                       OutType>
 fma(InType x, InType y, InType z);
 
 // TODO(lntue): Implement fmaf that is correctly rounded to all rounding modes.
@@ -90,7 +90,8 @@ namespace internal {
 // Extract the sticky bits and shift the `mantissa` to the right by
 // `shift_length`.
 template <typename T>
-LIBC_INLINE constexpr cpp::enable_if_t<is_unsigned_integral_or_big_int_v<T>, bool>
+LIBC_INLINE constexpr cpp::enable_if_t<is_unsigned_integral_or_big_int_v<T>,
+                                       bool>
 shift_mantissa(int shift_length, T &mant) {
   if (shift_length >= cpp::numeric_limits<T>::digits) {
     mant = 0;
@@ -106,9 +107,9 @@ shift_mantissa(int shift_length, T &mant) {
 
 template <typename OutType, typename InType>
 LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
-                                 cpp::is_floating_point_v<InType> &&
-                                 sizeof(OutType) <= sizeof(InType),
-                             OutType>
+                                           cpp::is_floating_point_v<InType> &&
+                                           sizeof(OutType) <= sizeof(InType),
+                                       OutType>
 fma(InType x, InType y, InType z) {
   using OutFPBits = FPBits<OutType>;
   using OutStorageType = typename OutFPBits::StorageType;
diff --git a/libc/src/__support/FPUtil/generic/add_sub.h b/libc/src/__support/FPUtil/generic/add_sub.h
index ea046dc89..7d5eb08d4 100644
--- a/libc/src/__support/FPUtil/generic/add_sub.h
+++ b/libc/src/__support/FPUtil/generic/add_sub.h
@@ -28,9 +28,9 @@ namespace fputil::generic {
 
 template <bool IsSub, typename OutType, typename InType>
 LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
-                                 cpp::is_floating_point_v<InType> &&
-                                 sizeof(OutType) <= sizeof(InType),
-                             OutType>
+                                           cpp::is_floating_point_v<InType> &&
+                                           sizeof(OutType) <= sizeof(InType),
+                                       OutType>
 add_or_sub(InType x, InType y) {
   using OutFPBits = FPBits<OutType>;
   using OutStorageType = typename OutFPBits::StorageType;
@@ -202,18 +202,18 @@ add_or_sub(InType x, InType y) {
 
 template <typename OutType, typename InType>
 LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
-                                 cpp::is_floating_point_v<InType> &&
-                                 sizeof(OutType) <= sizeof(InType),
-                             OutType>
+                                           cpp::is_floating_point_v<InType> &&
+                                           sizeof(OutType) <= sizeof(InType),
+                                       OutType>
 add(InType x, InType y) {
   return add_or_sub</*IsSub=*/false, OutType>(x, y);
 }
 
 template <typename OutType, typename InType>
 LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
-                                 cpp::is_floating_point_v<InType> &&
-                                 sizeof(OutType) <= sizeof(InType),
-                             OutType>
+                                           cpp::is_floating_point_v<InType> &&
+                                           sizeof(OutType) <= sizeof(InType),
+                                       OutType>
 sub(InType x, InType y) {
   return add_or_sub</*IsSub=*/true, OutType>(x, y);
 }
diff --git a/libc/src/__support/FPUtil/generic/div.h b/libc/src/__support/FPUtil/generic/div.h
index 993ac1656..85026bb3f 100644
--- a/libc/src/__support/FPUtil/generic/div.h
+++ b/libc/src/__support/FPUtil/generic/div.h
@@ -27,9 +27,9 @@ namespace fputil::generic {
 
 template <typename OutType, typename InType>
 LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
-                                 cpp::is_floating_point_v<InType> &&
-                                 sizeof(OutType) <= sizeof(InType),
-                             OutType>
+                                           cpp::is_floating_point_v<InType> &&
+                                           sizeof(OutType) <= sizeof(InType),
+                                       OutType>
 div(InType x, InType y) {
   using OutFPBits = FPBits<OutType>;
   using OutStorageType = typename OutFPBits::StorageType;
diff --git a/libc/src/__support/FPUtil/generic/mul.h b/libc/src/__support/FPUtil/generic/mul.h
index 1c75503cd..22c685994 100644
--- a/libc/src/__support/FPUtil/generic/mul.h
+++ b/libc/src/__support/FPUtil/generic/mul.h
@@ -26,9 +26,9 @@ namespace fputil::generic {
 
 template <typename OutType, typename InType>
 LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
-                                 cpp::is_floating_point_v<InType> &&
-                                 sizeof(OutType) <= sizeof(InType),
-                             OutType>
+                                           cpp::is_floating_point_v<InType> &&
+                                           sizeof(OutType) <= sizeof(InType),
+                                       OutType>
 mul(InType x, InType y) {
   using OutFPBits = FPBits<OutType>;
   using OutStorageType = typename OutFPBits::StorageType;
diff --git a/libc/src/__support/math/bf16fmal.h b/libc/src/__support/math/bf16fmal.h
index 70e8a0704..706183db8 100644
--- a/libc/src/__support/math/bf16fmal.h
+++ b/libc/src/__support/math/bf16fmal.h
@@ -17,7 +17,8 @@
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE constexpr bfloat16 bf16fmal(long double x, long double y, long double z) {
+LIBC_INLINE constexpr bfloat16 bf16fmal(long double x, long double y,
+                                        long double z) {
   return fputil::fma<bfloat16>(x, y, z);
 }
 
diff --git a/libc/test/src/math/smoke/bf16fmal_test.cpp b/libc/test/src/math/smoke/bf16fmal_test.cpp
index 17498ffe1..44bc24178 100644
--- a/libc/test/src/math/smoke/bf16fmal_test.cpp
+++ b/libc/test/src/math/smoke/bf16fmal_test.cpp
@@ -13,4 +13,5 @@
 
 LIST_NARROWING_FMA_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16fmal)
 
-static_assert(LIBC_NAMESPACE::math::bf16fmal(1.0l, 2.0l, 3.0l) == bfloat16(5.0f));
+static_assert(LIBC_NAMESPACE::math::bf16fmal(1.0l, 2.0l, 3.0l) ==
+              bfloat16(5.0f));

``````````

</details>


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


More information about the libc-commits mailing list