S2.5.1 Fill the Control Table

MediumImplement45 minIcarus Verilog · serverReview the topic

Write the main decoder and the ALU decoder of a single-cycle core, for nine opcodes. Six rows are in the lesson. You work out three more from the datapath.

Hardware context: The main decoder of a single-cycle RV32I core as a control table of six opcodes that steers the datapath of ap_rv32_sc, and the ALU decoder of the real core. Writing and reviewing the decoder of a processor

The lab of the lesson has a control table of six rows, and its ALU operation is given. A real core needs more. This one also runs jalr, lui and auipc, and it finds the ALU operation itself.

Write the block that makes every control signal from the instruction word. It has no clock. The bench feeds it real instruction words from an assembler.

Signals in the Timeline

SignalWidthRole
trial10input of each check
Full specification
The datapath that your signals steer
The multiplexers for alu_a_select and jump_register are new. The lab of the lesson does not have them.
SignalValueWhat the datapath does
alu_a_select0, 1, 2The first ALU operand is rs1_data, the PC, or zero.
alu_b_select0, 1The second ALU operand is rs2_data, or the immediate.
result_select0, 1, 2rd takes the ALU result, the loaded value, or the PC plus 4.
jump_register0, 1The target is the PC plus the immediate, or rs1_data plus the immediate.
reg_write, mem_read, mem_write, branch, jump0, 1As in the lesson.
The three instructions that are not in the lesson
The other six opcodes are OP, OP_IMM, LOAD, STORE, BRANCH and JAL, as in the lesson. The starter names all nine.
OpcodeInstructionWhat it does
1100111jalrThe PC takes rs1_data plus the immediate. rd takes the PC plus 4.
0110111luird takes the immediate. The immediate generator has already put its 20 bits in the upper part.
0010111auipcrd takes the PC plus the immediate.
The values of alu_operation
These are the constants of ap_rv32. The lesson shows how they are chosen.
OperationValueOperationValue
add0000xor0100
sub1000srl0101
sll0001sra1101
slt0010or0110
sltu0011and0111

How to read a result: a public case shows the outputs that the datapath uses for that word. A private case feeds many words of one kind, and all_match is 1 when every word was right.

Examples

Example 1

An Add
Input
the word 006283b3: add x7, x5, x6
Output
reg_write = 1, mem_read = 0, mem_write = 0, branch = 0, jump = 0, alu_a_select = 0, alu_b_select = 0, alu_operation = 'b0000, result_select = 0

The row OP. The ALU adds two registers, and the result goes to rd. The output jump_register is not used and not shown.

Example 2

A Load
Input
the word 00052283: lw x5, 0(x10)
Output
reg_write = 1, mem_read = 1, mem_write = 0, branch = 0, jump = 0, alu_a_select = 0, alu_b_select = 1, alu_operation = 'b0000, result_select = 1

The row LOAD. The ALU adds rs1_data and the immediate, the memory is read, and rd takes the loaded value.

Example 3

A Branch
Input
the word fe029ce3: bne x5, x0, 0x10, at address 18 in hex
Output
reg_write = 0, mem_read = 0, mem_write = 0, branch = 1, jump = 0

The row BRANCH. Only the five enables matter here. The datapath does not use the ALU or the result select.

Constraints and Contract

  • The outputs depend only on the word of the same moment. The bench waits 1 ns after it sets a word.
  • The five enables are checked for every word: reg_write, mem_read, mem_write, branch and jump.
  • For a word whose opcode is not one of the nine, all five enables are 0.
  • An output that the datapath does not use for a word is not checked. For a branch, that is every output except the five enables.
  • The bench feeds no word that has one of the nine opcodes and is not an instruction.

Hints

Hint 1

Write the six rows of the lesson first. For each new instruction, ask where its operands come from and where its result goes.

Hint 2

lui has no first operand. Which value of alu_a_select makes the ALU pass the immediate on unchanged?

Hint 3

In which words is bit 30 a part of the immediate? There it must not change the operation.

What the grader checks: All ten operations on two registers. Six kinds of arithmetic with an immediate, each with immediates that have bit 10 set and clear, and the three shifts. Loads and stores of every size, and the six branches. Then jal, jalr, lui and auipc with bit 30 at both values, and 16 words with other opcodes.

11 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 problems on this path

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

An Add

Input
the word 006283b3: add x7, x5, x6
Expected output
reg_write = 1, mem_read = 0, mem_write = 0, branch = 0, jump = 0, alu_a_select = 0, alu_b_select = 0, alu_operation = 'b0000, result_select = 0

The row OP. The ALU adds two registers, and the result goes to rd. The output jump_register is not used and not shown.

Run samples executes all 3 public checks. Check all tests runs 11 checks on the server.

Icarus Verilog · server