This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New no-undefined-overflow branch


Ian Lance Taylor wrote:
Richard Earnshaw <rearnsha@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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]