Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* SIGFPE -- the answer
@ 1997-04-17  3:05 Jim Paradis
  0 siblings, 0 replies; 8+ messages in thread
From: Jim Paradis @ 1997-04-17  3:05 UTC (permalink / raw)


[ cc'ed to axp-list for everyone's edification ]
Randy,

I can be soooo dense sometimes.  Remember the divide-by-zero
exception handling problem you were having?  I figured out what
was *really* going on.

Seeing as I wrote the floating-point emulation code for Linux/Alpha
(or, more accurately, I wrote the code for another project which I
then gave to David M-T to hammer into the Linux sources), I shoulda
known this.

Anyhow: there is a way to turn off those nasty SIGFPE's and get the
results you want.  It's a "secret" system call (osf_setsysinfo) 
which can be used to set the floating-point exception enable bits 
in the process struct.

Here's da goods:  To read and write the floating-point exception 
enable bits, you can use the following routines:

	#include <asm/fpu.h>

	#define __NR_getsysinfo 256
	#define __NR_setsysinfo 257

	unsigned long read_fpe_bits()
	{
	    unsigned long fpcw;
	    syscall(__NR_getsysinfo, 45, &fpcw, sizeof(fpcw), 0, 0);
	    return(fpcw & IEEE_TRAP_ENABLE_MASK);
	}

	void write_fpe_bits(unsigned long fpcw)
	{
	    syscall(__NR_setsysinfo, 14, &fpcw, sizeof(fpcw), 0, 0);
	}

The bits themselves are defined in /usr/include/asm/fpu.h.
Look for "IEEE_TRAP_ENABLE_xxx".  Apparently INV (invalid operand),
DZE (divide-by-zero) and OVF (overflow) are turned ON by default
for all processes, and you have to turn them off manually.

Hope this helps!

-- 
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 -- the answer
@ 1997-04-17 10:45 Uncle George
  0 siblings, 0 replies; 8+ messages in thread
From: Uncle George @ 1997-04-17 10:45 UTC (permalink / raw)


My impression was that the linux's were behaveing differently
(intel/axp).
should this FPE bit be normally disabled, so as to to be compatable?

-- 
Uncle George ( aka G. Baeslack )
http://www.voicenet.com/~gatgul

--
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 -- the answer
       [not found] <33559394.1AD81EDB@jrp.tiac.net>
@ 1997-04-17 19:51 ` Richard Henderson
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 1997-04-17 19:51 UTC (permalink / raw)


> Here's da goods:  To read and write the floating-point exception 
> enable bits, you can use the following routines:

Linux follows DEC in calling those functions ieee_get_fp_control()
and ieee_set_fp_control() respectively.

And to answer the question that came up elsewhere: those bits are
on by default on Linux/Alpha because they are on by default on DU.

r~

--
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 -- the answer
@ 1997-04-18  2:02 Jim Paradis
  0 siblings, 0 replies; 8+ messages in thread
From: Jim Paradis @ 1997-04-18  2:02 UTC (permalink / raw)


Richard Henderson wrote:
> Linux follows DEC in calling those functions ieee_get_fp_control()
> and ieee_set_fp_control() respectively.

Ahhh... thanks!  Usually when I chase these things down I start
with the kernel sources and work up rather than starting with the
library documentation and working down 8-)

> And to answer the question that came up elsewhere: those bits are
> on by default on Linux/Alpha because they are on by default on DU.

Hmmmm.... if there were some way to tell a DU executable from a
Linux/Alpha executable, we'd be ahead of the game.

Does crt0 call sys_personality on Linux/Alpha the way it does on
Linux/x86?

-- 
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 -- the answer
@ 1997-04-18  4:39 Randy Chapman
  0 siblings, 0 replies; 8+ messages in thread
From: Randy Chapman @ 1997-04-18  4:39 UTC (permalink / raw)


In article <3356D61F.78ED3FC1@jrp.tiac.net> you wrote:
: > And to answer the question that came up elsewhere: those bits are
: > on by default on Linux/Alpha because they are on by default on DU.
: 
: Hmmmm.... if there were some way to tell a DU executable from a
: Linux/Alpha executable, we'd be ahead of the game.
: 
: Does crt0 call sys_personality on Linux/Alpha the way it does on
: Linux/x86?

Hrm.  Could one modify glibc/axp to call that and set it into ieee mode ?

--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 -- the answer
       [not found] <3356D61F.78ED3FC1@jrp.tiac.net>
@ 1997-04-21 18:32 ` Richard Henderson
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 1997-04-21 18:32 UTC (permalink / raw)


> Does crt0 call sys_personality on Linux/Alpha the way it does on
> Linux/x86?

Yes.  And, if folks think it worthwhile, we can change what
crt0 sets the fpcr to at startup.  Until now it hadn't been
an issue.

r~

--
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 -- the answer
@ 1997-04-22  0:51 David Mosberger-Tang
  0 siblings, 0 replies; 8+ messages in thread
From: David Mosberger-Tang @ 1997-04-22  0:51 UTC (permalink / raw)


[I'm replying to a mail that appeared in the axp-list mailing list archive.
 I may have missed some follow-ups and apologize if this is an old hat...]

 Jim> Here's da goods:  To read and write the floating-point exception 
 Jim> enable bits, you can use the following routines:

 Richard> Linux follows DEC in calling those functions ieee_get_fp_control()
 Richard> and ieee_set_fp_control() respectively.

Yes, those routines are for DEC Unix compatibility (not binary
compatibility, but to make it easier to port DEC Unix source code to
Linux/Alpha).  However, there is also the setfpucw() call which is
there for Linux/x86 compatibility.

 Richard> And to answer the question that came up elsewhere: those bits are
 Richard> on by default on Linux/Alpha because they are on by default on DU.

For the kernel that is true.  For Linux application, the behaviour _should_
be the same as for Linux/x86.  glibc's init-first.c has the following
call:

      /* Set the FPU control word to the proper default value.  */
      __setfpucw (__fpu_control);

This is intented to establish the same environment as under Linux/x86
(modulo extendend precision).  But I think it would be an exaggeration
to claim that this code has been thoroughly tested, so it wouldn't
surprise me if things do not fully work as intended.

	--david

--
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 -- the answer
@ 1997-04-22 14:49 Randy Chapman
  0 siblings, 0 replies; 8+ messages in thread
From: Randy Chapman @ 1997-04-22 14:49 UTC (permalink / raw)


In article <199704220051.RAA05084@panda.mosberger> you wrote:
: [I'm replying to a mail that appeared in the axp-list mailing list archive.
:  I may have missed some follow-ups and apologize if this is an old hat...]
: 
:  Jim> Here's da goods:  To read and write the floating-point exception 
:  Jim> enable bits, you can use the following routines:
: 
:  Richard> Linux follows DEC in calling those functions ieee_get_fp_control()
:  Richard> and ieee_set_fp_control() respectively.
: 
: Yes, those routines are for DEC Unix compatibility (not binary
: compatibility, but to make it easier to port DEC Unix source code to
: Linux/Alpha).  However, there is also the setfpucw() call which is
: there for Linux/x86 compatibility.
:
...
: 
: For the kernel that is true.  For Linux application, the behaviour _should_
: be the same as for Linux/x86.  glibc's init-first.c has the following
: call:
: 
:       /* Set the FPU control word to the proper default value.  */
:       __setfpucw (__fpu_control);
: 
: This is intented to establish the same environment as under Linux/x86
: (modulo extendend precision).  But I think it would be an exaggeration
: to claim that this code has been thoroughly tested, so it wouldn't
: surprise me if things do not fully work as intended.

Hrm.  The ieee_set_fp_control() thing *definitely* changed the behavior
of the Java runtime for the better.  I am highly suspicious
that __setfpucw() doesn't work at all.  I tried setting something
with it and reading the cw back in and I don't recall that it had
even changed =(

thanks,
--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

end of thread, other threads:[~1997-04-22 14:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-04-17  3:05 SIGFPE -- the answer Jim Paradis
  -- strict thread matches above, loose matches on Subject: below --
1997-04-17 10:45 Uncle George
     [not found] <33559394.1AD81EDB@jrp.tiac.net>
1997-04-17 19:51 ` Richard Henderson
1997-04-18  2:02 Jim Paradis
1997-04-18  4:39 Randy Chapman
     [not found] <3356D61F.78ED3FC1@jrp.tiac.net>
1997-04-21 18:32 ` Richard Henderson
1997-04-22  0:51 David Mosberger-Tang
1997-04-22 14:49 Randy Chapman

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