Skip to content

Instantly share code, notes, and snippets.

@seunghyukcho
Last active February 10, 2021 12:22
Show Gist options
  • Save seunghyukcho/79ef2efdf7124f635d4bf4208922a743 to your computer and use it in GitHub Desktop.
Save seunghyukcho/79ef2efdf7124f635d4bf4208922a743 to your computer and use it in GitHub Desktop.
Optimization techniques
// Original code
for(i = 0; i < 10; i++) {
arr[i] += 5 * i + x * x;
}
// After code motion optimization
int temp = x * x;
for(i = 0; i < 10; i++) {
arr[i] += 5 * i + temp;
}
// Original code
c = 7;
for (i = 0; i < N; i++) {
y[i] = c * i;
}
// After strength reduction optimization
c = 7;
k = 0;
for (i = 0; i < N; i++) {
y[i] = k;
k = k + c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment