3 ms·
Why not just (a >> 1) + (b >> 1) + (a & 1) & (b & 1)
by dheera 5y ago
Why not just
(a >> 1) + (b >> 1) + (a & 1) & (b & 1)
- dreamcompiler 5y agoThat's the "patented solution" referred to in the article.
- Dylan16807 5y ago"just"? That's 2 additions, 2 shifts, and 2-3 bitwise operations, while the other method is 1 addition, 1 shift, and 2 bitwise operations.
- rustybolt 5y agoI would think optimizing compilers can optimize this expression to the one in the article, but I tried it on godbolt and they don't.