Gegell
gegellibu.bsky.social
Gegell
@gegellibu.bsky.social
Taking another look at the morton order code @vassvik.bsky.social posted, one can further reduce the amount of instructions required, using one of my favorite bit fudging techniques: Bit cloning using multiplication!

It sometimes lets you replace code like x | (x << a) | (x << b) if a, b are fixed.
Some random Morton Code tricks:

If you've worked with Morton codes you've probably seen something like the this GLSL code to decode a Morton code, which end up at roughly 27 integer operations to generate the equivalent 2D position.

Code transcribed from fgiesen.wordpress.com/2009/12/13/d...
December 6, 2025 at 2:59 AM