Ian Lance Taylor wrote:
Richard Earnshaw <rearn...@arm.com> writes:

On Fri, 2009-03-06 at 16:09 +0100, Paolo Bonzini wrote:
If this does not work, on ARM you can also hope for something like this:

     ADD    R0, R1, R2
     XORS   R0, R2, R3
     XORSMI R1, R2, R3
     SWIMI  #trap
On ARM you can just check for overflow directly...

        ADDS    R0, R1, R2
        SWIVS   #trap

This point should not be missed.  Some processors (MIPS) have trapping
arithmetic instructions, but many processors have an overflow flag which
can be tested.  Any useful design for -ftrapv needs to make it possible
to use that overflow flag in the generated code.  It will always be more
efficient than using arithmetic to check for overflow.

One needs to be careful on efficiency here, thinking about pipelines
etc. for example, into looks nice on the x86, but can be expensive to
use compared with explicit tests of the overflow flag.

Ian

Reply via email to