[libc-commits] [libc] [libc][math][c++23] Add bfloat16 support in LLVM libc (PR #144463)

Krishna Pandey via libc-commits libc-commits at lists.llvm.org
Mon Jul 7 06:58:52 PDT 2025


================
@@ -415,7 +415,11 @@ template <size_t Bits> struct DyadicFloat {
     if constexpr (cpp::is_same_v<T, float16>)
       return generic_as<T, ShouldSignalExceptions>();
 #endif
-    return fast_as<T, ShouldSignalExceptions>();
+    if constexpr (cpp::is_same_v<T, bfloat16>) {
+      return generic_as<T, ShouldSignalExceptions>();
+    } else {
+      return fast_as<T, ShouldSignalExceptions>();
+    }
   }
----------------
krishna2803 wrote:

i actually did this earlier, but it didn't work maybe because since it is `constexpr`, the compiler actually tries to compile both of the branches despite the first one has a `return` clause.

```
[...]
note: in instantiation of function template specialization '__llvm_libc_21_0_0_git::fputil::DyadicFloat<64>::fast_as<__llvm_libc_21_0_0_git::BFloat16, true, void>' requested here
  421 |     return fast_as<T, ShouldSignalExceptions>();
      |            ^
/home/krishna/projects/llvm-project/libc/src/__support/FPUtil/cast.h:70:24: note: in instantiation of function template specialization '__llvm_libc_21_0_0_git::fputil::DyadicFloat<64>::as<__llvm_libc_21_0_0_git::BFloat16, true, void>' requested here
   70 |     return xd.template as<OutType, /*ShouldSignalExceptions=*/true>();
[...]
   ```

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


More information about the libc-commits mailing list