134
EECC722 - Shaaban EECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Advanced Computer Architecture Course Goal: Understanding important and emerging design techniques, machine structures, technology factors, evaluation methods that will determine the form of programmable processors in 21st Century. Topics we will cover include: Support for Simultaneous Multithreading (SMT). Alpha EV8. Vector processing. Vector Intelligent RAM (VIRAM). Digital Signal Processing (DSP) & Media Architectures & Processors. Introduction to Multiprocessors: Single-Chip Multiprocessors: The Hydra Project Re-Configurable Computing and Processors. Advanced Branch Prediction Techniques. Storage: Redundant Arrays of Disks (RAID).

Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

  • Upload
    vobao

  • View
    215

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#1 Lec # 1 Fall 2000 9-6-2000

Advanced Computer ArchitectureAdvanced Computer ArchitectureCourse Goal:Understanding important and emerging design techniques, machinestructures, technology factors, evaluation methods that willdetermine the form of programmable processors in 21st Century.

Topics we will cover include:

• Support for Simultaneous Multithreading (SMT). Alpha EV8.• Vector processing. Vector Intelligent RAM (VIRAM).• Digital Signal Processing (DSP) & Media Architectures & Processors.• Introduction to Multiprocessors:

– Single-Chip Multiprocessors: The Hydra Project• Re-Configurable Computing and Processors.• Advanced Branch Prediction Techniques.• Storage: Redundant Arrays of Disks (RAID).

Page 2: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#2 Lec # 1 Fall 2000 9-6-2000

EECC551 ReviewEECC551 Review•• Recent Trends in Computer Design.Recent Trends in Computer Design.

•• A Hierarchy of Computer Design.A Hierarchy of Computer Design.

•• Computer Architecture’s Changing Definition.Computer Architecture’s Changing Definition.

•• Computer Performance Measures.Computer Performance Measures.

•• Instruction Pipelining.Instruction Pipelining.

•• Branch Prediction.Branch Prediction.

•• Instruction-Level Parallelism (ILP).Instruction-Level Parallelism (ILP).

•• Loop-Level Parallelism (LLP).Loop-Level Parallelism (LLP).

•• Dynamic Pipeline Scheduling.Dynamic Pipeline Scheduling.

•• Multiple Instruction Issue (CPI < 1): Multiple Instruction Issue (CPI < 1): Superscalar vsSuperscalar vs. VLIW. VLIW

•• Dynamic Hardware-Based SpeculationDynamic Hardware-Based Speculation•• Cache Design & Performance.Cache Design & Performance.

Page 3: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#3 Lec # 1 Fall 2000 9-6-2000

Recent Trends in Computer DesignRecent Trends in Computer Design• The cost/performance ratio of computing systems have seen a

steady decline due to advances in:

– Integrated circuit technology: decreasing feature size, λλ• Clock rate improves roughly proportional to improvement in λλ• Number of transistors improves proportional to λλ22 (or faster).

– Architectural improvements in CPU design.

• Microprocessor systems directly reflect IC improvement in termsof a yearly 35 to 55% improvement in performance.

• Assembly language has been mostly eliminated and replaced byother alternatives such as C or C++

• Standard operating Systems (UNIX, NT) lowered the cost ofintroducing new architectures.

• Emergence of RISC architectures and RISC-core architectures.

• Adoption of quantitative approaches to computer design based onempirical performance observations.

Page 4: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#4 Lec # 1 Fall 2000 9-6-2000

Microprocessor Architecture TrendsMicroprocessor Architecture Trends

CISC Machinesinstructions take variable times to complete

RISC Machines (microcode)simple instructions, optimized for speed

RISC Machines (pipelined)same individual instruction latency

greater throughput through instruction "overlap"

Superscalar Processorsmultiple instructions executing simultaneously

Multithreaded Processorsadditional HW resources (regs, PC, SP)each context gets processor for x cycles

VLIW"Superinstructions" grouped togetherdecreased HW control complexity

Single Chip Multiprocessorsduplicate entire processors

(tech soon due to Moore's Law)

SIMULTANEOUS MULTITHREADINGmultiple HW contexts (regs, PC, SP)each cycle, any context may execute

Page 5: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#5 Lec # 1 Fall 2000 9-6-2000

1988 Computer Food Chain1988 Computer Food Chain

PCWork-stationMini-

computer

Mainframe

Mini-supercomputer

Supercomputer

Massively ParallelProcessors

Page 6: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#6 Lec # 1 Fall 2000 9-6-2000

1997 Computer Food Chain1997 Computer Food Chain

PCWork-station

Mainframe

Supercomputer

Mini-supercomputerMassively Parallel Processors

Mini-computer

ServerPDA

Page 7: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#7 Lec # 1 Fall 2000 9-6-2000

Processor Performance TrendsProcessor Performance Trends

Microprocessors

Minicomputers

Mainframes

Supercomputers

Year

0.1

1

10

100

1000

1965 1970 1975 1980 1985 1990 1995 2000

Mass-produced microprocessors a cost-effective high-performancereplacement for custom-designed mainframe/minicomputer CPUs

Page 8: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#8 Lec # 1 Fall 2000 9-6-2000

Microprocessor PerformanceMicroprocessor Performance1987-971987-97

0

200

400

600

800

100 0

120 0

87 88 89 90 91 92 93 94 95 96 97

DEC Alpha 21264/600

DEC Alpha 5/500

DEC Alpha 5/300

DEC Alpha 4/266IBM POWER 100

DEC AXP/500

HP 9000/750

Sun-4/

260

IBMRS/

6000

MIPS M/

120

MIPS M

2000

Integer SPEC92 PerformanceInteger SPEC92 Performance

Page 9: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#9 Lec # 1 Fall 2000 9-6-2000

Microprocessor Frequency TrendMicroprocessor Frequency Trend

386486

Pentium(R)

Pentium Pro(R)

Pentium(R) II

MPC750604+604

601, 603

21264S

2126421164A

2116421064A

21066

10

100

1,000

10,000

1987

1989

1991

1993

1995

1997

1999

2001

2003

2005

Mh

z

1

10

100

Gat

e D

elay

s/ C

lock

Intel

IBM Power PC

DEC

Gate delays/clock

Processor freq scales by 2X per

generation

Ê Frequency doubles each generationË Number of gates/clock reduce by 25%

Page 10: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#10 Lec # 1 Fall 2000 9-6-2000

Microprocessor TransistorMicroprocessor TransistorCount Growth RateCount Growth Rate

Year

1000

10000

100000

1000000

10000000

100000000

1970 1975 1980 1985 1990 1995 2000

i80386

i4004

i8080

Pentium

i80486

i80286

i8086 Moore’sMoore’s Law: Law:2X transistors/ChipEvery 1.5 years

Alpha 21264: 15 millionPentium Pro: 5.5 millionPowerPC 620: 6.9 millionAlpha 21164: 9.3 millionSparc Ultra: 5.2 million

Moore’s Law

Page 11: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#11 Lec # 1 Fall 2000 9-6-2000

Increase of Capacity of VLSI Dynamic RAM ChipsIncrease of Capacity of VLSI Dynamic RAM Chips

size

Year

1000

10000

100000

1000000

10000000

100000000

1000000000

1970 1975 1980 1985 1990 1995 2000

year size(Megabit)

1980 0.0625

1983 0.251986 1

1989 4

1992 161996 64

1999 256

2000 1024

1.55X/yr,or doubling every 1.6years

Page 12: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#12 Lec # 1 Fall 2000 9-6-2000

Recent Technology TrendsRecent Technology Trends (Summary) (Summary)

Capacity Speed (latency)

Logic 2x in 3 years 2x in 3 years

DRAM 4x in 3 years 2x in 10 years

Disk 4x in 3 years 2x in 10 years

Page 13: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#13 Lec # 1 Fall 2000 9-6-2000

Computer Technology Trends:Computer Technology Trends:Evolutionary but Rapid ChangeEvolutionary but Rapid Change

• Processor:– 2X in speed every 1.5 years; 1000X performance in last decade.

• Memory:– DRAM capacity: > 2x every 1.5 years; 1000X size in last decade.– Cost per bit: Improves about 25% per year.

• Disk:– Capacity: > 2X in size every 1.5 years.– Cost per bit: Improves about 60% per year.– 200X size in last decade.– Only 10% performance improvement per year, due to mechanical

limitations.

• Expected State-of-the-art PC by end of year 2000 :– Processor clock speed: > 1500 MegaHertz (1.5 GigaHertz)– Memory capacity: > 500 MegaByte (0.5 GigaBytes)– Disk capacity: > 100 GigaBytes (0.1 TeraBytes)

Page 14: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#14 Lec # 1 Fall 2000 9-6-2000

A Hierarchy of Computer DesignA Hierarchy of Computer DesignLevel Name Modules Primitives Descriptive Media

1 Electronics Gates, FF’s Transistors, Resistors, etc. Circuit Diagrams

2 Logic Registers, ALU’s ... Gates, FF’s …. Logic Diagrams

3 Organization Processors, Memories Registers, ALU’s … Register Transfer

Notation (RTN)

4 Microprogramming Assembly Language Microinstructions Microprogram

5 Assembly language OS Routines Assembly language Assembly Language

programming Instructions Programs

6 Procedural Applications OS Routines High-level Language

Programming Drivers .. High-level Languages Programs

7 Application Systems Procedural Constructs Problem-Oriented

Programs

Low Level - Hardware

Firmware

High Level - Software

Page 15: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#15 Lec # 1 Fall 2000 9-6-2000

Hierarchy of Computer ArchitectureHierarchy of Computer Architecture

I/O systemInstr. Set Proc.

Compiler

OperatingSystem

Application

Digital DesignCircuit Design

Instruction Set Architecture

Firmware

Datapath & Control

Layout

Software

Hardware

Software/Hardware Boundary

High-Level Language Programs

Assembly LanguagePrograms

Microprogram

Register TransferNotation (RTN)

Logic Diagrams

Circuit Diagrams

Machine Language Program

Page 16: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#16 Lec # 1 Fall 2000 9-6-2000

Computer Architecture Vs. Computer Organization• The term Computer architecture is sometimes erroneously restricted

to computer instruction set design, with other aspects of computerdesign called implementation

• More accurate definitions:

– Instruction set architecture (ISA): The actual programmer-visible instruction set and serves as the boundary between thesoftware and hardware.

– Implementation of a machine has two components:

• Organization: includes the high-level aspects of a computer’sdesign such as: The memory system, the bus structure, theinternal CPU unit which includes implementations of arithmetic,logic, branching, and data transfer operations.

• Hardware: Refers to the specifics of the machine such as detailedlogic design and packaging technology.

• In general, Computer Architecture refers to the above three aspects:

Instruction set architecture, organization, and hardware.

Page 17: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#17 Lec # 1 Fall 2000 9-6-2000

Computer Architecture’s ChangingComputer Architecture’s ChangingDefinitionDefinition

• 1950s to 1960s:Computer Architecture Course = Computer Arithmetic

• 1970s to mid 1980s:Computer Architecture Course = Instruction Set Design,especially ISA appropriate for compilers

• 1990s:Computer Architecture Course = Design of CPU,memory system, I/O system, Multiprocessors

Page 18: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#18 Lec # 1 Fall 2000 9-6-2000

Recent Architectural ImprovementsRecent Architectural Improvements• Increased optimization and utilization of cache systems.

• Memory-latency hiding techniques.

• Optimization of pipelined instruction execution.

• Dynamic hardware-based pipeline scheduling.

• Improved handling of pipeline hazards.

• Improved hardware branch prediction techniques.

• Exploiting Instruction-Level Parallelism (ILP) in terms ofmultiple-instruction issue and multiple hardware functionalunits.

• Inclusion of special instructions to handle multimediaapplications.

• High-speed bus designs to improve data transfer rates.

Page 19: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#19 Lec # 1 Fall 2000 9-6-2000

Current Computer Architecture TopicsCurrent Computer Architecture Topics

Instruction Set Architecture

Pipelining, Hazard Resolution, Superscalar,Reordering, Branch Prediction, Speculation,VLIW, Vector, DSP, ...

Multiprocessing,Simultaneous CPU Multi-threading

Addressing,Protection,Exception Handling

L1 Cache

L2 Cache

DRAM

Disks, WORM, Tape

Coherence,Bandwidth,Latency

Emerging TechnologiesInterleavingBus protocols

RAID

VLSI

Input/Output and Storage

MemoryHierarchy

Pipelining and Instruction Level Parallelism (ILP)

Thread Level Parallelism (TLB)

Page 20: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#20 Lec # 1 Fall 2000 9-6-2000

• For a specific program compiled to run on a specific machine “A”,the following parameters are provided:

– The total instruction count of the program.– The average number of cycles per instruction (average CPI).– Clock cycle of machine “A”

• How can one measure the performance of this machine running thisprogram?

– Intuitively the machine is said to be faster or has better performancerunning this program if the total execution time is shorter.

– Thus the inverse of the total measured program execution time is apossible performance measure or metric:

PerformanceA = 1 / Execution TimeA

How to compare performance of different machines?

What factors affect performance? How to improve performance?

Computer Performance Measures:Computer Performance Measures:Program Execution TimeProgram Execution Time

Page 21: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#21 Lec # 1 Fall 2000 9-6-2000

CPU Execution Time: The CPU EquationCPU Execution Time: The CPU Equation• A program is comprised of a number of instructions, I

– Measured in: instructions/program

• The average instruction takes a number of cycles perinstruction (CPI) to be completed.– Measured in: cycles/instruction

• CPU has a fixed clock cycle time C = 1/clock rate– Measured in: seconds/cycle

• CPU execution time is the product of the above threeparameters as follows:

CPU Time = I x CPI x C

CPU time = Seconds = Instructions x Cycles x Seconds

Program Program Instruction Cycle

CPU time = Seconds = Instructions x Cycles x Seconds

Program Program Instruction Cycle

Page 22: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#22 Lec # 1 Fall 2000 9-6-2000

Factors Affecting CPU PerformanceFactors Affecting CPU PerformanceCPU time = Seconds = Instructions x Cycles x Seconds

Program Program Instruction Cycle

CPU time = Seconds = Instructions x Cycles x Seconds

Program Program Instruction Cycle

CPI Clock Cycle CInstruction Count I

Program

Compiler

Organization

Technology

Instruction SetArchitecture (ISA)

X

X

X

X

X

X

X X

X

Page 23: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#23 Lec # 1 Fall 2000 9-6-2000

Metrics of Computer PerformanceMetrics of Computer Performance

Compiler

Programming Language

Application

DatapathControl

Transistors Wires Pins

ISA

Function UnitsCycles per second (clock rate).

Megabytes per second.

Execution time: Target workload,SPEC95, etc.

Each metric has a purpose, and each can be misused.

(millions) of Instructions per second – MIPS(millions) of (F.P.) operations per second – MFLOP/s

Page 24: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#24 Lec # 1 Fall 2000 9-6-2000

Quantitative PrinciplesQuantitative Principlesof Computer Designof Computer Design

• Amdahl’s Law:

The performance gain from improving some portion ofa computer is calculated by:

Speedup = Performance for entire task using the enhancement

Performance for the entire task without using the enhancement

or Speedup = Execution time without the enhancement

Execution time for entire task using the enhancement

Page 25: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#25 Lec # 1 Fall 2000 9-6-2000

Performance Enhancement Calculations:Performance Enhancement Calculations: Amdahl's Law Amdahl's Law

• The performance enhancement possible due to a given designimprovement is limited by the amount that the improved feature is used

• Amdahl’s Law:

Performance improvement or speedup due to enhancement E:

Execution Time without E Performance with E Speedup(E) = -------------------------------------- = --------------------------------- Execution Time with E Performance without E

– Suppose that enhancement E accelerates a fraction F of theexecution time by a factor S and the remainder of the time isunaffected then:

Execution Time with E = ((1-F) + F/S) X Execution Time without E

Hence speedup is given by:

Execution Time without E 1Speedup(E) = --------------------------------------------------------- = -------------------- ((1 - F) + F/S) X Execution Time without E (1 - F) + F/S

Page 26: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#26 Lec # 1 Fall 2000 9-6-2000

Pictorial Depiction of Amdahl’s LawPictorial Depiction of Amdahl’s Law

Before: Execution Time without enhancement E:

Unaffected, fraction: (1- F)

After: Execution Time with enhancement E:

Enhancement E accelerates fraction F of execution time by a factor of S

Affected fraction: F

Unaffected, fraction: (1- F) F/S

Unchanged

Execution Time without enhancement E 1Speedup(E) = ------------------------------------------------------ = ------------------ Execution Time with enhancement E (1 - F) + F/S

Page 27: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#27 Lec # 1 Fall 2000 9-6-2000

Performance Enhancement ExamplePerformance Enhancement Example• For the RISC machine with the following instruction mix given earlier:

Op Freq Cycles CPI(i) % TimeALU 50% 1 .5 23%Load 20% 5 1.0 45%Store 10% 3 .3 14%

Branch 20% 2 .4 18%

• If a CPU design enhancement improves the CPI of load instructionsfrom 5 to 2, what is the resulting performance improvement from thisenhancement:

Fraction enhanced = F = 45% or .45

Unaffected fraction = 100% - 45% = 55% or .55

Factor of enhancement = 5/2 = 2.5

Using Amdahl’s Law: 1 1Speedup(E) = ------------------ = --------------------- = 1.37 (1 - F) + F/S .55 + .45/2.5

CPI = 2.2

Page 28: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#28 Lec # 1 Fall 2000 9-6-2000

Extending Amdahl's Law To Multiple EnhancementsExtending Amdahl's Law To Multiple Enhancements

• Suppose that enhancement Ei accelerates a fraction Fi of theexecution time by a factor Si and the remainder of the time isunaffected then:

∑ ∑+−=

i ii

ii

XSFF

SpeedupTime Execution Original)1

Time Execution Original

)((

∑ ∑+−=

i ii

ii S

FFSpeedup

)( )1

1

(

Note: All fractions refer to original execution time.

Page 29: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#29 Lec # 1 Fall 2000 9-6-2000

Amdahl's Law With Multiple Enhancements:Amdahl's Law With Multiple Enhancements:ExampleExample

• Three CPU performance enhancements are proposed with the followingspeedups and percentage of the code execution time affected:

Speedup1 = S1 = 10 Percentage1 = F1 = 20%

Speedup2 = S2 = 15 Percentage1 = F2 = 15%

Speedup3 = S3 = 30 Percentage1 = F3 = 10%

• While all three enhancements are in place in the new design, eachenhancement affects a different portion of the code and only oneenhancement can be used at a time.

• What is the resulting overall speedup?

• Speedup = 1 / [(1 - .2 - .15 - .1) + .2/10 + .15/15 + .1/30)] = 1 / [ .55 + .0333 ] = 1 / .5833 = 1.71

∑ ∑+−=

i ii

ii S

FFSpeedup

)( )1

1

(

Page 30: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#30 Lec # 1 Fall 2000 9-6-2000

Pictorial Depiction of ExamplePictorial Depiction of ExampleBefore: Execution Time with no enhancements: 1

After: Execution Time with enhancements: .55 + .02 + .01 + .00333 = .5833

Speedup = 1 / .5833 = 1.71

Note: All fractions refer to original execution time.

Unaffected, fraction: .55

Unchanged

Unaffected, fraction: .55 F1 = .2 F2 = .15 F3 = .1

S1 = 10 S2 = 15 S3 = 30

/ 10 / 30/ 15

Page 31: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#31 Lec # 1 Fall 2000 9-6-2000

Evolution of Instruction SetsEvolution of Instruction SetsSingle Accumulator (EDSAC 1950)

Accumulator + Index Registers(Manchester Mark I, IBM 700 series 1953)

Separation of Programming Model from Implementation

High-level Language Based Concept of a Family(B5000 1963) (IBM 360 1964)

General Purpose Register Machines

Complex Instruction Sets Load/Store Architecture

RISC

(Vax, Intel 432 1977-80) (CDC 6600, Cray 1 1963-76)

(Mips,SPARC,HP-PA,IBM RS6000, . . .1987)

Page 32: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#32 Lec # 1 Fall 2000 9-6-2000

A "Typical" RISCA "Typical" RISC

• 32-bit fixed format instruction (3 formats I,R,J)

• 32 32-bit GPR (R0 contains zero, DP take pair)

• 3-address, reg-reg arithmetic instruction

• Single address mode for load/store:base + displacement

– no indirection• Simple branch conditions (based on register values)

• Delayed branch

Page 33: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#33 Lec # 1 Fall 2000 9-6-2000

Example: MIPS (­ DLX)Example: MIPS (­ DLX)

Op

31 26 01516202125

Rs1 Rd immediate

Op

31 26 025

Op

31 26 01516202125

Rs1 Rs2

target

Rd Opx

Register-Register

561011

Register-Immediate

Op

31 26 01516202125

Rs1 Rs2/Opx immediate

Branch

Jump / Call

Page 34: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#34 Lec # 1 Fall 2000 9-6-2000

Pipelining: DefinitionsPipelining: Definitions• Pipelining is an implementation technique where multiple

operations on a number of instructions are overlapped inexecution.

• An instruction execution pipeline involves a number ofsteps, where each step completes a part of an instruction.

• Each step is called a pipe stage or a pipe segment.

• The stages or steps are connected one to the next to form apipe -- instructions enter at one end and progress throughthe stage and exit at the other end.

• Throughput of an instruction pipeline is determined byhow often an instruction exists the pipeline.

• The time to move an instruction one step down the line is isequal to the machine cycle and is determined by the stagewith the longest processing delay.

Page 35: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#35 Lec # 1 Fall 2000 9-6-2000

Simple DLX PipelinedSimple DLX PipelinedInstruction ProcessingInstruction Processing

Clock Number Time in clock cycles →Instruction Number 1 2 3 4 5 6 7 8 9

Instruction I IF ID EX MEM WB

Instruction I+1 IF ID EX MEM WB

Instruction I+2 IF ID EX MEM WB

Instruction I+3 IF ID EX MEM WBInstruction I +4 IF ID EX MEM WB

Time to fill the pipeline

DLX Pipeline Stages:

IF = Instruction Fetch

ID = Instruction Decode

EX = Execution

MEM = Memory Access

WB = Write Back

First instruction, ICompleted

Last instruction, I+4 completed

Page 36: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#36 Lec # 1 Fall 2000 9-6-2000

Page 37: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#37 Lec # 1 Fall 2000 9-6-2000

A Pipelined DLX DatapathA Pipelined DLX Datapath• Obtained from multi-cycle DLX datapath by adding buffer registers between pipeline stages• Assume register writes occur in first half of cycle and register reads occur in second half.

Page 38: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#38 Lec # 1 Fall 2000 9-6-2000

Pipeline HazardsPipeline Hazards• Hazards are situations in pipelining which prevent the next

instruction in the instruction stream from executing duringthe designated clock cycle.

• Hazards reduce the ideal speedup gained from pipeliningand are classified into three classes:

– Structural hazards: Arise from hardware resourceconflicts when the available hardware cannot support allpossible combinations of instructions.

– Data hazards: Arise when an instruction depends onthe results of a previous instruction in a way that isexposed by the overlapping of instructions in thepipeline

– Control hazards: Arise from the pipelining of conditionalbranches and other instructions that change the PC

Page 39: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#39 Lec # 1 Fall 2000 9-6-2000

Performance of Pipelines with StallsPerformance of Pipelines with Stalls

• Hazards in pipelines may make it necessary to stall thepipeline by one or more cycles and thus degradingperformance from the ideal CPI of 1.

CPI pipelined = Ideal CPI + Pipeline stall clock cycles per instruction

• If pipelining overhead is ignored and we assume that the stages areperfectly balanced then:

Speedup = CPI unpipelined / (1 + Pipeline stall cycles per instruction)

• When all instructions take the same number of cycles and is equal tothe number of pipeline stages then:

Speedup = Pipeline depth / (1 + Pipeline stall cycles per instruction)

Page 40: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#40 Lec # 1 Fall 2000 9-6-2000

Structural HazardsStructural Hazards• In pipelined machines overlapped instruction execution

requires pipelining of functional units and duplication ofresources to allow all possible combinations of instructionsin the pipeline.

• If a resource conflict arises due to a hardware resourcebeing required by more than one instruction in a singlecycle, and one or more such instructions cannot beaccommodated, then a structural hazard has occurred,for example:

– when a machine has only one register file write port

– or when a pipelined machine has a shared single-memory pipeline for data and instructions.

→ stall the pipeline for one cycle for register writes ormemory data access

Page 41: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#41 Lec # 1 Fall 2000 9-6-2000

DLX with MemoryDLX with MemoryUnit Structural HazardsUnit Structural Hazards

Page 42: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#42 Lec # 1 Fall 2000 9-6-2000

Resolving A StructuralResolving A StructuralHazard with StallingHazard with Stalling

Page 43: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#43 Lec # 1 Fall 2000 9-6-2000

Data HazardsData Hazards• Data hazards occur when the pipeline changes the order of

read/write accesses to instruction operands in such a way thatthe resulting access order differs from the original sequentialinstruction operand access order of the unpipelined machineresulting in incorrect execution.

• Data hazards usually require one or more instructions to bestalled to ensure correct execution.

• Example: ADD R1, R2, R3

SUB R4, R1, R5

AND R6, R1, R7

OR R8,R1,R9

XOR R10, R1, R11

– All the instructions after ADD use the result of the ADD instruction

– SUB, AND instructions need to be stalled for correct execution.

Page 44: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#44 Lec # 1 Fall 2000 9-6-2000

Figure 3.9 The use of the result of the ADD instruction in the next three instructionscauses a hazard, since the register is not written until after those instructions read it.

DLX Data DLX Data Hazard ExampleHazard Example

Page 45: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#45 Lec # 1 Fall 2000 9-6-2000

Minimizing Data hazard Stalls by ForwardingMinimizing Data hazard Stalls by Forwarding• Forwarding is a hardware-based technique (also called register

bypassing or short-circuiting) used to eliminate or minimizedata hazard stalls.

• Using forwarding hardware, the result of an instruction is copieddirectly from where it is produced (ALU, memory read portetc.), to where subsequent instructions need it (ALU inputregister, memory write port etc.)

• For example, in the DLX pipeline with forwarding:– The ALU result from the EX/MEM register may be forwarded or fed

back to the ALU input latches as needed instead of the registeroperand value read in the ID stage.

– Similarly, the Data Memory Unit result from the MEM/WB registermay be fed back to the ALU input latches as needed .

– If the forwarding hardware detects that a previous ALU operation is towrite the register corresponding to a source for the current ALUoperation, control logic selects the forwarded result as the ALU inputrather than the value read from the register file.

Page 46: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#46 Lec # 1 Fall 2000 9-6-2000

Minimizing Data hazard Stalls by ForwardingMinimizing Data hazard Stalls by Forwarding• Forwarding is a hardware-based technique (also called register

bypassing or short-circuiting) used to eliminate or minimizedata hazard stalls.

• Using forwarding hardware, the result of an instruction is copieddirectly from where it is produced (ALU, memory read portetc.), to where subsequent instructions need it (ALU inputregister, memory write port etc.)

• For example, in the DLX pipeline with forwarding:– The ALU result from the EX/MEM register may be forwarded or fed

back to the ALU input latches as needed instead of the registeroperand value read in the ID stage.

– Similarly, the Data Memory Unit result from the MEM/WB registermay be fed back to the ALU input latches as needed .

– If the forwarding hardware detects that a previous ALU operation is towrite the register corresponding to a source for the current ALUoperation, control logic selects the forwarded result as the ALU inputrather than the value read from the register file.

Page 47: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#47 Lec # 1 Fall 2000 9-6-2000

Pipelined DLX Pipelined DLXwith Forwardingwith Forwarding

Page 48: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#48 Lec # 1 Fall 2000 9-6-2000

Page 49: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#49 Lec # 1 Fall 2000 9-6-2000

Data Hazard ClassificationData Hazard Classification Given two instructions I, J, with I occurring before J

in an instruction stream:

• RAW (read after write): A true data dependence

J tried to read a source before I writes to it, so J incorrectly gets the old value.

• WAW (write after write): A name dependence

J tries to write an operand before it is written by I The writes end up being performed in the wrong order.

• WAR (write after read): A name dependence

J tries to write to a destination before it is read by I, so I incorrectly gets the new value.

• RAR (read after read): Not a hazard.

Page 50: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#50 Lec # 1 Fall 2000 9-6-2000

Data Hazard ClassificationData Hazard ClassificationI (Write)

Shared

Operand

J (Read)

Read after Write (RAW)

I (Read)

Shared

Operand

J (Write)

Write after Read (WAR)

I (Write)

Shared

Operand

J (Write)

Write after Write (WAW)

I (Read)

Shared

Operand

J (Read)

Read after Read (RAR) not a hazard

Page 51: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#51 Lec # 1 Fall 2000 9-6-2000

Data Hazards Requiring Stall CyclesData Hazards Requiring Stall Cycles

Page 52: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#52 Lec # 1 Fall 2000 9-6-2000

Compiler Instruction SchedulingCompiler Instruction Schedulingfor Data Hazard Stall Reductionfor Data Hazard Stall Reduction

• Many types of stalls resulting from data hazards are veryfrequent. For example:

A = B + C

produces a stall when loading the second data value (B).

• Rather than allow the pipeline to stall, the compiler couldsometimes schedule the pipeline to avoid stalls.

• Compiler pipeline or instruction scheduling involvesrearranging the code sequence (instruction reordering)to eliminate the hazard.

Page 53: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#53 Lec # 1 Fall 2000 9-6-2000

Compiler Instruction Scheduling ExampleCompiler Instruction Scheduling Example• For the code sequence:

a = b + c

d = e - f• Assuming loads have a latency of one clock cycle, the following

code or pipeline compiler schedule eliminates stalls:

a, b, c, d ,e, and f are in memory

Scheduled code with no stalls:

LW Rb,b

LW Rc,c

LW Re,e

ADD Ra,Rb,Rc

LW Rf,f

SW a,Ra

SUB Rd,Re,Rf

SW d,Rd

Original code with stalls:

LW Rb,bLW Rc,c

ADD Ra,Rb,Rc

SW a,Ra LW Re,e

LW Rf,f

SUB Rd,Re,RfSW d,Rd

Stall

Stall

Page 54: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#54 Lec # 1 Fall 2000 9-6-2000

Control HazardsControl Hazards

Branch instruction IF ID EX MEM WBBranch successor IF stall stall IF ID EX MEM WBBranch successor + 1 IF ID EX MEM WB Branch successor + 2 IF ID EX MEMBranch successor + 3 IF ID EXBranch successor + 4 IF IDBranch successor + 5 IF

Three clock cycles are wasted for every branch for current DLX pipeline

• When a conditional branch is executed it may change the PCand, without any special measures, leads to stalling the pipelinefor a number of cycles until the branch condition is known.

• In current DLX pipeline, the conditional branch is resolved inthe MEM stage resulting in three stall cycles as shown below:

Page 55: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#55 Lec # 1 Fall 2000 9-6-2000

Reducing Branch Stall CyclesReducing Branch Stall CyclesPipeline hardware measures to reduce branch stall cycles:

1- Find out whether a branch is taken earlier in the pipeline. 2- Compute the taken PC earlier in the pipeline.

In DLX:

– In DLX branch instructions BEQZ, BNEZ, test a registerfor equality to zero.

– This can be completed in the ID cycle by moving the zerotest into that cycle.

– Both PCs (taken and not taken) must be computed early.

– Requires an additional adder because the current ALU isnot useable until EX cycle.

– This results in just a single cycle stall on branches.

Page 56: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#56 Lec # 1 Fall 2000 9-6-2000

Modified DLX Pipeline:Modified DLX Pipeline: Conditional Branches Conditional Branches Completed in ID Stage Completed in ID Stage

Page 57: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#57 Lec # 1 Fall 2000 9-6-2000

Static Compiler Branch PredictionStatic Compiler Branch PredictionTwo basic methods exist to statically predict branches

at compile time:

1 By examination of program behavior and the use ofinformation collected from earlier runs of the program.

– For example, a program profile may show that most forwardbranches and backward branches (often forming loops) aretaken. The simplest scheme in this case is to just predict thebranch as taken.

2 To predict branches on the basis of branch direction,choosing backward branches as taken and forwardbranches as not taken.

Page 58: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#58 Lec # 1 Fall 2000 9-6-2000

Reduction of Branch Penalties:Reduction of Branch Penalties:Delayed BranchDelayed Branch

• When delayed branch is used, the branch is delayed by n cycles,following this execution pattern:

conditional branch instruction sequential successor1

sequential successor2

…….. sequential successorn

branch target if taken

• The sequential successor instruction are said to be in the branchdelay slots. These instructions are executed whether or not thebranch is taken.

• In Practice, all machines that utilize delayed branching have a single instruction delay slot.

• The job of the compiler is to make the successor instructions valid and useful instructions.

Page 59: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#59 Lec # 1 Fall 2000 9-6-2000

Delayed Branch ExampleDelayed Branch Example

Page 60: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#60 Lec # 1 Fall 2000 9-6-2000

Branch-delay Slot: Canceling BranchesBranch-delay Slot: Canceling Branches• In a canceling branch, a static compiler branch direction

prediction is included with the branch-delay slotinstruction.

• When the branch goes as predicted, the instruction in thebranch delay slot is executed normally.

• When the branch does not go as predicted the instructionis turned into a no-op.

• Canceling branches eliminate the conditions oninstruction selection in delay instruction strategies B, C

• The effectiveness of this method depends on whether wepredict the branch correctly.

Page 61: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#61 Lec # 1 Fall 2000 9-6-2000

Page 62: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#62 Lec # 1 Fall 2000 9-6-2000

Pipeline Performance ExamplePipeline Performance Example• Assume the following DLX instruction mix:

• What is the resulting CPI for the pipelined DLX withforwarding and branch address calculation in ID stagewhen using a branch not-taken scheme?

• CPI = Ideal CPI + Pipeline stall clock cycles per instruction

= 1 + stalls by loads + stalls by branches

= 1 + .3 x .25 x 1 + .2 x .45 x 1

= 1 + .075 + .09

= 1.165

Type FrequencyArith/Logic 40%Load 30% of which 25% are followed immediately by an instruction using the loaded valueStore 10%branch 20% of which 45% are taken

Page 63: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#63 Lec # 1 Fall 2000 9-6-2000

Pipelining and ExploitingPipelining and ExploitingInstruction-Level Parallelism (ILP)Instruction-Level Parallelism (ILP)

• Pipelining increases performance by overlapping theexecution of independent instructions.

• The CPI of a real-life pipeline is given by:

Pipeline CPI = Ideal Pipeline CPI + Structural Stalls + RAW Stalls

+ WAR Stalls + WAW Stalls + Control Stalls

• A basic instruction block is a straight-line code sequence withno branches in, except at the entry point, and no branchesout except at the exit point of the sequence .

• The amount of parallelism in a basic block is limited byinstruction dependence present and size of the basic block.

• In typical integer code, dynamic branch frequency is about15% (average basic block size of 7 instructions).

Page 64: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#64 Lec # 1 Fall 2000 9-6-2000

Increasing Instruction-Level ParallelismIncreasing Instruction-Level Parallelism• A common way to increase parallelism among instructions

is to exploit parallelism among iterations of a loop– (i.e Loop Level Parallelism, LLP).

• This is accomplished by unrolling the loop either staticallyby the compiler, or dynamically by hardware, whichincreases the size of the basic block present.

• In this loop every iteration can overlap with any otheriteration. Overlap within each iteration is minimal.

for (i=1; i<=1000; i=i+1;)

x[i] = x[i] + y[i];

• In vector machines, utilizing vector instructions is animportant alternative to exploit loop-level parallelism,

• Vector instructions operate on a number of data items. Theabove loop would require just four such instructions.

Page 65: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#65 Lec # 1 Fall 2000 9-6-2000

DLX Loop Unrolling ExampleDLX Loop Unrolling Example• For the loop:

for (i=1; i<=1000; i++)

x[i] = x[i] + s;

The straightforward DLX assembly code is given by:

Loop: LD F0, 0 (R1) ;F0=array element

ADDD F4, F0, F2 ;add scalar in F2

SD 0(R1), F4 ;store result

SUBI R1, R1, 8 ;decrement pointer 8 bytes

BENZ R1, Loop ;branch R1!=zero

Page 66: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#66 Lec # 1 Fall 2000 9-6-2000

DLX FP Latency AssumptionsDLX FP Latency Assumptions

• All FP units assumed to be pipelined.

• The following FP operations latencies are used:

Instruction Producing Result

FP ALU Op

FP ALU Op

Load Double

Load Double

Instruction Using Result

Another FP ALU Op

Store Double

FP ALU Op

Store Double

Latency InClock Cycles

3

2

1

0

Page 67: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#67 Lec # 1 Fall 2000 9-6-2000

Loop Unrolling Example (continued)Loop Unrolling Example (continued)• This loop code is executed on the DLX pipeline as follows:

With delayed branch scheduling(swap SUBI and SD)

Loop: LD F0, 0(R1) stall ADDD F4, F0, F2 SUBI R1, R1, #8 BENZ R1, Loop SD 8 (R1), F4

6 cycles per iteration

No scheduling Clock cycle

Loop: LD F0, 0(R1) 1

stall 2

ADDD F4, F0, F2 3

stall 4

stall 5

SD 0 (R1), F4 6

SUBI R1, R1, #8 7

BENZ R1, Loop 8

stall 9

9 cycles per iteration

Page 68: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#68 Lec # 1 Fall 2000 9-6-2000

Loop Unrolling Example (continued)Loop Unrolling Example (continued)• The resulting loop code when four copies of the loop body

are unrolled without reuse of registers:

No schedulingLoop: LD F0, 0(R1) ADDD F4, F0, F2 SD 0 (R1), F4 ; drop SUBI & BNEZ

LD F6, -8(R1) ADDD F8, F6, F2 SD -8 (R1), F8 ; drop SUBI & BNEZ

LD F10, -16(R1) ADDD F12, F10, F2 SD -16 (R1), F12 ; drop SUBI & BNEZ

LD F14, -24 (R1) ADDD F16, F14, F2 SD -24(R1), F16 SUBI R1, R1, #32 BNEZ R1, Loop

Three branches and threedecrements of R1 are eliminated.

Load and store addresses arechanged to allow SUBI instructionsto be merged.

The loop runs in 27 assuming LDtakes 2 cycles, each ADDD takes 3cycles, the branch 2 cycles, otherinstructions 1 cycle, or 6.8 cyclesfor each of the four elements.

Page 69: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#69 Lec # 1 Fall 2000 9-6-2000

Loop Unrolling Example (continued)Loop Unrolling Example (continued) When scheduled for DLXLoop: LD F0, 0(R1) LD F6,-8 (R1) LD F10, -16(R1) LD F14, -24(R1) ADDD F4, F0, F2 ADDD F8, F6, F2 ADDD F12, F10, F2 ADDD F16, F14, F2 SD 0(R1), F4 SD -8(R1), F8 SD -16(R1),F12 SUBI R1, R1,#32 BNEZ R1, Loop SD 8(R1), F16;8-32 =-24

The execution time of the loophas dropped to 14 cycles, or 3.5 clock cycles per element

compared to 6.8 before schedulingand 6 when scheduled but unrolled.

Unrolling the loop exposed more computation that can be scheduled to minimize stalls.

Page 70: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#70 Lec # 1 Fall 2000 9-6-2000

Loop-Level Parallelism (LLP) AnalysisLoop-Level Parallelism (LLP) Analysis• LLP analysis is normally done at the source level or close to

it since assembly language and target machine codegeneration introduces a loop-carried dependence, in theregisters used for addressing and incrementing.

• Instruction level parallelism (ILP) analysis is usually donewhen instructions are generated by the compiler.

• Analysis focuses on whether data accesses in later iterationsare data dependent on data values produced in earlieriterations.

e.g. in for (i=1; i<=1000; i++)

x[i] = x[i] + s;

the computation in each iteration is independent of the previous iterations and the loop is thus parallel. The use of X[i] twice is within a single iteration.

Page 71: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#71 Lec # 1 Fall 2000 9-6-2000

LLP Analysis ExamplesLLP Analysis Examples• In the loop:

for (i=1; i<=100; i=i+1) {

A[i+1] = A[i] + C[i]; /* S1 */

B[i+1] = B[i] + A[i+1];} /* S2 */

}

– S1 uses a value computed in an earlier iteration, sinceiteration i computes A[i+1] read in iteration i+1(loop-carried dependence, prevents parallelism).

– S2 uses the value A[i+1], computed by S1 in the sameiteration (not loop-carried dependence).

Page 72: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#72 Lec # 1 Fall 2000 9-6-2000

LLP Analysis ExamplesLLP Analysis Examples• In the loop:

for (i=1; i<=100; i=i+1) {

A[i] = A[i] + B[i]; /* S1 */

B[i+1] = C[i] + D[i]; /* S2 */

}

– S1 uses a value computed by S2 in a previous iteration (loop-carrieddependence)

– This dependence is not circular (neither statement depend on itself;S1 depends on S2 but S2 does not depend on S1.

– Can be made parallel by replacing the code with the following:

A[1] = A[1] + B[1];

for (i=1; i<=99; i=i+1) {

B[i+1] = C[i] + D[i];

A[i+1] = A[i+1] + B[i+1];

}

B[101] = C[100] + D[100];

Page 73: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#73 Lec # 1 Fall 2000 9-6-2000

Reduction of Data Hazards StallsReduction of Data Hazards Stallswith Dynamic Schedulingwith Dynamic Scheduling

• So far we have dealt with data hazards in instruction pipelines by:

– Result forwarding and bypassing to reduce latency and hide orreduce the effect of true data dependence.

– Hazard detection hardware to stall the pipeline starting with theinstruction that uses the result.

– Compiler-based static pipeline scheduling to separate the dependentinstructions minimizing actual hazards and stalls in scheduled code.

• Dynamic scheduling:– Uses a hardware-based mechanism to rearrange instruction

execution order to reduce stalls at runtime.

– Enables handling some cases where dependencies are unknown atcompile time.

– Similar to the other pipeline optimizations above, a dynamicallyscheduled processor cannot remove true data dependencies, but triesto avoid stalling.

Page 74: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#74 Lec # 1 Fall 2000 9-6-2000

Dynamic Pipeline Scheduling:Dynamic Pipeline Scheduling: The ConceptThe Concept

• Dynamic pipeline scheduling overcomes the limitations of in-orderexecution by allowing out-of-order instruction execution.

• Instruction are allowed to start executing out-of-order as soon astheir operands are available.

Example:

• This implies allowing out-of-order instruction commit (completion).

• May lead to imprecise exceptions if an instruction issued earlierraises an exception.

• This is similar to pipelines with multi-cycle floating point units.

In the case of in-order execution SUBD must wait for DIVD to complete which stalled ADDD before starting executionIn out-of-order execution SUBD can start as soon as the values of its operands F8, F14 are available.

DIVD F0, F2, F4

ADDD F10, F0, F8

SUBD F12, F8, F14

Page 75: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#75 Lec # 1 Fall 2000 9-6-2000

Dynamic Pipeline SchedulingDynamic Pipeline Scheduling• Dynamic instruction scheduling is accomplished by:

– Dividing the Instruction Decode ID stage into two stages:

• Issue: Decode instructions, check for structural hazards.• Read operands: Wait until data hazard conditions, if any,

are resolved, then read operands when available.

(All instructions pass through the issue stage in order but canbe stalled or pass each other in the read operands stage).

– In the instruction fetch stage IF, fetch an additional instructionevery cycle into a latch or several instructions into an instructionqueue.

– Increase the number of functional units to meet the demands ofthe additional instructions in their EX stage.

• Two dynamic scheduling approaches exist:– Dynamic scheduling with a Scoreboard used first in CDC6600– The Tomasulo approach pioneered by the IBM 360/91

Page 76: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#76 Lec # 1 Fall 2000 9-6-2000

Dynamic Scheduling With A ScoreboardDynamic Scheduling With A Scoreboard• The score board is a hardware mechanism that maintains an execution

rate of one instruction per cycle by executing an instruction as soon asits operands are available and no hazard conditions prevent it.

• It replaces ID, EX, WB with four stages: ID1, ID2, EX, WB

• Every instruction goes through the scoreboard where a record of datadependencies is constructed (corresponds to instruction issue).

• A system with a scoreboard is assumed to have several functional unitswith their status information reported to the scoreboard.

• If the scoreboard determines that an instruction cannot executeimmediately it executes another waiting instruction and keepsmonitoring hardware units status and decide when the instruction canproceed to execute.

• The scoreboard also decides when an instruction can write its results toregisters (hazard detection and resolution is centralized in thescoreboard).

Page 77: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#77 Lec # 1 Fall 2000 9-6-2000

Page 78: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#78 Lec # 1 Fall 2000 9-6-2000

Instruction Execution Stages with A ScoreboardInstruction Execution Stages with A Scoreboard1 Issue (ID1): If a functional unit for the instruction is available,

the scoreboard issues the instruction to the functional unit and updatesits internal data structure; structural and WAW hazards are resolvedhere. (this replaces part of ID stage in the conventional DLX pipeline).

2 Read operands (ID2): The scoreboard monitors theavailability of the source operands when no earlier active instructionwill written it and then tells the functional unit to read the the operandsfrom the registers and start execution (RAW hazards resolved heredynamically).

3 Execution (EX): The functional unit starts execution uponreceiving operands. When the results are ready it notifies thescoreboard (replaces EX in DLX).

4 Write result (WB): Once the scoreboard senses that a functionalunit completed execution, it checks for WAR hazards and stalls thecompleting instruction if needed otherwise the write back is completed.

Page 79: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#79 Lec # 1 Fall 2000 9-6-2000

Three Parts of the ScoreboardThree Parts of the Scoreboard1 Instruction status: Which of 4 steps the instruction is in.

2 Functional unit status: Indicates the state of the functionalunit (FU). Nine fields for each functional unit:

– Busy Indicates whether the unit is busy or not

– Op Operation to perform in the unit (e.g., + or –)

– Fi Destination register

– Fj, Fk Source-register numbers

– Qj, Qk Functional units producing source registers Fj, Fk

– Rj, Rk Flags indicating when Fj, Fk are ready

3 Register result status: Indicates which functional unit willwrite to each register, if one exists. Blank when no pendinginstructions will write that register.

Page 80: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#80 Lec # 1 Fall 2000 9-6-2000

Dynamic Scheduling:Dynamic Scheduling:The Tomasulo AlgorithmThe Tomasulo Algorithm

• Developed at IBM and first used in IBM 360/91 in 1966, about 3years after the debut of the scoreboard in the CDC 6600.

• Dynamically schedule the pipeline in hardware to reduce stalls.

• Differences between IBM 360 & CDC 6600 ISA.

– IBM has only 2 register specifiers/instr vs. 3 in CDC 6600.– IBM has 4 FP registers vs. 8 in CDC 6600.

• Current CPU architectures that can be considered descendants ofthe IBM 360/91 which implement and utilize a variation of theTomasulo Algorithm include:

Alpha 21264, HP 8000, MIPS 10000,

Pentium III, Xeon, PowerPC G3

Page 81: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#81 Lec # 1 Fall 2000 9-6-2000

Tomasulo Algorithm Vs. Scoreboard• Control & buffers distributed with Function Units (FU) Vs.

centralized in Scoreboard:– FU buffers are called “reservation stations” which have pending

instructions and operands and other instruction status info.• Registers in instructions are replaced by values or pointers to

reservation stations (RS):– This process is called register renaming.

– Avoids WAR, WAW hazards.

– Allows for hardware-based loop unrolling.– More reservation stations than registers are possible , leading to

optimizations that compilers can’t achieve and prevents the numberof registers from becoming a bottleneck.

• Instruction results go to FUs from RSs, not through registers, overCommon Data Bus (CDB) that broadcasts results to all FUs.

• Loads and Stores are treated as FUs with RSs as well.• Integer instructions can go past branches, allowing FP ops beyond

basic block in FP queue.

Page 82: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#82 Lec # 1 Fall 2000 9-6-2000

Dynamic Scheduling: The Tomasulo ApproachDynamic Scheduling: The Tomasulo Approach

Page 83: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#83 Lec # 1 Fall 2000 9-6-2000

Reservation Station ComponentsReservation Station Components• Op Operation to perform in the unit (e.g., + or –)

• Vj, Vk Value of Source operands– Store buffers have a single V field indicating result to be

stored.

• Qj, Qk Reservation stations producing source registers.(value to be written).– No ready flags as in Scoreboard; Qj,Qk=0 => ready.– Store buffers only have Qi for RS producing result.

• Busy: Indicates reservation station or FU is busy.

• Register result status: Indicates which functional unitwill write each register, if one exists.– Blank when no pending instructions exist that will write to

that register.

Page 84: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#84 Lec # 1 Fall 2000 9-6-2000

Three Stages of Tomasulo AlgorithmThree Stages of Tomasulo Algorithm1 Issue: Get instruction from pending Instruction Queue.

– Instruction issued to a free reservation station (no structural hazard).

– Selected RS is marked busy.– Control sends available instruction operands to assigned RS.

(renaming registers).

2 Execution (EX): Operate on operands.– When both operands are ready then start executing on assigned FU.

– If all operands are not ready, watch Common Data Bus (CDB) forneeded result.

3 Write result (WB): Finish execution.– Write result on Common Data Bus to all awaiting units– Mark reservation station as available.

• Normal data bus: data + destination (“go to” bus).• Common Data Bus (CDB): data + source (“come from” bus):

– 64 bits for data + 4 bits for Functional Unit source address.– Write if matches expected Functional Unit (produces result).– Does the result broadcast to waiting RSs.

Page 85: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#85 Lec # 1 Fall 2000 9-6-2000

Hardware Dynamic Branch PredictionHardware Dynamic Branch Prediction• Simplest method:

– A branch prediction buffer or Branch History Table (BHT)indexed by low address bits of the branch instruction.

– Each buffer location (or BHT entry) contains one bitindicating whether the branch was recently taken or not.

– Always mispredicts in first and last loop iterations.

• To improve prediction accuracy, two-bit prediction is used:– A prediction must miss twice before it is changed.

– Two-bit prediction is a specific case of n-bit saturatingcounter incremented when the branch is taken anddecremented otherwise.

• Based on observations, the performance of two-bit BHTprediction is comparable to that of n-bit predictors.

Page 86: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#86 Lec # 1 Fall 2000 9-6-2000

Basic Dynamic Two-Bit Branch Prediction:Basic Dynamic Two-Bit Branch Prediction:Two-bit Predictor State Two-bit Predictor State Transition Diagram Transition Diagram

Page 87: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#87 Lec # 1 Fall 2000 9-6-2000

Prediction AccuracyPrediction Accuracyof A 4096-Entry Basicof A 4096-Entry BasicDynamic Two-BitDynamic Two-BitBranch PredictorBranch Predictor

Page 88: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#88 Lec # 1 Fall 2000 9-6-2000

From The Analysis of Static Branch Prediction :From The Analysis of Static Branch Prediction :

DLX Performance Using Canceling Delay BranchesDLX Performance Using Canceling Delay Branches

Page 89: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#89 Lec # 1 Fall 2000 9-6-2000

Prediction Accuracy of BasicPrediction Accuracy of BasicTwo-Bit Branch Predictors:Two-Bit Branch Predictors:

4096-entry buffer Vs. An Infinite 4096-entry buffer Vs. An Infinite Buffer Under SPEC89Buffer Under SPEC89

Page 90: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#90 Lec # 1 Fall 2000 9-6-2000

Correlating BranchesCorrelating BranchesRecent branches are possibly correlated: The behavior ofrecently executed branches affects prediction of currentbranch.

Example:

Branch B3 is correlated with branches B1, B2. If B1, B2 areboth not taken, then B3 will be taken. Using only the behaviorof one branch cannot detect this behavior.

B1 if (aa==2) aa=0;B2 if (bb==2)

bb=0;

B3 if (aa!==bb){

SUBI R3, R1, #2 BENZ R3, L1 ; b1 (aa!=2) ADD R1, R0, R0 ; aa==0L1: SUBI R3, R1, #2 BNEZ R3, L2 ; b2 (bb!=2) ADD R2, R0, R0 ; bb==0L2 SUB R3, R1, R2 ; R3=aa-bb BEQZ R3, L3 ; b3 (aa==bb)

Page 91: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#91 Lec # 1 Fall 2000 9-6-2000

Correlating Two-Level DynamicCorrelating Two-Level DynamicBranch PredictorsBranch Predictors

• Improve branch prediction by looking not only at the historyof the branch in question but also at that of other branches:

– Record the pattern of the m most recently executedbranches as taken or not taken.

– Use that pattern to select the proper branch history table.

• In general, the notation: (m,n) predictor means:

– Record last m branches to select between 2m history tables.

– Each table uses n-bit counters (each table entry has n bits).

• Basic two-bit BHT is then a (0,2) predictor.

Page 92: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#92 Lec # 1 Fall 2000 9-6-2000

BNEZ R1, L1 ; branch b1 (d!=0)ADDI R1, R0, #1 ; d==0, so d=1

L1: SUBI R3, R1, #1BNEZ R3, L2 ; branch b2 (d!=1)

. . .L2:

DynamicBranchPrediction:Example

if (d==0) d=1;if (d==1)

Page 93: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#93 Lec # 1 Fall 2000 9-6-2000

BNEZ R1, L1 ; branch b1 (d!=0)ADDI R1, R0, #1 ; d==0, so d=1

L1: SUBI R3, R1, #1BNEZ R3, L2 ; branch b2 (d!=1)

. . .L2:

if (d==0) d=1;if (d==1)

DynamicBranchPrediction:Example(continued)

Page 94: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#94 Lec # 1 Fall 2000 9-6-2000

Organization of A CorrelatingTwo-level (2,2) Branch Predictor

Page 95: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#95 Lec # 1 Fall 2000 9-6-2000

Prediction AccuracyPrediction Accuracyof Two-Bit Dynamicof Two-Bit DynamicPredictors UnderPredictors UnderSPEC89SPEC89

BasicBasic BasicBasic Correlating Correlating Two-levelTwo-level

Page 96: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#96 Lec # 1 Fall 2000 9-6-2000

Further Reducing Control Stalls:Further Reducing Control Stalls: Branch-Target BuffersBranch-Target Buffers

Page 97: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#97 Lec # 1 Fall 2000 9-6-2000

Page 98: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#98 Lec # 1 Fall 2000 9-6-2000

Multiple Instruction Issue: CPI < 1Multiple Instruction Issue: CPI < 1• To improve a pipeline’s CPI to be better [less] than one, and to

utilize ILP better, a number of independent instructions have tobe issued in the same pipeline cycle.

• Multiple instruction issue processors are of two types:– Superscalar: A number of instructions (2-8) is issued in the same

cycle, scheduled statically by the compiler or dynamically(Tomasulo).

• PowerPC, Sun UltraSparc, Alpha, HP 8000

– VLIW (Very Long Instruction Word): A fixed number of instructions (3-6) are formatted as one long

instruction word or packet (statically scheduled by the compiler).– Joint HP/Intel agreement (Itanium, Q2 2000).– Intel Architecture-64 (IA-64) 64-bit address:

• Explicitly Parallel Instruction Computer (EPIC).

• Both types are limited by:– Available ILP in the program.– Specific hardware implementation difficulties.

Page 99: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#99 Lec # 1 Fall 2000 9-6-2000

Multiple Instruction Issue:Multiple Instruction Issue: SuperscalarSuperscalar Vs. Vs. VLIWVLIW

• Smaller code size.

• Binary compatibilityacross generations ofhardware.

• Simplified Hardware fordecoding, issuinginstructions.

• No Interlock Hardware(compiler checks?)

• More registers, butsimplified hardware forregister ports.

Page 100: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#100 Lec # 1 Fall 2000 9-6-2000

Superscalar Pipeline OperationSuperscalar Pipeline Operation

Page 101: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#101 Lec # 1 Fall 2000 9-6-2000

Intel/HP VLIW “Explicitly ParallelIntel/HP VLIW “Explicitly ParallelInstruction Computing (EPIC)”Instruction Computing (EPIC)”

• Three instructions in 128 bit “Groups”; instruction templatefields determines if instructions are dependent or independent– Smaller code size than old VLIW, larger than x86/RISC– Groups can be linked to show dependencies of more than three

instructions.

• 128 integer registers + 128 floating point registers– No separate register files per functional unit as in old VLIW.

• Hardware checks dependencies (interlocks ⇒ binary compatibility over time)

• Predicated execution: An implementation of conditionalinstructions used to reduce the number of conditional branchesused in the generated code ⇒ larger basic block size

• IA-64 : Name given to instruction set architecture (ISA);• Merced: Name of the first implementation (2000/2001??)

Page 102: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#102 Lec # 1 Fall 2000 9-6-2000

Intel/HP EPIC VLIW ApproachIntel/HP EPIC VLIW Approachoriginal sourceoriginal source

codecode

ExposeExposeInstructionInstructionParallelismParallelism

OptimizeOptimizeExploitExploit

Parallelism:Parallelism:GenerateGenerate

VLIWsVLIWs

compilercompiler

Instruction DependencyInstruction DependencyAnalysisAnalysis

Instruction 2Instruction 2 Instruction 1Instruction 1 Instruction 0Instruction 0 TemplateTemplate

128-bit bundle128-bit bundle

00127127

Page 103: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#103 Lec # 1 Fall 2000 9-6-2000

Unrolled Loop Example for Scalar PipelineUnrolled Loop Example for Scalar Pipeline

1 Loop: LD F0,0(R1)2 LD F6,-8(R1)3 LD F10,-16(R1)4 LD F14,-24(R1)5 ADDD F4,F0,F26 ADDD F8,F6,F27 ADDD F12,F10,F28 ADDD F16,F14,F29 SD 0(R1),F410 SD -8(R1),F811 SD -16(R1),F1212 SUBI R1,R1,#3213 BNEZ R1,LOOP14 SD 8(R1),F16 ; 8-32 = -24

14 clock cycles, or 3.5 per iteration

LD to ADDD: 1 CycleADDD to SD: 2 Cycles

Page 104: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#104 Lec # 1 Fall 2000 9-6-2000

Loop Unrolling in Superscalar Pipeline:Loop Unrolling in Superscalar Pipeline:(1 Integer, 1 FP/Cycle)(1 Integer, 1 FP/Cycle)

Integer instruction FP instruction Clock cycle

Loop: LD F0,0(R1) 1

LD F6,-8(R1) 2

LD F10,-16(R1) ADDD F4,F0,F2 3

LD F14,-24(R1) ADDD F8,F6,F2 4

LD F18,-32(R1) ADDD F12,F10,F2 5

SD 0(R1),F4 ADDD F16,F14,F2 6

SD -8(R1),F8 ADDD F20,F18,F2 7

SD -16(R1),F12 8

SD -24(R1),F16 9

SUBI R1,R1,#40 10

BNEZ R1,LOOP 11

SD -32(R1),F20 12

• Unrolled 5 times to avoid delays (+1 due to SS)• 12 clocks, or 2.4 clocks per iteration (1.5X)

Page 105: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#105 Lec # 1 Fall 2000 9-6-2000

Loop Unrolling in VLIW PipelineLoop Unrolling in VLIW Pipeline(2 Memory, 2 FP, 1 Integer / Cycle)(2 Memory, 2 FP, 1 Integer / Cycle)

Memory Memory FP FP Int. op/ Clockreference 1 reference 2 operation 1 op. 2 branchLD F0,0(R1) LD F6,-8(R1) 1

LD F10,-16(R1) LD F14,-24(R1) 2

LD F18,-32(R1) LD F22,-40(R1) ADDD F4,F0,F2 ADDD F8,F6,F2 3

LD F26,-48(R1) ADDD F12,F10,F2 ADDD F16,F14,F2 4

ADDD F20,F18,F2 ADDD F24,F22,F2 5

SD 0(R1),F4 SD -8(R1),F8 ADDD F28,F26,F2 6

SD -16(R1),F12 SD -24(R1),F16 7

SD -32(R1),F20 SD -40(R1),F24 SUBI R1,R1,#48 8

SD -0(R1),F28 BNEZ R1,LOOP 9

Unrolled 7 times to avoid delays 7 results in 9 clocks, or 1.3 clocks per iteration (1.8X) Average: 2.5 ops per clock, 50% efficiency Note: Needs more registers in VLIW (15 vs. 6 in Superscalar)

Page 106: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#106 Lec # 1 Fall 2000 9-6-2000

SuperscalarSuperscalar Dynamic Scheduling Dynamic Scheduling• How to issue two instructions and keep in-order instruction

issue for Tomasulo?

– Assume: 1 integer + 1 floating-point operations.

– 1 Tomasulo control for integer, 1 for floating point.

• Issue at 2X Clock Rate, so that issue remains in order.

• Only FP loads might cause a dependency between integer andFP issue:– Replace load reservation station with a load queue;

operands must be read in the order they are fetched.

– Load checks addresses in Store Queue to avoid RAWviolation

– Store checks addresses in Load Queue to avoid WAR,WAW.

• Called “Decoupled Architecture”

Page 107: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#107 Lec # 1 Fall 2000 9-6-2000

Multiple Instruction Issue ChallengesMultiple Instruction Issue Challenges• While a two-issue single Integer/FP split is simple in hardware, we get

a CPI of 0.5 only for programs with:

– Exactly 50% FP operations– No hazards of any type.

• If more instructions issue at the same time, greater difficulty of decodeand issue operations arise:– Even for a 2-issue superscalar machine, we have to examine 2

opcodes, 6 register specifiers, and decide if 1 or 2 instructions canissue.

• VLIW: tradeoff instruction space for simple decoding

– The long instruction word has room for many operations.

– By definition, all the operations the compiler puts in the longinstruction word are independent => execute in parallel

– E.g. 2 integer operations, 2 FP ops, 2 Memory refs, 1 branch• 16 to 24 bits per field => 7*16 or 112 bits to 7*24 or 168 bits wide

– Need compiling technique that schedules across several branches.

Page 108: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#108 Lec # 1 Fall 2000 9-6-2000

Limits to Multiple Instruction Issue MachinesLimits to Multiple Instruction Issue Machines• Inherent limitations of ILP:

– If 1 branch exist for every 5 instruction : How to keep a 5-wayVLIW busy?

– Latencies of unit adds complexity to the many operations that mustbe scheduled every cycle.

– For maximum performance multiple instruction issue requiresabout:

Pipeline Depth x No. Functional Units

independent instructions per cycle.

• Hardware implementation complexities:– Duplicate FUs for parallel execution are needed.

– More instruction bandwidth is essential.

– Increased number of ports to Register File (datapath bandwidth):• VLIW example needs 7 read and 3 write for Int. Reg.

& 5 read and 3 write for FP reg

– Increased ports to memory (to improve memory bandwidth).

– Superscalar decoding complexity may impact pipeline clock rate.

Page 109: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#109 Lec # 1 Fall 2000 9-6-2000

Hardware Support for Extracting More ParallelismHardware Support for Extracting More Parallelism• Compiler ILP techniques (loop-unrolling, software Pipelining etc.)

are not effective to uncover maximum ILP when branch behavioris not well known at compile time.

• Hardware ILP techniques:

– Conditional or Predicted Instructions: An extension to theinstruction set with instructions that turn into no-ops ifa condition is not valid at run time.

– Speculation: An instruction is executed before the processorknows that the instruction should execute to avoid controldependence stalls:

• Static Speculation by the compiler with hardware support:– The compiler labels an instruction as speculative and the hardware

helps by ignoring the outcome of incorrectly speculated instructions.

– Conditional instructions provide limited speculation.

• Dynamic Hardware-based Speculation:– Uses dynamic branch-prediction to guide the speculation process.

– Dynamic scheduling and execution continued passed a conditionalbranch in the predicted branch direction.

Page 110: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#110 Lec # 1 Fall 2000 9-6-2000

Conditional or Predicted InstructionsConditional or Predicted Instructions• Avoid branch prediction by turning branches into

conditionally-executed instructions:

if (x) then (A = B op C) else NOP– If false, then neither store result nor cause exception:

instruction is annulled (turned into NOP) .– Expanded ISA of Alpha, MIPS, PowerPC, SPARC

have conditional move.– HP PA-RISC can annul any following instruction.– IA-64: 64 1-bit condition fields selected so conditional execution of any instruction.

• Drawbacks of conditional instructions– Still takes a clock cycle even if “annulled”.

– Must stall if condition is evaluated late.– Complex conditions reduce effectiveness;

condition becomes known late in pipeline.

x

A = B op C

Page 111: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#111 Lec # 1 Fall 2000 9-6-2000

Dynamic Hardware-Based SpeculationDynamic Hardware-Based Speculation•• Combines:Combines:

– Dynamic hardware-based branch prediction– Dynamic Scheduling: of multiple instructions to issue and

execute out of order.

• Continue to dynamically issue, and execute instructions passeda conditional branch in the dynamically predicted branchdirection, before control dependencies are resolved.– This overcomes the ILP limitations of the basic block size.– Creates dynamically speculated instructions at run-time with no

compiler support at all.– If a branch turns out as mispredicted all such dynamically

speculated instructions must be prevented from changing the state ofthe machine (registers, memory).

• Addition of commit (retire or re-ordering) stage and forcinginstructions to commit in their order in the code (i.e to writeresults to registers or memory).

• Precise exceptions are possible since instructions must commit inorder.

Page 112: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#112 Lec # 1 Fall 2000 9-6-2000

Hardware-BasedHardware-BasedSpeculationSpeculation

Speculative Execution +Speculative Execution + Tomasulo’s Algorithm Tomasulo’s Algorithm

Page 113: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#113 Lec # 1 Fall 2000 9-6-2000

Four Steps of Speculative Tomasulo AlgorithmFour Steps of Speculative Tomasulo Algorithm1. Issue — Get an instruction from FP Op Queue

If a reservation station and a reorder buffer slot are free, issue instruction& send operands & reorder buffer number for destination (this stage issometimes called “dispatch”)

2. Execution — Operate on operands (EX) When both operands are ready then execute; if not ready, watch CDB for

result; when both operands are in reservation station, execute; checksRAW (sometimes called “issue”)

3. Write result — Finish execution (WB) Write on Common Data Bus to all awaiting FUs & reorder buffer; mark

reservation station available.

4. Commit — Update registers, memory with reorder buffer result– When an instruction is at head of reorder buffer & the result is present,

update register with result (or store to memory) and remove instructionfrom reorder buffer.

– A mispredicted branch at the head of the reorder buffer flushes thereorder buffer (sometimes called “graduation”)

⇒ Instructions issue, execute (EX), write result (WB) out of order but must commit in order.

Page 114: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#114 Lec # 1 Fall 2000 9-6-2000

Advantages of HW (Advantages of HW (TomasuloTomasulo) ) vsvs. SW. SW(VLIW) Speculation(VLIW) Speculation

• HW determines address conflicts.

• HW provides better branch prediction.

• HW maintains precise exception model.

• HW does not execute bookkeeping instructions.

• Works across multiple implementations

• SW speculation is much easier for HW design.

Page 115: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#115 Lec # 1 Fall 2000 9-6-2000

Memory Hierarchy: The motivationMemory Hierarchy: The motivation• The gap between CPU performance and main memory has been

widening with higher performance CPUs creating performancebottlenecks for memory access instructions.

• The memory hierarchy is organized into several levels of memory withthe smaller, more expensive, and faster memory levels closer to theCPU: registers, then primary Cache Level (L1), then additionalsecondary cache levels (L2, L3…), then main memory, then mass storage(virtual memory).

• Each level of the hierarchy is a subset of the level below: data found in alevel is also found in the level below but at lower speed.

• Each level maps addresses from a larger physical memory to a smallerlevel of physical memory.

• This concept is greatly aided by the principal of locality both temporaland spatial which indicates that programs tend to reuse data andinstructions that they have used recently or those stored in their vicinityleading to working set of a program.

Page 116: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#116 Lec # 1 Fall 2000 9-6-2000

Memory Hierarchy: MotivationMemory Hierarchy: MotivationProcessor-Memory (DRAM) Performance GapProcessor-Memory (DRAM) Performance Gap

µProc60%/yr.

DRAM7%/yr.

1

10

100

100019

8019

81

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

DRAM

CPU

1982

Processor-MemoryPerformance Gap:(grows 50% / year)

Per

form

ance

Page 117: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#117 Lec # 1 Fall 2000 9-6-2000

Cache Design & Operation IssuesCache Design & Operation Issues• Q1: Where can a block be placed cache?

(Block placement strategy & Cache organization)– Fully Associative, Set Associative, Direct Mapped.

• Q2: How is a block found if it is in cache?(Block identification)– Tag/Block.

• Q3: Which block should be replaced on a miss?(Block replacement)– Random, LRU.

• Q4: What happens on a write?(Cache write policy)– Write through, write back.

Page 118: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#118 Lec # 1 Fall 2000 9-6-2000

Cache Organization & Placement StrategiesCache Organization & Placement StrategiesPlacement strategies or mapping of a main memory data block onto

cache block frame addresses divide cache into three organizations:

1 Direct mapped cache: A block can be placed in one location only,given by:

(Block address) MOD (Number of blocks in cache)

2 Fully associative cache: A block can be placed anywhere incache.

3 Set associative cache: A block can be placed in a restricted set ofplaces, or cache block frames. A set is a group of block frames inthe cache. A block is first mapped onto the set and then it can beplaced anywhere within the set. The set in this case is chosen by:

(Block address) MOD (Number of sets in cache)

If there are n blocks in a set the cache placement is called n-wayset-associative.

Page 119: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#119 Lec # 1 Fall 2000 9-6-2000

Locating A Data Block in CacheLocating A Data Block in Cache• Each block frame in cache has an address tag.

• The tags of every cache block that might contain the required dataare checked in parallel.

• A valid bit is added to the tag to indicate whether this entry containsa valid address.

• The address from the CPU to cache is divided into:

– A block address, further divided into:

• An index field to choose a block set in cache.

(no index field when fully associative).

• A tag field to search and match addresses in the selected set.

– A block offset to select the data from the block.

Block Address BlockOffsetTag Index

Page 120: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#120 Lec # 1 Fall 2000 9-6-2000

Address Field SizesAddress Field Sizes

Block Address BlockOffsetTag Index

Block offset size = log2(block size)

Index size = log2(Total number of blocks/associativity)

Tag size = address size - index size - offset sizeTag size = address size - index size - offset size

Physical Address Generated by CPU

Page 121: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#121 Lec # 1 Fall 2000 9-6-2000

Direct-Mapped CacheDirect-Mapped CacheExampleExample

A d d re ss (s h o w i n g b it p o s i t io n s )

2 0 1 0

B yte

o ffs e t

V a lid T a g D a taIn d e x

0

1

2

1 0 2 1

1 0 2 2

1 0 2 3

T a g

In d e x

H it D a ta

2 0 3 2

3 1 3 0 1 3 1 2 1 1 2 1 0

1024 BlocksEach block = one word

Can cache up to232 bytes of memory

Index fieldTag field

Page 122: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#122 Lec # 1 Fall 2000 9-6-2000

Four-Way Set Associative Cache:Four-Way Set Associative Cache:DLX Implementation ExampleDLX Implementation Example

Address

22 8

V TagIndex

0

1

2

253

254

255

Data V Tag Data V Tag Data V Tag Data

3222

4- to-1 m ultiplexo r

Hit Da ta

123891011123 031 0

IndexField

TagField

256 sets1024 block frames

Page 123: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#123 Lec # 1 Fall 2000 9-6-2000

Miss Rates for Caches with Different Size,Miss Rates for Caches with Different Size,Associativity & Replacement AlgorithmAssociativity & Replacement Algorithm

Sample DataSample Data

Associativity: 2-way 4-way 8-way

Size LRU Random LRU Random LRU Random

16 KB 5.18% 5.69% 4.67% 5.29% 4.39% 4.96%

64 KB 1.88% 2.01% 1.54% 1.66% 1.39% 1.53%

256 KB 1.15% 1.17% 1.13% 1.13% 1.12% 1.12%

Page 124: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#124 Lec # 1 Fall 2000 9-6-2000

Cache Read/Write OperationsCache Read/Write Operations• Statistical data suggest that reads (including instruction

fetches) dominate processor cache accesses (writes accountfor 25% of data cache traffic).

• In cache reads, a block is read at the same time while thetag is being compared with the block address. If the read isa hit the data is passed to the CPU, if a miss it ignores it.

• In cache writes, modifying the block cannot begin until thetag is checked to see if the address is a hit.

• Thus for cache writes, tag checking cannot take place inparallel, and only the specific data (between 1 and 8 bytes)requested by the CPU can be modified.

• Cache is classified according to the write and memoryupdate strategy in place: write through, or write back.

Page 125: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#125 Lec # 1 Fall 2000 9-6-2000

Cache Write StrategiesCache Write Strategies1 Write Though: Data is written to both the cache block and to

a block of main memory.

– The lower level always has the most updated data; an importantfeature for I/O and multiprocessing.

– Easier to implement than write back.

– A write buffer is often used to reduce CPU write stall while datais written to memory.

2 Write back: Data is written or updated only to the cacheblock. The modified cache block is written to main memorywhen it’s being replaced from cache.

– Writes occur at the speed of cache

– A status bit called a dirty bit, is used to indicate whether the blockwas modified while in cache; if not the block is not written tomain memory.

– Uses less memory bandwidth than write through.

Page 126: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#126 Lec # 1 Fall 2000 9-6-2000

Cache Write Miss PolicyCache Write Miss Policy• Since data is usually not needed immediately on a write miss

two options exist on a cache write miss:

Write Allocate:

The cache block is loaded on a write miss followed by write hit actions.

No-Write Allocate:

The block is modified in the lower level (lower cache level, or main

memory) and not loaded into cache.

While any of the above two write miss policies can be used with either write back or write through:

• Write back caches use write allocate to capture subsequent writes to the block in cache.

• Write through caches usually use no-write allocate since subsequent writes still have to go to memory.

Page 127: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#127 Lec # 1 Fall 2000 9-6-2000

Cache PerformanceCache PerformanceFor a CPU with a single level (L1) of cache and no stalls for

cache hits:

CPU time = (CPU execution clock cycles +

Memory stall clock cycles) x clock cycle time

Memory stall clock cycles = (Reads x Read miss rate x Read miss penalty) + (Writes x Write miss rate x Write miss penalty)

If write and read miss penalties are the same:

Memory stall clock cycles = Memory accesses x Miss rate x Miss penalty

With ideal memory

Page 128: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#128 Lec # 1 Fall 2000 9-6-2000

Cache Performance ExampleCache Performance Example• Suppose a CPU executes at Clock Rate = 200 MHz (5 ns per cycle)

with a single level of cache.

• CPIexecution = 1.1

• Instruction mix: 50% arith/logic, 30% load/store, 20% control

• Assume a cache miss rate of 1.5% and a miss penalty of 50 cycles.

CPI = CPIexecution + mem stalls per instruction

Mem Stalls per instruction =

Mem accesses per instruction x Miss rate x Miss penalty

Mem accesses per instruction = 1 + .3 = 1.3

Mem Stalls per instruction = 1.3 x .015 x 50 = 0.975

CPI = 1.1 + .975 = 2.075

The ideal CPU with no misses is 2.075/1.1 = 1.88 times faster

Instruction fetch Load/store

Page 129: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#129 Lec # 1 Fall 2000 9-6-2000

Typical Cache Performance DataTypical Cache Performance DataUsing SPEC92Using SPEC92

Page 130: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#130 Lec # 1 Fall 2000 9-6-2000

Cache Performance ExampleCache Performance ExampleTo compare the performance of either using a 16-KB instruction cache and

a 16-KB data cache as opposed to using a unified 32-KB cache, we assume a hit to

take one clock cycle and a miss to take 50 clock cycles, and a load or store to take

one extra clock cycle on a unified cache, and that 75% of memory accesses are

instruction references. Using the miss rates for SPEC92 we get:

Overall miss rate for a split cache = (75% x 0.64%) + (25% x 6.74%) = 2.1%

From SPEC92 data a unified cache would have a miss rate of 1.99%

Average memory access time =

= % instructions ( Read hit time + Read miss rate x Miss penalty)

+ % data x ( Write hit time + Write miss rate x Miss penalty)

For split cache:

Average memory access timesplit = 75% x ( 1 + 0.64 x 50) + (1+6.47%x50) = 2.05

For unified cache:

Average memory access timeunified = 75% x ( 1 + 1.99%) x 50) +

25% x ( 1 + 1+ 1.99% x 50)

= 2.24 cycles

Page 131: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#131 Lec # 1 Fall 2000 9-6-2000

3 Levels of Cache3 Levels of Cache

CPU

L1 Cache

L2 Cache

L3 Cache

Main Memory

Hit Rate= H1, Hit time = 1 cycle

Hit Rate= H2, Hit time = T2 cycles

Hit Rate= H3, Hit time = T3

Memory access penalty, M

Page 132: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#132 Lec # 1 Fall 2000 9-6-2000

CPUtime = IC x (CPIexecution + Mem Stall cycles per instruction) x CMem Stall cycles per instruction = Mem accesses per instruction x Stall cycles per access

• For a system with 3 levels of cache, assuming no penaltywhen found in L1 cache:

Stall cycles per memory access =

[miss rate L1] x [ Hit rate L2 x Hit time L2

+ Miss rate L2 x (Hit rate L3 x Hit time L3

+ Miss rate L3 x Memory access penalty) ] =

[1 - H1] x [ H2 x T2

+ ( 1-H2 ) x (H3 x (T2 + T3)

+ (1 - H3) x M) ]

3-Level Cache Performance3-Level Cache Performance

Page 133: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#133 Lec # 1 Fall 2000 9-6-2000

Three Level Cache Performance ExampleThree Level Cache Performance Example• CPU with CPIexecution = 1.1 running at clock rate = 500 MHZ• 1.3 memory accesses per instruction.• L1 cache operates at 500 MHZ with a miss rate of 5%• L2 cache operates at 250 MHZ with miss rate 3%, (T2 = 2 cycles)• L3 cache operates at 100 MHZ with miss rate 1.5%, (T3 = 5 cycles)

• Memory access penalty, M= 100 cycles. Find CPI.

• With single L1, CPI = 1.1 + 1.3 x .05 x 100 = 7.6CPI = CPIexecution + Mem Stall cycles per instructionMem Stall cycles per instruction = Mem accesses per instruction x Stall cycles per access

Stall cycles per memory access = [1 - H1] x [ H2 x T2 + ( 1-H2 ) x (H3 x (T2 + T3)

+ (1 - H3) x M) ]

= [.05] x [ .97 x 2 + (.03) x ( .985 x (2+5)

+ .015 x 100)]

= .05 x [ 1.94 + .03 x ( 6.895 + 1.5) ]

= .05 x [ 1.94 + .274] = .11

• CPI = 1.1 + 1.3 x .11 = 1.24

Page 134: Advanced Computer Architecture - Rochester …meseec.ce.rit.edu/eecc722-fall2000/722-9-6-2000.pdfEECC722 - Shaaban #1 Lec # 1 Fall 2000 9-6-2000 Advanced Computer Architecture Course

EECC722 - ShaabanEECC722 - Shaaban#134 Lec # 1 Fall 2000 9-6-2000

Cache Optimization SummaryCache Optimization SummaryTechnique MR MP HT Complexity

Larger Block Size + – 0Higher Associativity + – 1Victim Caches + 2Pseudo-Associative Caches + 2HW Prefetching of Instr/Data + 2Compiler Controlled Prefetching + 3Compiler Reduce Misses + 0

Priority to Read Misses + 1Subblock Placement + + 1Early Restart & Critical Word 1st + 2Non-Blocking Caches + 3Second Level Caches + 2

Small & Simple Caches – + 0Avoiding Address Translation + 2Pipelining Writes + 1

Mis

s ra

teH

it t

ime

Mis

sP

enal

ty