ALU Stage
ALU
is the Arithmetic-Logic Unit.
This is where the "real work" for most instructions are done:
- Arithmetic:
add
,sub
,and
,or
, etc. - Memory: Address calculation for
lw
andsw
. - Branch: Register comparison for
beq
andbne
.
Requirements
The ALU stage was previously called the execution stage. The execution stage was split into into the ALU stage and memory stage.
-
Read input from previous stage (i.e., decode stage).
-
Calculate result.
-
The result is given as output to the next stage (i.e., memory stage).
Block Diagram
Basic
This part of the datapath is rather simple because the main complexity lies in the control. In particular, how do we decide which operation to perform.## Elements
Branch
When a branch is taken, we will need to compute the target address as $PC' = ($PC + 4) + (immediate × 4)
.
The control signal PCSrc
determines whether the branch is taken or not.
We will explain each step in this.
Complete ALU Stage
Non-Branch
Branch
Elements
ALU
The ALU
is the "brain" of the processor.
The block diagram is shown on the right.
Again, we can view it conceptually as a function instead.
Similar to multiplexer, we have the control line.
-
Inputs
- 2 inputs A and B shown by an arrow going in to the
ALU
. - Each input is a 32-bit numbers.
- 2 inputs A and B shown by an arrow going in to the
-
Outputs
- 2 outputs A op B and (A op B) == 0? shown by an arrow going out of the
ALU
. - A op B is a 32-bit numbers while (A op B) == 0? is a 1-bit value.
- 2 outputs A op B and (A op B) == 0? shown by an arrow going out of the
-
Control
- One control
ALUcontrol
with a width of 4 bits shown by the control line at the top. - This controls which operation is performed by the
ALU
.
- One control
The control can be summarised as follows.
The value of ALUcontrol
can be thought of as simply a "convention".
Certain values are simpler to implement, but at the end of the day, other arrangements can also be implemented.
ALUcontrol | Function |
---|---|
0000 | and |
0001 | or |
0010 | add |
0110 | sub |
0111 | slt |
1100 | nor |
Quick Quiz
Notice how there is no equality check available on ALUcontrol
.
The question is, how do we check if two values are equal?
We do have isZero?
output, but do we need to do additional operations to get this result?
No, we can simply use the sub
operation through the following equality:
Equality Check | |
---|---|
1 2 3 |
|
So, to check $rs == $rt
, we need to perform the ALU operation $rs - $rt == 0
.
This will be set using opcode
and funct
field.
We will discuss more of this on processor control.
Functional Conceptual View of ALU | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|