Take the 2-minute tour ×  I'm now trapped by a performance
optimization lab in the book "Computer System from a
Programmer's Perspective" described as following:  In a N*N
matrix M, where N is multiple of 32, the rotate operation can be
represented as: Transpose: interchange elements M(i,j) and
M(j,i) Exchange rows: Row i is exchanged with row N-1-i  A
example for matrix rotation(N is 3 instead of 32 for
simplicity):  |1|2|3|                          |3|6|9| |4|5|6|
after rotate is       |2|5|8| |7|8|9|
|1|4|7|  A naive implementation is:  #define RIDX(i,j,n)
((i)*(n)+(j))      void naive_rotate(int dim, pixel *src, pixel
*dst)          int i, j;          for (j = 0; j < dim; j++)
dst[RIDX(dim-1-j, i, dim)] = src[RIDX(i, j, dim)];  I come up
with an idea by inner-loop-unroll. The result is:  Code Version
Speed Up   original                1x  unrolled by 2
1.33x  unrolled by 4           1.33x  unrolled by 8
1.55x  unrolled by 16          1.67x