我有这个 Win32 代码:
fld x
fmul y
fstsw ax
似乎 fmul
没有清除 FPU 状态寄存器位,即如果已经设置了溢出 (ax
& 8) 那么它将在 fmul 之后保持设置
。这是正确的行为吗?是否需要在 FPU 操作之后或之前清除状态?
即我想 fmul
会设置这个位,但它应该重置它吗?我在网上找不到答案。
最佳答案
你打赌这是正确的行为。
来自 Intel® 64 和 IA-32 架构软件开发人员手册
的 8.1.3.3 x87 FPU 浮点异常标志
,第 1 卷:
The exception flags are “sticky” bits (once set, they remain set until explicitly cleared). They can be cleared by executing the FCLEX/FNCLEX (clear exceptions) instructions, by reinitializing the x87 FPU with the FINIT/FNINIT or FSAVE/FNSAVE instructions, or by overwriting the flags with an FRSTOR or FLDENV instruction.
如果禁用 FPU 异常,则不需要重置这些标志。
关于assembly - FMUL 不会清除 STATUS 寄存器中的溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15495720/