Instruction
STOS
Stores AL, AX, EAX or RAX at [RDI] and steps RDI; REP STOS fills RCX elements, the classic memset.
- Extensions
- Mnemonics
- STOS, STOSB, STOSW, STOSD, STOSQ
- Forms
- 8 (8 Legacy)
- Data
- Intel XED v2026.08.23
STOS stores AL, AX, EAX or RAX at [RDI] and moves RDI to the next
element, up or down as the direction flag says. A REP prefix repeats it
RCX times, so rep stosb is a memset with RDI, AL and RCX as its
arguments, and rep stosq fills quadwords.
In compiled code
GCC 14 at -O2 uses it for blocks whose size it knows:
- A 4 KiB local array initialized to zeros becomes
xor eax, eax,mov ecx, 512,mov rdi, rspandrep stosq. memset(p, 0, 256), with p achar *, stores the first and the last quadword with MOVs, moves RDI up to the next multiple of 8 and leaves the rest torep stosq, so the ends overlap instead of needing byte stores.- Any value but 0 must first be repeated in every byte of RAX:
memset(p, 7, 300)starts withmovabs rax, 0x0707070707070707.
Clang 23 uses none of it: it clears the 256 bytes with sixteen MOVUPS
of a zeroed XMM register and calls memset for the others, as GCC also
does for a 64 KiB array.
Things to know
- Destination. STOS always writes through ES:RDI; a segment prefix cannot redirect it, unlike the source of MOVS and LODS. In 64-bit mode ES has base 0, so RDI is the address.
- Shared with MOVS. The direction flag, which the ABIs want clear, the resumption after an interrupt or fault, the 67 prefix and the F2 prefix, which Zen 5 also ran as REP, work as the MOVS page describes.
- Count 0. With RCX = 0, REP STOS stores nothing and leaves RDI as it was.
Fast strings
The stores of one REP STOS may become visible to other processors out of order, but not before older stores or after younger ones (Intel’s Volume 3A, Section 11.2.4, and AMD’s Zen 5 guide, Section 2.13.6). On Zen 5, a fill at least as large as the L3 cache uses streaming stores, and in some system configurations smaller fills skip reading the cache lines they overwrite whole. Intel’s processors report fast fills of 0 to 128 bytes, from Golden Cove on, in CPUID.(EAX=7,ECX=1):EAX[11] (optimization manual, Section 3.8.2). On Ivy Bridge, by the same manual, a REP STOSB memset to a misaligned destination runs about 20% slower than to an aligned one (Section 3.7.6.4).
In the optimization guide
What the optimization guide says about STOS, a line per claim. Each links to the claim in the guide, with its sources and where they differ.
Memory
- REP MOVS and STOS: Intel’s cores made
rep movsbandrep stosbfast from Ivy Bridge, and short strings fast from Ice Lake and Golden Cove, as CPUID reports.
Bulldozer to Excavator
- Integer execution:
rep movsandrep stoshave a fast microcode path that moves 16 bytes at a time when the direction flag is clear, the blocks do not overlap and the addresses are aligned to the operand size.
Golden Cove and Raptor Cove
- Loads, stores and caches: Short
rep movsb,rep stosb,rep cmpsbandrep scasbare fast: with the data in the L1 cache, any length up to 128 bytes takes a flat 9, 12, 15 and 15 cycles, zero included except for the compares.
Haswell and Broadwell
- Loads, stores and strings:
rep movsbcopies more than 20 bytes a cycle when the copy is long, using the 256-bit store path, but loses to SIMD code below a few hundred bytes;rep stosbfills up to 32 bytes a cycle when the count is large.
Sandy Bridge and Ivy Bridge
- What Ivy Bridge changed: Ivy Bridge is the first core with enhanced REP MOVSB and STOSB, flagged by CPUID leaf 7’s EBX bit 9, which make a byte-granularity REP string fast as well as flexible for memory copies and fills; on Ivy Bridge itself, though, Intel’s manual notes they may still not reach the throughput of a hand-written 128-bit or 256-bit AVX copy.
Silvermont to Goldmont Plus
- Loads, stores and caches: rep movsb and rep stosb are enhanced from Silvermont on, but rep movs suffers from line splits.
Zen 5
- Loads, stores and caches:
rep movsandrep stosof at least the size of the L3 store with streaming stores that bypass the caches, and on some systems smaller ones skip reading the lines they overwrite whole.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
STOSB
STOSB | AA | Base instruction set |
STOSW
STOSW | 66 AB | Base instruction set |
STOSD
STOSD | AB | Base instruction set |
STOSQ 64-bit mode only
STOSQ | REX.W AB | LM |
REP STOSB
REP_STOSB | F3 AAF2 AA | Base instruction set |
REP STOSW
REP_STOSW | 66 F3 AB66 F2 AB | Base instruction set |
REP STOSD
REP_STOSD | F3 ABF2 AB | Base instruction set |
REP STOSQ 64-bit mode only
REP_STOSQ | F3 REX.W ABF2 REX.W AB | LM |
Latency and throughput
| Model | STOSBSTOSB | STOSWSTOSDSTOSQSTOSWSTOSDSTOSQ |
|---|---|---|
| Sandy Bridge | 5 / 1p0 p1 p4 p5 p23 | 5 / 1p0 p1 p4 p5 p23 |
| Haswell, Broadwell, Skylake, Skylake-SP | 2 / 1p01234567 | 2 / 1p01234567 |
| Ice Lake | 2 / 0.5p01456789 | 2 / 0.5p01456789 |
| Alder Lake, Sapphire Rapids | 8 / 0.5p0 p1 p4 p5 p6 p7 p8 p9 p11 | 7 / 0.5p0 p1 p4 p5 p6 p7 p8 p9 p11 |
| Lunar Lake | 8 / 0.5p0 p1 p2 p3 p4 p5 p10 p11 p25 p26 p27 | 7 / 0.5p0 p1 p2 p3 p4 p5 p10 p11 p25 p26 p27 |
| Bonnell | 1 / 0.5p01 | 1 / 0.5p01 |
| Silvermont | 100 / 1FPC0 | 100 / 1FPC0 |
| Piledriver | 100 / 0.5EX0 EX1 | 100 / 0.5EX0 EX1 |
| Zen, Zen 2 | 100 / 0.25 | 100 / 0.25 |
| Zen 3, Zen 4 | 100 / 25ALU0 ALU1 ALU2 ALU3 | 100 / 25ALU0 ALU1 ALU2 ALU3 |
| Jaguar | 100 / 0.5ALU0 ALU1 | 100 / 0.5ALU0 ALU1 |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
step = -(OSIZE // 8) if df else OSIZE // 8
store(aDI, OSIZE, rAX)
aDI = low(aDI + step, ASIZE)Run on AMD Zen 5 (EPYC 9645): 16 cases.
step = -(OSIZE // 8) if df else OSIZE // 8
d = aDI
for i in range(aCX):
store(d, OSIZE, rAX)
d = low(d + step, ASIZE)
aDI = d
aCX = 0Run on AMD Zen 5 (EPYC 9645): 24 cases.
Operands
| Operand | Kind | Action |
|---|---|---|
STOSB STOSW STOSD STOSQ 64-bit mode only | ||
m8/16/32/64 at ES:[rDI] | implicit | write |
rDI | implicit | read, write |
AL, AX, EAX, RAX | implicit | read |
RFLAGS | implicit | read |
REP STOSB REP STOSW REP STOSD REP STOSQ 64-bit mode only | ||
m8/16/32/64 at ES:[rDI] | implicit | conditional write |
rDI | implicit | read, conditional write |
AL, AX, EAX, RAX | implicit | read |
rCX | implicit | read, conditional write |
RFLAGS | implicit | read |
Flags
| DF |
|---|
| All forms |
| T |
Attributes
What else XED records about the forms. How to read.
- REP forms
- repeated: count in rCX
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 |
|---|---|---|
I86 | No CPUID bit: part of the base instruction set. | Every x86-64 processor in XED’s model and Zen 3 to Zen 6 |
I386 | No CPUID bit: part of the base instruction set. | Every x86-64 processor in XED’s model and Zen 3 to Zen 6 |
LONGMODE | LM | Every x86-64 processor in XED’s model and Zen 3 to Zen 6 |
More General-purpose 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. - LLVM 23.1.2's x86 scheduling models (commit
85ac56026243): the latency, reciprocal throughput and ports of each form, as llvm-mca reports them. - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2B, page 4-677 (STOS/
STOSB/ STOSW/ STOSD/ STOSQ) - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3 (325384-093, September 2026)
- AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 2026)
- Intel 64 and IA-32 Architectures Optimization Reference Manual, Volume 1 (248966-051, October 2026)
- 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 timings come from LLVM's scheduling models, part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.