The RISC-V Family: RV32I, RV64I and the Extension Letters

RISC-V is not one instruction set. It is a small base and a shelf of blocks, and the name of a processor says which blocks it has. This page reads those names.

You Will Be Able To

  • Read a name such as RV32IMAC or RV64GC: the register width, the base and each added block.
  • Say what changes between RV32I and RV64I, and what stays the same.
  • Compare a load-store instruction set with one whose instructions do more, using one table.
Lesson
S2.17
Time
22 min
Runs on
Your browser
Check
6 questions

A team buys a small processor for a motor controller. Its data sheet gives the processor a name of seven letters and digits. The software team has a library built for a name with one more letter. Will the library run?

Before You Start

You need the map of RV32I from S2.1: 32 registers, 40 instructions, and loads and stores as the only way to memory.

You do not need to know any instruction outside the base. This page names the other groups and does not teach them.

Five questions this page answers
Question
1What does each part of the name RV32IMAC say?
2What changes when the 32 becomes 64?
3What must software do when the processor lacks the letter M?
4May a program built for RV32IMAC run on an RV32IMC processor?
5How does a load-store instruction set differ from one with complex instructions?

The Idea: A Small Base and Named Blocks

A watch and a server need different processors. The watch wants few gates. The server wants fast arithmetic on large numbers. One fixed instruction set would be too large for the first, or too small for the second.

The answer is a base and blocks. The base is the 40 instructions of S2.1. Each block is a group of extra instructions with a name. Such a block is called an ISA extension, or an extension for short.

A processor is described by one short name, its ISA name. It starts with two fixed letters. Then comes the width of a register, then the base, then one letter for each extension.

Four names used on this page
ISA nameWhat it says
RV32IMRegisters of 32 bits, the base I, and the extension M.
RV32IMCThe same, with the extension C as well.
RV32IMACThe same, with the extensions A and C.
RV64GCRegisters of 64 bits, the bundle G of this page, and the extension C.

The same base also comes with registers of 64 bits. That form is RV64I. It is a second base, not an extension: every register and every address grows to 64 bits.

This way of building is often set against an older one. RISC stands for reduced instruction set computer. CISC stands for complex instruction set computer.

A RISC design has few, simple instructions. A CISC design has many, and some do a great deal each. RISC-V belongs to the first kind, as its name says.

New Words

New words on this page
WordMeaning
ISA extensionA named group of instructions that is added to a base. Extension for short.
ISA nameThe short name of what a processor implements: RV, the register width, the base and the extensions.
RV64IThe base of RISC-V with registers and addresses of 64 bits.
M extensionMultiply and divide.
A extensionA read and a write of memory, done as one step that nothing can split.
Floating-point extensionsThe letters F and D: arithmetic on numbers with a fraction. F works on 32 bits, D on 64.
C extensionShort forms of common instructions, 16 bits long.
ZicsrThe instructions that read and write the control registers of the processor.
General bundleThe letter G: a short way to write I, M, A, F and D together. It includes Zicsr as well.
Processor trapA forced jump out of the program, made by the processor when it cannot run an instruction. Trap for short.
Illegal instructionA word that the processor does not know as an instruction. The processor refuses it with a processor trap.
RISC designReduced instruction set computer: few, simple instructions of one length, and a load-store design.
CISC designComplex instruction set computer: many instructions of several lengths, some of which work on memory directly.

One Picture: The Base and Its Blocks

One Base, and Blocks That Are Added to ItStep through the picture. The base is in the middle. Each step adds one block, and names its letter.
  • Processor
  • Control / FSM
  • Memory
  • Bus
One Base, and Blocks That Are Added to ItStep through the picture. The base is in the middle. Each step adds one block, and names its letter. component Base I 40 integerinstructions;registers of 32 or64 bits component Letter M multiply and divide component Letter A memory steps thatcannot be split, formore than oneprocessor component Letters F and D arithmetic onfractions, inregisters of theirown component Letter C short forms, 16 bitslong, of commoninstructions component Zicsr instructions for thecontrol registers ofthe processor component Letter G short for I, M, A, Fand D together addsaddsaddsaddsaddsnames a bundle
  1. component Base I40 integer instructions; registers of 32 or 64 bits
  2. component Letter Mmultiply and divide
    • adds → Base I
  3. component Letter Amemory steps that cannot be split, for more than one processor
    • adds → Base I
  4. component Letters F and Darithmetic on fractions, in registers of their own
    • adds → Base I
  5. component Letter Cshort forms, 16 bits long, of common instructions
    • adds → Base I
  6. component Zicsrinstructions for the control registers of the processor
    • adds → Base I
  7. component Letter Gshort for I, M, A, F and D together
    • names a bundle → Base I
  1. The base

    Every RISC-V processor has the base I. The number in front, 32 or 64, is the width of a register.

  2. M: multiply and divide

    The base can only add, subtract, shift and compare. M adds instructions that multiply and divide.

  3. A: steps that cannot be split

    A adds instructions that read and write memory as one step that cannot be split. Module S9 needs them.

  4. F and D: fractions

    F and D add 32 more registers, and arithmetic on numbers with a fraction. F is the short form, D the long.

  5. C: short instructions

    C adds forms of 16 bits for the most common instructions. Programs get smaller.

  6. Zicsr, and the bundle G

    Longer names start with Z. Zicsr adds the instructions for control registers. G is a short way to write a common bundle.

Read the diagram as text
  • Base I: 40 integer instructions; registers of 32 or 64 bits
  • Letter M: multiply and divide
  • Letter A: memory steps that cannot be split, for more than one processor
  • Letters F and D: arithmetic on fractions, in registers of their own
  • Letter C: short forms, 16 bits long, of common instructions
  • Zicsr: instructions for the control registers of the processor
  • Letter G: short for I, M, A, F and D together
  • Letter M → Base I: adds
  • Letter A → Base I: adds
  • Letters F and D → Base I: adds
  • Letter C → Base I: adds
  • Zicsr → Base I: adds
  • Letter G → Base I: names a bundle

A block only adds instructions. It never changes what a base instruction does.

The Smallest Example, Worked by Hand

Read two names. Take them apart from left to right.

Two names, part by part
PartIn RV32IMACIn RV64GC
RVRISC-VRISC-V
The number32: registers of 32 bits64: registers of 64 bits
The baseI: the 40 integer instructionsinside G
The lettersM, A and CG is I, M, A, F and D. Then C.
Multiply instructions?yes: Myes: M is inside G
Arithmetic on fractions?no: neither F nor Dyes: F and D are inside G

The letters come in a fixed order: I, M, A, F, D, C.

Change the width. The second part of the example is one addition, done three times. The first row is the sum of S2.1. The other two push a sum past 32 bits.

Printed by test code on Icarus. The same two bit patterns are added in registers of 32 bits and of 64 bits.
00000007 + 00000005 | 32 bits: 0000000c | 64 bits: 000000000000000c | addw: 000000000000000c
ffffffff + 00000001 | 32 bits: 00000000 | 64 bits: 0000000100000000 | addw: 0000000000000000
7fffffff + 00000001 | 32 bits: 80000000 | 64 bits: 0000000080000000 | addw: ffffffff80000000

Row 2: in 32 bits, the largest value plus 1 wraps round to 0. In 64 bits there is room, and bit 32 is set.

Row 3, last column: RV64I keeps a second add, called addw. It adds the low 32 bits only, and copies bit 31 into the upper half. So old code that counts in 32 bits gets the answers it expects.

The Rules

  1. Rule 1: An ISA name is RV, a width, a base and the extensions.

    RV32IMC: 32 bits, the base I, then M and C.

  2. Rule 2: An extension only adds instructions.

    A base instruction does the same thing on every processor of that width.

  3. Rule 3: A program may use only what the processor has.

    A word from a missing extension is an illegal instruction, and the processor traps.

  4. Rule 4: A program built for fewer extensions still runs where there are more.

    The other direction fails at the first missing instruction.

  5. Rule 5: RV64I widens every register and address to 64 bits.

    An instruction is still 32 bits long. Code built for one width does not run on the other.

  6. Rule 6: What an extension does in one instruction, the base must do in several.

    Without M, a multiply is a loop of adds and shifts.

Sources for These Rules

Every RISC-V fact on this page is stated as commonly described. That covers the two widths, the letters and what each adds, the bundle G, and the word of the multiply instruction. The RISC-V specifications are not in the reference library. So none of these facts is checked against them. The statements about other instruction sets are common descriptions too, and are not checked.

The plan of this track points to two textbooks for this material. They are Patterson and Hennessy, chapter 2, and Harris and Harris, section 6.2. Those places are not checked either.

Now Run It

The lab at the end of this page multiplies 6 by 7 on RV32I, which has no multiply. It adds 6 into x12 seven times. Register x11 counts the turns.

Printed by the lab on Icarus. The instruction-level model of this track printed the same rows. The middle of the run is left out here.
00000000 | addi x12, x0, 0 | x12 = 00000000
00000004 | beq x11, x0, 0x14 | not taken
00000008 | add x12, x12, x10 | x12 = 00000006
0000000c | addi x11, x11, -1 | x11 = 00000006
00000010 | bne x11, x0, 0x8 | taken: next is 00000008
(15 more rows: five more turns of the loop)
00000008 | add x12, x12, x10 | x12 = 0000002a
0000000c | addi x11, x11, -1 | x11 = 00000000
00000010 | bne x11, x0, 0x8 | not taken
00000014 | ebreak | stop
x12=42 instructions=23

Rule 6 at work: read the last row. The answer is 42, and it took 23 instructions. That is 2 to set up, and 3 for each of the 7 turns.

With the M extension, the whole loop is one instruction: mul x12, x10, x11. Neither model of this track has M yet, so that instruction is not run here.

The count grows with the number itself. A multiply by 1000 this way takes 3002 instructions. Real software without M uses shifts, and needs about 32 turns at most.

Why It Is Built This Way

RISC against CISC
QuestionRISC, as in RISC-VCISC, as commonly described
How long is an instruction?One length: 32 bits. With C, also 16.Many lengths, from one byte up.
What may arithmetic work on?Registers and immediates only.Registers, and memory directly.
How is memory reached?By loads and stores only.By many instructions.
How many registers?Many: 32.Often fewer: 8 or 16.
The sum of S2.1: two words of memory added, and storedFour instructions: two loads, an add, a store.About three: the add reads one word from memory itself.
What is hard to build?Little. Each instruction does one small thing.Finding where each instruction ends, and running the large ones.
What does a program cost?More instructions for the same work.Fewer instructions, and each may take longer.

The CISC column is a common description and is not checked. No CISC code is run on this page.

Neither column wins every row. The RISC column trades longer programs for hardware that is simple to build and to check. That trade is why this track can build a whole RISC-V processor in a few lessons.

Design choiceThe alternativeWhat the choice buys, and costs
A small base and named extensionsOne large instruction setA tiny processor is still a complete RISC-V. Software must know which letters are there.
Extensions only addExtensions may change old instructionsOld programs keep working. Space for new instructions must be kept free.
A second base for 64 bitsA 64-bit extension on top of RV32IThe same assembly reads the same on both. Programs must be built again for the other width.

The Trap: A Multiply on a Chip with No M

A team tests its software on a board with an RV32IM processor. Every test passes. The product uses a cheaper chip with RV32I. Nobody builds the software again.

The first multiply in the program is the word 02b50633. On the test board, that word multiplies x10 by x11. Here is the same word on a processor with the base only:

Printed by the instruction-level model of this track, which has no M extension. Register x10 held 6 and x11 held 7.
00000000 | word 02b50633 | trap, cause 2: illegal instruction | x12 = 00000000

Read the row. The processor did not multiply, and it did not skip the word. It took a trap for an illegal instruction, and x12 still holds 0.

This is rule 3. The software was right, and the chip was right. The two were built for different names. The check is one line in the build: give the compiler the ISA name of the real chip.

At Scale

A small microcontrollerRV32I, or RV32IMC
A processor that runs a large operating systemRV64GC and more

This section looks ahead. Every RISC-V chip prints its ISA name somewhere, and each letter costs area.

  1. The processor of ap_soc

    The processor of this track is planned as RV32I with Zicsr. A later module adds a small part of A for a second processor.

  2. Fewer registers

    There is a base with only 16 registers, written E in place of I. It is meant for the smallest chips.

  3. Asking the chip

    A control register of the processor holds one bit for each letter. Software can read it to learn the name. A later lesson of this module reads it.

  4. Other families

    Arm processors are RISC designs as well. The processors of most desktop computers are CISC designs. This is a common description, and it is not checked here.

Try It

Run the lab. Count the rows of one turn of the loop.

Change x11 from 7 to 0 in the line that prepares it. Predict the number of instructions first.

Swap the two numbers, so that x10 holds 7 and x11 holds 6. The answer is the same. Is the count?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 00000000 | addi x12, x0, 0 | x12 = 00000000 00000004 | beq x11, x0, 0x14 | not taken 00000008 | add x12, x12, x10 | x12 = 00000006 0000000c | addi x11, x11, -1 | x11 = 00000006 00000010 | bne x11, x0, 0x8 | taken: next is 00000008 00000008 | add x12, x12, x10 | x12 = 0000000c 0000000c | addi x11, x11, -1 | x11 = 00000005 00000010 | bne x11, x0, 0x8 | taken: next is 00000008 00000008 | add x12, x12, x10 | x12 = 00000012 0000000c | addi x11, x11, -1 | x11 = 00000004 00000010 | bne x11, x0, 0x8 | taken: next is 00000008 00000008 | add x12, x12, x10 | x12 = 00000018 0000000c | addi x11, x11, -1 | x11 = 00000003 00000010 | bne x11, x0, 0x8 | taken: next is 00000008 00000008 | add x12, x12, x10 | x12 = 0000001e 0000000c | addi x11, x11, -1 | x11 = 00000002 00000010 | bne x11, x0, 0x8 | taken: next is 00000008 00000008 | add x12, x12, x10 | x12 = 00000024 0000000c | addi x11, x11, -1 | x11 = 00000001 00000010 | bne x11, x0, 0x8 | taken: next is 00000008 00000008 | add x12, x12, x10 | x12 = 0000002a 0000000c | addi x11, x11, -1 | x11 = 00000000 00000010 | bne x11, x0, 0x8 | not taken 00000014 | ebreak | stop x12=42 instructions=23

Check Yourself

Predict the outputThe same loop multiplies 9 by 3: x10 holds 9 and x11 holds 3. What does the last row say?
// Multiply 9 by 3 the same way.
// The program is the task at the top. Each row is one instruction: i(kind, a, b, c).
// The comment beside a row is the same instruction in assembly.
// Before the program starts, x10 holds 9 and x11 holds 3.
module tb;
  task automatic the_program();
    i(ADDI,   12, 0,  0);      // 00: addi x12, x0, 0
    i(BEQ,    11, 0,  'h14);   // 04: beq x11, x0, 0x14
    i(ADD,    12, 12, 10);     // 08: add x12, x12, x10      the loop starts here
    i(ADDI,   11, 11, -1);     // 0c: addi x11, x11, -1
    i(BNE,    11, 0,  'h8);    // 10: bne x11, x0, 0x8
    i(EBREAK, 0,  0,  0);      // 14: ebreak
  endtask

  // ---- From here down: a small model of an RV32I processor, as test code. You need not change it. ----
  localparam int LUI = 0, AUIPC = 1, JAL = 2, JALR = 3, BEQ = 4, BNE = 5, BLT = 6, BGE = 7, BLTU = 8, BGEU = 9, LW = 10, SW = 11,
                 ADDI = 12, SLTI = 13, SLTIU = 14, XORI = 15, ORI = 16, ANDI = 17, SLLI = 18, SRLI = 19, SRAI = 20,
                 ADD = 21, SUB = 22, SLL = 23, SLT = 24, SLTU = 25, XOR = 26, SRL = 27, SRA = 28, OR = 29, AND = 30, EBREAK = 31;
  int kind [0:63], fa [0:63], fb [0:63], fc [0:63];   // the program: one row for each instruction
  int rows = 0;
  task automatic i(input int k, input int a, input int b, input int c);   // add one row to the program
    if (rows < 64) begin kind[rows] = k; fa[rows] = a; fb[rows] = b; fc[rows] = c; rows++; end
  endtask
  logic [31:0] x [0:31];             // the 32 registers
  logic [31:0] pc;                   // the address of the next instruction
  logic [31:0] mem [0:16383];        // 64 KiB of data memory, from address 8000_0000 up
  int   steps;
  bit   stopped, faulted;
  function automatic string rn(input int n);
    return $sformatf("x%0d", n);
  endfunction
  function automatic string nm(input int k);                // the name of a kind of instruction
    case (k)
      0: return "lui"; 1: return "auipc"; 2: return "jal"; 3: return "jalr"; 4: return "beq"; 5: return "bne"; 
      6: return "blt"; 7: return "bge"; 8: return "bltu"; 9: return "bgeu"; 10: return "lw"; 11: return "sw"; 
      12: return "addi"; 13: return "slti"; 14: return "sltiu"; 15: return "xori"; 16: return "ori"; 17: return "andi"; 
      18: return "slli"; 19: return "srli"; 20: return "srai"; 21: return "add"; 22: return "sub"; 23: return "sll"; 
      24: return "slt"; 25: return "sltu"; 26: return "xor"; 27: return "srl"; 28: return "sra"; 29: return "or"; 
      30: return "and"; 31: return "ebreak"; 
      default: return "?";
    endcase
  endfunction
  // One instruction: read the row at the PC, do what it says, and print one line.
  task automatic step();
    int k, a, b;
    logic [31:0] c, r1, r2, res, next, ad;
    string text, effect;
    bit writes, go, take;
    go = 1;  k = EBREAK;  a = 0;  b = 0;  c = 0;
    if (pc[1:0] != 0 || pc >= 256) begin
      $display("%08h | no instruction at this address", pc);  faulted = 1;  stopped = 1;  go = 0;
    end
    else begin k = kind[pc >> 2];  a = fa[pc >> 2];  b = fb[pc >> 2];  c = fc[pc >> 2]; end
    r1 = x[b[4:0]];  r2 = x[c[4:0]];
    next = pc + 4;  writes = 1;  res = 0;  effect = "";
    if (go) case (k)
      LUI:   begin res = c << 12;       text = $sformatf("lui %s, 0x%0h", rn(a), c); end
      AUIPC: begin res = pc + (c << 12); text = $sformatf("auipc %s, 0x%0h", rn(a), c); end
      JAL:   begin res = pc + 4;  next = c;  text = $sformatf("jal %s, 0x%0h", rn(a), c); end
      JALR:  begin res = pc + 4;  next = (r1 + c) & ~32'd1;  text = $sformatf("jalr %s, %0d(%s)", rn(a), $signed(c), rn(b)); end
      BEQ, BNE, BLT, BGE, BLTU, BGEU: begin
        r1 = x[a[4:0]];  r2 = x[b[4:0]];  writes = 0;
        case (k)
          BEQ:  take = (r1 == r2);
          BNE:  take = (r1 != r2);
          BLT:  take = ($signed(r1) < $signed(r2));
          BGE:  take = ($signed(r1) >= $signed(r2));
          BLTU: take = (r1 < r2);
          default: take = (r1 >= r2);
        endcase
        if (take) next = c;
        text = $sformatf("%s %s, %s, 0x%0h", nm(k), rn(a), rn(b), c);
        if (take) effect = $sformatf("taken: next is %08h", next);
        else effect = "not taken";
      end
      LW, SW: begin
        ad = r1 + c;
        text = $sformatf("%s %s, %0d(%s)", nm(k), rn(a), $signed(c), rn(b));
        if (ad[1:0] != 0 || ad < 32'h8000_0000 || ad > 32'h8000_fffc) begin
          $display("%08h | %s | no data memory at %08h", pc, text, ad);  faulted = 1;  stopped = 1;  go = 0;
        end
        else if (k == LW) begin res = mem[ad[15:2]];  effect = $sformatf(" from mem[%08h]", ad); end
        else begin mem[ad[15:2]] = x[a[4:0]];  writes = 0;  effect = $sformatf("mem[%08h] = %08h", ad, x[a[4:0]]); end
      end
      ADDI:  res = r1 + c;
      SLTI:  res = ($signed(r1) < $signed(c)) ? 1 : 0;
      SLTIU: res = (r1 < c) ? 1 : 0;
      XORI:  res = r1 ^ c;
      ORI:   res = r1 | c;
      ANDI:  res = r1 & c;
      SLLI:  res = r1 << c[4:0];
      SRLI:  res = r1 >> c[4:0];
      SRAI:  res = $signed(r1) >>> c[4:0];
      ADD:   res = r1 + r2;
      SUB:   res = r1 - r2;
      SLL:   res = r1 << r2[4:0];
      SLT:   res = ($signed(r1) < $signed(r2)) ? 1 : 0;
      SLTU:  res = (r1 < r2) ? 1 : 0;
      XOR:   res = r1 ^ r2;
      SRL:   res = r1 >> r2[4:0];
      SRA:   res = $signed(r1) >>> r2[4:0];
      OR:    res = r1 | r2;
      AND:   res = r1 & r2;
      default: begin
        $display("%08h | ebreak | stop", pc);  stopped = 1;  go = 0;
      end
    endcase
    if (k >= ADDI && k <= SRAI) text = $sformatf("%s %s, %s, %0d", nm(k), rn(a), rn(b), $signed(c));
    if (k >= ADD && k <= AND)   text = $sformatf("%s %s, %s, %s", nm(k), rn(a), rn(b), rn(c[4:0]));
    if (go && writes) begin
      if (a[4:0] != 0) x[a[4:0]] = res;                      // register 0 is never written
      effect = {$sformatf("%s = %08h", rn(a), x[a[4:0]]), effect};
      if (k == JAL || k == JALR) begin                       // a jump with x0 as its destination keeps no return address
        if (a[4:0] == 0) effect = $sformatf("next is %08h", next);
        else effect = {effect, $sformatf(", next is %08h", next)};
      end
    end
    if (go) begin
      $display("%08h | %s | %s", pc, text, effect);
      pc = next;  steps++;
    end
  endtask
  task automatic run(input logic [31:0] start);
    pc = start;  steps = 0;  stopped = 0;  faulted = 0;
    while (!stopped && steps < 2000) step();
  endtask
  initial begin
    for (int n = 0; n < 32; n++) x[n] = 0;
    for (int n = 0; n < 16384; n++) mem[n] = 0;
    the_program();
    x[10] = 32'h0000_0009;
    x[11] = 32'h0000_0003;
    run(0);
    if (!stopped) $display("still running after %0d instructions", steps);
    $display("x12=%0d instructions=%0d", x[12], steps);
  end
endmodule
ConceptWhat does the name RV32IMAC say about a processor?
ConceptWhat changes from RV32I to RV64I?
ConceptA processor has no M extension. How does its software multiply?
ConceptA library is built for RV32IMAC. The chip is RV32IMC. What happens?
ConceptWhich rule makes RV32I a load-store instruction set?

Common Mistakes

Wrong Read RV32IMC as "32 instructions".

The number is the width of a register in bits.

Fix Read it as: registers of 32 bits, base I, extensions M and C.

Wrong Run software built for RV32IMAC on an RV32IMC chip.

The first instruction from A is an illegal instruction there.

Fix Build the software for the name of the chip, or for fewer letters.

Wrong Expect RV32I code to run on an RV64I processor.

RV64I is a second base. Registers and addresses have another width.

Fix Build the program again for the other width.

Remember

  • An ISA name is RV, the register width, the base and one letter for each extension.
  • An extension only adds instructions. A word from a missing extension is an illegal instruction.
  • RV64I widens registers and addresses to 64 bits. Instructions stay 32 bits long.
  • RISC: one instruction length, many registers, loads and stores only. CISC: the opposite on each count.

Practice

Report a problem with this page