loop_count
Specifies the
iterations for a for loop.
Syntax
#pragma loop_count
(
n
)
#pragma loop_count
=
n
or
#pragma loop_count
(
n1
[
,
n2
]
...
)
#pragma loop_count
=
n1
[
,
n2
]
...
or
#pragma loop_count
min
(
n
)
,
max
(
n
)
,
avg
(
n
)
#pragma loop_count
min
=
n
,
max
=
n
,
avg
=
n
Arguments
- (n) or =n
- A non-negative integer value. The compiler will attempt to iterate the next loop the number of times specified inn; however, the number of iterations is not guaranteed.
- (n1[,n2]...) or = n1[,n2]...
- Non-negative integer values. The compiler will attempt to iterate the next loop the number of time specified byn1orn2, or some other unspecified number of times. This behavior allows the compiler some flexibility in attempting to unroll the loop. The number of iterations is not guaranteed.
- min(n), max(n), avg(n) or min=n, max=n, avg=n
- Non-negative integer values. Specify one or more in any order without duplication. The compiler insures the next loop iterates for the specified maximum, minimum, or average number (n1) of times. The specified number of iterations is guaranteed for min and max.
Description
The
loop_count
pragma specifies the minimum, maximum, or
average number of iterations for a
for
loop. In addition, a list of commonly occurring values
can be specified to help the compiler generate multiple versions and perform
complete unrolling.
You can specify more than one pragma for a single loop;
however, do not duplicate the pragma.
The
loop_count
pragma is supported in host code only.
Examples
Use the
loop_count
pragma to iterate through the loop a minimum
of three, a maximum of ten, and average of five times:
#include <stdio.h>
int i;
int mysum(int start, int end, int a) {
int iret=0;
#pragma loop_count min(3), max(10), avg(5)
for (i=start;i<=end;i++)
iret += a;
return iret;
}
int main() {
int t;
t = mysum(1, 10, 3);
printf("t1=%d\r\n",t);
t = mysum(2, 6, 2);
printf("t2=%d\r\n",t);
t = mysum(5, 12, 1);
printf("t3=%d\r\n",t);
}