module 3b - ilp (ch2) - branch prediction€¦ · 2 stall 3 add.d f4,f0,f2 ;add scalar in f2 4...
TRANSCRIPT
1
�������� ��� ������������� ���� ������
� ��������� ������ ���������� �������������������
2
���!����� ����
� �� ���"������
� �����#�������$
� %��� �� ��� ����
2
3
������ ���������� ����������
� ��������$� ������&�������� ���'(�����������������)� ������* �
����������"����� ��+ ��� �������� �������������������������,�
-��. ������������������� �������� �����
� /)�����$����������$�������&��� ������$�������������"�
�������������)�����������$������� �����
� �������������������&�����* � ���������0���1�����������&��"����
��� ����������)�����������������
4
!. ������������� ���
� !. �����$��&����������������� ��������)�������$��� 2
� �&���� ��� ���3�����������������. ��������� ���������������
� 4���� ��� ���3�������&��� ������������"�. ���
� �� �� ��������������������&�� ���&�����������)��������� ���������"������������� ���
� �&���� � ���. ������������������� ������������������-����������������-���1��)��������� ���� ������,� �. ��� �,���������
� 4���� � ����������������������� ��������������������������������������������-��,��) ���,�"����)�����,�����5������������
3
5
6 ��������������������2
� 7 ������������"���������"����$�����* ���� ����������������������
��������"������������������ �������)�����������$������� �����8
� 9�. ��������$�����������������. ���8
� 7 ���������$�����������&����������"����� �8��"���,���. 8
6
:� ����"���� ��������$�:���.
� ��������� ��;���������������� ��<�4��� ������4������<������9�0���4������<���������4�����
� ��������������� �2����������"�������)��������"����� ��������������&�������������������
� 4��� ��������0���2�97 � ������������������� ������������"������� �����
� �������0���2������� ����������������������"������������� ��������������������������
� ����������0���2��������&����&����. ��������"�� ���$��"������� ���������� ������������� ���$������ �������"��. �=���� �������>����?
� ������������� ����������������������� �����. �����������&��� ������$�������������������$�. ����������
4
7
��������:�� ��4�����
�
���������� ������
�&���� �� ������$�� �������0����������
�&���� ����� ������ ����� ���������������
������$���������������� ���������� & ��� ������ ��
4�� �������� �������� ��������������
�&���� ������&�������$������� �������0����������������$������&�
�������������$� ����������0����������
%��� � ������������������ ������$�� �������0����������
��������������� ������&���� ������ �����������0����������
4�"�. �������������$������� ��� ������$� ������ �����������0�����������
������������ �������� ������ �,�������� ��������������
�
8
@����������������)�������$���
� !�����������"����������������������. ������������� ���� + �������$�������� ���
��3��� ��. ����������� ���������������) ���������������&����"��� �����)���+
���3����������
� !&�� ���&���� ����� ��"��3��� &�����"�������. ������A ����B�A �+ ���. ����
5����C������� �������)� �������. �������� ��������+ ������������ ����������
��-��&���������������� �������,��������������������. �� ����)������. ������
������ ���� -�����&�� ���&�������������������$����� -���0�
� !������������������������"����� ������� ������,�. ��������)�������� �� �����
������������� ���� -�
5
24
/)������+ �����#�������$
� !���� ��,������ ����������� ���2
for (i=1000; i>0; i=i–1)
x[i] = x[i] + s;
� �������"����. ��$������ ����"��������)������
� �$��������&������ ������������)������
Instruction Instruction Latency stalls betweenproducing result using result in cycles in cyclesFP ALU op Another FP ALU op 4 3FP ALU op Store double 3 2 Load double FP ALU op 1 1Load double Store double 1 0Integer op Integer op 1 0
25
@ �����2�7 �������������9�0���8
Loop: L.D F0,0(R1) ;F0=vector element
ADD.D F4,F0,F2 ;add scalar from F2
S.D 0(R1),F4 ;store result
DADDUI R1,R1,-8 ;decrement pointer 8B (DW)
BNEZ R1,Loop ;branch R1!=zero
First translate into MIPS code: � �!��������"&,��������(������. ���������
6
26
@ ������4��. ��$�4�����
� ����������������� ������������� ���� �����������
Instruction Instruction stalls b/n inproducing result using result clock cyclesFP ALU op Another FP ALU op 3FP ALU op Store double 2 Load double FP ALU op 1
1 Loop: L.D F0,0(R1) ;F0=vector element
2 stall
3 ADD.D F4,F0,F2 ;add scalar in F2
4 stall
5 stall
6 S.D 0(R1),F4 ;store result
7 DADDUI R1,R1,-8 ;decrement pointer 8B (DW)
8 stall ;assumes can’t forward to branch9 BNEZ R1,Loop ;branch R1!=zero
27
4 ������@ ������� �����0��$�4�����
�������������������������������� ��������!"#$��%$$#$�&#$'��(��������)��*�����+�,�� ����� �����������
Instruction Instruction stalls b/n inproducing result using result clock cyclesFP ALU op Another FP ALU op 3FP ALU op Store double 2 Load double FP ALU op 1
1 Loop: L.D F0,0(R1)
2 DADDUI R1,R1,-8
3 ADD.D F4,F0,F2
4 stall
5 stall
6 S.D 8(R1),F4 ;altered offset when move DSUBUI
7 BNEZ R1,Loop
&� �)�$%$$-.����&#$ ��������/��/����������&#$
7
28
#�����������@����!�����
=�����$��"��. ���. �&?
�� ��������)����
� ���� �����������1 Loop:L.D F0,0(R1)3 ADD.D F4,F0,F26 S.D 0(R1),F4 ;drop DSUBUI & BNEZ7 L.D F6,-8(R1)9 ADD.D F8,F6,F212 S.D -8(R1),F8 ;drop DSUBUI & BNEZ13 L.D F10,-16(R1)15 ADD.D F12,F10,F218 S.D -16(R1),F12 ;drop DSUBUI & BNEZ19 L.D F14,-24(R1)21 ADD.D F16,F14,F224 S.D -24(R1),F1625 DADDUI R1,R1,#-32 ;alter to 4*827 BNEZ R1,LOOP
������������������ ���������������
!%���� ���0����� ����)������('
������������
������������
29
#������������������
� �������������&�-��. �������������"�����
� 4��������������,����. ��. ������-��������������������������-��-
�������"�������&
� ��������"������$���������������,�. ��$����������������"�
���� ����������2
� �����)� �����=�����-?������������������&����������������$���������
� B�������������������&�����������&�����������������������������=�D-?�
�����
� @������$���������"��,�������"������)� �����������. �������������
�������������������
8
30
#������������4 ������$�!����� �����0���4�����
1 Loop:L.D F0,0(R1)2 L.D F6,-8(R1)3 L.D F10,-16(R1)4 L.D F14,-24(R1)5 ADD.D F4,F0,F26 ADD.D F8,F6,F27 ADD.D F12,F10,F28 ADD.D F16,F14,F29 S.D 0(R1),F410 S.D -8(R1),F811 S.D -16(R1),F1212 DSUBUI R1,R1,#3213 S.D 8(R1),F16 ; 8-32 = -2414 BNEZ R1,LOOP
0(�������������������#1�)������������
31
�������#�������$��� ������
:�3����������������$���. ����������� ���������������������������. �����
������ ������ ������ ���$�������������$�������������� ��2
�E �����������������������$����"����&�"����$����������������������. ����
����������=�) ����"������������ �� ��?�
BE #����""��������$������������������ �����&� �����������"�� ���&�����$�
�������$�������"����""������ ������������
�E /��������������)���������������� �������� ����������>�������������
������������������������� ��
5E ���������������������������������������������� ����������� ���$���&�
�������$���������������������"�����""�������������������������������
F !����"�����������3����������&0��$������&������������"����$���������&���
������"��������������������
�E 4 ���������� ��,���������$���&������� �����������&�������������
�����������������$����� ��
9
32
�����������������#�������$
�E �� �����������������"��������������0��. ������ ���)����
��������$
F �����G����.
BE H��. ������ �����0��
F @������$��������,� �� ��������� ����������������� ����� � ������������
�E :�$��������������2����������������"���������$������� �������&�
�$$���������������$����� ������$
F �"������������������������ �����������������������$������,���& ����������
��������"����������$�
� �������������$���� ������� ���"����� ���������������1�
��������. �&�������� ������ ����
33
12%
22%
18%
11% 12%
4%6%
9% 10%
15%
0%
5%
10%
15%
20%
25%
compre
sseq
ntott
espre
sso gc
c li
dodu
cea
r
hydro
2d
mdljdp
su2c
or
Mis
pred
ictio
n R
ate
4���� �%��� �� ��� ����
� �� ����������. ��� ������$� ������������&������ �
� !��������� ������������� ���,������������ ������ ������� ���&�
. ���� �������
� 4��������� ��������������� �������� �������-��
� ����$��������� �����;�����-������� ��"��3��� &�;��5A �4 /�
� ����� ������� ��������� ������� ��������$����"������"��������� ���� ���"����������������,�������"&����� ���������������������2
Integer Floating Point
10
34
�&���� �%��� �� ��� ����
� 7 �&��������� �����. ��-8
� #����&��$���$�������������$���������
� �����������������$������������������$���������
� ������ �������3��� ������������ �����������������"� ����"�. �&������
������D �������������-���������������
� ���&���� ����� ������ ���������������������� ����� ��
���� ����8
� 4�����������
� !�������������������������"��������������� ����������$�����. �� �
����&���� ��������
35
�&���� �%��� �� ��� ����
� ��"����� ��;�I=� ��� &,� �����"�������� ����?
� %��� ��9�����&�!����2���. ���������"� �����������)��������"�
�����������
� 4�&��. ������������������ ����-������������
� J�������� �� -
� ������2����������,�������%9!�. ���� ������. ��������� ������
=�$ ���'��������������"�����)��?2
� /���"������ ���,�. ��������)������������"��������$������"���
� @���������������$�������������� ����������$�� ��,�. ����������� ���
�)�����������"�������$
11
36
� 4�������2�B������ �����. ����� ���$������ ��������&��"�
������� ��� ���
� :�2�����,�������-��
� H����2�$�,���-��
� ������������� ���� ��������-��$���� ���
�&���� �%��� �� ��� ����
T
T NT
NT
Predict Taken
Predict Not Taken
Predict Taken
Predict Not TakenT
NTT
NT
37
18%
5%
12%10% 9%
5%
9% 9%
0% 1%
0%2%4%6%8%
10%12%14%16%18%20%
eqnto
tt
espre
sso gc
c li
spice
doduc
spice
fpppp
matrix3
00
nasa7
Mis
pred
ictio
n R
ate
%9!�� ��� &
� � ������ ���� �����������2
� 7 ���$�$�����"������������ �
� H������� ��������&��"�. ���$����� ��. �������)�����������. ������. ���5�����
� 5�'������&������2
Integer Floating Point
12
38
����������%��� �� ��� ����
� ���2���� ����������� ����&��)� �������� ���������-����������
��-��,���������������������������� ����������������������� ��
������&������
� ���$������,�=�,�?����� ������������ ��������� ���� �������
���� �����. ����B� ������&�������,��� ��. ���������� �������
� !���,����B�����%9!������=�,B?����� ���
� H������%��� ��9�����&2����������"����$������-�����$�!DJ!��������
�"������� ���� ���E
� /� ������&��������������� ��������� ����E
39
����������$�%��� ���
(2,2) predictor
– Behavior of recent branches selects between four predictions of next branch, updating just that prediction
Branch address
2-bits per branch predictor
Prediction
2-bit global branch history
4
13
40
0%
Freq
uenc
y of
Mis
pred
ictio
ns
0%1%
5%6% 6%
11%
4%
6%5%
1%2%
4%
6%
8%
10%
12%
14%
16%
18%
20%
4,096 entries: 2-bits per entry Unlimited entries: 2-bits/entry 1,024 entries (2,2)
� ��� &��"���""������4 �����
4096 Entries 2-bit BHTUnlimited Entries 2-bit BHT1024 Entries (2,2) BHT
nasa
7
mat
rix3
00
dodu
cd
spic
e
fppp
p
gcc
expr
esso
eqnt
ott li
tom
catv
41
!���������� ��� ����
� � ������������� ������ ���
� #������������������$� ���������� ���������. ����
���� ����
� #����� ��� �����. ����$����������� ������� ����
14
42
!���������� ��� ����
!�������������� ��������$,���&,�5K�B����� �����������)���&�
�� ������� �������E�������������. ���2
� H���������� ���
� 5K������������)��&�������&��"�������B����� ����=B�B�;�5K?
� /� ������&�������������B��������� ���
� �� ������� ���
� �� ���������&������2���B5������������������ ����$������������� ���,�
���)��&����� �������
� !������������"�������������� ����� ����"����������� ��������� �
����������)��������"��K���������. �������������������$� �������
43
��������$� ��� ����
� �����$���"���������������� �������������&�������� ������
��$������� ����"���������� ��������� �
� ���� �����&� �� ����"�������$������ ����-�E�
� ���&�� ������������������ ����. �������� ������$���������� ����
�������5�A ��"����������"�������4 /������$������ ����-����������
�������A ��"����������"�������4 /��@ ���� ����-�
15
44
�������5�� ������ �����:����
=��������������� �����,������������� �?
��
��
�
��
�
�� � �
�
�
�
�
�
�
�
�
�
��
��
��
��
��
���� ��
�������
������
������
��������
���������
��������
���������
���������
��������
����������� �����������������������
SPECint2000 SPECfp2000
≈≈≈≈6% misprediction rate per branch SPECint(19% of INT instructions are branch)
≈≈≈≈2% misprediction rate per branch SPECfp(5% of FP instructions are branch)
45
%��� ��!��$���%�""����=%!%?
� %��� �����$��� �� ����������� ����&��������������������� �����
"�� �E
� %!%�������� ������������. �&���� � ���
� !��� ���"������� �����������������%!%
� 7 ��������� �����"�������� ����������$� ��� ��� �����
�������
� �"��������� ��. ������� �����-��,������� �����"�� �� ���������
������������������� ��� �
16
46
%��� ��!��$���%�""����L ��������
47
�&���� �%��� �� ��� �����4�����&
� ��� ������� ����$�����������������"��)� �����
� %��� ��9�����&�!����2�B������"��������� ��� &
� �����������2�:� ����&��)� �������� ���� ���������. ������)��
���� �
� /�������""���������� ���
� L ���""�������)� ��������"���������� ����
� !�������������� �������-������$��������)������,��&�����$����������
���� �����
� ������&�������������$��������"�������������������������� ���
��"��������,���� �������$������. ���������� ���
� ���B���,���������������� ���������$�≈ ��K���������������� ���������-��
���� �. ������� �������5
� %��� ��!��$���%�""��2��� �������� ��������* ����� ����
17
48
��"���������
� ����&����-�����������=�$���8?