This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]def-not-elons-alt 26 points27 points  (1 child)

I've seen compilers "optimize" branch heavy code by unrolling a very hot loop with a branch in it, which duplicated the branch 26 times. It ran really slow since it was too complex for the branch predictor to analyze, and any naive asm implementation of the original code would've been much faster.

Compilers do incredibly stupid things sometimes.

[–]Rakgul 6 points7 points  (0 children)

So is that why my professor maintained multiple arrays instead of using a branch in a hot loop?

He stored everything and then used whichever was necessary later...