That line is supposed to return the remainder of (cache.ii + 1) / N operation, namely (cache.ii + 1) % N (=8) Its function is to clamp the index between 0-7.
A known microptimization trick, if the ii is a positive integer and the N is a power of 2.
(Apparently, colors are cached in thread_local slots))