136
edits
(Created page with "Loop unrolling is an optimization technique that reduces the number of iterations in a loop by expanding its body to process multiple elements per iteration. This transformation decreases loop overhead, improves execution efficiency, and can enhance opportunities for parallelization. By reducing control flow instructions, loop unrolling minimizes branching and increases instruction-level parallelism, making it particularly useful for performance-critical applications. Wh...") |
No edit summary |
||
Line 1: | Line 1: | ||
Loop | Loop fission, also known as loop distribution, is an optimization technique that splits a single loop into multiple loops over the same iteration range, with each handling a subset of the original loop’s operations. This transformation improves data locality, enhances cache efficiency, and enables better parallelization by reducing dependencies within a loop body. By breaking down complex loops, loop fission can optimize memory access patterns and improve overall program performance while preserving the original computation logic. | ||
==Loop | ==Loop Fission Transformation in emmtrix Studio== | ||
emmtrix Studio implements loop | emmtrix Studio implements loop fission using #pragma directives or via the GUI. Loop fission is a transformation that breaks a loop into multiple loops over the same index range with each taking only a part of the original loop’s body. | ||
===Typical Usage and Benefits=== | ===Typical Usage and Benefits=== | ||
Loop | Loop fission is used to achieve better utilization of locality of reference by breaking down a large loop body into smaller ones. | ||
===Example=== | ===Example=== | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 10: | Line 10: | ||
/* The following code tests LoopUnroll transformation applied to a for loop: */ | /* The following code tests LoopUnroll transformation applied to a for loop: */ | ||
int main( | int main() { | ||
int i; | int i, j; | ||
int a[ | int a[10], b, c, d; | ||
#pragma EMX_TRANSFORMATION | #pragma EMX_TRANSFORMATION LoopFission | ||
for (i = 0; i < | for (i = 0; i < 10; i++) { | ||
a[i] = i; | d = 0; | ||
a[i] = i * i; | |||
c = 9; | |||
b = i; | |||
b = 8 + i * b; | |||
if (a[i] > 50) { | |||
c = c + a[i]; | |||
printf(”Inside | |||
if, a[ % d] = % d and c = % d\ n”, i, a[i], c); | |||
} else { | |||
printf(”Inside | |||
else, c = % d\ n”, c); | |||
printf(”Inside | |||
else, a[ % d] = % d\ n”, i, a[i]); | |||
} | |||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|<syntaxhighlight lang="c"> | |<syntaxhighlight lang="c"> | ||
/* The generated code | /* The generated code has multiple loops, each loop containing groups of statements from the old loop | ||
that have dependencies on one another: */ | |||
int main( | int main() { | ||
int i; | int i; | ||
int a[ | int j; | ||
int a[10]; | |||
int b; | |||
int c; | |||
int d; | |||
{ | { | ||
for (i = 0; i < 10; i = i + 1) { | |||
d = 0; | |||
} | |||
for (i = 0; i < 10; i = i + 1) { | |||
a[i] = i * i; | |||
c = 9; | |||
if (a[i] > 50) { | |||
c = c + a[i]; | |||
printf(”Inside | |||
if, a[ % d] = % d and c = % d\ n”, i, a[i], c); | |||
} else { | |||
printf(”Inside | |||
else, c = % d\ n”, c); | |||
printf(”Inside | |||
else, a[ % d] = % d\ n”, i, a[i]); | |||
} | |||
} | |||
for (i = 0; i < 10; i = i + 1) { | |||
b = i; | |||
b = 8 + i * b; | |||
} | |||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|} | |} | ||
[[Category:Code Transformation]] | |||
edits