by ThePadawan · 7y ago · 0 comments
Notably, branching on a flag f on the GPU was so slow that most of the time it was faster to (manually) compute both branches b1 and b2 and then calculate the result as r = f * b1 + (1-f) * b2 (where f is either 0 or 1).
You trade it off with increased code size which might spill the cache but for small tight loops not exceeding the cache line/ size it would still be a good win.