# 6 RV64I Base Integer Instruction Set, Version 2.0

This chapter describes the RV64I base integer instruction set, which builds upon the RV32I variant described in Chapter [rv32]. This chapter presents only the differences with RV32I, so should be read in conjunction with the earlier chapter.

## 6.1 Register State

RV64I widens the integer registers and supported user address space to 64 bits (XLEN=64 in Figure [gprs]).

## 6.2 Integer Computational Instructions

Additional instruction variants are provided to manipulate 32-bit values in RV64I, indicated by a ‘W’ suffix to the opcode. These “*W” instructions ignore the upper 32 bits of their inputs and always produce 32-bit signed values, i.e. bits XLEN-1 through 31 are equal. They cause an illegal instruction exception in RV32I.

#### Integer Register-Immediate Instructions

ADDIW is an RV64I-only instruction that adds the sign-extended 12-bit
immediate to register *rs1* and produces the proper sign-extension
of a 32-bit result in *rd*. Overflows are ignored and the result
is the low 32 bits of the result sign-extended to 64 bits. Note,
ADDIW *rd, rs1, 0* writes the sign-extension of the lower 32 bits
of register *rs1* into register *rd* (assembler pseudo-op
SEXT.W).

Shifts by a constant are encoded as a specialization of the I-type
format using the same instruction opcode as RV32I. The operand to be
shifted is in *rs1*, and the shift amount is encoded in the lower
6 bits of the I-immediate field for RV64I. The right shift type is
encoded in bit 30. SLLI is a logical left shift (zeros are shifted
into the lower bits); SRLI is a logical right shift (zeros are shifted
into the upper bits); and SRAI is an arithmetic right shift (the
original sign bit is copied into the vacated upper bits). For RV32I,
SLLI, SRLI, and SRAI generate an illegal instruction exception if
*i**m**m*[5] ≠ 0.

SLLIW, SRLIW, and SRAIW are RV64I-only instructions that are
analogously defined but operate on 32-bit values and produce
signed 32-bit results. SLLIW, SRLIW, and SRAIW generate an illegal
instruction exception if *i**m**m*[5] ≠ 0.

LUI (load upper immediate) uses the same opcode as RV32I. LUI places
the 20-bit U-immediate into bits 31–12 of register *rd* and
places zero in the lowest 12 bits. The 32-bit result is
sign-extended to 64 bits.

AUIPC (add upper immediate to `pc`

) uses the same opcode as RV32I.
AUIPC (add upper immediate to `pc`

) is used to build ` pc`

-relative addresses and uses the U-type format. AUIPC appends 12
low-order zero bits to the 20-bit U-immediate, sign-extends the result
to 64 bits, then adds it to the `pc`

and places the result in
register *rd*.

#### Integer Register-Register Operations

ADDW and SUBW are RV64I-only instructions that are defined analogously to ADD and SUB but operate on 32-bit values and produce signed 32-bit results. Overflows are ignored, and the low 32-bits of the result is sign-extended to 64-bits and written to the destination register.

SLL, SRL, and SRA perform logical left, logical right, and arithmetic
right shifts on the value in register *rs1* by the shift amount
held in register *rs2*. In RV64I, only the low 6 bits of
*rs2* are considered for the shift amount.

SLLW, SRLW, and SRAW are RV64I-only instructions that are analogously
defined but operate on 32-bit values and produce signed 32-bit
results. The shift amount is given by *rs2[4:0]*.

## 6.3 Load and Store Instructions

RV64I extends the address space to 64 bits. The execution environment will define what portions of the address space are legal to access.

The LD instruction loads a 64-bit value from memory into register
*rd* for RV64I.

The LW instruction loads a 32-bit value from memory and sign-extends
this to 64 bits before storing it in register *rd* for RV64I. The
LWU instruction, on the other hand, zero-extends the 32-bit value from
memory for RV64I. LH and LHU are defined analogously for 16-bit
values, as are LB and LBU for 8-bit values. The SD, SW, SH, and SB
instructions store 64-bit, 32-bit, 16-bit, and 8-bit values from the
low bits of register *rs2* to memory respectively.

## 6.4 System Instructions

In RV64I, the CSR instructions can manipulate 64-bit CSRs. In particular, the
RDCYCLE, RDTIME, and RDINSTRET pseudo-instructions read the full 64 bits of
the `cycle`

, `time`

, and `instret`

counters. Hence, the RDCYCLEH,
RDTIMEH, and RDINSTRETH instructions are not necessary and are illegal in
RV64I.

The compiler and calling convention maintain an invariant that all 32-bit values are held in a sign-extended format in 64-bit registers. Even 32-bit unsigned integers extend bit 31 into bits 63 through 32. Consequently, conversion between unsigned and signed 32-bit integers is a no-op, as is conversion from a signed 32-bit integer to a signed 64-bit integer. Existing 64-bit wide SLTU and unsigned branch compares still operate correctly on unsigned 32-bit integers under this invariant. Similarly, existing 64-bit wide logical operations on 32-bit sign-extended integers preserve the sign-extension property. A few new instructions (ADD[I]W/SUBW/SxxW) are required for addition and shifts to ensure reasonable performance for 32-bit values.