* FP exceptions on redhat 5.1 @ 1998-09-11 4:00 Conrad Steenberg 1998-09-12 4:00 ` H.W. Stockman 0 siblings, 1 reply; 12+ messages in thread From: Conrad Steenberg @ 1998-09-11 4:00 UTC (permalink / raw) Hi all I have this really annoying problem with egcs-1.02 that came with Redhat 5.1: A floating point exception would be raised whenever an underflow occurs. My question is this: is there an easy way to disable FP exceptions? I can live with having a few NaN's generated now and again, but I don't want to litter the code with if's to test for underflows... Hope somebody out there can help! Conrad -- *-----------------------------------------* | Conrad Steenberg | | Caltech, Mail Code 220-47 | | Pasadena, CA, 91125 | | e-mail: conrad@srl.caltech.edu | | Tel: (626) 395-2965 Fax: (626) 449-8676 | *-----------------------------------------* ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: FP exceptions on redhat 5.1 1998-09-11 4:00 FP exceptions on redhat 5.1 Conrad Steenberg @ 1998-09-12 4:00 ` H.W. Stockman 1998-09-11 4:00 ` Matt Grossman 1998-09-12 4:00 ` Conrad Steenberg 0 siblings, 2 replies; 12+ messages in thread From: H.W. Stockman @ 1998-09-12 4:00 UTC (permalink / raw) Conrad Steenberg wrote: > > Hi all > > I have this really annoying problem with egcs-1.02 that came with Redhat 5.1: > A floating point exception would be raised whenever an underflow occurs. > > My question is this: is there an easy way to disable FP exceptions? I can live > with having a few NaN's generated now and again, but I don't want to litter > the code with if's to test for underflows... Isn't there a compiler switch to disable IEEE handling of denormals? Most alpha compilers make such a condition the default, since there alpha doesn't handle denormals in hardware. I'm quite curious about the answer, since I'm in the market for a Linux alpha system, would use ecgs, and have code that generates lots of unimportant denormals. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: FP exceptions on redhat 5.1 1998-09-12 4:00 ` H.W. Stockman @ 1998-09-11 4:00 ` Matt Grossman 1998-09-12 4:00 ` Christian Hasse 1998-09-16 4:00 ` Andreas Krall 1998-09-12 4:00 ` Conrad Steenberg 1 sibling, 2 replies; 12+ messages in thread From: Matt Grossman @ 1998-09-11 4:00 UTC (permalink / raw) "H.W. Stockman" <hwstock@wizard.com> writes: > Conrad Steenberg wrote: > > > > Hi all > > > > I have this really annoying problem with egcs-1.02 that came with Redhat 5.1: > > A floating point exception would be raised whenever an underflow occurs. > > > > My question is this: is there an easy way to disable FP exceptions? I can live > > with having a few NaN's generated now and again, but I don't want to litter > > the code with if's to test for underflows... > > Isn't there a compiler switch to disable IEEE handling > of denormals? Most alpha compilers make such a condition > the default, since there alpha doesn't handle denormals > in hardware. Yes, -mieee and friends. Do an "info gcc" and look under Invoking GCC/Submodel Options options for further information. It will probably make your code run slower. Matt Grossman mattg@oz.net http://www.oz.net/~mattg ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: FP exceptions on redhat 5.1 1998-09-11 4:00 ` Matt Grossman @ 1998-09-12 4:00 ` Christian Hasse 1998-09-12 4:00 ` Michal Jaegermann 1998-09-13 4:00 ` Greg Lindahl 1998-09-16 4:00 ` Andreas Krall 1 sibling, 2 replies; 12+ messages in thread From: Christian Hasse @ 1998-09-12 4:00 UTC (permalink / raw) Matt Grossman wrote: > Yes, -mieee and friends. Do an "info gcc" and look under > Invoking GCC/Submodel Options options for further information. > > It will probably make your code run slower. I had to use -mieee with our code (fortran), otherwise we got a lot of floating exceptions. Unfortunately the code runs 50% slower now. This applies to egcs-1.0.2, egcs-1.0.3 and egcs-1.1. I had no such problem with the DEC compilers which obviously handle these problem by default correctly. Christian ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: FP exceptions on redhat 5.1 1998-09-12 4:00 ` Christian Hasse @ 1998-09-12 4:00 ` Michal Jaegermann 1998-09-13 4:00 ` Greg Lindahl 1 sibling, 0 replies; 12+ messages in thread From: Michal Jaegermann @ 1998-09-12 4:00 UTC (permalink / raw) Christian Hasse (c.hasse@itm.rwth-aachen.de) wrote: : I had to use -mieee with our code (fortran), otherwise we got a lot of floating : exceptions. : Unfortunately the code runs 50% slower now. It is **supposed** to be slower. Alpha has to serialize exceptions, insert memory barriers killing pipelines and do some other nasty stuff like that. See compiler documentation for details. You may probably install instead an exception handler which will ignore all this stuff - if you consider that a "correct" solution. Michal ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: FP exceptions on redhat 5.1 1998-09-12 4:00 ` Christian Hasse 1998-09-12 4:00 ` Michal Jaegermann @ 1998-09-13 4:00 ` Greg Lindahl 1 sibling, 0 replies; 12+ messages in thread From: Greg Lindahl @ 1998-09-13 4:00 UTC (permalink / raw) Christian Hasse <c.hasse@itm.rwth-aachen.de> writes: > I had to use -mieee with our code (fortran), otherwise we got a lot > of floating exceptions. Unfortunately the code runs 50% slower now. > This applies to egcs-1.0.2, egcs-1.0.3 and egcs-1.1. I had no such > problem with the DEC compilers which obviously handle these problem > by default correctly. Digital Unix and its compiler are supposed to deal with this problem exactly like Linux and gcc do. If you can provide a small example, I'm sure the egcs people would love to look into it. -- g ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: FP exceptions on redhat 5.1 1998-09-11 4:00 ` Matt Grossman 1998-09-12 4:00 ` Christian Hasse @ 1998-09-16 4:00 ` Andreas Krall 1998-09-16 4:00 ` James D. Freels 1998-09-17 4:00 ` Robert Harley 1 sibling, 2 replies; 12+ messages in thread From: Andreas Krall @ 1998-09-16 4:00 UTC (permalink / raw) In article <m3ww79ncqs.fsf@mattg.oz.net>, Matt Grossman <mattg@oz.net> writes: > "H.W. Stockman" <hwstock@wizard.com> writes: > >> Isn't there a compiler switch to disable IEEE handling >> of denormals? Most alpha compilers make such a condition >> the default, since there alpha doesn't handle denormals >> in hardware. > > Yes, -mieee and friends. Do an "info gcc" and look under > Invoking GCC/Submodel Options options for further information. > I have the problem that these compiler options do not work under Linux(ALpha). I wrote the following small test program: void dotest(double a, double b) { printf("%f / %f = %f\n", a, b, a / b); } int main() { printf("trying to do division by zero in floating point\n"); dotest(0.0, 0.0); dotest(1.0, 0.0); dotest(-1.0, 0.0); return 0; } I compiled this program using gcc with -mieee, egcs with -mieee and the Digital cc with -ieee. The programs works correct (printing NaN's and Inf's) under Digital Unix, but does not work under Linux. Under Linux it just throws an exception. I also tried a static linked version from Digital Unix under Linux and it didn't work, it throws an exception. This shows that the floating point trap handler is integrated into the OS and not linked to the program. The question now is, why does the IEEE arithmetic not work under Linux (Alpha, redhat 4.2). I need this info urgently to release the new version of our Java JIT compiler not only for Digital Unix but also for Linux. Andi -- andi@complang.tuwien.ac.at Andreas Krall http://www.complang.tuwien.ac.at/andi/ Inst. f. Computersprachen, TU Wien tel: (+431) 58801/18511 Argentinierstr. 8/4/1851 fax: (+431) 5057838 A-1040 Wien AUSTRIA EUROPE ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: FP exceptions on redhat 5.1 1998-09-16 4:00 ` Andreas Krall @ 1998-09-16 4:00 ` James D. Freels 1998-09-17 4:00 ` Robert Harley 1 sibling, 0 replies; 12+ messages in thread From: James D. Freels @ 1998-09-16 4:00 UTC (permalink / raw) andi@complang.tuwien.ac.at (Andreas Krall) writes: > I compiled this program using gcc with -mieee, egcs with -mieee and the > Digital cc with -ieee. The programs works correct (printing NaN's and > Inf's) under Digital Unix, but does not work under Linux. Under Linux > it just throws an exception. I also tried a static linked version from > Digital Unix under Linux and it didn't work, it throws an exception. This > shows that the floating point trap handler is integrated into the OS > and not linked to the program. The question now is, why does the IEEE > arithmetic not work under Linux (Alpha, redhat 4.2). I need this info > urgently to release the new version of our Java JIT compiler not only > for Digital Unix but also for Linux. I too have had this same problem with g77. My legacy FORTRAN code will not run correctly under Linux; even with -mieee and/or statically linked DU f77 code. If this problem could be fixed, I would run Linux all the time on the alpha. As it stands now, I must run DU to do my work. One could argue: don't write code with floating point exceptions. Agreed it is bad code, but several hundered thousand lines of legacy FORTRAN is too much to fix. It is cheaper to buy the DU. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: FP exceptions on redhat 5.1 1998-09-16 4:00 ` Andreas Krall 1998-09-16 4:00 ` James D. Freels @ 1998-09-17 4:00 ` Robert Harley 1998-09-17 4:00 ` Michal Jaegermann 1998-09-17 4:00 ` Andreas Krall 1 sibling, 2 replies; 12+ messages in thread From: Robert Harley @ 1998-09-17 4:00 UTC (permalink / raw) andi@complang.tuwien.ac.at (Andreas Krall) writes: > I have the problem that these compiler options do not work under > Linux(ALpha). I wrote the following small test program: > >[...] > I compiled this program using gcc with -mieee, egcs with -mieee and the > Digital cc with -ieee. The programs works correct (printing NaN's and > Inf's) under Digital Unix, but does not work under Linux. Under Linux > it just throws an exception. [...] The difference is that in Digital Unix, no traps are enabled by default. Whereas on Linux, traps for invalid ops, division by zero and overflow are enabled by default. You should do something like this: #include <asm/fpu.h> extern unsigned long ieee_get_fp_control(); extern void ieee_set_fp_control(unsigned long fp_control); ieee_set_fp_control( ieee_get_fp_control() & ~IEEE_TRAP_ENABLE_INV & ~IEEE_TRAP_ENABLE_DZE & ~IEEE_TRAP_ENABLE_OVF ); at the beginning of your thread... >I need this info > urgently to release the new version of our Java JIT compiler not only > for Digital Unix but also for Linux. A new version of Cacao? Send it my way! Rob. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: FP exceptions on redhat 5.1 1998-09-17 4:00 ` Robert Harley @ 1998-09-17 4:00 ` Michal Jaegermann 1998-09-17 4:00 ` Andreas Krall 1 sibling, 0 replies; 12+ messages in thread From: Michal Jaegermann @ 1998-09-17 4:00 UTC (permalink / raw) Robert Harley (harley@corton.inria.fr) wrote: : The difference is that in Digital Unix, no traps are enabled by : default. Whereas on Linux, traps for invalid ops, division by zero : and overflow are enabled by default. : You should do something like this: : #include <asm/fpu.h> : extern unsigned long ieee_get_fp_control(); : extern void ieee_set_fp_control(unsigned long fp_control); : ieee_set_fp_control( ieee_get_fp_control() : & ~IEEE_TRAP_ENABLE_INV : & ~IEEE_TRAP_ENABLE_DZE : & ~IEEE_TRAP_ENABLE_OVF : ); : at the beginning of your thread... Hm, I wonder if this depends on Alpha CPU type and/or libraries. The reason for that is that I checked that on two different EB64+ machines (one is running at the moment RH 5.1, mostly, and the other one RH 5.0) and on both ieee_get_fp_control() returns, in a default settings, 0L. In any case, if you want to see what your machine is doing when you ask it to do something stupid in a floating point :-) here is a small demo program and a simple makefile for various hacks: Enjoy, Michal ***** xpm.c ***** /* * This program demonstrates various ways of disabling floating * point traps on Linux/Alpha. * Installing your own "do nothing" signal handles disables * traps in floating poing completely but, as you can see, may * have consequences which you may not like. * Using various -mieee.... options (see 'info gcc' for discussion) * forces serialization of exception handling which can be processed * then according with IEEE rules - this carries an extra cost. * * To install "ignore" handler in a Fortran program write that in C * and link with your Fortran using usual conventions. * * To "really ignore" floating point exception signal just return * from 'handler' */ #include <stdio.h> #include <signal.h> #include <asm/fpu.h> extern unsigned long ieee_get_fp_control(); extern void ieee_set_fp_control(unsigned long fp_control); #ifdef PRIVATE_HANDLER static void handler(int x) { fprintf(stdout, "ignoring signal %d\t", x); return; } void install_fpe_handler(void) { signal(SIGFPE, &handler); return; } #else void install_fpe_handler(void) { return; /* do nothing */ } #endif void traptest(double a, double b) { double result = a / b; printf("%g / %g = %g\n", a, b, result); /* printf("%f / %f = %f\n", a, b, result); */ } /* On Linux/Alpha traps for invalid ops, division by zero and overflow may be enabled - depending on library versions (?) */ int main(void) { printf("fpu mask is 0x%016lx\n", ieee_get_fp_control()); install_fpe_handler(); #ifdef DISABLE_TRAPS # warning "disabling invalid ops, division by zero and overflow traps" ieee_set_fp_control( ieee_get_fp_control() & ~IEEE_TRAP_ENABLE_INV & ~IEEE_TRAP_ENABLE_DZE & ~IEEE_TRAP_ENABLE_OVF ); printf("fpu mask is 0x%016lx\n", ieee_get_fp_control()); /* ieee_set_fp_control(-1L); *//* uncommenting this enables all in sight */ /* ieee_set_fp_control(IEEE_TRAP_ENABLE_MASK); */ #endif /* DISABLE_TRAPS */ printf("fpu mask is 0x%016lx\n", ieee_get_fp_control()); printf("trying to cause various traps in floating point\n"); traptest(0.0, 0.0); traptest(1.0, 0.0); traptest(-1.0, 0.0); traptest(1.0, 1.0e+309); traptest(1.0, 1.0e-309); return 0; } ***** Makefile ***** CFLAGS = -g -Wall -O2 MFLAGS = -mieee-with-inexact #MFLAGS = -mieee HFLAGS = -DPRIVATE_HANDLER DFLAGS = -DDISABLE_TRAPS PROGS = xpm xpmm xpmd xpmmd xpmh xpmmh xpmhd xpmmhd all: $(PROGS) xpm: $(CC) $(CFLAGS) -o $@ xpm.c xpmm: $(CC) $(CFLAGS) $(MFLAGS) -o $@ xpm.c xpmd: $(CC) $(CFLAGS) $(DFLAGS) -o $@ xpm.c xpmmd: $(CC) $(CFLAGS) $(MFLAGS) $(DFLAGS) -o $@ xpm.c xpmh: $(CC) $(CFLAGS) $(HFLAGS) -o $@ xpm.c xpmmh: $(CC) $(CFLAGS) $(MFLAGS) $(HFLAGS) -o $@ xpm.c xpmhd: $(CC) $(CFLAGS) $(HFLAGS) $(DFLAGS) -o $@ xpm.c xpmmhd: $(CC) $(CFLAGS) $(MFLAGS) $(HFLAGS) $(DFLAGS) -o $@ xpm.c run: $(PROGS) for f in $(PROGS) ; do echo $$f ; ./$$f || echo "TRAP" ; done clean: rm -f $(PROGS) ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: FP exceptions on redhat 5.1 1998-09-17 4:00 ` Robert Harley 1998-09-17 4:00 ` Michal Jaegermann @ 1998-09-17 4:00 ` Andreas Krall 1 sibling, 0 replies; 12+ messages in thread From: Andreas Krall @ 1998-09-17 4:00 UTC (permalink / raw) In article <rz7sohrc8tb.fsf@corton.inria.fr>, Robert Harley <harley@corton.inria.fr> writes: > > andi@complang.tuwien.ac.at (Andreas Krall) writes: >> I have the problem that these compiler options do not work under >> Linux(ALpha). I wrote the following small test program: >> >>[...] >> I compiled this program using gcc with -mieee, egcs with -mieee and the >> Digital cc with -ieee. The programs works correct (printing NaN's and >> Inf's) under Digital Unix, but does not work under Linux. Under Linux >> it just throws an exception. [...] > > The difference is that in Digital Unix, no traps are enabled by > default. Whereas on Linux, traps for invalid ops, division by zero > and overflow are enabled by default. > > > You should do something like this: > > #include <asm/fpu.h> > extern unsigned long ieee_get_fp_control(); > extern void ieee_set_fp_control(unsigned long fp_control); > > ieee_set_fp_control( ieee_get_fp_control() > & ~IEEE_TRAP_ENABLE_INV > & ~IEEE_TRAP_ENABLE_DZE > & ~IEEE_TRAP_ENABLE_OVF > ); > > at the beginning of your thread... Thanks, no it works. -- andi@complang.tuwien.ac.at Andreas Krall http://www.complang.tuwien.ac.at/andi/ Inst. f. Computersprachen, TU Wien tel: (+431) 58801/18511 Argentinierstr. 8/4/1851 fax: (+431) 5057838 A-1040 Wien AUSTRIA EUROPE ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: FP exceptions on redhat 5.1 1998-09-12 4:00 ` H.W. Stockman 1998-09-11 4:00 ` Matt Grossman @ 1998-09-12 4:00 ` Conrad Steenberg 1 sibling, 0 replies; 12+ messages in thread From: Conrad Steenberg @ 1998-09-12 4:00 UTC (permalink / raw) On Sat, 12 Sep 1998 01:08:19 GMT, H.W. Stockman <hwstock@wizard.com> wrote: >Isn't there a compiler switch to disable IEEE handling >of denormals? Most alpha compilers make such a condition >the default, since there alpha doesn't handle denormals >in hardware. > >I'm quite curious about the answer, since I'm in the >market for a Linux alpha system, would use ecgs, and >have code that generates lots of unimportant denormals. Thanks to everyone that replied. I took the quick and dirty way out by installing a signal handler for SIGFPE that just returns and does nothing. I will look at the suggested compiled switches on Monday when I get back to the alpha box and see if that makes any difference in speed. Just for trivia, here are the times for the code I run (yes, it is not a bench- mark, I know...) 1. Pentium Pro 200 MHz, Linux 2.0.30 with gcc 2.7.2.1: ~12h20 2. Sun ULTRASparc II 266 MHz, Solaris 2.6, Sun cc ?.?: ~19h45 3. IBM SP PowerII 300 MHz, AIX 4.1.4, xlc ?.? : ~17h05 4. Microway Alpha 533 MHz, Linux 2.0.35, egcs 1.02 : ~ 6h24 5. Pentium II 266 MHz, Linux 2.0.30, gcc 2.7.2.1 : ~14h30 Some observations: 1. I'm very uncertain about the IBM SP chip frequency, the thing didn't exactly sit on my desk ! 2. The Pentium Pro really performed extraordinarily well, my guess is that its memory access patterns suited the 256k on-board cache really well. 3. Probably for the same reason, the Pentium II's slower on-board cache made it much slower than the Pro. I guess the Xeons will remedy that, at a huge price. 4. From the above it would take about a 600 MHz Pentium II to bring the run time down to the level of the Alpha. Which means I'm very happy with the Alpha! If any one is interested, The Alpha is the "performance value special" with IDE disk and CDROM for $2800 without monitor. See www.microway.com for all the specs. Regards Conrad -- *-----------------------------------------* | Conrad Steenberg | | Caltech, Mail Code 220-47 | | Pasadena, CA, 91125 | | e-mail: conrad@srl.caltech.edu | | Tel: (626) 395-2965 Fax: (626) 449-8676 | *-----------------------------------------* ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~1998-09-17 4:00 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 1998-09-11 4:00 FP exceptions on redhat 5.1 Conrad Steenberg 1998-09-12 4:00 ` H.W. Stockman 1998-09-11 4:00 ` Matt Grossman 1998-09-12 4:00 ` Christian Hasse 1998-09-12 4:00 ` Michal Jaegermann 1998-09-13 4:00 ` Greg Lindahl 1998-09-16 4:00 ` Andreas Krall 1998-09-16 4:00 ` James D. Freels 1998-09-17 4:00 ` Robert Harley 1998-09-17 4:00 ` Michal Jaegermann 1998-09-17 4:00 ` Andreas Krall 1998-09-12 4:00 ` Conrad Steenberg
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox