3 ms·
> most loops are actually implemented as branches. No kidding! But the article does call attention to a very important technique. It merits serious thought o
by ncmncm 7y ago
> most loops are actually implemented as branches.
No kidding!
But the article does call attention to a very important technique. It merits serious thought over all the ways it can be applied, that may not look much like this one, on the surface.
- ithkuil 7y ago> no kidding Well, that also means that some loops are fully unrolled :-)
- mac01021 7y agoAnd some loops use only unconditional jumps.
- ithkuil 7y agoYes, those of the infinite variety
- 0xdeadbeefbabe 7y agoHaven't seen any, and I never expect to. (will it halt? == yes)
- ithkuil 7y agosure, pulling the plug is perfectly valid mechanism for terminating a loop, albeit an external one :-)
- sifar 7y agoMost DSPs have zero overhead loops (still branches) which don't incur a branch penalty. So something like below may take 1-2 cycles atmost, per iteration. for(i=0;i<howmany;i++) { out[index] = random(); } Ofcourse variable length loops would still have the branches.
- ncmncm 7y agoHaswell and later can run loops with 4 instructions, including 2 ALU ops and two conditional branches -- provided only one is taken -- in one cycle. Compilers prefer to order the instructions so they take two or more cycles.