Instruction
SHRD
Shifts an operand right 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
SHRD shifts its destination right and fills the vacated high bits from the bottom of a second register, as if the two formed one value of twice the width with the second register above. The second register is only read. It is the mirror image of SHLD, whose page says more about counts and speed.
Wide right shifts
GCC 14 and Clang 23 at -O2 compile x >> 20 on an
unsigned __int128 to shrd rax, rsi, 20 for the low half and a SHR
by 20 for the high half; when only the low 64 bits are wanted, as in
(uint64_t)(x >> 20), the SHRD alone remains. With n in a register,
both shift the halves by CL and then fix up counts of 64 and more with
two CMOVs, because the processor masks the count to 6 bits. For a
signed __int128, the high half takes a SAR instead.
When source and destination are the same
shrd eax, eax, n brings the low bits of EAX back in at the top, which
is a rotate right, as ROR does it; Intel’s optimization
manual notes that in Sandy Bridge this form with an immediate count has
a latency of one cycle (Section 3.5.1.4). The flags differ from ROR’s,
though: SHRD sets SF, ZF and PF from the result as well as CF and OF.
Edges
- Count 0. The destination and the flags stay as they were (a 32-bit register still has bits 63:32 cleared).
- 16 bits. A 16-bit SHRD can be given a masked count of 17 to 31, for which both manuals leave the result undefined. Zen 5 shifted the 48 bits of two copies of the source above the destination, so that the source’s bits came in a second time, and cleared CF.
- Memory. The destination may be in memory; the second operand is always a register.
AMD’s Zen 5 guide gives SHRD, like SHLD, a latency of three cycles (Section 2.10.2). 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 SHRD, a line per claim. Each links to the claim in the guide, with its sources and where they differ.
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.
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 |
|---|---|---|
SHRD m16/32/64, r16/32/64, imm8
SHRD_MEMv_GPRv_IMMb | 0F AC /r ib | Base instruction set |
SHRD r16/32/64, r16/32/64, imm8
SHRD_GPRv_GPRv_IMMb | 0F AC /r ib | Base instruction set |
SHRD m16/32/64, r16/32/64, CL
SHRD_MEMv_GPRv_CL | 0F AD /r | Base instruction set |
SHRD r16/32/64, r16/32/64, CL
SHRD_GPRv_GPRv_CL | 0F AD /r | Base instruction set |
SHRD r16/32/64, r16/32/64, imm8
SHRD_GPRv_GPRv_IMM8_APX | EVEX.LLZ.NP.MAP4.SCALABLE 2C /r ib | APX_F |
SHRD m16/32/64, r16/32/64, imm8
SHRD_MEMv_GPRv_IMM8_APX | EVEX.LLZ.NP.MAP4.SCALABLE 2C /r ib | APX_F |
SHRD r16/32/64, r16/32/64, imm8 NF
SHRD_GPRv_GPRv_IMM8_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE 2C /r ib NF=1 | APX_F + APX_NCI_NDD_NF |
SHRD m16/32/64, r16/32/64, imm8 NF
SHRD_MEMv_GPRv_IMM8_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE 2C /r ib NF=1 | APX_F + APX_NCI_NDD_NF |
SHRD r16/32/64, r16/32/64, r16/32/64, imm8 NDD NF optional
SHRD_GPRv_GPRv_GPRv_IMM8_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE 2C /r ib ND=1 NF=0/1 | APX_F + APX_NCI_NDD_NF |
SHRD r16/32/64, m16/32/64, r16/32/64, imm8 NDD NF optional
SHRD_GPRv_MEMv_GPRv_IMM8_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE 2C /r ib ND=1 NF=0/1 | APX_F + APX_NCI_NDD_NF |
SHRD r16/32/64, r16/32/64, CL
SHRD_GPRv_GPRv_CL_APX | EVEX.LLZ.NP.MAP4.SCALABLE AD /r | APX_F |
SHRD m16/32/64, r16/32/64, CL
SHRD_MEMv_GPRv_CL_APX | EVEX.LLZ.NP.MAP4.SCALABLE AD /r | APX_F |
SHRD r16/32/64, r16/32/64, CL NF
SHRD_GPRv_GPRv_CL_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE AD /r NF=1 | APX_F + APX_NCI_NDD_NF |
SHRD m16/32/64, r16/32/64, CL NF
SHRD_MEMv_GPRv_CL_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE AD /r NF=1 | APX_F + APX_NCI_NDD_NF |
SHRD r16/32/64, r16/32/64, r16/32/64, CL NDD NF optional
SHRD_GPRv_GPRv_GPRv_CL_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE AD /r ND=1 NF=0/1 | APX_F + APX_NCI_NDD_NF |
SHRD r16/32/64, m16/32/64, r16/32/64, CL NDD NF optional
SHRD_GPRv_MEMv_GPRv_CL_APX_N3 | EVEX.LLZ.NP.MAP4.SCALABLE AD /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 | 13 / 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 | 13 / 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.67p012345 | 5 / 0.67p012345 | 5 / 0.67p012345 |
| Bonnell | 6 / 3p1 | 4 / 2p1 | 9 / 4.5p1 | 6 / 3p01 | 2 / 1p01 | 9 / 4.5p01 | 6 / 3p1 | 4 / 2p1 | 9 / 4.5p1 | 6 / 3p01 | 2 / 1p01 | 8 / 4p01 |
| Silvermont | 4 / 2IEC0 MEC | 4 / 2IEC0 MEC | 4 / 2IEC0 MEC | 1 / 1IEC0 | 1 / 1IEC0 | 1 / 1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/ 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 src:src:dest, 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 = b << OSIZE | a # src above dest
r = low(x >> n) # the bottom half: dest, with the low n
# bits of src coming in from above
if n != 0 and not nf: # a count of 0 changes no flag; NF=1
# (APX) none at all
cf = a >> (n - 1) & 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 = b << OSIZE | a # src2 above src1
r = low(x >> n) # the bottom half: src1, with the low n
# bits of src2 coming in from above
if n != 0 and not nf: # a count of 0 changes no flag; NF=1
# none at all
cf = a >> (n - 1) & 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 |
|---|---|---|
SHRD 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 |
SHRD 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 |
SHRD 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 |
SHRD 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) |
SHRD 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 |
SHRD 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 |
|---|---|---|---|---|---|---|
SHRD 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 |
SHRD r/m16/32/64, r16/32/64, CL | ||||||
| in some cases | U | M | M | U | M | M |
| NF forms | ||||||
| Not affected | ||||||
SHRD 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 |
SHRD 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
- SHLD
- SHR
- 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-643 (SHRD)
- 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.