Can anyone tell me if this code is optimal? I could hope that this will be implemented without a branch, but when I put it into godbolt it doesn't look encouraging. But I'm unfamiliar with godbolt, and may have missed how to enable optimizations...
If rust can't do this without a branch, it would seem worth doing some bit-twiddling to avoid the branch.
Thanks! That looks more like what I was expecting, and confirms my suspicion that the compiler can do better than I can at optimizing this kind of code.