Instruction
PSHUFB
Rearranges the bytes of an MMX or XMM register by an index byte per result, which zeroes the byte when its top bit is set; SSSE3.
- Extensions
- Forms
- 4 (4 Legacy)
- Data
- Intel XED v2026.08.23
PSHUFB picks bytes by index. Each byte of the second operand selects
which byte of the first operand goes to its position in the result, and
a selector with bit 7 set writes zero there instead. Only the low four
bits of a selector count (three in the MMX form), so 10h selects byte 0
rather than giving zero. Because the selectors come from a register and
not from an immediate, one instruction applies any byte permutation,
chosen at run time or loaded from a table. In the intrinsic
_mm_shuffle_epi8(a, b), a holds the data and b the selectors.
It turns up in three roles:
- Fixed rearrangements, with a constant selector vector: reversing the order of the 16 bytes (the byte-order swap of a whole vector, which Intel’s optimization manual uses in a reverse memory copy), gathering the bytes of interest to one end, or spreading them out.
- Broadcasting a byte. All-zero selectors copy byte 0 everywhere.
Compiling for SSSE3, GCC 14 and Clang 23 at -O2 turn
_mm_set1_epi8(c)into MOVD, PXOR and PSHUFB; AVX2 has VPBROADCASTB for this. - Table lookup. With a table of 16 bytes as the data and values of 0 to 15 as selectors, PSHUFB looks up 16 entries at once. Splitting each byte into its low and high halves (a shift, and an AND with 0Fh) gives two lookups that together cover all 256 byte values; vector bit counting, hexadecimal conversion and character classification can be built this way.
The legacy form with a memory operand needs it aligned to 16 bytes. The VEX and EVEX forms, VPSHUFB, work within each 128-bit lane: a 256-bit shuffle cannot move a byte from one half of the register to the other, and each half needs its own copy of a lookup table. VPERMB of AVX512_VBMI permutes bytes across a whole register.
In the optimization guide
What the optimization guide says about PSHUFB, a line per claim. Each links to the claim in the guide, with its sources and where they differ.
Silvermont to Goldmont Plus
- Front end: Silvermont decodes SSSE3 and SSE4 instructions that use xmm8 to xmm15 slowly, as they exceed 3 bytes of prefixes and escapes. sources differ
- Vectors and cryptography: pshufb, pmulld, paddq and psubq are slow on Silvermont and much faster from Goldmont on.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
PSHUFB mm, m64
PSHUFB_MMXq_MEMq | NP 0F 38 00 /r | SSSE3 + MMX |
PSHUFB mm, mm
PSHUFB_MMXq_MMXq | NP 0F 38 00 /r | SSSE3 + MMX |
PSHUFB xmm, m128
PSHUFB_XMMdq_MEMdq | 66 0F 38 00 /r | SSSE3 |
PSHUFB xmm, xmm
PSHUFB_XMMdq_XMMdq | 66 0F 38 00 /r | SSSE3 |
Latency and throughput
| Model | mm, m64 | mm, mm | xmm, m128 | xmm, xmm |
|---|---|---|---|---|
| Sandy Bridge | 6 / 0.5p15 | 1 / 0.5p15 | 7 / 0.5p15 | 1 / 0.5p15 |
| Haswell | 6 / 1p5 | 1 / 1p5 | 7 / 1p5 | 1 / 1p5 |
| Broadwell | 6 / 1p5 | 1 / 1p5 | 6 / 1p5 | 1 / 1p5 |
| Skylake, Skylake-SP | 6 / 1p05 | 1 / 1p05 | 7 / 1p5 | 1 / 1p5 |
| Ice Lake | 6 / 1p05 | 1 / 1p05 | 7 / 0.5p15 | 1 / 0.5p15 |
| Alder Lake, Sapphire Rapids | 11 / 1p05 | 3 / 1p05 | 8 / 0.5p15 | 1 / 0.5p15 |
| Lunar Lake | 11 / 0.5V0 V1 V2 V3 | 3 / 0.5V0 V1 V2 V3 | 7 / 2V2 V3 | 1 / 0.5V2 V3 |
| Bonnell | 1 / 1p0 | 1 / 1p0 | 5 / 4p1 | 4 / 3p01 |
| Silvermont | 4 / 1FPC0 | 1 / 1FPC0 | 8 / 5FPC0 | 5 / 5FPC0 |
| Piledriver | 8 / 1.5FPU1 FPXBR | 3 / 1FPU1 FPXBR | 8 / 1.5FPU1 FPXBR | 3 / 1FPU1 FPXBR |
| Zen, Zen 2 | 8 / 0.5FPU1 FPU2 | 1 / 0.5FPU1 FPU2 | 8 / 0.5FPU1 FPU2 | 1 / 0.5FPU1 FPU2 |
| Zen 3, Zen 4 | 8 / 0.5FP1 FP2 | 1 / 0.5FP1 FP2 | 8 / 0.5FP1 FP2 | 1 / 0.5FP1 FP2 |
| Jaguar | 7 / 1FPU0 FPU1 VALU0 VALU1 | 2 / 0.5FPU0 FPU1 VALU0 VALU1 | 7 / 2FPU0 FPU1 VALU0 VALU1 | 2 / 2FPU0 FPU1 VALU0 VALU1 |
Data flow
Where the elements of the sources go, element 0 on the right; results that depend on a control value are drawn for an example. How to read.
Example index vector in xmm2 (element 0 on the right, in hex); only its low 4 bits and bit 7 count.
With the example indices, result bytes 15 to 0: a11, a6, a2, a10, a5, 0, a14, a1, a9, a15, a0, a7, a12, a12, 0, a3.
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
PSHUFB mm, mm/m64src1 = mm1.read() # mm1 as it was
for i in range(8):
x = src2.b[i]
if x & 0x80:
mm1.b[i] = 0
else:
mm1.b[i] = src1.b[x & 7]
# x87: TOP = 0, all tags valid, bits 79:64 of mm1's register all onesRun on AMD Zen 5 (EPYC 9645): 2 cases.
PSHUFB xmm, xmm/m128src1 = xmm1.read() # xmm1 as it was
for i in range(16):
x = src2.b[i]
if x & 0x80:
xmm1.b[i] = 0
else:
xmm1.b[i] = src1.b[x & 15]
# bits 128 and up of the register are unchangedRun on AMD Zen 5 (EPYC 9645): 2 cases.
Operands
| Operand | Kind | Action |
|---|---|---|
PSHUFB mm, mm/m64 | ||
mm | explicit | read, write |
mm/m64 | explicit | read |
PSHUFB xmm, xmm/m128 | ||
xmm | explicit | read, write |
xmm/m128 | explicit | read |
Flags
None: XED records no flag that the forms test or change.
Exceptions
The exception class is XED's name for the set of exception conditions that a form follows. How to read.
Attributes
What else XED records about the forms. How to read.
PSHUFB mm, mm/m64- may abort a TSX transaction
PSHUFB xmm, m128- aligned memory operand
Intrinsics
The C intrinsics of Clang 23.1.2 that compile to PSHUFB, each with the form it compiles to and the Clang options it needs. The forms come from compiling every intrinsic and decoding the result with Intel XED; all intrinsics A–Z explains the method.
| Intrinsic | Compiles to |
|---|---|
_mm_shuffle_epi8
__m128i _mm_shuffle_epi8(__m128i __a, __m128i __b) |
|
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 |
|---|---|---|
SSSE3MMX | SSSE3 + MMX XED and Intel’s SDM differ: For the forms on MMX registers that SSE2 added (PADDQ, PMULUDQ and PSUBQ) and those of SSSE3, XED also asks for the MMX bit, Sources: Intel XED v2026.08.23, datafiles/cpuid.xed.txt; Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026), PADDQ, PMULUDQ and PSUBQ: the opcode tables, pages 4-201, 4-395 and 4-487; PABSB/PABSW/PABSD/PABSQ and PSHUFB, pages 4-177 and 4-422, and the entries of the other SSSE3 instructions. | Core (Merom, Conroe), Penryn, Nehalem, Westmere, Sandy Bridge, Ivy Bridge, Haswell, Broadwell, Skylake, Comet Lake, Cannon Lake, Ice Lake (client), Tiger Lake, Alder Lake, Arrow Lake, Panther Lake, Nova Lake, Skylake-SP, Cascade Lake, Cooper Lake, Ice Lake (server), Sapphire Rapids, Emerald Rapids, Granite Rapids, Diamond Rapids, Bonnell, Saltwell, Silvermont, Goldmont, Goldmont Plus, Tremont, Snow Ridge, Lakefield, Sierra Forest, Clearwater Forest, Knights Landing, Knights Mill, K10 (Family 10h), Bulldozer, Piledriver, Zen, Zen+, Zen 2, Zen 3, Zen 4, Zen 5, Zen 6 |
SSSE3 | SSSE3 | Same as SSSE3MMXNote: XED's AMD_K10 inherits everything from its Westmere chip, including SSSE3, SSE4.1, SSE4.2, AES-NI and PCLMULQDQ; GCC's -march=amdfam10 has none of them. |
More SSSE3 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. - Clang's x86 intrinsic headers, LLVM 23.1.2 (commit
85ac56026243): the intrinsics, their signatures and doc comments, and the Clang of that release, which compiled each of them. - 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-422 (PSHUFB)
- Intel 64 and IA-32 Architectures Optimization Reference Manual, Volume 1 (248966-051, October 2026)
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 intrinsics and their signatures come from Clang and the timings from LLVM's scheduling models, both part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.