Extensions
Forms
2 (2 VEX)
Data
Intel XED v2026.08.23

VPERM2I128 builds a YMM register from 128-bit halves: each half of the result is one of the four halves of its two sources, or zero. The immediate has a nibble per result half, low nibble for the low half: bits 1:0 choose the block (0 and 1 the low and high half of the first source, 2 and 3 those of the second), bit 3 writes zeros instead, and bit 2 is not used. So 0x20 joins the two low halves, 0x31 the two high ones, 0x21 takes the high half of the first source and the low half of the second, and 0x01 with the same register twice swaps its halves.

It is the tool for the steps that in-lane shuffles leave: most AVX2 instructions work on each 128-bit lane separately, so code that needs data to cross between the lanes, such as a transpose or a byte shift of the whole register built on VPALIGNR, combines halves with it. The intrinsic is _mm256_permute2x128_si256.

What compilers make of it

GCC 14 at -O2 emits VPERM2I128 for the intrinsic whatever the immediate. Clang 23 replaces it with something cheaper or shorter when it can:

  • 0x20, two low halves, becomes VINSERTI128; when the second source is in memory, that reads 16 bytes instead of 32.
  • A swap of one register’s halves becomes VPERMQ (or VPERMPD) with 0x4E.
  • Without integer instructions around it, Clang uses the floating-point twin VPERM2F128, an AVX instruction that does the same.

Intel’s optimization guide shows an 8x8 transpose that loads 128-bit halves with VINSERTF128 instead of combining 256-bit loads with VPERM2F128, which in the Sandy Bridge microarchitecture runs only on port 5, the port of the other shuffles (Section 15.11.2); in Crestmont it takes two micro-ops and seven cycles (Section 4.1.9.1).

There is no EVEX form. With AVX-512, VSHUFI64X2 and VSHUFI32X4 pick 128-bit blocks for ZMM registers, each half of the result from one source, with masking; only a zeroing mask makes them write zeros.

In the optimization guide

What the optimization guide says about VPERM2I128, a line per claim. Each links to the claim in the guide, with its sources and where they differ.

Crestmont and Gracemont

Zen and Zen+

Forms

Every encoding of VPERM2I128 that Intel XED knows, one row per XED instruction form (iform). How to read the notation.
InstructionEncodingRequires
VPERM2I128 ymm, ymm, m256, imm8 VPERM2I128_YMMqq_YMMqq_MEMqq_IMMbVEX.256.66.0F3A.W0 46 /r ibAVX2
VPERM2I128 ymm, ymm, ymm, imm8 VPERM2I128_YMMqq_YMMqq_YMMqq_IMMbVEX.256.66.0F3A.W0 46 /r ibAVX2

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.

128-bit blocks by immediate: each half of the result is one of the four 128-bit halves of ymm2 and ymm3, or zero, as four bits of imm8 say.
VPERM2I128 with imm8 = 0x21With imm8 = 0x21, result quadwords 3 to 0: b1, b0, a3, a2.0x21imm8example0123ymm2aa2a3b0b1ymm10123ymm3or m256b

Example: imm8 = 0x21 (0010 0001 in binary).

With imm8 = 0x21, result quadwords 3 to 0: b1, b0, a3, a2.

Operation

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

for h in range(2):
    x = imm8 >> 4 * h & 15
    if x & 8:
        ymm1.dq[h] = 0
    elif x & 2:
        ymm1.dq[h] = src3.dq[x & 1]
    else:
        ymm1.dq[h] = ymm2.dq[x & 1]
# ymm1 is zeroed from bit 256 up

Run on AMD Zen 5 (EPYC 9645): 2 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
VPERM2I128 ymm, ymm, ymm/m256, imm8
ymmexplicitwrite
ymmexplicitread
ymm/m256explicitread
imm8explicitread

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
avx-type-6

Intrinsics

The C intrinsics of Clang 23.1.2 that compile to VPERM2I128, 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.

IntrinsicCompiles to
_mm256_alignr_epi64 __m256i _mm256_alignr_epi64(__m256i A, __m256i B, const int imm)

VPERM2I128 ymm, ymm, ymm, imm8 VEX.256 -mavx512vl

_mm256_permute2x128_si256 __m256i _mm256_permute2x128_si256(__m256i V1, __m256i V2, const int M)

VPERM2I128 ymm, ymm, m256, imm8 VEX.256 -mavx2when V2 comes from memory

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.

More AVX2 instructions

All 138 AVX2 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. 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.
  4. Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2C, page 5-496 (VPERM2I128)
  5. 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.