Bots, Bureaucrats, Interface administrators, smwadministrator, smwcurator, smweditor, Administrators
2,557
edits
Timo.stripf (talk | contribs) |
Timo.stripf (talk | contribs) No edit summary |
||
Line 50: | Line 50: | ||
These pragmas give developers flexibility to tailor loop transformations based on hardware characteristics (e.g., cache size, vector register width) or software constraints (e.g., real-time requirements or binary size limits). | These pragmas give developers flexibility to tailor loop transformations based on hardware characteristics (e.g., cache size, vector register width) or software constraints (e.g., real-time requirements or binary size limits). | ||
==Loop Unrolling Transformation in emmtrix Studio== | == Loop Unrolling Transformation in emmtrix Studio == | ||
emmtrix Studio | emmtrix Studio supports loop unrolling both through #pragma directives and via the graphical user interface (GUI). Unrolling reduces the number of loop iterations by expanding the loop body to process multiple elements in each iteration. | ||
By default, the transformation | By default, the transformation applies partial loop unrolling, resulting in two loops: | ||
- The first loop is the partially unrolled loop, processing multiple iterations per pass. | |||
- The second loop handles any remaining iterations that do not fit into the unroll factor (cleanup loop). | |||
emmtrix Studio attempts to calculate a trip count that enables two key optimizations: | |||
1. Full unrolling is applied if the unroll factor is greater than or equal to the trip count. | |||
2. The cleanup loop is omitted if the trip count is exactly divisible by the unroll factor. | |||
=== Example === | |||
In the following example, partial loop unrolling is applied with an unroll factor of 3. | In the following example, partial loop unrolling is applied with an unroll factor of 3. | ||
Please note | Please note: The condition <code>i < n - 2</code> would be incorrect if <code>n</code> could be <code>INT_MIN</code>, due to potential overflow. | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
Line 70: | Line 75: | ||
#pragma EMX_TRANSFORMATION LoopUnroll { "unrollfactor": 3 } | #pragma EMX_TRANSFORMATION LoopUnroll { "unrollfactor": 3 } | ||
for (int i = 1; i < n; i++) { | for (int i = 1; i < n; i++) { | ||
printf("%d\n", i); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|<syntaxhighlight lang="c"> | |<syntaxhighlight lang="c"> | ||
for (i = 1; (i + 2) < n; i = i + 3) { | for (i = 1; (i + 2) < n; i = i + 3) { | ||
printf("%d\n", i); | |||
printf("%d\n", i + 1); | |||
printf("%d\n", i + 2); | |||
} | } | ||
for (; i < n; i = i + 1) { | for (; i < n; i = i + 1) { | ||
printf("%d\n", i); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|} | |} | ||
===Parameters=== | === Parameters === | ||
The following parameters can be configured (each parameter includes its pragma keyword and default value): | |||
{| class="wikitable" | {| class="wikitable" | ||
|+ | |+ | ||
! | !Parameter | ||
!Default Value | !Default Value | ||
!Description | !Description | ||
Line 100: | Line 103: | ||
|<code>unrollfactor</code> | |<code>unrollfactor</code> | ||
|2 | |2 | ||
|'''Unroll factor''' - | |'''Unroll factor''' - Specifies the loop unroll factor. | ||
|- | |- | ||
|<code>subfunctions</code> | |<code>subfunctions</code> | ||
|false | |false | ||
|'''Apply to | |'''Apply to subfunctions''' - Specifies whether the transformation should also apply to subfunctions. | ||
|} | |} | ||
edits