Instruction
INS
Reads a byte, word or doubleword from the I/O port in DX into memory at [RDI] and steps RDI; REP repeats it RCX times.
- Extensions
- Mnemonics
- INS, INSB, INSW, INSD
- Forms
- 6 (6 Legacy)
- Data
- Intel XED v2026.08.23
INS reads one element, a byte, word or doubleword, from the I/O port in
DX and stores it at [RDI], then moves RDI to the next element: up while
the direction flag is clear, down while it is set. With a REP prefix it
repeats RCX times, so rep insw fills a buffer from a device’s data
port, the job IN would do one element at a time.
OUTS is the reverse, from [RSI] to a port.
Things that differ from the other string instructions
- Fixed segment. The destination is always ES:rDI, and no prefix overrides ES; in 64-bit mode the segment adds nothing. The port is always DX.
- No quadword. INSD with REX.W still moves a doubleword, AMD’s manual says, and steps RDI by 4.
- The port first. The permission check of IN comes first: at CPL 3 with IOPL 0, Zen 5 raised #GP for INSB, INSW, INSD and their REP forms, also with RCX = 0, where the REP forms would do nothing else, and with RDI = 8, in page 0, which the probe leaves unmapped, where a page fault might have been expected. Memory and RDI were left alone.
- A read without a write. Intel’s manual warns that REP INS may read the port and then fail to store the element, when the store takes a page fault or a VM exit, so that the value read is lost. A driver whose port reads have side effects must make sure that the buffer is present and writable first.
- Speed. Intel’s manual also cautions that not every device keeps up with the rate at which REP INS and REP OUTS run.
From C
glibc’s <sys/io.h> has insb, insw and insl, which take a port,
a buffer and a count. At -O2, GCC 14 and Clang 23 load the count into
RCX, the buffer into RDI and the port into EDX, then emit CLD followed
by REP INSW: the inline assembly clears the direction flag itself
rather than rely on the calling convention, which already requires it
clear (see CLD).
AMD’s Zen 5 guide lists INS as microcoded.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
INSB
INSB | 6C | Base instruction set |
INSW
INSW | 66 6D | Base instruction set |
INSD
INSD | 6DREX.W 6D | Base instruction set |
REP INSB
REP_INSB | F3 6CF2 6C | Base instruction set |
REP INSW
REP_INSW | 66 F3 6D66 F2 6D | Base instruction set |
REP INSD
REP_INSD | F3 6DF3 REX.W 6DF2 6DF2 REX.W 6D | Base instruction set |
Latency and throughput
| Model | INSBINSWINSBINSW | INSDINSD |
|---|---|---|
| Sandy Bridge | 100 / 0.33p015 | 100 / 0.33p015 |
| Haswell | 21 / 1.25p01234567 | 21 / 1.25p01234567 |
| Broadwell, Skylake, Skylake-SP | 20 / 1.25p01234567 | 20 / 1.25p01234567 |
| Ice Lake | 20 / 1.25p0123456789 | 20 / 1.25p0123456789 |
| Alder Lake, Sapphire Rapids | 20 / 19p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 | 20 / 21p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 |
| Lunar Lake | 100 / 0.17p012345 | 100 / 0.17p012345 |
| Bonnell | 59 / 29.5p01 | 59 / 29.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.
n = min(OSIZE, 32) # REX.W: still a doubleword
if CPL > iopl and not io_allowed(dx, n):
fault(GP, 0) # as in the probe's cases: CPL 3,
# IOPL 0, the port not allowed
store(aDI, n, io_read(dx, n)) # ES:rDI; no prefix overrides ES
step = -(n // 8) if df else n // 8
aDI = low(aDI + step, ASIZE)Run on AMD Zen 5 (EPYC 9645): 9 cases. Every one raised an exception, at CPL 3, where the probe runs.
n = min(OSIZE, 32) # REX.W: still a doubleword
if CPL > iopl and not io_allowed(dx, n):
fault(GP, 0) # even when aCX is 0 (Zen 5)
step = -(n // 8) if df else n // 8
d = aDI
for i in range(aCX): # one port read per element
store(d, n, io_read(dx, n))
d = low(d + step, ASIZE)
aDI = d
aCX = 0Run on AMD Zen 5 (EPYC 9645): 10 cases. Every one raised an exception, at CPL 3, where the probe runs.
Operands
Flags
| DF | IOPL |
|---|---|
| All forms | |
| T | T |
Attributes
What else XED records about the forms. How to read.
- All forms
- may abort a TSX transaction
- 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 |
|---|---|---|
I186 | 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 |
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 2A, page 3-464 (INS/
INSB/ INSW/ INSD) - 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.39, 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.