Instruction
PSRAW
Shifts packed words of an MMX or XMM register right arithmetically by a count from a register, memory or an immediate.
PSRAW shifts every word of an XMM or MMX register right by the same
count, copying each word’s sign bit into the vacated bits. Like
PSRAD, whose page covers the shared behaviour, it reads
its count from an immediate or from the whole low quadword of a register
or of memory, and a count of 16 or more leaves each word all sign, 0000h
or FFFFh. On Zen 5, the recorded psraw xmm7, 1 turned 8000h into C000h
and 7FFFh into 3FFFh, and psraw xmm4, xmm4, whose low quadword gave a
count of 15, reduced every word to its sign. The legacy XMM form keeps
bits 255:128 of its register (see mixing SSE and
AVX).
In compiled code
GCC 14 and Clang 23 at -O2, for the SSE2 baseline:
- Division by a power of two.
b[i] >> 3overint16_tis PSRAW by 3, which rounds toward minus infinity. Forb[i] / 4, rounding toward zero needs 3 added to negative elements first: Clang makes it with PSRAW by 15 and PSRLW by 14, GCC with PCMPGTW against zero and a PAND. - Signed bytes. No byte shift exists, so
b[i] >> 3overint8_tshifts words, GCC with PSRAW and Clang with PSRLW, keeps the five valid bits of each byte with a PAND of 1Fh, and extends their sign with a PXOR and a PSUBB of 10h. - Sign extension. To widen
int8_ttoint16_t, Clang puts each byte in the high half of a word with PUNPCKLBW of a register with itself and shifts by 8; GCC builds the high bytes with PCMPGTB against zero instead. SSE4.1’s PMOVSXBW replaces both. - Signed averages. For
(b[i] + c[i] + 1) >> 1overint16_t, Clang computes(b | c) - ((b ^ c) >> 1)with PSRAW, where the unsigned average is PAVGW.
AMD’s latency spreadsheet for Zen 5 gives the form with the count in a register two cycles, two per cycle. The MMX form came with MMX and the XMM form with SSE2, whose memory operand must be aligned to 16 bytes. VPSRAW is the VEX and EVEX form, and AVX512BW’s VPSRAVW takes a count per word.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
PSRAW mm, imm8
PSRAW_MMXq_IMMb | NP 0F 71 /4 ib | MMX |
PSRAW xmm, imm8
PSRAW_XMMdq_IMMb | 66 0F 71 /4 ib | SSE2 |
PSRAW mm, m64
PSRAW_MMXq_MEMq | NP 0F E1 /r | MMX |
PSRAW mm, mm
PSRAW_MMXq_MMXq | NP 0F E1 /r | MMX |
PSRAW xmm, m128
PSRAW_XMMdq_MEMdq | 66 0F E1 /r | SSE2 |
PSRAW xmm, xmm
PSRAW_XMMdq_XMMdq | 66 0F E1 /r | SSE2 |
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.
PSRAW mm, imm8 PSRAW xmm, imm8Every word works alike: 4 and 8 words in the mm and xmm forms.
Result word i comes from word i of xmm1. Result words 7 to 0: r7, r6, r5, r4, r3, r2, r1, r0.
PSRAW mm, mm/m64 PSRAW xmm, xmm/m128Every word works alike: 4 and 8 words in the mm and xmm forms.
Result word i comes from word i of xmm1 and the count in xmm2. Result words 7 to 0: r7, r6, r5, r4, r3, r2, r1, r0.
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
PSRAW mm, imm8for i in range(4):
mm1.w[i] = mm1.sw[i] >> imm8
# x87: TOP = 0, all tags valid, bits 79:64 of mm1's register all onesRun on AMD Zen 5 (EPYC 9645): 1 case.
PSRAW xmm, imm8for i in range(8):
xmm1.w[i] = xmm1.sw[i] >> imm8
# bits 128 and up of the register are unchangedRun on AMD Zen 5 (EPYC 9645): 1 case.
PSRAW mm, mm/m64count = src2.q[0]
for i in range(4):
mm1.w[i] = mm1.sw[i] >> count
# x87: TOP = 0, all tags valid, bits 79:64 of mm1's register all onesRun on AMD Zen 5 (EPYC 9645): 2 cases.
PSRAW xmm, xmm/m128count = src2.q[0]
for i in range(8):
xmm1.w[i] = xmm1.sw[i] >> count
# bits 128 and up of the register are unchangedRun on AMD Zen 5 (EPYC 9645): 2 cases.
Operands
| Operand | Kind | Action |
|---|---|---|
PSRAW mm, imm8 | ||
mm | explicit | read, write |
imm8 | explicit | read |
PSRAW xmm, imm8 | ||
xmm | explicit | read, write |
imm8 | explicit | read |
PSRAW mm, mm/m64 | ||
mm | explicit | read, write |
mm/m64 | explicit | read |
PSRAW xmm, xmm/m128 | ||
xmm | explicit | read, write |
xmm/m128 | 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.
PSRAW mm, imm8PSRAW mm, mm/m64mmx-memPSRAW xmm, imm8PSRAW xmm, xmmSSE_TYPE_7PSRAW xmm, m128SSE_TYPE_4
Attributes
What else XED records about the forms. How to read.
PSRAW mm, imm8PSRAW mm, mm/m64- may abort a TSX transaction
PSRAW xmm, m128- aligned memory operand
Intrinsics
The C intrinsics of Clang 23.1.2 that compile to PSRAW, 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_sra_epi16
__m128i _mm_sra_epi16(__m128i __a, __m128i __count) |
|
_mm_sra_pi16
__m64 _mm_sra_pi16(__m64 __m, __m64 __count) |
|
_mm_srai_epi16
__m128i _mm_srai_epi16(__m128i __a, int __count) |
|
_mm_srai_pi16
__m64 _mm_srai_pi16(__m64 __m, int __count) |
|
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.
More MMX instructions
- PADDB
- PADDD
- PADDSB
- PADDSW
- PADDUSB
- PADDUSW
- PADDW
- PAND
- PANDN
- PCMPEQB
- PCMPEQD
- PCMPEQW
- PCMPGTB
- PCMPGTD
- PCMPGTW
- PMADDWD
- PMULHW
- PMULLW
- POR
- PSLLD
- PSLLQ
- PSLLW
- PSRAD
- PSRLD
- PSRLQ
- PSRLW
- PSUBB
- PSUBD
- PSUBSB
- PSUBSW
- PSUBUSB
- PSUBUSW
- PSUBW
- PUNPCKHBW
- PUNPCKHDQ
- PUNPCKHWD
- PUNPCKLBW
- PUNPCKLDQ
- PUNPCKLWD
- PXOR
More SSE2 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. - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2B, page 4-455 (PSRAW/
PSRAD/ PSRAQ) - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1 (253665-093, September 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, part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.