1

如何在 x64-Assembly 中有效地用另一个寄存器的最低有效位填充寄存器的最高有效位。预期用途是将 128 位值除以 2(本质上是跨寄存器移位)。

RDX:RAX (result after MUL-Operation)
4

1 回答 1

2

使用该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
于 2020-04-27T14:15:02.857 回答