News for hackers. Stuff that matters.
Re:Using black magic to make a fast circular buffer by ahartmetz on Saturday January 11, 2025 @08:41PM (#42670486)
Actually, even "if (pos >= bufSize) { pos -= bufSize; }" is much faster than pos = pos % bufSize. Division (and modulo) are like the only basic math operations that a modern wide ALU doesn't easily do three to four of per cycle (they are much more expensive), OTOH easily predicted branches are fairly cheap (or even compiled into conditional moves here).

There are no comments on this comment yet.