Instruction
PCMPESTRM
Compares two strings of explicit lengths in EAX and EDX (RAX and RDX with REX.W) as an immediate says, returning a mask in XMM0; SSE4.2.
- Extensions
- Forms
- 4 (4 Legacy)
- Data
- Intel XED v2026.08.23
PCMPESTRM is the mask form of PCMPESTRI: the same comparison of a pattern in the first operand with a text in the second, their lengths taken from EAX and EDX, but the result goes to XMM0 as a mask, the way PCMPISTRM returns it, instead of an index in ECX. PCMPESTRI’s page covers how the lengths are read: by absolute value, at most 16 bytes or 8 words, and from RAX and RDX with REX.W. PCMPISTRM’s covers the two shapes of mask that bit 6 of the control byte picks. The flags are PCMPESTRI’s. XMM0 is the destination whatever the operands are, and the legacy form keeps the bits of its register above bit 127, as each of Zen 5’s 17 recorded cases did.
Past the end of the text
The elements of the text past its length are invalid, and bits 5:4 of the control byte decide what their mask bits become. A plain negation (01b) inverts every bit, so they come out set; the masked negation (11b) inverts only the bits inside the text and leaves the rest clear. Zen 5 recorded both:
pcmpestrm xmm12, xmm6, 0x70searched “programming” (EDX = 11) for the vowels “aeiou” (EAX = 5) with the masked negation and an element mask: FFh at each of the eight consonants, 00h at o, a and i, and 00h in the five bytes past the text.pcmpestrm xmm12, xmm6, 0x13, two signed words against a text of EDX = -4, read as 4 words, matched words 0, 2 and 3; the plain negation returned F2h, setting the bits of the four words past the text as well as that of word 1.
A search for elements outside a set wants 11b, or a mask of the result by the length.
Cost and compiled code
AMD’s Zen 5 guide lists PCMPESTRM as seven macro-ops with a latency of 3, of which a core starts one every seven cycles, and twelve with a memory operand, one every four cycles; PCMPISTRM takes three.
From C, _mm_cmpestrm(a, la, b, lb, mode) needs -msse4.2. In our
builds at -O2, GCC 14 and Clang 23 move la into EAX, fold an
unaligned load of the text into the memory operand, and read a bit mask
with one MOVD from _mm_cvtsi128_si32. An element mask passed to
_mm_blendv_epi8 goes to PBLENDVB with no move
between the two, since both use XMM0.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
PCMPESTRM xmm, m128, imm8
PCMPESTRM_XMMdq_MEMdq_IMMb | 66 0F 3A 60 /r ib | SSE4.2 |
PCMPESTRM xmm, xmm, imm8
PCMPESTRM_XMMdq_XMMdq_IMMb | 66 0F 3A 60 /r ib | SSE4.2 |
PCMPESTRM xmm, m128, imm8 64-bit mode only
PCMPESTRM64_XMMdq_MEMdq_IMMb | 66 REX.W 0F 3A 60 /r ib | SSE4.2 |
PCMPESTRM xmm, xmm, imm8 64-bit mode only
PCMPESTRM64_XMMdq_XMMdq_IMMb | 66 REX.W 0F 3A 60 /r ib | SSE4.2 |
Latency and throughput
| Model | xmm, m128, imm8 | xmm, xmm, imm8 |
|---|---|---|
| Sandy Bridge | 17 / 2.33p015 | 11 / 2.67p015 |
| Haswell, Skylake, Skylake-SP, Ice Lake | 25 / 4p0156 | 19 / 4p0156 |
| Broadwell | 24 / 4p0156 | 19 / 4p0156 |
| Alder Lake, Sapphire Rapids | 17 / 3p0156 | 16 / 3p0156 |
| Lunar Lake | 17 / 3p012345 | 16 / 3p012345 |
| Silvermont | 20 / 17FPC0 | 17 / 17FPC0 |
| Piledriver | 15 / 11.5EX0 FPFMA FPMAL FPU1 | 10 / 10AGLU01 EX0 FPFMA FPMAL FPU1 Load Store |
| Zen, Zen 2 | 100 / 0.25 | 100 / 0.25 |
| Zen 3 | 13 / 3FP0 FP1 FP2 FP3 | 6 / 3FP0 FP1 FP2 FP3 |
| Zen 4 | 14 / 3FP0 FP1 FP2 FP3 | 7 / 3FP0 FP1 FP2 FP3 |
| Jaguar | 19 / 5ALU0 FPA FPU1 VALU0 VALU1 | 14 / 5ALU0 FPA FPU1 LAGU SAGU VALU0 VALU1 |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
n = 8 if imm8 & 1 else 16 # words, bytes
w = 128 // n # bits each
m = (1 << w) - 1
k = 1 << w - 1 if imm8 & 2 else 0 # signed
# the lengths: |EAX| and |EDX|, at most n,
# the count of imm8[0] (not of imm8[3])
la = min(abs(signed(eax)), n)
lb = min(abs(signed(edx)), n)
a = xmm1.read()
b = src2.read()
agg = imm8 >> 2 & 3
# (v >> w * i & m ^ k) - k: element i of v,
# sign-extended where k is its sign bit
r = 0
for j in range(n): # bit j: src2's
y = (b >> w * j & m ^ k) - k # element j
bit = 0
if agg == 0: # equal any: y is
for i in range(la): # in xmm1
x = (a >> w * i & m ^ k) - k
if j < lb and x == y:
bit = 1
elif agg == 1: # ranges: y is in
for i in range(0, la - 1, 2):
t = w * i # a pair's range
lo = (a >> t & m ^ k) - k
hi = (a >> t + w & m ^ k) - k
if j < lb and lo <= y <= hi:
bit = 1
elif agg == 2: # equal each
x = (a >> w * j & m ^ k) - k
if j < la and j < lb:
bit = x == y
else: # 1 past both ends
bit = j >= la and j >= lb
else: # equal ordered: xmm1
bit = 1 # from element j on;
# what would fall past the end of the
# register matches, and an empty xmm1
# everywhere, as in Intel's manual
# (AMD's clears these bits)
for i in range(min(la, n - j)):
x = (a >> w * i & m ^ k) - k
u = j + i
z = (b >> w * u & m ^ k) - k
if u >= lb or x != z:
bit = 0
r |= bit << j
p = imm8 >> 4 & 3
if p == 1: # negated
r ^= (1 << n) - 1
elif p == 3: # negated within src2
r ^= (1 << lb) - 1
# imm8[6]: each bit made an element of ones,
# words where imm8[0] is set (whatever
# imm8[1], which Intel's table names)
if imm8 & 0x40:
v = 0
for j in range(n):
if r >> j & 1:
v |= m << w * j
xmm0.write(v)
else:
xmm0.write(r) # the bits alone
cf = r != 0
zf = lb < n # src2 is short
sf = la < n # xmm1 is short
of = r & 1
af = pf = 0
# bits 128 and up of xmm0 are unchangedRun on AMD Zen 5 (EPYC 9645): 14 cases.
n = 8 if imm8 & 1 else 16 # words, bytes
w = 128 // n # bits each
m = (1 << w) - 1
k = 1 << w - 1 if imm8 & 2 else 0 # signed
# the lengths: |RAX| and |RDX| (REX.W), at
# most n, the count of imm8[0]
la = min(abs(signed(rax)), n)
lb = min(abs(signed(rdx)), n)
a = xmm1.read()
b = src2.read()
agg = imm8 >> 2 & 3
# (v >> w * i & m ^ k) - k: element i of v,
# sign-extended where k is its sign bit
r = 0
for j in range(n): # bit j: src2's
y = (b >> w * j & m ^ k) - k # element j
bit = 0
if agg == 0: # equal any: y is
for i in range(la): # in xmm1
x = (a >> w * i & m ^ k) - k
if j < lb and x == y:
bit = 1
elif agg == 1: # ranges: y is in
for i in range(0, la - 1, 2):
t = w * i # a pair's range
lo = (a >> t & m ^ k) - k
hi = (a >> t + w & m ^ k) - k
if j < lb and lo <= y <= hi:
bit = 1
elif agg == 2: # equal each
x = (a >> w * j & m ^ k) - k
if j < la and j < lb:
bit = x == y
else: # 1 past both ends
bit = j >= la and j >= lb
else: # equal ordered: xmm1
bit = 1 # from element j on;
# what would fall past the end of the
# register matches, and an empty xmm1
# everywhere, as in Intel's manual
# (AMD's clears these bits)
for i in range(min(la, n - j)):
x = (a >> w * i & m ^ k) - k
u = j + i
z = (b >> w * u & m ^ k) - k
if u >= lb or x != z:
bit = 0
r |= bit << j
p = imm8 >> 4 & 3
if p == 1: # negated
r ^= (1 << n) - 1
elif p == 3: # negated within src2
r ^= (1 << lb) - 1
# imm8[6]: each bit made an element of ones,
# words where imm8[0] is set (whatever
# imm8[1], which Intel's table names)
if imm8 & 0x40:
v = 0
for j in range(n):
if r >> j & 1:
v |= m << w * j
xmm0.write(v)
else:
xmm0.write(r) # the bits alone
cf = r != 0
zf = lb < n # src2 is short
sf = la < n # xmm1 is short
of = r & 1
af = pf = 0
# bits 128 and up of xmm0 are unchangedRun on AMD Zen 5 (EPYC 9645): 3 cases.
Operands
| Operand | Kind | Action |
|---|---|---|
PCMPESTRM xmm, xmm/m128, imm8 | ||
xmm | explicit | read |
xmm/m128 | explicit | read |
imm8 | explicit | read |
rAX | implicit | read |
rDX | implicit | read |
XMM0 | implicit | write |
RFLAGS | implicit | write |
Flags
| OF | SF | ZF | AF | PF | CF |
|---|---|---|---|---|---|
| All forms | |||||
| M | M | M | 0 | 0 | M |
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
Intrinsics
The C intrinsics of Clang 23.1.2 that compile to PCMPESTRM, 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_cmpestrm
__m128i _mm_cmpestrm(__m128i A, int LA, __m128i B, int LB, const int M) |
|
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 |
|---|---|---|
SSE42 | SSE4.2 | 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, 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 Note: 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 SSE4.2 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-256 (PCMPESTRM)
- AMD64 Architecture Programmer's Manual, Volume 4: 128-Bit, 256-Bit, and 512-Bit Media Instructions (26568, rev. 3.27, July 2026)
- Software Optimization Guide for the AMD Zen5 Microarchitecture (58455, rev. 1.00, August 2024), Wayback Machine copy of AMD's ZIP
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.