Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What about "addWithCarry", ie. ADC? Getting the carry bit seems only half the battle. I'd not seen this compiler tool before so had a quick play around with it. It's very cool! But I couldn't get a compiler to recognise it could use ADC.


This seems to work. The compiler has to see the previous add to know what is in the carry flag.

    #include <stdint.h>

    uint64_t addWithCarry(uint64_t x, uint64_t y, uint64_t z) {
        return x + y + (y + z < y);
    }
Output here: https://godbolt.org/z/zfP7PnGcs




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: