Building A Datapath: CS 3204 Operating Systems
Building A Datapath: CS 3204 Operating Systems
We have already seen how to perform these arithmetic-logical instructions, and provided
support within the ALU for the beq instruction.
The primary elements that are missing are the logical connections among the primary
hardware components, and the control circuitry needed to direct data among the
components and to make those components perform the necessary work.
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Here's an updated view of the basic architecture needed to implement our subset of the
MIPS environment:
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
The basic steps are to send the address in the program counter (PC) to the instruction
memory, obtain the specified instruction, and increment the value in the PC.
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
register file contains the 3 32-bit data lines ALU as seen data memory
32 registers seen earlier earlier
3 5-bit register
address lines
to control logic
selects
appropriate value
for updating PC
ALU
evaluates
beq test
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
…and
We need a control
branch
element to decode
control
the 6-bit opcode
For arithmetic/logic
instructions, we also
need a control
element to decode
the fn field
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
To design the control logic we'll need some details of the specific instructions to be
supported:
Instr fmt opfield funct
-----------------------------
add R 000000 100000
sub R 000000 100010
and R 000000 100100
or R 000000 100101
slt R 000000 101010
lw I 100011 XXXXXX
sw I 101011 XXXXXX
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
# for destination
register needs to be
sent to the write
register address line
in the register file
If it’s a branch
instruction, we need
to select alternate
address for PC
If it’s a load
instruction, we need
to trigger a memory
read operation from
data RAM.
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
If it’s a store
instruction, we need
to trigger a memory
write operation to
data RAM
If it’s
arithmetic/logical, we
need to indicate
whether the second
Trigger register write operand comes from
operation if that’s the a register or from the
destination of the instruction itself.=
result
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
The diagram below is a high-level view of the overall control logic for execution on our
simplified MIPS machine:
Each box represents a discrete sub-section of the control logic which we will examine
shortly.
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
31 26 25 21 20 16 15 11 10 6 5 0
000000 t1 t2 t3 00000 100000
op rs rt rd shamt funct
1. The instruction is fetched, the opcode in bits 31:26 is examined, revealing this is an
R-type instruction, and the PC is incremented accordingly
2. Data registers, specified by bits 25:21 and 20:16, are read from the register file and
the main control unit sets its control lines
3. The ALU control determines the appropriate instruction from the funct field bits
5:0, and performs that operation on the data from the register file
4. The result from the ALU is written into the register file at the destination specified by
bits 15:11
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
31 26 25 21 20 16 15 0
100011 t2 t1 0000000001100100
op rs rt offset
1. The instruction is fetched from memory, the opcode in bits 31:26 is examined,
revealing this is an load/store instruction, and the PC is incremented accordingly
2. Data register, specified by bits 25:21, is read from the register file
3. The ALU computes the sum of the retrieved register data and the sign-extended
immediate value in bits 15:0
4. The sum from the ALU is used as the address for the data memory
5. The data at the specified address is fetched from memory and written into the register
file at the destination specified in bits 20:16 of the instruction
Note that this instruction uses a sequence of five functional processor units.
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
31 26 25 21 20 16 15 0
000100 t2 t1 0000000001100100
op rs rt offset
1. The instruction is fetched, the opcode in bits 31:26 is examined, revealing this is a
beq instruction, and the PC is incremented accordingly
2. The data registers, specified by bits 25:21 and 20:16, are read from the register file
3. The ALU computes the difference of the two retrieved register data values; the value
of PC + 4 is added to the sign-extended value from bits 16:0, shifted left 2 bits
4. The Zero result from the ALU is used to decide which adder result to store in the PC
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Up to this point, we have considered a design plan that will use a single clock cycle for
fetching and executing each instruction.
That is unrealistic.
- The clock cycle would be determined by the longest possible path in the machine
(which seems to be the path for a load instruction).
- Many instructions take much shorter paths through the machine, and so could be
executed in a shorter cycle… not doing so would reduce efficiency.
A multi-cycle design allows instructions to take several clock cycles, and for the number
to vary from one instruction to another. In this case, this appears to be preferable.
Each step in the execution of an instruction will take one clock cycle.
But, what are the ramifications for the simplified design we have seen?
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
We assume that 1 clock cycle can accommodate any one of the following:
a memory access a register file access (2R|1W) a ALU operation
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
The added elements are small in area compared to the ones that have been
eliminated (2nd memory unit, adders), so this should be a cheaper design.
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Control for
address input to
unified memory
Revised control for
ALU operands
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Instruction fetch:
IR Í Memory[PC] MemRead = 1
IRWrite = 1 Can we do all this in a
IorD = 0 single clock cycle?
PC Í PC + 4 ALUSrcA = 0
ALUSrcB = 01
ALUOp = 00 Note that accessing the PC
PCSource = 00 or IR requires only part of a
PCWrite = 1 clock cycle, but that reading
or writing the register file
will take an additional cycle.
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
ALUOut Í PC + (sign_extend(IR[15:0])<<2)
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
ALUOut Í A + (sign_extend(IR[15:0]))
ALUSrcA = 1
Arithmetic-logical? ALUSrcB = 10
ALUOp = 00
ALUOut Í A op B
???
Branch?
if ( A == B ) PC Í ALUOut
???
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Jump?
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Memory access:
MDR Í Memory[ALUOut]
or
Memory[ALUOut] Í B
R-type:
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Store:
Mem[ALUOut] Í
B
Memory read Load:
completion Reg[IR[20:16]] Í
MDR
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
The basic process of fetching and decoding is the same no matter which MIPS machine
instruction is involved.
MemRead ON
IRWrite ON
IorD = 0 chooses
address source to
be PC ALU controls are set
to compute a
ALUSrcA, ALUSrcB,
logical branch
ALUOp, PCWrite
address
and PCSource are
set to compute the Control input unit Op
address PC+4 and determines exactly
store it to the PC which type of
instruction is about
to be executed,
and that
information is used
to manage the
next logical
transition
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
From the user perspective, the ALU may be considered as a black box with a relatively
simple interface:
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
The necessary ALU control bits for our reduced instruction set can be summarized:
Opcode ALUOp Operation funct ALU action ALU control
LW 00 load word XXXXXX add 0010
SW 00 store word XXXXXX add 0010
BEQ 01 branch equal XXXXXX subtract 0110
R-type 10 add 100000 add 0010
R-type 10 subtract 100010 subtract 0110
R-type 10 AND 100100 and 0000
R-type 10 OR 100101 or 0001
R-type 10 set on less than 101010 set on less than 0111
The function in the last column depends upon the ALUOp values and the funct values.
We can thus derive a truth table for the necessary control bits…
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
The truth table can be simplified due to the patterns in the relevant columns:
ALUOp funct
ALUOp1 ALUOp2 F5 F4 F3 F2 F1 F0 Control
0 0 X X X X X X 0010
X 1 X X X X X X 0110
1 X X X 0 0 0 0 0010
1 X X X 0 0 1 0 0110
1 X X X 0 1 0 0 0000
1 X X X 0 1 0 1 0001
1 X X X 1 0 1 0 0111
Given the truth table for the function, it is now child's play to implement the necessary
combinational logic.
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Our ALU control function truth table is somewhat simpler than would be needed for the
full MIPS datapath, largely due to the partial instruction set it supports.
In particular, note that the first bit of the ALU control is always zero; hence we do not
need to generate it.
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
A similar analysis, based upon the preceding discussion of the particular instructions,
leads to the following design for the general controller:
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
0 0 0 0 0 1 1
0 0 1 1 1 0 0
m n 0 1 0 1 1 0 0
0 1 1 1 0 0 0
1 0 0 0 0 0 0
1 0 1 0 0 0 1
1 1 0 0 1 1 0
1 1 1 0 1 1 1
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
Rather wasteful, since for lots of the entries, the outputs are the same
- i.e., opcode is often ignored
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD
PLA cells usually about the size of a ROM cell (slightly bigger)
Computer Science Dept Va Tech April 2006 Intro Computer Organization ©2006 McQuain WD