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, rsp and rep stosq.
  • memset(p, 0, 256), with p a char *, stores the first and the last quadword with MOVs, moves RDI up to the next multiple of 8 and leaves the rest to rep 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 with movabs 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 movsb and rep stosb fast from Ivy Bridge, and short strings fast from Ice Lake and Golden Cove, as CPUID reports.

Bulldozer to Excavator

  • Integer execution: rep movs and rep stos have 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 cmpsb and rep scasb are 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 movsb copies 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 stosb fills 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 movs and rep stos of 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

Every encoding of STOS that Intel XED knows, one row per XED instruction form (iform). How to read the notation.
InstructionEncodingRequires
STOSB STOSBAABase instruction set
STOSW STOSW66 ABBase instruction set
STOSD STOSDABBase instruction set
STOSQ 64-bit mode only STOSQREX.W ABLM
REP STOSB REP_STOSBF3 AA
F2 AA
Base instruction set
REP STOSW REP_STOSW66 F3 AB
66 F2 AB
Base instruction set
REP STOSD REP_STOSDF3 AB
F2 AB
Base instruction set
REP STOSQ 64-bit mode only REP_STOSQF3 REX.W AB
F2 REX.W AB
LM

Latency and throughput

What the scheduling models of LLVM 23.1.2 give for each form, not measurements: latency / reciprocal throughput in cycles, the ports under them. A row is a model, or models that agree; a dash, a form that its processors lack. Memory forms: latency from the address, ports without the load and store units. Which processors each model covers.
ModelSTOSB
STOSB
STOSW
STOSD
STOSQ
STOSW
STOSD
STOSQ
Sandy Bridge5 / 1p0 p1 p4 p5 p235 / 1p0 p1 p4 p5 p23
Haswell, Broadwell, Skylake, Skylake-SP2 / 1p012345672 / 1p01234567
Ice Lake2 / 0.5p014567892 / 0.5p01456789
Alder Lake, Sapphire Rapids8 / 0.5p0 p1 p4 p5 p6 p7 p8 p9 p117 / 0.5p0 p1 p4 p5 p6 p7 p8 p9 p11
Lunar Lake8 / 0.5p0 p1 p2 p3 p4 p5 p10 p11 p25 p26 p277 / 0.5p0 p1 p2 p3 p4 p5 p10 p11 p25 p26 p27
Bonnell1 / 0.5p011 / 0.5p01
Silvermont100 / 1FPC0100 / 1FPC0
Piledriver100 / 0.5EX0 EX1100 / 0.5EX0 EX1
Zen, Zen 2100 / 0.25100 / 0.25
Zen 3, Zen 4100 / 25ALU0 ALU1 ALU2 ALU3100 / 25ALU0 ALU1 ALU2 ALU3
Jaguar100 / 0.5ALU0 ALU1100 / 0.5ALU0 ALU1

Operation

What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.

All forms but the REP forms
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.

REP forms
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 = 0

Run on AMD Zen 5 (EPYC 9645): 24 cases.

Operands

What each form reads and writes, as Intel XED records it: the operands of its syntax, in order, and the implicit ones that the syntax does not name. How to read.
OperandKindAction
STOSB STOSW STOSD STOSQ 64-bit mode only
m8/16/32/64 at ES:[rDI]implicitwrite
rDIimplicitread, write
AL, AX, EAX, RAXimplicitread
RFLAGSimplicitread
REP STOSB REP STOSW REP STOSD REP STOSQ 64-bit mode only
m8/16/32/64 at ES:[rDI]implicitconditional write
rDIimplicitread, conditional write
AL, AX, EAX, RAXimplicitread
rCXimplicitread, conditional write
RFLAGSimplicitread

Flags

T tested; blank: not affected. How to read.
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.

CPUID requirements and processors of the XED ISA sets above. Alternatives are separated by “or”; processors follow XED’s chip model, whose AMD processors end with Zen 2, and the CPU data of this site for Zen 3 to Zen 6.
ISA setCPUIDProcessors
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
CPUID.80000001H:EDX[29] LM

Every x86-64 processor in XED’s model and Zen 3 to Zen 6

More General-purpose instructions

All 109 General-purpose instructions

Sources

  1. Intel XED v2026.08.23 (commit 0bcb6237345c): forms, encodings, operands, flags, exception classes, attributes, ISA sets, CPUID bits and chip model.
  2. The CPU data of x86-64.net: Zen 3 to Zen 6, from GCC’s -march feature sets and AMD’s Processor Programming References, which the page of each processor cites.
  3. LLVM 23.1.2's x86 scheduling models (commit 85ac56026243): the latency, reciprocal throughput and ports of each form, as llvm-mca reports them.
  4. 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)
  5. Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3 (325384-093, September 2026)
  6. AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 2026)
  7. Intel 64 and IA-32 Architectures Optimization Reference Manual, Volume 1 (248966-051, October 2026)
  8. 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.