3 ms·
Was hoping this touched on Z-ordering. If you have a processor that can efficiently interleave bits (i.e. combine 0110 and 1011 to get 01101101), you can lay o
by colanderman 11y ago
Was hoping this touched on Z-ordering. If you have a processor that can efficiently interleave bits (i.e. combine 0110 and 1011 to get 01101101), you can lay out 2D and 4D arrays in Z-order, which will improve spatial locality (nearby elements in both the X and Y dimensions are also nearby in memory/cache/TLBs).
You can actually efficiently achieve this even on processors without an interleave instruction if you're only walking stepwise -- basically, mask out the odd (resp. even) bits separately, setting the even (resp. odd) bits to 1 before adding 1, or to 0 before subtracting 1, then recombine.