[libc-commits] [compiler-rt] [libc] [compiler-rt][builtins] libc-backed int-to-double/float builtins (PR #209900)
via libc-commits
libc-commits at lists.llvm.org
Wed Jul 15 21:15:07 PDT 2026
https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/209900
>From 4a15201210298d07eecc5189fa6f047eb9ed3e51 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 16 Jul 2026 00:21:51 +0300
Subject: [PATCH 1/3] [compiler-rt][builtins] libc-backed int-to-double/float
builtins
---
compiler-rt/lib/builtins/CMakeLists.txt | 12 ++
compiler-rt/lib/builtins/floatdidf.cpp | 24 ++++
compiler-rt/lib/builtins/floatdisf.cpp | 24 ++++
compiler-rt/lib/builtins/floatsidf.cpp | 24 ++++
compiler-rt/lib/builtins/floatsisf.cpp | 24 ++++
compiler-rt/lib/builtins/floattidf.cpp | 28 ++++
compiler-rt/lib/builtins/floattisf.cpp | 28 ++++
compiler-rt/lib/builtins/floatundidf.cpp | 24 ++++
compiler-rt/lib/builtins/floatundisf.cpp | 24 ++++
compiler-rt/lib/builtins/floatunsidf.cpp | 24 ++++
compiler-rt/lib/builtins/floatunsisf.cpp | 24 ++++
compiler-rt/lib/builtins/floatuntidf.cpp | 28 ++++
compiler-rt/lib/builtins/floatuntisf.cpp | 28 ++++
libc/shared/builtins.h | 12 ++
libc/shared/builtins/floatdidf.h | 29 ++++
libc/shared/builtins/floatdisf.h | 29 ++++
libc/shared/builtins/floatsidf.h | 29 ++++
libc/shared/builtins/floatsisf.h | 29 ++++
libc/shared/builtins/floattidf.h | 35 +++++
libc/shared/builtins/floattisf.h | 35 +++++
libc/shared/builtins/floatundidf.h | 29 ++++
libc/shared/builtins/floatundisf.h | 29 ++++
libc/shared/builtins/floatunsidf.h | 29 ++++
libc/shared/builtins/floatunsisf.h | 29 ++++
libc/shared/builtins/floatuntidf.h | 35 +++++
libc/shared/builtins/floatuntisf.h | 35 +++++
libc/src/__support/builtins/CMakeLists.txt | 136 ++++++++++++++++++
libc/src/__support/builtins/floatdidf.h | 34 +++++
libc/src/__support/builtins/floatdisf.h | 34 +++++
libc/src/__support/builtins/floatint_helper.h | 60 ++++++++
libc/src/__support/builtins/floatsidf.h | 34 +++++
libc/src/__support/builtins/floatsisf.h | 34 +++++
libc/src/__support/builtins/floattidf.h | 40 ++++++
libc/src/__support/builtins/floattisf.h | 40 ++++++
libc/src/__support/builtins/floatundidf.h | 34 +++++
libc/src/__support/builtins/floatundisf.h | 34 +++++
libc/src/__support/builtins/floatunsidf.h | 34 +++++
libc/src/__support/builtins/floatunsisf.h | 34 +++++
libc/src/__support/builtins/floatuntidf.h | 40 ++++++
libc/src/__support/builtins/floatuntisf.h | 40 ++++++
libc/test/shared/CMakeLists.txt | 13 ++
libc/test/shared/shared_builtins_test.cpp | 63 +++++---
42 files changed, 1388 insertions(+), 16 deletions(-)
create mode 100644 compiler-rt/lib/builtins/floatdidf.cpp
create mode 100644 compiler-rt/lib/builtins/floatdisf.cpp
create mode 100644 compiler-rt/lib/builtins/floatsidf.cpp
create mode 100644 compiler-rt/lib/builtins/floatsisf.cpp
create mode 100644 compiler-rt/lib/builtins/floattidf.cpp
create mode 100644 compiler-rt/lib/builtins/floattisf.cpp
create mode 100644 compiler-rt/lib/builtins/floatundidf.cpp
create mode 100644 compiler-rt/lib/builtins/floatundisf.cpp
create mode 100644 compiler-rt/lib/builtins/floatunsidf.cpp
create mode 100644 compiler-rt/lib/builtins/floatunsisf.cpp
create mode 100644 compiler-rt/lib/builtins/floatuntidf.cpp
create mode 100644 compiler-rt/lib/builtins/floatuntisf.cpp
create mode 100644 libc/shared/builtins/floatdidf.h
create mode 100644 libc/shared/builtins/floatdisf.h
create mode 100644 libc/shared/builtins/floatsidf.h
create mode 100644 libc/shared/builtins/floatsisf.h
create mode 100644 libc/shared/builtins/floattidf.h
create mode 100644 libc/shared/builtins/floattisf.h
create mode 100644 libc/shared/builtins/floatundidf.h
create mode 100644 libc/shared/builtins/floatundisf.h
create mode 100644 libc/shared/builtins/floatunsidf.h
create mode 100644 libc/shared/builtins/floatunsisf.h
create mode 100644 libc/shared/builtins/floatuntidf.h
create mode 100644 libc/shared/builtins/floatuntisf.h
create mode 100644 libc/src/__support/builtins/floatdidf.h
create mode 100644 libc/src/__support/builtins/floatdisf.h
create mode 100644 libc/src/__support/builtins/floatint_helper.h
create mode 100644 libc/src/__support/builtins/floatsidf.h
create mode 100644 libc/src/__support/builtins/floatsisf.h
create mode 100644 libc/src/__support/builtins/floattidf.h
create mode 100644 libc/src/__support/builtins/floattisf.h
create mode 100644 libc/src/__support/builtins/floatundidf.h
create mode 100644 libc/src/__support/builtins/floatundisf.h
create mode 100644 libc/src/__support/builtins/floatunsidf.h
create mode 100644 libc/src/__support/builtins/floatunsisf.h
create mode 100644 libc/src/__support/builtins/floatuntidf.h
create mode 100644 libc/src/__support/builtins/floatuntisf.h
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index ea21c36d3d31f..b11f6324267eb 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -265,6 +265,18 @@ if(COMPILER_RT_USE_LIBC_MATH)
add_definitions(-DCOMPILER_RT_USE_LIBC_MATH)
use_libc_builtin(GENERIC_TF_SOURCES addtf3)
+ use_libc_builtin(GENERIC_SOURCES floatsidf)
+ use_libc_builtin(GENERIC_SOURCES floatdidf)
+ use_libc_builtin(GENERIC_SOURCES floattidf)
+ use_libc_builtin(GENERIC_SOURCES floatsisf)
+ use_libc_builtin(GENERIC_SOURCES floatdisf)
+ use_libc_builtin(GENERIC_SOURCES floattisf)
+ 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_SOURCES floatundisf)
+ use_libc_builtin(GENERIC_SOURCES floatuntisf)
endif()
option(COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN
diff --git a/compiler-rt/lib/builtins/floatdidf.cpp b/compiler-rt/lib/builtins/floatdidf.cpp
new file mode 100644
index 0000000000000..4bc0a12090f1d
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatdidf.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatdidf, int64_t -> double conversion
+/// (round to nearest), on top of LLVM-libc's shared::floatdidf.
+///
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatdidf.h"
+
+extern "C" COMPILER_RT_ABI fp_t __floatdidf(di_int a) {
+ return LIBC_NAMESPACE::shared::floatdidf(a);
+}
diff --git a/compiler-rt/lib/builtins/floatdisf.cpp b/compiler-rt/lib/builtins/floatdisf.cpp
new file mode 100644
index 0000000000000..bfe1b8be533c1
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatdisf.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatdisf, int64_t -> float conversion
+/// (round to nearest), on top of LLVM-libc's shared::floatdisf.
+///
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatdisf.h"
+
+extern "C" COMPILER_RT_ABI fp_t __floatdisf(di_int a) {
+ return LIBC_NAMESPACE::shared::floatdisf(a);
+}
diff --git a/compiler-rt/lib/builtins/floatsidf.cpp b/compiler-rt/lib/builtins/floatsidf.cpp
new file mode 100644
index 0000000000000..cac1a66b0869c
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatsidf.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatsidf, int32_t -> double conversion
+/// (round to nearest), on top of LLVM-libc's shared::floatsidf.
+///
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatsidf.h"
+
+extern "C" COMPILER_RT_ABI fp_t __floatsidf(si_int a) {
+ return LIBC_NAMESPACE::shared::floatsidf(a);
+}
diff --git a/compiler-rt/lib/builtins/floatsisf.cpp b/compiler-rt/lib/builtins/floatsisf.cpp
new file mode 100644
index 0000000000000..5229ffc3614af
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatsisf.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatsisf, int32_t -> float conversion
+/// (round to nearest), on top of LLVM-libc's shared::floatsisf.
+///
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatsisf.h"
+
+extern "C" COMPILER_RT_ABI fp_t __floatsisf(si_int a) {
+ return LIBC_NAMESPACE::shared::floatsisf(a);
+}
diff --git a/compiler-rt/lib/builtins/floattidf.cpp b/compiler-rt/lib/builtins/floattidf.cpp
new file mode 100644
index 0000000000000..f92d1e2659460
--- /dev/null
+++ b/compiler-rt/lib/builtins/floattidf.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floattidf, __int128_t -> double
+/// conversion (round to nearest), on top of LLVM-libc's shared::floattidf.
+///
+//===----------------------------------------------------------------------===//
+
+#include "int_lib.h"
+
+#ifdef CRT_HAS_128BIT
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/floattidf.h"
+
+extern "C" COMPILER_RT_ABI fp_t __floattidf(ti_int a) {
+ return LIBC_NAMESPACE::shared::floattidf(a);
+}
+
+#endif // CRT_HAS_128BIT
diff --git a/compiler-rt/lib/builtins/floattisf.cpp b/compiler-rt/lib/builtins/floattisf.cpp
new file mode 100644
index 0000000000000..324b32d641dfc
--- /dev/null
+++ b/compiler-rt/lib/builtins/floattisf.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floattisf, __int128_t -> float
+/// conversion (round to nearest), on top of LLVM-libc's shared::floattisf.
+///
+//===----------------------------------------------------------------------===//
+
+#include "int_lib.h"
+
+#ifdef CRT_HAS_128BIT
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/floattisf.h"
+
+extern "C" COMPILER_RT_ABI fp_t __floattisf(ti_int a) {
+ return LIBC_NAMESPACE::shared::floattisf(a);
+}
+
+#endif // CRT_HAS_128BIT
diff --git a/compiler-rt/lib/builtins/floatundidf.cpp b/compiler-rt/lib/builtins/floatundidf.cpp
new file mode 100644
index 0000000000000..3a5b5b85047aa
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatundidf.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatundidf, uint64_t -> double
+/// conversion (round to nearest), on top of LLVM-libc's shared::floatundidf.
+///
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatundidf.h"
+
+extern "C" COMPILER_RT_ABI fp_t __floatundidf(du_int a) {
+ return LIBC_NAMESPACE::shared::floatundidf(a);
+}
diff --git a/compiler-rt/lib/builtins/floatundisf.cpp b/compiler-rt/lib/builtins/floatundisf.cpp
new file mode 100644
index 0000000000000..60844ce1b9cd6
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatundisf.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatundisf, uint64_t -> float
+/// conversion (round to nearest), on top of LLVM-libc's shared::floatundisf.
+///
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatundisf.h"
+
+extern "C" COMPILER_RT_ABI fp_t __floatundisf(du_int a) {
+ return LIBC_NAMESPACE::shared::floatundisf(a);
+}
diff --git a/compiler-rt/lib/builtins/floatunsidf.cpp b/compiler-rt/lib/builtins/floatunsidf.cpp
new file mode 100644
index 0000000000000..4cdff38e3e793
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatunsidf.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatunsidf, uint32_t -> double
+/// conversion (round to nearest), on top of LLVM-libc's shared::floatunsidf.
+///
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatunsidf.h"
+
+extern "C" COMPILER_RT_ABI fp_t __floatunsidf(su_int a) {
+ return LIBC_NAMESPACE::shared::floatunsidf(a);
+}
diff --git a/compiler-rt/lib/builtins/floatunsisf.cpp b/compiler-rt/lib/builtins/floatunsisf.cpp
new file mode 100644
index 0000000000000..aac12daa3d1aa
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatunsisf.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatunsisf, uint32_t -> float
+/// conversion (round to nearest), on top of LLVM-libc's shared::floatunsisf.
+///
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/floatunsisf.h"
+
+extern "C" COMPILER_RT_ABI fp_t __floatunsisf(su_int a) {
+ return LIBC_NAMESPACE::shared::floatunsisf(a);
+}
diff --git a/compiler-rt/lib/builtins/floatuntidf.cpp b/compiler-rt/lib/builtins/floatuntidf.cpp
new file mode 100644
index 0000000000000..22c9c443e3079
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatuntidf.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatuntidf, __uint128_t -> double
+/// conversion (round to nearest), on top of LLVM-libc's shared::floatuntidf.
+///
+//===----------------------------------------------------------------------===//
+
+#include "int_lib.h"
+
+#ifdef CRT_HAS_128BIT
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/floatuntidf.h"
+
+extern "C" COMPILER_RT_ABI fp_t __floatuntidf(tu_int a) {
+ return LIBC_NAMESPACE::shared::floatuntidf(a);
+}
+
+#endif // CRT_HAS_128BIT
diff --git a/compiler-rt/lib/builtins/floatuntisf.cpp b/compiler-rt/lib/builtins/floatuntisf.cpp
new file mode 100644
index 0000000000000..4a8d32c089def
--- /dev/null
+++ b/compiler-rt/lib/builtins/floatuntisf.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatuntisf, __uint128_t -> float
+/// conversion (round to nearest), on top of LLVM-libc's shared::floatuntisf.
+///
+//===----------------------------------------------------------------------===//
+
+#include "int_lib.h"
+
+#ifdef CRT_HAS_128BIT
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_libc_config.h"
+#include "shared/builtins/floatuntisf.h"
+
+extern "C" COMPILER_RT_ABI fp_t __floatuntisf(tu_int a) {
+ return LIBC_NAMESPACE::shared::floatuntisf(a);
+}
+
+#endif // CRT_HAS_128BIT
diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index ced054cb02582..fd1cf5c2c99c9 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -23,6 +23,18 @@
#include "builtins/divdf3.h"
#include "builtins/divsf3.h"
#include "builtins/divtf3.h"
+#include "builtins/floatdidf.h"
+#include "builtins/floatdisf.h"
+#include "builtins/floatsidf.h"
+#include "builtins/floatsisf.h"
+#include "builtins/floattidf.h"
+#include "builtins/floattisf.h"
+#include "builtins/floatundidf.h"
+#include "builtins/floatundisf.h"
+#include "builtins/floatunsidf.h"
+#include "builtins/floatunsisf.h"
+#include "builtins/floatuntidf.h"
+#include "builtins/floatuntisf.h"
#include "builtins/muldf3.h"
#include "builtins/mulsf3.h"
#include "builtins/multf3.h"
diff --git a/libc/shared/builtins/floatdidf.h b/libc/shared/builtins/floatdidf.h
new file mode 100644
index 0000000000000..6d5d54994cff3
--- /dev/null
+++ b/libc/shared/builtins/floatdidf.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatdidf implementation as
+/// shared::floatdidf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATDIDF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATDIDF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatdidf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatdidf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATDIDF_H
diff --git a/libc/shared/builtins/floatdisf.h b/libc/shared/builtins/floatdisf.h
new file mode 100644
index 0000000000000..b0f29485dc985
--- /dev/null
+++ b/libc/shared/builtins/floatdisf.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatdisf implementation as
+/// shared::floatdisf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATDISF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATDISF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatdisf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatdisf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATDISF_H
diff --git a/libc/shared/builtins/floatsidf.h b/libc/shared/builtins/floatsidf.h
new file mode 100644
index 0000000000000..f1d4708ac667b
--- /dev/null
+++ b/libc/shared/builtins/floatsidf.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatsidf implementation as
+/// shared::floatsidf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATSIDF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATSIDF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatsidf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatsidf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATSIDF_H
diff --git a/libc/shared/builtins/floatsisf.h b/libc/shared/builtins/floatsisf.h
new file mode 100644
index 0000000000000..0d318b26cd7ab
--- /dev/null
+++ b/libc/shared/builtins/floatsisf.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatsisf implementation as
+/// shared::floatsisf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATSISF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATSISF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatsisf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatsisf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATSISF_H
diff --git a/libc/shared/builtins/floattidf.h b/libc/shared/builtins/floattidf.h
new file mode 100644
index 0000000000000..4aaecb88d479f
--- /dev/null
+++ b/libc/shared/builtins/floattidf.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 __floattidf implementation as
+/// shared::floattidf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATTIDF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATTIDF_H
+
+#include "src/__support/macros/properties/types.h"
+
+#ifdef LIBC_TYPES_HAS_INT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floattidf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floattidf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATTIDF_H
diff --git a/libc/shared/builtins/floattisf.h b/libc/shared/builtins/floattisf.h
new file mode 100644
index 0000000000000..d2667cbb6d1be
--- /dev/null
+++ b/libc/shared/builtins/floattisf.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 __floattisf implementation as
+/// shared::floattisf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATTISF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATTISF_H
+
+#include "src/__support/macros/properties/types.h"
+
+#ifdef LIBC_TYPES_HAS_INT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floattisf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floattisf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATTISF_H
diff --git a/libc/shared/builtins/floatundidf.h b/libc/shared/builtins/floatundidf.h
new file mode 100644
index 0000000000000..34f78a01f6af7
--- /dev/null
+++ b/libc/shared/builtins/floatundidf.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatundidf implementation as
+/// shared::floatundidf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATUNDIDF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATUNDIDF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatundidf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatundidf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATUNDIDF_H
diff --git a/libc/shared/builtins/floatundisf.h b/libc/shared/builtins/floatundisf.h
new file mode 100644
index 0000000000000..3905e4157f168
--- /dev/null
+++ b/libc/shared/builtins/floatundisf.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatundisf implementation as
+/// shared::floatundisf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATUNDISF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATUNDISF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatundisf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatundisf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATUNDISF_H
diff --git a/libc/shared/builtins/floatunsidf.h b/libc/shared/builtins/floatunsidf.h
new file mode 100644
index 0000000000000..a1509fa1a6b7d
--- /dev/null
+++ b/libc/shared/builtins/floatunsidf.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatunsidf implementation as
+/// shared::floatunsidf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATUNSIDF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATUNSIDF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatunsidf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatunsidf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATUNSIDF_H
diff --git a/libc/shared/builtins/floatunsisf.h b/libc/shared/builtins/floatunsisf.h
new file mode 100644
index 0000000000000..c2190df469dd1
--- /dev/null
+++ b/libc/shared/builtins/floatunsisf.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatunsisf implementation as
+/// shared::floatunsisf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATUNSISF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATUNSISF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatunsisf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatunsisf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATUNSISF_H
diff --git a/libc/shared/builtins/floatuntidf.h b/libc/shared/builtins/floatuntidf.h
new file mode 100644
index 0000000000000..4a3f1ebaa7486
--- /dev/null
+++ b/libc/shared/builtins/floatuntidf.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 __floatuntidf implementation as
+/// shared::floatuntidf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATUNTIDF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATUNTIDF_H
+
+#include "src/__support/macros/properties/types.h"
+
+#ifdef LIBC_TYPES_HAS_INT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatuntidf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatuntidf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATUNTIDF_H
diff --git a/libc/shared/builtins/floatuntisf.h b/libc/shared/builtins/floatuntisf.h
new file mode 100644
index 0000000000000..100924f91a9dd
--- /dev/null
+++ b/libc/shared/builtins/floatuntisf.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 __floatuntisf implementation as
+/// shared::floatuntisf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATUNTISF_H
+#define LLVM_LIBC_SHARED_BUILTINS_FLOATUNTISF_H
+
+#include "src/__support/macros/properties/types.h"
+
+#ifdef LIBC_TYPES_HAS_INT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/floatuntisf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::floatuntisf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATUNTISF_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index f5b5ffe3e07b4..f0521d67f6e71 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -1,3 +1,15 @@
+add_header_library(
+ floatint_helper
+ HDRS
+ floatint_helper.h
+ DEPENDS
+ libc.src.__support.CPP.type_traits
+ libc.src.__support.FPUtil.dyadic_float
+ libc.src.__support.macros.attributes
+ libc.src.__support.macros.config
+ libc.src.__support.sign
+)
+
add_header_library(
addtf3
HDRS
@@ -109,3 +121,127 @@ add_header_library(
libc.src.__support.FPUtil.generic.div
libc.src.__support.macros.config
)
+
+add_header_library(
+ floatsidf
+ HDRS
+ floatsidf.h
+ DEPENDS
+ libc.hdr.stdint_proxy
+ libc.src.__support.builtins.floatint_helper
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ floatdidf
+ HDRS
+ floatdidf.h
+ DEPENDS
+ libc.hdr.stdint_proxy
+ libc.src.__support.builtins.floatint_helper
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ floattidf
+ HDRS
+ floattidf.h
+ DEPENDS
+ libc.hdr.stdint_proxy
+ libc.src.__support.builtins.floatint_helper
+ libc.src.__support.macros.config
+ libc.src.__support.macros.properties.types
+)
+
+add_header_library(
+ floatsisf
+ HDRS
+ floatsisf.h
+ DEPENDS
+ libc.hdr.stdint_proxy
+ libc.src.__support.builtins.floatint_helper
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ floatdisf
+ HDRS
+ floatdisf.h
+ DEPENDS
+ libc.hdr.stdint_proxy
+ libc.src.__support.builtins.floatint_helper
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ floattisf
+ HDRS
+ floattisf.h
+ DEPENDS
+ libc.hdr.stdint_proxy
+ libc.src.__support.builtins.floatint_helper
+ libc.src.__support.macros.config
+ libc.src.__support.macros.properties.types
+)
+
+add_header_library(
+ floatunsidf
+ HDRS
+ floatunsidf.h
+ DEPENDS
+ libc.hdr.stdint_proxy
+ libc.src.__support.builtins.floatint_helper
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ floatundidf
+ HDRS
+ floatundidf.h
+ DEPENDS
+ libc.hdr.stdint_proxy
+ libc.src.__support.builtins.floatint_helper
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ floatuntidf
+ HDRS
+ floatuntidf.h
+ DEPENDS
+ libc.hdr.stdint_proxy
+ libc.src.__support.builtins.floatint_helper
+ libc.src.__support.macros.config
+ libc.src.__support.macros.properties.types
+)
+
+add_header_library(
+ floatunsisf
+ HDRS
+ floatunsisf.h
+ DEPENDS
+ libc.hdr.stdint_proxy
+ libc.src.__support.builtins.floatint_helper
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ floatundisf
+ HDRS
+ floatundisf.h
+ DEPENDS
+ libc.hdr.stdint_proxy
+ libc.src.__support.builtins.floatint_helper
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ floatuntisf
+ HDRS
+ floatuntisf.h
+ DEPENDS
+ libc.hdr.stdint_proxy
+ libc.src.__support.builtins.floatint_helper
+ libc.src.__support.macros.config
+ libc.src.__support.macros.properties.types
+)
diff --git a/libc/src/__support/builtins/floatdidf.h b/libc/src/__support/builtins/floatdidf.h
new file mode 100644
index 0000000000000..118acefe0d44a
--- /dev/null
+++ b/libc/src/__support/builtins/floatdidf.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatdidf implementation as
+/// builtins::floatdidf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATDIDF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATDIDF_H
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// double <- int64_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatdidf.
+LIBC_INLINE double floatdidf(int64_t x) {
+ return floatint<double>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATDIDF_H
diff --git a/libc/src/__support/builtins/floatdisf.h b/libc/src/__support/builtins/floatdisf.h
new file mode 100644
index 0000000000000..d88c895bb4464
--- /dev/null
+++ b/libc/src/__support/builtins/floatdisf.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatdisf implementation as
+/// builtins::floatdisf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATDISF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATDISF_H
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// float <- int64_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatdisf.
+LIBC_INLINE float floatdisf(int64_t x) {
+ return floatint<float>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATDISF_H
diff --git a/libc/src/__support/builtins/floatint_helper.h b/libc/src/__support/builtins/floatint_helper.h
new file mode 100644
index 0000000000000..e1ee8f4d14d22
--- /dev/null
+++ b/libc/src/__support/builtins/floatint_helper.h
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Shared integer-to-floating-point conversions, rounded to nearest with ties
+/// to even. These mirror compiler-rt's __float<i><f> / __floatun<i><f>
+/// builtins via an LLVM-libc DyadicFloat, so they can be reused by
+/// compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATINT_HELPER_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATINT_HELPER_H
+
+#include "src/__support/CPP/type_traits.h"
+#include "src/__support/FPUtil/dyadic_float.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/sign.h"
+
+#include <stddef.h>
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Convert the integer I to the floating-point type F, rounding to nearest
+// (ties to even) per the current rounding mode. Handles signed and unsigned
+// I alike; mirrors compiler-rt's __float<i><f> / __floatun<i><f>.
+template <typename F, typename I> LIBC_INLINE constexpr F floatint(I x) {
+ using UI = cpp::make_unsigned_t<I>;
+
+ if (x == 0)
+ return F(0);
+
+ Sign sign = Sign::POS;
+ UI mag = static_cast<UI>(x);
+ if constexpr (cpp::is_signed_v<I>) {
+ if (x < 0) {
+ sign = Sign::NEG;
+ mag = static_cast<UI>(-mag); // modular negation; correct for I's min too
+ }
+ }
+
+ // A mantissa wide enough for I and for F's fraction, rounded up to a whole
+ // number of 64-bit words (UInt's width requirement). With exponent 0 the
+ // dyadic value is exactly `mag`, which as<F>() then rounds to F.
+ constexpr size_t NEED = (sizeof(I) > sizeof(F) ? sizeof(I) : sizeof(F)) * 8;
+ constexpr size_t BITS = ((NEED + 63) / 64) * 64;
+ return static_cast<F>(fputil::DyadicFloat<BITS>(sign, 0, mag));
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATINT_HELPER_H
diff --git a/libc/src/__support/builtins/floatsidf.h b/libc/src/__support/builtins/floatsidf.h
new file mode 100644
index 0000000000000..ce092d394d1d7
--- /dev/null
+++ b/libc/src/__support/builtins/floatsidf.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatsidf implementation as
+/// builtins::floatsidf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATSIDF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATSIDF_H
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// double <- int32_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatsidf.
+LIBC_INLINE double floatsidf(int32_t x) {
+ return floatint<double>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATSIDF_H
diff --git a/libc/src/__support/builtins/floatsisf.h b/libc/src/__support/builtins/floatsisf.h
new file mode 100644
index 0000000000000..c862121dcd861
--- /dev/null
+++ b/libc/src/__support/builtins/floatsisf.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatsisf implementation as
+/// builtins::floatsisf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATSISF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATSISF_H
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// float <- int32_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatsisf.
+LIBC_INLINE float floatsisf(int32_t x) {
+ return floatint<float>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATSISF_H
diff --git a/libc/src/__support/builtins/floattidf.h b/libc/src/__support/builtins/floattidf.h
new file mode 100644
index 0000000000000..8bc445ede7d94
--- /dev/null
+++ b/libc/src/__support/builtins/floattidf.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 __floattidf implementation as
+/// builtins::floattidf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATTIDF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATTIDF_H
+
+#include "src/__support/macros/properties/types.h"
+
+#ifdef 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 {
+
+// double <- __int128_t conversion, round to nearest.
+// Mirrors compiler-rt's __floattidf.
+LIBC_INLINE double floattidf(__int128_t x) {
+ return floatint<double>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATTIDF_H
diff --git a/libc/src/__support/builtins/floattisf.h b/libc/src/__support/builtins/floattisf.h
new file mode 100644
index 0000000000000..4b7330040f4d1
--- /dev/null
+++ b/libc/src/__support/builtins/floattisf.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 __floattisf implementation as
+/// builtins::floattisf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATTISF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATTISF_H
+
+#include "src/__support/macros/properties/types.h"
+
+#ifdef 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 {
+
+// float <- __int128_t conversion, round to nearest.
+// Mirrors compiler-rt's __floattisf.
+LIBC_INLINE float floattisf(__int128_t x) {
+ return floatint<float>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATTISF_H
diff --git a/libc/src/__support/builtins/floatundidf.h b/libc/src/__support/builtins/floatundidf.h
new file mode 100644
index 0000000000000..b138f8a9c31fd
--- /dev/null
+++ b/libc/src/__support/builtins/floatundidf.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatundidf implementation as
+/// builtins::floatundidf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNDIDF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNDIDF_H
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// double <- uint64_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatundidf.
+LIBC_INLINE double floatundidf(uint64_t x) {
+ return floatint<double>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNDIDF_H
diff --git a/libc/src/__support/builtins/floatundisf.h b/libc/src/__support/builtins/floatundisf.h
new file mode 100644
index 0000000000000..fc4439db39ba6
--- /dev/null
+++ b/libc/src/__support/builtins/floatundisf.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatundisf implementation as
+/// builtins::floatundisf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNDISF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNDISF_H
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// float <- uint64_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatundisf.
+LIBC_INLINE float floatundisf(uint64_t x) {
+ return floatint<float>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNDISF_H
diff --git a/libc/src/__support/builtins/floatunsidf.h b/libc/src/__support/builtins/floatunsidf.h
new file mode 100644
index 0000000000000..b99f8a6508a06
--- /dev/null
+++ b/libc/src/__support/builtins/floatunsidf.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatunsidf implementation as
+/// builtins::floatunsidf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNSIDF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNSIDF_H
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// double <- uint32_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatunsidf.
+LIBC_INLINE double floatunsidf(uint32_t x) {
+ return floatint<double>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNSIDF_H
diff --git a/libc/src/__support/builtins/floatunsisf.h b/libc/src/__support/builtins/floatunsisf.h
new file mode 100644
index 0000000000000..86bbc44c2fff4
--- /dev/null
+++ b/libc/src/__support/builtins/floatunsisf.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __floatunsisf implementation as
+/// builtins::floatunsisf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNSISF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNSISF_H
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/builtins/floatint_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// float <- uint32_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatunsisf.
+LIBC_INLINE float floatunsisf(uint32_t x) {
+ return floatint<float>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNSISF_H
diff --git a/libc/src/__support/builtins/floatuntidf.h b/libc/src/__support/builtins/floatuntidf.h
new file mode 100644
index 0000000000000..25b68280aab3d
--- /dev/null
+++ b/libc/src/__support/builtins/floatuntidf.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 __floatuntidf implementation as
+/// builtins::floatuntidf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNTIDF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNTIDF_H
+
+#include "src/__support/macros/properties/types.h"
+
+#ifdef 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 {
+
+// double <- __uint128_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatuntidf.
+LIBC_INLINE double floatuntidf(__uint128_t x) {
+ return floatint<double>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNTIDF_H
diff --git a/libc/src/__support/builtins/floatuntisf.h b/libc/src/__support/builtins/floatuntisf.h
new file mode 100644
index 0000000000000..7d83e6b36c969
--- /dev/null
+++ b/libc/src/__support/builtins/floatuntisf.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 __floatuntisf implementation as
+/// builtins::floatuntisf so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNTISF_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNTISF_H
+
+#include "src/__support/macros/properties/types.h"
+
+#ifdef 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 {
+
+// float <- __uint128_t conversion, round to nearest.
+// Mirrors compiler-rt's __floatuntisf.
+LIBC_INLINE float floatuntisf(__uint128_t x) {
+ return floatint<float>(x);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_INT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNTISF_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 6efe8365b1557..bc4a8715a42f7 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -833,12 +833,25 @@ add_fp_unittest(
libc.src.__support.builtins.divdf3
libc.src.__support.builtins.divsf3
libc.src.__support.builtins.divtf3
+ libc.src.__support.builtins.floatdidf
+ libc.src.__support.builtins.floatdisf
+ libc.src.__support.builtins.floatsidf
+ libc.src.__support.builtins.floatsisf
+ libc.src.__support.builtins.floattidf
+ libc.src.__support.builtins.floattisf
+ libc.src.__support.builtins.floatundidf
+ libc.src.__support.builtins.floatundisf
+ libc.src.__support.builtins.floatunsidf
+ libc.src.__support.builtins.floatunsisf
+ libc.src.__support.builtins.floatuntidf
+ libc.src.__support.builtins.floatuntisf
libc.src.__support.builtins.muldf3
libc.src.__support.builtins.mulsf3
libc.src.__support.builtins.multf3
libc.src.__support.builtins.subdf3
libc.src.__support.builtins.subsf3
libc.src.__support.builtins.subtf3
+ 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 dac84345eade1..b581e3966ceee 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -7,34 +7,65 @@
//===----------------------------------------------------------------------===//
#include "shared/builtins.h"
+#include "src/__support/uint128.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
+namespace shared = LIBC_NAMESPACE::shared;
+
TEST(LlvmLibcSharedBuiltinsTest, AllFloat) {
- EXPECT_FP_EQ(3.0f, LIBC_NAMESPACE::shared::addsf3(1.0f, 2.0f));
- EXPECT_FP_EQ(3.0f, LIBC_NAMESPACE::shared::divsf3(6.0f, 2.0f));
- EXPECT_FP_EQ(6.0f, LIBC_NAMESPACE::shared::mulsf3(2.0f, 3.0f));
- EXPECT_FP_EQ(2.0f, LIBC_NAMESPACE::shared::subsf3(5.0f, 3.0f));
+ EXPECT_FP_EQ(3.0f, shared::addsf3(1.0f, 2.0f));
+ EXPECT_FP_EQ(3.0f, shared::divsf3(6.0f, 2.0f));
+ EXPECT_FP_EQ(6.0f, shared::mulsf3(2.0f, 3.0f));
+ EXPECT_FP_EQ(2.0f, shared::subsf3(5.0f, 3.0f));
}
TEST(LlvmLibcSharedBuiltinsTest, AllDouble) {
- EXPECT_FP_EQ(3.0, LIBC_NAMESPACE::shared::adddf3(1.0, 2.0));
- EXPECT_FP_EQ(3.0, LIBC_NAMESPACE::shared::divdf3(6.0, 2.0));
- EXPECT_FP_EQ(6.0, LIBC_NAMESPACE::shared::muldf3(2.0, 3.0));
- EXPECT_FP_EQ(2.0, LIBC_NAMESPACE::shared::subdf3(5.0, 3.0));
+ EXPECT_FP_EQ(3.0, shared::adddf3(1.0, 2.0));
+ EXPECT_FP_EQ(3.0, shared::divdf3(6.0, 2.0));
+ EXPECT_FP_EQ(6.0, shared::muldf3(2.0, 3.0));
+ EXPECT_FP_EQ(2.0, shared::subdf3(5.0, 3.0));
}
#ifdef LIBC_TYPES_HAS_FLOAT128
TEST(LlvmLibcSharedBuiltinsTest, AllFloat128) {
- EXPECT_FP_EQ(float128(3.0),
- LIBC_NAMESPACE::shared::addtf3(float128(1.0), float128(2.0)));
- EXPECT_FP_EQ(float128(3.0),
- LIBC_NAMESPACE::shared::divtf3(float128(6.0), float128(2.0)));
- EXPECT_FP_EQ(float128(6.0),
- LIBC_NAMESPACE::shared::multf3(float128(2.0), float128(3.0)));
- EXPECT_FP_EQ(float128(2.0),
- LIBC_NAMESPACE::shared::subtf3(float128(5.0), float128(3.0)));
+ EXPECT_FP_EQ(float128(3.0), shared::addtf3(float128(1.0), float128(2.0)));
+ EXPECT_FP_EQ(float128(3.0), shared::divtf3(float128(6.0), float128(2.0)));
+ EXPECT_FP_EQ(float128(6.0), shared::multf3(float128(2.0), float128(3.0)));
+ EXPECT_FP_EQ(float128(2.0), shared::subtf3(float128(5.0), float128(3.0)));
}
#endif // LIBC_TYPES_HAS_FLOAT128
+
+TEST(LlvmLibcSharedBuiltinsTest, IntToDoubleConversion) {
+ EXPECT_FP_EQ(12.0, shared::floatdidf(int64_t(12)));
+ EXPECT_FP_EQ(12.0, shared::floatsidf(int32_t(12)));
+#ifdef LIBC_TYPES_HAS_INT128
+ EXPECT_FP_EQ(12.0, shared::floattidf(static_cast<Int128>(12)));
+#endif // LIBC_TYPES_HAS_INT128
+}
+
+TEST(LlvmLibcSharedBuiltinsTest, UIntToDoubleConversion) {
+ EXPECT_FP_EQ(12.0, shared::floatundidf(uint64_t(12)));
+ EXPECT_FP_EQ(12.0, shared::floatunsidf(uint32_t(12)));
+#ifdef LIBC_TYPES_HAS_INT128
+ EXPECT_FP_EQ(12.0, shared::floatuntidf(static_cast<UInt128>(12)));
+#endif // LIBC_TYPES_HAS_INT128
+}
+
+TEST(LlvmLibcSharedBuiltinsTest, IntToFloatConversion) {
+ EXPECT_FP_EQ(12.0f, shared::floatdisf(int64_t(12)));
+ EXPECT_FP_EQ(12.0f, shared::floatsisf(int32_t(12)));
+#ifdef LIBC_TYPES_HAS_INT128
+ EXPECT_FP_EQ(12.0f, shared::floattisf(static_cast<Int128>(12)));
+#endif // LIBC_TYPES_HAS_INT128
+}
+
+TEST(LlvmLibcSharedBuiltinsTest, UIntToFloatConversion) {
+ EXPECT_FP_EQ(12.0f, shared::floatundisf(uint64_t(12)));
+ EXPECT_FP_EQ(12.0f, shared::floatunsisf(uint32_t(12)));
+#ifdef LIBC_TYPES_HAS_INT128
+ EXPECT_FP_EQ(12.0f, shared::floatuntisf(static_cast<UInt128>(12)));
+#endif // LIBC_TYPES_HAS_INT128
+}
>From 1180411a3eea461d8afa80395653bebe46d1e5f8 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 16 Jul 2026 00:24:10 +0300
Subject: [PATCH 2/3] fix format
---
libc/src/__support/builtins/floatdidf.h | 4 +---
libc/src/__support/builtins/floatdisf.h | 4 +---
libc/src/__support/builtins/floatsidf.h | 4 +---
libc/src/__support/builtins/floatsisf.h | 4 +---
libc/src/__support/builtins/floattidf.h | 4 +---
libc/src/__support/builtins/floattisf.h | 4 +---
libc/src/__support/builtins/floatundidf.h | 4 +---
libc/src/__support/builtins/floatundisf.h | 4 +---
libc/src/__support/builtins/floatunsidf.h | 4 +---
libc/src/__support/builtins/floatunsisf.h | 4 +---
libc/src/__support/builtins/floatuntidf.h | 4 +---
libc/src/__support/builtins/floatuntisf.h | 4 +---
12 files changed, 12 insertions(+), 36 deletions(-)
diff --git a/libc/src/__support/builtins/floatdidf.h b/libc/src/__support/builtins/floatdidf.h
index 118acefe0d44a..c9843d53d5598 100644
--- a/libc/src/__support/builtins/floatdidf.h
+++ b/libc/src/__support/builtins/floatdidf.h
@@ -24,9 +24,7 @@ namespace builtins {
// double <- int64_t conversion, round to nearest.
// Mirrors compiler-rt's __floatdidf.
-LIBC_INLINE double floatdidf(int64_t x) {
- return floatint<double>(x);
-}
+LIBC_INLINE double floatdidf(int64_t x) { return floatint<double>(x); }
} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/builtins/floatdisf.h b/libc/src/__support/builtins/floatdisf.h
index d88c895bb4464..b53595a782c7f 100644
--- a/libc/src/__support/builtins/floatdisf.h
+++ b/libc/src/__support/builtins/floatdisf.h
@@ -24,9 +24,7 @@ namespace builtins {
// float <- int64_t conversion, round to nearest.
// Mirrors compiler-rt's __floatdisf.
-LIBC_INLINE float floatdisf(int64_t x) {
- return floatint<float>(x);
-}
+LIBC_INLINE float floatdisf(int64_t x) { return floatint<float>(x); }
} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/builtins/floatsidf.h b/libc/src/__support/builtins/floatsidf.h
index ce092d394d1d7..28b0c27bb5948 100644
--- a/libc/src/__support/builtins/floatsidf.h
+++ b/libc/src/__support/builtins/floatsidf.h
@@ -24,9 +24,7 @@ namespace builtins {
// double <- int32_t conversion, round to nearest.
// Mirrors compiler-rt's __floatsidf.
-LIBC_INLINE double floatsidf(int32_t x) {
- return floatint<double>(x);
-}
+LIBC_INLINE double floatsidf(int32_t x) { return floatint<double>(x); }
} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/builtins/floatsisf.h b/libc/src/__support/builtins/floatsisf.h
index c862121dcd861..75ab24c7680a5 100644
--- a/libc/src/__support/builtins/floatsisf.h
+++ b/libc/src/__support/builtins/floatsisf.h
@@ -24,9 +24,7 @@ namespace builtins {
// float <- int32_t conversion, round to nearest.
// Mirrors compiler-rt's __floatsisf.
-LIBC_INLINE float floatsisf(int32_t x) {
- return floatint<float>(x);
-}
+LIBC_INLINE float floatsisf(int32_t x) { return floatint<float>(x); }
} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/builtins/floattidf.h b/libc/src/__support/builtins/floattidf.h
index 8bc445ede7d94..2c346f1cb3256 100644
--- a/libc/src/__support/builtins/floattidf.h
+++ b/libc/src/__support/builtins/floattidf.h
@@ -28,9 +28,7 @@ namespace builtins {
// double <- __int128_t conversion, round to nearest.
// Mirrors compiler-rt's __floattidf.
-LIBC_INLINE double floattidf(__int128_t x) {
- return floatint<double>(x);
-}
+LIBC_INLINE double floattidf(__int128_t x) { return floatint<double>(x); }
} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/builtins/floattisf.h b/libc/src/__support/builtins/floattisf.h
index 4b7330040f4d1..accf1234b96c6 100644
--- a/libc/src/__support/builtins/floattisf.h
+++ b/libc/src/__support/builtins/floattisf.h
@@ -28,9 +28,7 @@ namespace builtins {
// float <- __int128_t conversion, round to nearest.
// Mirrors compiler-rt's __floattisf.
-LIBC_INLINE float floattisf(__int128_t x) {
- return floatint<float>(x);
-}
+LIBC_INLINE float floattisf(__int128_t x) { return floatint<float>(x); }
} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/builtins/floatundidf.h b/libc/src/__support/builtins/floatundidf.h
index b138f8a9c31fd..c368602892b38 100644
--- a/libc/src/__support/builtins/floatundidf.h
+++ b/libc/src/__support/builtins/floatundidf.h
@@ -24,9 +24,7 @@ namespace builtins {
// double <- uint64_t conversion, round to nearest.
// Mirrors compiler-rt's __floatundidf.
-LIBC_INLINE double floatundidf(uint64_t x) {
- return floatint<double>(x);
-}
+LIBC_INLINE double floatundidf(uint64_t x) { return floatint<double>(x); }
} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/builtins/floatundisf.h b/libc/src/__support/builtins/floatundisf.h
index fc4439db39ba6..ba450937ff73b 100644
--- a/libc/src/__support/builtins/floatundisf.h
+++ b/libc/src/__support/builtins/floatundisf.h
@@ -24,9 +24,7 @@ namespace builtins {
// float <- uint64_t conversion, round to nearest.
// Mirrors compiler-rt's __floatundisf.
-LIBC_INLINE float floatundisf(uint64_t x) {
- return floatint<float>(x);
-}
+LIBC_INLINE float floatundisf(uint64_t x) { return floatint<float>(x); }
} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/builtins/floatunsidf.h b/libc/src/__support/builtins/floatunsidf.h
index b99f8a6508a06..5fa90c640772e 100644
--- a/libc/src/__support/builtins/floatunsidf.h
+++ b/libc/src/__support/builtins/floatunsidf.h
@@ -24,9 +24,7 @@ namespace builtins {
// double <- uint32_t conversion, round to nearest.
// Mirrors compiler-rt's __floatunsidf.
-LIBC_INLINE double floatunsidf(uint32_t x) {
- return floatint<double>(x);
-}
+LIBC_INLINE double floatunsidf(uint32_t x) { return floatint<double>(x); }
} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/builtins/floatunsisf.h b/libc/src/__support/builtins/floatunsisf.h
index 86bbc44c2fff4..cb8bd27a044e6 100644
--- a/libc/src/__support/builtins/floatunsisf.h
+++ b/libc/src/__support/builtins/floatunsisf.h
@@ -24,9 +24,7 @@ namespace builtins {
// float <- uint32_t conversion, round to nearest.
// Mirrors compiler-rt's __floatunsisf.
-LIBC_INLINE float floatunsisf(uint32_t x) {
- return floatint<float>(x);
-}
+LIBC_INLINE float floatunsisf(uint32_t x) { return floatint<float>(x); }
} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/builtins/floatuntidf.h b/libc/src/__support/builtins/floatuntidf.h
index 25b68280aab3d..e2035a0d90584 100644
--- a/libc/src/__support/builtins/floatuntidf.h
+++ b/libc/src/__support/builtins/floatuntidf.h
@@ -28,9 +28,7 @@ namespace builtins {
// double <- __uint128_t conversion, round to nearest.
// Mirrors compiler-rt's __floatuntidf.
-LIBC_INLINE double floatuntidf(__uint128_t x) {
- return floatint<double>(x);
-}
+LIBC_INLINE double floatuntidf(__uint128_t x) { return floatint<double>(x); }
} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/builtins/floatuntisf.h b/libc/src/__support/builtins/floatuntisf.h
index 7d83e6b36c969..60e08c9b08151 100644
--- a/libc/src/__support/builtins/floatuntisf.h
+++ b/libc/src/__support/builtins/floatuntisf.h
@@ -28,9 +28,7 @@ namespace builtins {
// float <- __uint128_t conversion, round to nearest.
// Mirrors compiler-rt's __floatuntisf.
-LIBC_INLINE float floatuntisf(__uint128_t x) {
- return floatint<float>(x);
-}
+LIBC_INLINE float floatuntisf(__uint128_t x) { return floatint<float>(x); }
} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL
>From ffa40adb9e4e131e768361281b860bf8e665625d Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 16 Jul 2026 07:14:42 +0300
Subject: [PATCH 3/3] remove zero mantissa handling because it's handled inside
DyadicFloat::as<>
---
libc/src/__support/builtins/floatint_helper.h | 3 ---
1 file changed, 3 deletions(-)
diff --git a/libc/src/__support/builtins/floatint_helper.h b/libc/src/__support/builtins/floatint_helper.h
index e1ee8f4d14d22..aeb853fdec79f 100644
--- a/libc/src/__support/builtins/floatint_helper.h
+++ b/libc/src/__support/builtins/floatint_helper.h
@@ -34,9 +34,6 @@ namespace builtins {
template <typename F, typename I> LIBC_INLINE constexpr F floatint(I x) {
using UI = cpp::make_unsigned_t<I>;
- if (x == 0)
- return F(0);
-
Sign sign = Sign::POS;
UI mag = static_cast<UI>(x);
if constexpr (cpp::is_signed_v<I>) {
More information about the libc-commits
mailing list