srai
srai
rd, rs1, shamt
rd = rs1 >> shamt
R
31–25funct7
24–20rs2
19–15rs1
14–12funct3
11–7rd
6–0opcode
I
31–20imm[11:0]
19–15rs1
14–12funct3
11–7rd
6–0opcode
S
31–25imm[11:5]
24–20rs2
19–15rs1
14–12funct3
11–7imm[4:0]
6–0opcode
B
31–25imm[12,10:5]
24–20rs2
19–15rs1
14–12funct3
11–7imm[4:1,11]
6–0opcode
U
31–12imm[31:12]
11–7rd
6–0opcode
J
31–12imm[20,10:1,11,19:12]
11–7rd
6–0opcode

srai shifts bits to the right by a fixed amount, filling the vacated top positions with copies of the sign bit so that negative numbers stay negative. It is the constant-amount version of sra (which explains the sign-preserving fill and why it matters); the i means immediate, a constant written into the instruction rather than read from a register.

The form is srai rd, rs1, amount, with amount a fixed value from 0 to 31. Because each place shifted right halves the number, and the sign is preserved throughout, srai performs signed division by a power of two: srai t0, t0, 1 halves a signed value whether it is positive or negative, srai t0, t0, 3 divides by 8.

The one quirk to remember is rounding direction. srai always rounds downward, toward the more-negative side, rather than toward zero. So -7 shifted right by 1 gives -4, while the div instruction dividing by 2 would give -3. For non-negative numbers and for exact divisions the two agree; they differ by one only on negative numbers with a remainder. In most graphics, audio, and signal work the downward rounding is exactly what you want.

The rule of thumb across all four shifts: use srai for signed numbers being divided, srli for raw bits or never-negative values, and the non-i forms (sra, srl) when the shift distance is computed at runtime rather than fixed.