Instruction
SHLX
Shifts the source left by a count in a register into a separate destination without touching the flags.
SHLX shifts its source left by a count from any register, zeros coming
in at the bottom, and writes a third register without touching the
flags. It is the BMI2 form of SHL, and the third of a set
whose other members, SHRX and SARX,
explain the masked count and why a shift without flags helps. In Intel
syntax the count comes last: shlx eax, edi, esi is EDI « ESI. The
count register is encoded in VEX.vvvv, so only the value to shift may
be in memory.
One instruction for both signs
A left shift is the same for signed and unsigned numbers, so where
right shifts split into SHRX and SARX, SHLX serves both: with
-march=x86-64-v3, GCC 14 and Clang 23 at -O2 compile x << n to
shlx eax, edi, esi for an int and for an unsigned alike, and to
shlx rax, rdi, rsi for a uint64_t. A shift by a constant stays
shl eax, 7 (GCC writes sal), as SHLX has no immediate form.
Building masks
A single variable bit, 1ULL << n, becomes mov eax, 1 and
shlx rax, rax, rdi. A mask of the low n bits, (1u << n) - 1, is
SHLX of 1 and a subtraction with GCC, and SHLX of -1 and a NOT with
Clang. Both give 0, not all ones, for n = 32: the count is masked to 0,
so the shift leaves 1 or -1 as it was. Zen 5 showed the masking in its
recorded cases: FFFFFFFFH shifted by 32 stayed FFFFFFFFH, and a 64-bit
4000000000000001H shifted by C1H, read as 1, became
8000000000000002H. Where n may reach the width, BZHI
of -1 gives the mask directly, as it keeps every bit for an index of 32
or more.
To set or test bit n of a variable, the compilers do not shift: they
compile x | 1ULL << n to BTS, and x >> n & 1 to SHRX
followed by an AND.
Width and speed
The destination is written whole, so a 32-bit form clears bits 63:32. APX adds EVEX forms that reach its new registers. AMD’s Zen 5 instruction table lists SHLX, like SHL, as one macro-op with a latency of one cycle, three per cycle. SHLX belongs to BMI2, part of x86-64-v3.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
SHLX r32, m32, r32
SHLX_GPR32d_MEMd_GPR32d | VEX.LZ.66.0F38.W0 F7 /r | BMI2 |
SHLX r32, r32, r32
SHLX_GPR32d_GPR32d_GPR32d | VEX.LZ.66.0F38.W0 F7 /r | BMI2 |
SHLX r64, m64, r64 64-bit mode only
SHLX_GPR64q_MEMq_GPR64q | VEX.LZ.66.0F38.W1 F7 /r | BMI2 |
SHLX r64, r64, r64 64-bit mode only
SHLX_GPR64q_GPR64q_GPR64q | VEX.LZ.66.0F38.W1 F7 /r | BMI2 |
SHLX r32, r32, r32
SHLX_GPR32i32_GPR32i32_GPR32i32_APX | EVEX.LLZ.66.0F38.W0 F7 /r | APX_F + BMI2 |
SHLX r32, m32, r32
SHLX_GPR32i32_MEMi32_GPR32i32_APX | EVEX.LLZ.66.0F38.W0 F7 /r | APX_F + BMI2 |
SHLX r64, r64, r64
SHLX_GPR64i64_GPR64i64_GPR64i64_APX | EVEX.LLZ.66.0F38.W1 F7 /r | APX_F + BMI2 |
SHLX r64, m64, r64
SHLX_GPR64i64_MEMi64_GPR64i64_APX | EVEX.LLZ.66.0F38.W1 F7 /r | APX_F + BMI2 |
Latency and throughput
| Model | r32, m32, r32r64, m64, r64 | r32, r32, r32r64, r64, r64 |
|---|---|---|
| Haswell, Broadwell, Skylake, Skylake-SP, Ice Lake | 6 / 0.5p06 | 1 / 0.5p06 |
| Alder Lake, Sapphire Rapids | 8 / 0.5p06 | 3 / 0.5p06 |
| Lunar Lake | 8 / 0.33p024 | 3 / 0.33p024 |
| Zen | 5 / 0.5ALU0 ALU1 ALU2 ALU3 | 1 / 0.25ALU0 ALU1 ALU2 ALU3 |
| Zen 2 | 5 / 0.33ALU0 ALU1 ALU2 ALU3 | 1 / 0.25ALU0 ALU1 ALU2 ALU3 |
| Zen 3, Zen 4 | 5 / 0.5ALU1 ALU2 | 1 / 0.5ALU1 ALU2 |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
n = count & (0x3F if OSIZE == 64 else 0x1F) # the count is masked
dest.write(src << n) # zeros come in from the bottom; no flag
# changes, whatever the count
Run on AMD Zen 5 (EPYC 9645): 45 cases. The APX forms were not run: none of these processors has APX.
Operands
| Operand | Kind | Action |
|---|---|---|
SHLX r32, r/m32, r32 SHLX r64, r/m64, r64 64-bit mode only | ||
r32/64 | explicit | write |
r/m32/64 | explicit | read |
r32/64 | 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.
- VEX forms
- none in XED
- EVEX forms
APX-EVEX-BMI
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 |
|---|---|---|
BMI2 | BMI2 | 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, Sierra Forest, Clearwater Forest, Knights Landing, Knights Mill, Zen, Zen+, Zen 2, Zen 3, Zen 4, Zen 5, Zen 6 |
APX_F_BMI2 | APX_F + BMI2 | Nova Lake, Diamond Rapids |
More BMI2 instructions
More APX 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. - 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-609 (SARX/
SHLX/ SHRX) - Intel Advanced Performance Extensions (Intel APX) Architecture Specification, revision 9.0 (355828-009, August 2026)
- AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 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 timings come from LLVM's scheduling models, part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.