Comment by ahartmetz
5 hours ago
You want to avoid branches in hot paths. If you branch inside the loop, lots of branches. If you branch outside the loop (into different specialized loops), few branches. Big fucking deal.
5 hours ago
You want to avoid branches in hot paths. If you branch inside the loop, lots of branches. If you branch outside the loop (into different specialized loops), few branches. Big fucking deal.
https://en.wikipedia.org/wiki/Loop_unswitching
Slower but prettier with the if pushed down.
Is that true? The loop is a branch.
Who actually considers a loop a branch? A loop is a chunk of code that will be run N times depending on some evaluation that’s run before or after an iteration. A branch is a single decision which of several pieces of code to run, once.
> Who actually considers a loop a branch?
A loop contains a branch - keep looping or break. At least according to structured programming -- https://en.wikipedia.org/wiki/Structured_program_theorem.
>Who actually considers a loop a branch?
The machine?
The "go around" branch is obviously not completely avoidable (though unrolling helps). Branches inside the loop body sometimes are.