14:332:331 Computer Architecture and Assembly Language Spring 2006 Week 10 Building a Multi-Cycle Datapath - PowerPoint PPT Presentation

About This Presentation
Title:

14:332:331 Computer Architecture and Assembly Language Spring 2006 Week 10 Building a Multi-Cycle Datapath

Description:

... the clock cycle must be timed to accommodate the slowest instruction ... Can we figure out the values of the control signals? ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 32
Provided by: jani177
Category:

less

Transcript and Presenter's Notes

Title: 14:332:331 Computer Architecture and Assembly Language Spring 2006 Week 10 Building a Multi-Cycle Datapath


1
14332331Computer Architecture and Assembly
LanguageSpring 2006Week 10Building a
Multi-Cycle Datapath
  • Adapted from Dave Pattersons UCB CS152 slides
    and
  • Mary Jane Irwins PSU CSE331 slides

2
Heads Up
  • This weeks material
  • Multicycle MIPS datapath implementation
  • Reading assignment PH 5.5 and C.3

3
Review Single Cycle Data and Control Path
Instr25-0
1
Shift left 2
28
32
26
0
PC431-28
0
Add
Add
1
4
Shift left 2
PCSrc
Jump
ALUOp
Branch
MemRead
MemtoReg
Control
Instr31-26
MemWrite
ALUSrc
RegWrite
RegDst
ovf
Instr25-21
Read Addr 1
Instruction Memory
Read Data 1
Address
Register File
zero
Instr20-16
Read Addr 2
Data Memory
Read Address
Instr31-0
PC
Read Data
1
0
ALU
Write Addr
Read Data 2
0
1
Write Data
0
Instr15 -11
Write Data
1
Sign Extend
Instr15-0
ALU control
16
32
Instr5-0
4
Disadvantages of the Single Cycle Datapath
  • Uses the clock cycle inefficiently the clock
    cycle must be timed to accommodate the slowest
    instruction
  • especially problematic for more complex
    instructions like floating point multiply
  • Is wasteful of area since some functional units
    must be duplicated since they can not be shared
    during an instruction execution
  • e.g., need separate adders to do PC update and
    branch target address calculations, as well as an
    ALU to do R-type arithmetic/logic operations and
    data memory address calculations

5
Multicycle Implementation Overview
  • Each step in the execution takes 1 clock cycle
  • An instruction takes more than 1 clock cycle to
    complete
  • Not every instruction takes the same number of
    clock cycles to complete
  • Multicycle implementations allow
  • functional units to be used more than once per
    instruction as long as they are used on different
    clock cycles, as a result
  • only need one memory
  • need only one ALU/adder
  • faster clock rates
  • different instructions to take a different number
    of clock cycles

6
The Multicycle Datapath A High Level View
  • Registers have to be added after every major
    functional unit to hold the output value until it
    is used in a subsequent clock cycle

Address
Memory
Read Addr 1
PC
Read Data 1
Register File
Read Addr 2
Read Data (Instr. or Data)
ALU
Write Addr
Read Data 2
Write Data
Write Data
7
Clocking the Multicycle Datapath
8
Multicycle Approach
  • Break up the instructions into steps where each
    step takes a cycle while trying to
  • balance the amount of work to be done in each
    step
  • restrict each cycle to use only one major
    functional unit
  • At the end of a cycle
  • Store values needed in a later cycle by the
    current instruction in a state element (internal
    register) not visible to the programmer
  • IR Instruction Register
  • MDR Memory Data Register
  • A and B register file read data registers
  • ALUout ALU output register
  • All (except IR) hold data only between a pair of
    adjacent clock cycles (so dont need a write
    control signal)
  • Data used by subsequent instructions are stored
    in programmer visible state elements (i.e.,
    register file, PC, or memory)

9
The Complete Multicycle Data with Control
PCWriteCond
PCWrite
PCSource
ALUOp
IorD
Control
MemRead
ALUSrcB
MemWrite
ALUSrcA
MemtoReg
RegWrite
IRWrite
RegDst
PC31-28
Instr31-26
Shift left 2
28
Instr25-0
2
0
1
Address
Memory
0
PC
Read Addr 1
0
A
Read Data 1
IR
Register File
1
zero
1
Read Addr 2
Read Data (Instr. or Data)
0
ALUout
ALU
Write Addr
Read Data 2
Write Data
1
B
0
Write Data
1
4
1
0
2
Sign Extend
Shift left 2
3
Instr15-0
ALU control
32
Instr5-0
10
Multicycle Approach, cont
  • Reading/writing to
  • any of the internal registers or the PC occurs
    (quickly) at the end of a clock cycle
  • reading/writing to the register file takes 50
    of a clock cycle since it has additional control
    and access overhead (reading can be done in
    parallel with decode)
  • Have to add multiplexors in front of several of
    the functional unit inputs because the functional
    units are shared by different instruction cycles
  • All operations occurring in one step occur in
    parallel within the same clock cycle
  • This limits us to one ALU operation, one memory
    access, and one register file access per step
    (per clock cycle)

11
Five Instruction Steps
  • Instruction Fetch
  • Instruction Decode and Register Fetch
  • R-type Instruction Execution, Memory Read/Write
    Address Computation, Branch Completion, or Jump
    Completion
  • Memory Read Access, Memory Write Completion or
    R-type Instruction Completion
  • Memory Read Completion (Write Back)
  • INSTRUCTIONS TAKE FROM 3 - 5 CYCLES!

12
Step 1 Instruction Fetch
  • Use PC to get instruction from the memory and put
    it in the Instruction Register
  • Increment the PC by 4 and put the result back in
    the PC
  • Can be described succinctly using RTL
    "Register-Transfer Language
  • IR MemoryPC PC PC 4
  • Can we figure out the values of the control
    signals?
  • What is the advantage of updating the PC now?

13
Fetch Control Signals Settings
Instr Fetch
Start
14
Step 2 Instruction Decode and Register Fetch
  • Dont know what the instruction is yet, so can
    only
  • Read registers rs and rt in case we need them
  • Compute the branch address in case the
    instruction is a branch
  • RTL
  • A RegIR25-21B RegIR20-16ALUOut
    PC (sign-extend(IR15-0)ltlt 2)
  • Note we aren't setting any control lines based on
    the instruction (since we are busy "decoding" it
    in our control logic)

15
Datapath Activity During Instruction Decode
PCWriteCond
PCWrite
PCSource
ALUOp
IorD
Control
MemRead
ALUSrcB
MemWrite
ALUSrcA
MemtoReg
RegWrite
IRWrite
RegDst
PC31-28
Instr31-26
Shift left 2
28
Instr25-0
2
0
1
Address
Memory
0
PC
Read Addr 1
0
A
Read Data 1
IR
Register File
1
zero
1
Read Addr 2
Read Data (Instr. or Data)
0
ALUout
ALU
Write Addr
Read Data 2
Write Data
1
B
0
Write Data
1
4
1
0
2
Sign Extend
Shift left 2
3
Instr15-0
ALU control
32
Instr5-0
16
Decode Control Signals Settings
Decode
Instr Fetch
IorD0 MemReadIRWrite ALUSrcA0 ALUsrcB01 PCSour
ce,ALUOp00 PCWrite
Unless otherwise assigned PCWrite,IRWrite,
MemWrite,RegWrite0 othersX
Start
17
Step 3 (instruction dependent)
  • ALU is performing one of four functions, based on
    instruction type
  • Memory reference (lw and sw)
  • ALUOut A sign-extend(IR15-0)
  • R-type
  • ALUOut A op B
  • Branch
  • if (AB) PC ALUOut
  • Jump
  • PC PC31-28 (IR25-0 ltlt 2)

18
Datapath Activity During Instruction Execute
PCWriteCond
PCWrite
PCSource
ALUOp
IorD
Control
MemRead
ALUSrcB
MemWrite
ALUSrcA
MemtoReg
RegWrite
IRWrite
RegDst
PC31-28
Instr31-26
Shift left 2
28
Instr25-0
2
0
1
Address
Memory
0
PC
Read Addr 1
0
A
Read Data 1
IR
Register File
1
zero
1
Read Addr 2
Read Data (Instr. or Data)
0
ALUout
ALU
Write Addr
Read Data 2
Write Data
1
B
0
Write Data
1
4
1
0
2
Sign Extend
Shift left 2
3
Instr15-0
ALU control
32
Instr5-0
19
Execute Control Signals Settings
Decode
Instr Fetch
IorD0 MemReadIRWrite ALUSrcA0 ALUsrcB01 PCSour
ce,ALUOp00 PCWrite
Unless otherwise assigned PCWrite,IRWrite,
MemWrite,RegWrite0 othersX
ALUSrcA0 ALUSrcB11 ALUOp00 PCWriteCond0
Start
(Op R-type)
(Op beq)
(Op lw or sw)
(Op j)
Execute
20
Step 4 (instruction dependent)
  • Memory reference
  • MDR MemoryALUOut --
    lwor MemoryALUOut B -- sw
  • R-type instruction completion
  • RegIR15-11 ALUOut
  • Remember, the register write actually takes place
    at the end of the cycle on the clock edge

21
Datapath Activity During Memory Access
PCWriteCond
PCWrite
PCSource
ALUOp
IorD
Control
MemRead
ALUSrcB
MemWrite
ALUSrcA
MemtoReg
RegWrite
IRWrite
RegDst
PC31-28
Instr31-26
Shift left 2
28
Instr25-0
2
0
1
Address
Memory
0
PC
Read Addr 1
0
A
Read Data 1
IR
Register File
1
zero
1
Read Addr 2
Read Data (Instr. or Data)
0
ALUout
ALU
Write Addr
Read Data 2
Write Data
1
B
0
Write Data
1
4
1
0
2
Sign Extend
Shift left 2
3
Instr15-0
ALU control
32
Instr5-0
22
Memory Access Control Signals Settings
Decode
Instr Fetch
IorD0 MemReadIRWrite ALUSrcA0 ALUsrcB01 PCSour
ce,ALUOp00 PCWrite
Unless otherwise assigned PCWrite,IRWrite,
MemWrite,RegWrite0 othersX
ALUSrcA0 ALUSrcB11 ALUOp00 PCWriteCond0
Start
(Op R-type)
(Op beq)
(Op lw or sw)
(Op j)
ALUSrcA1 ALUSrcB10 ALUOp00 PCWriteCond0
ALUSrcA1 ALUSrcB00 ALUOp01 PCSource01 PCWriteC
ond
ALUSrcA1 ALUSrcB00 ALUOp10 PCWriteCond0
PCSource10 PCWrite
Execute
(Op lw)
(Op sw)
Memory Access
23
Step 5 Memory Read Completion (Write Back)
  • All we have left is the write back into the
    register file the data just read from memory for
    lw instruction
  • RegIR20-16 MDR
  • What about all the other instructions?

24
Datapath Activity During Write Back
PCWriteCond
PCWrite
PCSource
ALUOp
IorD
Control
MemRead
ALUSrcB
MemWrite
ALUSrcA
MemtoReg
RegWrite
IRWrite
RegDst
PC31-28
Instr31-26
Shift left 2
28
Instr25-0
2
0
1
Address
Memory
0
PC
Read Addr 1
0
A
Read Data 1
IR
Register File
1
zero
1
Read Addr 2
Read Data (Instr. or Data)
0
ALUout
ALU
Write Addr
Read Data 2
Write Data
1
B
0
Write Data
1
4
1
0
2
Sign Extend
Shift left 2
3
Instr15-0
ALU control
32
Instr5-0
25
Write Back Control Signals Settings
Decode
Instr Fetch
IorD0 MemReadIRWrite ALUSrcA0 ALUsrcB01 PCSour
ce,ALUOp00 PCWrite
Unless otherwise assigned PCWrite,IRWrite,
MemWrite,RegWrite0 othersX
ALUSrcA0 ALUSrcB11 ALUOp00 PCWriteCond0
Start
(Op R-type)
(Op beq)
(Op lw or sw)
(Op j)
ALUSrcA1 ALUSrcB10 ALUOp00 PCWriteCond0
ALUSrcA1 ALUSrcB00 ALUOp01 PCSource01 PCWriteC
ond
ALUSrcA1 ALUSrcB00 ALUOp10 PCWriteCond0
PCSource10 PCWrite
Execute
(Op lw)
(Op sw)
Memory Access
RegDst1 RegWrite MemtoReg0 PCWriteCond0
MemWrite IorD1 PCWriteCond0
MemRead IorD1 PCWriteCond0
Write Back
26
RTL Summary
Step R-type Mem Ref Branch Jump
Instr fetch IR MemoryPC PC PC 4 IR MemoryPC PC PC 4 IR MemoryPC PC PC 4 IR MemoryPC PC PC 4
Decode A RegIR25-21B RegIR20-16ALUOut PC (sign-extend(IR15-0)ltlt 2) A RegIR25-21B RegIR20-16ALUOut PC (sign-extend(IR15-0)ltlt 2) A RegIR25-21B RegIR20-16ALUOut PC (sign-extend(IR15-0)ltlt 2) A RegIR25-21B RegIR20-16ALUOut PC (sign-extend(IR15-0)ltlt 2)
Execute ALUOut A op B ALUOut A sign-extend (IR15-0) if (AB) PC ALUOut PC PC31-28 (IR25-0 ltlt 2)
Memory access RegIR15-11 ALUOut MDR MemoryALUOut orMemoryALUOut B
Write-back RegIR20-16 MDR
27
Simple Questions
  • How many cycles will it take to execute this
    code? lw t2, 0(t3) lw t3,
    4(t3) beq t2, t3, Label assume not add
    t5, t2, t3 sw t5, 8(t3)Label ...
  • What is going on during the 8th cycle of
    execution?
  • In what cycle does the actual addition of t2 and
    t3 takes place?
  • In what cycle is the branch target address
    calculated?

28
Multicycle Control
  • Multicycle datapath control signals are not
    determined solely by the bits in the instruction
  • e.g., op code bits tell what operation the ALU
    should be doing, but not what instruction cycle
    is to be done next
  • Well use a finite state machine for control
  • a set of states (current state stored in State
    Register)
  • next state function (determined
    by
    current state and the input)
  • output function (determined by
    current state
    and the input)
  • Well use a Moore machine
    (so control signals
    based only on current state)

. . .
. . .
. . .
29
Finite State Machine Implementation
PCWrite
PCWriteCond
IorD
MemRead
MemWrite
IRWrite
MemtoReg
Combinational control logic
PCSource
Outputs
ALUOp
ALUSourceB
ALUSourceA
RegWrite
RegDst
Inputs
Op0
Op1
Op2
Op3
Op4
Op5
Next State
State Reg
Inst31-26
System Clock
30
Datapath Control Outputs Truth Table
Outputs Input Values (Current State3-0) Input Values (Current State3-0) Input Values (Current State3-0) Input Values (Current State3-0) Input Values (Current State3-0) Input Values (Current State3-0) Input Values (Current State3-0) Input Values (Current State3-0) Input Values (Current State3-0) Input Values (Current State3-0)
Outputs 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
PCWrite 1 0 0 0 0 0 0 0 0 1
PCWriteCond X 0 0 0 0 0 0 0 1 X
IorD 0 X X 1 X 1 X X X X
MemRead 1 X X 1 X X X X X X
MemWrite 0 0 0 0 0 1 0 0 0 0
IRWrite 1 0 0 0 0 0 0 0 0 0
MemtoReg X X X X 1 X X 0 X X
PCSource 00 XX XX XX XX XX XX XX 01 10
ALUOp 00 00 00 XX XX XX 10 XX 01 XX
ALUSrcB 01 11 10 XX XX XX 00 XX 00 XX
ALUSrcA 0 0 1 X X X 1 X 1 X
RegWrite 0 0 0 0 1 0 0 1 0 0
RegDst X X X X 0 X X 1 X X
31
Next State Truth Table
Current State 3-0 Inst31-26 (Op5-0) Inst31-26 (Op5-0) Inst31-26 (Op5-0) Inst31-26 (Op5-0) Inst31-26 (Op5-0) Inst31-26 (Op5-0)
Current State 3-0 000000 (R-type) 000010 (jmp) 000100 (beq) 100011 (lw) 101011 (sw) Any other
0000 0001 0001 0001 0001 0001 0001
0001 0110 1001 1000 0010 0010 illegal
0010 XXXX XXXX XXXX 0011 0101 illegal
0011 XXXX XXXX XXXX 0100 XXXX illegal
0100 XXXX XXXX XXXX 0000 XXXX illegal
0101 XXXX XXXX XXXX XXXX 0000 illegal
0110 0111 XXXX XXXX XXXX XXXX illegal
0111 0000 XXXX XXXX XXXX XXXX illegal
1000 XXXX XXXX 0000 XXXX XXXX illegal
1001 XXXX 0000 XXXX XXXX XXXX illegal
Write a Comment
User Comments (0)
About PowerShow.com