This is the mail archive of the gcc-help@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: Efficient detection of signed overflow?


On Sun, 2009-11-29 at 16:00 -0500, me22 wrote:

> 
> What about using (long)((unsigned long)a + (unsigned long)b) or
> something to get around the UB?

Type casting may be ineffective. On x86-64 in 64-bit mode gcc (4.4.1)
generates unsigned addition. That is,

x = a + b;

is implemented as

leaq	(%rdx,%rax), %rbx

The leaq instruction has no effect on the rflags register. Hence, even
if we could test the overflow bit, it would not be accurate.

--Bob



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