imul指令如何计算符号标志?
How is the sign flag calculated with the imul instruction?
SF is updated according to the most significant bit of the operand-size-truncated result in the destination.
对于64位操作,那么,我的理解是SF = (a * b) >> 63
,或者更简单地说,如果a
和b
有符号,SF = a * b < 0
。
但是,我得到了两个大数相乘的意外结果:
mov rax, 0x9090909090909095
mov rdx, 0x4040404040404043
imul rax, rdx
0x9090909090909095 * 0x4040404040404043
的结果是0xefcba7835f3b16ff
。它设置了符号位,但是 SF 标志在 imul
指令后被清除。怎么回事?
这是 cross-posted to the Intel forums 前一段时间。
Other sources说SF在imul
之后没有定义。这很可能意味着 SF 的结果在较新的处理器上定义明确,但较旧的处理器不提供该功能。我的电脑用了 5 年,我可能属于第二类。
编辑:使用 Archive.org 的 Wayback Machine,我发现文档从声明 SF 未定义更改为 SF 在 September 2014 revision. The previous revision, June 2014, still says that SF is undefined. This is documented in the accompanying Documentation Changes 文档,尽管更改的理由不是。
编辑 2 我的 CPU 是 i7 M 620。我可以使用更旧的 Core2Duo P7550 并且能够确认 imul
没有也不要在上面设置 SF
。
编辑 3 从 2016 年 9 月版开始,IMUL
表示 SF 未定义,因此这解决了问题。
SF is updated according to the most significant bit of the operand-size-truncated result in the destination.
对于64位操作,那么,我的理解是SF = (a * b) >> 63
,或者更简单地说,如果a
和b
有符号,SF = a * b < 0
。
但是,我得到了两个大数相乘的意外结果:
mov rax, 0x9090909090909095
mov rdx, 0x4040404040404043
imul rax, rdx
0x9090909090909095 * 0x4040404040404043
的结果是0xefcba7835f3b16ff
。它设置了符号位,但是 SF 标志在 imul
指令后被清除。怎么回事?
这是 cross-posted to the Intel forums 前一段时间。
Other sources说SF在imul
之后没有定义。这很可能意味着 SF 的结果在较新的处理器上定义明确,但较旧的处理器不提供该功能。我的电脑用了 5 年,我可能属于第二类。
编辑:使用 Archive.org 的 Wayback Machine,我发现文档从声明 SF 未定义更改为 SF 在 September 2014 revision. The previous revision, June 2014, still says that SF is undefined. This is documented in the accompanying Documentation Changes 文档,尽管更改的理由不是。
编辑 2 我的 CPU 是 i7 M 620。我可以使用更旧的 Core2Duo P7550 并且能够确认 imul
没有也不要在上面设置 SF
。
编辑 3 从 2016 年 9 月版开始,IMUL
表示 SF 未定义,因此这解决了问题。