[lld] [clang-tools-extra] [compiler-rt] [libcxxabi] [flang] [libunwind] [lldb] [libclc] [llvm] [clang] [libc] [libcxx] [builtins] Generate __multc3 for z/OS (PR #77554)

Sean Perry via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 10 14:09:58 PST 2024


https://github.com/perry-ca updated https://github.com/llvm/llvm-project/pull/77554

>From 7ba4d61bd2beda03ba0fcefc9ca5c1ff08ffd48e Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Tue, 9 Jan 2024 20:59:28 -0600
Subject: [PATCH 1/3] Generate __multc3 for z/OS

---
 compiler-rt/lib/builtins/divtc3.c    | 3 ---
 compiler-rt/lib/builtins/fp_lib.h    | 8 ++++++--
 compiler-rt/lib/builtins/int_types.h | 6 ++++--
 compiler-rt/lib/builtins/multc3.c    | 4 ----
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/compiler-rt/lib/builtins/divtc3.c b/compiler-rt/lib/builtins/divtc3.c
index e970cef574b21d..6ec9c5f17d4b68 100644
--- a/compiler-rt/lib/builtins/divtc3.c
+++ b/compiler-rt/lib/builtins/divtc3.c
@@ -13,7 +13,6 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_TF_MODE)
 
 // Returns: the quotient of (a + ib) / (c + id)
 
@@ -52,5 +51,3 @@ COMPILER_RT_ABI Qcomplex __divtc3(fp_t __a, fp_t __b, fp_t __c, fp_t __d) {
   }
   return z;
 }
-
-#endif
diff --git a/compiler-rt/lib/builtins/fp_lib.h b/compiler-rt/lib/builtins/fp_lib.h
index af406e760497a4..a293788fc68f56 100644
--- a/compiler-rt/lib/builtins/fp_lib.h
+++ b/compiler-rt/lib/builtins/fp_lib.h
@@ -188,6 +188,8 @@ static __inline void wideMultiply(rep_t a, rep_t b, rep_t *hi, rep_t *lo) {
 #undef Word_HiMask
 #undef Word_LoMask
 #undef Word_FullMask
+#else
+typedef long double fp_t;
 #endif // defined(CRT_HAS_TF_MODE)
 #else
 #error SINGLE_PRECISION, DOUBLE_PRECISION or QUAD_PRECISION must be defined.
@@ -374,10 +376,10 @@ static __inline fp_t __compiler_rt_fmax(fp_t x, fp_t y) {
 #endif
 }
 
-#elif defined(QUAD_PRECISION) && defined(CRT_HAS_TF_MODE)
+#elif defined(QUAD_PRECISION)
 // The generic implementation only works for ieee754 floating point. For other
 // floating point types, continue to rely on the libm implementation for now.
-#if defined(CRT_HAS_IEEE_TF)
+#if defined(CRT_HAS_TF_MODE) && defined(CRT_HAS_IEEE_TF)
 static __inline tf_float __compiler_rt_logbtf(tf_float x) {
   return __compiler_rt_logbX(x);
 }
@@ -405,6 +407,8 @@ static __inline tf_float __compiler_rt_fmaxtf(tf_float x, tf_float y) {
 #define __compiler_rt_logbl crt_logbl
 #define __compiler_rt_scalbnl crt_scalbnl
 #define __compiler_rt_fmaxl crt_fmaxl
+#define crt_fabstf crt_fabsl
+#define crt_copysigntf crt_copysignl
 #else
 #error Unsupported TF mode type
 #endif
diff --git a/compiler-rt/lib/builtins/int_types.h b/compiler-rt/lib/builtins/int_types.h
index 7624c728061518..ebbc63af598b76 100644
--- a/compiler-rt/lib/builtins/int_types.h
+++ b/compiler-rt/lib/builtins/int_types.h
@@ -189,8 +189,10 @@ typedef long double tf_float;
 #define CRT_LDBL_IEEE_F128
 #endif
 #define TF_C(x) x##L
-#elif __LDBL_MANT_DIG__ == 113
-// Use long double instead of __float128 if it matches the IEEE 128-bit format.
+#elif __LDBL_MANT_DIG__ == 113 ||                                              \
+    (__FLT_RADIX__ == 16 && __LDBL_MANT_DIG__ == 28)
+// Use long double instead of __float128 if it matches the IEEE 128-bit format
+// or the IBM hexadecimal format.
 #define CRT_LDBL_128BIT
 #define CRT_HAS_F128
 #define CRT_HAS_IEEE_TF
diff --git a/compiler-rt/lib/builtins/multc3.c b/compiler-rt/lib/builtins/multc3.c
index f20e53ccbf233b..21c522d0330b7f 100644
--- a/compiler-rt/lib/builtins/multc3.c
+++ b/compiler-rt/lib/builtins/multc3.c
@@ -15,8 +15,6 @@
 #include "int_lib.h"
 #include "int_math.h"
 
-#if defined(CRT_HAS_TF_MODE)
-
 // Returns: the product of a + ib and c + id
 
 COMPILER_RT_ABI Qcomplex __multc3(fp_t a, fp_t b, fp_t c, fp_t d) {
@@ -66,5 +64,3 @@ COMPILER_RT_ABI Qcomplex __multc3(fp_t a, fp_t b, fp_t c, fp_t d) {
   }
   return z;
 }
-
-#endif

>From 81b814ccc0b216eb9464c9fa5d4d28b0511c2338 Mon Sep 17 00:00:00 2001
From: Sean Perry <39927768+perry-ca at users.noreply.github.com>
Date: Tue, 9 Jan 2024 23:49:29 -0500
Subject: [PATCH 2/3] formatting update

---
 compiler-rt/lib/builtins/divtc3.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/compiler-rt/lib/builtins/divtc3.c b/compiler-rt/lib/builtins/divtc3.c
index 6ec9c5f17d4b68..7d3185c9d71fbb 100644
--- a/compiler-rt/lib/builtins/divtc3.c
+++ b/compiler-rt/lib/builtins/divtc3.c
@@ -13,7 +13,6 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-
 // Returns: the quotient of (a + ib) / (c + id)
 
 COMPILER_RT_ABI Qcomplex __divtc3(fp_t __a, fp_t __b, fp_t __c, fp_t __d) {

>From 2cb932ab37caf472aa296f5d7c811feada8464f0 Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Wed, 10 Jan 2024 16:03:48 -0600
Subject: [PATCH 3/3] only define CRT_HAS_F128 & CRT_HAS_IEEE_TF for IEEE

---
 compiler-rt/lib/builtins/int_types.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/compiler-rt/lib/builtins/int_types.h b/compiler-rt/lib/builtins/int_types.h
index ebbc63af598b76..9ceced37a997f4 100644
--- a/compiler-rt/lib/builtins/int_types.h
+++ b/compiler-rt/lib/builtins/int_types.h
@@ -194,8 +194,10 @@ typedef long double tf_float;
 // Use long double instead of __float128 if it matches the IEEE 128-bit format
 // or the IBM hexadecimal format.
 #define CRT_LDBL_128BIT
+#if __LDBL_MANT_DIG__ == 113
 #define CRT_HAS_F128
 #define CRT_HAS_IEEE_TF
+#endif
 #define CRT_LDBL_IEEE_F128
 typedef long double tf_float;
 #define TF_C(x) x##L



More information about the cfe-commits mailing list