lkml.org 
[lkml]   [2003]   [Oct]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRE: Question on SIGFPE
Date
From
Hi Mr Johnson,
Thanks for the mail. Actually I see that there is no fpu_control.h
in my src.

Thanks and Regards
SReeram

---Never doubt that a small group of thoughtful, committed people can
change the world. Indeed, it is the only thing that ever has. -- Copied
from a mail


-----Original Message-----
From: Richard B. Johnson [mailto:root@chaos.analogic.com]
Sent: Thursday, October 30, 2003 6:23 PM
To: Sreeram Kumar Ravinoothala
Cc: Magnus Naeslund(t); Linux kernel
Subject: RE: Question on SIGFPE


On Thu, 30 Oct 2003, Sreeram Kumar Ravinoothala wrote:

> Hi,
> I tried this. It says that the address is 0. And also I saw that
it
> doesn't fall into any of the si_codes of SIGFPE.
>
> Regards
> Sreeram
>

First, to see if it's an access violation (#GP) or an actual FPE, set
the FPU unit to ignore /0 errors. You do it like this:

---------------
/*
* Note FPU control only exists per process. Therefore, you have
* to set up the FPU before you use it in any program.
*/
#include <i386/fpu_control.h>

#define FPU_MASK (_FPU_MASK_IM |\
_FPU_MASK_DM |\
_FPU_MASK_ZM |\
_FPU_MASK_OM |\
_FPU_MASK_UM |\
_FPU_MASK_PM)

void fpu()
{
// __setfpucw(_FPU_DEFAULT & ~FPU_MASK);
__setfpucw(_FPU_DEFAULT);
}


main() {
double zero=0.0;
double one=1.0;
fpu();

one /=zero;
}
--------------

With the above code, you can divide by zero with no problem. If you
unmask, using the FPU_MASK, you get the divide by zero error.

If your program now "functions", you have a real divide by zero error
that may be related to "real-world" data, that was not caught during
your initial testing.

If your program still fails, the error is really caused by the FPU
attempting to access memory you don't own. Note that all floating-pount
numbers exist as memory oprands in Intel stuff. So you could have an
out-of-bounds access or, perhaps, a stack- overflow.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:58    [W:0.027 / U:2.504 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site