Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* SIGFPE
@ 1997-08-27 14:23 Christopher J. Grayce
  0 siblings, 0 replies; 8+ messages in thread
From: Christopher J. Grayce @ 1997-08-27 14:23 UTC (permalink / raw)


> I'm getting a SIGFPE when multiplying together
> two SMALL numbers (~1e-311 and 1e-11).
> The same multiplication on my PC Linux box returns zero
> which is perfectly acceptable. I can find nothing
> in gcc info about this behavior. Is there
> some flag (or?) I can set to correct this?
>
> Thanks.
> 
> Tom Browder
> 
> P.S. Using gcc from alphabits.

If those are the actual numbers you are using, I think the problem is
not an underflow on the multiply but that one of your operands is
invalid, so you are generating an invalid operation exception.  That
is, 1.0e-311 is too small a double precision number to represent in 64
bits under IEEE 754 standards, so the floating point processor can't
do anything sensible with it.  The smallest double precision number is
provided in <float.h> (try /usr/lib/gcc-lib/alpha-linux/2.7.2.1/
include/float.h for gcc 2.7.2.1) and is 2.2e-308 for a 64-bit double.

This being the case, we must wonder: how did you *get* 1.0e-311 as one
of your operands?  I don't think you can get it by legitimate
arithmetic instructions on legitimate data.  But I frequently see
exactly the results you are describing when I forget to initialize a
double variable (hence it contains garbage) and then use it in (any)
arithmetic operation.

It's also true that the same code usually generates for me no
exception on a Pentium using GCC (or often on an EB164 Alpha using DEC
C).  Most of the time this just seems to be because the unitialized
variables have harmless numbers in them, for some obscure reason
reportedly related to certain deathbed mutterings of St. Thomas
Aquinas on the Nature Of The NaN. . .

But I digress.  From what I can see (and I have no genuine
understanding of the issues here, so I hope more knowledgeable folk
correct this), there's another issue as well: the IEEE 754 standard
says that floating point exceptions should not in general raise a
signal but rather return certain specific values and set various
user-accessible flags to say what happened.

Now perhaps Intel/Linux/GCC gives full IEEE behaviour by default, in
which case invalid operands do not raise SIGFPE.  But as I understand
it the Alpha FPU in general is not set by GCC nor DEC C to fully
conform to IEEE 754, because there is a performance hit on RISC
architectures associated with the overhead required to be able to
figure out, when a floating point exception occurs, which instruction
did the dirty deed, what type of exception it was, and what exactly
should be done about it.  There is an interesting discussion of the
problem at http://www.partner.digital.com/www-swdev/pages/Home/TECH/documents/alpha_cookbook/notes.htm#ieee_float .

In particular, floating point underflows on the Alpha simply return
zero, but bogus operands raise a signal when the fastest floating
point multiply operands (mult) are generated by the compiler.  You can
if you like force GCC to conform to the IEEE standard by specifying
-mieee on the compilation line.  This turns mult's into multsu's and
trapb's, and bogus operands do not raise SIGFPE.  I don't know just
what kind of performance hit you take in the resulting code.  I'd be
interested in the answer myself.

Christopher Grayce
UCI Dept of Chemistry

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: SIGFPE
@ 1997-04-10 18:31 Jim Paradis
  0 siblings, 0 replies; 8+ messages in thread
From: Jim Paradis @ 1997-04-10 18:31 UTC (permalink / raw)


Randy Chapman wrote:
> 
> In article <334D10D4.6CF5A78@jrp.tiac.net> you wrote:
> : When you specify the "-mieee" flag to gcc, it generates recoverable
> : code.  The recovery code itself is in the kernel
> : (arch/alpha/math-emu/fp-emul.c if you want to check it out).  If
> : everything is working right, then the SIGFPE presented to the user
> : contains the CPU state at the point where the exception occurred.
> 
> Whats this do to fp performance ?  If needed, I can actually check
> before the operation is done for divide-by-zero and pass to some
> other code for that case, but I was also hoping to avoid that extra
> compare.  Then again, I guess I could go check this myself.

Hmmm... good question.  Let me check with my more learned
colleagues as to the actual performance impact of -mieee.  I don't
think it's *that* great...

> Hrm.  I'm still getting a fault on double 0 divided by double 0 
> with -mieee on 2.1.26, however. (does the same thing with floats 
> as well)

Okay; I'll check this out when I revisit the fp code...

-- 
Jim Paradis   jrp@jrp.tiac.net  
http://www.tiac.net/users/jrp/index.html
"It's not procrastination, it's my new Just-In-Time Workload Management
System!"

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: SIGFPE
@ 1997-04-10 18:04 Randy Chapman
  1997-04-10 19:07 ` SIGFPE Richard Henderson
  1997-04-10 19:09 ` SIGFPE Richard Henderson
  0 siblings, 2 replies; 8+ messages in thread
From: Randy Chapman @ 1997-04-10 18:04 UTC (permalink / raw)


In article <334D10D4.6CF5A78@jrp.tiac.net> you wrote:
: When you specify the "-mieee" flag to gcc, it generates recoverable
: code.  The recovery code itself is in the kernel
: (arch/alpha/math-emu/fp-emul.c if you want to check it out).  If 
: everything is working right, then the SIGFPE presented to the user
: contains the CPU state at the point where the exception occurred.

Whats this do to fp performance ?  If needed, I can actually check
before the operation is done for divide-by-zero and pass to some
other code for that case, but I was also hoping to avoid that extra
compare.  Then again, I guess I could go check this myself.

: You're right.  I checked the code and found to my horror that there's
: a big hole in the divide-by-zero case.  In ieee-math.c the divide
: routines correctly return QNaN in the case of 0/0, but in the case of
: nonzero/0 they fall through and cause a signal to be generated.  I'll
: come up with a fix for this soon...

Hrm.  I'm still getting a fault on double 0 divided by double 0 with -mieee
on 2.1.26, however. (does the same thing with floats as well)

        a = 0.0;
        b = 0.0;
        printf("about to divide %g by %g\n", a, b);
        c = a/b;
		printf("divided\n");
        printf("result: %g\n", c);

compiled with:
nova:~> gcc -mieee testieee.c -lm
nova:~> ./a.out
about to divide 0 by 0
Floating exception (core dumped)
nova:~> uname -a
Linux nova.campus.luth.se 2.1.26 #3 Thu Apr 3 19:30:10 CEST 1997 alpha

--randy

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: SIGFPE
@ 1997-04-10 16:09 Jim Paradis
  0 siblings, 0 replies; 8+ messages in thread
From: Jim Paradis @ 1997-04-10 16:09 UTC (permalink / raw)


Olaf Flebbe wrote:
> 
> Randy,
> 
> [I did the first IEEE FPU exception things on linux/x86]
> 
> Don't do a signal handler on SIGFPE, it will not work most of the time.
> On Intel processorcs the Floating point unit is decoupled from the
> Integer Unit. You will raise an floating point exception, (the kernel
> will send you a SIGFPE if you trigger souch a thing) if you access the
> floating point unit the next time *after* the exception occurs.
> Incidently gcc produces code which mixes up integer and floating point
> operations (for performance reasons) and therefore you will get an
> Exception at unpredictable times later in your code. [ In your code it
> will happen deep in the printf library code]. So don't to this, the
> argument may be correctly for other cpu/compiler combinations.

What you say is only partially correct.  While it is true that Alpha
produces imprecise floating-point exceptions, if you code according to
certain rules then it is possible to backtrack from the reported
exception
PC to the actual faulting instruction.  This is all documented in the
Alpha Architecture Reference Manual.

When you specify the "-mieee" flag to gcc, it generates recoverable
code.  The recovery code itself is in the kernel
(arch/alpha/math-emu/fp-emul.c if you want to check it out).  If 
everything is working right, then the SIGFPE presented to the user
contains the CPU state at the point where the exception occurred.

> The IEEE754 states that no signal should be raised on invalid
> operations. They defined a set of pseudo numbers which define the
> outcome of an invalid operations like 1./0. [BTW this is INF].
> You are free to implement exception handlers and such things, but these
> should the default behaviour.

You're right.  I checked the code and found to my horror that there's
a big hole in the divide-by-zero case.  In ieee-math.c the divide
routines correctly return QNaN in the case of 0/0, but in the case of
nonzero/0 they fall through and cause a signal to be generated.  I'll
come up with a fix for this soon...

> Linux/alpha should handle it correctly, not the JDK. I don't know the
> alpha, but on x86 it is an issue of correctly initialising the FPU.

-- 
Jim Paradis   jrp@jrp.tiac.net  
http://www.tiac.net/users/jrp/index.html
"It's not procrastination, it's my new Just-In-Time Workload Management
System!"

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

^ permalink raw reply	[flat|nested] 8+ messages in thread
* SIGFPE
@ 1997-04-10 11:41 Olaf Flebbe
  0 siblings, 0 replies; 8+ messages in thread
From: Olaf Flebbe @ 1997-04-10 11:41 UTC (permalink / raw)


Randy,

[I did the first IEEE FPU exception things on linux/x86]

Don't do a signal handler on SIGFPE, it will not work most of the time.
On Intel processorcs the Floating point unit is decoupled from the
Integer Unit. You will raise an floating point exception, (the kernel
will send you a SIGFPE if you trigger souch a thing) if you access the
floating point unit the next time *after* the exception occurs.
Incidently gcc produces code which mixes up integer and floating point
operations (for performance reasons) and therefore you will get an
Exception at unpredictable times later in your code. [ In your code it
will happen deep in the printf library code]. So don't to this, the
argument may be correctly for other cpu/compiler combinations.

The IEEE754 states that no signal should be raised on invalid
operations. They defined a set of pseudo numbers which define the
outcome of an invalid operations like 1./0. [BTW this is INF].
You are free to implement exception handlers and such things, but these
should the default behaviour.

Speaking for linux/x86:
For new libraries (Version ~>5.1) the IEEE754 style is the default.
[And the library -lieee is obsolete]

Linux/alpha should handle it correctly, not the JDK. I don't know the
alpha, but on x86 it is an issue of correctly initialising the FPU.

Olaf

-- 
  Dr. Olaf Flebbe                            Phone +49 (0)7071-9457-32
  science + computing gmbh                     FAX +49 (0)7071-9457-27
  Hagellocher Weg 71
  D-72070 Tuebingen  Email: o.flebbe@science-computing.de
  PGP fingerprint =  56 FC 74 F7 31 FE 49 13  31 12 6F E5 B9 04 1E 02

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

^ permalink raw reply	[flat|nested] 8+ messages in thread
* SIGFPE
@ 1997-04-09 19:05 Jim Paradis
  0 siblings, 0 replies; 8+ messages in thread
From: Jim Paradis @ 1997-04-09 19:05 UTC (permalink / raw)


Randy Chapman wrote:
> Unfortunately, you're still getting an FPE here.  However, I
> think I can work around this one, it is the other that was more
> painful.

Hmmm... I see what you're getting after now.  I've just been
looking into this, and there may be a real problem here.  When
you specify the -mieee flag to gcc, it generates a DIVT/SU
instruction.  Supposedly if the /S qualifier is specified, the
kernel will do software completion on the divide-by-zero trap,
and the software emulator should return the appropriate non-numeric
result.

I just checked the code and found to my horror that there's a
path for 0/0 to return QNaN as it should... but there's *no*
path to handle nonzero/0.  This *should* return +Inf or -Inf
depending on the sign of the dividend.  Without this path, the
code falls through to where the caller generates a SIGFPE.

So, in short: for now, kludge around the divide-by-zero problem
with a signal handler, but I should have a kernel patch available
fairly soon.

-- 
Jim Paradis   jrp@jrp.tiac.net  
http://www.tiac.net/users/jrp/index.html
"It's not procrastination, it's my new Just-In-Time Workload Management
System!"

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

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

end of thread, other threads:[~1997-08-27 14:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-08-27 14:23 SIGFPE Christopher J. Grayce
  -- strict thread matches above, loose matches on Subject: below --
1997-04-10 18:31 SIGFPE Jim Paradis
1997-04-10 18:04 SIGFPE Randy Chapman
1997-04-10 19:07 ` SIGFPE Richard Henderson
1997-04-10 19:09 ` SIGFPE Richard Henderson
1997-04-10 16:09 SIGFPE Jim Paradis
1997-04-10 11:41 SIGFPE Olaf Flebbe
1997-04-09 19:05 SIGFPE Jim Paradis

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