Hi Segher, > Out of interest, what uses this? I have never seen it before.
It's used in sjeng in SPEC and gives a 2% speedup on Cortex-A57. Tricks like this used to be very common 20 years ago since a loop or binary search is way too slow and few CPUs supported fast clz/ctz instructions. It's one of those instructions you rarely need, but when you do, performance is absolutely critical... As Jakub mentioned in the PR, https://doc.lagout.org/security/Hackers%20Delight.pdf is a good resource for these bit tricks. Cheers, Wilco