Re:I've been writing ring buffers wrong all these years
by pklausler on Wednesday December 14, 2016 @12:45PM
(#13177951)
Oh, come on, you don't need a branch to do a conditional subtraction. Reify the condition to 0/1 and use multiplication, or use AND with a two's complement of the condition.
[ Parent
| on HN ]
Re:I've been writing ring buffers wrong all these years
by cksk on Thursday December 15, 2016 @11:44AM
(#13185891)
OK, my bit twiddling knowledge is weak, my google skills are weaker still, and now I'm curious: what does "AND with a two's complement of the condition" mean, exactly?
Re:I've been writing ring buffers wrong all these years
by pklausler on Thursday December 15, 2016 @12:41PM
(#13186424)
x -= N & -(x >= N);
Re:I've been writing ring buffers wrong all these years
by cksk on Thursday December 15, 2016 @01:20PM
(#13186767)
Ohh, nice, I get it now. Thanks a lot!