[libc-commits] [libc] [libc][math][C23] add software float16 support (PR #184283)

via libc-commits libc-commits at lists.llvm.org
Fri Aug 28 21:32:31 PDT 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/src/__support/FPUtil/float16.h libc/test/src/__support/FPUtil/float16_test.cpp libc/test/src/math/exhaustive/float16_test.cpp libc/include/llvm-libc-macros/float16-macros.h libc/src/__support/CPP/type_traits/is_floating_point.h libc/src/__support/FPUtil/BasicOperations.h libc/src/__support/FPUtil/FPBits.h libc/src/__support/FPUtil/cast.h libc/src/__support/FPUtil/dyadic_float.h libc/src/__support/macros/properties/types.h libc/src/__support/math/fabsf16.h libc/test/src/__support/FPUtil/comparison_operations_test.cpp libc/test/src/__support/FPUtil/dyadic_float_test.cpp libc/test/src/math/exhaustive/exhaustive_test.h libc/test/src/math/smoke/fabsf16_test.cpp libc/utils/MPFRWrapper/MPCommon.cpp libc/utils/MPFRWrapper/MPCommon.h libc/utils/MPFRWrapper/MPFRUtils.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/CPP/type_traits/is_floating_point.h b/libc/src/__support/CPP/type_traits/is_floating_point.h
index 973fd9909..d64f8784d 100644
--- a/libc/src/__support/CPP/type_traits/is_floating_point.h
+++ b/libc/src/__support/CPP/type_traits/is_floating_point.h
@@ -41,11 +41,7 @@ public:
                               float128
 #endif
                               ,
-                              bfloat16
-                              ,
-                              fputil::Float16
-                              ,
-                              fputil::Float128
+                              bfloat16, fputil::Float16, fputil::Float128
 
                               ,
                               fputil::Float80>();
diff --git a/libc/src/__support/FPUtil/float16.h b/libc/src/__support/FPUtil/float16.h
index 21349d682..58672b6f2 100644
--- a/libc/src/__support/FPUtil/float16.h
+++ b/libc/src/__support/FPUtil/float16.h
@@ -31,7 +31,8 @@ struct Float16 {
 
   template <size_t Bits>
   LIBC_INLINE constexpr explicit Float16(const DyadicFloat<Bits> &df)
-      : bits(df.template as<Float16, /*ShouldSignalExceptions=*/false>().bits) {}
+      : bits(df.template as<Float16, /*ShouldSignalExceptions=*/false>().bits) {
+  }
 
   template <typename T>
   LIBC_INLINE constexpr explicit Float16(T value)
diff --git a/libc/test/src/__support/FPUtil/float16_test.cpp b/libc/test/src/__support/FPUtil/float16_test.cpp
index 203e22c58..674afd0fe 100644
--- a/libc/test/src/__support/FPUtil/float16_test.cpp
+++ b/libc/test/src/__support/FPUtil/float16_test.cpp
@@ -12,8 +12,7 @@
 #include "utils/MPFRWrapper/MPCommon.h"
 
 using Float16 = LIBC_NAMESPACE::fputil::Float16;
-using LlvmLibcFloat16ConversionTest =
-    LIBC_NAMESPACE::testing::FPTest<Float16>;
+using LlvmLibcFloat16ConversionTest = LIBC_NAMESPACE::testing::FPTest<Float16>;
 
 // range: [0, inf]
 static constexpr uint16_t POS_START = 0x0000U;
@@ -69,9 +68,9 @@ TEST_F(LlvmLibcFloat16ConversionTest, FromInteger) {
 }
 
 TEST_F(LlvmLibcFloat16ConversionTest, CompoundAssignmentOperators) {
-  constexpr Float16 VAL[] = {zero,           neg_zero,        inf,
-                             neg_inf,        min_normal,      max_normal,
-                             Float16(1.0f),  Float16(-1.0f),  Float16(2.0f),
+  constexpr Float16 VAL[] = {zero,          neg_zero,       inf,
+                             neg_inf,       min_normal,     max_normal,
+                             Float16(1.0f), Float16(-1.0f), Float16(2.0f),
                              Float16(3.0f)};
   // *=
   for (const Float16 &x : VAL) {
diff --git a/libc/utils/MPFRWrapper/MPCommon.cpp b/libc/utils/MPFRWrapper/MPCommon.cpp
index 0393ce642..96c4b3d48 100644
--- a/libc/utils/MPFRWrapper/MPCommon.cpp
+++ b/libc/utils/MPFRWrapper/MPCommon.cpp
@@ -10,8 +10,8 @@
 
 #include "src/__support/CPP/string_view.h"
 #include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/FPUtil/float16.h"
 #include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/float16.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/types.h"
 
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 32a6a3ee4..f39af3cba 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -118,15 +118,16 @@ public:
   // to float, as the MPFR API does not support float16, thus requiring
   // conversion to a higher-precision format.
   template <typename XType,
-            cpp::enable_if_t<cpp::is_same_v<float, XType>
+            cpp::enable_if_t<
+                cpp::is_same_v<float, XType>
 #ifdef LIBC_TYPES_HAS_FLOAT16
-                                 || cpp::is_same_v<float16, XType>
+                    || cpp::is_same_v<float16, XType>
 #endif
 #if !defined(LIBC_USE_SOFT_FLOAT16)
-                                 || cpp::is_same_v<LIBC_NAMESPACE::fputil::Float16, XType>
+                    || cpp::is_same_v<LIBC_NAMESPACE::fputil::Float16, XType>
 #endif
-                                 || cpp::is_same_v<bfloat16, XType>,
-                             int> = 0>
+                    || cpp::is_same_v<bfloat16, XType>,
+                int> = 0>
   explicit MPFRNumber(XType x,
                       unsigned int precision = ExtraPrecision<XType>::VALUE,
                       RoundingMode rounding = RoundingMode::Nearest)
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index 92ac58d9f..3e61031fd 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -11,8 +11,8 @@
 
 #include "src/__support/CPP/array.h"
 #include "src/__support/CPP/stringstream.h"
-#include "src/__support/FPUtil/float16.h"
 #include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/float16.h"
 #include "src/__support/FPUtil/fpbits_str.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/types.h"

``````````

</details>


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


More information about the libc-commits mailing list