Instruction
FNSTSW
Stores the x87 status word to 16 bits of memory or to AX; FSTSW is FWAIT followed by it.
- Extensions
- Mnemonics
- FNSTSW, FSTSW
- Forms
- 2 (2 Legacy)
- Data
- Intel XED v2026.08.23
FNSTSW stores the x87 status word to 16 bits of memory or to AX. The word holds the six exception flags (bits 0 to 5), the stack fault SF (bit 6), the error summary ES (bit 7), the condition codes C0, C1 and C2 (bits 8 to 10) and C3 (bit 14), TOP (bits 13:11) and the busy bit B (bit 15). The N means no wait: FNSTSW does not first check for a pending unmasked exception, so an exception handler can read the word that describes it. FSTSW, listed on this page, is FWAIT followed by FNSTSW. The AX form writes AX alone; the rest of RAX stays.
Branching on the condition codes
Before FCOMI, the compares and FPREM reported only in C0 to C3, and FNSTSW AX was the way to branch on them. In AH, C0 lands in bit 0, C2 in bit 2 and C3 in bit 6, the places of CF, PF and ZF in the flags, so SAHF turns a compare’s result into the pattern FCOMI produces. Compiled code still shows both ways:
- GCC 14 at -O2 with
-m32 -march=i386compilesa < bon doubles to an FCOMP,fnstsw axandtest ah, 69, that is C0, C2 and C3 together; none set means b was greater. - GCC inlines
fmodlas a loop of FPREM,fnstsw ax,test ah, 4and a JNE back while C2 says the reduction is not complete.
In 64-bit mode SAHF exists only where CPUID 80000001H ECX[0] reports it; GCC’s TEST of AH needs no such check.
Cost
AMD’s Zen 5 guide lists FNSTSW as microcoded and advises against putting other instructions between a compare and the FNSTSW that reads its result (Section 2.11.3). FNSTCW stores the control word the same way, and FNSTENV the whole environment.
In the optimization guide
What the optimization guide says about FNSTSW, a line per claim. Each links to the claim in the guide, with its sources and where they differ.
Silvermont to Goldmont Plus
- Vectors and cryptography: Prefer SSE to x87, and fcomi to fcom with fnstsw, on these cores.
Forms
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
dest.write(fsw) # with TOP, ES and B; AX: bits 63:16
# of RAX stay
c0 = c1 = c2 = c3 = UNDEFINEDRun on AMD Zen 5 (EPYC 9645): 12 cases.
Operands
| Operand | Kind | Action |
|---|---|---|
FNSTSW m16 | ||
m16 | explicit | write |
x87 status word | implicit | read, write |
FNSTSW AX | ||
AX | explicit | write |
x87 status word | implicit | read, write |
Flags
| C0 | C1 | C2 | C3 |
|---|---|---|---|
| All forms | |||
| U | U | U | U |
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-392 (FSTSW/
FNSTSW) - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1 (253665-093, September 2026)
- AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.36, March 2024), Wayback Machine copy of AMD's PDF
- 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.