Pragma Unroll
sandordargo.com·13w·
Discuss: Hacker News

After conferences, I often write a couple of short articles about features or techniques I learned about, even if I don’t always find them particularly useful in my own work.

At a recent talk, Andrei Alexandrescu mentioned the unroll pragma. I knew what loop unrolling was, but I had never used it and had never seen the pragma before. So let’s dive into it.

What is loop unrolling?

Loop unrolling is a performance optimization technique that reduces the overhead of loop control instructions and can improve opportunities for parallel execution.

Normally, when a loop runs, three things happen in addition to executing the loop body:

  • the loop counter is incremented,
  • the loop condition is checked,
  • and the program jumps back to the start of the loop.

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help