18-447 computer architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... ·...

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

Upload: others

Post on 20-Oct-2019

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

18-447 Computer Architecture

Lecture 6: Multi-Cycle and Microprogrammed Microarchitectures

Prof. Onur Mutlu Carnegie Mellon University Spring 2015, 1/28/2015

Page 2: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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 OoO Execution: Load-Store Handling, …

2

Page 3: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Reminder on Assignments n  Lab 2 due next Friday (Feb 6)

q  Start early!

n  HW 1 due today n  HW 2 out

n  Remember that all is for your benefit q  Homeworks, especially so q  All assignments can take time, but the goal is for you to learn

very well

3

Page 4: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Lab 1 Grades

n  Mean: 88.0 n  Median: 96.0 n  Standard Deviation: 16.9

4

0  

5  

10  

15  

20  

25  

30   40   50   60   70   80   90   100  

Num

ber  o

f  Stude

nts  

Page 5: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Extra Credit for Lab Assignment 2

n  Complete your normal (single-cycle) implementation first, and get it checked off in lab.

n  Then, implement the MIPS core using a microcoded approach similar to what we will discuss in class.

n  We are not specifying any particular details of the microcode format or the microarchitecture; you can be creative.

n  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.

n  You will get maximum 4% of course grade n  Document what you have done and demonstrate well

5

Page 6: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Readings for Today n  P&P, Revised Appendix C

q  Microarchitecture of the LC-3b q  Appendix A (LC-3b ISA) will be useful in following this

n  P&H, Appendix D q  Mapping Control to Hardware

n  Optional q  Maurice Wilkes, “The Best Way to Design an Automatic

Calculating Machine,” Manchester Univ. Computer Inaugural Conf., 1951.

6

Page 7: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Readings for Next Lecture n  Pipelining

q  P&H Chapter 4.5-4.8

n  Pipelined LC-3b Microarchitecture q  http://www.ece.cmu.edu/~ece447/s14/lib/exe/fetch.php?

media=18447-lc3b-pipelining.pdf

7

Page 8: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

q  Single-cycle vs. multi-cycle q  Instruction processing “cycle” q  Datapath vs. control logic q  Hardwired vs. microprogrammed control q  Performance analysis: Execution time equation q  Power analysis: Dynamic power equation

n  Detailed walkthrough of a single-cycle MIPS implementation q  Datapath q  Control logic q  Critical path analysis

n  (Micro)architecture design principles

8

Page 9: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Review: A Key System Design Principle n  Keep it simple

n  “Everything should be made as simple as possible, but no simpler.” q  Albert Einstein

n  And, keep it low cost: “An engineer is a person who can do for a dime what any fool can do for a dollar.”

n  For more, see: q  Butler W. Lampson, “Hints for Computer System Design,” ACM

Operating Systems Review, 1983. q  http://research.microsoft.com/pubs/68221/acrobat.pdf

9

Page 10: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Review: (Micro)architecture Design Principles

n  Critical path design q  Find and decrease the maximum combinational logic delay q  Break a path into multiple cycles if it takes too long

n  Bread and butter (common case) design q  Spend time and resources on where it matters most

n  i.e., improve what the machine is really designed to do

q  Common case vs. uncommon case

n  Balanced design q  Balance instruction/data flow through hardware components q  Design to eliminate bottlenecks: balance the hardware for the

work

10

Page 11: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

Page 12: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Multi-Cycle Microarchitectures

12

Page 13: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

it really needs

n  Idea q  Determine clock cycle time independently of instruction

processing time q  Each instruction takes as many clock cycles as it needs to take

n  Multiple state transitions per instruction n  The states followed by each instruction is different

13

Page 14: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

instruction and AS q  It defines an abstract finite state machine where

n  State = programmer-visible state n  Next-state logic = instruction execution specification

q  From ISA point of view, there are no “intermediate states” between AS and AS’ during instruction execution n  One state transition per instruction

n  Microarchitecture implements how AS is transformed to AS’ q  There are many choices in implementation q  We can have programmer-invisible state to optimize the speed of

instruction execution: multiple state transitions per instruction n  Choice 1: AS à AS’ (transform AS to AS’ in a single clock cycle) n  Choice 2: AS à AS+MS1 à AS+MS2 à AS+MS3 à AS’ (take multiple

clock cycles to transform AS to AS’) 14

Page 15: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

Page 16: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Benefits of Multi-Cycle Design n  Critical path design

q  Can keep reducing the critical path independently of the worst-case processing time of any instruction

n  Bread and butter (common case) design q  Can optimize the number of states it takes to execute “important”

instructions that make up much of the execution time

n  Balanced design q  No need to provide more capability or resources than really

needed n  An instruction that needs resource X multiple times does not require

multiple X’s to be implemented n  Leads to more efficient hardware: Can reuse hardware components

needed multiple times for an instruction

16

Page 17: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Remember: Performance Analysis n  Execution time of an instruction

q  {CPI} x {clock cycle time}

n  Execution time of a program q  Sum over all instructions [{CPI} x {clock cycle time}] q  {# of instructions} x {Average CPI} x {clock cycle time}

n  Single cycle microarchitecture performance q  CPI = 1 q  Clock cycle time = long

n  Multi-cycle microarchitecture performance q  CPI = different for each instruction

n  Average CPI à hopefully small

q  Clock cycle time = short 17

Now, we have two degrees of freedom to optimize independently

Page 18: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

A Multi-Cycle Microarchitecture A Closer Look

18

Page 19: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

Calculating Machine,” Manchester Univ. Computer Inaugural Conf., 1951.

n  The concept of microcoded/microprogrammed machines

19

Page 20: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Microprogrammed Multi-Cycle uArch n  Key Idea for Realization

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

q  A state is defined by the control signals asserted in it

q  Control signals for the next state determined in current state

20

Page 21: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

The Instruction Processing Cycle

q  Fetch q  Decode q  Evaluate Address q  Fetch Operands q  Execute q  Store Result

21

Page 22: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

n  A stage in the instruction processing cycle can take multiple states

n  A multi-cycle microarchitecture sequences from state to 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 finite state machine

n  In a state (clock cycle), control signals control two things: n  How the datapath should process the data n  How to generate the control signals for the next clock cycle

22

Page 23: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Microprogrammed Control Terminology n  Control signals associated with the current state

q  Microinstruction

n  Act of transitioning from one state to another q  Determining the next state and the microinstruction for the

next state q  Microsequencing

n  Control store stores control signals for every possible state q  Store for microinstructions for the entire FSM

n  Microsequencer determines which set of control signals will be used in the next clock cycle (i.e., next state)

23

Page 24: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

control two things: q  Processing in the data path q  Generation of control signals (microinstruction) for the next

cycle q  See Supplemental Figure 1 (next slide)

n  Datapath and microsequencer operate concurrently

n  Question: why not generate control signals for the current cycle in the current cycle? q  This will lengthen the clock cycle q  Why would it lengthen the clock cycle? q  See Supplemental Figure 2

24

Page 25: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

A Clock Cycle

25

Page 26: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

A Bad Clock Cycle!

26

Page 27: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

A Simple LC-3b Control and Datapath

27

Read Appendix C under Technical Docs

Page 28: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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  What are these for?

n  The instruction that is being executed q  IR[15:11] coming from the Data Path

n  Whether the condition of a branch is met, if the instruction being processed is a branch q  BEN bit coming from the datapath

n  Whether the memory operation is completing in the current cycle, if one is in progress q  R bit coming from memory

28

Page 29: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

A Simple LC-3b Control and Datapath

29

Page 30: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

q  the 35 control signals and q  additional 7 bits that go into the control logic from the datapath

n  35 control signals completely describe the state of the control structure

n  We can completely describe the behavior of the LC-3b as a state machine, i.e. a directed graph of q  Nodes (one corresponding to each state) q  Arcs (showing flow from each state to the next state(s))

30

Page 31: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

n  Each state must be uniquely specified q  Done by means of state variables

n  31 distinct states in this LC-3b state machine q  Encoded with 6 state variables

n  Examples q  State 18,19 correspond to the beginning of the instruction

processing cycle q  Fetch phase: state 18, 19 à state 33 à state 35 q  Decode phase: state 32

31

Page 32: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

C.2. THE STATE MACHINE 5

R

PC<!BaseR

To 18

12

To 18

To 18

RR

To 18

To 18

To 18

MDR<!SR[7:0]

MDR <! M

IR <! MDR

R

DR<!SR1+OP2*set CC

DR<!SR1&OP2*set CC

[BEN]

PC<!MDR

32

1

5

0

0

1To 18

To 18 To 18

R R

[IR[15:12]]

28

30

R7<!PCMDR<!M[MAR]

set CC

BEN<!IR[11] & N + IR[10] & Z + IR[9] & P

9DR<!SR1 XOR OP2*

4

22

To 111011

JSRJMP

BR

1010

To 10

21

200 1

LDB

MAR<!B+off6

set CC

To 18

MAR<!B+off6

DR<!MDRset CC

To 18

MDR<!M[MAR]25

27

3762

STW STBLEASHF

TRAP

XOR

AND

ADD

RTI

To 8

set CC

set CCDR<!PC+LSHF(off9, 1)

14

LDW

MAR<!B+LSHF(off6,1) MAR<!B+LSHF(off6,1)

PC<!PC+LSHF(off9,1)

33

35

DR<!SHF(SR,A,D,amt4)

NOTESB+off6 : Base + SEXT[offset6]

R

MDR<!M[MAR[15:1]’0]

DR<!SEXT[BYTE.DATA]

R

29

31

18, 19

MDR<!SR

To 18

R R

M[MAR]<!MDR16

23

R R

17

To 19

24

M[MAR]<!MDR**

MAR<!LSHF(ZEXT[IR[7:0]],1)15To 18

PC+off9 : PC + SEXT[offset9]

MAR <! PCPC <! PC + 2

*OP2 may be SR2 or SEXT[imm5]** [15:8] or [7:0] depending on MAR[0]

[IR[11]]

PC<!BaseR

PC<!PC+LSHF(off11,1)

R7<!PC

R7<!PC

13

Figure C.2: A state machine for the LC-3b

Page 33: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

LC-3b 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

Page 34: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

n  Single-bus datapath design q  At any point only one value can be “gated” on the bus (i.e.,

can be driving the bus) q  Advantage: Low hardware cost: one bus q  Disadvantage: Reduced concurrency – if instruction needs the

bus twice for two different things, these need to happen in different states

n  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

Page 35: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

C.4. THE CONTROL STRUCTURE 7

MEMORY

OUTPUTINPUT

KBDR

ADDR. CTL.LOGIC

MDR

INMUX

MAR L

L

MAR[0]

MAR[0]

DATA.SIZE

R

DATA.SIZE

D

D

.

.

M

MDR

AR

2

KBSR

MEM.EN

R.W

MIO.EN

GatePCGateMARMUX

16

16 16

16

16 16 16

LD.CC

SR2MUX

SEXT

SEXT[8:0]

[10:0]

SEXT

SEXT[5:0]

16

+2

PCLD.PC

16

+

16

16

[7:0]

LSHF1

[4:0]

GateALU16

SHF

GateSHF

6IR[5:0]

16

1616

16

16

16

16

LOGIC

16 16

GateMDR

N Z P

SR2OUT

SR1OUT

REGFILE

MARMUX

16

3

0

16

R

ADDR2MUX

2

ZEXT &LSHF1

3

3

ALUALUK

2 AB

ADDR1MUX

PCMUX2

SR1

DR

SR2

LD.REG

IRLD.IR

CONTROL

DDR

DSR

MIO.EN

LOGIC

LOGIC

SIZEDATA.

WE0WE1

[0]WE

LOGIC

Figure C.3: The LC-3b data path

provide you with the additional flexibility of more states, so we have selected a controlstore consisting of 26 locations.

Page 36: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

C.4. THE CONTROL STRUCTURE 11

DR

IR[11:9]

111

DRMUX

(a)

SR1

SR1MUX

IR[11:9]

IR[8:6]

(b)

Logic BEN

PZN

IR[11:9]

(c)

Figure C.6: Additional logic required to provide control signals

LC-3b to operate correctly with a memory that takes multiple clock cycles to read orstore a value.

Suppose it takes memory five cycles to read a value. That is, once MAR containsthe address to be read and the microinstruction asserts READ, it will take five cyclesbefore the contents of the specified location in memory are available to be loaded intoMDR. (Note that the microinstruction asserts READ by means of three control signals:MIO.EN/YES, R.W/RD, and DATA.SIZE/WORD; see Figure C.3.)

Recall our discussion in Section C.2 of the function of state 33, which accessesan instruction from memory during the fetch phase of each instruction cycle. For theLC-3b to operate correctly, state 33 must execute five times before moving on to state35. That is, until MDR contains valid data from the memory location specified by thecontents of MAR, we want state 33 to continue to re-execute. After five clock cycles,the memory has completed the “read,” resulting in valid data in MDR, so the processorcan move on to state 35. What if the microarchitecture did not wait for the memory tocomplete the read operation before moving on to state 35? Since the contents of MDRwould still be garbage, the microarchitecture would put garbage into IR in state 35.

The ready signal (R) enables the memory read to execute correctly. Since the mem-ory knows it needs five clock cycles to complete the read, it asserts a ready signal(R) throughout the fifth clock cycle. Figure C.2 shows that the next state is 33 (i.e.,100001) if the memory read will not complete in the current clock cycle and state 35(i.e., 100011) if it will. As we have seen, it is the job of the microsequencer (FigureC.5) to produce the next state address.

Remember the MIPS datapath

Page 37: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified
Page 38: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

LC-3b 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

Page 39: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

LC-3b Microprogrammed Control Structure

n  Patt and Patel, Appendix C, Figure C.4

n  Three components: q  Microinstruction, control store, microsequencer

n  Microinstruction: control signals that control the datapath (26 of them) and help determine the next state (9 of them)

n  Each microinstruction is stored in a unique location in the control store (a special memory structure)

n  Unique location: address of the state corresponding to the microinstruction q  Remember each state corresponds to one microinstruction

n  Microsequencer determines the address of the next microinstruction (i.e., next state)

39

Page 40: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

C.4. THE CONTROL STRUCTURE 9

Microinstruction

R

Microsequencer

BEN

x2

Control Store6

IR[15:11]

6

(J, COND, IRD)

269

35

35

Figure C.4: The control structure of a microprogrammed implementation, overall blockdiagram

on the LC-3b instruction being executed during the current instruction cycle. This statecarries out the DECODE phase of the instruction cycle. If the IRD control signal in themicroinstruction corresponding to state 32 is 1, the output MUX of the microsequencer(Figure C.5) will take its source from the six bits formed by 00 concatenated with thefour opcode bits IR[15:12]. Since IR[15:12] specifies the opcode of the current LC-3b instruction being processed, the next address of the control store will be one of 16addresses, corresponding to the 14 opcodes plus the two unused opcodes, IR[15:12] =1010 and 1011. That is, each of the 16 next states is the first state to be carried outafter the instruction has been decoded in state 32. For example, if the instruction beingprocessed is ADD, the address of the next state is state 1, whose microinstruction isstored at location 000001. Recall that IR[15:12] for ADD is 0001.

If, somehow, the instruction inadvertently contained IR[15:12] = 1010 or 1011, the

Page 41: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

10APPENDIXC. THEMICROARCHITECTUREOFTHE LC-3B, BASICMACHINE

IRD

Address of Next State

6

6

0,0,IR[15:12]

J[5]

Branch ReadyModeAddr.

J[0]J[1]J[2]

COND0COND1

J[3]J[4]

R IR[11]BEN

Figure C.5: The microsequencer of the LC-3b base machine

unused opcodes, the microarchitecture would execute a sequence of microinstructions,starting at state 10 or state 11, depending on which illegal opcode was being decoded.In both cases, the sequence of microinstructions would respond to the fact that aninstruction with an illegal opcode had been fetched.

Several signals necessary to control the data path and the microsequencer are notamong those listed in Tables C.1 and C.2. They are DR, SR1, BEN, and R. Figure C.6shows the additional logic needed to generate DR, SR1, and BEN.

The remaining signal, R, is a signal generated by the memory in order to allow the

Page 42: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

14APPENDIXC. THEMICROARCHITECTUREOFTHE LC-3B, BASICMACHINE

J LD.PC

LD.BEN

LD.IR

LD.M

DR

LD.M

AR

LD.REG

LD.CC

Cond

IRD

GatePC

GateMDR

GateALU

GateMARMUX

GateSH

FPC

MUXDRMUXSR

1MUX

ADDR1MUX

ADDR2MUX

MARMUX

010000 (State 16)010001 (State 17)

010011 (State 19)010010 (State 18)

010100 (State 20)010101 (State 21)010110 (State 22)010111 (State 23)011000 (State 24)011001 (State 25)011010 (State 26)011011 (State 27)011100 (State 28)011101 (State 29)011110 (State 30)011111 (State 31)100000 (State 32)100001 (State 33)100010 (State 34)100011 (State 35)100100 (State 36)100101 (State 37)100110 (State 38)100111 (State 39)101000 (State 40)101001 (State 41)101010 (State 42)101011 (State 43)101100 (State 44)101101 (State 45)101110 (State 46)101111 (State 47)110000 (State 48)110001 (State 49)110010 (State 50)110011 (State 51)110100 (State 52)110101 (State 53)110110 (State 54)110111 (State 55)111000 (State 56)111001 (State 57)111010 (State 58)111011 (State 59)111100 (State 60)111101 (State 61)111110 (State 62)111111 (State 63)

001000 (State 8)001001 (State 9)001010 (State 10)001011 (State 11)001100 (State 12)001101 (State 13)001110 (State 14)001111 (State 15)

000000 (State 0)000001 (State 1)000010 (State 2)000011 (State 3)000100 (State 4)000101 (State 5)000110 (State 6)000111 (State 7)

ALUK

MIO.EN

R.W LSHF1

DATA.SI

ZE

Figure C.7: Specification of the control store

Page 43: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

LC-3b Microsequencer

n  Patt and Patel, Appendix C, Figure C.5

n  The purpose of the microsequencer is to determine the address of the next microinstruction (i.e., next state)

n  Next address depends on 9 control signals (plus 7 data signals)

43

Page 44: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

10APPENDIXC. THEMICROARCHITECTUREOFTHE LC-3B, BASICMACHINE

IRD

Address of Next State

6

6

0,0,IR[15:12]

J[5]

Branch ReadyModeAddr.

J[0]J[1]J[2]

COND0COND1

J[3]J[4]

R IR[11]BEN

Figure C.5: The microsequencer of the LC-3b base machine

unused opcodes, the microarchitecture would execute a sequence of microinstructions,starting at state 10 or state 11, depending on which illegal opcode was being decoded.In both cases, the sequence of microinstructions would respond to the fact that aninstruction with an illegal opcode had been fetched.

Several signals necessary to control the data path and the microsequencer are notamong those listed in Tables C.1 and C.2. They are DR, SR1, BEN, and R. Figure C.6shows the additional logic needed to generate DR, SR1, and BEN.

The remaining signal, R, is a signal generated by the memory in order to allow the

Page 45: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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  Minimize number of state variables (~ control store size) q  Start with the 16-way branch q  Then determine constraint tables and states dependent on COND

45

Page 46: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

An Exercise in Microprogramming

46

Page 47: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Handouts n  7 pages of Microprogrammed LC-3b design

n  http://www.ece.cmu.edu/~ece447/s14/doku.php?id=techdocs

n  http://www.ece.cmu.edu/~ece447/s14/lib/exe/fetch.php?media=lc3b-figures.pdf

47

Page 48: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

A Simple LC-3b Control and Datapath

48

Page 49: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

C.2. THE STATE MACHINE 5

R

PC<!BaseR

To 18

12

To 18

To 18

RR

To 18

To 18

To 18

MDR<!SR[7:0]

MDR <! M

IR <! MDR

R

DR<!SR1+OP2*set CC

DR<!SR1&OP2*set CC

[BEN]

PC<!MDR

32

1

5

0

0

1To 18

To 18 To 18

R R

[IR[15:12]]

28

30

R7<!PCMDR<!M[MAR]

set CC

BEN<!IR[11] & N + IR[10] & Z + IR[9] & P

9DR<!SR1 XOR OP2*

4

22

To 111011

JSRJMP

BR

1010

To 10

21

200 1

LDB

MAR<!B+off6

set CC

To 18

MAR<!B+off6

DR<!MDRset CC

To 18

MDR<!M[MAR]25

27

3762

STW STBLEASHF

TRAP

XOR

AND

ADD

RTI

To 8

set CC

set CCDR<!PC+LSHF(off9, 1)

14

LDW

MAR<!B+LSHF(off6,1) MAR<!B+LSHF(off6,1)

PC<!PC+LSHF(off9,1)

33

35

DR<!SHF(SR,A,D,amt4)

NOTESB+off6 : Base + SEXT[offset6]

R

MDR<!M[MAR[15:1]’0]

DR<!SEXT[BYTE.DATA]

R

29

31

18, 19

MDR<!SR

To 18

R R

M[MAR]<!MDR16

23

R R

17

To 19

24

M[MAR]<!MDR**

MAR<!LSHF(ZEXT[IR[7:0]],1)15To 18

PC+off9 : PC + SEXT[offset9]

MAR <! PCPC <! PC + 2

*OP2 may be SR2 or SEXT[imm5]** [15:8] or [7:0] depending on MAR[0]

[IR[11]]

PC<!BaseR

PC<!PC+LSHF(off11,1)

R7<!PC

R7<!PC

13

Figure C.2: A state machine for the LC-3b

Page 50: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

C.4. THE CONTROL STRUCTURE 7

MEMORY

OUTPUTINPUT

KBDR

ADDR. CTL.LOGIC

MDR

INMUX

MAR L

L

MAR[0]

MAR[0]

DATA.SIZE

R

DATA.SIZE

D

D

.

.

M

MDR

AR

2

KBSR

MEM.EN

R.W

MIO.EN

GatePCGateMARMUX

16

16 16

16

16 16 16

LD.CC

SR2MUX

SEXT

SEXT[8:0]

[10:0]

SEXT

SEXT[5:0]

16

+2

PCLD.PC

16

+

16

16

[7:0]

LSHF1

[4:0]

GateALU16

SHF

GateSHF

6IR[5:0]

16

1616

16

16

16

16

LOGIC

16 16

GateMDR

N Z P

SR2OUT

SR1OUT

REGFILE

MARMUX

16

3

0

16

R

ADDR2MUX

2

ZEXT &LSHF1

3

3

ALUALUK

2 AB

ADDR1MUX

PCMUX2

SR1

DR

SR2

LD.REG

IRLD.IR

CONTROL

DDR

DSR

MIO.EN

LOGIC

LOGIC

SIZEDATA.

WE0WE1

[0]WE

LOGIC

Figure C.3: The LC-3b data path

provide you with the additional flexibility of more states, so we have selected a controlstore consisting of 26 locations.

Page 51: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

10APPENDIXC. THEMICROARCHITECTUREOFTHE LC-3B, BASICMACHINE

IRD

Address of Next State

6

6

0,0,IR[15:12]

J[5]

Branch ReadyModeAddr.

J[0]J[1]J[2]

COND0COND1

J[3]J[4]

R IR[11]BEN

Figure C.5: The microsequencer of the LC-3b base machine

unused opcodes, the microarchitecture would execute a sequence of microinstructions,starting at state 10 or state 11, depending on which illegal opcode was being decoded.In both cases, the sequence of microinstructions would respond to the fact that aninstruction with an illegal opcode had been fetched.

Several signals necessary to control the data path and the microsequencer are notamong those listed in Tables C.1 and C.2. They are DR, SR1, BEN, and R. Figure C.6shows the additional logic needed to generate DR, SR1, and BEN.

The remaining signal, R, is a signal generated by the memory in order to allow theState  18  (010010)  State  33  (100001)  State  35  (100011)  State  32  (100000)  State  6        (000110)  State  25  (011001)  State  27  (011011)  

State  Machine  for  LDW   Microsequencer  

Page 52: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

C.4. THE CONTROL STRUCTURE 11

DR

IR[11:9]

111

DRMUX

(a)

SR1

SR1MUX

IR[11:9]

IR[8:6]

(b)

Logic BEN

PZN

IR[11:9]

(c)

Figure C.6: Additional logic required to provide control signals

LC-3b to operate correctly with a memory that takes multiple clock cycles to read orstore a value.

Suppose it takes memory five cycles to read a value. That is, once MAR containsthe address to be read and the microinstruction asserts READ, it will take five cyclesbefore the contents of the specified location in memory are available to be loaded intoMDR. (Note that the microinstruction asserts READ by means of three control signals:MIO.EN/YES, R.W/RD, and DATA.SIZE/WORD; see Figure C.3.)

Recall our discussion in Section C.2 of the function of state 33, which accessesan instruction from memory during the fetch phase of each instruction cycle. For theLC-3b to operate correctly, state 33 must execute five times before moving on to state35. That is, until MDR contains valid data from the memory location specified by thecontents of MAR, we want state 33 to continue to re-execute. After five clock cycles,the memory has completed the “read,” resulting in valid data in MDR, so the processorcan move on to state 35. What if the microarchitecture did not wait for the memory tocomplete the read operation before moving on to state 35? Since the contents of MDRwould still be garbage, the microarchitecture would put garbage into IR in state 35.

The ready signal (R) enables the memory read to execute correctly. Since the mem-ory knows it needs five clock cycles to complete the read, it asserts a ready signal(R) throughout the fifth clock cycle. Figure C.2 shows that the next state is 33 (i.e.,100001) if the memory read will not complete in the current clock cycle and state 35(i.e., 100011) if it will. As we have seen, it is the job of the microsequencer (FigureC.5) to produce the next state address.

Page 53: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified
Page 54: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

C.4. THE CONTROL STRUCTURE 9

Microinstruction

R

Microsequencer

BEN

x2

Control Store6

IR[15:11]

6

(J, COND, IRD)

269

35

35

Figure C.4: The control structure of a microprogrammed implementation, overall blockdiagram

on the LC-3b instruction being executed during the current instruction cycle. This statecarries out the DECODE phase of the instruction cycle. If the IRD control signal in themicroinstruction corresponding to state 32 is 1, the output MUX of the microsequencer(Figure C.5) will take its source from the six bits formed by 00 concatenated with thefour opcode bits IR[15:12]. Since IR[15:12] specifies the opcode of the current LC-3b instruction being processed, the next address of the control store will be one of 16addresses, corresponding to the 14 opcodes plus the two unused opcodes, IR[15:12] =1010 and 1011. That is, each of the 16 next states is the first state to be carried outafter the instruction has been decoded in state 32. For example, if the instruction beingprocessed is ADD, the address of the next state is state 1, whose microinstruction isstored at location 000001. Recall that IR[15:12] for ADD is 0001.

If, somehow, the instruction inadvertently contained IR[15:12] = 1010 or 1011, the

Page 55: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

10APPENDIXC. THEMICROARCHITECTUREOFTHE LC-3B, BASICMACHINE

IRD

Address of Next State

6

6

0,0,IR[15:12]

J[5]

Branch ReadyModeAddr.

J[0]J[1]J[2]

COND0COND1

J[3]J[4]

R IR[11]BEN

Figure C.5: The microsequencer of the LC-3b base machine

unused opcodes, the microarchitecture would execute a sequence of microinstructions,starting at state 10 or state 11, depending on which illegal opcode was being decoded.In both cases, the sequence of microinstructions would respond to the fact that aninstruction with an illegal opcode had been fetched.

Several signals necessary to control the data path and the microsequencer are notamong those listed in Tables C.1 and C.2. They are DR, SR1, BEN, and R. Figure C.6shows the additional logic needed to generate DR, SR1, and BEN.

The remaining signal, R, is a signal generated by the memory in order to allow the

Page 56: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

14APPENDIXC. THEMICROARCHITECTUREOFTHE LC-3B, BASICMACHINE

J LD.PC

LD.BEN

LD.IR

LD.M

DR

LD.M

AR

LD.REG

LD.CC

Cond

IRD

GatePC

GateMDR

GateALU

GateMARMUX

GateSH

FPC

MUXDRMUXSR

1MUX

ADDR1MUX

ADDR2MUX

MARMUX

010000 (State 16)010001 (State 17)

010011 (State 19)010010 (State 18)

010100 (State 20)010101 (State 21)010110 (State 22)010111 (State 23)011000 (State 24)011001 (State 25)011010 (State 26)011011 (State 27)011100 (State 28)011101 (State 29)011110 (State 30)011111 (State 31)100000 (State 32)100001 (State 33)100010 (State 34)100011 (State 35)100100 (State 36)100101 (State 37)100110 (State 38)100111 (State 39)101000 (State 40)101001 (State 41)101010 (State 42)101011 (State 43)101100 (State 44)101101 (State 45)101110 (State 46)101111 (State 47)110000 (State 48)110001 (State 49)110010 (State 50)110011 (State 51)110100 (State 52)110101 (State 53)110110 (State 54)110111 (State 55)111000 (State 56)111001 (State 57)111010 (State 58)111011 (State 59)111100 (State 60)111101 (State 61)111110 (State 62)111111 (State 63)

001000 (State 8)001001 (State 9)001010 (State 10)001011 (State 11)001100 (State 12)001101 (State 13)001110 (State 14)001111 (State 15)

000000 (State 0)000001 (State 1)000010 (State 2)000011 (State 3)000100 (State 4)000101 (State 5)000110 (State 6)000111 (State 7)

ALUK

MIO.EN

R.W LSHF1

DATA.SI

ZE

Figure C.7: Specification of the control store

Page 57: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

End of the Exercise in Microprogramming

57

Page 58: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

specified in Appendix C

58

Page 59: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Lab 2 Extra Credit n  Microprogrammed MIPS implementation

n  Exercise your creativity!

59

Page 60: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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  i.e., what signal cannot be available without processing in the

datapath?

n  Remember the MIPS datapath q  One PCSrc signal depends on processing that happens in the

datapath (bcond logic)

60

Page 61: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

correctly q  Example: transition from state 33 to state 35 is controlled by

the R bit asserted by memory when memory data is available

n  Could we have done this in a single-cycle microarchitecture?

61

Page 62: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

n  What if an instruction generates an exception?

n  How can you implement a complex instruction using this control structure? q  Think REP MOVS

62

Page 63: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

the hardware designer with a new abstraction: microprogramming

n  The designer can translate any desired operation to a sequence of microinstructions

n  All the designer needs to provide is q  The sequence of microinstructions needed to implement the

desired operation q  The ability for the control logic to correctly sequence through

the microinstructions q  Any additional datapath control signals needed (no need if the

operation can be “translated” into existing control signals)

63

Page 64: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

n  What changes, if any, do you make to the q  state machine? q  datapath? q  control store? q  microsequencer?

n  Show all changes and microinstructions n  Coming up in Homework 2

64

Page 65: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Aside: Alignment Correction in Memory n  Remember unaligned accesses

n  LC-3b has byte load and byte store instructions that move data not aligned at the word-address boundary q  Convenience to the programmer/compiler

n  How does the hardware ensure this works correctly? q  Take a look at state 29 for LDB q  States 24 and 17 for STB q  Additional logic to handle unaligned accesses

65

Page 66: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

address of LDx and STx are to memory or I/O devices

n  Correspondingly enables memory or I/O devices and sets up muxes

n  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

Page 67: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

controlling the datapath (using a sequencer) q  High-level ISA translated into microcode (sequence of microinstructions) q  Microcode (ucode) enables a minimal datapath to emulate an ISA q  Microinstructions can be thought of as a user-invisible ISA (micro ISA)

n  Enables easy extensibility of the ISA q  Can support a new instruction by changing the microcode q  Can support complex instructions as a sequence of simple microinstructions

n  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

Page 68: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

processor is shipped) enables q  Ability to add new instructions without changing the processor! q  Ability to “fix” buggy hardware implementations

n  Examples q  IBM 370 Model 145: microcode stored in main memory, can be

updated after a reboot q  IBM System z: Similar to 370/145.

n  Heller and Farrell, “Millicode in an IBM zSeries processor,” IBM JR&D, May/Jul 2004.

q  B1700 microcode can be updated while the processor is running n  User-microprogrammable machine!

68

Page 69: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

Page 70: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Horizontal Microcode

70

Microprogram counter

Address select logic

Adder

1

Input

Datapath control outputs

Microcode storage

Inputs from instruction register opcode field

Outputs

Sequencing control

[Based  on  original  figure  from  P&H  CO&D,  COPYRIGHT  2004  Elsevier.  ALL  RIGHTS  RESERVED.]  

ALUSrcA    IorD    IRWrite  PCWrite  PCWriteCond  ….  

n-­‐bit  µPC  input  

k-­‐bit  “

control”  outpu

t  

Control  Store:  2n×  k  bit    (not  including  sequencing)  

Page 71: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Vertical Microcode

71

Microprogram counter

Address select logic

Adder

1

Input

Datapath control outputs

Microcode storage

Inputs from instruction register opcode field

Outputs

Sequencing control

“PC  ⇐  PC+4”  “PC  ⇐  ALUOut”  “PC  ⇐  PC[  31:28  ],IR[  25:0  ],2’b00”  “IR   ⇐  MEM[  PC  ]”  “A  ←  RF[  IR[  25:21  ]  ]”  “B  ←  RF[  IR[  20:16  ]  ]”  ………….   …….  

ROM  

ALUSrcA    

IorD    IRW

rite  PCW

rite  PCW

riteCond  ….  

[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    (2n×m+2m×k  bit)  should  be  smaller  than  horizontal  microcode  ROM  (2n×k  bit)    

m-­‐bit  input  

k-­‐bit  output  

n-­‐bit  µPC  input  

1-­‐bit  signal  means  do  this  RT                  (or  combinadon  of  RTs)  

Page 72: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Nanocode and Millicode n  Nanocode:  a  level  below  tradidonal  µcode  

q   µprogrammed  control  for  sub-­‐systems  (e.g.,  a  complicated  floadng-­‐point  module)  that  acts  as  a  slave  in  a  µcontrolled  datapath  

n  Millicode:  a  level  above  tradidonal  µcode  q  ISA-­‐level  subroudnes  that  can  be  called  by  the  µcontroller  to  handle  

complicated  operadons  and  system  funcdons  q  E.g.,  Heller  and  Farrell,  “Millicode  in  an  IBM  zSeries  processor,”  IBM  

JR&D,  May/Jul  2004.  

n  In  both  cases,  we  avoid  complicadng  the  main  µcontroller    n  You  can  think  of  these  as  “microcode”  at  different  levels  of  

abstracdon

72

Page 73: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Nanocode Concept Illustrated

73

ROM  

µPC  

arithmedc  datapath  

a  “µcoded”  FPU  implementadon  

ROM  

µPC  

processor  datapath  

a  “µcoded”  processor  implementadon  

We  refer  to  this    as  “nanocode”  when  a  µcoded  subsystem  is  embedded    in  a  µcoded  system  

Page 74: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Microcoded Multi-Cycle MIPS Design n  P&H, Appendix D

n  Any ISA can be implemented this way

n  We will not cover this in class n  However, you can do an extra credit assignment for Lab 2

74

Page 75: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Microcoded Multi-Cycle MIPS Design

75 [Based  on  original  figure  from  P&H  CO&D,  COPYRIGHT  2004  Elsevier.  ALL  RIGHTS  RESERVED.]  

Page 76: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Control Logic for MIPS FSM

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

Page 77: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Microprogrammed Control for MIPS FSM

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

Page 78: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Multi-Cycle vs. Single-Cycle uArch n  Advantages

n  Disadvantages

n  You should be very familiar with this right now

78

Page 79: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Microprogrammed vs. Hardwired Control n  Advantages

n  Disadvantages

n  You should be very familiar with this right now

79

Page 80: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

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

n  Limited concurrency q  Some hardware resources are idle during different phases of

instruction processing cycle q  “Fetch” logic is idle when an instruction is being “decoded” or

“executed” q  Most of the datapath is idle when a memory access is

happening

80

Page 81: 18-447 Computer Architecture - archive.ece.cmu.eduece447/s15/lib/exe/fetch.php?media=onur-447... · Patt and Patel, Appendix C, Figure C.2 ! Each state must be uniquely specified

Can We Use the Idle Hardware to Improve Concurrency?

n  Goal: Concurrency à throughput (more “work” completed in one cycle)

n  Idea: When an instruction is using some resources in its processing phase, process other instructions on idle resources not needed by that instruction q  E.g., when an instruction is being decoded, fetch the next

instruction q  E.g., when an instruction is being executed, decode another

instruction q  E.g., when an instruction is accessing data memory (ld/st),

execute the next instruction q  E.g., when an instruction is writing its result into the register

file, access data memory for the next instruction 81