Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Processor: Datapath & Control. Implementing Instructions Simplified instruction set memory-reference instructions: lw, sw arithmetic-logical instructions:

Similar presentations


Presentation on theme: "The Processor: Datapath & Control. Implementing Instructions Simplified instruction set memory-reference instructions: lw, sw arithmetic-logical instructions:"— Presentation transcript:

1 The Processor: Datapath & Control

2 Implementing Instructions Simplified instruction set memory-reference instructions: lw, sw arithmetic-logical instructions: add, sub, and, or, slt control flow instructions: beq (bne), j (jal) Generic implementation: 1. PC to supply instruction address 2. get the instruction from memory 3. use the instruction to decide what to do 4. read registers Majority of instructions use the ALU the actions differ.

3 Clocking Methodology 1/2 Edge-triggered methodology values stored in a sequential logic elements are updated only on clock edge Typical execution: read contents of state elements, send values through some combinational logic write results to one or more state elements state element 1 state element 2 Combinational Logic

4 Clocking Methodology 2/2 An edge-triggered methodology allows a state element to be read and written in the same clock cycle state element Combinational Logic

5 Abstract View of Datapath Two types of functional units: combinational, e.g. ALU sequential, e.g. registers Add ALU Address Data Memory Data Registers Reg. No Instruction Memory Address Instruction PC Add 4

6 Datapath Including Control ALU Address Data Memory Data Registers Reg. No Instruction Memory Address Instruction PC Add 4 MemWrite MemRead RegWrite C ontrol zero branch

7 Register File Read register number 1 Read register number 2 Write register Write data Register file read data 1 read data 2 Write 5 5 5 32

8 ALU Symbol & Control ALU control lines Function 0000AND 0001OR 0010add 0110subtract 0111slt 1100NOR ALU 32 a b Result 32 Zero Overflow CarryOut ALU Control 4

9 Instruction Fetch Add Instruction Memory Address Instruction PC 4 Instruction

10 R-Type Instructions ALU Control Instruction read register 1 Read register 2 Write register Write data Register file read data 1 read data 2 Write 5 5 5 32 ALU Zero Overflow CarryOut 4 rs rt rd oprsrtrdshamtfunct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits add rd, rs, rt

11 Implementing Load & Stores rt rs rt ALU Address Data Memory Write Data Write Data Registers Read Reg. 1 MemWrite MemRead RegWrite zero Read Reg. 2 Write Reg. Read Data 1 Read Data 2 Read Data Sign Extend 32 Instruction 16 Immediate ALU Control oprsrtImm 6 bits 5 bits 5 bits 16 bits lw rt, index(rs)

12 Implementing Branches ALU Write Data Registers Read Reg. 1 RegWrite zero Read Reg. 2 Write Reg. Read Data 1 Read Data 2 Sign Extend 32 Instruction rs rt 16 Immediate ALU Control Add Shift left 2 PC+4 Branch Target Address To Branch Control Logic oprsrtImm 6 bits 5 bits 5 bits 16 bits beq rs, rt, Label

13 Building the Datapath Idea: Use multiplexors to stitch them together rs rt Imm rd

14 Implementing Jump opAddress 6 bits 26 bits j Label ALU Write Data Registers Read Reg. 1 RegWrite Read Reg. 2 Write Reg. Read Data 1 Read Data 2 Instruction rs rt ALU Control Shift left 2 PC+4 [31 : 28] Jump Target Address [27 : 0] 26

15 Complete Datapath with Control

16 Control Control Signals Selecting the operations to perform Controlling the flow of data (via MUX) Read/write enable inputs of memory and register file Information comes from the instruction Example: add $t0, $s0, $s1 op 00000010000100010100000000100000 rs rt rd shamt funct ALU operation is based on instruction type and function code

17 ALU Control Example: lw $t0, 100($s2) What should the ALU do with this instruction? ALU Control linesFunction 0000AND 0001OR 0010add 0110subtract 0111set on less than 1100NOR op 10010110010010000000000001100100 rs rt address

18 ALU Control Unit ALU performs addition for loads and stores subtraction for branches (beq) no operation for jumps or the operation is determined by the function field for R-type instructions. ALU Control unit will have the following inputs: 2-bit control field called ALUOp 6-bit function field

19 ALU Control Unit Instruction opcode Instruction operation ALUopFunct field Desired ALU action ALU Control lw Load word00xxxxxxadd0010 sw Store word00xxxxxxadd0010 beq Branch equal01xxxxxxsubtract0110 R-typeAdd10100000add0010 R-typeSubtract10100010subtract0110 R-typeAND10100100and0000 R-typeOR10100101or0001 R-typeslt10101010slt0111

20 Main Control Unit 0rsrtrdshamtfunct 31-26 25-21 20-16 15-1110-6 5-0 rsrtImm 31-26 25-21 20-1615-0 2address 35 or 43 31-2625-0 rsrtImm 31-26 25-21 20-1615-0 4 R-type Load or store jump branch Fields of Different Instruction Classes:

21 Datapath with Control Signals

22 Seven Control Signals Signal nameEffect when de- asserted Effect when asserted RegDst The destination register number comes from rt. The destination register number comes from rd. RegWrite NoneDestination register is written with value on Writedata ALUSrc 2 nd ALU operand comes from Read_Data_2 2 nd ALU operand is the sign extended, lower 16 bit of the instruction PCSrc The PC is replaced by PC + 4 The PC is replaced by the branch target address MemRead NoneMemory is read MemWrite NoneMemory is written MemtoReg The value to the register Writedata input comes from the ALU. The value to the register Writedata input comes from the data memory

23 RegDst & RegWrite read register #1 read register #2 write register write data Register file read #1 Write read #1 RegWrite RegDst 0 1 rt: Ins[20-16] rd: Ins[15-11] load R-type

24 ALUSrc read register #1 read register #2 write register write data Register file read #1 RegWrite ALUSrc 0 1 sign extend Imm: Ins[15-0] 3216 result Zero ALU

25 MemtoReg Address write data Data Memory read data MemtoReg 1 0 Zero To the write data input of Register File From the read data 2 output of Register File

26 PCSrc Add PCSrc 0 1 PC Shift left by 2 Imm: Ins[15-0] 32 sign extend Add 4 zero branch

27 Datapath & Control

28 Operation of the Datapath 101000X0Xbeq 000100X1Xsw 000011110lw 010001001R-format ALU Op0 ALU Op1 BranchMem Write Mem Read Reg Write Memto -Reg ALUSrcRegDestInstruction Example Flow: beq $s0, $s1, address The instruction is fetched from memory and PC is incremented Read two register values Subtract one from the other, calculate the branch address Use the zero signal to determine which of the addresses is to be used for fetching the next instruction

29 Control Function Input or output Signal nameR-formatlwswbeq Inputs Op5 0110 Op4 0000 Op3 0010 Op2 0001 Op1 0110 Op0 0110 Outputs RegDst 10xx ALUSrc 0110 MemtoReg 01xx RegWrite 1100 MemRead 0100 MemWrite 0010 Branch 0001 ALUOp1 1000 ALIOp0 0001

30 Cycle Time The control logic is combinational every instruction is executed in one clock cycle Cycle time determined by length of the longest path state element 1 state element 2 Combinational Logic

31 Single Cycle Approach Different instructions have different execution times Add: 3 ns Subtract: 3.5 ns Memory access: 10 ns Multiplication: 20 ns In single cycle approach, the slowest instruction determines the clock cycle time. Another approach, divide instruction into smaller parts and execute each in a shorter clock cycle

32 Instruction in Datapath

33 Instruction Timings Instruction class Functional Units used by the instruction class R-typeInstruction fetch Register access ALURegister access Load wordInstruction fetch Register access ALUMemory access Register access Store wordInstruction fetch Register access ALUMemory access BranchInstruction fetch Register access ALU JumpInstruction fetch

34 Example Memory access: 200 ps ALU and addition operations: 100 ps Register file access (read or write): 50 ps And assume other parts (multiplexors, control units, etc) have no delay. Instruction mix: 25% loads, 10% stores, 45% ALU ops, 15% branches, 5% jumps Compare two approaches: single fixed clock cycle and multiple clock cycle per instruction, i.e. what is the clock period per instruction and CPI for a fixed cycle what is the nominal clock period and CPI for the multiple cycle approach Execution times?


Download ppt "The Processor: Datapath & Control. Implementing Instructions Simplified instruction set memory-reference instructions: lw, sw arithmetic-logical instructions:"

Similar presentations


Ads by Google