3 ms·
The example is super confusing because they define the alternative coordinate system (i', j') in the previous paragraph, but then proceed to use i and j (unprim
by ulrikrasmussen 7y ago
The example is super confusing because they define the alternative coordinate system (i', j') in the previous paragraph, but then proceed to use i and j (unprimed) in the code example, presumably because C does not allow for primes in variable names. p and q would have been better.
But, note that if you execute the inner loop for two consecutive values, j' and j' + 1, then you get the following computations:
a[i' - j'][j'] <- a[i' - j' - 1][j' ] + a[i' - j' ][j' - 1]
a[i' - j' - 1][j' + 1] <- a[i' - j' - 2][j' + 1] + a[i' - j' - 1][j']
You can see from the above that the left hand side of the first line does not actually appear on the right hand side of the second. This is because both indexes into a vary as j' changes.
It's a cool optimization, but I think the article fails to clearly explain the general method of how a compiler would arrive there.
Edit: I completely screwed up the indices in my initial post. They should be fixed now.