Lets Build a Processor Almost ready to move into chapter 5 and - - PowerPoint PPT Presentation

lets build a processor
SMART_READER_LITE
LIVE PREVIEW

Lets Build a Processor Almost ready to move into chapter 5 and - - PowerPoint PPT Presentation

Lets Build a Processor Almost ready to move into chapter 5 and start building a processor First, lets review Boolean Logic and build the ALU well need (Material from Appendix B) operation a 32 ALU result 32 b 32 86


slide-1
SLIDE 1

86

2004 Morgan Kaufmann Publishers

Lets Build a Processor

  • Almost ready to move into chapter 5 and start building a processor
  • First, let’s review Boolean Logic and build the ALU we’ll need

(Material from Appendix B)

32 32 32

  • peration

result a b

ALU

slide-2
SLIDE 2

87

2004 Morgan Kaufmann Publishers

  • Problem: Consider a logic function with three inputs: A, B, and C.

Output D is true if at least one input is true Output E is true if exactly two inputs are true Output F is true only if all three inputs are true

  • Show the truth table for these three functions.
  • Show the Boolean equations for these three functions.
  • Show an implementation consisting of inverters, AND, and OR gates.

Review: Boolean Algebra & Gates

slide-3
SLIDE 3

88

2004 Morgan Kaufmann Publishers

  • Let's build an ALU to support the andi and ori instructions

– we'll just build a 1 bit ALU, and use 32 of them

  • Possible Implementation (sum-of-products):

b a

  • peration

result

  • p a

b res

An ALU (arithmetic logic unit)

slide-4
SLIDE 4

89

2004 Morgan Kaufmann Publishers

  • Selects one of the inputs to be the output, based on a control input
  • Lets build our ALU using a MUX:

S C A B

1

Review: The Multiplexor

note: we call this a 2-input mux even though it has 3 inputs!

slide-5
SLIDE 5

90

2004 Morgan Kaufmann Publishers

  • Not easy to decide the “best” way to build something

– Don't want too many inputs to a single gate – Don’t want to have to go through too many gates – for our purposes, ease of comprehension is important

  • Let's look at a 1-bit ALU for addition:
  • How could we build a 1-bit ALU for add, and, and or?
  • How could we build a 32-bit ALU?

Different Implementations

cout = a b + a cin + b cin sum = a xor b xor cin

Sum CarryIn CarryOut a b

slide-6
SLIDE 6

91

2004 Morgan Kaufmann Publishers

Building a 32 bit ALU

b 2 Result Operation a 1 CarryIn CarryOut Result31 a31 b31 Result0 CarryIn a0 b0 Result1 a1 b1 Result2 a2 b2 Operation ALU0 CarryIn CarryOut ALU1 CarryIn CarryOut ALU2 CarryIn CarryOut ALU31 CarryIn

slide-7
SLIDE 7

92

2004 Morgan Kaufmann Publishers

  • Two's complement approach: just negate b and add.
  • How do we negate?
  • A very clever solution:

What about subtraction (a – b) ?

2 Result Operation a 1 CarryIn CarryOut 1 Binvert b

slide-8
SLIDE 8

93

2004 Morgan Kaufmann Publishers

Adding a NOR function

  • Can also choose to invert a. How do we get “a NOR b” ?

Binvert a b CarryIn CarryOut Operation 1 2 + Result 1 Ainvert 1

slide-9
SLIDE 9

94

2004 Morgan Kaufmann Publishers

  • Need to support the set-on-less-than instruction (slt)

– remember: slt is an arithmetic instruction – produces a 1 if rs < rt and 0 otherwise – use subtraction: (a-b) < 0 implies a < b

  • Need to support test for equality (beq $t5, $t6, $t7)

– use subtraction: (a-b) = 0 implies a = b

Tailoring the ALU to the MIPS

slide-10
SLIDE 10

Supporting slt

  • Can we figure out the idea?

Binvert a b CarryIn CarryOut Operation 1 2 + Result 1 Ainvert 1 3 Less Binvert a b CarryIn Operation 1 2 + Result 1 3 Less Overflow detection Set Overflow Ainvert 1

Use this ALU for most significant bit all other bits

slide-11
SLIDE 11

96

2004 Morgan Kaufmann Publishers a0 Operation CarryIn ALU0 Less CarryOut b0 CarryIn a1 CarryIn ALU1 Less CarryOut b1 Result0 Result1 a2 CarryIn ALU2 Less CarryOut b2 a31 CarryIn ALU31 Less b31 Result2 Result31 . . . . . . . . . Binvert Ainvert Overflow Set CarryIn

Supporting slt

slide-12
SLIDE 12

97

2004 Morgan Kaufmann Publishers

Test for equality

  • Notice control lines:

0000 = and 0001 = or 0010 = add 0110 = subtract 0111 = slt 1100 = NOR

  • Note: zero is a 1 when the result is zero!

a0 Operation CarryIn ALU0 Less CarryOut b0 a1 CarryIn ALU1 Less CarryOut b1 Result0 Result1 a2 CarryIn ALU2 Less CarryOut b2 a31 CarryIn ALU31 Less b31 Result2 Result31 . . . . . . . . . Bnegate Ainvert Overflow Set CarryIn . . . . . . Zero

slide-13
SLIDE 13

98

2004 Morgan Kaufmann Publishers

Conclusion

  • We can build an ALU to support the MIPS instruction set

– key idea: use multiplexor to select the output we want – we can efficiently perform subtraction using two’s complement – we can replicate a 1-bit ALU to produce a 32-bit ALU

  • Important points about hardware

– all of the gates are always working – the speed of a gate is affected by the number of inputs to the gate – the speed of a circuit is affected by the number of gates in series (on the “critical path” or the “deepest level of logic”)

  • Our primary focus: comprehension, however,

– Clever changes to organization can improve performance (similar to using better algorithms in software) – We saw this in multiplication, let’s look at addition now

slide-14
SLIDE 14

99

2004 Morgan Kaufmann Publishers

  • Is a 32-bit ALU as fast as a 1-bit ALU?
  • Is there more than one way to do addition?

– two extremes: ripple carry and sum-of-products Can you see the ripple? How could you get rid of it? c1 = b0c0 + a0c0 + a0b0 c2 = b1c1 + a1c1 + a1b1 c2 = c3 = b2c2 + a2c2 + a2b2 c3 = c4 = b3c3 + a3c3 + a3b3 c4 = Not feasible! Why?

Problem: ripple carry adder is slow

slide-15
SLIDE 15

100

2004 Morgan Kaufmann Publishers

  • An approach in-between our two extremes
  • Motivation:

– If we didn't know the value of carry-in, what could we do? – When would we always generate a carry? gi = ai bi – When would we propagate the carry? pi = ai + bi

  • Did we get rid of the ripple?

c1 = g0 + p0c0 c2 = g1 + p1c1 c2 = c3 = g2 + p2c2 c3 = c4 = g3 + p3c3 c4 = Feasible! Why?

Carry-lookahead adder

slide-16
SLIDE 16

101

2004 Morgan Kaufmann Publishers

  • Can’t build a 16 bit adder this way... (too big)
  • Could use ripple carry of 4-bit CLA adders
  • Better: use the CLA principle again!

Use principle to build bigger adders

a4 CarryIn ALU1 P1 G1 b4 a5 b5 a6 b6 a7 b7 a0 CarryIn ALU0 P0 G0 b0 Carry-lookahead unit a1 b1 a2 b2 a3 b3 CarryIn Result0–3 pi gi ci + 1 pi + 1 gi + 1 C1 Result4–7 a8 CarryIn ALU2 P2 G2 b8 a9 b9 a10 b10 a11 b11 ci + 2 pi + 2 gi + 2 C2 Result8–11 a12 CarryIn ALU3 P3 G3 b12 a13 b13 a14 b14 a15 b15 ci + 3 pi + 3 gi + 3 C3 Result12–15 ci + 4 C4 CarryOut

slide-17
SLIDE 17

102

2004 Morgan Kaufmann Publishers

ALU Summary

  • We can build an ALU to support MIPS addition
  • Our focus is on comprehension, not performance
  • Real processors use more sophisticated techniques for arithmetic
  • Where performance is not critical, hardware description languages

allow designers to completely automate the creation of hardware!

slide-18
SLIDE 18

103

2004 Morgan Kaufmann Publishers

Chapter Five

slide-19
SLIDE 19

104

2004 Morgan Kaufmann Publishers

  • We're ready to look at an implementation of the MIPS
  • Simplified to contain only:

– memory-reference instructions: lw, sw – arithmetic-logical instructions: add, sub, and, or, slt – control flow instructions: beq, j

  • Generic Implementation:

– use the program counter (PC) to supply instruction address – get the instruction from memory – read registers – use the instruction to decide exactly what to do

  • All instructions use the ALU after reading the registers

Why? memory-reference? arithmetic? control flow?

The Processor: Datapath & Control

slide-20
SLIDE 20

105

2004 Morgan Kaufmann Publishers

  • Abstract / Simplified View:

Two types of functional units: – elements that operate on data values (combinational) – elements that contain state (sequential)

More Implementation Details

Data Register # Register # Register # PC Address Instruction Instruction memory Registers ALU Address Data Data memory Add Add 4

slide-21
SLIDE 21

106

2004 Morgan Kaufmann Publishers

  • Unclocked vs. Clocked
  • Clocks used in synchronous logic

– when should an element that contains state be updated?

State Elements

Clock period Rising edge Falling edge

cycle time

slide-22
SLIDE 22

107

2004 Morgan Kaufmann Publishers

  • The set-reset latch

– output depends on present inputs and also on past inputs

An unclocked state element

R S Q Q

slide-23
SLIDE 23

108

2004 Morgan Kaufmann Publishers

  • Output is equal to the stored value inside the element

(don't need to ask for permission to look at the value)

  • Change of state (value) is based on the clock
  • Latches: whenever the inputs change, and the clock is asserted
  • Flip-flop: state changes only on a clock edge

(edge-triggered methodology) "logically true", — could mean electrically low A clocking methodology defines when signals can be read and written — wouldn't want to read a signal at the same time it was being written

Latches and Flip-flops

slide-24
SLIDE 24

109

2004 Morgan Kaufmann Publishers

  • Two inputs:

– the data value to be stored (D) – the clock signal (C) indicating when to read & store D

  • Two outputs:

– the value of the internal state (Q) and it's complement

D-latch

Q C D _ Q

D C Q

slide-25
SLIDE 25

110

2004 Morgan Kaufmann Publishers

D flip-flop

  • Output changes only on the clock edge

D C Q

D C D latch D C Q D latch D C Q Q Q Q

slide-26
SLIDE 26

111

2004 Morgan Kaufmann Publishers

Our Implementation

  • An edge triggered methodology
  • Typical execution:

– read contents of some state elements, – send values through some combinational logic – write results to one or more state elements

State element 1 State element 2 Combinational logic Clock cycle

slide-27
SLIDE 27

112

2004 Morgan Kaufmann Publishers

  • Built using D flip-flops

Register File

Read register number 1 Read data 1 Read register number 2 Read data 2 Write register Write Write data Register file Read register number 1 Register 0 Register 1 . . . Register n – 2 Register n – 1 M u x Read register number 2 M u x Read data 1 Read data 2

Do you understand? What is the “Mux” above?

slide-28
SLIDE 28

113

2004 Morgan Kaufmann Publishers

Abstraction

  • Make sure you understand the abstractions!
  • Sometimes it is easy to think you do, when you don’t

M u x C Select 32 32 32 B A M u x Select B31 A31 C31 M u x B30 A30 C30 M u x B0 A0 C0 . . . . . .

slide-29
SLIDE 29

114

2004 Morgan Kaufmann Publishers

Register File

  • Note: we still use the real clock to determine when to write

Write 1 n-to-2n decoder n – 1 n Register 0 C D Register 1 C D Register n – 2 C D Register n – 1 C D . . . Register number . . . Register data

slide-30
SLIDE 30

115

2004 Morgan Kaufmann Publishers

Simple Implementation

  • Include the functional units we need for each instruction

Why do we need this stuff?

PC Instruction address Instruction Instruction memory Add Sum

  • a. Instruction memory
  • b. Program counter
  • c. Adder

Read register 1 Read register 2 Write register Write Data Registers ALU Data Data Zero ALU result RegWrite

  • a. Registers
  • b. ALU

5 5 5 Register numbers Read data 1 Read data 2 ALU operation 4 Address Read data Data memory

  • a. Data memory unit

Write data MemRead MemWrite

  • b. Sign-extension unit

Sign extend 16 32

slide-31
SLIDE 31

116

2004 Morgan Kaufmann Publishers

Building the Datapath

  • Use multiplexors to stitch them together

Read register 1 Read register 2 Write register Write data Write data Registers ALU Add Zero RegWrite MemRead MemWrite PCSrc MemtoReg Read data 1 Read data 2 ALU operation 4 Sign extend 16 32 Instruction ALU result Add ALU result M u x M u x M u x ALUSrc Address Data memory Read data Shift left 2 4 Read address Instruction memory PC

slide-32
SLIDE 32

117

2004 Morgan Kaufmann Publishers

Control

  • Selecting the operations to perform (ALU, read/write, etc.)
  • Controlling the flow of data (multiplexor inputs)
  • Information comes from the 32 bits of the instruction
  • Example:

add $8, $17, $18 Instruction Format: 000000 10001 10010 01000 00000 100000

  • p

rs rt rd shamt funct

  • ALU's operation based on instruction type and function code
slide-33
SLIDE 33

118

2004 Morgan Kaufmann Publishers

  • e.g., what should the ALU do with this instruction
  • Example: lw $1, 100($2)

35 2 1 100

  • p

rs rt 16 bit offset

  • ALU control input

0000 AND 0001 OR 0010 add 0110 subtract 0111 set-on-less-than 1100 NOR

  • Why is the code for subtract 0110 and not 0011?

Control

slide-34
SLIDE 34

119

2004 Morgan Kaufmann Publishers

  • Must describe hardware to compute 4-bit ALU control input

– given instruction type 00 = lw, sw 01 = beq, 10 = arithmetic – function code for arithmetic

  • Describe it using a truth table (can turn into gates):

ALUOp computed from instruction type

Control

slide-35
SLIDE 35

Instruction RegDst ALUSrc Memto- Reg Reg Write Mem Read Mem Write Branch ALUOp1 ALUp0 R-format 1 1 1 lw 1 1 1 1 sw X 1 X 1 beq X X 1 1

Read register 1 Read register 2 Write register Write data Write data Registers ALU Add Zero Read data 1 Read data 2 Sign extend 16 32 Instruction [31–0] ALU result Add ALU result M u x M u x M u x Address Data memory Read data Shift left 2 4 Read address Instruction memory PC 1 1 1 M u x 1 ALU control Instruction [5–0] Instruction [25–21] Instruction [31–26] Instruction [15–11] Instruction [20–16] Instruction [15–0] RegDst Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Control

slide-36
SLIDE 36

121

2004 Morgan Kaufmann Publishers

Control

  • Simple combinational logic (truth tables)

Operation2 Operation1 Operation0 Operation ALUOp1 F3 F2 F1 F0 F (5– 0) ALUOp0 ALUOp ALU control block R-format Iw sw beq Op0 Op1 Op2 Op3 Op4 Op5 Inputs Outputs RegDst ALUSrc MemtoReg RegWrite MemRead MemWrite Branch ALUOp1 ALUOpO

slide-37
SLIDE 37

122

2004 Morgan Kaufmann Publishers

  • All of the logic is combinational
  • We wait for everything to settle down, and the right thing to be done

– ALU might not produce “right answer” right away – we use write signals along with clock to determine when to write

  • Cycle time determined by length of the longest path

Our Simple Control Structure

We are ignoring some details like setup and hold times

State element 1 State element 2 Combinational logic Clock cycle

slide-38
SLIDE 38

123

2004 Morgan Kaufmann Publishers

Single Cycle Implementation

  • Calculate cycle time assuming negligible delays except:

– memory (200ps), ALU and adders (100ps), register file access (50ps)

Read register 1 Read register 2 Write register Write data Write data Registers ALU Add Zero RegWrite MemRead MemWrite PCSrc MemtoReg Read data 1 Read data 2 ALU operation 4 Sign extend 16 32 Instruction ALU result Add ALU result M u x M u x M u x ALUSrc Address Data memory Read data Shift left 2 4 Read address Instruction memory PC

slide-39
SLIDE 39

124

2004 Morgan Kaufmann Publishers

Where we are headed

  • Single Cycle Problems:

– what if we had a more complicated instruction like floating point? – wasteful of area

  • One Solution:

– use a “smaller” cycle time – have different instructions take different numbers of cycles – a “multicycle” datapath:

Data Register # Register # Register # PC Address Instruction

  • r data

Memory Registers ALU Instruction register Memory data register ALUOut A B Data

slide-40
SLIDE 40

125

2004 Morgan Kaufmann Publishers

  • We will be reusing functional units

– ALU used to compute address and to increment PC – Memory used for instruction and data

  • Our control signals will not be determined directly by instruction

– e.g., what should the ALU do for a “subtract” instruction?

  • We’ll use a finite state machine for control

Multicycle Approach

slide-41
SLIDE 41

126

2004 Morgan Kaufmann Publishers

  • Break up the instructions into steps, each step takes a cycle

– balance the amount of work to be done – restrict each cycle to use only one major functional unit

  • At the end of a cycle

– store values for use in later cycles (easiest thing to do) – introduce additional “internal” registers

Multicycle Approach

Read register 1 Read register 2 Write register Write data Registers ALU Zero Read data 1 Read data 2 Sign extend 16 32 Instruction [25–21] Instruction [20–16] Instruction [15–0] ALU result M u x M u x Shift left 2 Instruction register PC 1 M u x 1 M u x 1 M u x 1 A B 1 2 3 ALUOut Instruction [15–0] Memory data register Address Write data Memory MemData 4 Instruction [15–11]

slide-42
SLIDE 42

127

2004 Morgan Kaufmann Publishers

Instructions from ISA perspective

  • Consider each instruction from perspective of ISA.
  • Example:

– The add instruction changes a register. – Register specified by bits 15:11 of instruction. – Instruction specified by the PC. – New value is the sum (“op”) of two registers. – Registers specified by bits 25:21 and 20:16 of the instruction

  • Reg[Memory[PC][15:11]] <= Reg[Memory[PC][25:21]]
  • p

Reg[Memory[PC][20:16]] – In order to accomplish this we must break up the instruction. (kind of like introducing variables when programming)

slide-43
SLIDE 43

128

2004 Morgan Kaufmann Publishers

Breaking down an instruction

  • ISA definition of arithmetic:

Reg[Memory[PC][15:11]] <= Reg[Memory[PC][25:21]] op Reg[Memory[PC][20:16]]

  • Could break down to:

– IR <= Memory[PC] – A <= Reg[IR[25:21]] – B <= Reg[IR[20:16]] – ALUOut <= A op B – Reg[IR[20:16]] <= ALUOut

  • We forgot an important part of the definition of arithmetic!

– PC <= PC + 4

slide-44
SLIDE 44

129

2004 Morgan Kaufmann Publishers

Idea behind multicycle approach

  • We define each instruction from the ISA perspective (do this!)
  • Break it down into steps following our rule that data flows through at

most one major functional unit (e.g., balance work across steps)

  • Introduce new registers as needed (e.g, A, B, ALUOut, MDR, etc.)
  • Finally try and pack as much work into each step

(avoid unnecessary cycles) while also trying to share steps where possible (minimizes control, helps to simplify solution)

  • Result: Our book’s multicycle Implementation!
slide-45
SLIDE 45

130

2004 Morgan Kaufmann Publishers

  • Instruction Fetch
  • Instruction Decode and Register Fetch
  • Execution, Memory Address Computation, or Branch Completion
  • Memory Access or R-type instruction completion
  • Write-back step

INSTRUCTIONS TAKE FROM 3 - 5 CYCLES!

Five Execution Steps

slide-46
SLIDE 46

131

2004 Morgan Kaufmann Publishers

  • Use PC to get instruction and put it in the Instruction Register.
  • Increment the PC by 4 and put the result back in the PC.
  • Can be described succinctly using RTL "Register-Transfer Language"

IR <= Memory[PC]; PC <= PC + 4; Can we figure out the values of the control signals? What is the advantage of updating the PC now?

Step 1: Instruction Fetch

slide-47
SLIDE 47

132

2004 Morgan Kaufmann Publishers

  • Read registers rs and rt in case we need them
  • Compute the branch address in case the instruction is a branch
  • RTL:

A <= Reg[IR[25:21]]; B <= Reg[IR[20:16]]; ALUOut <= PC + (sign-extend(IR[15:0]) << 2);

  • We aren't setting any control lines based on the instruction type

(we are busy "decoding" it in our control logic)

Step 2: Instruction Decode and Register Fetch

slide-48
SLIDE 48

133

2004 Morgan Kaufmann Publishers

  • ALU is performing one of three functions, based on instruction type
  • Memory Reference:

ALUOut <= A + sign-extend(IR[15:0]);

  • R-type:

ALUOut <= A op B;

  • Branch:

if (A==B) PC <= ALUOut;

Step 3 (instruction dependent)

slide-49
SLIDE 49

134

2004 Morgan Kaufmann Publishers

  • Loads and stores access memory

MDR <= Memory[ALUOut];

  • r

Memory[ALUOut] <= B;

  • R-type instructions finish

Reg[IR[15:11]] <= ALUOut; The write actually takes place at the end of the cycle on the edge

Step 4 (R-type or memory-access)

slide-50
SLIDE 50

135

2004 Morgan Kaufmann Publishers

  • Reg[IR[20:16]] <= MDR;

Which instruction needs this?

Write-back step

slide-51
SLIDE 51

136

2004 Morgan Kaufmann Publishers

Summary:

slide-52
SLIDE 52

137

2004 Morgan Kaufmann Publishers

  • How many cycles will it take to execute this code?

lw $t2, 0($t3) lw $t3, 4($t3) beq $t2, $t3, Label #assume not add $t5, $t2, $t3 sw $t5, 8($t3) Label: ...

  • What is going on during the 8th cycle of execution?
  • In what cycle does the actual addition of $t2 and $t3 takes place?

Simple Questions

slide-53
SLIDE 53

Read register 1 Read register 2 Write register Write data Registers ALU Zero Read data 1 Read data 2 Sign extend 16 32 Instruction [31–26] Instruction [25–21] Instruction [20–16] Instruction [15–0] ALU result M u x M u x Shift left 2 Shift left 2 Instruction register PC 1 M u x 1 M u x 1 M u x 1 A B 1 2 3 M u x 1 2 ALUOut Instruction [15–0] Memory data register Address Write data Memory MemData 4 Instruction [15–11] PCWriteCond PCWrite IorD MemRead MemWrite MemtoReg IRWrite PCSource ALUOp ALUSrcB ALUSrcA RegWrite RegDst 26 28 Outputs Control Op [5–0] ALU control PC [31–28] Instruction [25-0] Instruction [5–0] Jump address [31–0]

slide-54
SLIDE 54

139

2004 Morgan Kaufmann Publishers

  • Finite state machines:

– a set of states and – next state function (determined by current state and the input) – output function (determined by current state and possibly input) – We’ll use a Moore machine (output based only on current state)

Review: finite state machines

Inputs Current state Outputs Clock Next-state function Output function Next state

slide-55
SLIDE 55

140

2004 Morgan Kaufmann Publishers

Review: finite state machines

  • Example:
  • B. 37 A friend would like you to build an “electronic eye” for use as a fake security
  • device. The device consists of three lights lined up in a row, controlled by the outputs

Left, Middle, and Right, which, if asserted, indicate that a light should be on. Only one light is on at a time, and the light “moves” from left to right and then from right to left, thus scaring away thieves who believe that the device is monitoring their activity. Draw the graphical representation for the finite state machine used to specify the electronic eye. Note that the rate of the eye’s movement will be controlled by the clock speed (which should not be too great) and that there are essentially no inputs.

slide-56
SLIDE 56

141

2004 Morgan Kaufmann Publishers

  • Value of control signals is dependent upon:

– what instruction is being executed – which step is being performed

  • Use the information we’ve accumulated to specify a finite state machine

– specify the finite state machine graphically, or – use microprogramming

  • Implementation can be derived from specification

Implementing the Control

slide-57
SLIDE 57

142

2004 Morgan Kaufmann Publishers

  • Note:

– don’t care if not mentioned – asserted if name only –

  • therwise exact value
  • How many state

bits will we need?

Graphical Specification of FSM

MemRead ALUSrcA = 0 IorD = 0 IRWrite ALUSrcB = 01 ALUOp = 00 PCWrite PCSource = 00 ALUSrcA = 0 ALUSrcB = 11 ALUOp = 00 ALUSrcA = 1 ALUSrcB = 00 ALUOp = 10 ALUSrcA = 1 ALUSrcB = 10 ALUOp = 00 MemRead IorD = 1 MemWrite IorD = 1 RegDst = 1 RegWrite MemtoReg = 0 RegDst = 1 RegWrite MemtoReg = 0 PCWrite PCSource = 10 ALUSrcA = 1 ALUSrcB = 00 ALUOp = 01 PCWriteCond PCSource = 01 Instruction decode/ register fetch Instruction fetch 1 Start Jump completion 9 8 6 2 3 4 5 7 Memory read completon step R-type completion Memory access Memory access Execution Branch completion Memory address computation

slide-58
SLIDE 58

143

2004 Morgan Kaufmann Publishers

  • Implementation:

Finite State Machine for Control

PCWrite PCWriteCond IorD MemtoReg PCSource ALUOp ALUSrcB ALUSrcA RegWrite RegDst NS3 NS2 NS1 NS0 O p 5 O p 4 O p 3 O p 2 O p 1 O p S 3 S 2 S 1 S State register IRWrite MemRead MemWrite Instruction register

  • pcode field

Outputs Control logic Inputs

slide-59
SLIDE 59

144

2004 Morgan Kaufmann Publishers

PLA Implementation

  • If I picked a horizontal or vertical line could you explain it?

Op5 Op4 Op3 Op2 Op1 Op0 S3 S2 S1 S0 IorD IRWrite MemRead MemWrite PCWrite PCWriteCond MemtoReg PCSource1 ALUOp1 ALUSrcB0 ALUSrcA RegWrite RegDst NS3 NS2 NS1 NS0 ALUSrcB1 ALUOp0 PCSource0

slide-60
SLIDE 60

145

2004 Morgan Kaufmann Publishers

  • ROM = "Read Only Memory"

– values of memory locations are fixed ahead of time

  • A ROM can be used to implement a truth table

– if the address is m-bits, we can address 2m entries in the ROM. – our outputs are the bits of data that the address points to. m is the "height", and n is the "width"

ROM Implementation

m n

0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1

slide-61
SLIDE 61

146

2004 Morgan Kaufmann Publishers

  • How many inputs are there?

6 bits for opcode, 4 bits for state = 10 address lines (i.e., 210 = 1024 different addresses)

  • How many outputs are there?

16 datapath-control outputs, 4 state bits = 20 outputs

  • ROM is 210 x 20 = 20K bits (and a rather unusual size)
  • Rather wasteful, since for lots of the entries, the outputs are the

same — i.e., opcode is often ignored

ROM Implementation

slide-62
SLIDE 62

147

2004 Morgan Kaufmann Publishers

  • Break up the table into two parts

— 4 state bits tell you the 16 outputs, 24 x 16 bits of ROM — 10 bits tell you the 4 next state bits, 210 x 4 bits of ROM — Total: 4.3K bits of ROM

  • PLA is much smaller

— can share product terms — only need entries that produce an active output — can take into account don't cares

  • Size is (#inputs × #product-terms) + (#outputs × #product-terms)

For this example = (10x17)+(20x17) = 510 PLA cells

  • PLA cells usually about the size of a ROM cell (slightly bigger)

ROM vs PLA

slide-63
SLIDE 63

148

2004 Morgan Kaufmann Publishers

  • Complex instructions: the "next state" is often current state + 1

Another Implementation Style

AddrCtl Outputs PLA or ROM State Address select logic O p [ 5 – ] Adder Instruction register

  • pcode field

1 Control unit Input PCWrite PCWriteCond IorD MemtoReg PCSource ALUOp ALUSrcB ALUSrcA RegWrite RegDst IRWrite MemRead MemWrite BWrite

slide-64
SLIDE 64

149

2004 Morgan Kaufmann Publishers

Details

Dispatch ROM 1 Dispatch ROM 2 Op Opcode name Value Op Opcode name Value 000000 R-format 0110 100011 lw 0011 000010 jmp 1001 101011 sw 0101 000100 beq 1000 100011 lw 0010 101011 sw 0010

State number Address-control action Value of AddrCtl Use incremented state 3 1 Use dispatch ROM 1 1 2 Use dispatch ROM 2 2 3 Use incremented state 3 4 Replace state number by 0 5 Replace state number by 0 6 Use incremented state 3 7 Replace state number by 0 8 Replace state number by 0 9 Replace state number by 0

State Adder 1 PLA or ROM Mux 3 2 1 Dispatch ROM 1 Dispatch ROM 2 AddrCtl Address select logic Instruction register

  • pcode field
slide-65
SLIDE 65

150

2004 Morgan Kaufmann Publishers

Microprogramming

  • What are the “microinstructions” ?

PCWrite PCWriteCond IorD MemtoReg PCSource ALUOp ALUSrcB ALUSrcA RegWrite AddrCtl Outputs Microcode memory IRWrite MemRead MemWrite RegDst Control unit Input Microprogram counter Address select logic Adder 1 Instruction register

  • pcode field

BWrite Datapath

slide-66
SLIDE 66

151

2004 Morgan Kaufmann Publishers

  • A specification methodology

– appropriate if hundreds of opcodes, modes, cycles, etc. – signals specified symbolically using microinstructions

  • Will two implementations of the same architecture have the same microcode?
  • What would a microassembler do?

Microprogramming

Label ALU control SRC1 SRC2 Register control Memory PCWrite control Sequencing Fetch Add PC 4 Read PC ALU Seq Add PC Extshft Read Dispatch 1 Mem1 Add A Extend Dispatch 2 LW2 Read ALU Seq Write MDR Fetch SW2 Write ALU Fetch Rformat1 Func code A B Seq Write ALU Fetch BEQ1 Subt A B ALUOut-cond Fetch JUMP1 Jump address Fetch

slide-67
SLIDE 67

152

2004 Morgan Kaufmann Publishers

Microinstruction format

Field name Value Signals active Comment Add ALUOp = 00 Cause the ALU to add. ALU control Subt ALUOp = 01 Cause the ALU to subtract; this implements the compare for branches. Func code ALUOp = 10 Use the instruction's function code to determine ALU control. SRC1 PC ALUSrcA = 0 Use the PC as the first ALU input. A ALUSrcA = 1 Register A is the first ALU input. B ALUSrcB = 00 Register B is the second ALU input. SRC2 4 ALUSrcB = 01 Use 4 as the second ALU input. Extend ALUSrcB = 10 Use output of the sign extension unit as the second ALU input. Extshft ALUSrcB = 11 Use the output of the shift-by-two unit as the second ALU input. Read Read two registers using the rs and rt fields of the IR as the register numbers and putting the data into registers A and B. Write ALU RegWrite, Write a register using the rd field of the IR as the register number and Register RegDst = 1, the contents of the ALUOut as the data. control MemtoReg = 0 Write MDR RegWrite, Write a register using the rt field of the IR as the register number and RegDst = 0, the contents of the MDR as the data. MemtoReg = 1 Read PC MemRead, Read memory using the PC as address; write result into IR (and lorD = 0 the MDR). Memory Read ALU MemRead, Read memory using the ALUOut as address; write result into MDR. lorD = 1 Write ALU MemWrite, Write memory using the ALUOut as address, contents of B as the lorD = 1 data. ALU PCSource = 00 Write the output of the ALU into the PC. PCWrite PC write control ALUOut-cond PCSource = 01, If the Zero output of the ALU is active, write the PC with the contents PCWriteCond

  • f the register ALUOut.

jump address PCSource = 10, Write the PC with the jump address from the instruction. PCWrite Seq AddrCtl = 11 Choose the next microinstruction sequentially. Sequencing Fetch AddrCtl = 00 Go to the first microinstruction to begin a new instruction. Dispatch 1 AddrCtl = 01 Dispatch using the ROM 1. Dispatch 2 AddrCtl = 10 Dispatch using the ROM 2.

slide-68
SLIDE 68

153

2004 Morgan Kaufmann Publishers

  • No encoding:

– 1 bit for each datapath operation – faster, requires more memory (logic) – used for Vax 780 — an astonishing 400K of memory!

  • Lots of encoding:

– send the microinstructions through logic to get control signals – uses less memory, slower

  • Historical context of CISC:

– Too much logic to put on a single chip with everything else – Use a ROM (or even RAM) to hold the microcode – It’s easy to add new instructions

Maximally vs. Minimally Encoded

slide-69
SLIDE 69

154

2004 Morgan Kaufmann Publishers

Microcode: Trade-offs

  • Distinction between specification and implementation is sometimes blurred
  • Specification Advantages:

– Easy to design and write – Design architecture and microcode in parallel

  • Implementation (off-chip ROM) Advantages

– Easy to change since values are in memory – Can emulate other architectures – Can make use of internal registers

  • Implementation Disadvantages, SLOWER now that:

– Control is implemented on same chip as processor – ROM is no longer faster than RAM – No need to go back and make changes

slide-70
SLIDE 70

155

2004 Morgan Kaufmann Publishers

Historical Perspective

  • In the ‘60s and ‘70s microprogramming was very important for

implementing machines

  • This led to more sophisticated ISAs and the VAX
  • In the ‘80s RISC processors based on pipelining became popular
  • Pipelining the microinstructions is also possible!
  • Implementations of IA-32 architecture processors since 486 use:

– “hardwired control” for simpler instructions

(few cycles, FSM control implemented using PLA or random logic)

– “microcoded control” for more complex instructions

(large numbers of cycles, central control store)

  • The IA-64 architecture uses a RISC-style ISA and can be

implemented without a large central control store

slide-71
SLIDE 71

156

2004 Morgan Kaufmann Publishers

Pentium 4

  • Pipelining is important (last IA-32 without it was 80386 in 1985)
  • Pipelining is used for the simple instructions favored by compilers

“Simply put, a high performance implementation needs to ensure that the simple instructions execute quickly, and that the burden of the complexities of the instruction set penalize the complex, less frequently used, instructions”

Control Control Control Enhanced floating point and multimedia Control I/O interface Instruction cache Integer datapath Data cache Secondary cache and memory interface Advanced pipelining hyperthreading support

Chapter 6 Chapter 7

slide-72
SLIDE 72

157

2004 Morgan Kaufmann Publishers

Pentium 4

  • Somewhere in all that “control we must handle complex instructions
  • Processor executes simple microinstructions, 70 bits wide (hardwired)
  • 120 control lines for integer datapath (400 for floating point)
  • If an instruction requires more than 4 microinstructions to implement,

control from microcode ROM (8000 microinstructions)

  • Its complicated!

Control Control Control Enhanced floating point and multimedia Control I/O interface Instruction cache Integer datapath Data cache Secondary cache and memory interface Advanced pipelining hyperthreading support

slide-73
SLIDE 73

158

2004 Morgan Kaufmann Publishers

Chapter 5 Summary

  • If we understand the instructions…

We can build a simple processor!

  • If instructions take different amounts of time, multi-cycle is better
  • Datapath implemented using:

– Combinational logic for arithmetic – State holding elements to remember bits

  • Control implemented using:

– Combinational logic for single-cycle implementation – Finite state machine for multi-cycle implementation