[llvm-branch-commits] [compiler-rt] [libc] [compiler-rt][builtins] libc-backed quad-to-int conversion builtins (PR #215727)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 11 22:48:03 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: hulxv (hulxv)

<details>
<summary>Changes</summary>

libc-backed quad precision to integer conversion builtins

Part of #<!-- -->197824

<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>

---

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


23 Files Affected:

- (modified) compiler-rt/lib/builtins/CMakeLists.txt (+6) 
- (added) compiler-rt/lib/builtins/fixtfdi.cpp (+26) 
- (added) compiler-rt/lib/builtins/fixtfsi.cpp (+26) 
- (added) compiler-rt/lib/builtins/fixtfti.cpp (+26) 
- (added) compiler-rt/lib/builtins/fixunstfdi.cpp (+26) 
- (added) compiler-rt/lib/builtins/fixunstfsi.cpp (+26) 
- (added) compiler-rt/lib/builtins/fixunstfti.cpp (+27) 
- (modified) libc/shared/builtins.h (+6) 
- (added) libc/shared/builtins/fixtfdi.h (+35) 
- (added) libc/shared/builtins/fixtfsi.h (+35) 
- (added) libc/shared/builtins/fixtfti.h (+36) 
- (added) libc/shared/builtins/fixunstfdi.h (+35) 
- (added) libc/shared/builtins/fixunstfsi.h (+35) 
- (added) libc/shared/builtins/fixunstfti.h (+36) 
- (modified) libc/src/__support/builtins/CMakeLists.txt (+79) 
- (added) libc/src/__support/builtins/fixtfdi.h (+40) 
- (added) libc/src/__support/builtins/fixtfsi.h (+40) 
- (added) libc/src/__support/builtins/fixtfti.h (+41) 
- (added) libc/src/__support/builtins/fixunstfdi.h (+40) 
- (added) libc/src/__support/builtins/fixunstfsi.h (+40) 
- (added) libc/src/__support/builtins/fixunstfti.h (+41) 
- (modified) libc/test/shared/CMakeLists.txt (+6) 
- (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 73c2743ec7abe..5fe4adf2a2e99 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -340,6 +340,12 @@ if(COMPILER_RT_USE_LIBC_MATH)
   use_libc_builtin(GENERIC_TF_SOURCES trunctfdf2)
   use_libc_builtin(GENERIC_TF_SOURCES trunctfsf2)
   use_libc_builtin(x86_80_BIT_SOURCES trunctfxf2)
+  use_libc_builtin(GENERIC_TF_SOURCES fixtfsi)
+  use_libc_builtin(GENERIC_TF_SOURCES fixtfdi)
+  use_libc_builtin(GENERIC_TF_SOURCES fixtfti)
+  use_libc_builtin(GENERIC_TF_SOURCES fixunstfsi)
+  use_libc_builtin(GENERIC_TF_SOURCES fixunstfdi)
+  use_libc_builtin(GENERIC_TF_SOURCES fixunstfti)
 endif()
 
 option(COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN
diff --git a/compiler-rt/lib/builtins/fixtfdi.cpp b/compiler-rt/lib/builtins/fixtfdi.cpp
new file mode 100644
index 0000000000000..f95f24a1f699d
--- /dev/null
+++ b/compiler-rt/lib/builtins/fixtfdi.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __fixtfdi, truncating float128 -> int64_t
+/// conversion (saturating), on top of LLVM-libc's shared::fixtfdi.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/fixtfdi.h"
+
+#if defined(CRT_HAS_TF_MODE)
+extern "C" COMPILER_RT_ABI di_int __fixtfdi(fp_t a) {
+  return LIBC_NAMESPACE::shared::fixtfdi(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/fixtfsi.cpp b/compiler-rt/lib/builtins/fixtfsi.cpp
new file mode 100644
index 0000000000000..e5220732a7453
--- /dev/null
+++ b/compiler-rt/lib/builtins/fixtfsi.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __fixtfsi, truncating float128 -> int32_t
+/// conversion (saturating), on top of LLVM-libc's shared::fixtfsi.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/fixtfsi.h"
+
+#if defined(CRT_HAS_TF_MODE)
+extern "C" COMPILER_RT_ABI si_int __fixtfsi(fp_t a) {
+  return LIBC_NAMESPACE::shared::fixtfsi(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/fixtfti.cpp b/compiler-rt/lib/builtins/fixtfti.cpp
new file mode 100644
index 0000000000000..c3d84d5d21097
--- /dev/null
+++ b/compiler-rt/lib/builtins/fixtfti.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __fixtfti, truncating float128 ->
+/// __int128_t conversion (saturating), on top of LLVM-libc's shared::fixtfti.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/fixtfti.h"
+
+#if defined(CRT_HAS_TF_MODE)
+extern "C" COMPILER_RT_ABI ti_int __fixtfti(fp_t a) {
+  return LIBC_NAMESPACE::shared::fixtfti(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/fixunstfdi.cpp b/compiler-rt/lib/builtins/fixunstfdi.cpp
new file mode 100644
index 0000000000000..2025e6c290ff4
--- /dev/null
+++ b/compiler-rt/lib/builtins/fixunstfdi.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __fixunstfdi, truncating float128 ->
+/// uint64_t conversion (saturating), on top of LLVM-libc's shared::fixunstfdi.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/fixunstfdi.h"
+
+#if defined(CRT_HAS_TF_MODE)
+extern "C" COMPILER_RT_ABI du_int __fixunstfdi(fp_t a) {
+  return LIBC_NAMESPACE::shared::fixunstfdi(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/fixunstfsi.cpp b/compiler-rt/lib/builtins/fixunstfsi.cpp
new file mode 100644
index 0000000000000..aca69261270e8
--- /dev/null
+++ b/compiler-rt/lib/builtins/fixunstfsi.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __fixunstfsi, truncating float128 ->
+/// uint32_t conversion (saturating), on top of LLVM-libc's shared::fixunstfsi.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/fixunstfsi.h"
+
+#if defined(CRT_HAS_TF_MODE)
+extern "C" COMPILER_RT_ABI su_int __fixunstfsi(fp_t a) {
+  return LIBC_NAMESPACE::shared::fixunstfsi(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/fixunstfti.cpp b/compiler-rt/lib/builtins/fixunstfti.cpp
new file mode 100644
index 0000000000000..02b9a464a955c
--- /dev/null
+++ b/compiler-rt/lib/builtins/fixunstfti.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __fixunstfti, truncating float128 ->
+/// __uint128_t conversion (saturating), on top of LLVM-libc's
+/// shared::fixunstfti.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/fixunstfti.h"
+
+#if defined(CRT_HAS_TF_MODE)
+extern "C" COMPILER_RT_ABI tu_int __fixunstfti(fp_t a) {
+  return LIBC_NAMESPACE::shared::fixunstfti(a);
+}
+#endif
diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 6e59031aa28a3..c1af1d39733ff 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -33,12 +33,18 @@
 #include "builtins/fixsfdi.h"
 #include "builtins/fixsfsi.h"
 #include "builtins/fixsfti.h"
+#include "builtins/fixtfdi.h"
+#include "builtins/fixtfsi.h"
+#include "builtins/fixtfti.h"
 #include "builtins/fixunsdfdi.h"
 #include "builtins/fixunsdfsi.h"
 #include "builtins/fixunsdfti.h"
 #include "builtins/fixunssfdi.h"
 #include "builtins/fixunssfsi.h"
 #include "builtins/fixunssfti.h"
+#include "builtins/fixunstfdi.h"
+#include "builtins/fixunstfsi.h"
+#include "builtins/fixunstfti.h"
 #include "builtins/floatdidf.h"
 #include "builtins/floatdisf.h"
 #include "builtins/floatditf.h"
diff --git a/libc/shared/builtins/fixtfdi.h b/libc/shared/builtins/fixtfdi.h
new file mode 100644
index 0000000000000..1cae343fe0d3d
--- /dev/null
+++ b/libc/shared/builtins/fixtfdi.h
@@ -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 header exposes LLVM-libc's __fixtfdi implementation as shared::fixtfdi
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FIXTFDI_H
+#define LLVM_LIBC_SHARED_BUILTINS_FIXTFDI_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/fixtfdi.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::fixtfdi;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FIXTFDI_H
diff --git a/libc/shared/builtins/fixtfsi.h b/libc/shared/builtins/fixtfsi.h
new file mode 100644
index 0000000000000..1d287892a258e
--- /dev/null
+++ b/libc/shared/builtins/fixtfsi.h
@@ -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 header exposes LLVM-libc's __fixtfsi implementation as shared::fixtfsi
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FIXTFSI_H
+#define LLVM_LIBC_SHARED_BUILTINS_FIXTFSI_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/fixtfsi.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::fixtfsi;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FIXTFSI_H
diff --git a/libc/shared/builtins/fixtfti.h b/libc/shared/builtins/fixtfti.h
new file mode 100644
index 0000000000000..ae0862ce4ae06
--- /dev/null
+++ b/libc/shared/builtins/fixtfti.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 header exposes LLVM-libc's __fixtfti implementation as shared::fixtfti
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FIXTFTI_H
+#define LLVM_LIBC_SHARED_BUILTINS_FIXTFTI_H
+
+#include "include/llvm-libc-types/float128.h"
+#include "src/__support/macros/properties/types.h"
+
+#if defined(LIBC_TYPES_HAS_FLOAT128) && defined(LIBC_TYPES_HAS_INT128)
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/fixtfti.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::fixtfti;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128 && LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FIXTFTI_H
diff --git a/libc/shared/builtins/fixunstfdi.h b/libc/shared/builtins/fixunstfdi.h
new file mode 100644
index 0000000000000..4afe2e94c383f
--- /dev/null
+++ b/libc/shared/builtins/fixunstfdi.h
@@ -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 header exposes LLVM-libc's __fixunstfdi implementation as
+/// shared::fixunstfdi so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FIXUNSTFDI_H
+#define LLVM_LIBC_SHARED_BUILTINS_FIXUNSTFDI_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/fixunstfdi.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::fixunstfdi;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FIXUNSTFDI_H
diff --git a/libc/shared/builtins/fixunstfsi.h b/libc/shared/builtins/fixunstfsi.h
new file mode 100644
index 0000000000000..c856a8420114a
--- /dev/null
+++ b/libc/shared/builtins/fixunstfsi.h
@@ -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 header exposes LLVM-libc's __fixunstfsi implementation as
+/// shared::fixunstfsi so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FIXUNSTFSI_H
+#define LLVM_LIBC_SHARED_BUILTINS_FIXUNSTFSI_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/fixunstfsi.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::fixunstfsi;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FIXUNSTFSI_H
diff --git a/libc/shared/builtins/fixunstfti.h b/libc/shared/builtins/fixunstfti.h
new file mode 100644
index 0000000000000..53ad7bb03a7c9
--- /dev/null
+++ b/libc/shared/builtins/fixunstfti.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 header exposes LLVM-libc's __fixunstfti implementation as
+/// shared::fixunstfti so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FIXUNSTFTI_H
+#define LLVM_LIBC_SHARED_BUILTINS_FIXUNSTFTI_H
+
+#include "include/llvm-libc-types/float128.h"
+#include "src/__support/macros/properties/types.h"
+
+#if defined(LIBC_TYPES_HAS_FLOAT128) && defined(LIBC_TYPES_HAS_INT128)
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/fixunstfti.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::fixunstfti;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128 && LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FIXUNSTFTI_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index 5307462794c20..e1b1f819f7e4a 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -1,3 +1,14 @@
+add_header_library(
+  fixint_helper
+  HDRS
+    fixint_helper.h
+  DEPENDS
+    libc.src.__support.CPP.type_traits
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.macros.attributes
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   floatint_helper
   HDRS
@@ -640,3 +651,71 @@ add_header_library(
     libc.src.__support.macros.config
     libc.src.__support.macros.properties.types
 )
+
+add_header_library(
+  fixtfsi
+  HDRS
+    fixtfsi.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.builtins.fixint_helper
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fixtfdi
+  HDRS
+    fixtfdi.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.builtins.fixint_helper
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fixtfti
+  HDRS
+    fixtfti.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.builtins.fixint_helper
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
+
+add_header_library(
+  fixunstfsi
+  HDRS
+    fixunstfsi.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.builtins.fixint_helper
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fixunstfdi
+  HDRS
+    fixunstfdi.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.builtins.fixint_helper
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fixunstfti
+  HDRS
+    fixunstfti.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.builtins.fixint_helper
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
diff --git a/libc/src/__support/builtins/fixtfdi.h b/libc/src/__support/builtins/fixtfdi.h
new file mode 100644
index 0000000000000..659789517c6a5
--- /dev/null
+++ b/libc/src/__support/builtins/fixtfdi.h
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 header exposes LLVM-libc's __fixtfdi implementation as
+/// builtins::fixtfdi so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXTFDI_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXTFDI_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/fixint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Truncating float128 -> int64_t conversion, saturating on overflow.
+// Mirrors compiler-rt's __fixtfdi.
+LIBC_INLINE int64_t fixtfdi(float128 x) {
+  return fixint<int64_t>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXTFDI_H
diff --git a/libc/src/__support/builtins/fixtfsi.h b/libc/src/__support/builtins/fixtfsi.h
new file mode 100644
index 0000000000000..101acadfbf83c
--- /dev/null
+++ b/libc/src/__support/builtins/fixtfsi.h
@@...
[truncated]

``````````

</details>


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


More information about the llvm-branch-commits mailing list