18 447 Computer Architecture Lecture 6 MultiCycle and

  • Slides: 81
Download presentation
18 -447 Computer Architecture Lecture 6: Multi-Cycle and Microprogrammed Microarchitectures Prof. Onur Mutlu Carnegie

18 -447 Computer Architecture Lecture 6: Multi-Cycle and Microprogrammed Microarchitectures Prof. Onur Mutlu Carnegie Mellon University Spring 2015, 1/28/2015

Agenda for Today & Next Few Lectures n Single-cycle Microarchitectures n Multi-cycle and Microprogrammed

Agenda for Today & Next Few Lectures n Single-cycle Microarchitectures n Multi-cycle and Microprogrammed Microarchitectures n Pipelining n Issues in Pipelining: Control & Data Dependence Handling, State Maintenance and Recovery, … n Out-of-Order Execution n Issues in Oo. O Execution: Load-Store Handling, … 2

Reminder on Assignments n Lab 2 due next Friday (Feb 6) q Start early!

Reminder on Assignments n Lab 2 due next Friday (Feb 6) q Start early! n HW 1 due today HW 2 out n Remember that all is for your benefit n q q Homeworks, especially so All assignments can take time, but the goal is for you to learn very well 3

Number of Students Lab 1 Grades 25 20 15 10 5 0 30 n

Number of Students Lab 1 Grades 25 20 15 10 5 0 30 n n n 40 50 60 70 80 90 100 Mean: 88. 0 Median: 96. 0 Standard Deviation: 16. 9 4

Extra Credit for Lab Assignment 2 n n n Complete your normal (single-cycle) implementation

Extra Credit for Lab Assignment 2 n n n Complete your normal (single-cycle) implementation first, and get it checked off in lab. Then, implement the MIPS core using a microcoded approach similar to what we will discuss in class. We are not specifying any particular details of the microcode format or the microarchitecture; you can be creative. For the extra credit, the microcoded implementation should execute the same programs that your ordinary implementation does, and you should demo it by the normal lab deadline. You will get maximum 4% of course grade Document what you have done and demonstrate well 5

Readings for Today n P&P, Revised Appendix C q q n P&H, Appendix D

Readings for Today n P&P, Revised Appendix C q q n P&H, Appendix D q n Microarchitecture of the LC-3 b Appendix A (LC-3 b ISA) will be useful in following this Mapping Control to Hardware Optional q Maurice Wilkes, “The Best Way to Design an Automatic Calculating Machine, ” Manchester Univ. Computer Inaugural Conf. , 1951. 6

Readings for Next Lecture n Pipelining q n P&H Chapter 4. 5 -4. 8

Readings for Next Lecture n Pipelining q n P&H Chapter 4. 5 -4. 8 Pipelined LC-3 b Microarchitecture q http: //www. ece. cmu. edu/~ece 447/s 14/lib/exe/fetch. php? medi a=18447 -lc 3 b-pipelining. pdf 7

Recap of Last Lecture n Intro to Microarchitecture: Single-cycle Microarchitectures q q q n

Recap of Last Lecture n Intro to Microarchitecture: Single-cycle Microarchitectures q q q n Detailed walkthrough of a single-cycle MIPS implementation q q q n Single-cycle vs. multi-cycle Instruction processing “cycle” Datapath vs. control logic Hardwired vs. microprogrammed control Performance analysis: Execution time equation Power analysis: Dynamic power equation Datapath Control logic Critical path analysis (Micro)architecture design principles 8

Review: A Key System Design Principle n Keep it simple n “Everything should be

Review: A Key System Design Principle n Keep it simple n “Everything should be made as simple as possible, but no simpler. ” q n n Albert Einstein And, keep it low cost: “An engineer is a person who can do for a dime what any fool can do for a dollar. ” For more, see: q q Butler W. Lampson, “Hints for Computer System Design, ” ACM Operating Systems Review, 1983. http: //research. microsoft. com/pubs/68221/acrobat. pdf 9

Review: (Micro)architecture Design Principles n Critical path design q q n Find and decrease

Review: (Micro)architecture Design Principles n Critical path design q q n Find and decrease the maximum combinational logic delay Break a path into multiple cycles if it takes too long Bread and butter (common case) design q Spend time and resources on where it matters most n q n i. e. , improve what the machine is really designed to do Common case vs. uncommon case Balanced design q q Balance instruction/data flow through hardware components Design to eliminate bottlenecks: balance the hardware for the work 10

Review: Single-Cycle Design vs. Design Principles n Critical path design n Bread and butter

Review: Single-Cycle Design vs. Design Principles n Critical path design n Bread and butter (common case) design n Balanced design How does a single-cycle microarchitecture fare in light of these principles? 11

Multi-Cycle Microarchitectures 12

Multi-Cycle Microarchitectures 12

Multi-Cycle Microarchitectures n n Goal: Let each instruction take (close to) only as much

Multi-Cycle Microarchitectures n n Goal: Let each instruction take (close to) only as much time it really needs Idea q q Determine clock cycle time independently of instruction processing time Each instruction takes as many clock cycles as it needs to take n n Multiple state transitions per instruction The states followed by each instruction is different 13

Remember: The “Process instruction” n ISA specifies abstractly what AS’ should be, given an

Remember: The “Process instruction” n ISA specifies abstractly what AS’ should be, given an Step instruction and AS q It defines an abstract finite state machine where n n q From ISA point of view, there are no “intermediate states” between AS and AS’ during instruction execution n n State = programmer-visible state Next-state logic = instruction execution specification One state transition per instruction Microarchitecture implements how AS is transformed to AS’ q q There are many choices in implementation We can have programmer-invisible state to optimize the speed of instruction execution: multiple state transitions per instruction n n Choice 1: AS AS’ (transform AS to AS’ in a single clock cycle) Choice 2: AS AS+MS 1 AS+MS 2 AS+MS 3 AS’ (take multiple clock cycles to transform AS to AS’) 14

Multi-Cycle Microarchitecture AS = Architectural (programmer visible) state at the beginning of an instruction

Multi-Cycle Microarchitecture AS = Architectural (programmer visible) state at the beginning of an instruction Step 1: Process part of instruction in one clock cycle Step 2: Process part of instruction in the next clock cycle … AS’ = Architectural (programmer visible) state at the end of a clock cycle 15

Benefits of Multi-Cycle Design n Critical path design q n Bread and butter (common

Benefits of Multi-Cycle Design n Critical path design q n Bread and butter (common case) design q n Can keep reducing the critical path independently of the worstcase processing time of any instruction Can optimize the number of states it takes to execute “important” instructions that make up much of the execution time Balanced design q No need to provide more capability or resources than really needed n n An instruction that needs resource X multiple times does not require multiple X’s to be implemented Leads to more efficient hardware: Can reuse hardware components needed multiple times for an instruction 16

Remember: Performance Analysis n Execution time of an instruction q n Execution time of

Remember: Performance Analysis n Execution time of an instruction q n Execution time of a program q q n Sum over all instructions [{CPI} x {clock cycle time}] {# of instructions} x {Average CPI} x {clock cycle time} Single cycle microarchitecture performance q q n {CPI} x {clock cycle time} CPI = 1 Clock cycle time = long Multi-cycle microarchitecture performance q CPI = different for each instruction n q Average CPI hopefully small Clock cycle time = short Now, we have two degrees of freedom to optimize independently 17

A Multi-Cycle Microarchitecture A Closer Look 18

A Multi-Cycle Microarchitecture A Closer Look 18

How Do We Implement This? n n Maurice Wilkes, “The Best Way to Design

How Do We Implement This? n n Maurice Wilkes, “The Best Way to Design an Automatic Calculating Machine, ” Manchester Univ. Computer Inaugural Conf. , 1951. The concept of microcoded/microprogrammed machines 19

Microprogrammed Multi-Cycle u. Arch n Key Idea for Realization q q q One can

Microprogrammed Multi-Cycle u. Arch n Key Idea for Realization q q q One can implement the “process instruction” step as a finite state machine that sequences between states and eventually returns back to the “fetch instruction” state A state is defined by the control signals asserted in it Control signals for the next state determined in current state 20

The Instruction Processing Cycle q q q Fetch Decode Evaluate Address Fetch Operands Execute

The Instruction Processing Cycle q q q Fetch Decode Evaluate Address Fetch Operands Execute Store Result 21

A Basic Multi-Cycle Microarchitecture n Instruction processing cycle divided into “states” n n A

A Basic Multi-Cycle Microarchitecture n Instruction processing cycle divided into “states” n n A stage in the instruction processing cycle can take multiple states A multi-cycle microarchitecture sequences from state to process an instruction n The behavior of the machine in a state is completely determined by control signals in that state n The behavior of the entire processor is specified fully by a n In a state (clock cycle), control signals control two things: finite state machine n n How the datapath should process the data How to generate the control signals for the next clock cycle 22

Microprogrammed Control Terminology n Control signals associated with the current state q n Act

Microprogrammed Control Terminology n Control signals associated with the current state q n Act of transitioning from one state to another q q n Determining the next state and the microinstruction for the next state Microsequencing Control stores control signals for every possible state q n Microinstruction Store for microinstructions for the entire FSM Microsequencer determines which set of control signals will be used in the next clock cycle (i. e. , next state) 23

What Happens In A Clock Cycle? n The control signals (microinstruction) for the current

What Happens In A Clock Cycle? n The control signals (microinstruction) for the current state control two things: q Processing in the data path Generation of control signals (microinstruction) for the next cycle q See Supplemental Figure 1 (next slide) q n n Datapath and microsequencer operate concurrently Question: why not generate control signals for the current cycle in the current cycle? q This will lengthen the clock cycle Why would it lengthen the clock cycle? q See Supplemental Figure 2 q 24

A Clock Cycle 25

A Clock Cycle 25

A Bad Clock Cycle! 26

A Bad Clock Cycle! 26

A Simple LC-3 b Control and Datapath Read Appendix C under Technical Docs 27

A Simple LC-3 b Control and Datapath Read Appendix C under Technical Docs 27

What Determines Next-State Control Signals? n What is happening in the current clock cycle

What Determines Next-State Control Signals? n What is happening in the current clock cycle q See the 9 control signals coming from “Control” block n n The instruction that is being executed q n IR[15: 11] coming from the Data Path Whether the condition of a branch is met, if the instruction being processed is a branch q n What are these for? BEN bit coming from the datapath Whether the memory operation is completing in the current cycle, if one is in progress q R bit coming from memory 28

A Simple LC-3 b Control and Datapath 29

A Simple LC-3 b Control and Datapath 29

The State Machine for Multi-Cycle Processing n The behavior of the LC-3 b uarch

The State Machine for Multi-Cycle Processing n The behavior of the LC-3 b uarch is completely determined by q q n n the 35 control signals and additional 7 bits that go into the control logic from the datapath 35 control signals completely describe the state of the control structure We can completely describe the behavior of the LC-3 b as a state machine, i. e. a directed graph of q q Nodes (one corresponding to each state) Arcs (showing flow from each state to the next state(s)) 30

An LC-3 b State Machine n n n Patt and Patel, Appendix C, Figure

An LC-3 b State Machine n n n Patt and Patel, Appendix C, Figure C. 2 Each state must be uniquely specified q Done by means of state variables 31 distinct states in this LC-3 b state machine q n Encoded with 6 state variables Examples q q q State 18, 19 correspond to the beginning of the instruction processing cycle Fetch phase: state 18, 19 state 33 state 35 Decode phase: state 32 31

LC-3 b State Machine: Some Questions n How many cycles does the fastest instruction

LC-3 b State Machine: Some Questions n How many cycles does the fastest instruction take? n How many cycles does the slowest instruction take? n Why does the BR take as long as it takes in the FSM? n What determines the clock cycle time? 33

LC-3 b Datapath n Patt and Patel, Appendix C, Figure C. 3 n Single-bus

LC-3 b Datapath n Patt and Patel, Appendix C, Figure C. 3 n Single-bus datapath design q q q n At any point only one value can be “gated” on the bus (i. e. , can be driving the bus) Advantage: Low hardware cost: one bus Disadvantage: Reduced concurrency – if instruction needs the bus twice for two different things, these need to happen in different states Control signals (26 of them) determine what happens in the datapath in one clock cycle q Patt and Patel, Appendix C, Table C. 1 34

Remember the MIPS datapath

Remember the MIPS datapath

LC-3 b Datapath: Some Questions n How does instruction fetch happen in this datapath

LC-3 b Datapath: Some Questions n How does instruction fetch happen in this datapath according to the state machine? n What is the difference between gating and loading? n Is this the smallest hardware you can design? 38

LC-3 b Microprogrammed Control Structure n Patt and Patel, Appendix C, Figure C. 4

LC-3 b Microprogrammed Control Structure n Patt and Patel, Appendix C, Figure C. 4 n Three components: q n n n Microinstruction: control signals that control the datapath (26 of them) and help determine the next state (9 of them) Each microinstruction is stored in a unique location in the control store (a special memory structure) Unique location: address of the state corresponding to the microinstruction q n Microinstruction, control store, microsequencer Remember each state corresponds to one microinstruction Microsequencer determines the address of the next microinstruction (i. e. , next state) 39

LC-3 b Microsequencer n n n Patt and Patel, Appendix C, Figure C. 5

LC-3 b Microsequencer n n n Patt and Patel, Appendix C, Figure C. 5 The purpose of the microsequencer is to determine the address of the next microinstruction (i. e. , next state) Next address depends on 9 control signals (plus 7 data signals) 43

The Microsequencer: Some Questions n When is the IRD signal asserted? n What happens

The Microsequencer: Some Questions n When is the IRD signal asserted? n What happens if an illegal instruction is decoded? n What are condition (COND) bits for? n How is variable latency memory handled? n How do you do the state encoding? q q q Minimize number of state variables (~ control store size) Start with the 16 -way branch Then determine constraint tables and states dependent on COND 45

An Exercise in Microprogramming 46

An Exercise in Microprogramming 46

Handouts n n n 7 pages of Microprogrammed LC-3 b design http: //www. ece.

Handouts n n n 7 pages of Microprogrammed LC-3 b design http: //www. ece. cmu. edu/~ece 447/s 14/doku. php? id=techd ocs http: //www. ece. cmu. edu/~ece 447/s 14/lib/exe/fetch. php? m edia=lc 3 b-figures. pdf 47

A Simple LC-3 b Control and Datapath 48

A Simple LC-3 b Control and Datapath 48

State Machine for LDW State 18 (010010) State 33 (100001) State 35 (100011) State

State Machine for LDW State 18 (010010) State 33 (100001) State 35 (100011) State 32 (100000) State 6 (000110) State 25 (011001) State 27 (011011) Microsequencer

End of the Exercise in Microprogramming 57

End of the Exercise in Microprogramming 57

Homework 2 n You will write the microcode for some states in LC-3 b

Homework 2 n You will write the microcode for some states in LC-3 b as specified in Appendix C 58

Lab 2 Extra Credit n Microprogrammed MIPS implementation n Exercise your creativity! 59

Lab 2 Extra Credit n Microprogrammed MIPS implementation n Exercise your creativity! 59

The Control Store: Some Questions n What control signals can be stored in the

The Control Store: Some Questions n What control signals can be stored in the control store? vs. n What control signals have to be generated in hardwired logic? q n i. e. , what signal cannot be available without processing in the datapath? Remember the MIPS datapath q One PCSrc signal depends on processing that happens in the datapath (bcond logic) 60

Variable-Latency Memory n The ready signal (R) enables memory read/write to execute correctly q

Variable-Latency Memory n The ready signal (R) enables memory read/write to execute correctly q n Example: transition from state 33 to state 35 is controlled by the R bit asserted by memory when memory data is available Could we have done this in a single-cycle microarchitecture? 61

The Microsequencer: Advanced Questions n What happens if the machine is interrupted? n n

The Microsequencer: Advanced Questions n What happens if the machine is interrupted? n n What if an instruction generates an exception? How can you implement a complex instruction using this control structure? q Think REP MOVS 62

The Power of Abstraction n The concept of a control store of microinstructions enables

The Power of Abstraction n The concept of a control store of microinstructions enables the hardware designer with a new abstraction: microprogramming The designer can translate any desired operation to a sequence of microinstructions All the designer needs to provide is q q q The sequence of microinstructions needed to implement the desired operation The ability for the control logic to correctly sequence through the microinstructions Any additional datapath control signals needed (no need if the operation can be “translated” into existing control signals) 63

Let’s Do Some More Microprogramming n Implement REP MOVS in the LC-3 b microarchitecture

Let’s Do Some More Microprogramming n Implement REP MOVS in the LC-3 b microarchitecture n What changes, if any, do you make to the q q n n state machine? datapath? control store? microsequencer? Show all changes and microinstructions Coming up in Homework 2 64

Aside: Alignment Correction in Memory n Remember unaligned accesses n LC-3 b has byte

Aside: Alignment Correction in Memory n Remember unaligned accesses n LC-3 b has byte load and byte store instructions that move data not aligned at the word-address boundary q n Convenience to the programmer/compiler How does the hardware ensure this works correctly? q q q Take a look at state 29 for LDB States 24 and 17 for STB Additional logic to handle unaligned accesses 65

Aside: Memory Mapped I/O n n n Address control logic determines whether the specified

Aside: Memory Mapped I/O n n n Address control logic determines whether the specified address of LDx and STx are to memory or I/O devices Correspondingly enables memory or I/O devices and sets up muxes Another instance where the final control signals (e. g. , MEM. EN or INMUX/2) cannot be stored in the control store q These signals are dependent on address 66

Advantages of Microprogrammed Control n Allows a very simple design to do powerful computation

Advantages of Microprogrammed Control n Allows a very simple design to do powerful computation by controlling the datapath (using a sequencer) q q q n Enables easy extensibility of the ISA q q n High-level ISA translated into microcode (sequence of microinstructions) Microcode (ucode) enables a minimal datapath to emulate an ISA Microinstructions can be thought of as a user-invisible ISA (micro ISA) Can support a new instruction by changing the microcode Can support complex instructions as a sequence of simple microinstructions If I can sequence an arbitrary instruction then I can sequence an arbitrary “program” as a microprogram sequence q will need some new state (e. g. loop counters) in the microcode for sequencing more elaborate programs 67

Update of Machine Behavior n The ability to update/patch microcode in the field (after

Update of Machine Behavior n The ability to update/patch microcode in the field (after a processor is shipped) enables q q n Ability to add new instructions without changing the processor! Ability to “fix” buggy hardware implementations Examples q q IBM 370 Model 145: microcode stored in main memory, can be updated after a reboot IBM System z: Similar to 370/145. n q Heller and Farrell, “Millicode in an IBM z. Series processor, ” IBM JR&D, May/Jul 2004. B 1700 microcode can be updated while the processor is running n User-microprogrammable machine! 68

We did not cover the following slides in lecture. These are for your preparation

We did not cover the following slides in lecture. These are for your preparation for the next lecture.

n-bit m. PC input [Based on original figure from P&H CO&D, COPYRIGHT 2004 Elsevier.

n-bit m. PC input [Based on original figure from P&H CO&D, COPYRIGHT 2004 Elsevier. ALL RIGHTS RESERVED. ] ALUSrc. A Ior. D IRWrite PCWrite. Cond …. Control Store: 2 n k bit (not including sequencing) k-bit “control” output Horizontal Microcode 70

Vertical Microcode 1 -bit signal means do this RT (or combination of RTs) n-bit

Vertical Microcode 1 -bit signal means do this RT (or combination of RTs) n-bit m. PC input “PC PC+4” “PC ALUOut” “PC PC[ 31: 28 ], IR[ 25: 0 ], 2’b 00” “IR MEM[ PC ]” “A RF[ IR[ 25: 21 ] ]” “B RF[ IR[ 20: 16 ] ]” ……. …………. m-bit input ROM k-bit output ALUSrc. A Ior. D IRWrite PCWrite. Cond …. [Based on original figure from P&H CO&D, COPYRIGHT 2004 Elsevier. ALL RIGHTS RESERVED. ] If done right (i. e. , m<<n, and m<<k), two ROMs together (2 n m+2 m k bit) should be smaller than horizontal microcode ROM (2 n k bit) 71

Nanocode and Millicode n Nanocode: a level below traditional mcode q n Millicode: a

Nanocode and Millicode n Nanocode: a level below traditional mcode q n Millicode: a level above traditional mcode q q n n mprogrammed control for sub-systems (e. g. , a complicated floatingpoint module) that acts as a slave in a mcontrolled datapath ISA-level subroutines that can be called by the mcontroller to handle complicated operations and system functions E. g. , Heller and Farrell, “Millicode in an IBM z. Series processor, ” IBM JR&D, May/Jul 2004. In both cases, we avoid complicating the main mcontroller You can think of these as “microcode” at different levels of abstraction 72

Nanocode Concept Illustrated a “mcoded” processor implementation ROM m. PC processor datapath We refer

Nanocode Concept Illustrated a “mcoded” processor implementation ROM m. PC processor datapath We refer to this as “nanocode” when a mcoded subsystem is embedded in a mcoded system a “mcoded” FPU implementation ROM m. PC arithmetic datapath 73

Microcoded Multi-Cycle MIPS Design n P&H, Appendix D n Any ISA can be implemented

Microcoded Multi-Cycle MIPS Design n P&H, Appendix D n Any ISA can be implemented this way n n We will not cover this in class However, you can do an extra credit assignment for Lab 2 74

Microcoded Multi-Cycle MIPS Design [Based on original figure from P&H CO&D, COPYRIGHT 2004 Elsevier.

Microcoded Multi-Cycle MIPS Design [Based on original figure from P&H CO&D, COPYRIGHT 2004 Elsevier. ALL RIGHTS RESERVED. ] 75

Control Logic for MIPS FSM [Based on original figure from P&H CO&D, COPYRIGHT 2004

Control Logic for MIPS FSM [Based on original figure from P&H CO&D, COPYRIGHT 2004 Elsevier. ALL RIGHTS RESERVED. ] 76

Microprogrammed Control for MIPS FSM [Based on original figure from P&H CO&D, COPYRIGHT 2004

Microprogrammed Control for MIPS FSM [Based on original figure from P&H CO&D, COPYRIGHT 2004 Elsevier. ALL RIGHTS RESERVED. ] 77

Multi-Cycle vs. Single-Cycle u. Arch n Advantages n Disadvantages n You should be very

Multi-Cycle vs. Single-Cycle u. Arch n Advantages n Disadvantages n You should be very familiar with this right now 78

Microprogrammed vs. Hardwired Control n Advantages n Disadvantages n You should be very familiar

Microprogrammed vs. Hardwired Control n Advantages n Disadvantages n You should be very familiar with this right now 79

Can We Do Better? n What limitations do you see with the multi-cycle design?

Can We Do Better? n What limitations do you see with the multi-cycle design? n Limited concurrency q q q Some hardware resources are idle during different phases of instruction processing cycle “Fetch” logic is idle when an instruction is being “decoded” or “executed” Most of the datapath is idle when a memory access is happening 80

Can We Use the Idle Hardware to Improve Concurrency? n n Goal: Concurrency throughput

Can We Use the Idle Hardware to Improve Concurrency? n n Goal: Concurrency throughput (more “work” completed in one cycle) Idea: When an instruction is using some resources in its processing phase, process other instructions on idle resources not needed by that instruction q q E. g. , when an instruction is being decoded, fetch the next instruction E. g. , when an instruction is being executed, decode another instruction E. g. , when an instruction is accessing data memory (ld/st), execute the next instruction E. g. , when an instruction is writing its result into the register file, access data memory for the next instruction 81