Hi Jayden
Jayden Shui wrote:
> int ib = 1, ie = 99;
> int jb = 1, je = 99;
> int kb0 = 0, ke0 = 1;
> int kb1 = 3, ke1 = 2;
.....
> for (int j = jb; j <= je; ++j)
> {
> for (int k0 = kb0, k1 = kb1; k0 <= ke0; ++k0, --k1)
putting in the numbers:
for (int k0 = 0, k1 = 3; k0 <= ke0; ++k0, --k1)
so You are essentially only swapping the first four floats, right ?
well to my solution:
no need for all these [][][] they are just to make things slower
and in some cases simpler to understand.
// first set some sizes
const int lineSize = 8;
const int squareSize = 800;
const int cubeSize = 80000;
// get one chuck of memory of the right size
float cube[ cubeSize ];
float *square = cube;
float* squaresEnd = cube + cubeSize;
while( square < squaresEnd )
{
float* line = square;
float* linesEnd = square + squareSize;
while( line < linesEnd )
{
float* lineBegin = line;
float* lineEnd = line + 3; // lineSize ****
for(; lineBegin < lineEnd; ++lineBegin, --lineEnd )//**
*lineBegin = *lineEnd;
line += lineSize;
}
square += squareSize;
}
this is close to double speed on my machine, but I only have an old
Borland compiler, so it might not be the same for You.
****
I don't know if the 3 was what You intended, if not replace with
lineSize.
**
I removed the = from <= if they are pointing to the same float there
is really no need to swap.
Best regards
Asger-P