Professional Documents
Culture Documents
Computer Architecture
Lecture 15: Branch Prediction and
Interrupts/Exceptions
https://www.cse.iitb.ac.in/~biswa/courses/CS230/autumn23/main.html
https://www.cse.iitb.ac.in/~biswa/
Phones
(smart/non-smart)
on silence plz,
Thanks
Computer Architecture 2
2-bit Bimodal Predictors: A bit better
actually actually
taken !taken 2-bit saturating counter:
pred pred
Taken Taken Values from 00 to 11
11 10
actually
actually taken actually
taken !taken
actually
pred !taken pred
!taken !taken
actually actually
Counter greater than 01 00
!taken
taken
equal to 10,
prediction: taken Computer Architecture 3
No history predictor: 2 bit predictor
k bit
Computer Architecture 6
Two Level Branch Predictors
First level: Global branch history register (N bits)
The direction of last N branches
Second level: Table of saturating counters for each history entry
The direction the branch took the last time the same history was seen
00 …. 00
1 1 ….. 1 0 00 …. 01
previous one 00 …. 10
GHR
(global history register) index
GHR
(global history register) index
0 1
00 …. 00
00 …. 01
00 …. 10
2p 1 1 ….. 1 0 2m
11 …. 11
BHT PHT
(PC >> 2) & (2p -1)
BHT: Branch history table
Mostly K=2, m =12 for example
Computer Architecture 9
Set of branches: One register for correlated
ones m bit k bit
00 …. 00
00 …. 01
00 …. 10
2p
1 1 ….. 1 0 2m
B1: if (aa == 2) aa = 0;
B2: if (bb == 2); bb=0;
11 …. 11
B3: if (aa != bb) { … }
BHT PHT
(PC % 2p )
Can lead to positive/negative/neutral interference
Computer Architecture 10
Gshare is the answer
k bit
m bit
00 …. 00
1 1 ….. 1 0 00 …. 01
00 …. 10
2m
PC >>2 & 2m -1
11 …. 11
Computer Architecture 12
Issue
I1 F D E
I2 F D E
I3 F D E
Computer Architecture 14
BTB (Target Address Predictor)
Address of branch instruction Branch instruction
0b0110[...]01001000 BNEZ R1 Loop
Branch BTB is probed in
Branch Target Buffer (BTB) History Table the fetch stage
30-bit address tag target address (BHT)
along with the
direction predictor.
A hit in the BTB
0b0110[...]0010 PC + 4 + Loop 2 state means the PC is a
bits
branch PC.
Computer Architecture 15
Exception/Interrupt
Computer Architecture 16
Interrupt Handling
Ii-1 HI1
interrupt
program Ii HI2 handler
Ii+1 HIn
Computer Architecture 19
Exception program counter (EPC):
address of the offending instruction,
Computer Architecture 20
Processor:
Saves EPC
and the OS Disables further interrupts
Computer Architecture 21
OS:
Handshake Looks at the cause of the exception
between Interrupt handler saves the GPRs
processor
Handles the interrupt/exception
and the OS
Calls RFE
Computer Architecture 22
Contd.
• enables interrupts
• restores the processor to the user mode
Computer Architecture 23