Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
From: Eberhard Burr <Eberhard.Burr@gmx.de>
Subject: Re: Floating Point Exception
Date: 1999/09/09	[thread overview]
Message-ID: <874sh4rzfs.fsf@gmx.de> (raw)
In-Reply-To: 37D7A42E.91156981@ijs.si

Tone Kokalj <Tone.Kokalj@ijs.si> writes:


> First, I do think that FPE is not due to GCC, since compiled programs with
> DEC FORTAN90 have
> nothing to do with GCC, but yet FPE occurs.
> 
> Yesterday I compiled kernel 2.2.12. It runs OK, and there are no more <sc *>
> messages.
> 
> However, I still don't know how to get rid of FPEs. Do You have any recipes
> how
> to get rid of that???

hmm, seems when two weeks ago after I had just installed this nice
SX164, my news system was misconfiged and thus my call for help in the 
very same subject didn't get thru... I've since learned the following
and I'd appreciate to get even more (or better) information on it.

Here we go:
 1) the Alpha is not fully IEEE compliant by itself and differs from
    other processors in that the FPU exception cannot be switched off.
    When a division by zero appears then other processors represent
    the result with a special bit pattern which has the meaning "this
    result is invalid" while the alpha fires an exception (same for
    underflows, overflows and undefined operations, of course)
 2) the alpha is faster in floating point. Part of this is because it
    doesn't have to treat those special bit patterns (NaN, INF and
    friends, which are defined somewhere in math.h on i86 Linux).
 3) someone suggested using the -mieee switch to gcc to get the same
    behaviour as with the defaults on i86. I have not tried it though.
 4) Exception handling is easy:

   a) make a global variable to hold error codes
     volatile int my_err;

   b) write the error handler, which might be as lean as
     static void my_fpu_handler(int err)
     {
       my_err = err;  /* my_err defined globally and volatile */
     }

   c) install the handler:
    
     void (*oldhandler)();  /* keep a reference to the initial value
                               so it can be restored later */

     oldhandler = signal(SIGFPE, my_fpu_handler);
     if (SIG_ERR == oldhandler) {
        /* you might want to write your own BARF(), of course */
        BARF("cannot install floating point exception handler");
    }

   d) instead of using the functions isnan(), finite() and friends to
    check results for validity, check the content of my_err and reset
    it to zero after having taken sensible measures.

 5) Code which neither uses exception handling nor the ieee-conformant 
    finite() isnan() ... functions to test results is broken by
    design.

 6) the gcc-documentation is rather good, it's just a bit hard to read 
    because it's in info format. Same for the glibc-documentation;
    -mieee and friends are described in the egcs node about
    architecture-dependent options, the signal() function is in the
    glibc docs. Both are definitely worth reading if you want to make
    use of the alpha's superior floating point performance.


kind regards,
-- 
Eberhard Burr    check http://www.uni-karlsruhe.de/~Eberhard.Burr/publickey.asc
                 for PGP Key -- #include <stddisc.h> -- electric cookie follows
Truly simple systems... require infinite testing.
		-- Norman Augustine



  reply	other threads:[~1999-09-09  4:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-07  4:00 Floating Point Exception Tone Kokalj
1999-09-07  4:00 ` Greg Lindahl
1999-09-07  4:00 ` J. Josh Feng
1999-09-08  4:00   ` Tone Kokalj
1999-09-08  4:00     ` J. Josh Feng
1999-09-08  4:00       ` Greg Lindahl
1999-09-08  4:00   ` Greg Lindahl
1999-09-09  4:00     ` Tone Kokalj
1999-09-09  4:00       ` Eberhard Burr [this message]
1999-09-10  4:00         ` Tone Kokalj
  -- strict thread matches above, loose matches on Subject: below --
2001-05-29 10:11 Floating point exception BERTRAND Joël
2001-05-29 12:50 ` BERTRAND Joël
2001-06-25 21:45   ` Ken Whaley
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox