[compiler-rt] e3374c8 - [builtins] Avoid using CRT_LDBL_128BIT in implementation. NFC

Alex Richardson via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 17:20:21 PDT 2023


Author: Alex Richardson
Date: 2023-07-24T17:19:11-07:00
New Revision: e3374c8c31fb54a2c8df6c906884e14f1c8a2209

URL: https://github.com/llvm/llvm-project/commit/e3374c8c31fb54a2c8df6c906884e14f1c8a2209
DIFF: https://github.com/llvm/llvm-project/commit/e3374c8c31fb54a2c8df6c906884e14f1c8a2209.diff

LOG: [builtins] Avoid using CRT_LDBL_128BIT in implementation. NFC

Currently the *tf builtin functions can only be built if long double is an
IEEE float, which prevents them from being available e.g. for x86 targets
(unlike libgcc which has them). This non-functional change prepares the
builtins library *tf functions for being able to target x86 by decoupling
their presence from CRT_LDBL_128BIT and instead checking for a
CRT_HAS_TF_MODE macro. This change is NFC since the CRT_HAS_TF_MODE is
currently only set if long double is an IEEE 128-bit float.

Reviewed By: compnerd

Differential Revision: https://reviews.llvm.org/D153812

Added: 
    

Modified: 
    compiler-rt/lib/builtins/addtf3.c
    compiler-rt/lib/builtins/comparetf2.c
    compiler-rt/lib/builtins/divtf3.c
    compiler-rt/lib/builtins/extenddftf2.c
    compiler-rt/lib/builtins/extendhftf2.c
    compiler-rt/lib/builtins/extendsftf2.c
    compiler-rt/lib/builtins/fixtfdi.c
    compiler-rt/lib/builtins/fixtfsi.c
    compiler-rt/lib/builtins/fixtfti.c
    compiler-rt/lib/builtins/fixunstfdi.c
    compiler-rt/lib/builtins/fixunstfsi.c
    compiler-rt/lib/builtins/fixunstfti.c
    compiler-rt/lib/builtins/floatditf.c
    compiler-rt/lib/builtins/floatsitf.c
    compiler-rt/lib/builtins/floattitf.c
    compiler-rt/lib/builtins/floatunditf.c
    compiler-rt/lib/builtins/floatunsitf.c
    compiler-rt/lib/builtins/floatuntitf.c
    compiler-rt/lib/builtins/fp_lib.h
    compiler-rt/lib/builtins/multf3.c
    compiler-rt/lib/builtins/powitf2.c
    compiler-rt/lib/builtins/subtf3.c
    compiler-rt/lib/builtins/trunctfdf2.c
    compiler-rt/lib/builtins/trunctfhf2.c
    compiler-rt/lib/builtins/trunctfsf2.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/builtins/addtf3.c b/compiler-rt/lib/builtins/addtf3.c
index 86e4f4cfc3fc63..2cb3a4d5919175 100644
--- a/compiler-rt/lib/builtins/addtf3.c
+++ b/compiler-rt/lib/builtins/addtf3.c
@@ -13,7 +13,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 #include "fp_add_impl.inc"
 
 COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b) {

diff  --git a/compiler-rt/lib/builtins/comparetf2.c b/compiler-rt/lib/builtins/comparetf2.c
index f1592454138cd1..be5e9e5e44dd2d 100644
--- a/compiler-rt/lib/builtins/comparetf2.c
+++ b/compiler-rt/lib/builtins/comparetf2.c
@@ -39,7 +39,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 #include "fp_compare_impl.inc"
 
 COMPILER_RT_ABI CMP_RESULT __letf2(fp_t a, fp_t b) { return __leXf2__(a, b); }

diff  --git a/compiler-rt/lib/builtins/divtf3.c b/compiler-rt/lib/builtins/divtf3.c
index 5bcc9a8e4aa184..bd76763b07d3a4 100644
--- a/compiler-rt/lib/builtins/divtf3.c
+++ b/compiler-rt/lib/builtins/divtf3.c
@@ -14,7 +14,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 
 #define NUMBER_OF_HALF_ITERATIONS 4
 #define NUMBER_OF_FULL_ITERATIONS 1

diff  --git a/compiler-rt/lib/builtins/extenddftf2.c b/compiler-rt/lib/builtins/extenddftf2.c
index ddf470ecd6293f..835076be1f2080 100644
--- a/compiler-rt/lib/builtins/extenddftf2.c
+++ b/compiler-rt/lib/builtins/extenddftf2.c
@@ -9,7 +9,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 #define SRC_DOUBLE
 #define DST_QUAD
 #include "fp_extend_impl.inc"

diff  --git a/compiler-rt/lib/builtins/extendhftf2.c b/compiler-rt/lib/builtins/extendhftf2.c
index aefe9737d34f93..a2cb0f771ee9aa 100644
--- a/compiler-rt/lib/builtins/extendhftf2.c
+++ b/compiler-rt/lib/builtins/extendhftf2.c
@@ -10,8 +10,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) &&                     \
-    defined(COMPILER_RT_HAS_FLOAT16)
+#if defined(CRT_HAS_TF_MODE) && defined(COMPILER_RT_HAS_FLOAT16)
 #define SRC_HALF
 #define DST_QUAD
 #include "fp_extend_impl.inc"

diff  --git a/compiler-rt/lib/builtins/extendsftf2.c b/compiler-rt/lib/builtins/extendsftf2.c
index cf1fd2face20ab..0739859bcbc18f 100644
--- a/compiler-rt/lib/builtins/extendsftf2.c
+++ b/compiler-rt/lib/builtins/extendsftf2.c
@@ -9,7 +9,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 #define SRC_SINGLE
 #define DST_QUAD
 #include "fp_extend_impl.inc"

diff  --git a/compiler-rt/lib/builtins/fixtfdi.c b/compiler-rt/lib/builtins/fixtfdi.c
index fe570e6b375559..d27a99b6f364ee 100644
--- a/compiler-rt/lib/builtins/fixtfdi.c
+++ b/compiler-rt/lib/builtins/fixtfdi.c
@@ -9,7 +9,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 typedef di_int fixint_t;
 typedef du_int fixuint_t;
 #include "fp_fixint_impl.inc"

diff  --git a/compiler-rt/lib/builtins/fixtfsi.c b/compiler-rt/lib/builtins/fixtfsi.c
index a32bd964caa3b8..01e352acc592d3 100644
--- a/compiler-rt/lib/builtins/fixtfsi.c
+++ b/compiler-rt/lib/builtins/fixtfsi.c
@@ -9,7 +9,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 typedef si_int fixint_t;
 typedef su_int fixuint_t;
 #include "fp_fixint_impl.inc"

diff  --git a/compiler-rt/lib/builtins/fixtfti.c b/compiler-rt/lib/builtins/fixtfti.c
index 19f84ce3890740..491fca502113df 100644
--- a/compiler-rt/lib/builtins/fixtfti.c
+++ b/compiler-rt/lib/builtins/fixtfti.c
@@ -9,7 +9,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 typedef ti_int fixint_t;
 typedef tu_int fixuint_t;
 #include "fp_fixint_impl.inc"

diff  --git a/compiler-rt/lib/builtins/fixunstfdi.c b/compiler-rt/lib/builtins/fixunstfdi.c
index a0805e63db8205..febdb8f5682fa9 100644
--- a/compiler-rt/lib/builtins/fixunstfdi.c
+++ b/compiler-rt/lib/builtins/fixunstfdi.c
@@ -9,7 +9,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 typedef du_int fixuint_t;
 #include "fp_fixuint_impl.inc"
 

diff  --git a/compiler-rt/lib/builtins/fixunstfsi.c b/compiler-rt/lib/builtins/fixunstfsi.c
index 3a1320ed3e0a26..4efc387df453da 100644
--- a/compiler-rt/lib/builtins/fixunstfsi.c
+++ b/compiler-rt/lib/builtins/fixunstfsi.c
@@ -9,7 +9,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 typedef su_int fixuint_t;
 #include "fp_fixuint_impl.inc"
 

diff  --git a/compiler-rt/lib/builtins/fixunstfti.c b/compiler-rt/lib/builtins/fixunstfti.c
index 23cd1ab615a709..fa9e7aa07108b8 100644
--- a/compiler-rt/lib/builtins/fixunstfti.c
+++ b/compiler-rt/lib/builtins/fixunstfti.c
@@ -9,7 +9,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 typedef tu_int fixuint_t;
 #include "fp_fixuint_impl.inc"
 

diff  --git a/compiler-rt/lib/builtins/floatditf.c b/compiler-rt/lib/builtins/floatditf.c
index 9b07b65825b888..c6e326a1923a6d 100644
--- a/compiler-rt/lib/builtins/floatditf.c
+++ b/compiler-rt/lib/builtins/floatditf.c
@@ -15,7 +15,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 COMPILER_RT_ABI fp_t __floatditf(di_int a) {
 
   const int aWidth = sizeof a * CHAR_BIT;

diff  --git a/compiler-rt/lib/builtins/floatsitf.c b/compiler-rt/lib/builtins/floatsitf.c
index 80a4ef08fb0ed1..4d5b52f4ed9199 100644
--- a/compiler-rt/lib/builtins/floatsitf.c
+++ b/compiler-rt/lib/builtins/floatsitf.c
@@ -15,7 +15,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 COMPILER_RT_ABI fp_t __floatsitf(si_int a) {
 
   const int aWidth = sizeof a * CHAR_BIT;

diff  --git a/compiler-rt/lib/builtins/floattitf.c b/compiler-rt/lib/builtins/floattitf.c
index 8e273734593397..fff0755c3bb46a 100644
--- a/compiler-rt/lib/builtins/floattitf.c
+++ b/compiler-rt/lib/builtins/floattitf.c
@@ -25,7 +25,7 @@
 // mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm
 // mmmm mmmm mmmm
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 COMPILER_RT_ABI fp_t __floattitf(ti_int a) {
   if (a == 0)
     return 0.0;

diff  --git a/compiler-rt/lib/builtins/floatunditf.c b/compiler-rt/lib/builtins/floatunditf.c
index 8d310851e179c6..abe0ca9ed8c503 100644
--- a/compiler-rt/lib/builtins/floatunditf.c
+++ b/compiler-rt/lib/builtins/floatunditf.c
@@ -15,7 +15,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 COMPILER_RT_ABI fp_t __floatunditf(du_int a) {
 
   const int aWidth = sizeof a * CHAR_BIT;

diff  --git a/compiler-rt/lib/builtins/floatunsitf.c b/compiler-rt/lib/builtins/floatunsitf.c
index 7ba1fb6000dcc1..3f0a5249fddd36 100644
--- a/compiler-rt/lib/builtins/floatunsitf.c
+++ b/compiler-rt/lib/builtins/floatunsitf.c
@@ -15,7 +15,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 COMPILER_RT_ABI fp_t __floatunsitf(su_int a) {
 
   const int aWidth = sizeof a * CHAR_BIT;

diff  --git a/compiler-rt/lib/builtins/floatuntitf.c b/compiler-rt/lib/builtins/floatuntitf.c
index a8b3b4835bbcaa..33a81b34eeb195 100644
--- a/compiler-rt/lib/builtins/floatuntitf.c
+++ b/compiler-rt/lib/builtins/floatuntitf.c
@@ -25,7 +25,7 @@
 // mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm
 // mmmm mmmm mmmm
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 COMPILER_RT_ABI fp_t __floatuntitf(tu_int a) {
   if (a == 0)
     return 0.0;

diff  --git a/compiler-rt/lib/builtins/fp_lib.h b/compiler-rt/lib/builtins/fp_lib.h
index 0e7e93cb319004..58eb45fcc72929 100644
--- a/compiler-rt/lib/builtins/fp_lib.h
+++ b/compiler-rt/lib/builtins/fp_lib.h
@@ -106,7 +106,12 @@ COMPILER_RT_ABI fp_t __adddf3(fp_t a, fp_t b);
 
 #elif defined QUAD_PRECISION
 #if __LDBL_MANT_DIG__ == 113 && defined(__SIZEOF_INT128__)
+// TODO: Availability of the *tf functions should not depend on long double
+// being IEEE 128, but instead on being able to use a 128-bit floating-point
+// type, which includes __float128.
+// Right now this (incorrectly) stops the builtins from being used for x86.
 #define CRT_LDBL_128BIT
+#define CRT_HAS_TF_MODE
 #define TF_C(c) c##L
 typedef uint64_t half_rep_t;
 typedef __uint128_t rep_t;

diff  --git a/compiler-rt/lib/builtins/multf3.c b/compiler-rt/lib/builtins/multf3.c
index 0626fb8c7fc9cd..8fd73688712cbd 100644
--- a/compiler-rt/lib/builtins/multf3.c
+++ b/compiler-rt/lib/builtins/multf3.c
@@ -14,7 +14,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 #include "fp_mul_impl.inc"
 
 COMPILER_RT_ABI fp_t __multf3(fp_t a, fp_t b) { return __mulXf3__(a, b); }

diff  --git a/compiler-rt/lib/builtins/powitf2.c b/compiler-rt/lib/builtins/powitf2.c
index 8e639a03a3c4b1..74fe707a4e8c40 100644
--- a/compiler-rt/lib/builtins/powitf2.c
+++ b/compiler-rt/lib/builtins/powitf2.c
@@ -13,7 +13,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 
 // Returns: a ^ b
 

diff  --git a/compiler-rt/lib/builtins/subtf3.c b/compiler-rt/lib/builtins/subtf3.c
index 3364c28f817927..e1b1022034bf79 100644
--- a/compiler-rt/lib/builtins/subtf3.c
+++ b/compiler-rt/lib/builtins/subtf3.c
@@ -13,7 +13,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b);
 
 // Subtraction; flip the sign bit of b and add.

diff  --git a/compiler-rt/lib/builtins/trunctfdf2.c b/compiler-rt/lib/builtins/trunctfdf2.c
index 6857ea54d8a57c..f0d2e4141f3b04 100644
--- a/compiler-rt/lib/builtins/trunctfdf2.c
+++ b/compiler-rt/lib/builtins/trunctfdf2.c
@@ -9,7 +9,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 #define SRC_QUAD
 #define DST_DOUBLE
 #include "fp_trunc_impl.inc"

diff  --git a/compiler-rt/lib/builtins/trunctfhf2.c b/compiler-rt/lib/builtins/trunctfhf2.c
index e3a2309d954bcf..f7776327251c79 100644
--- a/compiler-rt/lib/builtins/trunctfhf2.c
+++ b/compiler-rt/lib/builtins/trunctfhf2.c
@@ -10,8 +10,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) &&                     \
-    defined(COMPILER_RT_HAS_FLOAT16)
+#if defined(CRT_HAS_TF_MODE) && defined(COMPILER_RT_HAS_FLOAT16)
 #define SRC_QUAD
 #define DST_HALF
 #include "fp_trunc_impl.inc"

diff  --git a/compiler-rt/lib/builtins/trunctfsf2.c b/compiler-rt/lib/builtins/trunctfsf2.c
index 0261b1e90f5daf..242735f738c137 100644
--- a/compiler-rt/lib/builtins/trunctfsf2.c
+++ b/compiler-rt/lib/builtins/trunctfsf2.c
@@ -9,7 +9,7 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_TF_MODE)
 #define SRC_QUAD
 #define DST_SINGLE
 #include "fp_trunc_impl.inc"


        


More information about the llvm-commits mailing list