c++ - Removing Data-Dependence from Loop -


i have following c++ loop:

for (i = len_max - 1; >= 0; i--) {             int j = - len_max + len;                   if (j < 0)                 break;             int ind = a.getelem(j);             short t = ind;             ind = --c[ind];             b.setelem(ind, t); } 

what remove dependency between iterations it. in above loop, example, line ind = --c[ind] has inter-iteration dependency, because decrease, need have value previous iteration. here example of transformation i'm looking for:

from:

        (i = 1; < radix_max; i++) {             if (i == radix)                 break;             c[i] += c[i - 1];             c[i] += temp;                } 

to:

        short temp = c[0];         (i = 1; < radix_max; i++) {             if (i == radix)                 break;             c[i] += temp;     //this loop no longer depends on last iteration              temp = c[i];         } 

i want apply same technique first loop posted, i'm not sure how. reason want because required in order optimize performance of tool using. have ideas?

there no simple transformation of loop provided remove inter-iteration dependency (and second example gave doesn't remove inter-iteration dependency). each iteration depends on happened c previous iteration , there's no way around with current implementation. if know algorithm and/or values stored within c and/or values within a, may able rework code remove order dependency, can't given short segment of code provided.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -