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

via libc-commits libc-commits at lists.llvm.org
Fri Jul 24 11:55:24 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: hulxv (hulxv)

<details>
<summary>Changes</summary>

add libc-backed bfloat16 extend/truncate builtins

depends on:
   - #<!-- -->209984
   
Part of #<!-- -->197824

---

Patch is 72.53 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/211882.diff


48 Files Affected:

- (modified) compiler-rt/lib/builtins/CMakeLists.txt (+35-21) 
- (added) compiler-rt/lib/builtins/extenddftf2.cpp (+25) 
- (added) compiler-rt/lib/builtins/extendhfdf2.cpp (+30) 
- (added) compiler-rt/lib/builtins/extendhfsf2.cpp (+44) 
- (added) compiler-rt/lib/builtins/extendhftf2.cpp (+35) 
- (added) compiler-rt/lib/builtins/extendsfdf2.cpp (+21) 
- (added) compiler-rt/lib/builtins/extendsftf2.cpp (+25) 
- (added) compiler-rt/lib/builtins/extendxftf2.cpp (+25) 
- (added) compiler-rt/lib/builtins/truncdfhf2.cpp (+30) 
- (added) compiler-rt/lib/builtins/truncdfsf2.cpp (+21) 
- (added) compiler-rt/lib/builtins/truncsfhf2.cpp (+44) 
- (added) compiler-rt/lib/builtins/trunctfdf2.cpp (+25) 
- (added) compiler-rt/lib/builtins/trunctfhf2.cpp (+35) 
- (added) compiler-rt/lib/builtins/trunctfsf2.cpp (+25) 
- (added) compiler-rt/lib/builtins/trunctfxf2.cpp (+25) 
- (modified) libc/shared/builtins.h (+12) 
- (added) libc/shared/builtins/extenddftf2.h (+35) 
- (added) libc/shared/builtins/extendhfdf2.h (+35) 
- (added) libc/shared/builtins/extendhfsf2.h (+35) 
- (added) libc/shared/builtins/extendhftf2.h (+36) 
- (added) libc/shared/builtins/extendsfdf2.h (+29) 
- (added) libc/shared/builtins/extendsftf2.h (+35) 
- (added) libc/shared/builtins/extendxftf2.h (+37) 
- (added) libc/shared/builtins/truncdfhf2.h (+35) 
- (added) libc/shared/builtins/truncdfsf2.h (+29) 
- (added) libc/shared/builtins/truncsfhf2.h (+35) 
- (added) libc/shared/builtins/trunctfdf2.h (+35) 
- (added) libc/shared/builtins/trunctfhf2.h (+36) 
- (added) libc/shared/builtins/trunctfsf2.h (+35) 
- (added) libc/shared/builtins/trunctfxf2.h (+37) 
- (modified) libc/src/__support/builtins/CMakeLists.txt (+208) 
- (added) libc/src/__support/builtins/extenddftf2.h (+36) 
- (added) libc/src/__support/builtins/extendhfdf2.h (+39) 
- (added) libc/src/__support/builtins/extendhfsf2.h (+39) 
- (added) libc/src/__support/builtins/extendhftf2.h (+40) 
- (added) libc/src/__support/builtins/extendsfdf2.h (+30) 
- (added) libc/src/__support/builtins/extendsftf2.h (+36) 
- (added) libc/src/__support/builtins/extendxftf2.h (+40) 
- (added) libc/src/__support/builtins/fpconvert_helper.h (+100) 
- (added) libc/src/__support/builtins/truncdfhf2.h (+40) 
- (added) libc/src/__support/builtins/truncdfsf2.h (+30) 
- (added) libc/src/__support/builtins/truncsfhf2.h (+40) 
- (added) libc/src/__support/builtins/trunctfdf2.h (+36) 
- (added) libc/src/__support/builtins/trunctfhf2.h (+41) 
- (added) libc/src/__support/builtins/trunctfsf2.h (+36) 
- (added) libc/src/__support/builtins/trunctfxf2.h (+40) 
- (modified) libc/test/shared/CMakeLists.txt (+18) 
- (modified) libc/test/shared/shared_builtins_test.cpp (+24) 


``````````diff
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index ea21c36d3d31f..62f46e753b1e6 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -243,6 +243,27 @@ set(GENERIC_TF_SOURCES
   trunctfsf2.c
 )
 
+# Implement extended-precision builtins, assuming long double is 80 bits.
+# long double is not 80 bits on Android or MSVC.
+set(x86_80_BIT_SOURCES
+  divxc3.c
+  extendhfxf2.c
+  extendxftf2.c
+  fixxfdi.c
+  fixxfti.c
+  fixunsxfdi.c
+  fixunsxfsi.c
+  fixunsxfti.c
+  floatdixf.c
+  floattixf.c
+  floatundixf.c
+  floatuntixf.c
+  mulxc3.c
+  powixf2.c
+  trunctfxf2.c
+  truncxfhf2.c
+)
+
 option(COMPILER_RT_USE_LIBC_MATH
       "Use LLVM libc math routines for floating-point builtins" OFF)
 
@@ -265,6 +286,20 @@ if(COMPILER_RT_USE_LIBC_MATH)
   add_definitions(-DCOMPILER_RT_USE_LIBC_MATH)
 
   use_libc_builtin(GENERIC_TF_SOURCES addtf3)
+  use_libc_builtin(GENERIC_TF_SOURCES extenddftf2)
+  use_libc_builtin(GENERIC_SOURCES    extendhfsf2)
+  use_libc_builtin(GENERIC_SOURCES    extendhfdf2)
+  use_libc_builtin(GENERIC_TF_SOURCES extendhftf2)
+  use_libc_builtin(GENERIC_SOURCES    extendsfdf2)
+  use_libc_builtin(GENERIC_TF_SOURCES extendsftf2)
+  use_libc_builtin(x86_80_BIT_SOURCES extendxftf2)
+  use_libc_builtin(GENERIC_SOURCES    truncdfsf2)  
+  use_libc_builtin(GENERIC_TF_SOURCES trunctfdf2)
+  use_libc_builtin(GENERIC_SOURCES    truncsfhf2)
+  use_libc_builtin(GENERIC_SOURCES    truncdfhf2)
+  use_libc_builtin(GENERIC_TF_SOURCES trunctfhf2)
+  use_libc_builtin(GENERIC_TF_SOURCES trunctfsf2)
+  use_libc_builtin(x86_80_BIT_SOURCES trunctfxf2)
 endif()
 
 option(COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN
@@ -336,27 +371,6 @@ if (NOT MSVC)
   )
 endif ()
 
-# Implement extended-precision builtins, assuming long double is 80 bits.
-# long double is not 80 bits on Android or MSVC.
-set(x86_80_BIT_SOURCES
-  divxc3.c
-  extendhfxf2.c
-  extendxftf2.c
-  fixxfdi.c
-  fixxfti.c
-  fixunsxfdi.c
-  fixunsxfsi.c
-  fixunsxfti.c
-  floatdixf.c
-  floattixf.c
-  floatundixf.c
-  floatuntixf.c
-  mulxc3.c
-  powixf2.c
-  trunctfxf2.c
-  truncxfhf2.c
-)
-
 if (NOT MSVC)
   set(x86_64_SOURCES
     ${GENERIC_SOURCES}
diff --git a/compiler-rt/lib/builtins/extenddftf2.cpp b/compiler-rt/lib/builtins/extenddftf2.cpp
new file mode 100644
index 0000000000000..38f201316a1cd
--- /dev/null
+++ b/compiler-rt/lib/builtins/extenddftf2.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __extenddftf2, extend double to float128,
+/// on top of LLVM-libc's shared::extenddftf2.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/extenddftf2.h"
+
+#ifdef CRT_HAS_TF_MODE
+extern "C" COMPILER_RT_ABI tf_float __extenddftf2(double a) {
+  return LIBC_NAMESPACE::shared::extenddftf2(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/extendhfdf2.cpp b/compiler-rt/lib/builtins/extendhfdf2.cpp
new file mode 100644
index 0000000000000..f1d40971b7f45
--- /dev/null
+++ b/compiler-rt/lib/builtins/extendhfdf2.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __extendhfdf2, extend float16 to double,
+/// on top of LLVM-libc's shared::extendhfdf2.
+///
+//===----------------------------------------------------------------------===//
+
+#define SRC_HALF
+#define DST_DOUBLE
+#include "fp_extend_impl.inc"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/extendhfdf2.h"
+
+#if defined(LIBC_TYPES_HAS_FLOAT16)
+extern "C" COMPILER_RT_ABI NOINLINE dst_t __extendhfdf2(src_t a) {
+  return LIBC_NAMESPACE::shared::extendhfdf2(__builtin_bit_cast(uint16_t, a));
+}
+#else
+extern "C" COMPILER_RT_ABI NOINLINE dst_t __extendhfdf2(src_t a) {
+  return __extendXfYf2__(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/extendhfsf2.cpp b/compiler-rt/lib/builtins/extendhfsf2.cpp
new file mode 100644
index 0000000000000..6dc3ef17c22d5
--- /dev/null
+++ b/compiler-rt/lib/builtins/extendhfsf2.cpp
@@ -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); }
+#else
+COMPILER_RT_ALIAS(__extendhfsf2, __gnu_h2f_ieee)
+COMPILER_RT_ALIAS(__extendhfsf2, __aeabi_h2f)
+#endif
+#else
+COMPILER_RT_ABI dst_t __gnu_h2f_ieee(src_t a) { return __extendhfsf2(a); }
+#endif
+}
diff --git a/compiler-rt/lib/builtins/extendhftf2.cpp b/compiler-rt/lib/builtins/extendhftf2.cpp
new file mode 100644
index 0000000000000..2b035ee639b22
--- /dev/null
+++ b/compiler-rt/lib/builtins/extendhftf2.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __extendhftf2, extend float16 to
+/// float128, on top of LLVM-libc's shared::extendhftf2.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/extendhftf2.h"
+
+#if defined(CRT_HAS_TF_MODE) && defined(COMPILER_RT_HAS_FLOAT16)
+#define SRC_HALF
+#define DST_QUAD
+#include "fp_extend_impl.inc"
+
+#if defined(LIBC_TYPES_HAS_FLOAT16)
+extern "C" COMPILER_RT_ABI dst_t __extendhftf2(src_t a) {
+  return LIBC_NAMESPACE::shared::extendhftf2(__builtin_bit_cast(uint16_t, a));
+}
+#else
+extern "C" COMPILER_RT_ABI dst_t __extendhftf2(src_t a) {
+  return __extendXfYf2__(a);
+}
+#endif
+#endif
diff --git a/compiler-rt/lib/builtins/extendsfdf2.cpp b/compiler-rt/lib/builtins/extendsfdf2.cpp
new file mode 100644
index 0000000000000..e7c48dbac0cd8
--- /dev/null
+++ b/compiler-rt/lib/builtins/extendsfdf2.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __extendsfdf2, extend float to double, on
+/// top of LLVM-libc's shared::extendsfdf2.
+///
+//===----------------------------------------------------------------------===//
+
+#include "shared/builtins/extendsfdf2.h"
+#include "fp_libc_config.h"
+#include "int_lib.h"
+
+extern "C" COMPILER_RT_ABI double __extendsfdf2(float a) {
+  return LIBC_NAMESPACE::shared::extendsfdf2(a);
+}
diff --git a/compiler-rt/lib/builtins/extendsftf2.cpp b/compiler-rt/lib/builtins/extendsftf2.cpp
new file mode 100644
index 0000000000000..0c6cc83b9d142
--- /dev/null
+++ b/compiler-rt/lib/builtins/extendsftf2.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __extendsftf2, extend float to float128,
+/// on top of LLVM-libc's shared::extendsftf2.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/extendsftf2.h"
+
+#ifdef CRT_HAS_TF_MODE
+extern "C" COMPILER_RT_ABI tf_float __extendsftf2(float a) {
+  return LIBC_NAMESPACE::shared::extendsftf2(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/extendxftf2.cpp b/compiler-rt/lib/builtins/extendxftf2.cpp
new file mode 100644
index 0000000000000..5c0c91118ecbe
--- /dev/null
+++ b/compiler-rt/lib/builtins/extendxftf2.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __extendxftf2, extend long double to
+/// float128, on top of LLVM-libc's shared::extendxftf2.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/extendxftf2.h"
+
+#if defined(CRT_HAS_TF_MODE) && __LDBL_MANT_DIG__ == 64 && defined(__x86_64__)
+extern "C" COMPILER_RT_ABI tf_float __extendxftf2(xf_float a) {
+  return LIBC_NAMESPACE::shared::extendxftf2(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/truncdfhf2.cpp b/compiler-rt/lib/builtins/truncdfhf2.cpp
new file mode 100644
index 0000000000000..ab08483cdabfa
--- /dev/null
+++ b/compiler-rt/lib/builtins/truncdfhf2.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __truncdfhf2, truncate double to float16,
+/// on top of LLVM-libc's shared::truncdfhf2.
+///
+//===----------------------------------------------------------------------===//
+
+#define SRC_DOUBLE
+#define DST_HALF
+#include "fp_trunc_impl.inc"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/truncdfhf2.h"
+
+#if defined(LIBC_TYPES_HAS_FLOAT16)
+extern "C" COMPILER_RT_ABI dst_t __truncdfhf2(src_t a) {
+  return __builtin_bit_cast(dst_t, LIBC_NAMESPACE::shared::truncdfhf2(a));
+}
+#else
+extern "C" COMPILER_RT_ABI dst_t __truncdfhf2(src_t a) {
+  return __truncXfYf2__(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/truncdfsf2.cpp b/compiler-rt/lib/builtins/truncdfsf2.cpp
new file mode 100644
index 0000000000000..775526dbff96a
--- /dev/null
+++ b/compiler-rt/lib/builtins/truncdfsf2.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __truncdfsf2, truncate double to float,
+/// on top of LLVM-libc's shared::truncdfsf2.
+///
+//===----------------------------------------------------------------------===//
+
+#include "shared/builtins/truncdfsf2.h"
+#include "fp_libc_config.h"
+#include "int_lib.h"
+
+extern "C" COMPILER_RT_ABI float __truncdfsf2(double a) {
+  return LIBC_NAMESPACE::shared::truncdfsf2(a);
+}
diff --git a/compiler-rt/lib/builtins/truncsfhf2.cpp b/compiler-rt/lib/builtins/truncsfhf2.cpp
new file mode 100644
index 0000000000000..3fa614d2970fe
--- /dev/null
+++ b/compiler-rt/lib/builtins/truncsfhf2.cpp
@@ -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 __truncsfhf2, truncate float to float16,
+/// on top of LLVM-libc's shared::truncsfhf2.
+///
+//===----------------------------------------------------------------------===//
+
+#define SRC_SINGLE
+#define DST_HALF
+#include "fp_trunc_impl.inc"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/truncsfhf2.h"
+
+#if defined(LIBC_TYPES_HAS_FLOAT16)
+extern "C" COMPILER_RT_ABI NOINLINE dst_t __truncsfhf2(src_t a) {
+  return __builtin_bit_cast(dst_t, LIBC_NAMESPACE::shared::truncsfhf2(a));
+}
+#else
+extern "C" COMPILER_RT_ABI NOINLINE dst_t __truncsfhf2(src_t a) {
+  return __truncXfYf2__(a);
+}
+#endif
+
+extern "C" {
+#if defined(__ARM_EABI__)
+#if defined(COMPILER_RT_ARMHF_TARGET)
+AEABI_RTABI dst_t __gnu_f2h_ieee(float a) { return __truncsfhf2(a); }
+AEABI_RTABI dst_t __aeabi_f2h(float a) { return __truncsfhf2(a); }
+#else
+COMPILER_RT_ALIAS(__truncsfhf2, __gnu_f2h_ieee)
+COMPILER_RT_ALIAS(__truncsfhf2, __aeabi_f2h)
+#endif
+#else
+COMPILER_RT_ABI dst_t __gnu_f2h_ieee(float a) { return __truncsfhf2(a); }
+#endif
+}
diff --git a/compiler-rt/lib/builtins/trunctfdf2.cpp b/compiler-rt/lib/builtins/trunctfdf2.cpp
new file mode 100644
index 0000000000000..487a09bba0071
--- /dev/null
+++ b/compiler-rt/lib/builtins/trunctfdf2.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __trunctfdf2, truncate float128 to
+/// double, on top of LLVM-libc's shared::trunctfdf2.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/trunctfdf2.h"
+
+#ifdef CRT_HAS_TF_MODE
+extern "C" COMPILER_RT_ABI double __trunctfdf2(tf_float a) {
+  return LIBC_NAMESPACE::shared::trunctfdf2(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/trunctfhf2.cpp b/compiler-rt/lib/builtins/trunctfhf2.cpp
new file mode 100644
index 0000000000000..a1c06a9415229
--- /dev/null
+++ b/compiler-rt/lib/builtins/trunctfhf2.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __trunctfhf2, truncate float128 to
+/// float16, on top of LLVM-libc's shared::trunctfhf2.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/trunctfhf2.h"
+
+#if defined(CRT_HAS_TF_MODE) && defined(COMPILER_RT_HAS_FLOAT16)
+#define SRC_QUAD
+#define DST_HALF
+#include "fp_trunc_impl.inc"
+
+#if defined(LIBC_TYPES_HAS_FLOAT16)
+extern "C" COMPILER_RT_ABI dst_t __trunctfhf2(src_t a) {
+  return __builtin_bit_cast(dst_t, LIBC_NAMESPACE::shared::trunctfhf2(a));
+}
+#else
+extern "C" COMPILER_RT_ABI dst_t __trunctfhf2(src_t a) {
+  return __truncXfYf2__(a);
+}
+#endif
+#endif
diff --git a/compiler-rt/lib/builtins/trunctfsf2.cpp b/compiler-rt/lib/builtins/trunctfsf2.cpp
new file mode 100644
index 0000000000000..2486cb3a39a7f
--- /dev/null
+++ b/compiler-rt/lib/builtins/trunctfsf2.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __trunctfsf2, truncate float128 to float,
+/// on top of LLVM-libc's shared::trunctfsf2.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/trunctfsf2.h"
+
+#ifdef CRT_HAS_TF_MODE
+extern "C" COMPILER_RT_ABI float __trunctfsf2(tf_float a) {
+  return LIBC_NAMESPACE::shared::trunctfsf2(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/trunctfxf2.cpp b/compiler-rt/lib/builtins/trunctfxf2.cpp
new file mode 100644
index 0000000000000..88dae578025bc
--- /dev/null
+++ b/compiler-rt/lib/builtins/trunctfxf2.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __trunctfxf2, truncate float128 to long
+/// double, on top of LLVM-libc's shared::trunctfxf2.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/trunctfxf2.h"
+
+#if defined(CRT_HAS_TF_MODE) && __LDBL_MANT_DIG__ == 64 && defined(__x86_64__)
+extern "C" COMPILER_RT_ABI xf_float __trunctfxf2(tf_float a) {
+  return LIBC_NAMESPACE::shared::trunctfxf2(a);
+}
+#endif
diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index ced054cb02582..52d8ab48b41e8 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -23,11 +23,23 @@
 #include "builtins/divdf3.h"
 #include "builtins/divsf3.h"
 #include "builtins/divtf3.h"
+#include "builtins/extenddftf2.h"
+#include "builtins/extendhfdf2.h"
+#include "builtins/extendhfsf2.h"
+#include "builtins/extendhftf2.h"
+#include "builtins/extendsfdf2.h"
+#include "builtins/extendsftf2.h"
+#include "builtins/extendxftf2.h"
 #include "builtins/muldf3.h"
 #include "builtins/mulsf3.h"
 #include "builtins/multf3.h"
 #include "builtins/subdf3.h"
 #include "builtins/subsf3....
[truncated]

``````````

</details>


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


More information about the libc-commits mailing list