FADDP ST(0),ST(1) 有意义吗?

huangapple go评论47阅读模式
英文:

Does FADDP ST(0), ST(1) make sense?

问题

FADDP ST(0), ST(1) 指令在汇编语言中是有意义的。据我所知,在这个指令中,我们将ST(0)和ST(1)相加,并将结果写入ST(0),之后ST(0)被删除。

英文:

I have a question: does the FADDP ST(0), ST(1) instruction make sense in the assembly language?
As far as I know, in this instruction, we add ST(0) and ST(1) and write the result to ST(0), after which ST(0) gets deleted.

答案1

得分: 3

faddp st(0), st(1)无法编码成机器码。

你是对的,这没什么用(除了引发FP异常),这就是为什么8087的架构师没有包括faddp st(0), st(i)的操作码。
有用于3种形式的fadd的操作码,带有寄存器源:

  • D8 C0+i FADD ST(0), ST(i)
  • DC C0+i FADD ST(i), ST(0)
  • DE C0+i FADDP ST(i), ST(0)
  • 但没有适用于faddp st(0), st(i)的操作码

所以faddp st(0), st(0)是可以编码但无用的,可以使用faddp st(i), st(0)的操作码,其中目标可以是任何寄存器,包括无用情况的st(0),但源固定为st(0)


不做其他操作最便宜的出栈方式是fstp st(0)http://www.ray.masmcode.com/tutorial/fpuchap4.htm#fstp

(有关指令成本,请参见 https://agner.org/optimize/。https://uops.info/ 未测试传统的x87指令,尽管它对其中一些指令有一些IACA数据。)

如果你真的想要将一个数字相加并丢弃结果,例如在从使用整数位操作的数学库函数返回之前引发FP异常,你可以使用以下代码模拟faddp:

; 模拟 faddp st(0), st(1),例如用于引发FP异常
   fadd st(0), st(1)
   fstp st(0)
英文:

faddp st(0), st(1) is not even encodeable into machine code.

You're right, it wouldn't be useful (except to raise FP exceptions), that's why the architects of 8087 didn't include an faddp st(0), st(i) opcode.
There are opcodes for 3 forms of fadd with a register source:

  • D8 C0+i FADD ST(0), ST(i)
  • DC C0+i FADD ST(i), ST(0)
  • DE C0+i FADDP ST(i), ST(0)
  • but no opcode for faddp st(0), st(i)

So faddp st(0), st(0) is encodeable but not useful, using the faddp st(i), st(0) opcode, where the destination can be any register including the useless case of st(0), but the source is fixed as st(0).


The cheapest way to pop the stack by 1 without doing anything else is fstp st(0). http://www.ray.masmcode.com/tutorial/fpuchap4.htm#fstp

(And for instruction costs, see https://agner.org/optimize/. https://uops.info/ didn't test legacy x87 instructions, although it does have some IACA data for some of them.)

If you really wanted to add a number and discard the result, e.g. to raise FP exceptions before returning from a math library function that used integer bit-manipulation, you can emulate that faddp with

; Emulate faddp st(0), st(1), e.g. for raising FP exceptions
   fadd st(0), st(1)
   fstp st(0)

huangapple
  • 本文由 发表于 2023年5月10日 20:49:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76218634.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定