https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/215725
>From 53071a416a870c469b0b1958989faf54b9296f78 Mon Sep 17 00:00:00 2001 From: hulxv <[email protected]> Date: Sun, 9 Aug 2026 01:57:07 +0300 Subject: [PATCH 1/2] [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 ef3de95f9e982..0254cb6f8f31a 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 591c5e042c28c..d37879c3ec7a2 100644 --- a/libc/src/__support/builtins/CMakeLists.txt +++ b/libc/src/__support/builtins/CMakeLists.txt @@ -580,3 +580,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 c7ac8d0f3f2b7..e40b1a101bdf3 100644 --- a/libc/test/shared/CMakeLists.txt +++ b/libc/test/shared/CMakeLists.txt @@ -854,16 +854,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 @@ -882,10 +888,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 f4409d8909508..d2387bf7db0f8 100644 --- a/libc/test/shared/shared_builtins_test.cpp +++ b/libc/test/shared/shared_builtins_test.cpp @@ -39,6 +39,30 @@ TEST(LlvmLibcSharedBuiltinsTest, QuadPrecisionArithmtic) { } #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) { EXPECT_FP_EQ(1.5, shared::extendsfdf2(1.5f)); >From 7e0b77d88a126ef31ecb4c3529cefa3477691842 Mon Sep 17 00:00:00 2001 From: hulxv <[email protected]> Date: Wed, 12 Aug 2026 09:36:42 +0300 Subject: [PATCH 2/2] format --- libc/src/__support/builtins/floatditf.h | 4 +--- libc/src/__support/builtins/floatsitf.h | 4 +--- libc/src/__support/builtins/floattitf.h | 4 +--- libc/src/__support/builtins/floatunditf.h | 4 +--- libc/src/__support/builtins/floatunsitf.h | 4 +--- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/libc/src/__support/builtins/floatditf.h b/libc/src/__support/builtins/floatditf.h index 110a6350ce299..4108cc8a877cd 100644 --- a/libc/src/__support/builtins/floatditf.h +++ b/libc/src/__support/builtins/floatditf.h @@ -28,9 +28,7 @@ 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); -} +LIBC_INLINE float128 floatditf(int64_t x) { return floatint<float128>(x); } } // namespace builtins } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/__support/builtins/floatsitf.h b/libc/src/__support/builtins/floatsitf.h index bbc46a584bb50..cb0af3fbdc387 100644 --- a/libc/src/__support/builtins/floatsitf.h +++ b/libc/src/__support/builtins/floatsitf.h @@ -28,9 +28,7 @@ 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); -} +LIBC_INLINE float128 floatsitf(int32_t x) { return floatint<float128>(x); } } // namespace builtins } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/__support/builtins/floattitf.h b/libc/src/__support/builtins/floattitf.h index 5b4e65598b645..1bbab29fe1a28 100644 --- a/libc/src/__support/builtins/floattitf.h +++ b/libc/src/__support/builtins/floattitf.h @@ -29,9 +29,7 @@ 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); -} +LIBC_INLINE float128 floattitf(__int128_t x) { return floatint<float128>(x); } } // namespace builtins } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/__support/builtins/floatunditf.h b/libc/src/__support/builtins/floatunditf.h index 0fb47dc8d728a..a29b2a9ac61b9 100644 --- a/libc/src/__support/builtins/floatunditf.h +++ b/libc/src/__support/builtins/floatunditf.h @@ -28,9 +28,7 @@ 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); -} +LIBC_INLINE float128 floatunditf(uint64_t x) { return floatint<float128>(x); } } // namespace builtins } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/__support/builtins/floatunsitf.h b/libc/src/__support/builtins/floatunsitf.h index f570b5f0fe215..5bdb5be1d12e4 100644 --- a/libc/src/__support/builtins/floatunsitf.h +++ b/libc/src/__support/builtins/floatunsitf.h @@ -28,9 +28,7 @@ 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); -} +LIBC_INLINE float128 floatunsitf(uint32_t x) { return floatint<float128>(x); } } // namespace builtins } // namespace LIBC_NAMESPACE_DECL _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
