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

via libc-commits libc-commits at lists.llvm.org
Mon Jul 7 07:23:33 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>();
+    }
   }
----------------
overmighty wrote:

Right. Looks like the compiler isn't supposed to understand early returns before the template is instantiated, and an `else` in the `if constexpr` is the only way to make sure only `generic_as` or `fast_as` is instantiated and not both.

> During the instantiation of an enclosing templated entity ([temp.pre]), if the condition is not value-dependent after its instantiation, the discarded substatement (if any) is not instantiated.

https://eel.is/c++draft/stmt.if#2

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


More information about the libc-commits mailing list