7 ms·
If it's a power of two, you don't need the branch at all. Let the unsigned index wrap.
by JonChesterfield 6mo ago
If it's a power of two, you don't need the branch at all. Let the unsigned index wrap.
- loeg 6mo agoYou ultimately need a mask to access the correct slot in the ring. But it's true that you can leave unmasked values in your reader/writer indices.
- dalvrosa 6mo agoInteresting, I've never heard about anybody using this. Maybe a bit unreadable? But yeah, should work :)
- mandarax8 6mo agoSee https://fgiesen.wordpress.com/2012/07/21/the-magic-ring-buffer/ https://fgiesen.wordpress.com/2012/07/21/the-magic-ring-buff... which takes it even further :)
- dalvrosa 6mo agoNice one!
- loeg 6mo agoI believe ConcurrencyKit's impl does this. https://github.com/concurrencykit/ck/blob/master/include/ck_ring.h#L124 https://github.com/concurrencykit/ck/blob/master/include/ck_...