Skip to content
Electronics 16 min read

What Is RISC-V? The Open ISA and Its Instruction Formats

Observation recorded
Title "RISC-V Explained" beside a glowing view of the OnionSoC chip layout
Quick answerRISC-V is an instruction set architecture, the rulebook a processor follows, whose specification anyone may read and implement with no licence fee. Open means the rulebook, not the chips: cores built on it can be open source or sold as IP. Every base instruction is 32 bits, in one of six formats: R, I, S, B, U and J.

The instruction add x5, x6, x7 is the 32-bit number 0x007302B3\mathtt{0x007302B3}. You can work that out with a pencil, from a PDF that anyone can download, and you can build a processor that executes it without asking anyone's permission or paying anyone a cent. Try the same thing with an Arm or x86 instruction and the first two steps are easy, but the third needs a licence that only Arm can sell you, or does not exist at all.

That is the whole idea behind RISC-V in one paragraph. The rest of this guide unpacks what "open" covers and what it does not, then takes the instruction formats apart bit by bit, because the encoding is where you see the design choices most clearly. It is the first of three pillar guides. The second decodes the extension letters in names like RV64GC, and the third compares RISC-V with Arm and x86 on licensing, performance and power.

Infographic: What does open ISA really mean? A RISC-V chip labelled RV32I, 40 instructions, sits on a circuit board under a coloured 32-bit instruction word split into funct7, rs2, rs1, rd and opcode fields. The licence fee to implement the RISC-V instruction set is zero; RV32I has 40 instructions in six 32-bit formats, R, I, S, B, U and J. A bar chart shows the reach of each immediate: 2 KiB for a load or store offset, 4 KiB for a branch, 1 MiB for jal and 2 GiB for auipc plus jalr. Tiles: 32 registers, add x5, x6, x7 encodes as 0x007302B3, and the specification is licensed CC BY 4.0. Myth: an open ISA does not make every RISC-V chip open source.
Tap the image to view it full size. View the accessible, editable SVG.

What is RISC-V, in plain terms?

A processor only understands numbers. The instruction set architecture, or ISA, is the agreement that says which numbers mean what: this 32-bit pattern adds two registers, that one loads a word from memory, this other one jumps. It also fixes how many registers exist, how memory is addressed and what happens on an interrupt. Software is compiled against the ISA. Hardware is built to obey it. As long as both sides keep to the agreement, any compiler's output runs on any compliant chip.

RISC-V is one such agreement. It started in 2010 as a research project at the University of California, Berkeley, where the team wanted a clean instruction set for teaching and research that they could share freely. The specification moved to the RISC-V Foundation in 2015, and that body is now RISC-V International, incorporated in Switzerland. The base integer set and the main extensions were ratified in 2019, which is roughly when commercial chips started to appear in numbers. RISC-V International's former chief executive, Calista Redmond, put the installed base at about ten billion cores in early 2023.

The design itself is a classic load and store RISC. Arithmetic happens only between registers, memory is touched only by loads and stores, and every base instruction is exactly 32 bits long. RV32I, the 32-bit base, has 32 integer registers, x0x0 to x31x31, and x0x0 is wired to zero. The unprivileged specification counts 40 unique instructions in RV32I. That is small enough to implement in a student project, and it is the reason so many hobby and research cores exist.

What does “open ISA” actually mean?

It means three concrete things. The specification is published openly: the ISA manual sits in a public repository under a Creative Commons Attribution 4.0 licence. Anyone may implement it without a licence fee, and RISC-V International's own FAQ says there is no fee to use the ISA. And changes to the standard go through an open process run by member companies and individuals, rather than being decided by one vendor.

Compare that with the two incumbents. To build an Arm core, you either license one of Arm's designs, or you buy an architecture licence that lets you design your own core to the Arm specification. Both come with fees and royalties. x86 is narrower still. Intel does not sell x86 licences in the normal sense. AMD builds x86 under a long-standing patent cross-licence with Intel, and VIA, through its stake in Zhaoxin, holds the only other licence of any consequence. If you are not one of those companies, you cannot ship an x86 processor.

What the open ISA does not give you is a free processor. The specification tells you what the hardware must do, not how. Turning it into logic is a large engineering job, and the result belongs to whoever did the work.

Three-layer diagram showing that an open ISA does not mean an open chip. Layer 1, the RISC-V specification, is free to read and implement, published under Creative Commons Attribution 4.0, with no fee to use the ISA. Layer 2, core designs in RTL, can be open source, such as OnionSoC, Hazard3 and Ibex under Apache-2.0, or licensed for a fee, such as cores from SiFive and Andes. Layer 3 is the chips you buy: ESP32-C3, RP2350, CH32V003 and StarFive JH7110.
Figure 1. Only the top layer is guaranteed open. Cores and chips are open or closed by their owners' choice.

Myth: an open ISA means open-source chips

This is the most common misunderstanding about RISC-V, and it leads people to two wrong conclusions: that RISC-V chips must be cheap because "nobody pays for it", and that a RISC-V chip in a product means its design is public. Neither follows.

Look at the second layer in Figure 1. Some cores are fully open. Hazard3, the RISC-V core inside the Raspberry Pi RP2350, is on GitHub under Apache-2.0, and so is lowRISC's Ibex. OnionSoC, the hand-written RV32IM system-on-chip built here at The Science 360, publishes its RTL, testbenches and board logs under the same licence. Other cores are commercial products. SiFive and Andes sell RISC-V cores the way Arm sells Cortex cores, under licence, and their RTL is as private as Arm's.

The chip you buy is a third layer again. An ESP32-C3 runs a RISC-V core, but Espressif's silicon design is not public, and nobody expects it to be. What the open ISA guarantees is that the compiler, the debugger and your knowledge of the instruction set carry over to any RISC-V part, from any vendor, open or closed.

How is a RISC-V instruction built?

Every base instruction is one 32-bit word, and the low seven bits are always the opcode, the field that says which family the instruction belongs to. The remaining 25 bits are laid out in one of six formats, shown in Figure 2.

RISC-V instruction format diagram showing the six base formats of RV32I as 32-bit bit-field maps. R-type: funct7 bits 31 to 25, rs2 bits 24 to 20, rs1 bits 19 to 15, funct3 bits 14 to 12, rd bits 11 to 7, opcode bits 6 to 0. I-type replaces funct7 and rs2 with a 12-bit immediate. S-type and B-type split the immediate around rs2, rs1 and funct3. U-type and J-type carry a 20-bit immediate above rd. The register fields rd, rs1 and rs2 sit in the same bits in every format that has them.
Figure 2. The six base formats. The colours line up vertically: that alignment is the most important design decision in the encoding.
  • R-type is register to register: add, sub, and, sll and friends. Two sources, one destination, plus funct3 and funct7 to pick the exact operation.
  • I-type swaps rs2 and funct7 for a 12-bit signed immediate. It covers addi, the loads and jalr.
  • S-type is for stores. A store has two source registers (the address base and the data) and no destination, so the immediate is split into two pieces to keep rs1 and rs2 where they are.
  • B-type is for conditional branches such as beq and blt. Same shape as S, with the immediate bits shuffled.
  • U-type holds a 20-bit upper immediate for lui and auipc.
  • J-type is jal, jump and link, with a 20-bit shuffled offset.

Why do the register fields never move?

Look down any column of Figure 2. rd is always bits 11 to 7. rs1 is always bits 19 to 15. rs2 is always bits 24 to 20. A pipelined processor wants to read the register file as early as possible, ideally in the same cycle it is still working out what the instruction is. If the register numbers always sit in the same place, the hardware can just send those bits to the register file every cycle, whether or not the instruction turns out to need them. No multiplexer, no waiting for the opcode decoder. In a core like OnionSoC that is a few gates saved; in a fast core, it is a shorter critical path in the decode stage.

The price is paid in the immediates. To keep rs1 and rs2 fixed, the store immediate has to be cut in two. The branch and jump immediates are cut in stranger ways, imm[12 ∣ 10:5]\text{imm}[12\,|\,10{:}5] and imm[4:1 ∣ 11]\text{imm}[4{:}1\,|\,11], because the designers also wanted the sign bit of every immediate to sit at bit 31. Sign extension can then start before decode finishes, and most immediate bits land in the same position across formats, which keeps the immediate multiplexers small. The assembler sorts out the shuffle. Humans almost never have to.

Worked example: encoding two instructions by hand

Take add x5, x6, x7, which sets x5=x6+x7x5 = x6 + x7. It is R-type, with opcode 0110011\mathtt{0110011}, funct3 0 and funct7 0. Each field is shifted to its position and the results are added:

word=(f7≪25)+(rs2≪20)+(rs1≪15)+(f3≪12)+(rd≪7)+opcode\begin{aligned} \text{word} &= (f_7 \ll 25) + (rs_2 \ll 20) \\ &\quad + (rs_1 \ll 15) + (f_3 \ll 12) \\ &\quad + (rd \ll 7) + \text{opcode} \end{aligned}
=(7≪20)+(6≪15)+(5≪7)+0x33=0x700000+0x30000+0x280+0x33=0x007302B3\begin{aligned} &= (7 \ll 20) + (6 \ll 15) \\ &\quad + (5 \ll 7) + \mathtt{0x33} \\ &= \mathtt{0x700000} + \mathtt{0x30000} \\ &\quad + \mathtt{0x280} + \mathtt{0x33} \\ &= \mathbf{\mathtt{0x007302B3}} \end{aligned}

Now addi x5, x6, -1. It is I-type, opcode 0010011\mathtt{0010011}. The immediate is −1-1, which in 12-bit two's complement is twelve ones, 0xFFF\mathtt{0xFFF}:

word=(0xFFF≪20)+(6≪15)+(5≪7)+0x13=0xFFF00000+0x30000+0x280+0x13=0xFFF30293\begin{aligned} \text{word} &= (\mathtt{0xFFF} \ll 20) + (6 \ll 15) \\ &\quad + (5 \ll 7) + \mathtt{0x13} \\ &= \mathtt{0xFFF00000} + \mathtt{0x30000} \\ &\quad + \mathtt{0x280} + \mathtt{0x13} \\ &= \mathbf{\mathtt{0xFFF30293}} \end{aligned}

Figure 3 shows the same two words as fields, bits and hex digits. If you have a RISC-V toolchain, riscv64-unknown-elf-objdump -d on any compiled program will print words like these next to each instruction, and you can check them against the table.

Worked RISC-V instruction encoding example. add x5, x6, x7 is R-type with funct7 0, rs2 x7, rs1 x6, funct3 0, rd x5 and opcode 0110011; its 32 bits 0000 0000 0111 0011 0000 0010 1011 0011 read as hex 0x007302B3. addi x5, x6, -1 is I-type with a 12-bit immediate of all ones, rs1 x6, funct3 0, rd x5 and opcode 0010011; its bits read as hex 0xFFF30293.
Figure 3. Fields, then bits, then hex. Ones are drawn in gold so the register numbers stand out.

How far can a RISC-V immediate reach?

Fixed 32-bit instructions mean no instruction can carry a full 32-bit constant or address. The ISA works around that with reach. A 12-bit signed immediate covers −2048-2048 to +2047+2047, so a load or store can reach 2 KiB either side of its base register. Branch and jump offsets are always even (instructions are at least 2 bytes long once the compressed extension exists), so the hardware does not store bit 0, and 12 stored bits give a 13-bit offset:

branch=±213−1=±4,096 Bjal=±221−1=±1,048,576 B=±1 MiB\begin{aligned} \text{branch} &= \pm 2^{13-1} \\ &= \pm 4{,}096\ \text{B} \\ \text{jal} &= \pm 2^{21-1} \\ &= \pm 1{,}048{,}576\ \text{B} \\ &= \pm 1\ \text{MiB} \end{aligned}

Beyond that, two instructions team up. lui puts a 20-bit value in the top of a register and addi adds a signed 12-bit low part, which together can build any 32-bit constant. There is one trap here that catches everyone who writes an assembler: the low part is signed. To load 0x12345FFF\mathtt{0x12345FFF}, the low 12 bits are 0xFFF\mathtt{0xFFF}, which addi reads as −1-1, so the upper part has to be rounded up by one:

0x12345FFF=(0x12346≪12)−1→lui x5, 0x12346→addi x5, x5, -1\begin{aligned} \mathtt{0x12345FFF} &= (\mathtt{0x12346} \ll 12) - 1 \\ &\to \texttt{lui x5, 0x12346} \\ &\to \texttt{addi x5, x5, -1} \end{aligned}

auipc does the same trick relative to the program counter, and paired with jalr it can call any address within 2 GiB, which on a 32-bit machine is all of memory.

Log-scale bar chart of how far RISC-V immediates reach either side of the base address. A load, store or addi offset with a 12-bit immediate reaches plus or minus 2 KiB. A conditional branch reaches plus or minus 4 KiB. A jal jump reaches plus or minus 1 MiB. An auipc and jalr pair reaches plus or minus 2 GiB, the whole 32-bit address space. lui plus addi builds any 32-bit constant.
Figure 4. Single instructions cover the common, nearby cases. Pairs cover everything else.

Why keep the base ISA so small?

Forty instructions is not much. There is no multiply in RV32I, no floating point, and no atomic memory operation. That is deliberate. The base is frozen, so software written for RV32I will run on every 32-bit RISC-V core ever built. Everything else comes in optional, named extensions: M for multiply and divide, A for atomics, F and D for floating point, C for 16-bit compressed instructions, V for vectors, and a growing list of Z extensions. A tiny microcontroller can implement only what it needs, and a server core can implement nearly all of it.

That is why RISC-V chips are described by strings such as RV32IMC (the ESP32-C3), RV32EC (the WCH CH32V003, which halves the register file to 16) or RV64GC (the SiFive U74 cores in the StarFive JH7110). OnionSoC is RV32IM: base plus multiply and divide, with no compressed instructions yet, which costs it roughly a quarter more code space than a core with C. The extension letters guide decodes every letter and what it costs in hardware.

The flexibility has a cost too: fragmentation. If every vendor picks a different set of extensions, software vendors cannot target "RISC-V" as a single platform. RISC-V International's answer is profiles, named bundles of mandatory extensions. RVA23, ratified in October 2024, is the profile for application processors that run full operating systems, and it makes the vector and hypervisor extensions mandatory.

What does open actually buy you?

For a chip company, it buys freedom from a single supplier and from per-chip royalties on the ISA. For a researcher or student, it buys the right to build, publish and tape out a processor without lawyers. For a programmer, it buys a single, stable target that many vendors compete to implement.

It does not buy a finished, verified, fast core, and that is where most of the real cost of a processor sits. Arm's business is not really selling the right to use an instruction set. It is selling cores that are known to work. A team choosing RISC-V either licenses a commercial core, adopts an open one and takes on its verification, or writes its own. How that trade looks in money, CoreMark per megahertz and power is the subject of the RISC-V vs Arm vs x86 comparison.

Source note The "ten billion cores" figure is RISC-V International's own count, reported from its Embedded World remarks. Reports differ on whether it was first stated in 2022 or early 2023, and it counts cores, not chips, so a single chip with several RISC-V cores counts more than once.

Frequently asked questions

Is RISC-V really free?

The instruction set is. The specification is published under a Creative Commons Attribution 4.0 licence and RISC-V International charges no fee to implement it. A finished core design or a chip is a different matter: some cores are open source, many are sold as licensed IP, and every chip is a product you pay for.

Is RISC-V open-source hardware?

Not automatically. RISC-V is an open instruction set, which is a specification. A particular processor that implements it can be open source, like Hazard3, Ibex or OnionSoC under Apache-2.0, or closed, like most commercial cores from SiFive or Andes.

How many instructions does RISC-V have?

The 32-bit base integer set, RV32I, has 40 unique instructions according to the unprivileged specification. Everything else, such as multiply, atomics, floating point, compressed and vector instructions, comes in optional extensions named by letters.

What are the RISC-V instruction formats?

There are six base formats, all 32 bits long: R-type for register to register operations, I-type for immediates, loads and jalr, S-type for stores, B-type for conditional branches, U-type for lui and auipc, and J-type for jal. The opcode is always bits 6 to 0, and rd, rs1 and rs2 sit in the same bit positions in every format that uses them.

Why are RISC-V branch immediates scrambled?

So that the register fields never move and the sign bit of every immediate is always bit 31. The hardware can then read registers and start sign extension before it has fully decoded the instruction, at the cost of a slightly odd bit order that only the assembler has to deal with.

Sources

  1. RISC-V Unprivileged ISA, RV32I base integer instruction set (40 unique instructions, base formats): docs.riscv.org
  2. RISC-V ISA manual repository and its Creative Commons Attribution 4.0 licence: github.com/riscv/riscv-isa-manual
  3. About RISC-V International (history, Swiss incorporation): riscv.org/about
  4. RISC-V history overview: Wikipedia, RISC-V
  5. RISC-V installed base of about ten billion cores: Wccftech report
  6. RVA23 profile ratification, October 2024: riscv.org
  7. Intel and AMD x86 cross-licence and the VIA licence: Tom's Hardware
  8. Hazard3 RISC-V core (Apache-2.0): github.com/Wren6991/Hazard3
  9. Ibex RISC-V core (Apache-2.0): github.com/lowRISC/ibex
  10. OnionSoC repository (Apache-2.0): github.com/oniondas/onion-soc
  11. ESP32-C3 product page: espressif.com
  12. WCH CH32V003 (QingKe RV32EC core) datasheet: wch-ic.com
  13. StarFive JH7110 datasheet, U74 cores (RV64GC): doc-en.rvspace.org

Header image: OnionSoC Sky130 chip layout, from github.com/oniondas/onion-soc, regraded for this article.

Related observations
Electronics 555 Timer Astable Circuit Explained with Waveforms Electronics 555 Timer Frequency Formula: Where 1.44 Comes From Electronics ADC Resolution vs Accuracy: ENOB, INL and the Reference
Transmit