Skip to content

Instantly share code, notes, and snippets.

@tuckerzp
Last active December 5, 2019 21:30
Show Gist options
  • Select an option

  • Save tuckerzp/5a0611c437bffdf45a75224b669a27ef to your computer and use it in GitHub Desktop.

Select an option

Save tuckerzp/5a0611c437bffdf45a75224b669a27ef to your computer and use it in GitHub Desktop.
Basic Example of loop unrolling
int normal_loop(int[] nums) {
int x = 0;
for (int i = 0; i < 250; i++) {
x += nums[i];
}
return x;
}
int unrolled_loop(int[] nums) {
int x = 0;
for (int i = 0; i < 250; i+=5) {
x += nums[i];
x += nums[i+1];
x += nums[i+2];
x += nums[i+3];
x += nums[i+4];
}
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment