[libc-commits] [compiler-rt] [libc] [compiler-rt][builtins] libc-backed float16 extend/truncate builtins (PR #211882)

Muhammad Bassiouni via libc-commits libc-commits at lists.llvm.org
Tue Aug 11 10:53:57 PDT 2026


================
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file implements compiler-rt's __extendhfsf2, extend float16 to float,
+/// on top of LLVM-libc's shared::extendhfsf2.
+///
+//===----------------------------------------------------------------------===//
+
+#define SRC_HALF
+#define DST_SINGLE
+#include "fp_extend_impl.inc"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/extendhfsf2.h"
+
+#if defined(LIBC_TYPES_HAS_FLOAT16)
+extern "C" COMPILER_RT_ABI NOINLINE dst_t __extendhfsf2(src_t a) {
+  return LIBC_NAMESPACE::shared::extendhfsf2(__builtin_bit_cast(uint16_t, a));
+}
+#else
+extern "C" COMPILER_RT_ABI NOINLINE dst_t __extendhfsf2(src_t a) {
+  return __extendXfYf2__(a);
+}
+#endif
+
+extern "C" {
+#if defined(__ARM_EABI__)
+#if defined(COMPILER_RT_ARMHF_TARGET)
+AEABI_RTABI dst_t __gnu_h2f_ieee(src_t a) { return __extendhfsf2(a); }
+AEABI_RTABI dst_t __aeabi_h2f(src_t a) { return __extendhfsf2(a); }
----------------
bassiounix wrote:

I'd prefer `LIBC_NAMESPACE::shared::extendhfsf2` over `__extendhfsf2` always.
I don't know if it's required to use `__extendhfsf2` instead, maybe @statham-arm could give the right direction here for this

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


More information about the libc-commits mailing list