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.

- 33,889
- 7
- 43
- 76

- 29
- 3
-
1Not only it does not make sense, it does not even exist. – Jester May 10 '23 at 12:55
-
4With ST(0) as the destination? There's no way to encode it in the first place: https://www.felixcloutier.com/x86/fadd:faddp:fiadd – teapot418 May 10 '23 at 12:55
1 Answers
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)

- 328,167
- 45
- 605
- 847