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

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 11 23:31:00 PDT 2026


https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/215725

>From 34215900dc02bfdad597e45b95cd3912ad1d2ecd Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Sun, 9 Aug 2026 01:57:07 +0300
Subject: [PATCH] [compiler-rt][builtins] libc-backed int-to-quad conversion
 builtins

---
 compiler-rt/lib/builtins/CMakeLists.txt    |  6 ++
 compiler-rt/lib/builtins/floatditf.cpp     | 26 +++++++++
 compiler-rt/lib/builtins/floatsitf.cpp     | 26 +++++++++
 compiler-rt/lib/builtins/floattitf.cpp     | 26 +++++++++
 compiler-rt/lib/builtins/floatunditf.cpp   | 26 +++++++++
 compiler-rt/lib/builtins/floatunsitf.cpp   | 26 +++++++++
 compiler-rt/lib/builtins/floatuntitf.cpp   | 26 +++++++++
 libc/shared/builtins.h                     |  6 ++
 libc/shared/builtins/floatditf.h           | 35 +++++++++++
 libc/shared/builtins/floatsitf.h           | 35 +++++++++++
 libc/shared/builtins/floattitf.h           | 36 ++++++++++++
 libc/shared/builtins/floatunditf.h         | 35 +++++++++++
 libc/shared/builtins/floatunsitf.h         | 35 +++++++++++
 libc/shared/builtins/floatuntitf.h         | 36 ++++++++++++
 libc/src/__support/builtins/CMakeLists.txt | 68 ++++++++++++++++++++++
 libc/src/__support/builtins/floatditf.h    | 40 +++++++++++++
 libc/src/__support/builtins/floatsitf.h    | 40 +++++++++++++
 libc/src/__support/builtins/floattitf.h    | 41 +++++++++++++
 libc/src/__support/builtins/floatunditf.h  | 40 +++++++++++++
 libc/src/__support/builtins/floatunsitf.h  | 40 +++++++++++++
 libc/src/__support/builtins/floatuntitf.h  | 41 +++++++++++++
 libc/test/shared/CMakeLists.txt            |  8 ++-
 libc/test/shared/shared_builtins_test.cpp  | 24 ++++++++
 23 files changed, 721 insertions(+), 1 deletion(-)
 create mode 100644 compiler-rt/lib/builtins/floatditf.cpp
 create mode 100644 compiler-rt/lib/builtins/floatsitf.cpp
 create mode 100644 compiler-rt/lib/builtins/floattitf.cpp
 create mode 100644 compiler-rt/lib/builtins/floatunditf.cpp
 create mode 100644 compiler-rt/lib/builtins/floatunsitf.cpp
 create mode 100644 compiler-rt/lib/builtins/floatuntitf.cpp
 create mode 100644 libc/shared/builtins/floatditf.h
 create mode 100644 libc/shared/builtins/floatsitf.h
 create mode 100644 libc/shared/builtins/floattitf.h
 create mode 100644 libc/shared/builtins/floatunditf.h
 create mode 100644 libc/shared/builtins/floatunsitf.h
 create mode 100644 libc/shared/builtins/floatuntitf.h
 create mode 100644 libc/src/__support/builtins/floatditf.h
 create mode 100644 libc/src/__support/builtins/floatsitf.h
 create mode 100644 libc/src/__support/builtins/floattitf.h
 create mode 100644 libc/src/__support/builtins/floatunditf.h
 create mode 100644 libc/src/__support/builtins/floatunsitf.h
 create mode 100644 libc/src/__support/builtins/floatuntitf.h

diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index a4393e10559b0..73c2743ec7abe 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -314,14 +314,20 @@ if(COMPILER_RT_USE_LIBC_MATH)
   use_libc_builtin(GENERIC_SOURCES    floatdidf)
   use_libc_builtin(GENERIC_SOURCES    floattidf)
   use_libc_builtin(GENERIC_SOURCES    floatsisf)
+  use_libc_builtin(GENERIC_TF_SOURCES floatsitf)
   use_libc_builtin(GENERIC_SOURCES    floatdisf)
+  use_libc_builtin(GENERIC_TF_SOURCES floatditf)
   use_libc_builtin(GENERIC_SOURCES    floattisf)
+  use_libc_builtin(GENERIC_TF_SOURCES floattitf)
   use_libc_builtin(GENERIC_SOURCES    floatunsidf)
   use_libc_builtin(GENERIC_SOURCES    floatundidf)
   use_libc_builtin(GENERIC_SOURCES    floatuntidf)
   use_libc_builtin(GENERIC_SOURCES    floatunsisf)
+  use_libc_builtin(GENERIC_TF_SOURCES floatunsitf)
   use_libc_builtin(GENERIC_SOURCES    floatundisf)
+  use_libc_builtin(GENERIC_TF_SOURCES floatunditf)
   use_libc_builtin(GENERIC_SOURCES    floatuntisf)
+  use_libc_builtin(GENERIC_TF_SOURCES floatuntitf)
   use_libc_builtin(GENERIC_SOURCES    muldf3)
   use_libc_builtin(GENERIC_SOURCES    mulsf3)
   use_libc_builtin(GENERIC_TF_SOURCES multf3)
diff --git a/compiler-rt/lib/builtins/floatditf.cpp b/compiler-rt/lib/builtins/floatditf.cpp
new file mode 100644
index 0000000000000..99adc4f7af66f
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatditf.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 __floatditf, int64_t -> float128
+/// conversion (round to nearest), on top of LLVM-libc's shared::floatditf.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatditf.h"
+
+#if defined(CRT_HAS_TF_MODE)
+extern "C" COMPILER_RT_ABI fp_t __floatditf(di_int a) {
+  return LIBC_NAMESPACE::shared::floatditf(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/floatsitf.cpp b/compiler-rt/lib/builtins/floatsitf.cpp
new file mode 100644
index 0000000000000..a56323253d94c
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatsitf.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 __floatsitf, int32_t -> float128
+/// conversion (round to nearest), on top of LLVM-libc's shared::floatsitf.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatsitf.h"
+
+#if defined(CRT_HAS_TF_MODE)
+extern "C" COMPILER_RT_ABI fp_t __floatsitf(si_int a) {
+  return LIBC_NAMESPACE::shared::floatsitf(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/floattitf.cpp b/compiler-rt/lib/builtins/floattitf.cpp
new file mode 100644
index 0000000000000..f36ce1a63804e
--- /dev/null
+++ b/compiler-rt/lib/builtins/floattitf.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 __floattitf, __int128_t -> float128
+/// conversion (round to nearest), on top of LLVM-libc's shared::floattitf.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floattitf.h"
+
+#if defined(CRT_HAS_TF_MODE)
+extern "C" COMPILER_RT_ABI fp_t __floattitf(ti_int a) {
+  return LIBC_NAMESPACE::shared::floattitf(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/floatunditf.cpp b/compiler-rt/lib/builtins/floatunditf.cpp
new file mode 100644
index 0000000000000..53764215a58b1
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatunditf.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 __floatunditf, uint64_t -> float128
+/// conversion (round to nearest), on top of LLVM-libc's shared::floatunditf.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatunditf.h"
+
+#if defined(CRT_HAS_TF_MODE)
+extern "C" COMPILER_RT_ABI fp_t __floatunditf(du_int a) {
+  return LIBC_NAMESPACE::shared::floatunditf(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/floatunsitf.cpp b/compiler-rt/lib/builtins/floatunsitf.cpp
new file mode 100644
index 0000000000000..f94cef9c96e9b
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatunsitf.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 __floatunsitf, uint32_t -> float128
+/// conversion (round to nearest), on top of LLVM-libc's shared::floatunsitf.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatunsitf.h"
+
+#if defined(CRT_HAS_TF_MODE)
+extern "C" COMPILER_RT_ABI fp_t __floatunsitf(su_int a) {
+  return LIBC_NAMESPACE::shared::floatunsitf(a);
+}
+#endif
diff --git a/compiler-rt/lib/builtins/floatuntitf.cpp b/compiler-rt/lib/builtins/floatuntitf.cpp
new file mode 100644
index 0000000000000..6fd73c246b384
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatuntitf.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 __floatuntitf, __uint128_t -> float128
+/// conversion (round to nearest), on top of LLVM-libc's shared::floatuntitf.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatuntitf.h"
+
+#if defined(CRT_HAS_TF_MODE)
+extern "C" COMPILER_RT_ABI fp_t __floatuntitf(tu_int a) {
+  return LIBC_NAMESPACE::shared::floatuntitf(a);
+}
+#endif
diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 29380688849e5..6e59031aa28a3 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -41,16 +41,22 @@
 #include "builtins/fixunssfti.h"
 #include "builtins/floatdidf.h"
 #include "builtins/floatdisf.h"
+#include "builtins/floatditf.h"
 #include "builtins/floatsidf.h"
 #include "builtins/floatsisf.h"
+#include "builtins/floatsitf.h"
 #include "builtins/floattidf.h"
 #include "builtins/floattisf.h"
+#include "builtins/floattitf.h"
 #include "builtins/floatundidf.h"
 #include "builtins/floatundisf.h"
+#include "builtins/floatunditf.h"
 #include "builtins/floatunsidf.h"
 #include "builtins/floatunsisf.h"
+#include "builtins/floatunsitf.h"
 #include "builtins/floatuntidf.h"
 #include "builtins/floatuntisf.h"
+#include "builtins/floatuntitf.h"
 #include "builtins/gedf2.h"
 #include "builtins/gesf2.h"
 #include "builtins/getf2.h"
diff --git a/libc/shared/builtins/floatditf.h b/libc/shared/builtins/floatditf.h
new file mode 100644
index 0000000000000..eed3e486d203d
--- /dev/null
+++ b/libc/shared/builtins/floatditf.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 __floatditf implementation as
+/// shared::floatditf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATDITF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATDITF_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatditf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatditf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATDITF_H
diff --git a/libc/shared/builtins/floatsitf.h b/libc/shared/builtins/floatsitf.h
new file mode 100644
index 0000000000000..b5d71e468a386
--- /dev/null
+++ b/libc/shared/builtins/floatsitf.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 __floatsitf implementation as
+/// shared::floatsitf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATSITF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATSITF_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatsitf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatsitf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATSITF_H
diff --git a/libc/shared/builtins/floattitf.h b/libc/shared/builtins/floattitf.h
new file mode 100644
index 0000000000000..4cdbffa709975
--- /dev/null
+++ b/libc/shared/builtins/floattitf.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 __floattitf implementation as
+/// shared::floattitf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATTITF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATTITF_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/floattitf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floattitf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128 && LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATTITF_H
diff --git a/libc/shared/builtins/floatunditf.h b/libc/shared/builtins/floatunditf.h
new file mode 100644
index 0000000000000..6f88073e5758b
--- /dev/null
+++ b/libc/shared/builtins/floatunditf.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 __floatunditf implementation as
+/// shared::floatunditf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATUNDITF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATUNDITF_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatunditf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatunditf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATUNDITF_H
diff --git a/libc/shared/builtins/floatunsitf.h b/libc/shared/builtins/floatunsitf.h
new file mode 100644
index 0000000000000..4c85c7b4e9986
--- /dev/null
+++ b/libc/shared/builtins/floatunsitf.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 __floatunsitf implementation as
+/// shared::floatunsitf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATUNSITF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATUNSITF_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatunsitf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatunsitf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATUNSITF_H
diff --git a/libc/shared/builtins/floatuntitf.h b/libc/shared/builtins/floatuntitf.h
new file mode 100644
index 0000000000000..26594dbda3d13
--- /dev/null
+++ b/libc/shared/builtins/floatuntitf.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 __floatuntitf implementation as
+/// shared::floatuntitf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATUNTITF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATUNTITF_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/floatuntitf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatuntitf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128 && LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATUNTITF_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index 0f41b07a10bbb..5307462794c20 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -572,3 +572,71 @@ add_header_library(
     libc.src.__support.builtins.cmp_helper
     libc.src.__support.macros.config
 )
+
+add_header_library(
+  floatsitf
+  HDRS
+    floatsitf.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.builtins.floatint_helper
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  floatditf
+  HDRS
+    floatditf.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.builtins.floatint_helper
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  floattitf
+  HDRS
+    floattitf.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.builtins.floatint_helper
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
+
+add_header_library(
+  floatunsitf
+  HDRS
+    floatunsitf.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.builtins.floatint_helper
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  floatunditf
+  HDRS
+    floatunditf.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.builtins.floatint_helper
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  floatuntitf
+  HDRS
+    floatuntitf.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.builtins.floatint_helper
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
diff --git a/libc/src/__support/builtins/floatditf.h b/libc/src/__support/builtins/floatditf.h
new file mode 100644
index 0000000000000..110a6350ce299
--- /dev/null
+++ b/libc/src/__support/builtins/floatditf.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 __floatditf implementation as
+/// builtins::floatditf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATDITF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATDITF_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// float128 <- int64_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatditf.
+LIBC_INLINE float128 floatditf(int64_t x) {
+  return floatint<float128>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATDITF_H
diff --git a/libc/src/__support/builtins/floatsitf.h b/libc/src/__support/builtins/floatsitf.h
new file mode 100644
index 0000000000000..bbc46a584bb50
--- /dev/null
+++ b/libc/src/__support/builtins/floatsitf.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 __floatsitf implementation as
+/// builtins::floatsitf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATSITF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATSITF_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// float128 <- int32_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatsitf.
+LIBC_INLINE float128 floatsitf(int32_t x) {
+  return floatint<float128>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATSITF_H
diff --git a/libc/src/__support/builtins/floattitf.h b/libc/src/__support/builtins/floattitf.h
new file mode 100644
index 0000000000000..5b4e65598b645
--- /dev/null
+++ b/libc/src/__support/builtins/floattitf.h
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floattitf implementation as
+/// builtins::floattitf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATTITF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATTITF_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 "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// float128 <- __int128_t conversion, round to nearest.
+// Mirrors compiler-rt's __floattitf.
+LIBC_INLINE float128 floattitf(__int128_t x) {
+  return floatint<float128>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128 && LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATTITF_H
diff --git a/libc/src/__support/builtins/floatunditf.h b/libc/src/__support/builtins/floatunditf.h
new file mode 100644
index 0000000000000..0fb47dc8d728a
--- /dev/null
+++ b/libc/src/__support/builtins/floatunditf.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 __floatunditf implementation as
+/// builtins::floatunditf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNDITF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNDITF_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// float128 <- uint64_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatunditf.
+LIBC_INLINE float128 floatunditf(uint64_t x) {
+  return floatint<float128>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNDITF_H
diff --git a/libc/src/__support/builtins/floatunsitf.h b/libc/src/__support/builtins/floatunsitf.h
new file mode 100644
index 0000000000000..f570b5f0fe215
--- /dev/null
+++ b/libc/src/__support/builtins/floatunsitf.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 __floatunsitf implementation as
+/// builtins::floatunsitf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNSITF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNSITF_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// float128 <- uint32_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatunsitf.
+LIBC_INLINE float128 floatunsitf(uint32_t x) {
+  return floatint<float128>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNSITF_H
diff --git a/libc/src/__support/builtins/floatuntitf.h b/libc/src/__support/builtins/floatuntitf.h
new file mode 100644
index 0000000000000..51011dcfb72b8
--- /dev/null
+++ b/libc/src/__support/builtins/floatuntitf.h
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatuntitf implementation as
+/// builtins::floatuntitf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNTITF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNTITF_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 "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// float128 <- __uint128_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatuntitf.
+LIBC_INLINE float128 floatuntitf(__uint128_t x) {
+  return floatint<float128>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128 && LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNTITF_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 4aa6a070785d1..9a830488ca22c 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -852,16 +852,22 @@ add_fp_unittest(
     libc.src.__support.builtins.fixunssfti
     libc.src.__support.builtins.floatdidf
     libc.src.__support.builtins.floatdisf
+    libc.src.__support.builtins.floatditf
     libc.src.__support.builtins.floatsidf
     libc.src.__support.builtins.floatsisf
+    libc.src.__support.builtins.floatsitf
     libc.src.__support.builtins.floattidf
     libc.src.__support.builtins.floattisf
+    libc.src.__support.builtins.floattitf
     libc.src.__support.builtins.floatundidf
     libc.src.__support.builtins.floatundisf
+    libc.src.__support.builtins.floatunditf
     libc.src.__support.builtins.floatunsidf
     libc.src.__support.builtins.floatunsisf
+    libc.src.__support.builtins.floatunsitf
     libc.src.__support.builtins.floatuntidf
     libc.src.__support.builtins.floatuntisf
+    libc.src.__support.builtins.floatuntitf
     libc.src.__support.builtins.gedf2
     libc.src.__support.builtins.gesf2
     libc.src.__support.builtins.getf2
@@ -880,10 +886,10 @@ add_fp_unittest(
     libc.src.__support.builtins.trunctfdf2
     libc.src.__support.builtins.trunctfsf2
     libc.src.__support.builtins.trunctfxf2
-    libc.src.__support.uint128
     libc.src.__support.builtins.unorddf2
     libc.src.__support.builtins.unordsf2
     libc.src.__support.builtins.unordtf2
+    libc.src.__support.uint128
 )
 
 add_fp_unittest(
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index 70910f1fc414d..88ab86cc61741 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -38,6 +38,30 @@ TEST(LlvmLibcSharedBuiltinsTest, QuadPrecisionArithmtic) {
   EXPECT_FP_EQ(float128(2.0), shared::subtf3(float128(5.0), float128(3.0)));
 }
 
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+TEST(LlvmLibcSharedBuiltinsTest, IntToQuadConversion) {
+  EXPECT_FP_EQ(float128(12.0), shared::floatditf(int64_t(12)));
+  EXPECT_FP_EQ(float128(12.0), shared::floatsitf(int32_t(12)));
+#ifdef LIBC_TYPES_HAS_INT128
+  EXPECT_FP_EQ(float128(12.0), shared::floattitf(static_cast<__int128_t>(12)));
+#endif // LIBC_TYPES_HAS_INT128
+}
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+TEST(LlvmLibcSharedBuiltinsTest, UIntToQuadConversion) {
+  EXPECT_FP_EQ(float128(12.0), shared::floatunditf(uint64_t(12)));
+  EXPECT_FP_EQ(float128(12.0), shared::floatunsitf(uint32_t(12)));
+#ifdef LIBC_TYPES_HAS_INT128
+  EXPECT_FP_EQ(float128(12.0),
+               shared::floatuntitf(static_cast<__uint128_t>(12)));
+#endif // LIBC_TYPES_HAS_INT128
+}
+
 #endif // LIBC_TYPES_HAS_FLOAT128
 
 TEST(LlvmLibcSharedBuiltinsTest, ExtendConversion) {



More information about the llvm-branch-commits mailing list