sraw
Shift Right Algebraic Word
sraw RA, RS, RB
Performs an arithmetic right shift (sign bit replicated) on a 32-bit word. Updates Carry (CA) if bits are shifted out.
Details
Arithmetically shift the 32-bit word in RS right by the number of bits specified in RB[27:31], replicating the sign bit into vacated positions. The result is placed in RA. The CA bit in XER is set if any 1-bits are shifted out from a negative value, otherwise cleared. If Rc=1, CR0 is updated based on the result.
Pseudocode Operation
n ← RB[27:31]
if n = 0 then
RA ← RS
CA ← 0
else if n < 32 then
shifted ← RS >> n
if RS[0] = 1 ∧ (RS & ((1 << n) - 1)) ≠ 0 then
CA ← 1
else
CA ← 0
RA ← shifted
else
if RS[0] = 1 then
RA ← -1
CA ← 1
else
RA ← 0
CA ← 0
if Rc = 1 then
CR0 ← (RA = 0) || LT || GT || SO
Programming Note
When Rc=1 (dot form), CR0 is updated with the signed comparison of the result against zero (LT, GT, EQ) and the current SO bit from XER.
Example
sraw r3, r4, r5
// r3 = r4 >> r5 (Signed 32-bit).
Encoding
Binary Layout
31
0
RS
6
RA
11
RB
16
792
21
Rc
31
Operands
-
RA
Target Register -
RS
Source Register -
RB
Shift Amount Register