如何在 x64-Assembly 中有效地用另一个寄存器的最低有效位填充寄存器的最高有效位。预期用途是将 128 位值除以 2(本质上是跨寄存器移位)。
RDX:RAX (result after MUL-Operation)
如何在 x64-Assembly 中有效地用另一个寄存器的最低有效位填充寄存器的最高有效位。预期用途是将 128 位值除以 2(本质上是跨寄存器移位)。
RDX:RAX (result after MUL-Operation)
使用该shrd
指令从 src 向目标移动一点:
shrd rax, rdx, 1 ; shift a bit from bottom of RDX into top of RAX
shr rdx, 1 ; and then shift the high half
; rdx:rax is shifted one bit to the right
或者,使用 ashr
和 arcr
指令,但请注意这rcr
是多个 uops,因此在大多数 CPU 上这会更慢:
shr rdx, 1 ; shift LSB of rdx into cf
rcr rax, 1 ; shift CF into rax