Skip to contentSkip to conversation

Floating point exceptions with MPC5200

DISCUSSION Wolfgang Grandegger 3 participants 5 messages Jan 19, 2009

lore
Share & tools
lore
#0 lore raw

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.

#1 lore raw
Quoted 1 line · Wolfgang Grandegger

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.

Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected]
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."
#2 lore raw
Quoted 5 lines · Andreas Schwab
Quoted 1 line · Wolfgang Grandegger

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.

#3 lore raw
In reply to Wolfgang Grandegger
Quoted 11 lines · Wolfgang Grandegger

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

#4 lore raw
Quoted 24 lines · Gabriel Paubert
Quoted 11 lines · Wolfgang Grandegger

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).

Quoted 4 lines

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.