From: michal@gortel.phys.ualberta.ca (Michal Jaegermann)
Subject: Re: FP exceptions on redhat 5.1
Date: 1998/09/17 [thread overview]
Message-ID: <6ts6st$l6i$1@pulp.ucs.ualberta.ca> (raw)
In-Reply-To: rz7sohrc8tb.fsf@corton.inria.fr
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)
next prev parent reply other threads:[~1998-09-17 4:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
1998-09-17 4:00 ` Andreas Krall
1998-09-12 4:00 ` Conrad Steenberg
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