News for hackers. Stuff that matters.
Re:Source code for Quake 2 rerelease by scott_s on Friday August 11, 2023 @11:11AM (#37089591)
Seconded that the main reason was probably avoiding a mod. But it's not because of the compiler, but the processor. Mod and division instructions are always more expensive than additions and multiplications. If this function was on the hot path (and looking at where it's called, it's at least called once per frame), that may have mattered a lot.
Re:Source code for Quake 2 rerelease by Sharlin on Friday August 11, 2023 @12:41PM (#37090725)
A modern optimizing compiler would quite likely do induction variable elimination/strength reduction and replace the % with increment-and-reset if it deemed it worth it, so it’s also about the compiler.