Home/Instructions/Shift Right Arithmetic Immediate Word
SRAIW

RISC-V SRAIW Instruction Details

Instruction ManualI-type

Shift 32-bit value in rs1 right arithmetically by immediate, sign-extend 32-bit result to 64 bits

Instruction Syntax

sraiw rd, rs1, shamt
Operand Breakdown
Destination rd: general-purpose register receiving the result.
Source rs1: register holding the first operand.
Immediate imm: 12-bit signed value, sign-extended before operation with rs1.
RV64IArithmetic32-bit Shift

Instruction Behavior

SRAIW is an I-type instruction with opcode=0011011, funct3=101, and fixed imm[11:5]=0100000. It arithmetically shifts the lower 32 bits of rs1 by imm[4:0], copying the original bit 31 into vacated upper bits, then sign-extends the 32-bit result to 64 bits. Encodings with imm[5] not equal to 0 are reserved.

SRAIW Decode And Execute Animation

Starts with machine-code field decoding, then shows operand reads, instruction-specific execution, and ISA-visible state update.

rd
rs1
shamt
sraiw
,
,
Execution Context
a6(x16)
0xFFFFFFFFFFFFFFF0
31..25
24..20
19..15
14..12
11..7
6..0
0100000
fixed imm[11:5]
00010
shamt[4:0]
10000
rs1
101
funct3
00101
rd
0011011
opcode
Execution Data Path
instruction
0x4028529B
opcode
0011011 -> OP-IMM-32
funct3
101 -> SRAIW
imm[11:5]
imm[11:5]=0100000 fixed; shamt[4:0]=00010
rd / rs1
t0(x5) / a6(x16)
imm[11:5] + shamt[4:0]
imm[11:5]=0100000 fixed; shamt[4:0]=00010
32-bit arithmetic shift
0xFFFFFFF0 arithmetic >> 2 -> low 32 bits 0xFFFFFFFC -> sext.w 0xFFFFFFFFFFFFFFFC
x5
t0(x5) = 0xFFFFFFFFFFFFFFFC
Current Step

Concept Step: receive the 32-bit instruction encoding

The machine code is split by the current instruction format; the animation starts from encoding/decode.

encoding: 0x4028529B
syntax : sraiw t0(x5), a6(x16), 2
result : t0(x5) = 0xFFFFFFFFFFFFFFFC
Architectural Result
t0(x5) = 0xFFFFFFFFFFFFFFFC

This animation shows ISA-visible decode and state changes, not any specific CPU pipeline, cache, prediction, or timing implementation.

Common Usage Scenarios

Bit Operations & Masks

Understand this scenario with real code like «sraiw x10, x11, 2 # x10 = sign-extend((x11[31:0] >>> 2)[31:0])».

Pre-Use Checklist

Syntax Check
  • Verify the immediate field is within the valid range.
  • Confirm source register rs1 points to the correct operand.
Semantic Check
  • Check if the immediate sign-extension matches expectations.
  • Ensure the result register rd has a clear purpose.

Pitfalls / Common Confusions

Shift amounts >31 are reserved encodings
Arithmetic shift preserves sign, unlike SRLIW
W-suffix instructions produce a 32-bit result and sign-extend bit 31 to XLEN; do not treat them as ordinary 64-bit operations.
These W-suffix forms belong to RV64I; RV32 has no corresponding forms.
rd=x0 is a custom HINT; it does not change architecturally visible state except PC and applicable performance counters, and an implementation may ignore it.