This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR 51057/PR 51616 - fix quad_2.f90 test case


The test case quad_2.f90 was failing for multiple reasons:
* Some systems support REAL(16) but do not have a sqrtl function
* Some systems have a REAL(16) data type, but with less precision (106 instread of 113 digits)


This patch fixes the issue by adding an effective target macro to check for the former - and by distinguishing the available digits at compile time.

The patch was is mostly by Dominique (bid kudos!), I mainly changed the name of the dg check. The patch was tested on several systems by Dominique, Iain and Eric - and I just tested it on x86-64-linux (with libquadmath).

I intent to commit the patch tomorrow.

Tobias
2012-01-11  Dominique d'Humieres  <dominiq@lps.ens.fr>
	    Tobias Burnus  <burnus@net-b.de>

	PR fortran/51057
	PR fortran/51616
	* lib/target-supports.exp
	(check_effective_target_fortran_largest_fp_has_sqrt): New.
	* gfortran.dg/quad_2.f90: Use it, add pattern for IBM's real(16).

Index: gcc/testsuite/lib/target-supports.exp
===================================================================
--- gcc/testsuite/lib/target-supports.exp	(Revision 183101)
+++ gcc/testsuite/lib/target-supports.exp	(Arbeitskopie)
@@ -984,6 +984,28 @@
     }]
 }
 
+
+# Return 1 if the target supports SQRT for the largest floating-point
+# type. (Some targets lack the libm support for this FP type.)
+# On most targets, this check effectively checks either whether sqrtl is
+# available or on __float128 systems whether libquadmath is installed,
+# which provides sqrtq.
+#
+# When the target name changes, replace the cached result.
+
+proc check_effective_target_fortran_largest_fp_has_sqrt { } {
+    return [check_no_compiler_messages fortran_largest_fp_has_sqrt executable {
+	! Fortran
+        use iso_fortran_env, only: real_kinds
+        integer,parameter:: maxFP = real_kinds(ubound(real_kinds,dim=1))
+	real(kind=maxFP), volatile :: x
+        x = 2.0_maxFP
+	x = sqrt (x)
+	end
+    }]
+}
+
+
 # Return 1 if the target supports Fortran integer kinds larger than
 # integer(8), 0 otherwise.
 #
Index: gcc/testsuite/gfortran.dg/quad_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/quad_2.f90	(Revision 183101)
+++ gcc/testsuite/gfortran.dg/quad_2.f90	(Arbeitskopie)
@@ -1,4 +1,5 @@
 ! { dg-do run }
+! { dg-require-effective-target fortran_largest_fp_has_sqrt }
 !
 ! This test checks whether the largest possible
 ! floating-point number works.
@@ -40,22 +41,36 @@
        if (str2 /= "1.0000000000000000") call abort()
        if (str3 /= "   1.4142135623730951") call abort()
        if (str4 /= "1.4142135623730951") call abort()
+
      case (10)
        if (str1 /= "   1.00000000000000000000") call abort()
        if (str2 /= "1.00000000000000000000") call abort()
        if (str3 /= "   1.41421356237309504876") call abort()
        if (str4 /= "1.41421356237309504876") call abort()
+
      case (16)
        if (str1 /= "   1.00000000000000000000000000000000000") call abort()
        if (str2 /= "1.00000000000000000000000000000000000") call abort()
-       if (str3 /= "   1.41421356237309504880168872420969798") call abort()
-       if (str4 /= "1.41421356237309504880168872420969798") call abort()
+
+       if (digits(1.0_qp) == 113) then
+         ! IEEE 754 binary 128 format
+         ! e.g. libquadmath/__float128 on i686/x86_64/ia64
+         if (str3 /= "   1.41421356237309504880168872420969798") call abort()
+         if (str4 /= "1.41421356237309504880168872420969798") call abort()
+       else if (digits(1.0_qp) == 106) then
+         ! IBM binary 128 format
+         if (str3(1:37) /= "   1.41421356237309504880168872420969") call abort()
+         if (str4(1:34) /= "1.41421356237309504880168872420969") call abort()
+       end if
+
+       ! Do a libm run-time test
        block
          real(qp), volatile :: fp2a
          fp2a = 2.0_qp
          fp2a = sqrt (fp2a)
          if (abs (fp2a - fp2) > sqrt(2.0_qp)-nearest(sqrt(2.0_qp),-1.0_qp)) call abort()
        end block
+
      case default
        call abort()
    end select

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]