On Fri, Jan 07, 2022 at 12:29:25PM +0100, Jakub Jelinek wrote:
> we don't do it consistently:
> readelf -Wr 
> /home/jakub/gcc/obj38/powerpc64le-unknown-linux-gnu/libgfortran/.libs/libgfortran.so.5.0.0
>  | grep ieee128
> 0000000000250310  0000012800000015 R_PPC64_JMP_SLOT       0000000000000000 
> __atan2ieee128 + 0
> 0000000000250340  0000014200000015 R_PPC64_JMP_SLOT       0000000000000000 
> __clogieee128 + 0
> 0000000000250438  000001a300000015 R_PPC64_JMP_SLOT       0000000000000000 
> __acoshieee128 + 0
> 00000000002504b8  000001cc00000015 R_PPC64_JMP_SLOT       0000000000000000 
> __csinieee128 + 0
> 0000000000250500  000001f300000015 R_PPC64_JMP_SLOT       0000000000000000 
> __sinhieee128 + 0
> 0000000000250570  0000022a00000015 R_PPC64_JMP_SLOT       0000000000000000 
> __asinieee128 + 0
> 0000000000250580  0000022d00000015 R_PPC64_JMP_SLOT       0000000000000000 
> __roundieee128 + 0
> 00000000002505a0  0000023e00000015 R_PPC64_JMP_SLOT       0000000000000000 
> __logieee128 + 0
> 00000000002505c8  0000024900000015 R_PPC64_JMP_SLOT       0000000000000000 
> __tanieee128 + 0
> 0000000000250630  0000027500000015 R_PPC64_JMP_SLOT       0000000000000000 
> __ccosieee128 + 0
> 0000000000250670  0000028a00000015 R_PPC64_JMP_SLOT       0000000000000000 
> __log10ieee128 + 0
> 00000000002506c8  000002bd00000015 R_PPC64_JMP_SLOT       0000000000000000 
> __cexpieee128 + 0
> 00000000002506d8  000002c800000015 R_PPC64_JMP_SLOT       0000000000000000 
> __coshieee128 + 0
> 00000000002509b0  000003ef00000015 R_PPC64_JMP_SLOT       0000000000000000 
> __truncieee128 + 0
> 0000000000250af8  000004a600000015 R_PPC64_JMP_SLOT       0000000000000000 
> __expieee128 + 0
> 0000000000250b50  000004c600000015 R_PPC64_JMP_SLOT       0000000000000000 
> __fmodieee128 + 0
> 0000000000250bb0  000004e700000015 R_PPC64_JMP_SLOT       0000000000000000 
> __tanhieee128 + 0
> 0000000000250c38  0000051300000015 R_PPC64_JMP_SLOT       0000000000000000 
> __acosieee128 + 0
> 0000000000250ce0  0000055400000015 R_PPC64_JMP_SLOT       0000000000000000 
> __sinieee128 + 0
> 0000000000250d60  0000057e00000015 R_PPC64_JMP_SLOT       0000000000000000 
> __atanieee128 + 0
> 0000000000250dd8  000005b100000015 R_PPC64_JMP_SLOT       0000000000000000 
> __sqrtieee128 + 0
> 0000000000250e98  0000060200000015 R_PPC64_JMP_SLOT       0000000000000000 
> __cosieee128 + 0
> 0000000000250eb0  0000060a00000015 R_PPC64_JMP_SLOT       0000000000000000 
> __atanhieee128 + 0
> 0000000000250ef0  0000062000000015 R_PPC64_JMP_SLOT       0000000000000000 
> __asinhieee128 + 0
> 0000000000250fd8  0000067f00000015 R_PPC64_JMP_SLOT       0000000000000000 
> __csqrtieee128 + 0
> 0000000000251038  000006ad00000015 R_PPC64_JMP_SLOT       0000000000000000 
> __cabsieee128 + 0
> All these should for POWER_IEEE128 use atan2q@QUADMATH_1.0 etc.

So, seems all these come from f951 compiled sources.
For user code, I think the agreement was if you want to use successfully
-mabi=ieeelongdouble, you need glibc 2.32 or later, which is why the Fortran
FE doesn't conditionalize on whether glibc 2.32 is available or not and just
emits __WHATEVERieee128 entrypoints.
But for Fortran compiled sources in libgfortran, we need to use
__WHATEVERieee128 only if glibc 2.32 or later and WHATEVERq (from
libquadmath) otherwise.
I guess easiest would be to do this always in the FE, but we need to
determine in the FE if the target is glibc 2.32 or later.

> On the other side, on glibc 2.32+ build, we still use some libquadmath APIs
> when we shouldn't:
> readelf -Wr 
> /home/jakub/gcc/obj/powerpc64le-unknown-linux-gnu/libgfortran/.libs/libgfortran.so.5
>  | grep QUADMATH
> 00000000002502c8  0000002600000015 R_PPC64_JMP_SLOT       0000000000000000 
> fmaq@QUADMATH_1.0 + 0
> 00000000002505f8  0000006700000015 R_PPC64_JMP_SLOT       0000000000000000 
> tanq@QUADMATH_1.0 + 0
> 0000000000250930  0000009b00000015 R_PPC64_JMP_SLOT       0000000000000000 
> fabsq@QUADMATH_1.0 + 0
> 0000000000250940  0000009d00000015 R_PPC64_JMP_SLOT       0000000000000000 
> sinq@QUADMATH_1.0 + 0
> 0000000000250c98  000000cf00000015 R_PPC64_JMP_SLOT       0000000000000000 
> copysignq@QUADMATH_1.0 + 0
> 0000000000251038  0000010700000015 R_PPC64_JMP_SLOT       0000000000000000 
> cosq@QUADMATH_1.0 + 0
> 0000000000251068  0000010a00000015 R_PPC64_JMP_SLOT       0000000000000000 
> fmodq@QUADMATH_1.0 + 0
> These should use __fmaieee128, __tanieee128 etc. instead.

This one seems easily fixed by the following patch, ok for power-ieee128?

2022-01-07  Jakub Jelinek  <ja...@redhat.com>

        * libgfortran.h (__copysignieee128, __fmaieee128, __fmodieee128):
        Declare.
        * intrinsics/trigd.c (COPYSIGN, FMOD, FABS, FMA, SIN, COS, TAN): If
        POWER_IEEE128 is defined, define these for kind 17 include.
        * intrinsics/trigd_lib.inc (COPYSIGN, FMOD, FABS, FMA, SIN, COS, TAN):
        Don't define if COPYSIGN is already defined.

--- libgfortran/libgfortran.h.jj        2022-01-07 09:39:10.222157644 +0000
+++ libgfortran/libgfortran.h   2022-01-07 12:58:57.604483761 +0000
@@ -1956,6 +1956,8 @@ extern __float128 __atanhieee128 (__floa
   __attribute__ ((__nothrow__, __leaf__));
 extern __float128 __atanieee128 (__float128)
   __attribute__ ((__nothrow__, __leaf__));
+extern __float128 __copysignieee128 (__float128, __float128)
+  __attribute__ ((__nothrow__, __leaf__));
 extern __float128 __coshieee128 (__float128)
   __attribute__ ((__nothrow__, __leaf__));
 extern __float128 __cosieee128 (__float128)
@@ -1968,6 +1970,10 @@ extern __float128 __expieee128 (__float1
   __attribute__ ((__nothrow__, __leaf__));
 extern __float128 __fabsieee128 (__float128)
   __attribute__ ((__nothrow__, __leaf__));
+extern __float128 __fmaieee128 (__float128, __float128, __float128)
+  __attribute__ ((__nothrow__, __leaf__));
+extern __float128 __fmodieee128 (__float128, __float128)
+  __attribute__ ((__nothrow__, __leaf__));
 extern __float128 __jnieee128 (int, __float128)
   __attribute__ ((__nothrow__, __leaf__));
 extern __float128 __log10ieee128 (__float128)
--- libgfortran/intrinsics/trigd.c.jj   2022-01-07 09:39:10.222157644 +0000
+++ libgfortran/intrinsics/trigd.c      2022-01-07 12:57:01.311939084 +0000
@@ -313,6 +313,16 @@ see the files COPYING3 and COPYING.RUNTI
 #define HAVE_INFINITY_KIND
 #endif
 
+#ifdef POWER_IEEE128
+#define COPYSIGN __copysignieee128
+#define FMOD __fmodieee128
+#define FABS __fabsieee128
+#define FMA __fmaieee128
+#define SIN __sinieee128
+#define COS __cosieee128
+#define TAN __tanieee128
+#endif
+
 #include "trigd_lib.inc"
 
 #undef KIND
--- libgfortran/intrinsics/trigd_lib.inc.jj     2021-12-31 11:00:58.083137032 
+0000
+++ libgfortran/intrinsics/trigd_lib.inc        2022-01-07 12:56:25.491155265 
+0000
@@ -65,6 +65,7 @@ PIO180L               -- lower bits of p
 #define CONCAT(x,y) x ## y
 #define CONCAT_EXPAND(x,y) CONCAT(x,y)
 
+#ifndef COPYSIGN
 #define COPYSIGN LITERAL(copysign)
 #define FMOD LITERAL(fmod)
 #define FABS LITERAL(fabs)
@@ -72,6 +73,7 @@ PIO180L               -- lower bits of p
 #define SIN LITERAL(sin)
 #define COS LITERAL(cos)
 #define TAN LITERAL(tan)
+#endif
 
 #ifdef TINY
 #define TINY_LITERAL LITERAL(TINY)


        Jakub

Reply via email to