testing for arithmetic carry

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

 



Hi.

  Suppose I have the following unsigned integer variables, a0, a1, b0, b1, r0 r1. The operation that is performed is:
        r0 = a0 + b0
        r1 = a1 + b1 + carry from previous addition
        if ( carry in r1 calculation) do something

This is done straight forward on assembly language, assuming 'add' and 'add with carry' are provided by CPU. Is there a way in C to test for carry from last addition ? Some GCC extensions (not ASM(...) ;)?

  There is of course method of testing whether r0 is less then a0 (for detecting first carry), and the second carry can be inferred by two comparison operations. Is GCC optimizing with -O2 able to reduce the comparisons to actual 'add-with-carry' and 'branch-if-carry' operations in assembly ?

Thanks, regards,
  Dima.

P.S.
  Please CC my address, as I am not on the list.


[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