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

VINSERTI128 copies a YMM source to the destination and replaces one 128-bit half of the copy, the low one if bit 0 of the immediate is 0, the high one if it is 1, with 16 bytes from an XMM register or memory. The other bits of the immediate are not used. It is the usual way to put two 128-bit values into one YMM register:

  • _mm256_set_m128i(hi, lo) becomes vinserti128 ymm0, ymm0, xmm1, 1 in GCC 14 at -O2, and in Clang 23 when integer instructions use the result, with lo already in the low half of YMM0, so the low half needs no instruction of its own.
  • Two 16-byte loads from unrelated addresses, such as two rows of an image, become a load and VINSERTI128 with a memory operand.
  • _mm256_broadcastsi128_si256 of a register inserts the register into itself; from memory, both compilers use VBROADCASTI128 instead.

Clang also turns _mm256_permute2x128_si256(a, b, 0x20) into VINSERTI128, which reads only 16 bytes when b is in memory, and an insert into the low half into the blend VPBLENDD; GCC emits VINSERTI128 with an immediate of 0 there.

Lanes

Most AVX and AVX2 instructions work within each 128-bit lane, and Intel’s optimization guide shows how loading the data of two iterations into the two lanes with inserts lets 128-bit algorithms run on YMM registers without lane-crossing shuffles (Sections 15.4.1 and 15.4.2). It also notes that in Crestmont the memory form takes two micro-ops of which the second waits for the first, while the register form runs both halves in parallel (Section 4.1.9.3).

VINSERTF128 does the same and needs only AVX; Clang emits it instead, for integer data too, when no integer instruction uses the result, as in a function that only joins two halves. The EVEX forms are VINSERTI32X4 and its kin, which insert 128 or 256 bits into ZMM registers, under a mask of doublewords or quadwords. VEXTRACTI128 is the reverse.

In the optimization guide

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

Crestmont and Gracemont

  • Vectors and AVX2: The 256-bit forms that widen or insert data loaded from memory take two dependent micro-ops.

Forms

Every encoding of VINSERTI128 that Intel XED knows, one row per XED instruction form (iform). How to read the notation.
InstructionEncodingRequires
VINSERTI128 ymm, ymm, m128, imm8 VINSERTI128_YMMqq_YMMqq_MEMdq_IMMbVEX.256.66.0F3A.W0 38 /r ibAVX2
VINSERTI128 ymm, ymm, xmm, imm8 VINSERTI128_YMMqq_YMMqq_XMMdq_IMMbVEX.256.66.0F3A.W0 38 /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.

Insert: xmm3 replaces the 128-bit block of ymm2 that imm8 numbers; the rest of the result comes from ymm2.
VINSERTI128 with imm8 = 0x02With imm8 = 0x02, result quadwords 3 to 0: a3, a2, b1, b0.0123ymm2ab0b1a2a3ymm101xmm3or m128b

Example: imm8 = 0x02.

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

Operation

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

ymm1.write(ymm2.read())
ymm1.dq[imm8 & 1] = src3.dq[0]
# 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
VINSERTI128 ymm, ymm, xmm/m128, imm8
ymmexplicitwrite
ymmexplicitread
xmm/m128explicitread
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 VINSERTI128, 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
_mm_broadcastsi128_si256 __m256i _mm_broadcastsi128_si256(__m128i X)

VINSERTI128 ymm, ymm, xmm, imm8 VEX.256 -mavx2

_mm256_broadcast_i32x4 __m256i _mm256_broadcast_i32x4(__m128i __A)

VINSERTI128 ymm, ymm, xmm, imm8 VEX.256 -mavx512vl

_mm256_broadcast_i64x2 __m256i _mm256_broadcast_i64x2(__m128i __A)

VINSERTI128 ymm, ymm, xmm, imm8 VEX.256 -mavx512vl -mavx512dq

_mm256_inserti128_si256 __m256i _mm256_inserti128_si256(__m256i V1, __m128i V2, const int M)

VINSERTI128 ymm, ymm, xmm, imm8 VEX.256 -mavx2

_mm256_inserti32x4 __m256i _mm256_inserti32x4(__m256i A, __m128i B, const int imm)

VINSERTI128 ymm, ymm, xmm, imm8 VEX.256 -mavx512vl

_mm256_inserti64x2 __m256i _mm256_inserti64x2(__m256i A, __m128i B, const int imm)

VINSERTI128 ymm, ymm, xmm, imm8 VEX.256 -mavx512vl -mavx512dq

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-411 (VINSERTI128/VINSERTI32x4/VINSERTI64x2/VINSERTI32x8/VINSERTI64x4)
  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.