I've written something like this in C - including resulting assembler code for ARM and x86.

https://easylang.online/blog/branchless