Webcentive RISC-V Reference

c.addiw

Add a sign-extended non-zero immediate

Extension
C
XLEN
RV64 only
Assembly (riscv-unified-db)
c.addiw xd, imm
Length
16-bit (compressed)

Encoding

1513121176210
001imm[5]rd/rs≠0imm[4:0]01

Match 0x2001, mask 0xe003. Source: c.addiw rd_rs1_n0 c_imm6lo c_imm6hi 1..0=1 15..13=1 in riscv-opcodes/extensions/rv64_c.

FieldBitsriscv-opcodes name
imm[5]12c_imm6hi
rd/rs≠011:7rd_rs1_n0
imm[4:0]6:2c_imm6lo

Description

C.ADDIW is an RV64C/RV128C-only instruction that performs the same computation as C.ADDI but produces a 32-bit result, then sign-extends result to 64 bits. C.ADDIW expands into addiw xd, xd, imm. The immediate can be zero for C.ADDIW, where this corresponds to sext.w xd. C.ADDIW is only valid when xd ≠ x0; the code points with xd=x0 are reserved.

Description from riscv-unified-db, reformatted.

Operation

if (implemented?(ExtensionName::C) && MISA_CSR_IMPLEMENTED && (CSR[misa].C == 1'b0)) {
  reserved_instruction($encoding);
}

X[xd] = sext((X[xd] + sext(imm, 6)), 32);

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages