cs 152 computer architecture and engineering lecture 3 ...cs152/sp09/lectures/l03-ciscrisc.pdf ·...
TRANSCRIPT
CS 152 Computer Architecture and
Engineering
Lecture 3 - From CISC to RISC
Krste AsanovicElectrical Engineering and Computer Sciences
University of California at Berkeley
http://www.eecs.berkeley.edu/~krste
http://inst.eecs.berkeley.edu/~cs152
1/29/2009 CS152-Spring!09 2
Instruction Set Architecture (ISA) versusImplementation
• ISA is the hardware/software interface– Defines set of programmer visible state
– Defines instruction format (bit encoding) and instructionsemantics
– Examples: MIPS, x86, IBM 360, JVM
• Many possible implementations of one ISA– 360 implementations: model 30 (c. 1964), z990 (c. 2004)
– x86 implementations: 8086 (c. 1978), 80186, 286, 386, 486,Pentium, Pentium Pro, Pentium-4 (c. 2000), AMD Athlon,Transmeta Crusoe, SoftPC
– MIPS implementations: R2000, R4000, R10000, ...
– JVM: HotSpot, PicoJava, ARM Jazelle, ...
1/29/2009 CS152-Spring!09 3
Styles of ISA
• Accumulator
• Stack
• GPR
• CISC
• RISC
• VLIW
• Vector
• Boundaries are fuzzy, and hybrids are common– E.g., 8086/87 is hybrid accumulator-GPR-stack ISA
– Many ISAs have added vector extensions
1/29/2009 CS152-Spring!09 4
Styles of Implementation
• Microcoded
• Unpipelined single cycle
• Hardwired in-order pipeline
• Out-of-order pipeline with speculative execution andregister renaming
• Software interpreter
• Binary translator
• Just-in-Time compiler
1/29/2009 CS152-Spring!09 5
Last Time in Lecture 2
• Stack machines popular to simplify High-LevelLanguage (HLL) implementation
– Algol-68 & Burroughs B5000, Forth machines, Occam & Transputers,Java VMs & Java Interpreters
• General-purpose register machines provide greaterefficiency with better compiler technology (or assemblycoding)
– Compilers can explicitly manage fastest level of memory hierarchy(registers)
• Microcoding was a straightforward methodical way toimplement machines with low gate count
1/29/2009 CS152-Spring!09 6
A Bus-based Datapath for MIPS
Microinstruction: register to register transfer (17 control signals) MA ! PC means RegSel = PC; enReg=yes; ldMA= yes
B ! Reg[rt] means
enMem
MA
addr
data
ldMA
Memory
busy
MemWrt
Bus 32
zero?
A B
OpSel ldA ldB
ALU
enALU
ALUcontrol
2
RegWrt
enReg
addr
data
rsrtrd
32(PC)31(Link)
RegSel
32 GPRs+ PC ...
32-bit Reg
3
rsrtrd
ExtSel
IR
Opcode
ldIR
ImmExt
enImm
2
RegSel = rt; enReg=yes; ldB = yes
1/29/2009 CS152-Spring!09 7
MIPS Microcontroller: first attempt
nextstate
µPC (state)
Opcodezero?
Busy (memory)
Control Signals (17)
s
s
6
µProgram ROM
addr
data
latching the inputsmay cause a one-cycle delay
= 2(opcode+status+s) words
How bigis “s”?
ROM size ?
Word size ?
= control+s bits
1/29/2009 CS152-Spring!09 8
Reducing Control Store Size
• Reduce the ROM height (= address bits)– reduce inputs by extra external logic
each input bit doubles the size of the control store
– reduce states by grouping opcodes find common sequences of actions
– condense input status bitscombine all exceptions into one, i.e.,exception/no-exception
• Reduce the ROM width– restrict the next-state encoding
Next, Dispatch on opcode, Wait for memory, ...– encode control signals (vertical microcode)
Control store has to be fast ! expensive
1/29/2009 CS152-Spring!09 9
MIPS Controller V2
µJumpType =
next | spin | fetch | dispatch | feqz | fnez
Control Signals (17)
Control ROM
address
data
+1
Opcode ext
µPC (state)
jumplogic
zero
µPC µPC+1
absolute
op-group
busy
µPCSrcinput encoding
reduces ROM height
next-state encodingreduces ROM width
1/29/2009 CS152-Spring!09 10
Jump Logic
µPCSrc = Case µJumpTypes
next " µPC+1
spin " if (busy) then µPC else µPC+1
fetch " absolute
dispatch " op-group
feqz " if (zero) then absolute else µPC+1
fnez " if (zero) then µPC+1 else absolute
1/29/2009 CS152-Spring!09 11
Instruction Fetch & ALU:MIPS-Controller-2
State Control points next-state
fetch0 MA ! PC fetch1 IR ! Memoryfetch2 A ! PCfetch3 PC ! A + 4
...ALU0 A ! Reg[rs] ALU1 B ! Reg[rt] ALU2 Reg[rd]!func(A,B)
ALUi0 A ! Reg[rs] ALUi1 B ! sExt16(Imm)ALUi2 Reg[rd]! Op(A,B)
nextspinnextdispatch
nextnextfetch
nextnextfetch
1/29/2009 CS152-Spring!09 12
Load & Store: MIPS-Controller-2
State Control points next-state
LW0 A ! Reg[rs] next LW1 B ! sExt16(Imm) nextLW2 MA ! A+B nextLW3 Reg[rt] ! Memory spin
LW4 fetch
SW0 A ! Reg[rs] next SW1 B ! sExt16(Imm) nextSW2 MA ! A+B nextSW3 Memory ! Reg[rt] spin
SW4 fetch
1/29/2009 CS152-Spring!09 13
Branches: MIPS-Controller-2
State Control points next-state
BEQZ0 A ! Reg[rs] next
BEQZ1 fnez BEQZ2 A ! PC nextBEQZ3 B ! sExt16(Imm<<2) nextBEQZ4 PC ! A+B fetch
BNEZ0 A ! Reg[rs] next
BNEZ1 feqzBNEZ2 A ! PC nextBNEZ3 B ! sExt16(Imm<<2) nextBNEZ4 PC ! A+B fetch
1/29/2009 CS152-Spring!09 14
Jumps: MIPS-Controller-2
State Control points next-state
J0 A ! PC nextJ1 B ! IR nextJ2 PC ! JumpTarg(A,B) fetch
JR0 A ! Reg[rs] nextJR1 PC ! A fetch
JAL0 A ! PC next JAL1 Reg[31] ! A next JAL2 B ! IR nextJAL3 PC ! JumpTarg(A,B) fetch
JALR0 A ! PC next JALR1 B ! Reg[rs] nextJALR2 Reg[31] ! A next
JALR3 PC ! B fetch
1/29/2009 CS152-Spring!09 15
Implementing Complex Instructions
ExtSel
A B
RegWrt
enReg
enMem
MA
addr addr
data data
rsrtrd
32(PC)31(Link)
RegSel
OpSel ldA ldB ldMA
Memory
32 GPRs+ PC ...
32-bit RegALU
enALU
Bus
IR
busyzero?Opcode
ldIR
ImmExt
enImm
2
ALUcontrol
2
3
MemWrt
32
rsrtrd
rd ! M[(rs)] op (rt) Reg-Memory-src ALU op M[(rd)] ! (rs) op (rt) Reg-Memory-dst ALU op M[(rd)] ! M[(rs)] op M[(rt)] Mem-Mem ALU op
1/29/2009 CS152-Spring!09 16
Mem-Mem ALU Instructions:MIPS-Controller-2
Mem-Mem ALU op M[(rd)] ! M[(rs)] op M[(rt)]
ALUMM0 MA ! Reg[rs] nextALUMM1 A ! Memory spinALUMM2 MA ! Reg[rt] nextALUMM3 B ! Memory spinALUMM4 MA !Reg[rd] nextALUMM5 Memory ! func(A,B) spin
ALUMM6 fetch
Complex instructions usually do not require datapathmodifications in a microprogrammed implementation
-- only extra space for the control program
Implementing these instructions using a hardwiredcontroller is difficult without datapath modifications
1/29/2009 CS152-Spring!09 17
Performance Issues
Microprogrammed control " multiple cycles per instruction
Cycle time ? tC > max(treg-reg, tALU, tµROM)
Suppose 10 * tµROM < tRAM
Good performance, relative to a single-cyclehardwired implementation, can be achievedeven with a CPI of 10
1/29/2009 CS152-Spring!09 18
Horizontal vs Vertical µCode
• Horizontal µcode has wider µinstructions– Multiple parallel operations per µinstruction
– Fewer steps per macroinstruction– Sparser encoding " more bits
• Vertical µcode has narrower µinstructions– Typically a single datapath operation per µinstruction
– separate µinstruction for branches
– More steps to per macroinstruction– More compact " less bits
• Nanocoding– Tries to combine best of horizontal and vertical µcode
# µInstructions
Bits per µInstruction
1/29/2009 CS152-Spring!09 19
Nanocoding
• MC68000 had 17-bit µcode containing either 10-bit µjump or9-bit nanoinstruction pointer
– Nanoinstructions were 68 bits wide, decoded to give 196control signals
µcode ROM
nanoaddress
µcode
next-state
µaddress
µPC (state)
nanoinstruction ROMdata
Exploits recurringcontrol signal patternsin µcode, e.g.,
ALU0 A ! Reg[rs]
...ALUi0 A ! Reg[rs]
...
1/29/2009 CS152-Spring!09 20
Microprogramming in IBM 360
Only the fastest models (75 and 95) were hardwired
750200025001500memory cycle(ns)
351574Rental fee($K/month)
200500625750µstore cycle(ns)
BCROSBCROSTCROSCCROSµstoretechnology
2.752.7544µcode size(K !insts)
87855250µinst width(bits)
6432168Datapath width(bits)
M65M50M40M30
1/29/2009 CS152-Spring!09 21
Microcode Emulation
• IBM initially miscalculated the importance of softwarecompatibility with earlier models when introducing the360 series
• Honeywell stole some IBM 1401 customers by offeringtranslation software (“Liberator”) for Honeywell H200series machine
• IBM retaliated with optional additional microcode for 360series that could emulate IBM 1401 ISA, later extendedfor IBM 7000 series
– one popular program on 1401 was a 650 simulator, so somecustomers ran many 650 programs on emulated 1401s
– (650 simulated on 1401 emulated on 360)
1/29/2009 CS152-Spring!09 22
Microprogramming thrived in theSeventies
• Significantly faster ROMs than magnetic corememory or DRAMs were available
• For complex instruction sets (CISC), datapath andcontroller were cheaper and simpler
• New instructions , e.g., floating point, could besupported without datapath modifications
• Fixing bugs in the controller was easier
• ISA compatibility across various models could beachieved easily and cheaply
Except for the cheapest and fastest machines,all computers were microprogrammed
1/29/2009 CS152-Spring!09 23
Writable Control Store (WCS)
• Implement control store in RAM not ROM– MOS SRAM memories now became almost as fast as control store
(core memories/DRAMs were 2-10x slower)– Bug-free microprograms difficult to write
• User-WCS provided as option on several minicomputers– Allowed users to change microcode for each processor
• User-WCS failed– Little or no programming tools support– Difficult to fit software into small space– Microcode control tailored to original ISA, less useful for others– Large WCS part of processor state - expensive context switches– Protection difficult if user can change microcode– Virtual memory required restartable microcode
1/29/2009 CS152-Spring!09 24
Microprogramming: early Eighties
• Evolution bred more complex micro-machines– Ever more complex CISC ISAs led to need for subroutine and call
stacks in !code
– Need for fixing bugs in control programs was in conflict with read-onlynature of !ROM
– --> WCS (B1700, QMachine, Intel i432, …)
• With the advent of VLSI technology assumptions aboutROM & RAM speed became invalid
• Better compilers made complex instructions lessimportant
• Use of numerous micro-architectural innovations, e.g.,pipelining, caches and buffers, made multiple-cycleexecution of reg-reg instructions unattractive
1/29/2009 CS152-Spring!09 25
Microprogramming in Modern Usage
• Microprogramming is far from extinct
• Played a crucial role in micros of the EightiesDEC uVAX, Motorola 68K series, Intel 386 and 486
• Microcode pays an assisting role in most modernmicros (AMD Athlon, Intel Core 2 Duo, IBM PowerPC)
• Most instructions are executed directly, i.e., with hard-wired control• Infrequently-used and/or complicated instructions invoke the microcode engine
• Patchable microcode common for post-fabrication bug fixes, e.g. Intel Pentiums load !code patches at bootup
1/29/2009 CS152-Spring!09 26
From CISC to RISC
• Use fast RAM to build fast instruction cache ofuser-visible instructions, not fixed hardwaremicroroutines
– Can change contents of fast instruction memory to fit whatapplication needs right now
• Use simple ISA to enable hardwired pipelinedimplementation
– Most compiled code only used a few of the available CISCinstructions
– Simpler encoding allowed pipelined implementations
• Further benefit with integration– In early ‘80s, could finally fit 32-bit datapath + small caches
on a single chip
– No chip crossings in common case allows faster operation
1/29/2009 CS152-Spring!09 27
Nanocoding
• MC68000 had 17-bit µcode containing either 10-bit µjump or 9-bitnanoinstruction pointer
– Nanoinstructions were 68 bits wide, decoded to give 196 controlsignals
µcode ROM
nanoaddress
µcode
next-state
µaddress
µPC (state)
nanoinstruction ROMdata
Exploits recurringcontrol signal patternsin µcode, e.g.,
ALU0 A ! Reg[rs]
...ALUi0 A ! Reg[rs]
...
User PC
Inst. Cache
Hardwired Decode
1/29/2009 CS152-Spring!09 28
CDC 6600 Seymour Cray, 1964
• A fast pipelined machine with 60-bit words
• Ten functional units- Floating Point: adder, multiplier, divider- Integer: adder, multiplier...
• Hardwired control (no microcoding)
• Dynamic scheduling of instructions using ascoreboard
• Ten Peripheral Processors for Input/Output - a fast time-shared 12-bit integer ALU
• Very fast clock, 10MHz
• Novel freon-based technology for cooling
1/29/2009 CS152-Spring!09 29
CDC 6600: Datapath
Address Regs Index Regs 8 x 18-bit 8 x 18-bit
Operand Regs8 x 60-bit
Inst. Stack8 x 60-bit
IR
10 FunctionalUnits
CentralMemory
128K words,32 banks,1µs cycle
resultaddr
result
operand
operandaddr
1/29/2009 CS152-Spring!09 30
• Separate instructions to manipulate three types of reg.8 60-bit data registers (X)8 18-bit address registers (A)8 18-bit index registers (B)
• All arithmetic and logic instructions are reg-to-reg
• Only Load and Store instructions refer to memory!
Touching address registers 1 to 5 initiates a load 6 to 7 initiates a store
- very useful for vector operations
6 3 3 3
opcode i j k Ri ! (Rj) op (Rk)
CDC 6600:A Load/Store Architecture
6 3 3 18
opcode i j disp Ri ! M[(Rj) + disp]
1/29/2009 CS152-Spring!09 31
CDC6600: Vector Addition
B0 ! - n
loop: JZE B0, exitA0 ! B0 + a0 load X0A1 ! B0 + b0 load X1X6 ! X0 + X1A6 ! B0 + c0 store X6B0 ! B0 + 1
jump loop
Ai = address registerBi = index registerXi = data register
1/29/2009 CS152-Spring!09 32
CDC6600 ISA designed to simplifyhigh-performance implementation• Use of three-address, register-register ALU
instructions simplifies pipelined implementation– No implicit dependencies between inputs and outputs
• Decoupling setting of address register (Ar) fromretrieving value from data register (Xr) simplifiesproviding multiple outstanding memory accesses
– Software can schedule load of address register before use of value
– Can interleave independent instructions inbetween
• CDC6600 has multiple parallel but unpipelinedfunctional units
– E.g., 2 separate multipliers
• Follow-on machine CDC7600 used pipelinedfunctional units
– Foreshadows later RISC designs
1/29/2009 CS152-Spring!09 33
“Iron Law” of Processor Performance
Time = Instructions Cycles Time Program Program * Instruction * Cycle
– Instructions per program depends on source code, compilertechnology, and ISA
– Cycles per instructions (CPI) depends upon the ISA and themicroarchitecture
– Time per cycle depends upon the microarchitecture and thebase technology
short1Pipelined
long1Single-cycle unpipelined
short>1Microcoded
cycle timeCPIMicroarchitecture
this lecture
1/29/2009 CS152-Spring!09 34
CS152 Administrivia
• Check web site for new calendar, quiz dates shouldnot change
– Feb 17 and Mar 17 lecture in 320 Soda
– All other lectures in 306 Soda (here)
• PS1 and Lab 1 available now or tomorrow– PS 1 / Lab 1 due Tuesday February 10
• Section tomorrow (Friday 1/30) 12-1pm 258 Dwinelle– Covers lab 1 details
• Quiz 1 on Thursday Feb 12
1/29/2009 CS152-Spring!09
Hardware Elements
• Combinational circuits– Mux, Decoder, ALU, ...
• Synchronous state elements– Flipflop, Register, Register file, SRAM, DRAM
Edge-triggered: Data is sampled at the rising edge
Clk
D
Q
Enff
Q
D
Clk
En
OpSelect - Add, Sub, ...
- And, Or, Xor, Not, ... - GT, LT, EQ, Zero, ...
Result
Comp?
A
B
ALU
Sel
O
A0
A1
An-1
Mux...
lg(n)
A
Decoder
...
O0
O1
On-1
lg(n)
1/29/2009 CS152-Spring!09 36
Register Files
ReadData1ReadSel1
ReadSel2
WriteSel
Register file
2R+1W
ReadData2
WriteData
WEClock
rd1rs1
rs2
ws
wd
rd2
we
• Reads are combinational
ff
Q0
D0
Clk
Enff
Q1
D1
ff
Q2
D2
ff
Qn-1
Dn-1
...
...
...
register
1/29/2009 CS152-Spring!09 37
Register File Implementation
reg 31
ws clk
reg 1
wd
we
rs1rd1 rd2
reg 0
…
32
…
532 32
…
rs25
5
• Register files with a large number of ports are difficult to design– Almost all MIPS instructions have exactly 2 register source operands
– Intel’s Itanium, GPR File has 128 registers with 8 read ports and 4 write ports!!!
1/29/2009 CS152-Spring!09 38
A Simple Memory Model
MAGIC RAM
ReadData
WriteData
Address
WriteEnable
Clock
Reads and writes are always completed in one cycle• a Read can be done any time (i.e. combinational)• a Write is performed at the rising clock edge if it is enabled
" the write address and data
must be stable at the clock edge
Later in the course we will present a more realisticmodel of memory
1/29/2009 CS152-Spring!09 39
Implementing MIPS:
Single-cycle per instructiondatapath & control logic
(Should be review of CS61C)
1/29/2009 CS152-Spring!09 40
The MIPS ISA
Processor State32 32-bit GPRs, R0 always contains a 032 single precision FPRs, may also be viewed as
16 double precision FPRsFP status register, used for FP compares & exceptionsPC, the program countersome other special registers
Data types8-bit byte, 16-bit half word 32-bit word for integers32-bit word for single precision floating point64-bit word for double precision floating point
Load/Store style instruction setdata addressing modes- immediate & indexedbranch addressing modes- PC relative & register indirectByte addressable memory- big endian mode
All instructions are 32 bits
1/29/2009 CS152-Spring!09 41
Instruction Execution
Execution of an instruction involves
1. instruction fetch2. decode and register fetch3. ALU operation4. memory operation (optional)5. write back
and the computation of the address of the next instruction
1/29/2009 CS152-Spring!09 42
Datapath: Reg-Reg ALU Instructions
RegWrite Timing? 6 5 5 5 5 6 0 rs rt rd 0 func rd ! (rs) func (rt)
31 26 25 21 20 16 15 11 5 0
0x4
Add
clk
addrinst
Inst.Memory
PC
inst<25:21>inst<20:16>
inst<15:11>
inst<5:0>
OpCode
zALU
ALU
Control
RegWrite
clk
rd1
GPRs
rs1rs2
wswd rd2
we
1/29/2009 CS152-Spring!09 43
Datapath: Reg-Imm ALU Instructions
6 5 5 16opcode rs rt immediate rt ! (rs) op immediate
31 26 25 2120 16 15 0
ImmExt
ExtSel
inst<15:0>
OpCode
0x4
Add
clk
addrinst
Inst.Memory
PC
zALU
RegWrite
clk
rd1
GPRs
rs1rs2
wswd rd2
weinst<25:21>
inst<20:16>
inst<31:26> ALUControl
1/29/2009 CS152-Spring!09 44
Conflicts in Merging Datapath
ImmExt
ExtSelOpCode
0x4
Add
clk
addrinst
Inst.Memory
PC
zALU
RegWrite
clk
rd1
GPRs
rs1rs2
wswd rd2
weinst<25:21>
inst<20:16>
inst<15:0>
inst<31:26> ALUControl
inst<15:11>
inst<5:0>
opcode rs rt immediate rt ! (rs) op immediate
6 5 5 5 5 6 0 rs rt rd 0 func rd ! (rs) func (rt)
Introducemuxes
1/29/2009 CS152-Spring!09 45
Datapath for ALU Instructions
<31:26>, <5:0>
opcode rs rt immediate rt ! (rs) op immediate
6 5 5 5 5 6 0 rs rt rd 0 func rd ! (rs) func (rt)
BSrc
Reg / ImmRegDst
rt / rd
ImmExt
ExtSelOpCode
0x4
Add
clk
addrinst
Inst.Memory
PC
zALU
RegWrite
clk
rd1
GPRs
rs1rs2
wswd rd2
we<25:21>
<20:16>
<15:0>
OpSel
ALUControl
<15:11>
1/29/2009 CS152-Spring!09 46
Datapath for Memory Instructions
Should program and data memory be separate?
Harvard style: separate (Aiken and Mark 1 influence)- read-only program memory- read/write data memory
- Note:Somehow there must be a way to load theprogram memory
Princeton style: the same (von Neumann’s influence)- single read/write memory for program and data
- Note: A Load or Store instruction requires accessing the memory more than once during its execution
1/29/2009 CS152-Spring!09 47
Load/Store Instructions:Harvard Datapath
WBSrc
ALU / Mem
rs is the base registerrt is the destination of a Load or the source for a Store
6 5 5 16 addressing modeopcode rs rt displacement (rs) + displacement
31 26 25 21 20 16 15 0
RegDst BSrc
“base”
disp
ExtSelOpCode OpSel
ALUControl
zALU
0x4
Add
clk
addrinst
Inst.Memory
PC
RegWrite
clk
rd1
GPRs
rs1rs2
wswd rd2
we
ImmExt
clk
MemWrite
addr
wdata
rdataData Memory
we
1/29/2009 CS152-Spring!09 48
MIPS Control Instructions
Conditional (on GPR) PC-relative branch
Unconditional register-indirect jumps
Unconditional absolute jumps
• PC-relative branches add offset#4 to PC+4 to calculate thetarget address (offset is in words): ±128 KB range
• Absolute jumps append target#4 to PC<31:28> to calculate
the target address: 256 MB range• jump-&-link stores PC+4 into the link register (R31)• All Control Transfers are delayed by 1 instruction
we will worry about the branch delay slot later
6 5 5 16opcode rs offset BEQZ, BNEZ
6 26opcode target J, JAL
6 5 5 16opcode rs JR, JALR
1/29/2009 CS152-Spring!09 49
Conditional Branches (BEQZ, BNEZ)
0x4
Add
PCSrc
clk
WBSrcMemWrite
addr
wdata
rdataData Memory
we
RegDst BSrcExtSelOpCode
z
OpSel
clk
zero?
clk
addrinst
Inst.Memory
PC rd1
GPRs
rs1rs2
wswd rd2
we
ImmExt
ALU
ALUControl
Add
br
pc+4
RegWrite
1/29/2009 CS152-Spring!09 50
Register-Indirect Jumps (JR)
0x4
RegWrite
Add
Add
clk
WBSrcMemWrite
addr
wdata
rdataData Memory
we
RegDst BSrcExtSelOpCode
z
OpSel
clk
zero?
clk
addrinst
Inst.Memory
PC rd1
GPRs
rs1rs2
wswd rd2
we
ImmExt
ALU
ALUControl
PCSrc
br
pc+4
rind
1/29/2009 CS152-Spring!09 51
Register-Indirect Jump-&-Link (JALR)
0x4
RegWrite
Add
Add
clk
WBSrcMemWrite
addr
wdata
rdataData Memory
we
RegDst BSrcExtSelOpCode
z
OpSel
clk
zero?
clk
addrinst
Inst.Memory
PC rd1
GPRs
rs1rs2
wswd rd2
we
ImmExt
ALU
ALUControl
31
PCSrc
br
pc+4
rind
1/29/2009 CS152-Spring!09 52
Absolute Jumps (J, JAL)
0x4
RegWrite
Add
Add
clk
WBSrcMemWrite
addr
wdata
rdataData Memory
we
RegDst BSrcExtSelOpCode
z
OpSel
clk
zero?
clk
addrinst
Inst.Memory
PC rd1
GPRs
rs1rs2
wswd rd2
we
ImmExt
ALU
ALUControl
31
PCSrc
br
pc+4
rindjabs
1/29/2009 CS152-Spring!09 53
Harvard-Style Datapath for MIPS
0x4
RegWrite
Add
Add
clk
WBSrcMemWrite
addr
wdata
rdataData Memory
we
RegDst BSrcExtSelOpCode
z
OpSel
clk
zero?
clk
addrinst
Inst.Memory
PC rd1
GPRs
rs1rs2
wswd rd2
we
ImmExt
ALU
ALUControl
31
PCSrc
br
rindjabs
pc+4
1/29/2009 CS152-Spring!09 54
Hardwired Control is pureCombinational Logic
combinational logic
op code
zero?
ExtSel
BSrc
OpSel
MemWrite
WBSrc
RegDst
RegWrite
PCSrc
1/29/2009 CS152-Spring!09 55
ALU Control & Immediate Extension
Inst<31:26> (Opcode)
Decode Map
Inst<5:0> (Func)
ALUop
0?
+
OpSel( Func, Op, +, 0? )
ExtSel( sExt16, uExt16, High16)
1/29/2009 CS152-Spring!09 56
JALR
JR
JAL
J
BEQZz=1
BEQZz=0
SW
LW
ALUiu
ALUi
ALU
PCSrcRegDstWBSrcRegWMemWOpSelBSrcExtSelOpcode
Hardwired Control Table
BSrc = Reg / Imm WBSrc = ALU / Mem / PC RegDst = rt / rd / R31 PCSrc = pc+4 / br / rind / jabs
* * * no yes rindPC R31
rind* * * no no * *
jabs* * * no yes PC R31
jabs* * * no no * *
pc+4sExt16 * 0? no no * *
brsExt16 * 0? no no * *
pc+4sExt16 Imm + yes no * *
pc+4Imm Op no yes ALU rt
pc+4* Reg Func no yes ALU rd
sExt16 Imm Op pc+4no yes ALU rt
pc+4sExt16 Imm + no yes Mem rt
uExt16
1/29/2009 CS152-Spring!09 57
Single-Cycle Hardwired Control:Harvard architecture
We will assume • clock period is sufficiently long for all of the following steps to be “completed”:
1. instruction fetch2. decode and register fetch3. ALU operation4. data fetch if required5. register write-back setup time
" tC > tIFetch + tRFetch + tALU+ tDMem+ tRWB
• At the rising edge of the following clock, the PC, the register file and the memory are updated
1/29/2009 CS152-Spring!09 58
An Ideal Pipeline
• All objects go through the same stages
• No sharing of resources between any two stages
• Propagation delay through all pipeline stages is equal
• The scheduling of an object entering the pipeline is not affected by the objects in other stages
stage1
stage2
stage3
stage4
These conditions generally hold for industrialassembly lines.But can an instruction pipeline satisfy the lastcondition?
1/29/2009 CS152-Spring!09 59
Pipelined MIPS
To pipeline MIPS:
• First build MIPS without pipelining with CPI=1
• Next, add pipeline registers to reduce cycle time whilemaintaining CPI=1
1/29/2009 CS152-Spring!09 60
Pipelined Datapath
Clock period can be reduced by dividing the execution of aninstruction into multiple cycles
tC > max {tIM, tRF, tALU, tDM, tRW} ( = tDM probably)
However, CPI will increase unless instructions are pipelined
write-backphase
fetchphase
executephase
decode & Reg-fetchphase
memoryphase
addr
wdata
rdataDataMemory
we
ALU
ImmExt
0x4
Add
addrrdata
Inst.Memory
rd1
GPRs
rs1rs2
wswd rd2
we
IRPC
1/29/2009 CS152-Spring!09 61
How to divide the datapathinto stages
Suppose memory is significantly slower thanother stages. In particular, suppose
Since the slowest stage determines the clock, itmay be possible to combine some stages withoutany loss of performance
= 1 unittRW
= 1 unittRF
= 5 unitstALU
= 10 unitstDM
= 10 unitstIM
1/29/2009 CS152-Spring!09 62
Alternative Pipelining
tC > max {tIM, tRF, tALU, tDM, tRW} = tDMtC > max {tIM, tRF+tALU, tDM, tRW} = tDM
Write-back stage takes much less time than other stages.Suppose we combined it with the memory phase
tC > max {tIM, tRF+tALU, tDM+tRW} = tDM+ tRW
! increase the critical path by 10%
write-backphase
fetchphase
executephase
decode & Reg-fetchphase
memoryphase
addr
wdata
rdataDataMemory
we
ALU
ImmExt
0x4
Add
addrrdata
Inst.Memory
rd1
GPRs
rs1rs2
wswd rd2
we
IRPC
1/29/2009 CS152-Spring!09 63
Summary
• Microcoding became less attractive as gap betweenRAM and ROM speeds reduced
• Complex instruction sets difficult to pipeline, sodifficult to increase performance as gate count grew
• Iron Law explains architecture design space– Trade instruction/program, cycles/instruction, and time/cycle
• Load-Store RISC ISAs designed for efficientpipelined implementations
– Very similar to vertical microcode
– Inspired by earlier Cray machines
• MIPS ISA will be used in class and problems,SPARC in lab (two very similar ISAs)
1/29/2009 CS152-Spring!09 64
Acknowledgements
• These slides contain material developed andcopyright by:
– Arvind (MIT)
– Krste Asanovic (MIT/UCB)
– Joel Emer (Intel/MIT)
– James Hoe (CMU)
– John Kubiatowicz (UCB)
– David Patterson (UCB)
• MIT material derived from course 6.823
• UCB material derived from course CS252