Home/Instructions/Shift Left 2 and Add
SH2ADD

RISC-V SH2ADD Instruction Details

Instruction ManualR-type

Shift left by 2 and add

Instruction Syntax

sh2add rd, rs1, rs2
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
BZbaAddress GenerationBit Manipulation

Instruction Encoding

31..25
funct7
24..20
rs2
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

SH2ADD uses opcode 0110011 (0x33), funct3 100, funct7 0010000. The rs1 and rs2 fields select the two source registers, and rd selects the destination register.

Format: R-type
opcode: 0110011 (0x33)
funct3: 100 (0x4)
funct7: 0010000 (0x10)

Instruction Behavior

Shifts rs1 left by 2 then adds rs2: rd = rs2 + (rs1 << 2). For word (4-byte) array address generation. Part of Zba.

Quick Understanding & Search Notes

SH2ADD is a B/Zba instruction for rs2 plus rs1 shifted left by 2. This page is checked against the official B extension semantics, with emphasis on XLEN, W suffixes, .uw suffixes, and bitwise or rotate boundaries.

rs1 is shifted left by 2 and added to rs2, commonly for address generation.
The addition is XLEN-wide; the instruction itself does not access memory.

Common Usage Scenarios

Address & Pointer

Understand this scenario with real code like «sh2add x10, x11, x12 ; x10 = x12 + (x11 << 2)».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is R-type.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

Pitfalls / Common Confusions

Shift amount is fixed at 2

FAQ

Does SH2ADD access memory?

No. It only reads and writes integer registers; any memory access must be performed by a separate load or store instruction.

What is the result width of SH2ADD?

Except that W-suffixed forms produce a 32-bit result then sign-extend and .uw forms first extract a 32-bit unsigned operand, the result is written to rd at XLEN width.