Download presentation
Presentation is loading. Please wait.
Published byCaren Moody Modified over 8 years ago
1
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 1 ELEC 5200-001/6200-001 Computer Architecture and Design Fall 2015 Datapath and Control (Chapter 4) Vishwani D. Agrawal James J. Danaher Professor Department of Electrical and Computer Engineering Auburn University, Auburn, AL 36849 http://www.eng.auburn.edu/~vagrawal vagrawal@eng.auburn.edu
2
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 2 Von Neumann Kitchen Registers ALU Control MemoryOutput Program Data My choice PC Start Processor Input
3
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 3 Where Does It All Begin? In a register called program counter (PC). PC contains the memory address of the next instruction to be executed. In the beginning, PC contains the address of the memory location where the program begins.
4
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 4 Where is the Program? Machine code of program Memory Start address Program counter (register) Processor
5
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 5 How Does It Run? Start PC has memory address where program begins Fetch instruction word from memory address in PC and increment PC ← PC + 4 to point to next instruction Decode instruction Program complete? YesNo STOP Execute instruction Save result in register or memory
6
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 6 Datapath and Control Datapath: Memory, registers, adders, ALU, and communication buses. Each step (fetch, decode, execute, save result) requires communication (data transfer) paths between memory, registers and ALU. Control: Datapath for each step is set up by control signals that set up dataflow directions on communication buses and select ALU and memory functions. Control signals are generated by a control unit consisting of one or more finite- state machines.
7
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 7 Datapath for Instruction Fetch PC Instruction Memory 4 Address Instruction word to control unit and registers Add
8
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 8 Register File: A Datapath Component 32 Registers (reg. file) Write register reg 1 data reg 2 data 5 5 5 32 reg 1 reg 2 Read registers Write data RegWrite from control
9
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 9 Multi-Operation ALU ALU 3 zero result overflow Operation select from control Operation selectALU function 000AND 001OR 010Add 110Subtract 111Set on less than zero = 1, when all bits of result are 0
10
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 10 R-Type Instructions Also known as arithmetic-logical instructions add, sub, slt add, sub, slt Example: add$t0, $s1, $s2 –Machine instruction word 000000 10001 10010 01000 00000 100000 opcode $s1 $s2 $t0function –Read two registers –Write one register –Opcode and function code go to control unit that generates RegWrite and ALU operation code.
11
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 11 Datapath for R-Type Instruction 32 Registers (reg. file) Write reg. number 5 5 5 32 $s1 $s2 Read register numbers Write data ALU 3 zero result overflow Operation select from control (add) 10001 10010 01000 RegWrite from control activated 32 $t0 000000 10001 10010 01000 00000 100000 opcode $s1 $s2 $t0 function (add)
12
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 12 Load and Store Instructions I-type instructions lw$t0, 1200 ($t1)# incr. in bytes lw$t0, 1200 ($t1)# incr. in bytes 100011 01001 01000 0000 0100 1011 0000 opcode $t1 $t01200 sw$t0, 1200 ($t1)# incr. in bytes sw$t0, 1200 ($t1)# incr. in bytes 101011 01001 01000 0000 0100 1011 0000 opcode $t1 $t01200
13
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 13 Datapath for lw Instruction Operation select from control (add) 32 Registers (reg. file) Write reg. number 5 5 5 32 $t1 Read register numbers Write data ALU 3 zero result overflow 01001 01000 RegWrite from control activated 32 Sign extend 16 0000 0100 1011 0000 Data memory Addr. Read data MemWrite MemRead activated $t0 Write data 100011 01001 01000 0000 0100 1011 0000 opcode $t1 $t0 1200 opcode $t1 $t0 1200 mem. data to $t0
14
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 14 Datapath for sw Instruction Operation select from control (add) 32 Registers (reg. file) Write reg. number 5 5 5 32 $t1 $t0 Read register numbers Write data ALU 3 zero result overflow 01001 RegWrite from control 32 Sign extend 16 0000 0100 1011 0000 Data memory Addr. Read data $t0 data to mem. 01000 MemWrite activated MemRead Write data 101011 01001 01000 0000 0100 1011 0000 opcode $t1 $t0 1200 opcode $t1 $t0 1200 32
15
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 15 Branch Instruction (I-Type) beq$s1, $s2, 25# if $s1 = $s2, advance PC through 25 instructions beq$s1, $s2, 25# if $s1 = $s2, advance PC through 25 instructions 16-bits 16-bits 000100 10001 10010 0000 0000 0001 1001 opcode $s1 $s2 25 Note: Can branch within ± 2 15 words from the current instruction address in PC.
16
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 16 Datapath for beq Instruction Operation select from control (subtract) 32 Registers (reg. file) Write reg. number 5 5 5 32 $s1 Read register numbers Write data ALU 3 zero result overflow 10001 10010 RegWrite from control 32 Sign extend 16 0000 0000 0001 1001 Shift left 2 Add 16-bits 16-bits 000100 10001 10010 0000 0000 0001 1001 opcode $s1 $s225 opcode $s1 $s225 $s2 32 To branch control logic PC+4 From instruction fetch datapath Branch target 32
17
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 17 J-Type Instruction j2500# jump to instruction 2,500 j2500# jump to instruction 2,500 26-bits 26-bits 000010 0000 0000 0000 0010 0111 0001 00 000010 0000 0000 0000 0010 0111 0001 00 opcode 2,500 opcode 2,500 0000 0000 0000 0000 0010 0111 0001 0000 bits 28-31 from PC+4 32-bit jump address
18
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 18 Datapath for Jump Instruction PC Instruction Memory Address Instruction word to control and registers 4 Add 1 mux 0 mux 1 opcode (bits 26-31) to control Shift left 2 6 26 Branch addr. Branch Jump 32 28 4 32 PC+4 32
19
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 19 Instr. mem. PC Add Reg. File Data mem. 1 mux 0 0 mux 1 4 1 mux 0 Sign ext. Shift left 2 ALU Cont. CONTROL opcode MemWrite MemRead ALU Branch zero 0-15 0-5 11-15 16-20 21-25 26-31 ALU 0 mux 1 Shift left 2 0-25 Jump Combined Datapaths RegDst MemtoReg
20
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 20 Control Control Logic Instruction bits 26-31 opcode RegDst Jump Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite ALU Control Instruction bits 0-5 funct. 2 to ALU
21
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 21 Control Logic: Truth Table Instr type Inputs: instr. opcode bits Outputs: control signals 313029282726 RegDstJumpALUSrcMemtoRegRegWriteMemReadMemWriteBranchALOOp1ALUOp2 R0000001000100010 lw lw1000110011110000 sw sw101011X01X001000 beq beq000100X00X000101 j000010X1XX0X0XXX
22
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 22 How Long Does It Take? Assume control logic is fast and does not affect the critical timing. Major time delay components are ALU, memory read/write, and register read/write. Arithmetic-type (R-type) Fetch (memory read)2ns Register read1ns ALU operation2ns Register write1ns Total6ns
23
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 23 Time for lw and sw (I-Types) ALU (R-type)6ns Load word (I-type) –Fetch (memory read)2ns –Register read1ns –ALU operation2ns –Get data (mem. Read)2ns –Register write1ns –Total8ns Store word (no register write)7ns
24
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 24 Time for beq (I-Type) ALU (R-type)6ns Load word (I-type)8ns Store word (I-type)7ns Branch on equal (I-type) –Fetch (memory read)2ns –Register read1ns –ALU operation2ns –Total 5ns
25
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 25 Time for Jump (J-Type) ALU (R-type)6ns Load word (I-type)8ns Store word (I-type)7ns Branch on equal (I-type)5ns Jump (J-type) –Fetch (memory read)2ns –Total 2ns
26
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 26 How Fast Can Clock Run? If every instruction is executed in one clock cycle, then: –Clock period must be at least 8ns to perform the longest instruction, i.e., lw. –This is a single cycle machine. –It is slower because many instructions take less than 8ns but are still allowed that much time. Method of speeding up: Use multicycle datapath.
27
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 27 A Single Cycle Example a31. a2 a1 a0 b31. b2 b1 b0 1-b full adder 1-b full adder 1-b full adder 1-b full adder s31. s2 s1 s0 0 c32 Delay of 1-bit full adder = 1ns Clock period ≥ 32ns Time of adding words~ 32ns Time of adding bytes~ 32ns
28
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 28 A Multicycle Implementation a31. a2 a1 a0 b31. b2 b1 b0 1-b full adder s31. s2 s1 s0 c32 FF Initialize to 0 Shift Delay of 1-bit full adder = 1ns Clock period ≥ 1ns Time of adding words~ 32ns Time of adding bytes~ 8ns
29
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 29 Instr. mem. PC Add Reg. File Data mem. 1 mux 0 0 mux 1 4 1 mux 0 Sign ext. Shift left 2 ALU Cont. CONTROL opcode MemWrite MemRead ALU Branch zero 0-15 0-5 11-15 16-20 21-25 26-31 ALU 0 mux 1 Shift left 2 0-25 Jump Single-cycle Datapaths RegDst MemtoReg
30
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 30 Multicycle Datapath PC Instr. reg. (IR) Mem. Data (MDR) ALUOut Reg. A Reg. B Reg. ALU Register file Memory Addr. Data One-cycle data transfer paths (need registers to hold data) 4
31
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 31 Multicycle Datapath Requirements Only one ALU, since it can be reused. Single memory for instructions and data. Five registers added: –Instruction register (IR) –Memory data register (MDR) –Three ALU registers, A and B for inputs and ALUOut for output
32
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 32 Multicycle Datapath PC Instr. reg. (IR) Mem. Data (MDR) ALUOut Reg. A Reg. B Reg. ALU Register file Memory Addr. Data 4 Sign extend Shift left 2 ALU control 0-5 0-15 16-20 21-25 IorD MemtoReg ALUOp ALUSrcBALUSrcA RegDst IRWrite RegWrite MemWrite MemRead in1 in2 out control MUX Shift left 2 0-25 28-31 PCSource PCWrite etc. 26-31 to Control FSM 11-15
33
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 33 3 to 5 Cycles for an Instruction StepR-type (4 cycles) Mem. Ref. (4 or 5 cycles) Branch type (3 cycles) J-type Instruction fetch IR ← Memory[PC]; PC ← PC+4 Instr. decode/ Reg. fetch A ← Reg(IR[21-25]); B ← Reg(IR[16-20]) ALUOut ← PC + {(sign extend IR[0-15]) << 2} Execution, addr. Comp., branch & jump completion ALUOut ← A op B ALUOut ← A+sign extend (IR[0-15]) If (A= =B) then thenPC←ALUOut PC←PC[28- 31] ||(IR[0-25]<<2) Mem. Access or R-type completion Reg(IR[11- 15]) ← ALUOut MDR←M[ALUout] or M[ALUOut]←B Memory read completion Reg(IR[16-20]) ← MDR
34
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 34 Cycle 1 of 5: Instruction Fetch (IF) Read instruction into IR, M[PC] → IR Control signals used: IorD=0select PC MemRead=1read memory IRWrite=1write IR Increment PC, PC + 4 → PC Control signals used: ALUSrcA=0select PC into ALU ALUSrcB=01select constant 4 ALUOp=00ALU adds PCSource=00select ALU output PCWrite=1write PC
35
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 35 Cycle 2 of 5: Instruction Decode (ID) Control unit decodes instruction Datapath prepares for execution R and I types, reg 1→ A reg, reg 2 → B reg No control signals needed Branch type, compute branch address in ALUOut ALUSrcA= 0select PC into ALU ALUSrcB= 11Instr. Bits 0-15 shift 2 into ALU ALUOp= 00ALU adds opcode | reg 1 | reg 2 | reg 3 | shamt | fncode opcode | reg 1 | reg 2 | word address increment opcode | word address jump 31-26 25-21 20-16 15-11 10-6 5-0 RIJRIJ
36
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 36 Cycle 3 of 5: Execute (EX) R type: execute function on reg A and reg B, result in ALUOut Control signals used: ALUSrcA=1A reg into ALU ALUsrcB=00B reg into ALU ALUOp=10instr. Bits 0-5 control ALU I type, lw or sw: compute memory address in ALUOut ← A reg + sign extend IR[0-15] Control signals used: ALUSrcA=1A reg into ALU ALUSrcB= 10Instr. Bits 0-15 into ALU ALUOp= 00ALU adds
37
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 37 Cycle 3 of 5: Execute (EX) I type, beq: subtract reg A and reg B, write ALUOut to PC Control signals used: ALUSrcA=1A reg into ALU ALUsrcB=00B reg into ALU ALUOp=01ALU subtracts If zero = 1, PCSource = 01ALUOut to PC If zero = 1, PCwriteCond =1write PC Instruction complete, go to IF J type: write jump address to PC ← IR[0-25] shift 2 and four leading bits of PC Control signals used: PCSource=10 PCWrite= 1write PC Instruction complete, go to IF
38
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 38 Cycle 4 of 5: Reg Write/Memory R type, write destination register from ALUOut Control signals used: RegDst=1Instr. Bits 11-15 specify reg. MemtoReg=0ALUOut into reg. RegWrite=1write register Instruction complete, go to IF I type, lw: read M[ALUOut] into MDR Control signals used: IorD=1select ALUOut as mem adr. MemRead= 1read memory to MDR I type, sw: write M[ALUOut] from B reg Control signals used: IorD=1select ALUOut as mem adr. MemWrite= 1write memory Instruction complete, go to IF
39
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 39 Cycle 5 of 5: Reg Write I type, lw: write MDR to reg[IR(16-20)] Control signals used: RegDst=0instr. Bits 16-20 are write reg MemtoReg=1MDR to reg file write input RegWrite= 1write reg. file Instruction complete, go to IF For an alternative method of designing datapath, see N. Tredennick, Microprocessor Logic Design, the Flowchart Method, Digital Press, 1987.
40
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 40 1-bit Control Signals Signal name Value = 0 Value =1 RegDst Write reg. # = bit 16-20 Write reg. # = bit 11-15 RegWrite No action Write reg. ← Write data ALUSrcA First ALU Operand ← PC First ALU Operand←Reg. A MemRead No action Mem.Data Output←M[Addr.] MemWrite No action M[Addr.]←Mem. Data Input MemtoReg Reg.File Write In←ALUOut Reg.File Write In←MDR IorD Mem. Addr. ← PC Mem. Addr. ← ALUOut IRWrite No action IR ← Mem.Data Output PCWrite No action PC is written PCWriteCond No action PC is written if zero(ALU)=1 PCWrite etc. PCWrite PCWriteCond zero(ALU)
41
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 41 2-bit Control Signals Signal name ValueAction ALUOp00 ALU performs add 01 ALU performs subtract 10 Funct. field (0-5 bits of IR ) determines ALU operation ALUSrcB00 Second input of ALU ← B reg. 01 Second input of ALU ← 4 (constant) 10 Second input of ALU ← 0-15 bits of IR sign ext. to 32b 11 Second input of ALU ← 0-15 bits of IR sign ext. and left shift 2 bits PCSource00 ALU output (PC +4) sent to PC 01 ALUOut (branch target addr.) sent to PC 10 Jump address IR[0-25] shifted left 2 bits, concatenated with PC+4[28-31], sent to PC
42
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 42 Control: Finite State Machine Instruction decode and register fetch Memory access instr. R-type instr. Branch instr. Jump instr. Start Instruction fetch State 0 State 1 FSM-M FSM-RFSM-BFSM-J Clock cycle 1 Clock cycle 2 Clock cycles 3-5
43
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 43 State 0: Instruction Fetch (CC1) PC Instr. reg. (IR) Mem. Data (MDR) ALUOut Reg. A Reg. B Reg. ALU Register file Memory Addr. Data 4 Sign extend Shift left 2 ALU control 0-5 0-15 16-20 21-25 IorD=0 MemtoReg ALUOp =00 ALUSrcB=01 ALUSrcA=0 RegDst IRWrite =1 RegWrite MemWrite MemRead = 1 in1 in2 out control MUX Shift left 2 0-25 28-31 PCSource=00 PCWrite etc.=1 Add 26-31 to Control FSM
44
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 44 State 0 Control FSM Outputs MemRead =1 ALUSrcA = 0 IorD = 0 IRWrite = 1 ALUSrcB = 01 ALUOp = 00 PCWrite = 1 PCSource = 00 Start State0 Instruction fetch State 1 Instruction decode/ Register fetch/ Branch addr. Outputs?
45
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 45 State 1: Instr. Decode/Reg. Fetch/ Branch Address (CC2) PC Instr. reg. (IR) Mem. Data (MDR) ALUOut Reg. A Reg. B Reg. ALU Register file Memory Addr. Data 4 Sign extend Shift left 2 ALU control 0-5 0-15 16-20 21-25 IorD MemtoReg ALUOp = 00 ALUSrcB=11 ALUSrcA=0 RegDst IRWrite RegWrite MemWrite MemRead in1 in2 out control MUX Shift left 2 0-25 28-31 PCSource PCWrite etc. Add 26-31 to Control FSM
46
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 46 State 1 Control FSM Outputs MemRead =1 ALUSrcA = 0 IorD = 0 IRWrite = 1 ALUSrcB = 01 ALUOp = 00 PCWrite = 1 PCSource = 00 Start State0 Instruction fetch (IF) State 1 Instruction decode (ID) / Register fetch / Branch addr. ALUSrcA = 0 ALUSrcB = 11 ALUOp = 00 FSM-MFSM-RFSM-BFSM-J Opcode = lw, sw Opcode = R-type Opcode = J-typeOpcode = BEQ
47
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 47 State 1 (Opcode = lw) → FSM-M (CC3-5) PC Instr. reg. (IR) Mem. Data (MDR) ALUOut Reg. A Reg. B Reg. ALU Register file Addr. Data 4 Sign extend Shift left 2 ALU control 0-5 0-15 16-20 21-25 IorD=1 MemtoReg=1 ALUOp = 00 ALUSrcB=10 ALUSrcA=1 RegDst=0 IRWrite RegWrite=1 MemWrite MemRead=1 in1 in2 out control MUX Shift left 2 0-25 28-31 PCSource PCWrite etc. Add 26-31 to Control FSM Memory CC3 CC4 CC5
48
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 48 State 1 (Opcode= sw)→FSM-M (CC3-4) PC Instr. reg. (IR) Mem. Data (MDR) ALUOut Reg. A Reg. B Reg. ALU Register file Addr. Data 4 Sign extend Shift left 2 ALU control 0-5 0-15 16-20 21-25 IorD=1 MemtoReg ALUOp = 00 ALUSrcB=10 ALUSrcA=1 RegDst=0 IRWrite RegWrite MemWrite=1 MemRead in1 in2 out control MUX Shift left 2 0-25 28-31 PCSource PCWrite etc. Add 26-31 to Control FSM Memory CC3 CC4
49
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 49 FSM-M (Memory Access) ALUSrcA =1 ALUSrcB = 10 ALUOp = 00 MemRead = 1 IorD = 1 RegWrite = 1 MemtoReg = 1 RegDst = 0 MemWrite = 1 IorD = 1 Compute mem addrress Read Memory data Write memory Write register Opcode = “lw” Opcode = “sw” To state 0 (Instr. Fetch) From state 1 Opcode = “lw” or “sw”
50
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 50 State 1(Opcode=R-type)→FSM-R (CC3-4) PC Instr. reg. (IR) Mem. Data (MDR) ALUOut Reg. A Reg. B Reg. ALU Register file Addr. Data 4 Sign extend Shift left 2 ALU control 0-5 0-15 16-20 21-25 IorD MemtoReg=0 ALUOp = 10 ALUSrcB=00 ALUSrcA=1 RegDst=0 IRWrite RegWrite MemWrite MemRead in1 in2 out control MUX Shift left 2 0-25 28-31 PCSource PCWrite etc. 26-31 to Control FSM Memory “funct. code” 11-15 CC3 CC4
51
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 51 FSM-R (R-type Instruction) ALUSrcA =1 ALUSrcB = 00 ALUOp = 10 RegWrite = 1 MemtoReg = 0 RegDst = 1 ALU operation Write register To state 0 (Instr. Fetch) From state 1 Opcode = R-type
52
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 52 State 1 (Opcode = beq ) → FSM-B (CC3) PC Instr. reg. (IR) Mem. Data (MDR) ALUOut Reg. A Reg. B Reg. ALU Register file Addr. Data 4 Sign extend Shift left 2 ALU control 0-5 0-15 16-20 21-25 IorD MemtoReg ALUOp = 01 ALUSrcB=00 ALUSrcA=1 RegDst IRWrite RegWrite MemWrite MemRead in1 in2 out control MUX Shift left 2 0-25 28-31 PCSource 01 PCWrite etc.=1 26-31 to Control FSM Memory subtract 11-15 zero CC3 If(zero)
53
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 53 Write PC on “zero” PCWrite etc.=1 PCWrite PCWriteCond=1 zero=1 PCWrite = 1, unconditionally write PC Cycle 1, fetch Cycle 3, jump
54
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 54 FSM-B (Branch) ALUSrcA =1 ALUSrcB = 00 ALUOp = 01 PCWriteCond=1 PCSource=01 Branch condition: If A – B=0 zero = 1 To state 0 (Instr. Fetch) From state 1 Opcode = “beq” Write PC on branch condition
55
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 55 State 1 (Opcode = j) → FSM-J (CC3) PC Instr. reg. (IR) Mem. Data (MDR) ALUOut Reg. A Reg. B Reg. Register file Addr. Data 4 Sign extend Shift left 2 ALU control 0-5 0-15 16-20 21-25 IorD MemtoReg ALUOp ALUSrcB ALUSrcA RegDst IRWrite RegWrite MemWrite MemRead in1 in2 out control MUX Shift left 2 0-25 28-31 PCSource 10 PCWrite etc. 26-31 to Control FSM Memory 11-15 zero ALU CC3
56
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 56 Write PC PCWrite etc.=1 PCWrite=1 PCWriteCond zero PCWrite = 1, unconditionally write PC Cycle 1, fetch Cycle 3, jump
57
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 57 FSM-J (Jump) PCWrite=1 PCSource=10 To state 0 (Instr. Fetch) From state 1 Opcode = “jump” Write jump addr. In PC
58
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 58 Control FSM Instr. decode/reg. fetch/branch addr. ALU operation Write PC on branch condition Write memory data Write jump addr. to PC Write register Read memory data Instr. fetch/ adv. PC Compute memory addr. Write register lw or sw lw sw R B J Start State 0 1 23 45 6 7 8 9
59
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 59 Control FSM (Controller) Combinational logic FF 16 control outputs 6 inputs (opcode) Next state Present state Clock Reset
60
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 60 Designing the Control FSM Encode states; need 4 bits for 10 states, e.g., –State 0 is 0000, state 1 is 0001, and so on. Write a truth table for combinational logic: OpcodePresent stateControl signalsNext state 000000000000010001100001000001................................ Synthesize a logic circuit from the truth table. Connect four flip-flops between the next state outputs and present state inputs.
61
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 61 Block Diagram of a Processor Datapath (PC, register file, registers, ALU) Controller (Control FSM) ALU control Reset Clock Mem. Addr. Mem. write data Mem. data out MemWrite MemRead ALUOp 2-bits funct. [0,5] ALUOp 3-bits Opcode 6-bits zero Overflow ALUSrcA ALUSrcB 2-bits PCSource 2-bits RegDst RegWrite MemtoReg IorD IRWrite PCWrite PCWriteCond
62
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 62 Exceptions or Interrupts Conditions under which the processor may produce incorrect result or may “hang”. –Illegal or undefined opcode. –Arithmetic overflow, divide by zero, etc. –Out of bounds memory address. EPC: 32-bit register holds the affected instruction address. Cause: 32-bit register holds an encoded exception type. For example, –0 for undefined instruction –1 for arithmetic overflow
63
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 63 Implementing Exceptions PC Instr. reg. (IR) 4 ALU control ALUOp =01 ALUSrcB=01 ALUSrcA=0 in1 in2 out control MUX PCSource 11 PCWrite etc.=1 26-31 to Control FSM ALU Subtract 8000 0180(hex) EPC Cause EPCWrite=1 0 1 CauseWrite=1 Overflow to Control FSM 32-bit register
64
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 64 How Long Does It Take? Again Assume control logic is fast and does not affect the critical timing. Major time components are ALU, memory read/write, and register read/write. Time for hardware operations, suppose Memory read or write2ns Register read1ns ALU operation2ns Register write1ns
65
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 65 Single-Cycle Datapath R-type6ns Load word (I-type)8ns Store word (I-type)7ns Branch on equal (I-type)5ns Jump (J-type)2ns Clock cycle time = 8ns Each instruction takes one cycle
66
Performance Parameters Average cycles per instruction (CPI) Cycle time (clock period, T) Execution time of a program For single-cycle datapath: CPI = 1 T = hardware time for lw instruction Execution time of a program =T × CPI × (Total instructions executed) Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 66
67
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 67 Multicycle Datapath Clock cycle time is determined by the longest operation, ALU or memory: Clock cycle time = 2ns Cycles per instruction: lw5(10ns) lw5(10ns) sw4(8ns) sw4(8ns) R-type4(8ns) R-type4(8ns) beq3(6ns) beq3(6ns) j3(6ns) j3(6ns)
68
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 68 CPI of a Multicycle Computer ∑ k (Instructions of type k) × CPI k CPI=—————————————— ∑ k (instructions of type k) where CPI k =Cycles for instruction of type k Note:CPI is dependent on the instruction mix of the program being run. Standard benchmark programs are used for specifying the performance of CPUs.
69
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 69 Example Consider a program containing: loads25% loads25% stores10% stores10% branches11% branches11% jumps2% jumps2% Arithmetic52% CPI= 0.25×5 + 0.10×4 + 0.11×3 + 0.02×3 + 0.52×4 = 4.12 for multicycle datapath CPI= 1.00 for single-cycle datapath
70
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 70 Multicycle vs. Single-Cycle Performance ratio=Single cycle time / Multicycle time (CPI × cycle time) for single-cycle = ——————————————— (CPI × cycle time) for multicycle 1.00 × 8ns =—————=0.97 4.12 × 2ns Single cycle is faster in this case, but is it always so?
71
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 71 Consider Another Example For this program: loads5% loads5% stores5% stores5% branches30% branches30% jumps10% jumps10% Arithmetic50% CPI= 0.05×5 + 0.05×4 + 0.30×3 + 0.10×3 + 0.50×4 = 3.65 for multicycle datapath CPI= 1.00 for single-cycle datapath
72
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 72 Multicycle vs. Single-Cycle Performance ratio=Single cycle time / Multicycle time (CPI × cycle time) for single-cycle = ——————————————— (CPI × cycle time) for multicycle 1.00 × 8ns =—————=1.096 3.65 × 2ns Multicycle is faster in this case, so the performance ratio depends on the instruction mix. Can we do better?
73
Fall 2015, Sep 16... ELEC 5200-001/6200-001 Lecture 5 73 Next: Pipelining https://www.youtube.com/watch?v=IjarLbD9r30 https://www.youtube.com/watch?v=ANXGJe6i3G8 https://www.youtube.com/watch?v=5lp4EbfPAtI
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.