------- Comment #6 from veksler at il dot ibm dot com  2007-01-17 08:49 -------
(In reply to comment #0)
> The program below shows (at all the optimization levels) a miscompilation of
> the remainder expression that causes INT_MIN % -1 to cause a SIGFPE on CPUs of
> the i386 family.
For the record on Linux i386, this was my suggestion for the best performing
work-around (fastest at least for all cases other than INT_MIN % -1).
Intercept SIGFPE, and if it comes from
  idivl
then set the remainder to 0, and the quotient to INT_MIN (in C/C++ we are
allowed to do this because INT_MIN/-1 is undefined).

There are several technical problems to this suggestion:

(1)
To avoid interference with user assembly code that expects SIGFPE in case of
INT_MIN/-1 (e.g. -ftrapv), the compiler will have to mark this 
  idivl 
in some special way (e.g. add some useless prefixes, or write something
in one of the ELF sections).

(2)
Who should intercept SIGFPE? User space or kernel?

(2.1)
User space is much more complicated, because it might interfere with
other user set SIGFPE signal handlers. libgcc would have to chain
the signal handlers.

(2.2)
If implemented in the kernel then it will take much more time to see this
change propagate to all users. This also means that BSD,Hurd and cygwin 
will all have to use a different fix, each.


-- 

veksler at il dot ibm dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |veksler at il dot ibm dot
                   |                            |com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30484

Reply via email to