SH2ADD

Shift Left 2 and Add

SH2ADD rd, rs1, rs2

Shifts rs1 left by 2 and adds rs2. Used for calculating addresses of 32-bit elements.

Details

SH2ADD shifts rs1 left by 2 bits, then adds to rs2, writing to rd. Used for stride-4 array indexing (e.g., int32 arrays).

Pseudocode Operation

R[rd] = R[rs2] + (R[rs1] << 2);

Example

SH2ADD x10, x11, x12

Encoding

Binary Layout
0010000
31:25
rs2
24:20
rs1
19:15
100
14:12
rd
11:7
0110011
6:0
 
Format R-Type
Opcode 0x33
Extension Zba

Operands

  • rd
    Destination register (integer)
  • rs1
    Index
  • rs2
    Base