Instruction
FTST
Compares ST(0) with 0.0 and sets C0, C2 and C3 of the x87 status word.
- Extensions
- Forms
- 1 (1 Legacy)
- Data
- Intel XED v2026.08.23
FTST compares ST(0) with zero and reports the answer in the condition codes, as FCOM does with another value: C3, C2 and C0 clear when ST(0) is greater, C0 set when it is less, C3 set when it is zero of either sign, and all three when it is a NaN or unsupported. C1 is cleared. It is two bytes, D9 E4, with no operand, needs no zero in a register and pops nothing.
A signaling compare
Intel’s manual calls the comparison unordered, but that only names the fourth outcome: FTST raises the invalid-operation exception for a NaN of either kind, as FCOM does, not only for a signaling one as FUCOM does. AMD’s manual lists QNaNs among its IE causes too, and Zen 5 raised IE for QNaNs of both signs, an SNaN and the unsupported encodings it was given (an unnormal, a pseudo-infinity and a pseudo-NaN). A denormal raises DE and compares as its value, which is never zero: Zen 5 reported a positive denormal as greater.
With IE unmasked, Intel’s table does not say whether the codes are written. Zen 5 wrote them as unordered for a QNaN and for an empty ST(0), cleared C1, and #MF came at the next waiting instruction; with DE unmasked it wrote the result of the compare. With an exception already pending, the #MF came at FTST itself and the codes stayed.
Where it still appears
C’s x > 0 may raise the invalid exception for a NaN, so it can use
FTST, and GCC 14 does at -O2 with -m32 -march=i386 on a double:
FLD, FTST, FNSTSW AX, fstp st(0) and test ah, 69,
which is true only when all three codes are clear. For x == 0, which
must stay quiet, it loads FLDZ and uses FUCOMPP instead.
On processors with FCOMI, and in 64-bit code, compilers
compare with an FLDZ and FCOMIP or FUCOMIP, which set
RFLAGS directly; FTST has no form that does. Clang 23 used no FTST in
these tests, even for i386: it loads FLDZ and compares with FUCOMPP.
FXAM classifies ST(0) without raising anything. AMD’s Zen 5 guide lists FTST as one macro-op on pipe FP1, one per cycle.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
FTST
FTST | D9 E4 | FPU |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
if empty(st0):
underflow()
x = 3 # unordered
else:
x = comi(st0, 0) # against +0; any NaN raises IE
c3 = x in (2, 3) # set with IE or DE unmasked too
c2 = x == 3
c0 = x in (1, 3)
c1 = 0Run on AMD Zen 5 (EPYC 9645): 22 cases.
Operands
| Operand | Kind | Action |
|---|---|---|
FTST | ||
ST(0) | implicit | read, write |
x87 status word | implicit | write |
Flags
| C0 | C1 | C2 | C3 |
|---|---|---|---|
| All forms | |||
| M | M | M | M |
Attributes
What else XED records about the forms. How to read.
- All forms
- may abort a TSX transaction
CPUID and processors
Each form belongs to an XED ISA set. A form can be used when the processor reports every CPUID bit of one of its ISA set's alternatives.
| ISA set | CPUID | Processors |
|---|---|---|
X87 | FPU | Every x86-64 processor in XED’s model and Zen 3 to Zen 6 |
More x87 instructions
Sources
- Intel XED v2026.08.23 (commit
0bcb6237345c): forms, encodings, operands, flags, exception classes, attributes, ISA sets, CPUID bits and chip model. - The CPU data of x86-64.net: Zen 3 to Zen 6, from GCC’s
-marchfeature sets and AMD’s Processor Programming References, which the page of each processor cites. - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2A, page 3-400 (FTST)
- Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1 (253665-093, September 2026)
- AMD64 Architecture Programmer's Manual, Volume 5: 64-Bit Media and x87 Floating-Point Instructions (26569, rev. 3.16, November 2021), Wayback Machine copy of AMD's PDF
- Software Optimization Guide for the AMD Zen5 Microarchitecture (58455, rev. 1.00, August 2024), Wayback Machine copy of AMD's ZIP
The tables are derived from Intel XED, Copyright Intel Corporation, licensed under the Apache License 2.0; x86-64.net converted and reformatted them. The text is our own.