I have the following structure inside a code and it has been used many times. So, improving the code readability and decreasing the number of lines, I really need to use a macro instead of that. The part which I am looking to write a macro for it is as follow:
#define _UNROLL_FACTOR_volIntGrad 32
int jj = 0;
for (; jj < (ngbSize - 32); jj += 32) {
int j = offset + jj;
#pragma unroll
for (int k = 0; k < 32; k++){
...
arbitrary calculation 1 (depends on k)
...
}
...
arbitrary calculation 2
...
}
for (; jj < (ngbSize - (_UNROLL_FACTOR_volIntGrad / 2)); jj+= (_UNROLL_FACTOR_volIntGrad / 2)){
int j = offset + jj;
#pragma unroll
for (int k = 0; k < 16; k++){
...
arbitrary calculation 1 (depends on k)
...
}
...
arbitrary calculation 2
...
}
for (; jj < (ngbSize - (_UNROLL_FACTOR_volIntGrad / 4)); jj+= (_UNROLL_FACTOR_volIntGrad / 4)){
int j = offset + jj;
#pragma unroll
for (int k = 0; k < 8; k++){
...
arbitrary calculation 1 (depends on k)
...
}
...
arbitrary calculation 2
...
}
for (; jj < (ngbSize - (_UNROLL_FACTOR_volIntGrad / 8)); jj+= (_UNROLL_FACTOR_volIntGrad / 8)){
int j = offset + jj;
#pragma unroll
for (int k = 0; k < 4; k++){
...
arbitrary calculation 1 (depends on k)
...
}
...
arbitrary calculation 2
...
}
for (; jj < (ngbSize - (_UNROLL_FACTOR_volIntGrad / 16)); jj+= (_UNROLL_FACTOR_volIntGrad / 16)){
int j = offset + jj;
#pragma unroll
for (int k = 0; k < 2; k++){
...
arbitrary calculation 1 (depends on k)
...
}
...
arbitrary calculation 2
...
}
for (; jj < ngbSize; jj++){
int j = offset + jj;
...
arbitrary calculation 3
...
}
}
by arbitrary calculation X, I mean a set of calculations which is independent of macro and differs function by function. Does anyone know how to write this macro in order to decrease the above structure's size? for example like the following:
__MACRO
arbitrary calculation 1
arbitrary calculation 2
arbitrary calculation 3
__END