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 |
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.
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. - 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, part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.