Instruction
SHLD
Shifts an operand left and fills the vacated bits from a second register; APX adds three-operand forms and forms that leave the flags unchanged.
- Extensions
- Forms
- 16 (4 Legacy, 12 EVEX)
- Data
- Intel XED v2026.08.23
SHLD shifts its destination left and fills the vacated low bits from the top of a second register, as if the two formed one value of twice the width with the destination above. The second register is only read. SHRD is the mirror image: it shifts right and fills the top from the bottom of the second register.
That is the step a wide shift needs. GCC 14 and Clang 23 at -O2
compile x << 5 on an unsigned __int128 to shld rdx, rdi, 5 for
the high half and a SHL by 5 for the low one, and take 64 bits from
the middle of a 128-bit value, (uint64_t)(x >> 20), with a single
shrd rax, rsi, 20. A constant funnel shift such as
(hi << 52) | (lo >> 12) becomes shld rax, rsi, 52.
The count
The count is masked to 5 bits, or 6 for a 64-bit operand, as for
SHL. For a 128-bit x << n with n
in a register, both compilers therefore run SHLD and SHL by CL on the
two halves, then test bit 6 of the count and, when n is 64 or more,
use two CMOVs to move the low result into the high half and clear the
low half.
A masked count of 0 leaves the destination and the flags alone. So the
variable funnel shift (hi << n) | (lo >> (-n & 63)) does not become
SHLD: for n = 0 it gives hi | lo, where SHLD would give hi. Both
compilers build it from two shifts and an OR instead.
16-bit operands
With a 16-bit operand, the masked count can reach 31, more than the 16 bits the second register supplies. Intel’s and AMD’s manuals leave the result undefined then, and Intel’s leaves all the flags undefined too. Zen 5 shifted the 48 bits of the destination above two copies of the source, so that the source’s bits came in a second time, and cleared CF.
Speed
Intel’s optimization manual lists SHLD among the instructions of the one “Slow Int” execution unit of Golden Cove, beside MUL and BSR (Table 2-4). AMD’s Zen 5 guide gives SHLD and SHRD a latency of three cycles (Section 2.10.2), and its instruction table lists them as microcoded. APX adds forms with a new destination and forms that leave the flags unchanged (NF).
In the optimization guide
What the optimization guide says about SHLD, a line per claim. Each links to the claim in the guide, with its sources and where they differ.
Bulldozer to Excavator
- Integer execution: SHLD and SHRD are microcoded, 4 cycles in AMD’s table.
Golden Cove and Raptor Cove
- Integer execution: Port 1 alone runs the slower integer operations: multiplication, PDEP and PEXT,
popcnt,bsr,crc32and the double shifts with an immediate count, which LLVM’s models give a latency of three cycles and one per cycle.
Jaguar and Puma
- Integer execution: SHLD and SHRD are microcoded, six to eight macro-ops in AMD’s spreadsheet, and LLVM treats double shifts as slow on these cores.
Silvermont to Goldmont Plus
- Out-of-order and in-order execution: shld and shrd come from microcode at 64 bits, with a memory destination or a count in cl. sources differ
Skylake to Cooper Lake
- Integer execution: Port 1 alone runs integer multiplication, PDEP and PEXT,
popcnt,lzcnt,tzcnt,bsf,bsrand the double shifts, with a latency of three cycles and one a cycle in LLVM’s models, as on Golden Cove.
Zen and Zen+
- Integer execution: SHLD is microcoded, taking four cycles in AMD’s spreadsheet, and LLVM treats double shifts as slow for
-march=znver1. sources differ
Zen 2
- Integer execution: SHLD and SHRD are microcoded, and LLVM treats them as slow for
-march=znver2, as it stops doing for Zen 3. sources differ
Zen 3
- Integer execution: SHLD and SHRD have a latency of three cycles, and LLVM’s
-march=znver3no longer treats them as slow, as it does for the Zen cores before. sources differ
Zen 4
- Integer execution: SHLD and SHRD have a latency of three cycles. sources differ
Forms
| Instruction | Encoding | Requires |
|---|---|---|
SHLD m16/32/64, r16/32/64, imm8
SHLD_MEMv_GPRv_IMMb | 0F A4 /r ib | Base instruction set |
SHLD r16/32/64, r16/32/64, imm8
SHLD_GPRv_GPRv_IMMb | 0F A4 /r ib | Base instruction set |
SHLD m16/32/64, r16/32/64, CL
SHLD_MEMv_GPRv_CL | 0F A5 /r | Base instruction set |
SHLD r16/32/64, r16/32/64, CL
SHLD_GPRv_GPRv_CL | 0F A5 /r | Base instruction set |
SHLD r16/32/64, r16/32/64, imm8
SHLD_GPRv_GPRv_IMM8_APX | EVEX.LLZ.NP.MAP4.SCALABLE 24 /r ib | APX_F |
SHLD m16/32/64, r16/32/64, imm8
SHLD_MEMv_GPRv_IMM8_APX | EVEX.LLZ.NP.MAP4.SCALABLE 24 /r ib | APX_F |
SHLD r16/32/64, r16/32/64, imm8 NF
SHLD_GPRv_GPRv_IMM8_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE 24 /r ib NF=1 | APX_F + APX_NCI_NDD_NF |
SHLD m16/32/64, r16/32/64, imm8 NF
SHLD_MEMv_GPRv_IMM8_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE 24 /r ib NF=1 | APX_F + APX_NCI_NDD_NF |
SHLD r16/32/64, r16/32/64, r16/32/64, imm8 NDD NF optional
SHLD_GPRv_GPRv_GPRv_IMM8_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE 24 /r ib ND=1 NF=0/1 | APX_F + APX_NCI_NDD_NF |
SHLD r16/32/64, m16/32/64, r16/32/64, imm8 NDD NF optional
SHLD_GPRv_MEMv_GPRv_IMM8_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE 24 /r ib ND=1 NF=0/1 | APX_F + APX_NCI_NDD_NF |
SHLD r16/32/64, r16/32/64, CL
SHLD_GPRv_GPRv_CL_APX | EVEX.LLZ.NP.MAP4.SCALABLE A5 /r | APX_F |
SHLD m16/32/64, r16/32/64, CL
SHLD_MEMv_GPRv_CL_APX | EVEX.LLZ.NP.MAP4.SCALABLE A5 /r | APX_F |
SHLD r16/32/64, r16/32/64, CL NF
SHLD_GPRv_GPRv_CL_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE A5 /r NF=1 | APX_F + APX_NCI_NDD_NF |
SHLD m16/32/64, r16/32/64, CL NF
SHLD_MEMv_GPRv_CL_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE A5 /r NF=1 | APX_F + APX_NCI_NDD_NF |
SHLD r16/32/64, r16/32/64, r16/32/64, CL NDD NF optional
SHLD_GPRv_GPRv_GPRv_CL_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE A5 /r ND=1 NF=0/1 | APX_F + APX_NCI_NDD_NF |
SHLD r16/32/64, m16/32/64, r16/32/64, CL NDD NF optional
SHLD_GPRv_MEMv_GPRv_CL_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE A5 /r ND=1 NF=0/1 | APX_F + APX_NCI_NDD_NF |
Latency and throughput
| Model | m16, r16, imm8 | m32, r32, imm8 | m64, r64, imm8 | r16, r16, imm8 | r32, r32, imm8 | r64, r64, imm8 | m16, r16, CL | m32, r32, CL | m64, r64, CL | r16, r16, CL | r32, r32, CL | r64, r64, CL |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Sandy Bridge | 8 / 1p015 | 8 / 1p015 | 8 / 1p015 | 2 / 0.67p015 | 2 / 0.67p015 | 2 / 0.67p015 | 10 / 1.5p015 | 10 / 1.5p015 | 10 / 1.5p015 | 4 / 1.5p015 | 4 / 1.5p015 | 4 / 1.5p015 |
| Haswell | 10 / 1p0156 | 10 / 1p0156 | 10 / 1p0156 | 3 / 1p1 | 3 / 1p1 | 3 / 1p1 | 12 / 1p0156 | 12 / 1p0156 | 12 / 1p0156 | 6 / 1p0156 | 6 / 1p0156 | 6 / 1p0156 |
| Broadwell, Skylake, Skylake-SP, Ice Lake | 9 / 1p0156 | 9 / 1p0156 | 9 / 1p0156 | 3 / 1p1 | 3 / 1p1 | 3 / 1p1 | 11 / 1p0156 | 11 / 1p0156 | 11 / 1p0156 | 6 / 1p0156 | 6 / 1p0156 | 6 / 1p0156 |
| Alder Lake, Sapphire Rapids | 12 / 1p0 p1 p5 p6 p11 | 12 / 1p0 p1 p5 p6 p11 | 12 / 1p0 p1 p5 p6 p11 | 3 / 1p1 | 3 / 1p1 | 3 / 1p1 | 12 / 1p0 p1 p5 p6 p11 | 12 / 1p0 p1 p5 p6 p11 | 12 / 1p0 p1 p5 p6 p11 | 5 / 1p0 p1 p5 p6 p11 | 5 / 1p0 p1 p5 p6 p11 | 5 / 1p0 p1 p5 p6 p11 |
| Lunar Lake | 12 / 0.5p012345 | 12 / 0.5p012345 | 12 / 0.5p012345 | 3 / 0.33p135 | 3 / 0.33p135 | 3 / 0.33p135 | 12 / 0.67p012345 | 12 / 0.67p012345 | 12 / 0.67p012345 | 5 / 0.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ALU1 ALU2 | 2 / 1.5ALU1 ALU2 | 2 / 1.5ALU1 ALU2 | 2 / 1.5ALU1 ALU2 |
| Jaguar | 9 / 11ALU0 ALU1 | 9 / 11ALU0 ALU1 | 9 / 11ALU0 ALU1 | 3 / 3ALU0 ALU1 | 3 / 3ALU0 ALU1 | 3 / 3ALU0 ALU1 | 9 / 11ALU0 ALU1 | 9 / 11ALU0 ALU1 | 9 / 11ALU0 ALU1 | 4 / 4ALU0 ALU1 | 4 / 4ALU0 ALU1 | 4 / 4ALU0 ALU1 |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
a = dest.read()
b = src.read()
n = count & (0x3F if OSIZE == 64 else 0x1F) # the count is masked
if OSIZE == 16 and n > 16:
# Intel's manual leaves the result and the flags undefined. Zen 5
# shifts the 48 bits of dest:src:src, so that src comes in
# again, and clears CF.
dest.write(UNDEFINED)
if not nf:
of = sf = zf = UNDEFINED
af = pf = cf = UNDEFINED
else:
x = a << OSIZE | b # dest above src
r = low(x << n >> OSIZE) # the top half: dest, with the top n
# bits of src coming in from below
if n != 0 and not nf: # a count of 0 changes no flag; NF=1
# (APX) none at all
cf = x >> (2 * OSIZE - n) & 1 # the last bit shifted out
flip = msb(r) ^ msb(a)
of = flip if n == 1 else UNDEFINED # the sign changed
sf = msb(r)
zf = r == 0
pf = parity(r)
af = UNDEFINED
dest.write(r) # even for a count of 0, a 32-bit
# register gets bits 63:32 cleared
Run on AMD Zen 5 (EPYC 9645): 131 cases. The APX forms were not run: none of these processors has APX.
a = src1.read()
b = src2.read()
n = count & (0x3F if OSIZE == 64 else 0x1F) # the count is masked
if OSIZE == 16 and n > 16:
# Intel's manual leaves the result and the flags undefined
dest.write(UNDEFINED)
if not nf:
of = sf = zf = UNDEFINED
af = pf = cf = UNDEFINED
else:
x = a << OSIZE | b # src1 above src2
r = low(x << n >> OSIZE) # the top half: src1, with the top n
# bits of src2 coming in from below
if n != 0 and not nf: # a count of 0 changes no flag; NF=1
# none at all
cf = x >> (2 * OSIZE - n) & 1 # the last bit shifted out
flip = msb(r) ^ msb(a)
of = flip if n == 1 else UNDEFINED # the sign changed
sf = msb(r)
zf = r == 0
pf = parity(r)
af = UNDEFINED
dest.write(r) # the new destination: bits 63:OSIZE
# cleared, even for 16 bits
Not run on a processor: none of these processors has APX.
Operands
| Operand | Kind | Action |
|---|---|---|
SHLD r/m16/32/64, r16/32/64, imm8 | ||
r/m16/32/64 | explicit | read, conditional write |
r16/32/64 | explicit | read |
imm8 | explicit | read |
RFLAGS | implicit | write |
SHLD r/m16/32/64, r16/32/64, CL | ||
r/m16/32/64 | explicit | read, conditional write |
r16/32/64 | explicit | read |
CL | explicit | read |
RFLAGS | implicit | conditional write |
SHLD r/m16/32/64, r16/32/64, imm8 NF | ||
r/m16/32/64 | explicit | read, conditional write |
r16/32/64 | explicit | read |
imm8 | explicit | read |
SHLD r16/32/64, r/m16/32/64, r16/32/64, imm8 NDD NF optional | ||
r16/32/64 | explicit | write |
r/m16/32/64 | explicit | read |
r16/32/64 | explicit | read |
imm8 | explicit | read |
RFLAGS | implicit | write (NF=0) |
SHLD r/m16/32/64, r16/32/64, CL NF | ||
r/m16/32/64 | explicit | read, conditional write |
r16/32/64 | explicit | read |
CL | explicit | read |
SHLD r16/32/64, r/m16/32/64, r16/32/64, CL NDD NF optional | ||
r16/32/64 | explicit | write |
r/m16/32/64 | explicit | read |
r16/32/64 | explicit | read |
CL | explicit | read |
RFLAGS | implicit | conditional write (NF=0) |
Flags
| When | OF | SF | ZF | AF | PF | CF |
|---|---|---|---|---|---|---|
SHLD r/m16/32/64, r16/32/64, imm8 | ||||||
| count 1 | M | M | M | U | M | M |
| count 2 or more | U | M | M | U | M | M |
SHLD r/m16/32/64, r16/32/64, CL | ||||||
| in some cases | U | M | M | U | M | M |
| NF forms | ||||||
| Not affected | ||||||
SHLD r16/32/64, r/m16/32/64, r16/32/64, imm8 NDD NF optional | ||||||
| NF=0, count 1 | M | M | M | U | M | M |
| NF=0, count 2 or more | U | M | M | U | M | M |
SHLD r16/32/64, r/m16/32/64, r16/32/64, CL NDD NF optional | ||||||
| NF=0, in some cases | U | M | M | U | M | M |
Exceptions
The exception class is XED's name for the set of exception conditions that a form follows. How to read.
- Legacy forms
- none in XED
- EVEX forms
APX-EVEX-INT
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 |
|---|---|---|
I386 | No CPUID bit: part of the base instruction set. | Every x86-64 processor in XED’s model and Zen 3 to Zen 6 |
APX_F | APX_F | Nova Lake, Diamond Rapids |
APX_F_N3 | APX_F + APX_NCI_NDD_NF | Same as APX_F |
More General-purpose instructions
- NEG
- NOP
- NOT
- OR
- OUT
- OUTS
- PAUSE
- POP
- POPA
- POPF
- PUSH
- PUSHA
- PUSHF
- RCL
- RCR
- RET
- ROL
- ROR
- SALC
- SAR
- SBB
- SCAS
- SETcc
- SHL
- SHR
- SHRD
- STC
- STD
- STI
- STOS
- SUB
- TEST
- UD0
- UD1
- UD2
- UDB
- XADD
- XCHG
- XLAT
- XOR
All 109 General-purpose 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-640 (SHLD)
- 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)
- Intel 64 and IA-32 Architectures Optimization Reference Manual, Volume 1 (248966-051, 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.