switched order of loops for N < 512, faster for all Ns except 2. N > 512 still the same.
modified N=2 case for moderate speedup, switched to multiple blocking levels with each iterator and played around to find best values