Re: Efficient detection of signed overflow?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux