+
William Stallings
Computer Organization
and Architecture
10th Edition
© 2016 Pearson Education, Inc., Hoboken,
NJ. All rights reserved.
+ Chapter 14
Processor Structure and Function
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Pipelining Strategy
Similar to the use of
an assembly line in a
manufacturing plant
New inputs are
accepted at one end
before previously
accepted inputs
appear as outputs at
the other end
To apply this concept
to instruction
execution we must
recognize that an
instruction has a
number of stages
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Fetch
Instruction Instruction
(a) Simplified view
Result
Execute
Fetch
Instruction
Discard
Instruction
New address
Wait Wait
(b) Expanded view
Figure 14.9 Two-Stage Instruction Pipeline
Result
Execute
+ Additional Stages
 Fetch instruction (FI)
 Read the next expected
instruction into a buffer
 Decode instruction (DI)
 Determine the opcode and
the operand specifiers
 Calculate operands (CO)
 Calculate the effective
address of each source
operand
 This may involve
displacement, register
indirect, indirect, or other
forms of address calculation
 Fetch operands (FO)
 Fetch each operand from
memory
 Operands in registers need
not be fetched
 Execute instruction (EI)
 Perform the indicated
operation and store the
result, if any, in the specified
destination operand location
 Write operand (WO)
 Store the result in memory
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
1
Instruction 1
Time
FI
Instruction 2
Instruction 3
Instruction 4
Instruction 5
Instruction 6
Instruction 7
Instruction 8
Instruction 9
Figure 14.10 Timing Diagram for Instruction Pipeline Operation
2 3 4 5 6 7 8 9 10 11 12 13 14
DI CO FO EI WO
WO
FI DI CO FO EI
FI DI CO FO EI WO
FI DI CO FO EI WO
FI DI CO FO EI WO
FI DI CO FO EI WO
FI DI CO FO EI WO
FI DI CO FO EI WO
FI DI CO FO EI WO
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
1
Instruction 1
Time
Instruction 2
Instruction 3
Instruction 4
Instruction 5
Instruction 6
Instruction 7
Instruction 15
Instruction 16
Figure 14.11 The Effect of a Conditional Branch on Instruction Pipeline Operation
2 3 4 5 6 7 8 9 10
Branch Penalty
11 12 13 14
FI DI CO FO EI WO
FI DI CO FO EI WO
FI DI CO FO EI WO
FI DI CO FO
FI DI CO
FI DI
FI
FI DI CO FO EI WO
FI DI CO FO EI WO
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
No
Yes
Yes
No
FI
DI
CO
FO
EI
WO
Calculate
Operands
Fetch
Instruction
Decode
Instruction
Uncon-
ditional
Branch?
Branch
or
Inter
-rupt?
Figure 14.12 Six-Stage Instruction Pipeline
Write
Operands
Fetch
Operands
Execute
Instruction
Update
PC
Empty
Pipe
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
I16
I16
I16
I16
I16
I16
FI DI CO FO EI WO
I1
1
I2 I1
2
I3 I2 I1
3
I4 I3 I2 I1
4
I5 I4 I3 I2 I1
I6 I5 I4 I3 I2 I1
I7 I6 I5 I4 I3 I2
I8 I7 I6 I5 I4 I3
I9 I8 I7 I6 I5 I4
I9 I8 I7 I6 I5
I9 I8 I7 I6
I9 I8 I7
I9 I8
I9
5
6
7
8
9
10
11
12
13
14
Figure 14.13 An Alternative Pipeline Depiction
(a) No branches
FI DI CO FO EI WO
I1
1
I2 I1
2
I3 I2 I1
3
I4 I3 I2 I1
4
I5 I4 I3 I2 I1
I6 I5 I4 I3 I2 I1
I7 I6 I5 I4 I3 I2
I15
I15
I15
I15
I15
I15
I3
5
6
7
8
9
10
11
12
13
14
(b) With conditional branch
Time
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
1
0
2
4
6
8
10
12
0 5 10 15 20
0
2
4
6
8
10
12
14
2 4 8
Number of instructions (log scale)
(a)
Speedup
factor
Speedup
factor
Number of stages
(b)
Figure 14.14 Speedup Factors with Instruction Pipelining
16
k = 6 stages
n = 10 instructions
n = 20 instructions
n = 30 instructions
k = 9 stages
k = 12 stages
32 64 128
Pipeline Hazards
Occur when the
pipeline, or some
portion of the
pipeline, must stall
because conditions
do not permit
continued execution
Also referred to as a
pipeline bubble
There are three
types of hazards:
• Resource
• Data
• Control
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
1
I1
Clock cycle
(a) Five-stage pipeline, ideal case
Instrutcion
FI
I2
I3
I4
Figure 14.15 Example of Resource Hazard
2 3 4 5 6 7 8 9
DI FO EI WO
FI DI FO EI WO
FI DI FO EI WO
FI DI FO EI WO
1
I1
Clock cycle
(b) I1 source operand in memory
Instrutcion
FI
I2
I3
I4
2 3 4 5 6 7 8 9
DI FO EI WO
FI DI FO EI WO
FI
Idle DI FO EI WO
FI DI FO EI WO
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
1
ADD EAX, EBX
Clock cycle
FI
SUB ECX, EAX
I3
I4
Figure 14.16 Example of Data Hazard
2 3 4 5 6 7 8 9 10
DI FO EI WO
FI DI Idle FO EI WO
FI DI FO EI WO
FI DI FO EI WO
+ Types of Data Hazard
 Read after write (RAW), or true dependency
 An instruction modifies a register or memory location
 Succeeding instruction reads data in memory or register location
 Hazard occurs if the read takes place before write operation is
complete
 Write after read (WAR), or antidependency
 An instruction reads a register or memory location
 Succeeding instruction writes to the location
 Hazard occurs if the write operation completes before the read
operation takes place
 Write after write (WAW), or output dependency
 Two instructions both write to the same location
 Hazard occurs if the write operations take place in the reverse
order of the intended sequence
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Control Hazard
 Also known as a branch hazard
 Occurs when the pipeline makes the wrong decision on a
branch prediction
 Brings instructions into the pipeline that must subsequently be
discarded
 Dealing with Branches:
 Multiple streams
 Prefetch branch target
 Loop buffer
 Branch prediction
 Delayed branch
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Multiple Streams
A simple pipeline suffers a penalty for a
branch instruction because it must choose
one of two instructions to fetch next and may
make the wrong choice
A brute-force approach is to replicate the
initial portions of the pipeline and allow the
pipeline to fetch both instructions, making
use of two streams
Drawbacks:
• With multiple pipelines there are contention delays for
access to the registers and to memory
• Additional branch instructions may enter the pipeline
before the original branch decision is resolved
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Prefetch Branch Target
 When a conditional branch is recognized, the
target of the branch is prefetched, in addition to
the instruction following the branch
 Target is then saved until the branch instruction
is executed
 If the branch is taken, the target has already
been prefetched
 IBM 360/91 uses this approach
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Loop Buffer
 Small, very-high speed memory maintained by the instruction
fetch stage of the pipeline and containing the n most recently
fetched instructions, in sequence
 Benefits:
 Instructions fetched in sequence will be available without the usual
memory access time
 If a branch occurs to a target just a few locations ahead of the
address of the branch instruction, the target will already be in the
buffer
 This strategy is particularly well suited to dealing with loops
 Similar in principle to a cache dedicated to instructions
 Differences:
 The loop buffer only retains instructions in sequence
 Is much smaller in size and hence lower in cost
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Branch Prediction
 Various techniques can be used to predict whether a branch
will be taken:
1. Predict never taken
2. Predict always taken
3. Predict by opcode
1. Taken/not taken switch
2. Branch history table
 These approaches are static
 They do not depend on the execution
history up to the time of the
conditional branch instruction
 These approaches are dynamic
 They depend on the execution history
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Figure 14.18 Branch Prediction Flow Chart
Yes
Yes
Predict taken
Read next
conditional
branch instr
Branch
taken?
Predict taken
Read next
conditional
branch instr
Branch
taken?
No Yes
Yes
Predict not taken
Read next
conditional
branch instr
Branch
taken?
Predict not taken
Read next
conditional
branch instr
Branch
taken?
No
No
No
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Figure 14.19 Branch Prediction State Diagram
Not Taken
Not Taken
Not
Taken
Taken
Taken
Not Taken
Taken
Taken Predict
Taken
Predict
Taken
Predict
Not Taken
Predict
Not Taken
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Branch Miss
Handling
Select
E
Branch Miss
Handling
E
Memory
Select
Memory
IPFAR
IPFAR = instruction
prefix address register
Lookup
Update
state
Add new
entry
Redirect
Branch
instruction
address
Target
address State
Next sequential
address
Next sequential
address
(a) Predict never taken strategy
(b) Branch history table strategy
Figure 14.20 Dealing with Branches
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Intel 80486 Pipelining
Write back
Updates registers and status flags modified during the preceding execute stage
Execute
Stage includes ALU operations, cache access, and register update
Decode stage 2
Expands each opcode into control signals for the ALU
Also controls the computation of the more complex addressing
modes
Decode stage 1
All opcode and addressing-mode
information is decoded in the D1 stage
3 bytes of instruction are passed to the D1
stage from the prefetch buffers
D1 decoder can then direct the D2 stage to
capture the rest of the instruction
Fetch
Objective is to fill the prefetch buffers with new data as soon as the
old data have been consumed by the instruction decoder
Operates independently of the other stages to keep the prefetch
buffers full
+ Summary
 Processor organization
 Register organization
 User-visible registers
 Control and status registers
 Instruction cycle
 The indirect cycle
 Data flow
 The x86 processor family
 Register organization
 Interrupt processing
 Instruction pipelining
 Pipelining strategy
 Pipeline performance
 Pipeline hazards
 Dealing with branches
 Intel 80486 pipelining
 The Arm processor
 Processor organization
 Processor modes
 Register organization
 Interrupt processing
Chapter 14
Processor Structure
and Function
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Slides.pptx

  • 1.
    + William Stallings Computer Organization andArchitecture 10th Edition © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
  • 2.
    + Chapter 14 ProcessorStructure and Function © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
  • 3.
    Pipelining Strategy Similar tothe use of an assembly line in a manufacturing plant New inputs are accepted at one end before previously accepted inputs appear as outputs at the other end To apply this concept to instruction execution we must recognize that an instruction has a number of stages © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
  • 4.
    © 2016 PearsonEducation, Inc., Hoboken, NJ. All rights reserved. Fetch Instruction Instruction (a) Simplified view Result Execute Fetch Instruction Discard Instruction New address Wait Wait (b) Expanded view Figure 14.9 Two-Stage Instruction Pipeline Result Execute
  • 5.
    + Additional Stages Fetch instruction (FI)  Read the next expected instruction into a buffer  Decode instruction (DI)  Determine the opcode and the operand specifiers  Calculate operands (CO)  Calculate the effective address of each source operand  This may involve displacement, register indirect, indirect, or other forms of address calculation  Fetch operands (FO)  Fetch each operand from memory  Operands in registers need not be fetched  Execute instruction (EI)  Perform the indicated operation and store the result, if any, in the specified destination operand location  Write operand (WO)  Store the result in memory © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
  • 6.
    © 2016 PearsonEducation, Inc., Hoboken, NJ. All rights reserved. 1 Instruction 1 Time FI Instruction 2 Instruction 3 Instruction 4 Instruction 5 Instruction 6 Instruction 7 Instruction 8 Instruction 9 Figure 14.10 Timing Diagram for Instruction Pipeline Operation 2 3 4 5 6 7 8 9 10 11 12 13 14 DI CO FO EI WO WO FI DI CO FO EI FI DI CO FO EI WO FI DI CO FO EI WO FI DI CO FO EI WO FI DI CO FO EI WO FI DI CO FO EI WO FI DI CO FO EI WO FI DI CO FO EI WO
  • 7.
    © 2016 PearsonEducation, Inc., Hoboken, NJ. All rights reserved. 1 Instruction 1 Time Instruction 2 Instruction 3 Instruction 4 Instruction 5 Instruction 6 Instruction 7 Instruction 15 Instruction 16 Figure 14.11 The Effect of a Conditional Branch on Instruction Pipeline Operation 2 3 4 5 6 7 8 9 10 Branch Penalty 11 12 13 14 FI DI CO FO EI WO FI DI CO FO EI WO FI DI CO FO EI WO FI DI CO FO FI DI CO FI DI FI FI DI CO FO EI WO FI DI CO FO EI WO
  • 8.
    © 2016 PearsonEducation, Inc., Hoboken, NJ. All rights reserved. No Yes Yes No FI DI CO FO EI WO Calculate Operands Fetch Instruction Decode Instruction Uncon- ditional Branch? Branch or Inter -rupt? Figure 14.12 Six-Stage Instruction Pipeline Write Operands Fetch Operands Execute Instruction Update PC Empty Pipe
  • 9.
    © 2016 PearsonEducation, Inc., Hoboken, NJ. All rights reserved. I16 I16 I16 I16 I16 I16 FI DI CO FO EI WO I1 1 I2 I1 2 I3 I2 I1 3 I4 I3 I2 I1 4 I5 I4 I3 I2 I1 I6 I5 I4 I3 I2 I1 I7 I6 I5 I4 I3 I2 I8 I7 I6 I5 I4 I3 I9 I8 I7 I6 I5 I4 I9 I8 I7 I6 I5 I9 I8 I7 I6 I9 I8 I7 I9 I8 I9 5 6 7 8 9 10 11 12 13 14 Figure 14.13 An Alternative Pipeline Depiction (a) No branches FI DI CO FO EI WO I1 1 I2 I1 2 I3 I2 I1 3 I4 I3 I2 I1 4 I5 I4 I3 I2 I1 I6 I5 I4 I3 I2 I1 I7 I6 I5 I4 I3 I2 I15 I15 I15 I15 I15 I15 I3 5 6 7 8 9 10 11 12 13 14 (b) With conditional branch Time
  • 10.
    © 2016 PearsonEducation, Inc., Hoboken, NJ. All rights reserved. 1 0 2 4 6 8 10 12 0 5 10 15 20 0 2 4 6 8 10 12 14 2 4 8 Number of instructions (log scale) (a) Speedup factor Speedup factor Number of stages (b) Figure 14.14 Speedup Factors with Instruction Pipelining 16 k = 6 stages n = 10 instructions n = 20 instructions n = 30 instructions k = 9 stages k = 12 stages 32 64 128
  • 11.
    Pipeline Hazards Occur whenthe pipeline, or some portion of the pipeline, must stall because conditions do not permit continued execution Also referred to as a pipeline bubble There are three types of hazards: • Resource • Data • Control © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
  • 12.
    © 2016 PearsonEducation, Inc., Hoboken, NJ. All rights reserved. 1 I1 Clock cycle (a) Five-stage pipeline, ideal case Instrutcion FI I2 I3 I4 Figure 14.15 Example of Resource Hazard 2 3 4 5 6 7 8 9 DI FO EI WO FI DI FO EI WO FI DI FO EI WO FI DI FO EI WO 1 I1 Clock cycle (b) I1 source operand in memory Instrutcion FI I2 I3 I4 2 3 4 5 6 7 8 9 DI FO EI WO FI DI FO EI WO FI Idle DI FO EI WO FI DI FO EI WO
  • 13.
    © 2016 PearsonEducation, Inc., Hoboken, NJ. All rights reserved. 1 ADD EAX, EBX Clock cycle FI SUB ECX, EAX I3 I4 Figure 14.16 Example of Data Hazard 2 3 4 5 6 7 8 9 10 DI FO EI WO FI DI Idle FO EI WO FI DI FO EI WO FI DI FO EI WO
  • 14.
    + Types ofData Hazard  Read after write (RAW), or true dependency  An instruction modifies a register or memory location  Succeeding instruction reads data in memory or register location  Hazard occurs if the read takes place before write operation is complete  Write after read (WAR), or antidependency  An instruction reads a register or memory location  Succeeding instruction writes to the location  Hazard occurs if the write operation completes before the read operation takes place  Write after write (WAW), or output dependency  Two instructions both write to the same location  Hazard occurs if the write operations take place in the reverse order of the intended sequence © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
  • 15.
    + Control Hazard  Alsoknown as a branch hazard  Occurs when the pipeline makes the wrong decision on a branch prediction  Brings instructions into the pipeline that must subsequently be discarded  Dealing with Branches:  Multiple streams  Prefetch branch target  Loop buffer  Branch prediction  Delayed branch © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
  • 16.
    Multiple Streams A simplepipeline suffers a penalty for a branch instruction because it must choose one of two instructions to fetch next and may make the wrong choice A brute-force approach is to replicate the initial portions of the pipeline and allow the pipeline to fetch both instructions, making use of two streams Drawbacks: • With multiple pipelines there are contention delays for access to the registers and to memory • Additional branch instructions may enter the pipeline before the original branch decision is resolved © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
  • 17.
    + Prefetch Branch Target When a conditional branch is recognized, the target of the branch is prefetched, in addition to the instruction following the branch  Target is then saved until the branch instruction is executed  If the branch is taken, the target has already been prefetched  IBM 360/91 uses this approach © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
  • 18.
    + Loop Buffer  Small,very-high speed memory maintained by the instruction fetch stage of the pipeline and containing the n most recently fetched instructions, in sequence  Benefits:  Instructions fetched in sequence will be available without the usual memory access time  If a branch occurs to a target just a few locations ahead of the address of the branch instruction, the target will already be in the buffer  This strategy is particularly well suited to dealing with loops  Similar in principle to a cache dedicated to instructions  Differences:  The loop buffer only retains instructions in sequence  Is much smaller in size and hence lower in cost © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
  • 19.
    + Branch Prediction  Varioustechniques can be used to predict whether a branch will be taken: 1. Predict never taken 2. Predict always taken 3. Predict by opcode 1. Taken/not taken switch 2. Branch history table  These approaches are static  They do not depend on the execution history up to the time of the conditional branch instruction  These approaches are dynamic  They depend on the execution history © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
  • 20.
    © 2016 PearsonEducation, Inc., Hoboken, NJ. All rights reserved. Figure 14.18 Branch Prediction Flow Chart Yes Yes Predict taken Read next conditional branch instr Branch taken? Predict taken Read next conditional branch instr Branch taken? No Yes Yes Predict not taken Read next conditional branch instr Branch taken? Predict not taken Read next conditional branch instr Branch taken? No No No
  • 21.
    © 2016 PearsonEducation, Inc., Hoboken, NJ. All rights reserved. Figure 14.19 Branch Prediction State Diagram Not Taken Not Taken Not Taken Taken Taken Not Taken Taken Taken Predict Taken Predict Taken Predict Not Taken Predict Not Taken
  • 22.
    © 2016 PearsonEducation, Inc., Hoboken, NJ. All rights reserved. Branch Miss Handling Select E Branch Miss Handling E Memory Select Memory IPFAR IPFAR = instruction prefix address register Lookup Update state Add new entry Redirect Branch instruction address Target address State Next sequential address Next sequential address (a) Predict never taken strategy (b) Branch history table strategy Figure 14.20 Dealing with Branches
  • 23.
    © 2016 PearsonEducation, Inc., Hoboken, NJ. All rights reserved. Intel 80486 Pipelining Write back Updates registers and status flags modified during the preceding execute stage Execute Stage includes ALU operations, cache access, and register update Decode stage 2 Expands each opcode into control signals for the ALU Also controls the computation of the more complex addressing modes Decode stage 1 All opcode and addressing-mode information is decoded in the D1 stage 3 bytes of instruction are passed to the D1 stage from the prefetch buffers D1 decoder can then direct the D2 stage to capture the rest of the instruction Fetch Objective is to fill the prefetch buffers with new data as soon as the old data have been consumed by the instruction decoder Operates independently of the other stages to keep the prefetch buffers full
  • 24.
    + Summary  Processororganization  Register organization  User-visible registers  Control and status registers  Instruction cycle  The indirect cycle  Data flow  The x86 processor family  Register organization  Interrupt processing  Instruction pipelining  Pipelining strategy  Pipeline performance  Pipeline hazards  Dealing with branches  Intel 80486 pipelining  The Arm processor  Processor organization  Processor modes  Register organization  Interrupt processing Chapter 14 Processor Structure and Function © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.