Instruction
PSHUFHW
Rearranges the upper four words of an XMM operand as an immediate selects, copying the lower four.
- Extensions
- Forms
- 2 (2 Legacy)
- Data
- Intel XED v2026.08.23
PSHUFHW rearranges the four words of the high quadword of its source and
copies the low quadword through unchanged, the mirror image of
PSHUFLW. Its immediate counts within the high half:
bits 1:0 choose which of words 4 to 7 lands in word 4, and so on up to
bits 7:6 for word 7, so the same immediate means the same arrangement
in either instruction. A word may be chosen more than once, the
destination is not read, and the intrinsic is
_mm_shufflehi_epi16(v, imm).
On its own it reverses or rotates the high four words; most often it
works in a pair or a trio with PSHUFLW and PSHUFD,
since SSE2 has no instruction that moves words freely across the whole
register (see PSHUFLW). Examples from GCC 14 and Clang 23 at -O2 for
the SSE2 baseline, written with GCC’s __builtin_shuffle and Clang’s
__builtin_shufflevector:
- Swapping neighboring words, the same arrangement in both halves: both compilers emit PSHUFLW B1h and PSHUFHW B1h.
- Broadcasting word 5: Clang emits PSHUFHW 55h, which copies word 5 into words 4 to 7, then PSHUFD EEh, which copies the high quadword down, the two-step broadcast that Intel’s optimization manual shows (Section 6.4.11). GCC uses PUNPCKHWD of the register with itself and PSHUFD 55h.
- Reversing the high half alone is one PSHUFHW 1Bh in both.
The legacy form reads all 16 bytes of a memory operand, which must be
aligned to 16. With SSSE3, a PSHUFB with a table can do
any of these at once: reversing all eight words, which Clang does with
PSHUFD, PSHUFLW and PSHUFHW for SSE2, is one PSHUFB in both compilers with
-mssse3. The VEX and EVEX forms,
VPSHUFHW, apply the immediate to the high quadword of
each 128-bit lane, and the EVEX form can mask words.
Forms
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: imm8 = 0x1B (0001 1011 in binary).
With imm8 = 0x1B, result words 7 to 0: a4, a5, a6, a7, a3, a2, a1, a0.
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
for i in range(8):
k = imm8 >> 2 * (i % 4) & 3
j = i - i % 4 + k if i % 8 >= 4 else i # the low four copied
xmm1.w[i] = src2.w[j]
# bits 128 and up of the register are unchangedRun on AMD Zen 5 (EPYC 9645): 2 cases.
Operands
| Operand | Kind | Action |
|---|---|---|
PSHUFHW xmm, xmm/m128, imm8 | ||
xmm | explicit | write |
xmm/m128 | explicit | read |
imm8 | 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.
- All forms
SSE_TYPE_4
Attributes
What else XED records about the forms. How to read.
- Memory forms
- aligned memory operand
Intrinsics
The C intrinsics of Clang 23.1.2 that compile to PSHUFHW, 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_shufflehi_epi16
__m128i _mm_shufflehi_epi16(__m128i a, const int imm) |
|
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 |
|---|---|---|
SSE2 | SSE2 | Every x86-64 processor in XED’s model and Zen 3 to Zen 6 |
More SSE2 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-430 (PSHUFHW)
- Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1 (253665-093, September 2026)
- 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.