Most/Least significant bits (msb)
__builtin_ctz = Number of trailing zero’s, but require value to be non-zero.
Bruijn multiplication.
The de Bruijn version beats the other implementations soundly because it is branchless, and therefore it runs well against inputs that produce an evenly distributed set of outputs. All the other versions are slower against arbitrary inputs because of the penalties of branch misprediction on modern CPUs. The smbFfs function produces incorrect results so it can be ignored.
Here are the results in performance mode, running on my i7-4600 laptop, compiled in release mode:
Least Significant 1 Bit
Written on July 2, 2018, Last update on February 4, 2023
c++
bits