public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Thomas Koenig <tkoenig@netcologne.de>
Cc: Michael Meissner <meissner@linux.ibm.com>,
	Segher Boessenkool <segher@kernel.crashing.org>,
	"fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
	Peter Bergner <bergner@linux.ibm.com>,
	gcc-patches@gcc.gnu.org, Bill Schmidt <wschmidt@linux.ibm.com>,
	David Edelsohn <dje.gcc@gmail.com>
Subject: Re: [power-ieee128] RFH: LTO broken
Date: Fri, 7 Jan 2022 17:46:14 +0100	[thread overview]
Message-ID: <20220107164614.GM2646553@tucnak> (raw)
In-Reply-To: <5aa645cf-89bf-a620-a107-9564b7aa8fc3@netcologne.de>

On Fri, Jan 07, 2022 at 03:25:57PM +0100, Thomas Koenig wrote:
> > > 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.
> 
> That was the idea, I think.
> 
> > 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.
> 
> Instead of determining this in the front end, maybe we can add
> an option (documented, but marked as useful as only for internal
> use and with no guarantee that it will remain) and use that option
> when compiling libgfortran.

We apparently have already TARGET_GLIBC_MAJOR and TARGET_GLIBC_MINOR target
macros, and e.g. libgcc or D testsuite uses internal options like
-fbuilding-libgcc.

So, the following patch adds -fbuilding-libgfortran option and uses
it together with TARGET_GLIBC_M* checks to decide whether to use
libquadmath APIs (for the IEEE quad kind=16 if -fbuilding-libgfortran
and not glibc or glibc is older than 2.32) or glibc 2.32 APIs
(otherwise).  This way, libgfortran uses solely the libquadmath APIs
on glibc < 2.32 and __*ieee128 APIs on glibc 2.32, while user code
always uses the latter.

Ok for power-ieee128?

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

gcc/fortran/
	* trans-types.c (gfc_init_kinds): When setting abi_kind to 17, if not
	targetting glibc 2.32 or later and -fbuilding-libgfortran, set
	gfc_real16_is_float128 and c_float128 in gfc_real_kinds.
	(gfc_build_real_type): Don't set c_long_double if c_float128 is
	already set.
	* trans-intrinsic.c (builtin_decl_for_precision): Don't use
	long_double_built_in if gfc_real16_is_float128 and
	long_double_type_node == gfc_float128_type_node.
	* lang.opt (fbuilding-libgfortran): New undocumented option.
libgfortran/
	* Makefile.am (AM_FCFLAGS): Add -fbuilding-libgfortran after
	-fallow-leading-underscore.
	* Makefile.in: Regenerated.

--- gcc/fortran/trans-types.c.jj	2022-01-04 10:27:56.498322942 +0000
+++ gcc/fortran/trans-types.c	2022-01-07 16:19:06.737066905 +0000
@@ -516,7 +516,16 @@ gfc_init_kinds (void)
     {
       for (int i = 0; i < r_index; ++i)
 	if (gfc_real_kinds[i].kind == 16)
-	  gfc_real_kinds[i].abi_kind = 17;
+	  {
+	    gfc_real_kinds[i].abi_kind = 17;
+	    if (flag_building_libgfortran
+		&& (TARGET_GLIBC_MAJOR < 2
+		    || (TARGET_GLIBC_MAJOR == 2 && TARGET_GLIBC_MINOR < 32)))
+	      {
+		gfc_real16_is_float128 = true;
+		gfc_real_kinds[i].c_float128 = 1;
+	      }
+	  }
     }
 
   /* Choose the default integer kind.  We choose 4 unless the user directs us
@@ -859,7 +868,7 @@ gfc_build_real_type (gfc_real_info *info
     info->c_float = 1;
   if (mode_precision == DOUBLE_TYPE_SIZE)
     info->c_double = 1;
-  if (mode_precision == LONG_DOUBLE_TYPE_SIZE)
+  if (mode_precision == LONG_DOUBLE_TYPE_SIZE && !info->c_float128)
     info->c_long_double = 1;
   if (mode_precision != LONG_DOUBLE_TYPE_SIZE && mode_precision == 128)
     {
--- gcc/fortran/trans-intrinsic.c.jj	2022-01-07 09:39:10.222157644 +0000
+++ gcc/fortran/trans-intrinsic.c	2022-01-07 13:57:35.451495059 +0000
@@ -154,7 +154,9 @@ builtin_decl_for_precision (enum built_i
     i = m->float_built_in;
   else if (precision == TYPE_PRECISION (double_type_node))
     i = m->double_built_in;
-  else if (precision == TYPE_PRECISION (long_double_type_node))
+  else if (precision == TYPE_PRECISION (long_double_type_node)
+	   && (!gfc_real16_is_float128
+	       || long_double_type_node != gfc_float128_type_node))
     i = m->long_double_built_in;
   else if (precision == TYPE_PRECISION (gfc_float128_type_node))
     {
--- gcc/fortran/lang.opt.jj	2021-12-31 11:00:15.042190365 +0000
+++ gcc/fortran/lang.opt	2022-01-07 16:18:17.685995005 +0000
@@ -413,6 +413,9 @@ fblas-matmul-limit=
 Fortran RejectNegative Joined UInteger Var(flag_blas_matmul_limit) Init(30)
 -fblas-matmul-limit=<n>	Size of the smallest matrix for which matmul will use BLAS.
 
+fbuilding-libgfortran
+Fortran Undocumented Var(flag_building_libgfortran)
+
 fcheck-array-temporaries
 Fortran
 Produce a warning at runtime if a array temporary has been created for a procedure argument.
--- libgfortran/Makefile.am.jj	2022-01-04 10:27:56.498322942 +0000
+++ libgfortran/Makefile.am	2022-01-07 16:23:20.052602554 +0000
@@ -1079,8 +1079,8 @@ endif
 $(patsubst %.c,%.lo,$(notdir $(i_matmull_c))): AM_CFLAGS += -funroll-loops
 
 # Add the -fallow-leading-underscore option when needed
-$(patsubst %.F90,%.lo,$(patsubst %.f90,%.lo,$(notdir $(gfor_specific_src)))): AM_FCFLAGS += -fallow-leading-underscore
-selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-underscore
+$(patsubst %.F90,%.lo,$(patsubst %.f90,%.lo,$(notdir $(gfor_specific_src)))): AM_FCFLAGS += -fallow-leading-underscore -fbuilding-libgfortran
+selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-underscore -fbuilding-libgfortran
 
 # Build *_r17.F90 and *_c17.F90 with additional -mabi=ieeelongdouble on powerpc64le-linux.
 
@@ -1097,7 +1097,7 @@ endif
 
 if IEEE_SUPPORT
 # Add flags for IEEE modules
-$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore
+$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore -fbuilding-libgfortran
 endif
 
 # Dependencies between IEEE_ARITHMETIC and IEEE_EXCEPTIONS
--- libgfortran/Makefile.in.jj	2022-01-04 10:27:56.508323161 +0000
+++ libgfortran/Makefile.in	2022-01-07 16:23:50.853275633 +0000
@@ -7633,8 +7633,8 @@ $(patsubst %.c,%.lo,$(notdir $(i_matmul_
 $(patsubst %.c,%.lo,$(notdir $(i_matmull_c))): AM_CFLAGS += -funroll-loops
 
 # Add the -fallow-leading-underscore option when needed
-$(patsubst %.F90,%.lo,$(patsubst %.f90,%.lo,$(notdir $(gfor_specific_src)))): AM_FCFLAGS += -fallow-leading-underscore
-selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-underscore
+$(patsubst %.F90,%.lo,$(patsubst %.f90,%.lo,$(notdir $(gfor_specific_src)))): AM_FCFLAGS += -fallow-leading-underscore -fbuilding-libgfortran
+selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-underscore -fbuilding-libgfortran
 
 # Build *_r17.F90 and *_c17.F90 with additional -mabi=ieeelongdouble on powerpc64le-linux.
 
@@ -7648,7 +7648,7 @@ selected_real_kind.lo selected_int_kind.
 @HAVE_REAL_17_TRUE@$(patsubst %_c17.c,%_c17.lo,$(notdir $(gfor_built_src))): AM_CFLAGS += -mabi=ieeelongdouble
 
 # Add flags for IEEE modules
-@IEEE_SUPPORT_TRUE@$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore
+@IEEE_SUPPORT_TRUE@$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore -fbuilding-libgfortran
 
 # Dependencies between IEEE_ARITHMETIC and IEEE_EXCEPTIONS
 ieee_arithmetic.lo: ieee/ieee_arithmetic.F90 ieee_exceptions.lo


	Jakub


  reply	other threads:[~2022-01-07 16:46 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-03 15:36 [power-ieee128] libgfortran: -mabi=ieeelongdouble I/O Jakub Jelinek
2022-01-03 16:26 ` Jakub Jelinek
2022-01-03 17:03   ` Thomas Koenig
2022-01-03 20:00     ` [power-ieee128] libgfortran, fortran: " Jakub Jelinek
2022-01-03 22:43       ` Thomas Koenig
2022-01-04 11:07         ` [power-ieee128] RFH: LTO broken Jakub Jelinek
2022-01-04 13:41           ` [power-ieee128] libgfortran: -mabi=ieeelongdouble I/O fix Jakub Jelinek
2022-01-04 14:35             ` Thomas Koenig
2022-01-06  2:48           ` [power-ieee128] RFH: LTO broken Michael Meissner
2022-01-06  4:17           ` Michael Meissner
2022-01-06  5:00           ` Michael Meissner
2022-01-06 20:01             ` Thomas Koenig
2022-01-06 20:10               ` Jakub Jelinek
2022-01-07  9:22               ` [power-ieee128] OPEN CONV Jakub Jelinek
2022-01-07 10:26                 ` Thomas Koenig
2022-01-07 19:52                   ` Jakub Jelinek
2022-01-07 21:40                     ` Thomas Koenig
2022-01-07 21:48                       ` Jakub Jelinek
2022-01-08 10:07                         ` Thomas Koenig
2022-01-08 11:00                           ` Jakub Jelinek
2022-01-08 11:10                             ` Jakub Jelinek
2022-01-08 14:02                               ` Jakub Jelinek
2022-01-08 14:13                                 ` Thomas Koenig
2022-01-08 14:18                                   ` Jakub Jelinek
2022-01-08 18:59                                     ` Michael Meissner
2022-01-08 19:15                                       ` David Edelsohn
2022-01-08 19:37                                         ` Michael Meissner
2022-01-07 11:29               ` [power-ieee128] RFH: LTO broken Jakub Jelinek
2022-01-07 13:31                 ` Jakub Jelinek
2022-01-07 14:25                   ` Thomas Koenig
2022-01-07 16:46                     ` Jakub Jelinek [this message]
2022-01-07 21:33                       ` Thomas Koenig
2022-01-03 16:48 ` [power-ieee128] libgfortran: -mabi=ieeelongdouble I/O Thomas Koenig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220107164614.GM2646553@tucnak \
    --to=jakub@redhat.com \
    --cc=bergner@linux.ibm.com \
    --cc=dje.gcc@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=meissner@linux.ibm.com \
    --cc=segher@kernel.crashing.org \
    --cc=tkoenig@netcologne.de \
    --cc=wschmidt@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).