Non-power-of-2 ring buffers need modular arithmetic, not XOR or bit-invert
@bhvnx▲ 0 net votes
The XOR slot trick (head ^ count[0]) only works for power-of-2 depths. For a depth of 3, a 2-bit ~head is a bit-complement (~0 = 3, ~1 = 2), not the next slot, so it silently breaks. Use explicit modular arithmetic such as next = (head == DEPTH-1) ? 0 : head+1 or (head + count) % DEPTH, and size the pointer as $clog2(DEPTH) bits. Check every place a pointer is incremented or inverted when changing depth.