diff mbox

[libgfortran] : Fix support_fpu_rounding_mode and add -mieee flags for alpha

Message ID CAFULd4aJVUjr57x+_AO8k81w8Dsf1gshdsL-qbMUX72s+ZoVFA@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak July 2, 2014, 8:54 a.m. UTC
Hello!

Attached patch fixes some fallout from IEEE support and enables -mieee
for alpha. Also, the patch removes -O0 from dg-additiona-options in
IEEE testsuite, as this always override default optimization flag.

libgfortran/ChangeLog:

2014-07-02  Uros Bizjak  <ubizjak@gmail.com>

    * configure.host (ieee_flags): Add -mieee for alpha*.

    * config/fpu-glibc.h (support_fpu_rounding_mode): Correctly handle
    GFC_FPE_UPWARD, GFC_FPE_DOWNWARD and GFC_FPE_TOWARDZERO.
    * config/fpu-aix.h (support_fpu_rounding_mode): Ditto.

testsuite/ChangeLog:

2014-07-02  Uros Bizjak  <ubizjak@gmail.com>

    * gfortran.dg/ieee/ieee_1.F90 (dg-additional-options): Remove -O0.
    * gfortran.dg/ieee/ieee_rounding_1.f90 (dg-additional-options): Add.

Patch was tested on alphaev68-linux-gnu (uses fpu-glibc.h) and
x86_64-linux-gnu.  Patch was committed to mainline SVN.

BTW: On alpha, it is possible to enable underflow handling:

#ifdef __USE_GNU
/* On later hardware, and later kernels for earlier hardware, we can forcibly
   underflow denormal inputs and outputs.  This can speed up certain programs
   significantly, usually without affecting accuracy.  */
enum
  {
    FE_MAP_DMZ =        1UL << 12,      /* Map denorm inputs to zero */
#define FE_MAP_DMZ      FE_MAP_DMZ

    FE_MAP_UMZ =        1UL << 13,      /* Map underflowed outputs to zero */
#define FE_MAP_UMZ      FE_MAP_UMZ
  };
#endif

FX, if you care for this option, I can help test the patch and
corresponding testcases.

Uros.

Comments

FX Coudert July 2, 2014, 9:16 a.m. UTC | #1
Dear Uros,

Thanks very much for the patch. I have a few questions:

> the patch removes -O0 from dg-additiona-options in IEEE testsuite, as this always override default optimization flag.

That was my purpose: this test can fail with optimization (on x86_64, IIRC), hence the -O0 should override the default optimization flags in the testsuite.

>    * gfortran.dg/ieee/ieee_rounding_1.f90 (dg-additional-options): Add.

If -mfp-rounding-mode=d is required on alpha for IEEE conformance, it should be added to add-ieee-options in lib/fortran-torture.exp, shouldn’t it? Rather than enabled on a case-by-case basis. Also, we might want to document these target-specific options here: https://gcc.gnu.org/onlinedocs/gfortran/IEEE-modules.html



> BTW: On alpha, it is possible to enable underflow handling:
> 
> #ifdef __USE_GNU
> /* On later hardware, and later kernels for earlier hardware, we can forcibly
>   underflow denormal inputs and outputs.  This can speed up certain programs
>   significantly, usually without affecting accuracy.  */
> enum
>  {
>    FE_MAP_DMZ =        1UL << 12,      /* Map denorm inputs to zero */
> #define FE_MAP_DMZ      FE_MAP_DMZ
> 
>    FE_MAP_UMZ =        1UL << 13,      /* Map underflowed outputs to zero */
> #define FE_MAP_UMZ      FE_MAP_UMZ
>  };
> #endif
> 
> FX, if you care for this option, I can help test the patch and
> corresponding testcases.

Yes, that’s interesting. What libc function do you call with those FE_MAP_{D,U}MZ values?

I would also like to enable FTZ for i386/x86_64 at some point, but my issue there is that it’s not “universal”, ie it’s only for SSE math if I understand correctly. One point of view is that it’s better than nothing (especially now that SSE math is probably the most used mode), but another point of view is that it wouldn’t be standard conforming.

FX
Uros Bizjak July 2, 2014, 10:25 a.m. UTC | #2
On Wed, Jul 2, 2014 at 11:16 AM, FX <fxcoudert@gmail.com> wrote:

> Thanks very much for the patch. I have a few questions:
>
>> the patch removes -O0 from dg-additiona-options in IEEE testsuite, as this always override default optimization flag.
>
> That was my purpose: this test can fail with optimization (on x86_64, IIRC), hence the -O0 should override the default optimization flags in the testsuite.

I did test this on x86_64-linux-gnu (with and without -m32) and there
were no problems with the testrun.

>>    * gfortran.dg/ieee/ieee_rounding_1.f90 (dg-additional-options): Add.
>
> If -mfp-rounding-mode=d is required on alpha for IEEE conformance, it should be added to add-ieee-options in lib/fortran-torture.exp, shouldn’t it? Rather than enabled on a case-by-case basis. Also, we might want to document these target-specific options here: https://gcc.gnu.org/onlinedocs/gfortran/IEEE-modules.html

I'm not sure if this is good idea ATM, since very few testcases (one
exactly ;) ) require strict rounding modes. Due to this, I don't think
dynamic rounding mode should be enabled for all testcases, as it comes
with a price. We can review this in future, if many testcases depend
on this option.

>> BTW: On alpha, it is possible to enable underflow handling:
>>
>> #ifdef __USE_GNU
>> /* On later hardware, and later kernels for earlier hardware, we can forcibly
>>   underflow denormal inputs and outputs.  This can speed up certain programs
>>   significantly, usually without affecting accuracy.  */
>> enum
>>  {
>>    FE_MAP_DMZ =        1UL << 12,      /* Map denorm inputs to zero */
>> #define FE_MAP_DMZ      FE_MAP_DMZ
>>
>>    FE_MAP_UMZ =        1UL << 13,      /* Map underflowed outputs to zero */
>> #define FE_MAP_UMZ      FE_MAP_UMZ
>>  };
>> #endif
>>
>> FX, if you care for this option, I can help test the patch and
>> corresponding testcases.
>
> Yes, that’s interesting. What libc function do you call with those FE_MAP_{D,U}MZ values?

Hm, it looks that this functionality is handled through fesetenv, but
I'm not 100% sure.

> I would also like to enable FTZ for i386/x86_64 at some point, but my issue there is that it’s not “universal”, ie it’s only for SSE math if I understand correctly. One point of view is that it’s better than nothing (especially now that SSE math is probably the most used mode), but another point of view is that it wouldn’t be standard conforming.

It is possible to test _SSE_MATH_ and _SSE2_MATH_ here?

Uros.
diff mbox

Patch

Index: libgfortran/configure.host
===================================================================
--- libgfortran/configure.host	(revision 212221)
+++ libgfortran/configure.host	(working copy)
@@ -48,6 +48,8 @@  esac
 # Some targets require additional compiler options for NaN/Inf.
 ieee_flags=
 case "${host_cpu}" in
+  alpha*)
+    ieee_flags="-mieee" ;;
   sh*)
     ieee_flags="-mieee" ;;
 esac
Index: libgfortran/config/fpu-aix.h
===================================================================
--- libgfortran/config/fpu-aix.h	(revision 212221)
+++ libgfortran/config/fpu-aix.h	(working copy)
@@ -372,18 +372,21 @@  support_fpu_rounding_mode (int mode)
 	return 0;
 #endif
 
+      case GFC_FPE_UPWARD:
 #ifdef FE_UPWARD
 	return 1;
 #else
 	return 0;
 #endif
 
+      case GFC_FPE_DOWNWARD:
 #ifdef FE_DOWNWARD
 	return 1;
 #else
 	return 0;
 #endif
 
+      case GFC_FPE_TOWARDZERO:
 #ifdef FE_TOWARDZERO
 	return 1;
 #else
Index: libgfortran/config/fpu-glibc.h
===================================================================
--- libgfortran/config/fpu-glibc.h	(revision 212221)
+++ libgfortran/config/fpu-glibc.h	(working copy)
@@ -387,18 +387,21 @@  support_fpu_rounding_mode (int mode)
 	return 0;
 #endif
 
+      case GFC_FPE_UPWARD:
 #ifdef FE_UPWARD
 	return 1;
 #else
 	return 0;
 #endif
 
+      case GFC_FPE_DOWNWARD:
 #ifdef FE_DOWNWARD
 	return 1;
 #else
 	return 0;
 #endif
 
+      case GFC_FPE_TOWARDZERO:
 #ifdef FE_TOWARDZERO
 	return 1;
 #else
Index: gcc/testsuite/gfortran.dg/ieee/ieee_1.F90
===================================================================
--- gcc/testsuite/gfortran.dg/ieee/ieee_1.F90	(revision 212221)
+++ gcc/testsuite/gfortran.dg/ieee/ieee_1.F90	(working copy)
@@ -1,5 +1,5 @@ 
 ! { dg-do run }
-! { dg-additional-options "-ffree-line-length-none -O0" }
+! { dg-additional-options "-ffree-line-length-none" }
 !
 ! Use dg-additional-options rather than dg-options to avoid overwriting the
 ! default IEEE options which are passed by ieee.exp and necessary.
Index: gcc/testsuite/gfortran.dg/ieee/ieee_rounding_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/ieee/ieee_rounding_1.f90	(revision 212221)
+++ gcc/testsuite/gfortran.dg/ieee/ieee_rounding_1.f90	(working copy)
@@ -1,4 +1,5 @@ 
 ! { dg-do run }
+! { dg-additional-options "-mfp-rounding-mode=d" { target alpha*-*-* } }
 
   use, intrinsic :: ieee_features, only : ieee_rounding
   use, intrinsic :: ieee_arithmetic