Fetch and Decode in Computer Architecture
Fetch and Decode in Computer Architecture
[Link]
PC Instruction
Decode
i-cache packet
r
Clock
Clock
Fetch 4 instructions
Predict the addresses
of the next 4
Fetch 4 instructions
Predict the addresses
of the next 4
Fetch 4 instructions
Predict the addresses
of the next 4
Predict if an instruction is a
branch or not.
If it is a branch, predict is direction.
Predict its target.
4. Decode Stage
Insights
• Given a PC, the status of the instruction (branch or not) does not
change.
• Can we use this information?
Approach
• The last time that we had seen a branch
remember its PC
• Next time we see a PC, check if we have seen it before
• Also remember the type of the branch:
• Unconditional branch
• Conditional branch
depends on the result of a previous compare instruction
• Function call
• Return
Type of the
instruction
PC
32 - n n
2n entries
Instruction Status
Table (IST)
Why 10 bits?
For a 32-bit PC, we cannot have a 232 entry table.
• Too big
• Too slow
• Too much of power
• Too much of area
We need to manage with a smaller table
Defined as destructive
inteference
PC
32 - n n
2n entries
Branch
32 – n
type
4. Decode Stage
C Assembly
void foo() { .foo:
for (i=0; i < 5; i++) { mov r0, 0
... .loop: cmp r0, 5
} beq .exit
} add r0, r0, 1
Predict b .loop
Outcome of the
branch
PC
32 - n n
2n entries
Predictor Table
Saturating
Counter Increment when taken
00 01 10 11
00 01 10 11
Outcome of the
Logic branch
PC
32 - n n
2n entries
2-bit saturating
Predictor Table counter
.foo:
mov r0, 0
.loop: cmp r0, 5
beq .exit
add r0, r0, 1
b .loop
Global history
register (GHR)
• Let us have a shift register that records the history of the last n branches
encountered by the processor
• We have one bit for each branch (regardless of the PC)
• We record: 1 taken branch, 0 not taken branch
• Let us consider a 2-bit shift register also known as the GHR
• GHR Global History Register
• We have two conditional branches in the running example
• beq .exit
• bne .inc
Use the GHR information to also decide the direction of the branch.
PC
32 - n n
2n+k entries
k-bit GHR
GAg GAp
PAg PAp
Only the
global history
Outcome of the
k Logic
branch
2k entries
k-bit GHR
Outcome of the
k Logic
branch
PC 2k entries
n1
k-bit GHR
k-bit GHR
PC
32 - n n
2n+k entries
n1
k-bit GHR
k-bit GHR
PC
32 - n n 2max(n,k) entries
k-bit GHR
Choose
Predictor 1 Predictor 2
Prediction
Choose
PC
n bits Predictor 1 Predictor 2
Prediction
• Find the entry in the choice array
• Choose the predictor based on the value of a saturating counter
• Use its prediction because of the saturating counter, we
automatically choose the predictor that performs the best for a given
PC.
Training
• Train both the predictors
• Train the entry in the choice array if we chose the wrong predictor
• If both the predictions are the same, we don’t modify the choice
array
• If they differ, we increment the counter if Predictor 1 was correct and
decrement it if it was incorrect.
Reduce aliasing
• Incorporate a few tag bits in each entry of the predictor
• Have multiple predictors for different subsets of branches
• Include a bias bit with every branch (its most likely direction), and
just predict if we need to agree with the bias bit or not (agree
predictor)
Better use of bits
• Separate high confidence and low confidence branches. Dedicate
more bits to low confidence branches
Examples of other predictors:
• Bi-mode, Agree, Skew, YAGS, TAGE
Func 1 Pred1
Prediction
Majority
Func 2 Pred2
Func 3 Pred3
4. Decode Stage
PC
2n entries
32 - n n
Branch
32 – n target
type
call call
0xFC0 call 0xBF8
0xFF4
ret ret ret
call call
0xFC0 call 0xBF8
0xBF8
0xFF4
0xFF4
ret ret ret
Stack
RAS
4. Decode Stage
CISC Instructions
Decode
CISC RISC
unit
instructions instructions (μOPs)
CISC
instruction Decoder μOPs
8 bits
three-ROP
start bit two-ROP
end bit functional
bit
Instruction
csp packet
The decode
unit Subsequent
pipeline stages
ld sp, 12[r1]
Dictionary
To the fetch
stage
i-cache