[libc-commits] [libc] [libc][math][c++23] Add bfloat16 support in LLVM libc (PR #144463)
via libc-commits
libc-commits at lists.llvm.org
Sun Jul 6 20:16:45 PDT 2025
================
@@ -26,9 +26,20 @@ LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
cpp::is_floating_point_v<InType>,
OutType>
cast(InType x) {
-#if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
- if constexpr (cpp::is_same_v<OutType, float16> ||
- cpp::is_same_v<InType, float16>) {
+
+ // no need to cast to the same type
+ if constexpr (cpp::is_same_v<InType, OutType>) {
+ return x;
+ }
+
+ // bfloat16 is always defined (for now)
+ if constexpr (cpp::is_same_v<OutType, bfloat16> ||
+ cpp::is_same_v<InType, bfloat16>
+#if (defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION))
+ || cpp::is_same_v<InType, float16> ||
+ cpp::is_same_v<InType, float16>
----------------
overmighty wrote:
```suggestion
|| cpp::is_same_v<OutType, float16> ||
cpp::is_same_v<InType, float16>
```
https://github.com/llvm/llvm-project/pull/144463
More information about the libc-commits
mailing list