lazyweb, let's say I have `uintmax_t a, b;`. I need to figure out if `a + b` has carry-out. by definition I can't put the result in a wider integer type; what's a good portable way to do this anyway?
-
-
Replying to @whitequark
I know I'm late to the party but since I looked into those patterns for RISC-V BitManip Carry / Unsigned Overflow: a+b < a Signed Overflow: (a+b < a) != (b < 0) (modulo bugs. I am afk so this is off the top of my head. :)
1 reply 0 retweets 9 likes -
Replying to @oe1cxw @whitequark
Signed version isn't valid C. Unsigned one is okay though.
1 reply 0 retweets 6 likes -
Replying to @RichFelker @whitequark
Oh, yeah, good catch. Didn't care about that in the BitManip work because there it's written in RISC-V asm. :)pic.twitter.com/2dQT78AYCP
1 reply 0 retweets 4 likes -
And here ist adding three values (a0, a1, and a2) with sum output in a0 and carry-out in a1.pic.twitter.com/CCWquRDDag
1 reply 0 retweets 1 like
(looking at this again I think the "or" at the end should be an "add" so that it works for any input values, producing a two-bit carry-out when needed.)
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.