Rust generates unoptimized code to compute number of significant bits with leading_zeros

Godbolt link -- as you can see, in the assembly code of the first function z, the two lines xor rax, 63; xor rax, 63 are redundant, and should be removed; while the code for function u is optimal.

Related issue on GitHub. (not the same as this issue)

For reference, clang can optimize the equivalent C++ code well.

Is there any other way to count the number of significant bits in the number?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.