SH2ADD

Shift Left 2 and Add

SH2ADD rd, rs1, rs2

Computes rd = rs2 + (rs1 << 2); scales an index by 4 for 32-bit elements.

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 0x20004033
Extension Zba

Operands

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

Example

SH2ADD x10, x11, x12

// Calculate address: x12 + (x11 * 4).

Related

More in Zba

Description

SH2ADD shifts rs1 left by 2 bits and adds the result to rs2, writing the sum to rd: rd = rs2 + (rs1 << 2). With rs1 an element index and rs2 a base address it computes the address of element rs1 of an array of 32-bit elements.

Operation

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