Disable tests that require fesetround() on platforms without it

Message ID 20220428155514.27063-1-palmer@rivosinc.com
State New
Headers
Series Disable tests that require fesetround() on platforms without it |

Commit Message

Palmer Dabbelt April 28, 2022, 3:55 p.m. UTC
  Some tests check for fenv and then proceed to use fesetround() directly,
but some platforms (at least RISC-V soft-float) have fenv but don't
support rounding modes.  This adds a DG check that fesetround() actually
functions, which is then used by all the tests that call fesetround()
explicitly.

gcc/testsuite/ChangeLog

	* lib/target-supports.exp
	(check_effective_target_fenv_setround): New function.
	* gcc.dg/torture/fp-double-convert-float-1.c: Check
	fenv_fesetround.
	* gcc.dg/torture/fp-int-convert-float128-timode-3.c: Likewise.
	* gcc.dg/torture/fp-int-convert-timode-2.c: Likewise.
	* gcc.dg/torture/fp-int-convert-timode-3.c: Likewise.
	* gcc.dg/torture/fp-int-convert-timode-4.c: Likewise.
	* gcc.dg/torture/fp-uint64-convert-double-1.c: Likewise.
	* gcc.dg/torture/fp-uint64-convert-double-2.c: Likewise.

---

I started getting a bunch of atomic-related failures with this patch,
but they persist when I've gone back and disabled it so I'm pretty sure
it's something in my environment.  Without this patch I get a bunch of
failures on the RISC-V soft float targets, I haven't tried anywhere
else.
---
 .../gcc.dg/torture/fp-double-convert-float-1.c |  2 +-
 .../torture/fp-int-convert-float128-timode-3.c |  2 +-
 .../gcc.dg/torture/fp-int-convert-timode-2.c   |  2 +-
 .../gcc.dg/torture/fp-int-convert-timode-3.c   |  2 +-
 .../gcc.dg/torture/fp-int-convert-timode-4.c   |  2 +-
 .../torture/fp-uint64-convert-double-1.c       |  2 +-
 .../torture/fp-uint64-convert-double-2.c       |  2 +-
 gcc/testsuite/lib/target-supports.exp          | 18 ++++++++++++++++++
 8 files changed, 25 insertions(+), 7 deletions(-)
  

Comments

Joseph Myers April 28, 2022, 10:12 p.m. UTC | #1
On Thu, 28 Apr 2022, Palmer Dabbelt wrote:

> +proc check_effective_target_fenv_setround {} {
> +  return [check_runtime fenv_setround {
> +    #include <fenv.h>
> +    #include <stdlib.h>
> +    int
> +    main (void)
> +    {
> +      if (fesetround (1) == 0)

There is no reason to expect that 1 is a valid argument to fesetround.  
(It isn't with x86 glibc, for example.)  You need to use whatever FE_* 
rounding mode macro the test in question cares about.
  
Palmer Dabbelt April 28, 2022, 10:16 p.m. UTC | #2
On Thu, 28 Apr 2022 15:12:39 PDT (-0700), joseph@codesourcery.com wrote:
> On Thu, 28 Apr 2022, Palmer Dabbelt wrote:
>
>> +proc check_effective_target_fenv_setround {} {
>> +  return [check_runtime fenv_setround {
>> +    #include <fenv.h>
>> +    #include <stdlib.h>
>> +    int
>> +    main (void)
>> +    {
>> +      if (fesetround (1) == 0)
>
> There is no reason to expect that 1 is a valid argument to fesetround.
> (It isn't with x86 glibc, for example.)  You need to use whatever FE_*
> rounding mode macro the test in question cares about.

Sorry, I mis-read the man page and thought that list of numbers was ABI.  
At least some of the tests are using all the rounding modes, so unless 
you think it's worth splitting up both the tests and the DG check I'll 
just check for all of them?
  
Joseph Myers April 28, 2022, 10:22 p.m. UTC | #3
On Thu, 28 Apr 2022, Palmer Dabbelt wrote:

> On Thu, 28 Apr 2022 15:12:39 PDT (-0700), joseph@codesourcery.com wrote:
> > On Thu, 28 Apr 2022, Palmer Dabbelt wrote:
> > 
> > > +proc check_effective_target_fenv_setround {} {
> > > +  return [check_runtime fenv_setround {
> > > +    #include <fenv.h>
> > > +    #include <stdlib.h>
> > > +    int
> > > +    main (void)
> > > +    {
> > > +      if (fesetround (1) == 0)
> > 
> > There is no reason to expect that 1 is a valid argument to fesetround.
> > (It isn't with x86 glibc, for example.)  You need to use whatever FE_*
> > rounding mode macro the test in question cares about.
> 
> Sorry, I mis-read the man page and thought that list of numbers was ABI.  At
> least some of the tests are using all the rounding modes, so unless you think
> it's worth splitting up both the tests and the DG check I'll just check for
> all of them?

I think checking for all four of the IEEE binary rounding modes is 
reasonable.  (If we add support for FE_TONEARESTFROMZERO in RISC-V glibc, 
that ought to be handled separately for any GCC tests involving that 
rounding mode, given that most architectures don't support it.)
  
Palmer Dabbelt April 28, 2022, 10:28 p.m. UTC | #4
On Thu, 28 Apr 2022 15:22:37 PDT (-0700), joseph@codesourcery.com wrote:
> On Thu, 28 Apr 2022, Palmer Dabbelt wrote:
>
>> On Thu, 28 Apr 2022 15:12:39 PDT (-0700), joseph@codesourcery.com wrote:
>> > On Thu, 28 Apr 2022, Palmer Dabbelt wrote:
>> >
>> > > +proc check_effective_target_fenv_setround {} {
>> > > +  return [check_runtime fenv_setround {
>> > > +    #include <fenv.h>
>> > > +    #include <stdlib.h>
>> > > +    int
>> > > +    main (void)
>> > > +    {
>> > > +      if (fesetround (1) == 0)
>> >
>> > There is no reason to expect that 1 is a valid argument to fesetround.
>> > (It isn't with x86 glibc, for example.)  You need to use whatever FE_*
>> > rounding mode macro the test in question cares about.
>>
>> Sorry, I mis-read the man page and thought that list of numbers was ABI.  At
>> least some of the tests are using all the rounding modes, so unless you think
>> it's worth splitting up both the tests and the DG check I'll just check for
>> all of them?
>
> I think checking for all four of the IEEE binary rounding modes is
> reasonable.  (If we add support for FE_TONEARESTFROMZERO in RISC-V glibc,
> that ought to be handled separately for any GCC tests involving that
> rounding mode, given that most architectures don't support it.)

Yep, I was just talking about the IEEE modes.  I'll send a v2.
  

Patch

diff --git a/gcc/testsuite/gcc.dg/torture/fp-double-convert-float-1.c b/gcc/testsuite/gcc.dg/torture/fp-double-convert-float-1.c
index ec23274ea98..656e5c345e7 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-double-convert-float-1.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-double-convert-float-1.c
@@ -1,6 +1,6 @@ 
 /* PR57245 */
 /* { dg-do run } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
 /* { dg-additional-options "-frounding-math" } */
 
 #include <fenv.h>
diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert-float128-timode-3.c b/gcc/testsuite/gcc.dg/torture/fp-int-convert-float128-timode-3.c
index c445d10522e..499e8c0cabf 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-int-convert-float128-timode-3.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert-float128-timode-3.c
@@ -4,7 +4,7 @@ 
 /* { dg-require-effective-target __float128 } */
 /* { dg-require-effective-target base_quadfloat_support } */
 /* { dg-require-effective-target int128 } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
 /* { dg-options "-frounding-math" } */
 /* { dg-add-options __float128 } */
 
diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-2.c b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-2.c
index a82f03d079c..3f91f8f3833 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-2.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-2.c
@@ -2,7 +2,7 @@ 
    float.  */
 /* { dg-do run } */
 /* { dg-require-effective-target int128 } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
 /* { dg-options "-frounding-math" } */
 
 #include <fenv.h>
diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-3.c b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-3.c
index 707d539335f..816fcb1120e 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-3.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-3.c
@@ -2,7 +2,7 @@ 
    float.  */
 /* { dg-do run } */
 /* { dg-require-effective-target int128 } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
 /* { dg-options "-frounding-math" } */
 
 #include <fenv.h>
diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-4.c b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-4.c
index 09600f90903..6337a6d3f1e 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-4.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-4.c
@@ -2,7 +2,7 @@ 
    float.  */
 /* { dg-do run } */
 /* { dg-require-effective-target int128 } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
 /* { dg-options "-frounding-math" } */
 
 #include <fenv.h>
diff --git a/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-1.c b/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-1.c
index fadad8c3198..43aeb81a602 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-1.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-1.c
@@ -1,6 +1,6 @@ 
 /* PR84407 */
 /* { dg-do run } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
 /* { dg-additional-options "-frounding-math -fexcess-precision=standard" } */
 
 #include <fenv.h>
diff --git a/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-2.c b/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-2.c
index 952f96b33c9..d380b4a80e8 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-2.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-2.c
@@ -1,6 +1,6 @@ 
 /* PR84407 */
 /* { dg-do run } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
 /* { dg-additional-options "-frounding-math" } */
 
 #include <fenv.h>
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 2d5d0539bb4..1a9b41a73bb 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -10685,6 +10685,24 @@  proc check_effective_target_fenv_exceptions_dfp {} {
     } [add_options_for_ieee "-std=gnu99"]]
 }
 
+
+# Return 1 if <fenv.h> is availiable and supports fesetround.
+
+proc check_effective_target_fenv_setround {} {
+  return [check_runtime fenv_setround {
+    #include <fenv.h>
+    #include <stdlib.h>
+    int
+    main (void)
+    {
+      if (fesetround (1) == 0)
+        exit (0);
+      else
+        abort ();
+    }
+  } [add_options_for_ieee "-std=gnu99"]]
+}
+
 # Return 1 if -fexceptions is supported.
 
 proc check_effective_target_exceptions {} {