Skip to content

[builtins] Support building the 128-bit float functions on i386 #122658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler-rt/lib/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ if (NOT MSVC)
set(i386_SOURCES
${GENERIC_SOURCES}
${x86_ARCH_SOURCES}
${GENERIC_TF_SOURCES}
i386/ashldi3.S
i386/ashrdi3.S
i386/divdi3.S
Expand Down Expand Up @@ -906,7 +907,7 @@ else ()

# For RISCV32, we must force enable int128 for compiling long
# double routines.
if(COMPILER_RT_ENABLE_SOFTWARE_INT128 OR "${arch}" STREQUAL "riscv32")
if(COMPILER_RT_ENABLE_SOFTWARE_INT128 OR "${arch}" STREQUAL "riscv32" OR "${arch}" STREQUAL "i386")
list(APPEND BUILTIN_CFLAGS_${arch} -fforce-enable-int128)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we support other compilers? If so enabling this unconditionally for i386 might break them?

endif()

Expand Down
3 changes: 2 additions & 1 deletion compiler-rt/lib/builtins/extendxftf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#define QUAD_PRECISION
#include "fp_lib.h"

#if defined(CRT_HAS_TF_MODE) && __LDBL_MANT_DIG__ == 64 && defined(__x86_64__)
#if defined(CRT_HAS_TF_MODE) && __LDBL_MANT_DIG__ == 64 && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is concerning. Not all 32-bit environments support FP80. Concretely, Windows, FreeBSD, and Darwin definitely do support FP80 even though the hardware does. This can make it easy to get ABI breakages.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about only enable for linux

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should actually be checking HAS_80_BIT_LONG_DOUBLE, which is set correctly depending on environments that support it:

#if (defined(__i386__) || defined(__x86_64__)) && \

Suggested change
#if defined(CRT_HAS_TF_MODE) && __LDBL_MANT_DIG__ == 64 && \
#if defined(CRT_HAS_TF_MODE) && HAS_80_BIT_LONG_DOUBLE

(defined(__x86_64__) || defined(__i386__))
#define SRC_80
#define DST_QUAD
#include "fp_extend_impl.inc"
Expand Down
3 changes: 2 additions & 1 deletion compiler-rt/lib/builtins/trunctfxf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#define QUAD_PRECISION
#include "fp_lib.h"

#if defined(CRT_HAS_TF_MODE) && __LDBL_MANT_DIG__ == 64 && defined(__x86_64__)
#if defined(CRT_HAS_TF_MODE) && __LDBL_MANT_DIG__ == 64 && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise

(defined(__x86_64__) || defined(__i386__))
Comment on lines +15 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if defined(CRT_HAS_TF_MODE) && __LDBL_MANT_DIG__ == 64 && \
(defined(__x86_64__) || defined(__i386__))
#if defined(CRT_HAS_TF_MODE) && HAS_80_BIT_LONG_DOUBLE

As above


#define SRC_QUAD
#define DST_80
Expand Down
6 changes: 3 additions & 3 deletions compiler-rt/test/builtins/Unit/extendxftf2_test.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// RUN: %clang_builtins %s %librt -fforce-enable-int128 -o %t && %run %t
// REQUIRES: librt_has_extendxftf2

#include "int_lib.h"
#include <stdio.h>

#if __LDBL_MANT_DIG__ == 64 && defined(__x86_64__) && \
#if __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))

Comment on lines +7 to 8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))
#if defined(CRT_HAS_TF_MODE) && HAS_80_BIT_LONG_DOUBLE

Since we include int_lib.h should be possible to simplify this

#include "fp_test.h"
Expand All @@ -28,7 +28,7 @@ char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
#endif

int main() {
#if __LDBL_MANT_DIG__ == 64 && defined(__x86_64__) && \
#if __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))
// qNaN
Comment on lines +31 to 32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))
#if defined(CRT_HAS_TF_MODE) && HAS_80_BIT_LONG_DOUBLE

Since we include int_lib.h should be possible to simplify this

if (test__extendxftf2(makeQNaN80(), UINT64_C(0x7fff800000000000),
Expand Down
6 changes: 3 additions & 3 deletions compiler-rt/test/builtins/Unit/trunctfxf2_test.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// RUN: %clang_builtins %s %librt -fforce-enable-int128 -o %t && %run %t
// REQUIRES: librt_has_trunctfxf2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will adding this flag unconditionally break other/older compilers? Maybe this needs to be a lit substitution?


#include "int_lib.h"
#include <stdio.h>

#if __LDBL_MANT_DIG__ == 64 && defined(__x86_64__) && \
#if __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))

Comment on lines +7 to 8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))
#if defined(CRT_HAS_TF_MODE) && HAS_80_BIT_LONG_DOUBLE

Since we include int_lib.h should be possible to simplify this

#include "fp_test.h"
Expand All @@ -28,7 +28,7 @@ char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
#endif

int main() {
#if __LDBL_MANT_DIG__ == 64 && defined(__x86_64__) && \
#if __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))
// qNaN
Comment on lines +31 to 32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))
#if defined(CRT_HAS_TF_MODE) && HAS_80_BIT_LONG_DOUBLE

Since we include int_lib.h should be possible to simplify this

if (test__trunctfxf2(makeQNaN128(), UINT64_C(0x7FFF),
Expand Down
Loading