assembly - 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
}
编译时,-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
一切似乎都很好,除了我无法解释这两个指令:
xor ecx, 63
xor cl, 63
据我所知,这些都是无操作的。为什么会生成它们?
解决方案
推荐阅读
- c# - 一些 C# 代码导致“服务器忙”错误消息
- python - 在 Pandas 中使用 groupby 语句执行多个 case 的有效方法
- r - 从任意深度列表中提取值
- python - 使用 python (FFMPEG) 编辑音频文件的一部分
- android-studio - Android Studio - 生成签名包会遗漏本地 json 文件
- javascript - 请帮助我理解这个递归问题
- elasticsearch - Elasticsearch:给长标题更高的分数
- python - Else 语句未使用字符串或浮点输入执行
- c# - 如何在 mvc 视图中获取会话对象
- botframework - 重新启动机器人后,主动消息在 MS Teams 中不起作用