srad

Shift Right Algebraic Doubleword

srad RA, RS, RB

Arithmetic right shift of 64-bit value (preserves sign).

Details

The srd instruction shifts the contents of register RS to the right by a number of bits specified by the upper 8 bits of RB (RB58:63). Bits shifted out of position 63 are lost. Bit 32 of RS is replicated to fill the vacated positions on the left. The result is placed into RA. If the shift amount is zero, RA receives EXTS((RS)32:63), and CA and CA32 are set to 0. Shift amounts from 32 to 63 give a result of 64 sign bits, and cause CA and CA32 to receive the sign bit of (RS)32:63.

Pseudocode Operation

n ←(RB)58:63
r ←ROTL64((RS), 64-n)
if (RB)57 = 0 then
     m ←MASK(n, 63)
else m ←640
RA ←r & m

Programming Note

The srad instruction is commonly used for right-shifting signed integers while preserving the sign bit. Be cautious with shift amounts of 32 or more, as they result in a full sign extension and clear the carry bits. Ensure that the input register RS contains valid data and that RB's upper 8 bits specify a valid shift amount (0-63).

Example

srad r4, r3, r5

Encoding

Binary Layout
31
0
RS
6
RA
11
RB
16
794
21
 
Format X-form
Opcode 0x7C000634
Extension Base

Operands

  • RA
    Target
  • RS
    Source
  • RB
    Shift Reg