Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

1Learning Outcomes

Most processor implementations include a special combinational logic block called an arithmetic logic unit (ALU). In RISC-V, the ALU is used to compute the result in the R-type instructions, such as, add, sub, and, or addi, ori, etc.

2ALU Block

We are going to consider the design of a simpler version of the ALU than the one in our RISC-V processor. Ours will include only four basic functions:

This ALU is implemented as a combinational logic block in Figure 1:

"TODO"

Figure 1:Basic ALU: ADD, SUB, AND, and OR

In our basic ALU, S is used to select R as one of the four operations:

R={A + Bwhen S=00A - Bwhen S=01A & Bwhen S=10A | Bwhen S=11\texttt{R} = \begin{cases} \texttt{A + B} & \text{when } \texttt{S} = 00 \\ \texttt{A - B} & \text{when } \texttt{S} = 01 \\ \texttt{A \& B} & \text{when } \texttt{S} = 10 \\ \texttt{A | B} & \text{when } \texttt{S} = 11 \\ \end{cases}

3ALU Circuit

The internal design of our simple ALU is shown in Figure 2:

"TODO"

Figure 2:Basic ALU circuit with three blocks (AND, OR, add/subtract) and a 4-to-1 mux.

For our simple ALU we will need an add/subtract block, an AND block, and an OR block. Each of these blocks will take two 32-bit inputs and produce a 32-bit output. Read more about implementing these blocks below.

3.1Implementing the Internal Blocks

The logical operations as defined by the RISC-V ISA are bitwise operations.

case of the AND, the resultant bit ri is generated as ai AND bi. The circuit to perform this operation is simply a collection of 32 AND gates. Each AND gate is responsible for one of the 32 resultant bits. Similarly, the OR block is a collection of 32 OR gates.