https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/215728
>From 3169be68df85731589125ab8447a7e7d06ad44b9 Mon Sep 17 00:00:00 2001 From: hulxv <[email protected]> Date: Sun, 9 Aug 2026 02:33:39 +0300 Subject: [PATCH] [compiler-rt][builtins] libc-backed float80-int conversion builtins --- compiler-rt/lib/builtins/CMakeLists.txt | 9 ++ compiler-rt/lib/builtins/fixunsxfdi.cpp | 24 ++++++ compiler-rt/lib/builtins/fixunsxfsi.cpp | 24 ++++++ compiler-rt/lib/builtins/fixunsxfti.cpp | 25 ++++++ compiler-rt/lib/builtins/fixxfdi.cpp | 24 ++++++ compiler-rt/lib/builtins/fixxfti.cpp | 24 ++++++ compiler-rt/lib/builtins/floatdixf.cpp | 24 ++++++ compiler-rt/lib/builtins/floattixf.cpp | 24 ++++++ compiler-rt/lib/builtins/floatundixf.cpp | 24 ++++++ compiler-rt/lib/builtins/floatuntixf.cpp | 24 ++++++ libc/shared/builtins.h | 9 ++ libc/shared/builtins/fixunsxfdi.h | 35 ++++++++ libc/shared/builtins/fixunsxfsi.h | 35 ++++++++ libc/shared/builtins/fixunsxfti.h | 36 ++++++++ libc/shared/builtins/fixxfdi.h | 35 ++++++++ libc/shared/builtins/fixxfti.h | 36 ++++++++ libc/shared/builtins/floatdixf.h | 35 ++++++++ libc/shared/builtins/floattixf.h | 36 ++++++++ libc/shared/builtins/floatundixf.h | 35 ++++++++ libc/shared/builtins/floatuntixf.h | 36 ++++++++ libc/src/__support/builtins/CMakeLists.txt | 99 ++++++++++++++++++++++ libc/src/__support/builtins/fixunsxfdi.h | 40 +++++++++ libc/src/__support/builtins/fixunsxfsi.h | 40 +++++++++ libc/src/__support/builtins/fixunsxfti.h | 41 +++++++++ libc/src/__support/builtins/fixxfdi.h | 40 +++++++++ libc/src/__support/builtins/fixxfti.h | 41 +++++++++ libc/src/__support/builtins/floatdixf.h | 40 +++++++++ libc/src/__support/builtins/floattixf.h | 41 +++++++++ libc/src/__support/builtins/floatundixf.h | 40 +++++++++ libc/src/__support/builtins/floatuntixf.h | 41 +++++++++ libc/test/shared/CMakeLists.txt | 9 ++ libc/test/shared/shared_builtins_test.cpp | 45 ++++++++++ 32 files changed, 1071 insertions(+) create mode 100644 compiler-rt/lib/builtins/fixunsxfdi.cpp create mode 100644 compiler-rt/lib/builtins/fixunsxfsi.cpp create mode 100644 compiler-rt/lib/builtins/fixunsxfti.cpp create mode 100644 compiler-rt/lib/builtins/fixxfdi.cpp create mode 100644 compiler-rt/lib/builtins/fixxfti.cpp create mode 100644 compiler-rt/lib/builtins/floatdixf.cpp create mode 100644 compiler-rt/lib/builtins/floattixf.cpp create mode 100644 compiler-rt/lib/builtins/floatundixf.cpp create mode 100644 compiler-rt/lib/builtins/floatuntixf.cpp create mode 100644 libc/shared/builtins/fixunsxfdi.h create mode 100644 libc/shared/builtins/fixunsxfsi.h create mode 100644 libc/shared/builtins/fixunsxfti.h create mode 100644 libc/shared/builtins/fixxfdi.h create mode 100644 libc/shared/builtins/fixxfti.h create mode 100644 libc/shared/builtins/floatdixf.h create mode 100644 libc/shared/builtins/floattixf.h create mode 100644 libc/shared/builtins/floatundixf.h create mode 100644 libc/shared/builtins/floatuntixf.h create mode 100644 libc/src/__support/builtins/fixunsxfdi.h create mode 100644 libc/src/__support/builtins/fixunsxfsi.h create mode 100644 libc/src/__support/builtins/fixunsxfti.h create mode 100644 libc/src/__support/builtins/fixxfdi.h create mode 100644 libc/src/__support/builtins/fixxfti.h create mode 100644 libc/src/__support/builtins/floatdixf.h create mode 100644 libc/src/__support/builtins/floattixf.h create mode 100644 libc/src/__support/builtins/floatundixf.h create mode 100644 libc/src/__support/builtins/floatuntixf.h diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt index 5fe4adf2a2e99..8d3eee6f777be 100644 --- a/compiler-rt/lib/builtins/CMakeLists.txt +++ b/compiler-rt/lib/builtins/CMakeLists.txt @@ -340,6 +340,15 @@ if(COMPILER_RT_USE_LIBC_MATH) use_libc_builtin(GENERIC_TF_SOURCES trunctfdf2) use_libc_builtin(GENERIC_TF_SOURCES trunctfsf2) use_libc_builtin(x86_80_BIT_SOURCES trunctfxf2) + use_libc_builtin(x86_80_BIT_SOURCES floatdixf) + use_libc_builtin(x86_80_BIT_SOURCES floattixf) + use_libc_builtin(x86_80_BIT_SOURCES floatundixf) + use_libc_builtin(x86_80_BIT_SOURCES floatuntixf) + use_libc_builtin(x86_80_BIT_SOURCES fixxfdi) + use_libc_builtin(x86_80_BIT_SOURCES fixxfti) + use_libc_builtin(x86_80_BIT_SOURCES fixunsxfsi) + use_libc_builtin(x86_80_BIT_SOURCES fixunsxfdi) + use_libc_builtin(x86_80_BIT_SOURCES fixunsxfti) use_libc_builtin(GENERIC_TF_SOURCES fixtfsi) use_libc_builtin(GENERIC_TF_SOURCES fixtfdi) use_libc_builtin(GENERIC_TF_SOURCES fixtfti) diff --git a/compiler-rt/lib/builtins/fixunsxfdi.cpp b/compiler-rt/lib/builtins/fixunsxfdi.cpp new file mode 100644 index 0000000000000..5022f38348cc4 --- /dev/null +++ b/compiler-rt/lib/builtins/fixunsxfdi.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 __fixunsxfdi, truncating long double -> +/// uint64_t conversion (saturating), on top of LLVM-libc's shared::fixunsxfdi. +/// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" + +#include "fp_libc_config.h" +#include "shared/builtins/fixunsxfdi.h" + +#if !_ARCH_PPC +extern "C" COMPILER_RT_ABI du_int __fixunsxfdi(xf_float a) { + return LIBC_NAMESPACE::shared::fixunsxfdi(a); +} +#endif diff --git a/compiler-rt/lib/builtins/fixunsxfsi.cpp b/compiler-rt/lib/builtins/fixunsxfsi.cpp new file mode 100644 index 0000000000000..4d475d012dfd9 --- /dev/null +++ b/compiler-rt/lib/builtins/fixunsxfsi.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 __fixunsxfsi, truncating long double -> +/// uint32_t conversion (saturating), on top of LLVM-libc's shared::fixunsxfsi. +/// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" + +#include "fp_libc_config.h" +#include "shared/builtins/fixunsxfsi.h" + +#if !_ARCH_PPC +extern "C" COMPILER_RT_ABI su_int __fixunsxfsi(xf_float a) { + return LIBC_NAMESPACE::shared::fixunsxfsi(a); +} +#endif diff --git a/compiler-rt/lib/builtins/fixunsxfti.cpp b/compiler-rt/lib/builtins/fixunsxfti.cpp new file mode 100644 index 0000000000000..7136bdbf96eea --- /dev/null +++ b/compiler-rt/lib/builtins/fixunsxfti.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file implements compiler-rt's __fixunsxfti, truncating long double -> +/// __uint128_t conversion (saturating), on top of LLVM-libc's +/// shared::fixunsxfti. +/// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" + +#include "fp_libc_config.h" +#include "shared/builtins/fixunsxfti.h" + +#if defined(CRT_HAS_128BIT) +extern "C" COMPILER_RT_ABI tu_int __fixunsxfti(xf_float a) { + return LIBC_NAMESPACE::shared::fixunsxfti(a); +} +#endif diff --git a/compiler-rt/lib/builtins/fixxfdi.cpp b/compiler-rt/lib/builtins/fixxfdi.cpp new file mode 100644 index 0000000000000..7f8b9a3bf184b --- /dev/null +++ b/compiler-rt/lib/builtins/fixxfdi.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 __fixxfdi, truncating long double -> +/// int64_t conversion (saturating), on top of LLVM-libc's shared::fixxfdi. +/// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" + +#include "fp_libc_config.h" +#include "shared/builtins/fixxfdi.h" + +#if !_ARCH_PPC +extern "C" COMPILER_RT_ABI di_int __fixxfdi(xf_float a) { + return LIBC_NAMESPACE::shared::fixxfdi(a); +} +#endif diff --git a/compiler-rt/lib/builtins/fixxfti.cpp b/compiler-rt/lib/builtins/fixxfti.cpp new file mode 100644 index 0000000000000..193b15ea503d2 --- /dev/null +++ b/compiler-rt/lib/builtins/fixxfti.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 __fixxfti, truncating long double -> +/// __int128_t conversion (saturating), on top of LLVM-libc's shared::fixxfti. +/// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" + +#include "fp_libc_config.h" +#include "shared/builtins/fixxfti.h" + +#if defined(CRT_HAS_128BIT) +extern "C" COMPILER_RT_ABI ti_int __fixxfti(xf_float a) { + return LIBC_NAMESPACE::shared::fixxfti(a); +} +#endif diff --git a/compiler-rt/lib/builtins/floatdixf.cpp b/compiler-rt/lib/builtins/floatdixf.cpp new file mode 100644 index 0000000000000..7d5f30f0b1d17 --- /dev/null +++ b/compiler-rt/lib/builtins/floatdixf.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 __floatdixf, int64_t -> long double +/// conversion (round to nearest), on top of LLVM-libc's shared::floatdixf. +/// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" + +#include "fp_libc_config.h" +#include "shared/builtins/floatdixf.h" + +#if !_ARCH_PPC +extern "C" COMPILER_RT_ABI xf_float __floatdixf(di_int a) { + return LIBC_NAMESPACE::shared::floatdixf(a); +} +#endif diff --git a/compiler-rt/lib/builtins/floattixf.cpp b/compiler-rt/lib/builtins/floattixf.cpp new file mode 100644 index 0000000000000..5c13e4cbc7f96 --- /dev/null +++ b/compiler-rt/lib/builtins/floattixf.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 __floattixf, __int128_t -> long double +/// conversion (round to nearest), on top of LLVM-libc's shared::floattixf. +/// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" + +#include "fp_libc_config.h" +#include "shared/builtins/floattixf.h" + +#if defined(CRT_HAS_128BIT) +extern "C" COMPILER_RT_ABI xf_float __floattixf(ti_int a) { + return LIBC_NAMESPACE::shared::floattixf(a); +} +#endif diff --git a/compiler-rt/lib/builtins/floatundixf.cpp b/compiler-rt/lib/builtins/floatundixf.cpp new file mode 100644 index 0000000000000..e8541b055e650 --- /dev/null +++ b/compiler-rt/lib/builtins/floatundixf.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 __floatundixf, uint64_t -> long double +/// conversion (round to nearest), on top of LLVM-libc's shared::floatundixf. +/// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" + +#include "fp_libc_config.h" +#include "shared/builtins/floatundixf.h" + +#if !_ARCH_PPC +extern "C" COMPILER_RT_ABI xf_float __floatundixf(du_int a) { + return LIBC_NAMESPACE::shared::floatundixf(a); +} +#endif diff --git a/compiler-rt/lib/builtins/floatuntixf.cpp b/compiler-rt/lib/builtins/floatuntixf.cpp new file mode 100644 index 0000000000000..8315e82a93c0b --- /dev/null +++ b/compiler-rt/lib/builtins/floatuntixf.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 __floatuntixf, __uint128_t -> long double +/// conversion (round to nearest), on top of LLVM-libc's shared::floatuntixf. +/// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" + +#include "fp_libc_config.h" +#include "shared/builtins/floatuntixf.h" + +#if defined(CRT_HAS_128BIT) +extern "C" COMPILER_RT_ABI xf_float __floatuntixf(tu_int a) { + return LIBC_NAMESPACE::shared::floatuntixf(a); +} +#endif diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h index c1af1d39733ff..f44f793736702 100644 --- a/libc/shared/builtins.h +++ b/libc/shared/builtins.h @@ -45,24 +45,33 @@ #include "builtins/fixunstfdi.h" #include "builtins/fixunstfsi.h" #include "builtins/fixunstfti.h" +#include "builtins/fixunsxfdi.h" +#include "builtins/fixunsxfsi.h" +#include "builtins/fixunsxfti.h" +#include "builtins/fixxfdi.h" +#include "builtins/fixxfti.h" #include "builtins/floatdidf.h" #include "builtins/floatdisf.h" #include "builtins/floatditf.h" +#include "builtins/floatdixf.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/floattixf.h" #include "builtins/floatundidf.h" #include "builtins/floatundisf.h" #include "builtins/floatunditf.h" +#include "builtins/floatundixf.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/floatuntixf.h" #include "builtins/gedf2.h" #include "builtins/gesf2.h" #include "builtins/getf2.h" diff --git a/libc/shared/builtins/fixunsxfdi.h b/libc/shared/builtins/fixunsxfdi.h new file mode 100644 index 0000000000000..1546a604c93f7 --- /dev/null +++ b/libc/shared/builtins/fixunsxfdi.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 __fixunsxfdi implementation as +/// shared::fixunsxfdi so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_BUILTINS_FIXUNSXFDI_H +#define LLVM_LIBC_SHARED_BUILTINS_FIXUNSXFDI_H + +#include "src/__support/macros/properties/types.h" + +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#include "shared/libc_common.h" +#include "src/__support/builtins/fixunsxfdi.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using builtins::fixunsxfdi; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#endif // LLVM_LIBC_SHARED_BUILTINS_FIXUNSXFDI_H diff --git a/libc/shared/builtins/fixunsxfsi.h b/libc/shared/builtins/fixunsxfsi.h new file mode 100644 index 0000000000000..8f16a4c7192b1 --- /dev/null +++ b/libc/shared/builtins/fixunsxfsi.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 __fixunsxfsi implementation as +/// shared::fixunsxfsi so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_BUILTINS_FIXUNSXFSI_H +#define LLVM_LIBC_SHARED_BUILTINS_FIXUNSXFSI_H + +#include "src/__support/macros/properties/types.h" + +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#include "shared/libc_common.h" +#include "src/__support/builtins/fixunsxfsi.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using builtins::fixunsxfsi; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#endif // LLVM_LIBC_SHARED_BUILTINS_FIXUNSXFSI_H diff --git a/libc/shared/builtins/fixunsxfti.h b/libc/shared/builtins/fixunsxfti.h new file mode 100644 index 0000000000000..21352a58bdc7b --- /dev/null +++ b/libc/shared/builtins/fixunsxfti.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 __fixunsxfti implementation as +/// shared::fixunsxfti so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_BUILTINS_FIXUNSXFTI_H +#define LLVM_LIBC_SHARED_BUILTINS_FIXUNSXFTI_H + +#include "src/__support/macros/properties/types.h" + +#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80) && \ + defined(LIBC_TYPES_HAS_INT128) + +#include "shared/libc_common.h" +#include "src/__support/builtins/fixunsxfti.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using builtins::fixunsxfti; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 && LIBC_TYPES_HAS_INT128 + +#endif // LLVM_LIBC_SHARED_BUILTINS_FIXUNSXFTI_H diff --git a/libc/shared/builtins/fixxfdi.h b/libc/shared/builtins/fixxfdi.h new file mode 100644 index 0000000000000..139973c88fbe0 --- /dev/null +++ b/libc/shared/builtins/fixxfdi.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 __fixxfdi implementation as shared::fixxfdi +/// so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_BUILTINS_FIXXFDI_H +#define LLVM_LIBC_SHARED_BUILTINS_FIXXFDI_H + +#include "src/__support/macros/properties/types.h" + +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#include "shared/libc_common.h" +#include "src/__support/builtins/fixxfdi.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using builtins::fixxfdi; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#endif // LLVM_LIBC_SHARED_BUILTINS_FIXXFDI_H diff --git a/libc/shared/builtins/fixxfti.h b/libc/shared/builtins/fixxfti.h new file mode 100644 index 0000000000000..3529a427fea26 --- /dev/null +++ b/libc/shared/builtins/fixxfti.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 __fixxfti implementation as shared::fixxfti +/// so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_BUILTINS_FIXXFTI_H +#define LLVM_LIBC_SHARED_BUILTINS_FIXXFTI_H + +#include "src/__support/macros/properties/types.h" + +#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80) && \ + defined(LIBC_TYPES_HAS_INT128) + +#include "shared/libc_common.h" +#include "src/__support/builtins/fixxfti.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using builtins::fixxfti; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 && LIBC_TYPES_HAS_INT128 + +#endif // LLVM_LIBC_SHARED_BUILTINS_FIXXFTI_H diff --git a/libc/shared/builtins/floatdixf.h b/libc/shared/builtins/floatdixf.h new file mode 100644 index 0000000000000..28ed14f1f8201 --- /dev/null +++ b/libc/shared/builtins/floatdixf.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 __floatdixf implementation as +/// shared::floatdixf so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATDIXF_H +#define LLVM_LIBC_SHARED_BUILTINS_FLOATDIXF_H + +#include "src/__support/macros/properties/types.h" + +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#include "shared/libc_common.h" +#include "src/__support/builtins/floatdixf.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using builtins::floatdixf; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATDIXF_H diff --git a/libc/shared/builtins/floattixf.h b/libc/shared/builtins/floattixf.h new file mode 100644 index 0000000000000..b5473a914c03a --- /dev/null +++ b/libc/shared/builtins/floattixf.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 __floattixf implementation as +/// shared::floattixf so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATTIXF_H +#define LLVM_LIBC_SHARED_BUILTINS_FLOATTIXF_H + +#include "src/__support/macros/properties/types.h" + +#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80) && \ + defined(LIBC_TYPES_HAS_INT128) + +#include "shared/libc_common.h" +#include "src/__support/builtins/floattixf.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using builtins::floattixf; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 && LIBC_TYPES_HAS_INT128 + +#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATTIXF_H diff --git a/libc/shared/builtins/floatundixf.h b/libc/shared/builtins/floatundixf.h new file mode 100644 index 0000000000000..3b3d131a651e0 --- /dev/null +++ b/libc/shared/builtins/floatundixf.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 __floatundixf implementation as +/// shared::floatundixf so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATUNDIXF_H +#define LLVM_LIBC_SHARED_BUILTINS_FLOATUNDIXF_H + +#include "src/__support/macros/properties/types.h" + +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#include "shared/libc_common.h" +#include "src/__support/builtins/floatundixf.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using builtins::floatundixf; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATUNDIXF_H diff --git a/libc/shared/builtins/floatuntixf.h b/libc/shared/builtins/floatuntixf.h new file mode 100644 index 0000000000000..f4f5dada15616 --- /dev/null +++ b/libc/shared/builtins/floatuntixf.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 __floatuntixf implementation as +/// shared::floatuntixf so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_BUILTINS_FLOATUNTIXF_H +#define LLVM_LIBC_SHARED_BUILTINS_FLOATUNTIXF_H + +#include "src/__support/macros/properties/types.h" + +#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80) && \ + defined(LIBC_TYPES_HAS_INT128) + +#include "shared/libc_common.h" +#include "src/__support/builtins/floatuntixf.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using builtins::floatuntixf; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 && LIBC_TYPES_HAS_INT128 + +#endif // LLVM_LIBC_SHARED_BUILTINS_FLOATUNTIXF_H diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt index e1b1f819f7e4a..436d14ebcdd93 100644 --- a/libc/src/__support/builtins/CMakeLists.txt +++ b/libc/src/__support/builtins/CMakeLists.txt @@ -719,3 +719,102 @@ add_header_library( libc.src.__support.macros.config libc.src.__support.macros.properties.types ) + +add_header_library( + floatdixf + HDRS + floatdixf.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( + floattixf + HDRS + floattixf.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( + floatundixf + HDRS + floatundixf.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( + floatuntixf + HDRS + floatuntixf.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( + fixxfdi + HDRS + fixxfdi.h + DEPENDS + libc.hdr.stdint_proxy + libc.src.__support.builtins.fixint_helper + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) + +add_header_library( + fixxfti + HDRS + fixxfti.h + DEPENDS + libc.hdr.stdint_proxy + libc.src.__support.builtins.fixint_helper + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) + +add_header_library( + fixunsxfsi + HDRS + fixunsxfsi.h + DEPENDS + libc.hdr.stdint_proxy + libc.src.__support.builtins.fixint_helper + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) + +add_header_library( + fixunsxfdi + HDRS + fixunsxfdi.h + DEPENDS + libc.hdr.stdint_proxy + libc.src.__support.builtins.fixint_helper + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) + +add_header_library( + fixunsxfti + HDRS + fixunsxfti.h + DEPENDS + libc.hdr.stdint_proxy + libc.src.__support.builtins.fixint_helper + libc.src.__support.macros.config + libc.src.__support.macros.properties.types +) diff --git a/libc/src/__support/builtins/fixunsxfdi.h b/libc/src/__support/builtins/fixunsxfdi.h new file mode 100644 index 0000000000000..7ba7784b6090f --- /dev/null +++ b/libc/src/__support/builtins/fixunsxfdi.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 __fixunsxfdi implementation as +/// builtins::fixunsxfdi so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXUNSXFDI_H +#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXUNSXFDI_H + +#include "src/__support/macros/properties/types.h" + +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#include "hdr/stdint_proxy.h" +#include "src/__support/builtins/fixint_helper.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace builtins { + +// Truncating long double -> uint64_t conversion, saturating on overflow. +// Mirrors compiler-rt's __fixunsxfdi. +LIBC_INLINE uint64_t fixunsxfdi(long double x) { + return fixuint<uint64_t>(x); +} + +} // namespace builtins +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXUNSXFDI_H diff --git a/libc/src/__support/builtins/fixunsxfsi.h b/libc/src/__support/builtins/fixunsxfsi.h new file mode 100644 index 0000000000000..f663d76350f3d --- /dev/null +++ b/libc/src/__support/builtins/fixunsxfsi.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 __fixunsxfsi implementation as +/// builtins::fixunsxfsi so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXUNSXFSI_H +#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXUNSXFSI_H + +#include "src/__support/macros/properties/types.h" + +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#include "hdr/stdint_proxy.h" +#include "src/__support/builtins/fixint_helper.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace builtins { + +// Truncating long double -> uint32_t conversion, saturating on overflow. +// Mirrors compiler-rt's __fixunsxfsi. +LIBC_INLINE uint32_t fixunsxfsi(long double x) { + return fixuint<uint32_t>(x); +} + +} // namespace builtins +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXUNSXFSI_H diff --git a/libc/src/__support/builtins/fixunsxfti.h b/libc/src/__support/builtins/fixunsxfti.h new file mode 100644 index 0000000000000..4bf2c36684ae2 --- /dev/null +++ b/libc/src/__support/builtins/fixunsxfti.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 __fixunsxfti implementation as +/// builtins::fixunsxfti so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXUNSXFTI_H +#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXUNSXFTI_H + +#include "src/__support/macros/properties/types.h" + +#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80) && \ + defined(LIBC_TYPES_HAS_INT128) + +#include "hdr/stdint_proxy.h" +#include "src/__support/builtins/fixint_helper.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace builtins { + +// Truncating long double -> __uint128_t conversion, saturating on overflow. +// Mirrors compiler-rt's __fixunsxfti. +LIBC_INLINE __uint128_t fixunsxfti(long double x) { + return fixuint<__uint128_t>(x); +} + +} // namespace builtins +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 && LIBC_TYPES_HAS_INT128 + +#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXUNSXFTI_H diff --git a/libc/src/__support/builtins/fixxfdi.h b/libc/src/__support/builtins/fixxfdi.h new file mode 100644 index 0000000000000..796e6e98ca04c --- /dev/null +++ b/libc/src/__support/builtins/fixxfdi.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 __fixxfdi implementation as +/// builtins::fixxfdi so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXXFDI_H +#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXXFDI_H + +#include "src/__support/macros/properties/types.h" + +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#include "hdr/stdint_proxy.h" +#include "src/__support/builtins/fixint_helper.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace builtins { + +// Truncating long double -> int64_t conversion, saturating on overflow. +// Mirrors compiler-rt's __fixxfdi. +LIBC_INLINE int64_t fixxfdi(long double x) { + return fixint<int64_t>(x); +} + +} // namespace builtins +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXXFDI_H diff --git a/libc/src/__support/builtins/fixxfti.h b/libc/src/__support/builtins/fixxfti.h new file mode 100644 index 0000000000000..b11f8f847375f --- /dev/null +++ b/libc/src/__support/builtins/fixxfti.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 __fixxfti implementation as +/// builtins::fixxfti so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXXFTI_H +#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXXFTI_H + +#include "src/__support/macros/properties/types.h" + +#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80) && \ + defined(LIBC_TYPES_HAS_INT128) + +#include "hdr/stdint_proxy.h" +#include "src/__support/builtins/fixint_helper.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace builtins { + +// Truncating long double -> __int128_t conversion, saturating on overflow. +// Mirrors compiler-rt's __fixxfti. +LIBC_INLINE __int128_t fixxfti(long double x) { + return fixint<__int128_t>(x); +} + +} // namespace builtins +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 && LIBC_TYPES_HAS_INT128 + +#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FIXXFTI_H diff --git a/libc/src/__support/builtins/floatdixf.h b/libc/src/__support/builtins/floatdixf.h new file mode 100644 index 0000000000000..677b687f02eb7 --- /dev/null +++ b/libc/src/__support/builtins/floatdixf.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 __floatdixf implementation as +/// builtins::floatdixf so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATDIXF_H +#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATDIXF_H + +#include "src/__support/macros/properties/types.h" + +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#include "hdr/stdint_proxy.h" +#include "src/__support/builtins/floatint_helper.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace builtins { + +// long double <- int64_t conversion, round to nearest. +// Mirrors compiler-rt's __floatdixf. +LIBC_INLINE long double floatdixf(int64_t x) { + return floatint<long double>(x); +} + +} // namespace builtins +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATDIXF_H diff --git a/libc/src/__support/builtins/floattixf.h b/libc/src/__support/builtins/floattixf.h new file mode 100644 index 0000000000000..9fafd53a51573 --- /dev/null +++ b/libc/src/__support/builtins/floattixf.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 __floattixf implementation as +/// builtins::floattixf so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATTIXF_H +#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATTIXF_H + +#include "src/__support/macros/properties/types.h" + +#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80) && \ + 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 { + +// long double <- __int128_t conversion, round to nearest. +// Mirrors compiler-rt's __floattixf. +LIBC_INLINE long double floattixf(__int128_t x) { + return floatint<long double>(x); +} + +} // namespace builtins +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 && LIBC_TYPES_HAS_INT128 + +#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATTIXF_H diff --git a/libc/src/__support/builtins/floatundixf.h b/libc/src/__support/builtins/floatundixf.h new file mode 100644 index 0000000000000..cfb2151267937 --- /dev/null +++ b/libc/src/__support/builtins/floatundixf.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 __floatundixf implementation as +/// builtins::floatundixf so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNDIXF_H +#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNDIXF_H + +#include "src/__support/macros/properties/types.h" + +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#include "hdr/stdint_proxy.h" +#include "src/__support/builtins/floatint_helper.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace builtins { + +// long double <- uint64_t conversion, round to nearest. +// Mirrors compiler-rt's __floatundixf. +LIBC_INLINE long double floatundixf(uint64_t x) { + return floatint<long double>(x); +} + +} // namespace builtins +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNDIXF_H diff --git a/libc/src/__support/builtins/floatuntixf.h b/libc/src/__support/builtins/floatuntixf.h new file mode 100644 index 0000000000000..cc390be7ad63d --- /dev/null +++ b/libc/src/__support/builtins/floatuntixf.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 __floatuntixf implementation as +/// builtins::floatuntixf so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNTIXF_H +#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNTIXF_H + +#include "src/__support/macros/properties/types.h" + +#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80) && \ + 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 { + +// long double <- __uint128_t conversion, round to nearest. +// Mirrors compiler-rt's __floatuntixf. +LIBC_INLINE long double floatuntixf(__uint128_t x) { + return floatint<long double>(x); +} + +} // namespace builtins +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 && LIBC_TYPES_HAS_INT128 + +#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_FLOATUNTIXF_H diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt index 93904311ae9a3..5633813dcc0ae 100644 --- a/libc/test/shared/CMakeLists.txt +++ b/libc/test/shared/CMakeLists.txt @@ -856,24 +856,33 @@ add_fp_unittest( libc.src.__support.builtins.fixunstfdi libc.src.__support.builtins.fixunstfsi libc.src.__support.builtins.fixunstfti + libc.src.__support.builtins.fixunsxfdi + libc.src.__support.builtins.fixunsxfsi + libc.src.__support.builtins.fixunsxfti + libc.src.__support.builtins.fixxfdi + libc.src.__support.builtins.fixxfti libc.src.__support.builtins.floatdidf libc.src.__support.builtins.floatdisf libc.src.__support.builtins.floatditf + libc.src.__support.builtins.floatdixf 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.floattixf libc.src.__support.builtins.floatundidf libc.src.__support.builtins.floatundisf libc.src.__support.builtins.floatunditf + libc.src.__support.builtins.floatundixf 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.floatuntixf libc.src.__support.builtins.gedf2 libc.src.__support.builtins.gesf2 libc.src.__support.builtins.getf2 diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp index d98574cb0fabd..beca828800def 100644 --- a/libc/test/shared/shared_builtins_test.cpp +++ b/libc/test/shared/shared_builtins_test.cpp @@ -97,6 +97,29 @@ TEST(LlvmLibcSharedBuiltinsTest, QuadToUIntConversion) { #endif // LIBC_TYPES_HAS_FLOAT128 +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +TEST(LlvmLibcSharedBuiltinsTest, X86Float80ToIntConversion) { + EXPECT_EQ(int64_t(12), shared::fixxfdi(12.5L)); +#ifdef LIBC_TYPES_HAS_INT128 + EXPECT_EQ(static_cast<__int128_t>(12), shared::fixxfti(12.5L)); +#endif // LIBC_TYPES_HAS_INT128 +} + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +TEST(LlvmLibcSharedBuiltinsTest, X86Float80ToUIntConversion) { + EXPECT_EQ(uint64_t(12), shared::fixunsxfdi(12.5L)); + EXPECT_EQ(uint32_t(12), shared::fixunsxfsi(12.5L)); +#ifdef LIBC_TYPES_HAS_INT128 + EXPECT_EQ(static_cast<__uint128_t>(12), shared::fixunsxfti(12.5L)); +#endif // LIBC_TYPES_HAS_INT128 +} + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + TEST(LlvmLibcSharedBuiltinsTest, IntToDoubleConversion) { EXPECT_FP_EQ(12.0, shared::floatdidf(int64_t(12))); EXPECT_FP_EQ(12.0, shared::floatsidf(int32_t(12))); @@ -154,6 +177,28 @@ TEST(LlvmLibcSharedBuiltinsTest, UIntToQuadConversion) { #endif // LIBC_TYPES_HAS_FLOAT128 +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +TEST(LlvmLibcSharedBuiltinsTest, IntToX86Float80Conversion) { + EXPECT_FP_EQ(12.0L, shared::floatdixf(int64_t(12))); +#ifdef LIBC_TYPES_HAS_INT128 + EXPECT_FP_EQ(12.0L, shared::floattixf(static_cast<__int128_t>(12))); +#endif // LIBC_TYPES_HAS_INT128 +} + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + +TEST(LlvmLibcSharedBuiltinsTest, UIntToX86Float80Conversion) { + EXPECT_FP_EQ(12.0L, shared::floatundixf(uint64_t(12))); +#ifdef LIBC_TYPES_HAS_INT128 + EXPECT_FP_EQ(12.0L, shared::floatuntixf(static_cast<__uint128_t>(12))); +#endif // LIBC_TYPES_HAS_INT128 +} + +#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80 + TEST(LlvmLibcSharedBuiltinsTest, ExtendConversion) { EXPECT_FP_EQ(1.5, shared::extendsfdf2(1.5f)); #ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
