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.