From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111c93,84278579ba085c08 X-Google-Attributes: gid111c93,public From: michal@gortel.phys.ualberta.ca (Michal Jaegermann) Subject: Re: FP exceptions on redhat 5.1 Date: 1998/09/17 Message-ID: <6ts6st$l6i$1@pulp.ucs.ualberta.ca>#1/1 X-Deja-AN: 392226059 References: Organization: Disorganized Bits Reply-To: michal@gortel.phys.ualberta.ca Newsgroups: comp.os.linux.alpha 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 : 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 #include #include 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)