The compiler probably turned
for(int I = 0; I < 4; ++I) {
real32 PixelPx = (real32)(XI + I);
real32 PixelPy = (real32)Y;
real32 dx = PixelPx - Origin.x;
real32 dy = PixelPy - Origin.y;
real32 U = dx*nXAxis.x + dy*nXAxis.y;
real32 V = dx*nYAxis.x + dy*nYAxis.y;
//rest of the loop
}
into something like real32 PixelPy = (real32)Y;
real32 dy = PixelPy - Origin.y;
real32 PixelPx = (real32)(XI);
real32 dx = PixelPx - Origin.x;
real32 U = dx*nXAxis.x + dy*nXAxis.y;
real32 V = dx*nYAxis.x + dy*nYAxis.y;
for(int I = 0; I < 4; ++I) {
U += nXAxis.x;
V += nYAxis.x;
//rest of the loop
}
PixelPy and dy are not affected by the counter in the loop which means they can safely moved outside the loop.This also results in the subexpression dynXAxis.y and dynYAxis.y being lifted outside the loop.
Now we've moved half of the code outside the loop but we aren't done yet.
The same can be done with PixelPx and dx, the trick is to then replace dxnXAxis.x with
(dx + I)*nXAxis.x
Expanding (dx + I)*nXAxis.x
yields dx*nXAxis.x + I*nXAxis.x
We can now lift the subexpression dx*nXAxis.x
out of the loop.The only thing that is now done in the loop is
I*nXAxis.x
which can be further simplified to U += nXAxis.x
The same happens with nYAxis.x.EDIT: Sorry for the bad formatting. The markdown parser ate my asterisks so I put things into code blocks which requires a new line each time.