Ian Lance Taylor wrote:
Joe Buck <[EMAIL PROTECTED]> writes:

How will the kernel know whether the overflow in the divide instruction
is because the user's source code has a '%' and not a '/'?  We generate
the exact same instruction for i / minus_one(), after all, and in that
case the trap really should be there.

We don't need to generate a trap for INT_MIN / -1.  That is undefined
signed overflow.  We can legitimately set the quotient register to
INT_MIN while setting the remainder register to zero.  (Hmmm, what
should we do if -ftrapv is set?  Probably generate a different code
sequence in the compiler.)
Simply let the kernel/libc set the overflow flag in this case, and let the compiler
append an INTO instruction right after the idivl.
We do want to generate a trap for x / 0, of course.

Ian



--
Michael Veksler
http:///tx.technion.ac.il/~mveksler

Reply via email to