public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/37581]  New: IEEE inexact-flag not working on the Alpha
@ 2008-09-19  7:04 bagnara at cs dot unipr dot it
  2008-09-19  7:05 ` [Bug target/37581] " bagnara at cs dot unipr dot it
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: bagnara at cs dot unipr dot it @ 2008-09-19  7:04 UTC (permalink / raw)
  To: gcc-bugs

The following shows a problem on the Alpha whereby
the division 2/3 made on floats is flagged as exact.
Here are the details:

$ cat sf.cc
#include <fenv.h>
#include <cstdio>


int main() {
  float x = 2;
  float y = 3;
  feclearexcept(FE_INEXACT);
  x = x / y;
  printf("%d %.1000g\n", fetestexcept(FE_INEXACT) != 0, x);
}
$ g++ -v
Using built-in specs.
Target: alpha-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2
--program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --enable-mpfr --disable-libssp --with-long-double-128
--enable-checking=release --build=alpha-linux-gnu --host=alpha-linux-gnu
--target=alpha-linux-gnu
Thread model: posix
gcc version 4.2.4 (Debian 4.2.4-3)
$ g++ -mieee-with-inexact sf.cc
$ ./a.out
0 0.666666686534881591796875
$ cat /proc/cpuinfo
cpu                     : Alpha
cpu model               : EV56
cpu variation           : 7
cpu revision            : 0
cpu serial number       :
system type             : Rawhide
system variation        : Tincup
system revision         : 0
system serial number    : AY74642662
cycle frequency [Hz]    : 399642346 est.
timer frequency [Hz]    : 1200.00
page size [bytes]       : 8192
phys. address bits      : 40
max. addr. space #      : 127
BogoMIPS                : 705.16
kernel unaligned acc    : 0 (pc=0,va=0)
user unaligned acc      : 31 (pc=20000074c18,va=87)
platform string         : AlphaServer 1200 5/400 4MB
cpus detected           : 1
cpus active             : 1
cpu active mask         : 0000000000000001
L1 Icache               : 8K, 1-way, 32b line
L1 Dcache               : 8K, 1-way, 32b line
L2 cache                : 96K, 3-way, 64b line
L3 cache                : 4096K, 1-way, 64b line
$

I attach the generated assembly code, which shows this is not a constant
propagation issue.


-- 
           Summary: IEEE inexact-flag not working on the Alpha
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bagnara at cs dot unipr dot it
  GCC host triplet: alphaev56-unknown-linux-gnu


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


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

* [Bug target/37581] IEEE inexact-flag not working on the Alpha
  2008-09-19  7:04 [Bug target/37581] New: IEEE inexact-flag not working on the Alpha bagnara at cs dot unipr dot it
@ 2008-09-19  7:05 ` bagnara at cs dot unipr dot it
  2009-01-23  8:47 ` ubizjak at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bagnara at cs dot unipr dot it @ 2008-09-19  7:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from bagnara at cs dot unipr dot it  2008-09-19 07:04 -------
Created an attachment (id=16359)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16359&action=view)
Assembly code generated with g++ -S -mieee-with-inexact sf.cc


-- 


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


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

* [Bug target/37581] IEEE inexact-flag not working on the Alpha
  2008-09-19  7:04 [Bug target/37581] New: IEEE inexact-flag not working on the Alpha bagnara at cs dot unipr dot it
  2008-09-19  7:05 ` [Bug target/37581] " bagnara at cs dot unipr dot it
@ 2009-01-23  8:47 ` ubizjak at gmail dot com
  2009-01-24  5:43 ` abramobagnara at tin dot it
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2009-01-23  8:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from ubizjak at gmail dot com  2009-01-23 08:47 -------
Works for me with:

--cut here--
#define _GNU_SOURCE
#include <fenv.h>
#include <signal.h>
#include <stdlib.h>

static void foo (int sig)
{
  exit (0);
}

float __attribute__((noinline)) test (float x) { return 2.0f / x; };

int main()
{
  volatile float x;

  signal (SIGFPE, foo);

  feclearexcept (FE_ALL_EXCEPT);
  feenableexcept (FE_INEXACT);

  x = test (3.0f);

  abort ();
}
--cut here--

$ gcc -O2 -lm -mieee-with-inexact sf.c
$ ./a.out
$


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug target/37581] IEEE inexact-flag not working on the Alpha
  2008-09-19  7:04 [Bug target/37581] New: IEEE inexact-flag not working on the Alpha bagnara at cs dot unipr dot it
  2008-09-19  7:05 ` [Bug target/37581] " bagnara at cs dot unipr dot it
  2009-01-23  8:47 ` ubizjak at gmail dot com
@ 2009-01-24  5:43 ` abramobagnara at tin dot it
  2009-01-24  8:09 ` bagnara at cs dot unipr dot it
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: abramobagnara at tin dot it @ 2009-01-24  5:43 UTC (permalink / raw)
  To: gcc-bugs



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


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

* [Bug target/37581] IEEE inexact-flag not working on the Alpha
  2008-09-19  7:04 [Bug target/37581] New: IEEE inexact-flag not working on the Alpha bagnara at cs dot unipr dot it
                   ` (2 preceding siblings ...)
  2009-01-24  5:43 ` abramobagnara at tin dot it
@ 2009-01-24  8:09 ` bagnara at cs dot unipr dot it
  2009-01-24 10:17 ` ubizjak at gmail dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bagnara at cs dot unipr dot it @ 2009-01-24  8:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bagnara at cs dot unipr dot it  2009-01-24 08:08 -------
I don't know why the bug was closed: I can confirm the erroneous behavior is
present also in GCC 4.3.2.


-- 

bagnara at cs dot unipr dot it changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


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

* [Bug target/37581] IEEE inexact-flag not working on the Alpha
  2008-09-19  7:04 [Bug target/37581] New: IEEE inexact-flag not working on the Alpha bagnara at cs dot unipr dot it
                   ` (3 preceding siblings ...)
  2009-01-24  8:09 ` bagnara at cs dot unipr dot it
@ 2009-01-24 10:17 ` ubizjak at gmail dot com
  2009-01-24 15:41 ` abramobagnara at tin dot it
  2009-02-03 11:10 ` ubizjak at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2009-01-24 10:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from ubizjak at gmail dot com  2009-01-24 10:17 -------
(In reply to comment #4)
> I don't know why the bug was closed: I can confirm the erroneous behavior is
> present also in GCC 4.3.2.

Because it looks to me that this is libc problem with fetestexcept. As far as
the compiler is concerned, GCC correctly decorates trapping instructions with
/sui and puts trap barrier to expected place:

        ...
        jsr $26,($27),__nldbl_printf            !lituse_jsr!5
        ldah $29,0($26)         !gpdisp!6
        divs/sui $f3,$f2,$f0
        trapb
        ...


-- 


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


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

* [Bug target/37581] IEEE inexact-flag not working on the Alpha
  2008-09-19  7:04 [Bug target/37581] New: IEEE inexact-flag not working on the Alpha bagnara at cs dot unipr dot it
                   ` (4 preceding siblings ...)
  2009-01-24 10:17 ` ubizjak at gmail dot com
@ 2009-01-24 15:41 ` abramobagnara at tin dot it
  2009-02-03 11:10 ` ubizjak at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: abramobagnara at tin dot it @ 2009-01-24 15:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from abramobagnara at tin dot it  2009-01-24 15:41 -------
(In reply to comment #5)

> Because it looks to me that this is libc problem with fetestexcept. As far as
> the compiler is concerned, GCC correctly decorates trapping instructions with
> /sui and puts trap barrier to expected place:
> 
>         ...
>         jsr $26,($27),__nldbl_printf            !lituse_jsr!5
>         ldah $29,0($26)         !gpdisp!6
>         divs/sui $f3,$f2,$f0
>         trapb
>         ...

I've reported a bug according to the valuable info you provide.

http://sourceware.org/bugzilla/show_bug.cgi?id=9783


-- 


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


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

* [Bug target/37581] IEEE inexact-flag not working on the Alpha
  2008-09-19  7:04 [Bug target/37581] New: IEEE inexact-flag not working on the Alpha bagnara at cs dot unipr dot it
                   ` (5 preceding siblings ...)
  2009-01-24 15:41 ` abramobagnara at tin dot it
@ 2009-02-03 11:10 ` ubizjak at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2009-02-03 11:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from ubizjak at gmail dot com  2009-02-03 11:10 -------
Not a GCC bug.


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2009-02-03 11:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-19  7:04 [Bug target/37581] New: IEEE inexact-flag not working on the Alpha bagnara at cs dot unipr dot it
2008-09-19  7:05 ` [Bug target/37581] " bagnara at cs dot unipr dot it
2009-01-23  8:47 ` ubizjak at gmail dot com
2009-01-24  5:43 ` abramobagnara at tin dot it
2009-01-24  8:09 ` bagnara at cs dot unipr dot it
2009-01-24 10:17 ` ubizjak at gmail dot com
2009-01-24 15:41 ` abramobagnara at tin dot it
2009-02-03 11:10 ` ubizjak at gmail dot com

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