function (a, w, h) { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { a.touch(i,j); } } }
function (a, w, h) { for (j = 0; j < w; j++) { for (i = 0; i < h; i++) { a.touch(i,j); } } }
function (a, w, h) { for (i = 0; i < h; i++) { for (j = i+1; j < w; j++) { a.touch(i,j); a.touch(j,i); } } }
function (a, w, h) { var transpose_base = function(a, x, y, w, h) { for (i = x; i < x+w; i++) { for (j = y; j < y+h; j++) { if (j >= i) continue; /* when iterating over a block that straddles the diagonal, only swap the upper triangle */ a.touch(i,j); a.touch(j,i); } } }; var transpose_block = function(a, x, y, w, h) { /* avoid blocks entirely below diagonal */ if ( (x+w) <= y ) return; if (w <= 4 && h <= 4) { transpose_base(a, x, y, w, h); return; } if (w >= h) { var mid = Math.floor(w/2); transpose_block(a, x , y, mid, h); transpose_block(a, x+mid, y, w-mid, h); } else { var mid = Math.floor(h/2); transpose_block(a, x, y, w, mid); transpose_block(a, x, y+mid, w, h-mid); } }; transpose_block(a, 0, 0, w, h); }
In the code below, a.touch(i,j) indicates array access a[i][j].
Memory Touches | Cache Hits (green) / Misses (red) | TODO |
---|---|---|
|
||
Memory touches are colored by time: black at the start, white at the end |
Each "pixel" is a four-byte element. |