Goals of This Chapter: COEN-4710 Computer Hardware Processor Part 1: Datapath and Control (Ch.4)
Goals of This Chapter: COEN-4710 Computer Hardware Processor Part 1: Datapath and Control (Ch.4)
Lecture 3
Processor Part 1: Datapath and Control (Ch.4)
Cristinel Ababei
Marquette University
Department of Electrical and Computer Engineering
Page 1
Page 2
Page 1
What are datapath and control?
❖ Datapath
◆ The path the “data” follow and undergo computations.
◆ Realized by the hardware components connected in a way to
perform operations on data such that machine instructions are
implemented.
❖ Control
◆ Control is the sequential logic that reconfigures the Datapath to
allow the “data” to flow properly through the hardware
components.
◆ Responsible with the generation of all control signals to
“orchestrate” the correct flow of data through Datapath!
◆ Can be implemented as finite state-machine(s).
◆ Can also be implemented as a computer inside of a computer
(microcode).
Page 3
Design Process
1. Select a subset of the instruction set to
implement. Simple subset, shows most
aspects
◆Memory reference: ld, sd
◆Arithmetic/logical: add, sub, and, or
◆Control transfer: beq
2. Order the steps within instruction cycle
(performed during instruction execution)
3. Select the hardware components.
4. Connect the hardware components.
5. Design the control to make the components
work together properly.
Page 4
Page 2
Order the steps: F I D E
❖ FIDE – the sequence of activities that
happens during instruction execution
1. Fetch (the instruction)
2. “Increment” (the Program Counter)
3. Decode (the Instruction Register)
4. Execute (using datapath hardware)
Page 5
Instruction
Instruction Memory Instruction
address Adder
PC
Page 6
Page 3
Fetch and Increment Connections
Adder
4
Increment by
4 for next
instruction
Instruction
PC Instruction
address
Memory Instruction
64-bit
register
Page 7
Page 8
Page 4
Instruction Execution
❖PC → instruction memory, fetch instruction
❖Register numbers → register file, read
registers
❖Depending on instruction class
◆Use ALU to calculate
➢ Arithmetic result
➢ Memory address for load/store
➢ Branch comparison
◆Access data memory for load/store
◆PC target address or PC + 4
Page 9
add x9,x20,x21
0 21 20 0 9 51
Page 10
10
Page 5
R-Format Instructions - Hardware
❖Read two register operands
❖Perform arithmetic/logical operation
❖Write register result
Page 11
11
0010
Registers
Page 12
12
Page 6
Complete “Add” Datapath
PC Adder
read reg1
read data1
read reg2
read data2
Instruction write reg
zero
ALU
Memory write data result
Registers
Page 13
13
PC Adder
read reg1
read data1
read reg2
read data2
Instruction write reg
zero
ALU
Memory write data result
Registers
Page 14
14
Page 7
Complete Add Datapath
PC Adder
read reg1
read data1
read reg2
read data2
Instruction write reg
zero
ALU
Memory write data result
Registers
Page 15
15
PC Adder
rs1 [19-15]
read reg1
read data1
rs2 [24-20]
read reg2
read data2
Instruction rd [11-7]
write reg
zero
ALU
Memory write data result
Registers
Page 16
16
Page 8
Complete Add Datapath
PC Adder
0010
rs1 [19-15]
read reg1
read data1
rs2 [24-20]
read reg2
read data2
Instruction rd [11-7]
write reg
zero
ALU
Memory write data result
Registers
Page 17
17
PC Adder
0010
rs1 [19-15]
read reg1
read data1
rs2 [24-20]
read reg2
read data2
Instruction rd [11-7] write reg
zero
ALU
Memory write data result
Registers
Page 18
18
Page 9
Control of R-format Instructions
❖ Simplicity favors regularity!
◆ and, or, add, subtract, set-on-less-than all use the same
datapath
❖ Need to decode the instructions to control the ALU.
◆ Input: Function codes for each (recall from Chapter 2)
◆ Output: ALU control lines (will look at later)
Page 19
19
rs1 [19-15]
zero
rs2 [24-20] ALU
result
rd [11-7]
Page 20
20
Page 10
R-format Datapath and Control
PC Adder
ALU
Control
read reg1
read data1
Instruction read reg2
read data2 zero
Memory write reg ALU
write data result
Registers
Page 21
21
PC Adder
4
ALU
Control
read reg1
read data1
Instruction read reg2
read data2 zero
Memory write reg ALU
write data result
Registers
Page 22
22
Page 11
R-format Datapath and Control
PC Adder
4
ALU
Control
rs1 [19-15]
read reg1
read data1
Instruction rs2 [24-20]
read reg2
read data2 zero
Memory rd [11-7]
write reg ALU
write data result
Registers
Page 23
23
PC Adder
4
ALU
Control
rs1 [19-15]
read reg1
read data1
Instruction rs2 [24-20]
read reg2
read data2 zero
Memory rd [11-7]
write reg ALU
write data result
Registers
Page 24
24
Page 12
R-format Datapath and Control
PC Adder
4
ALU
Control
rs1 [19-15]
read reg1
read data1
Instruction rs2 [24-20]
read reg2
read data2 zero
Memory rd [11-7]
write reg ALU
write data result
Registers
Page 25
25
PC Adder
4
ALU
Control
rs1 [19-15]
read reg1
read data1
Instruction rs2 [24-20]
read reg2
read data2 zero
Memory rd [11-7]
write reg ALU
write data result
Registers
Page 26
26
Page 13
R-format Datapath and Control
PC Adder
4
ALU
Control
rs1 [19-15]
read reg1
read data1
Instruction rs2 [24-20]
read reg2
read data2 zero
Memory rd [11-7]
write reg ALU
write data result
Registers
Page 27
27
Page 28
28
Page 14
I-format Instructions
immediate rs1 funct3 rd opcode
12 bits 5 bits 3 bits 5 bits 7 bits
Page 29
29
S-format Instructions
imm[11:5] rs2 rs1 funct3 imm[4:0] opcode
7 bits 5 bits 5 bits 3 bits 5 bits 7 bits
Page 30
30
Page 15
Composing the Elements
❖First-cut datapath does an instruction in one
clock cycle
◆Each datapath element can only do one function
at a time
◆Hence, we need separate instruction and data
memories
❖Use multiplexers where alternate data
sources are used for different instructions
Page 31
31
R-Type/Load/Store Datapath
Page 32
32
Page 16
Branch Instructions
❖Read register operands
❖Compare operands
◆Use ALU, subtract and check Zero output
❖Calculate target address
◆Sign-extend displacement
◆Shift left 1 place (halfword displacement)
◆Add to PC value
Page 33
33
imm[12] imm[11]
◼ PC-relative addressing
◼ Target address = PC + immediate × 2
❖Branch to a labeled instruction if a condition
is true
◆Otherwise, continue sequentially
❖beq rs1, rs2, L1
◆if (rs1 == rs2) branch to instruction labeled L1
Page 34
34
Page 17
Branch Instructions
Just
re-routes
wires
Sign-bit wire
replicated
Page 35
35
Page 36
36
Page 18
Overall Control
❖Split into two Controllers (for now…)
❖Divide and Conquer
1. “ALU Control” unit
➢ Uses 2-bit ALUOp generated by Main Control unit
➢ Uses also Funct7 and Funct3 fields from Instruction
➢ Generates control signals ALUOperation (4 bits) that control
directly the function executed by the ALU
2. “Main Control” unit
➢ Control signals derived from instruction (Opcode)
➢ Generates a 2-bit ALUOp used by ALU Control
Page 37
37
ALUOp Values
Page 38
38
Page 19
ALU Control – Truth Table
❖ Input signals:
◆ ALUOp (2 bits), Funct7 (7 bits, Instruction[31-25], Funct3 (3 bits,
Instruction [14-12])
❖ Output signals:
◆ ALUOperation control signals (4 bits)
Truth Table
ALUOperat
ion
39
Page 40
40
Page 20
Main Control – Truth Table
❖ Input signals:
◆ Opcode (7 bits, Instruction [6-0])
❖ Output signals:
◆ ALUOp (2 bits, used by ALU Control), ALUSrc, MemtoReg, RegWrite, etc.
Truth Table
ALUOp Values
41
Page 42
42
Page 21
R-Type Instruction
Instr.[31-25,14-12]
Page 43
43
Load Instruction
Instr.[31-25,14-12]
Page 44
44
Page 22
BEQ Instruction
Instr.[31-25,14-12]
Page 45
45
Control table:
New control
Instruction
Type
ALUSrc MemtoReg RegWrite MemRead MemWrite Branch ALUOp1 ALUOp0 signal:
SUBGTZ
R-type 0 0 1 0 0 0 1 0 0
LW 1 1 1 1 0 0 0 0 0
SW 1 X 0 0 1 0 0 0 0
BEQ 0 X 0 0 0 1 0 1 0
SUBGTZ 0 0 1 0 0 0 1 0 1 Page 46
46
Page 23
Practice – Performance Analysis
❖ Calculate cycle time assuming:
◆ memory (2ns), ALU and adders (2ns), register file access (1ns)
Instr.[31-25,14-12]
Page 47
47
Page 48
48
Page 24