public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [Patch, Fortran] PR 82143: add a -fdefault-real-16 flag
@ 2017-09-18  9:31 Dominique d'Humières
  2017-09-18 18:13 ` Janus Weil
  0 siblings, 1 reply; 30+ messages in thread
From: Dominique d'Humières @ 2017-09-18  9:31 UTC (permalink / raw)
  To: Janus Weil; +Cc: gfortran, gcc-patches

As said in bugzilla

(1) real(16) is an order of magnitude slower than real(8) for the codes I have tested (a long time ago). So its real utility is quite low.

(2) I think your time would be better used by dealing with your assigned PRs.

But now the wasted time is done, I don’t have further objection.

Dominique

Note: Using -fdefault-* for "production" is a very bad idea.

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: [Patch, Fortran] PR 82143: add a -fdefault-real-16 flag
@ 2017-09-25 15:07 David Edelsohn
  2017-09-25 21:14 ` Janus Weil
  0 siblings, 1 reply; 30+ messages in thread
From: David Edelsohn @ 2017-09-25 15:07 UTC (permalink / raw)
  To: Janus Weil, Janne Blomqvist; +Cc: Steve Kargl, Fortran List, GCC Patches

promotion_3.f90 and promotion_4.f90 are failing on at least PowerPC
and AArch64.  Are these new tests limited to x86 or some long double
assumptions?

f951: Fatal Error: REAL(KIND=16) is not available for '-fdefault-real-16' option
compilation terminated.

f951: Fatal Error: REAL(KIND=10) is not available for '-fdefault-real-10' option
compilation terminated.

Thanks, David

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: [Patch, Fortran] PR 82143: add a -fdefault-real-16 flag
@ 2017-09-18  9:38 Dominique d'Humières
  0 siblings, 0 replies; 30+ messages in thread
From: Dominique d'Humières @ 2017-09-18  9:38 UTC (permalink / raw)
  To: Janus Weil; +Cc: gfortran

For the record, I just stumbled on http://www.davidhbailey.com/dhbpapers/mpfun2015.pdf.

IMO if real(8) is not enough for a given problem, this is really the way to go (there is no guarantee that real(16) will be enough). In my "real life", real(8) was not enough only once and real(16) was not enough too: I had to use precisions between 40 and 200 with Mathematica.

Dominique

^ permalink raw reply	[flat|nested] 30+ messages in thread
* [Patch, Fortran] PR 82143: add a -fdefault-real-16 flag
@ 2017-09-17 20:42 Janus Weil
  2017-09-18  4:51 ` Steve Kargl
  0 siblings, 1 reply; 30+ messages in thread
From: Janus Weil @ 2017-09-17 20:42 UTC (permalink / raw)
  To: gfortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1748 bytes --]

Hi all,

attached is a (technically) simple patch that implements the compiler
flag "-fdefault-real-16" for gfortran.

I know that there is some opposition against this, but I am proposing
it anyway, because I do think it is useful after all. My reasoning is
as follows:

1) Despite tons of -freal-X-real-Y flags, there currently is no way to
only promote the default real kind to real(16).
2) Since a variable of default REAL kind does not specify a KIND value
explicitly, it is quite natural for a compiler to control this by
means of flags.
3) gfortran already has -fdefault-real-8 (which is used in lots of
real-world codes AFAIK) and does support quad-precision variables.
4) Other compilers do have flags for this as well (e.g. ifort's
"-real-size 128" etc).
5) I know that it is possible, any maybe cleaner, to declare variables
with explicit kinds instead of relying on compiler flags, but for
large and historically grown codes it is not always straightforward to
do this right away.
6) The patch does not modify the default behavior of gfortran.
7) No one who dislikes such compiler flags is forced to use them.
8) I don't see how this flag can cause any harm. It adds additional
possibilities of using the compiler and thus makes gfortran more
powerful (and more compatible with other compilers).

The patch regtests cleanly on x86_64-linux-gnu. Ok for trunk?

Cheers,
Janus


2017-09-17  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/82143
    * lang.opt: Add the option -fdefault-real-16.
    * invoke.texi: Add documentation for -fdefault-real-16.
    * trans-types.c (gfc_init_kinds): Implement -fdefault-real-16.

2017-09-17  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/82143
    * gfortran.dg/promotion_3.f90: New test case.

[-- Attachment #2: pr82143.diff --]
[-- Type: text/plain, Size: 2884 bytes --]

Index: gcc/fortran/invoke.texi
===================================================================
--- gcc/fortran/invoke.texi	(revision 252892)
+++ gcc/fortran/invoke.texi	(working copy)
@@ -120,7 +120,7 @@ by type.  Explanations are in the following sectio
 -fd-lines-as-comments @gol
 -fdec -fdec-structure -fdec-intrinsic-ints -fdec-static -fdec-math @gol
 -fdefault-double-8 -fdefault-integer-8 @gol
--fdefault-real-8 -fdollar-ok -ffixed-line-length-@var{n} @gol
+-fdefault-real-8 -fdefault-real-16 -fdollar-ok -ffixed-line-length-@var{n} @gol
 -ffixed-line-length-none -ffree-form -ffree-line-length-@var{n} @gol
 -ffree-line-length-none -fimplicit-none -finteger-4-integer-8 @gol
 -fmax-identifier-length -fmodule-private -ffixed-form -fno-range-check @gol
@@ -404,6 +404,14 @@ the default width of @code{DOUBLE PRECISION} to 16
 @code{-fdefault-double-8} is given, too. Unlike @option{-freal-4-real-8},
 it does not promote variables with explicit kind declaration.
 
+@item -fdefault-real-16
+@opindex @code{fdefault-real-16}
+Set the default real type to a 16 byte wide type. This option also affects
+the kind of non-double real constants like @code{1.0}, and does promote
+the default width of @code{DOUBLE PRECISION} to 16 bytes if possible, unless
+@code{-fdefault-double-8} is given. Unlike @option{-freal-4-real-16},
+it does not promote variables with explicit kind declaration.
+
 @item -fdefault-double-8
 @opindex @code{fdefault-double-8}
 Set the @code{DOUBLE PRECISION} type to an 8 byte wide type.  Do nothing if this
Index: gcc/fortran/lang.opt
===================================================================
--- gcc/fortran/lang.opt	(revision 252892)
+++ gcc/fortran/lang.opt	(working copy)
@@ -460,6 +460,10 @@ fdefault-real-8
 Fortran Var(flag_default_real)
 Set the default real kind to an 8 byte wide type.
 
+fdefault-real-16
+Fortran Var(flag_default_real_16)
+Set the default real kind to an 16 byte wide type.
+
 fdollar-ok
 Fortran Var(flag_dollar_ok)
 Allow dollar signs in entity names.
Index: gcc/fortran/trans-types.c
===================================================================
--- gcc/fortran/trans-types.c	(revision 252892)
+++ gcc/fortran/trans-types.c	(working copy)
@@ -538,6 +538,14 @@ gfc_init_kinds (void)
 
       gfc_default_real_kind = 8;
     }
+  else if (flag_default_real_16)
+  {
+    if (!saw_r16)
+      gfc_fatal_error ("REAL(KIND=16) is not available for "
+			"%<-fdefault-real-16%> option");
+
+    gfc_default_real_kind = 16;
+  }
   else if (flag_real4_kind == 8)
   {
     if (!saw_r8)
@@ -577,7 +585,7 @@ gfc_init_kinds (void)
 
   if (flag_default_real && flag_default_double && saw_r8)
     gfc_default_double_kind = 8;
-  else if (flag_default_real && saw_r16)
+  else if ((flag_default_real || flag_default_real_16) && saw_r16)
     gfc_default_double_kind = 16;
   else if (flag_real8_kind == 4)
     {

[-- Attachment #3: promotion_3.f90 --]
[-- Type: text/x-fortran, Size: 387 bytes --]

! { dg-do run }
! { dg-options "-fdefault-real-16" }
!
! PR 82143: add a -fdefault-real-16 flag
!
! Contributed by Janus Weil <janus@gcc.gnu.org>

real :: r
real(kind=4) :: r4
real(kind=8) :: r8
double precision :: d
print *, kind(r4), kind(r8), kind(r), kind(d)
if (kind(r4) /= 4) call abort
if (kind(r8) /= 8) call abort
if (kind(r) /= 16) call abort
if (kind(d) /= 16) call abort
end

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2017-12-03 17:36 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-18  9:31 [Patch, Fortran] PR 82143: add a -fdefault-real-16 flag Dominique d'Humières
2017-09-18 18:13 ` Janus Weil
2017-09-22 10:06   ` Dominique d'Humières
2017-09-22 11:21     ` Janus Weil
2017-09-22 14:37     ` Steve Kargl
2017-09-22 22:46       ` Dominique d'Humières
2017-09-22 23:47         ` Steve Kargl
2017-12-03 17:36   ` Gerald Pfeifer
  -- strict thread matches above, loose matches on Subject: below --
2017-09-25 15:07 David Edelsohn
2017-09-25 21:14 ` Janus Weil
2017-09-25 21:23   ` Steve Kargl
2017-09-26  8:44     ` Janus Weil
2017-09-26  9:03       ` Janus Weil
2017-09-26  9:12         ` Rainer Orth
2017-09-26  9:47           ` Janus Weil
2017-09-26 14:54       ` David Edelsohn
2017-09-18  9:38 Dominique d'Humières
2017-09-17 20:42 Janus Weil
2017-09-18  4:51 ` Steve Kargl
2017-09-18  7:02   ` Janus Weil
2017-09-18 14:08     ` Steve Kargl
2017-09-18 17:57       ` Janus Weil
2017-09-21  7:10         ` Janus Weil
2017-09-21 20:38           ` Steve Kargl
2017-09-22  5:03             ` Janus Weil
2017-09-22  7:12               ` Janne Blomqvist
2017-09-22  9:44                 ` Janus Weil
2017-09-22 19:32                   ` Janus Weil
2017-09-23 13:19                     ` Janus Weil
2017-09-22 14:06                 ` Steve Kargl

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).