[Bug target/37581] IEEE inexact-flag not working on the Alpha

abramobagnara at tin dot it gcc-bugzilla@gcc.gnu.org
Sat Jan 24 05:43:00 GMT 2009



------- Comment #3 from abramobagnara at tin dot it  2009-01-24 05:43 -------
The test case you have used it's different from the original that showed the
bug.

Nevertheless it's useful to understand the possible nature of the bug.

It seems that if feenableexcept(FE_INEXACT) is not called
fetestexcept(FE_INEXACT) doesn't work as expected (and as C99 standard
provides).

Please note that according to documentation GNU extension
feenableexcept/fedisablexcept does not enable/disable inexact detection, but
does enable/disable inexact *trapping* via SIGFPE signal.

Here below there is a new test case that shows the wrong behaviour.

$ cat sf2.c 
#define _GNU_SOURCE
#include <fenv.h>
#include <signal.h>
#include <stdio.h>

static void foo (int sig)
{
  printf("inexact\n");
}


float __attribute__((noinline)) test (float x) {
        printf("%f / %f\n", 2.0f, x);
        return 2.0f / x;
}

void t()
{
  volatile float x;
  feclearexcept (FE_ALL_EXCEPT);
  x = test (3.0f);
  printf("fetestexcept(FE_INEXACT) = %d\n", fetestexcept(FE_INEXACT));
  feclearexcept (FE_ALL_EXCEPT);
  x = test (2.0f);
  printf("fetestexcept(FE_INEXACT) = %d\n", fetestexcept(FE_INEXACT));
}

int main() {
  printf("\nWith FE_INEXACT SIGFPE disabled\n");
  t();

  printf("\nWith FE_INEXACT SIGFPE enabled\n");
  signal (SIGFPE, foo);
  feenableexcept (FE_INEXACT);
  t();
}
$ gcc -O2 -lm -mieee-with-inexact sf2.c
$ ./a.out

With FE_INEXACT SIGFPE disabled
2.000000 / 3.000000
fetestexcept(FE_INEXACT) = 0
2.000000 / 2.000000
fetestexcept(FE_INEXACT) = 0

With FE_INEXACT SIGFPE enabled
2.000000 / 3.000000
inexact
fetestexcept(FE_INEXACT) = 2097152
2.000000 / 2.000000
fetestexcept(FE_INEXACT) = 0
$


-- 

abramobagnara at tin dot it changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |abramobagnara at tin dot it


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37581



More information about the Gcc-bugs mailing list