linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Floating point exceptions with MPC5200
@ 2009-01-19  9:33 Wolfgang Grandegger
  2009-01-19  9:50 ` Andreas Schwab
  2009-01-19 10:03 ` Gabriel Paubert
  0 siblings, 2 replies; 5+ messages in thread
From: Wolfgang Grandegger @ 2009-01-19  9:33 UTC (permalink / raw)
  To: linuxppc-dev

Hello,

I want to provoke a "floating point exception" by doing a division by 0.
The expection does come as expected on my x86 PC:

  $ ./divby0
  Floating point exception

but not on my MPC5200 board. Any idea why? I think the processor can
handle all floating-point exceptions. I'm using Linux 2.6.28 and the
ELDK v4.2.

Wolfgang.

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

* Re: Floating point exceptions with MPC5200
  2009-01-19  9:33 Floating point exceptions with MPC5200 Wolfgang Grandegger
@ 2009-01-19  9:50 ` Andreas Schwab
  2009-01-19  9:58   ` Wolfgang Grandegger
  2009-01-19 10:03 ` Gabriel Paubert
  1 sibling, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2009-01-19  9:50 UTC (permalink / raw)
  To: Wolfgang Grandegger; +Cc: linuxppc-dev

Wolfgang Grandegger <wg@grandegger.com> writes:

> I want to provoke a "floating point exception" by doing a division by 0.

Division by 0 is undefined, so you cannot expect any kind of outcome.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: Floating point exceptions with MPC5200
  2009-01-19  9:50 ` Andreas Schwab
@ 2009-01-19  9:58   ` Wolfgang Grandegger
  0 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Grandegger @ 2009-01-19  9:58 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: linuxppc-dev

Andreas Schwab wrote:
> Wolfgang Grandegger <wg@grandegger.com> writes:
> 
>> I want to provoke a "floating point exception" by doing a division by 0.
> 
> Division by 0 is undefined, so you cannot expect any kind of outcome.

Hm, even not a "floating point exception" signal like on x86?

Wolfgang.

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

* Re: Floating point exceptions with MPC5200
  2009-01-19  9:33 Floating point exceptions with MPC5200 Wolfgang Grandegger
  2009-01-19  9:50 ` Andreas Schwab
@ 2009-01-19 10:03 ` Gabriel Paubert
  2009-01-19 12:10   ` Wolfgang Grandegger
  1 sibling, 1 reply; 5+ messages in thread
From: Gabriel Paubert @ 2009-01-19 10:03 UTC (permalink / raw)
  To: Wolfgang Grandegger; +Cc: linuxppc-dev

On Mon, Jan 19, 2009 at 10:33:40AM +0100, Wolfgang Grandegger wrote:
> Hello,
> 
> I want to provoke a "floating point exception" by doing a division by 0.
> The expection does come as expected on my x86 PC:
> 
>   $ ./divby0
>   Floating point exception
> 
> but not on my MPC5200 board. Any idea why? I think the processor can
> handle all floating-point exceptions. I'm using Linux 2.6.28 and the
> ELDK v4.2.

No, the PPC continue happily after performing an _integer_ division by zero.
It is in the architecture specification AFAIR and allowed by C and other 
language definitions. 

This is not exactly a floating point exception per se: it has a different
vector on x86, that the Linux kernel remaps to a floating point exception,
although numeric exception would be more correct. PPC implements all 
standard IEEE754 floating point exceptions (you have to enable them 
with fesetenv() or something equivalent, but it's the same on all 
architectures).

Even the C++ headers acknowledge this, see for example: 
/usr/include/c++/4.3/powerpc-linux-gnu/bits/cpu_defines.h
(or a similar file on your system, note that older versions
of GCC got it wrong, but I can't remember when it was fixed).

	Gabriel

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

* Re: Floating point exceptions with MPC5200
  2009-01-19 10:03 ` Gabriel Paubert
@ 2009-01-19 12:10   ` Wolfgang Grandegger
  0 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Grandegger @ 2009-01-19 12:10 UTC (permalink / raw)
  To: Gabriel Paubert; +Cc: linuxppc-dev

Gabriel Paubert wrote:
> On Mon, Jan 19, 2009 at 10:33:40AM +0100, Wolfgang Grandegger wrote:
>> Hello,
>>
>> I want to provoke a "floating point exception" by doing a division by 0.
>> The expection does come as expected on my x86 PC:
>>
>>   $ ./divby0
>>   Floating point exception
>>
>> but not on my MPC5200 board. Any idea why? I think the processor can
>> handle all floating-point exceptions. I'm using Linux 2.6.28 and the
>> ELDK v4.2.
> 
> No, the PPC continue happily after performing an _integer_ division by zero.
> It is in the architecture specification AFAIR and allowed by C and other 
> language definitions. 
> 
> This is not exactly a floating point exception per se: it has a different
> vector on x86, that the Linux kernel remaps to a floating point exception,
> although numeric exception would be more correct. PPC implements all 
> standard IEEE754 floating point exceptions (you have to enable them 
> with fesetenv() or something equivalent, but it's the same on all 
> architectures).
> 
> Even the C++ headers acknowledge this, see for example: 
> /usr/include/c++/4.3/powerpc-linux-gnu/bits/cpu_defines.h
> (or a similar file on your system, note that older versions
> of GCC got it wrong, but I can't remember when it was fixed).

I get the "Floating point exception" signal when I explicitly enable
them with fesetenv() as you suggested:

  $ cat divby0.c
  #include <stdio.h>
  #define __USE_GNU
  #include <fenv.h>

  int main(int argc, char* argv[])
  {
      double fa = 10., fb = 0., fc;
      int ia = 10, ib = 0, ic;

      printf("excepts=%#x\n", fegetexcept());
      fesetenv(FE_NOMASK_ENV);
      printf("excepts=%#x\n", fegetexcept());

      ic = ia / ib;
      printf("ic=%d\n", ic);

      fc = fa / fb;
      printf("c=%f\n", fc);

      return 0;
  }

  $ ./divby0
  excepts=0
  excepts=0x3e000000
  ic=0
  Floating point exception

See "man fesetenv" for further information. On the x86 PC, I even get a
SIGFPE signal for the integer division by 0.

Thanks for the quick help.

Wolfgang.

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

end of thread, other threads:[~2009-01-19 12:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-19  9:33 Floating point exceptions with MPC5200 Wolfgang Grandegger
2009-01-19  9:50 ` Andreas Schwab
2009-01-19  9:58   ` Wolfgang Grandegger
2009-01-19 10:03 ` Gabriel Paubert
2009-01-19 12:10   ` Wolfgang Grandegger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).