public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Wolfgang Grandegger <wg@grandegger•com>
To: Gabriel Paubert <paubert@iram•es>
Cc: linuxppc-dev <Linuxppc-dev@ozlabs•org>
Subject: Re: Floating point exceptions with MPC5200
Date: Mon, 19 Jan 2009 13:10:00 +0100	[thread overview]
Message-ID: <49746D98.9080300@grandegger.com> (raw)
In-Reply-To: <20090119100347.GA27655@iram.es>

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.

      reply	other threads:[~2009-01-19 12:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49746D98.9080300@grandegger.com \
    --to=wg@grandegger$(echo .)com \
    --cc=Linuxppc-dev@ozlabs$(echo .)org \
    --cc=paubert@iram$(echo .)es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox