-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[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
base: main
Are you sure you want to change the base?
[builtins] Support building the 128-bit float functions on i386 #122658
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
b1dd80a
to
0fa2736
Compare
You can test this locally with the following command:git-clang-format --diff 211bcf67aadb1175af382f55403ae759177281c7 fe61e4aeae112ec6a1ed1d3d2bd0537a582eea9f --extensions c -- compiler-rt/lib/builtins/extendxftf2.c compiler-rt/lib/builtins/trunctfxf2.c compiler-rt/test/builtins/Unit/extendxftf2_test.c compiler-rt/test/builtins/Unit/trunctfxf2_test.c View the diff from clang-format here.diff --git a/compiler-rt/test/builtins/Unit/extendxftf2_test.c b/compiler-rt/test/builtins/Unit/extendxftf2_test.c
index e82dd67404..d5bec2b463 100644
--- a/compiler-rt/test/builtins/Unit/extendxftf2_test.c
+++ b/compiler-rt/test/builtins/Unit/extendxftf2_test.c
@@ -7,7 +7,7 @@
#if __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))
-#include "fp_test.h"
+# include "fp_test.h"
COMPILER_RT_ABI tf_float __extendxftf2(long double a);
diff --git a/compiler-rt/test/builtins/Unit/trunctfxf2_test.c b/compiler-rt/test/builtins/Unit/trunctfxf2_test.c
index ea88732aa7..bd195d64c4 100644
--- a/compiler-rt/test/builtins/Unit/trunctfxf2_test.c
+++ b/compiler-rt/test/builtins/Unit/trunctfxf2_test.c
@@ -7,7 +7,7 @@
#if __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))
-#include "fp_test.h"
+# include "fp_test.h"
COMPILER_RT_ABI long double __trunctfxf2(tf_float a);
|
@@ -12,7 +12,7 @@ | |||
#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 && (defined(__x86_64__) || defined(__i386__)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enable __i386__
in extendxftf2_test.c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, enabled.
@@ -12,7 +12,7 @@ | |||
#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 && (defined(__x86_64__) || defined(__i386__)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enable i386 in trunctfxf2_test.c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, enabled.
627acf7
to
26f0383
Compare
GCC provides these functions (e.g.__subtf3) in libgcc on i386. Since Clang supports float128, we can also enable the existing code in i386 for ABI compatible.
26f0383
to
fe61e4a
Compare
@tru Take a look, the code_formatter suggestion is weird. |
@@ -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 && \ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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__)) && \ |
#if defined(CRT_HAS_TF_MODE) && __LDBL_MANT_DIG__ == 64 && \ | |
#if defined(CRT_HAS_TF_MODE) && HAS_80_BIT_LONG_DOUBLE |
@@ -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 && \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks this mostly looks good just a few suggestions
@@ -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) |
There was a problem hiding this comment.
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?
@@ -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 && \ |
There was a problem hiding this comment.
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__)) && \ |
#if defined(CRT_HAS_TF_MODE) && __LDBL_MANT_DIG__ == 64 && \ | |
#if defined(CRT_HAS_TF_MODE) && HAS_80_BIT_LONG_DOUBLE |
#if defined(CRT_HAS_TF_MODE) && __LDBL_MANT_DIG__ == 64 && \ | ||
(defined(__x86_64__) || defined(__i386__)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#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
#if __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \ | ||
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#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 __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \ | ||
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#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 __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \ | ||
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#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 __LDBL_MANT_DIG__ == 64 && (defined(__x86_64__) || defined(__i386__)) && \ | ||
(defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#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
@@ -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 |
There was a problem hiding this comment.
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?
GCC provides these functions (e.g.__subtf3) in libgcc on i386.
Since Clang supports float128, we can also enable the existing code in i386 for ABI compatible.
#121757