Table of Contents

Instruction decoder and controller

An Instruction Decoder is a circuit that processors implement in order to interpret instructions coming from memory. In synchronous designs, this circuit feeds the appropriate operands into the datapath of the processor, according to the instruction. Additionally, it must communicate with a Controller, whose role is to direct the flow of the execution at every stage of the pipeline.

In this exercise we are interested in implementing the instruction decoder and controller for a small asynchronous processor. While these are often different circuits, in this case the simplicity of the processor allows us to incorporate all the functionality into a single module. From now on, in this exercise, we will refer to this combined module simply as Decoder.

The following figure shows a block diagram of the relevant processor modules.

tutorial:model:instruction_decoder:instruction_decoder-diagram.svg

The diagram contains 6 blocks. Your task is to implement the block labelled as DEC. All the input and output signals for DEC are colored in red and blue, respectively. Signals in black do not interact with DEC and are shown only to provide context.

The different modules operate in the following way:

The processor implements four instructions that must be decoded and controlled by DEC:

Exercise 1: Arithmetic Instructions

The first instruction you have to implement is the arithmetic instruction. But before that, it is always a good idea with WTG to first set the basic structure of the controller. This not only makes it easier to approach the problem, but also allows Workcraft to infer signal values when possible.

Let us first define the initialization and leave a waveform for every instruction. Remember to rename every waveform with the instruction it intends to solve.

Detailed instructions

The WTG should look similar to the following figure.

tutorial:model:instruction_decoder:instruction_decoder-wtg_structure.svg

You can now implement the arithmetic instruction controller.

Detailed instructions

The implementation for the first signal can be seen in the next figure.

tutorial:model:instruction_decoder:instruction_decoder-arithmetic.svg

Exercise 2: Branch Instructions

The next instruction we will implement is the branching instruction. This instruction allows the processor to alter the execution flow depending on logic conditions. Any operation performed in the ALU will set the signal z to high if the result was zero. It will set low otherwise. By using this signal we can determine whether to branch or not.

This instruction will need to use guards. Implement structure of the WTG for the branch instruction and the common waveform before the guard. Keep in mind that z has to be initialized in a similar way to op0 and op1. The value of this signal is only relevant to the branch operation, so it should remain unstable in every waveform and become stable when we need it.

Detailed instructions

The resulting WTG can be seen in the following figure.

tutorial:model:instruction_decoder:instruction_decoder-branch_structure.svg

The simplest scenario occurs when z is low. In this case, there is nothing to do and DEC immediately acknowledges the instruction after the decoding request. Implement the waveform for this scenario.

Detailed instructions

You can see the implementation of no_jmp in the following figure.

tutorial:model:instruction_decoder:instruction_decoder-branch_no_jmp.svg

Finally, implement the last waveform for the branch instruction.

Detailed instructions

The next figure shows a complete implementation of the branch instruction.

tutorial:model:instruction_decoder:instruction_decoder-branch.svg

Exercise 3: Simplify the model

By looking at our current design, you can observe that the instructions always finish in the same way. This is due to the protocol between DEC and INST. In this exercise, your task is to identify the common parts and create a new waveform called instruction_finished that produces the necessary transitions between completing instruction and waiting for the next.

Detailed instructions

The simplified WTG can be seen in the next figure.

tutorial:model:instruction_decoder:instruction_decoder-simplified.svg

Exercise 4: Load and Store Instructions

The remaining instructions have to access the DATA MEM module for read and write operations. This module uses a similar handshake protocol to the REG module. Complete the DEC module by adding the Load and Store operations to the WTG.

This exercise intentionally lacks detailed instructions to encourage working on it independnetly. You can compare your solution to the complete WTG of the decoder: instruction_decoder.wtg.work

Solutions

Download all the Workcraft models discussed in this tutorial here:

All instruction decoder WTGs