orl*_*rlp 6 assembly bit-manipulation x86-64 rust
我正在研究以下函数的 x86_64 程序集:
/// Returns the greatest power of two less than or equal to `self`, or 0 otherwise.
pub const fn prev_power_of_two(n: u64) -> u64 {
// n = 0 gives highest_bit_set_idx = 0.
let highest_bit_set_idx = 63 - (n|1).leading_zeros();
// Binary AND of highest bit with n is a no-op, except zero gets wiped.
(1 << highest_bit_set_idx) & n
}
Run Code Online (Sandbox Code Playgroud)
编译时,-C opt=level=3
我们在 nightly 和 1.50.0 上得到以下程序集:
example::prev_power_of_two:
mov rax, rdi
or rax, 1
bsr rcx, rax
xor ecx, 63
xor cl, 63
mov eax, 1
shl rax, cl
and rax, rdi
ret
Run Code Online (Sandbox Code Playgroud)
一切似乎都很好,除了我无法解释这两个指令:
xor ecx, 63
xor cl, 63
Run Code Online (Sandbox Code Playgroud)
据我所知,这些都是空操作。它们为什么会产生?
归档时间: |
|
查看次数: |
107 次 |
最近记录: |