Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17...
Transcript of Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17...
![Page 1: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/1.jpg)
����������� �������������� �������� ��� ��
�������������
����������� �
![Page 2: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/2.jpg)
Tcl VM Dispatch 2
������
� ����������!�������� �"����#�
� � ������ ���#����������#�$%&
� ����$����'��%��(���
� $����'�������#�)
� *� ���
![Page 3: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/3.jpg)
Tcl VM Dispatch 3
*����)�������%��)���
���+�����
�"����#� !����������
�"����#�$������
![Page 4: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/4.jpg)
Tcl VM Dispatch 4
$�����)�����"����#�
# find first power of 2# greater than 100
proc find_pow {} {set x 1while {$x < 100} {
incr x $x}return $x
}
0 push1 0 # x = 12 storeScalar1 04 pop
5 jump1 +7
7 loadScalar1 0 # x += x9 incrScalar1 0
11 pop
12 loadScalar1 0 # if x < 10014 push1 1 # goto 716 lt17 jumpTrue1 -10
19 loadScalar1 0 # return x21 done
![Page 5: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/5.jpg)
Tcl VM Dispatch 5
!����������
…
0
incrScalar1
0
loadScalar1
7
jump1
pop
0
storeScalar1
0
push1
vpc
for (;;) {
opcode = *vpc;
switch (opcode) {
case PUSH1:
// real work…
vpc += 2;
break;
case POP:
…�"����#��
*���� �������
![Page 6: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/6.jpg)
Tcl VM Dispatch 6
%�����������%��(���
� !���������)�("����#�� ��� ������������������)� �����
� ���� ���� ���
� �������(�������� ������ �������������� �����
� ���#�� �������� # ����������,
![Page 7: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/7.jpg)
Tcl VM Dispatch 7
���$������� �switch()
push_work:add r6, 4, r6ldub [r4+1], o0ld [fp+72], o2…bra .switch_end
pop_work:ld [r2], g1add r2, -4, r2mov g1, l0…bra .switch_end
…
&&sub_work
&&add_work
&&pop_work
&&push_work
$�#���##�� �
![Page 8: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/8.jpg)
Tcl VM Dispatch 8
-'�����)�switch()
ldub opc = [vpc] // ����#� ���#�.����)��#/
cmp opc, max_opc // ����# �������.� ��� /bg switch_default
set r5 = switch_table // ��(����������.��#�(��/mul r1 = r4 * 4ld [r5 + r1], r1
jmp r1 + r5 // !�#�����"�������������
� ���������
![Page 9: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/9.jpg)
Tcl VM Dispatch 9
�����������#�)
ld address = [vpc] // ����#� ���#�.������/jmp address // !�#���������
� 01�$"���
� �����(�"��'��� �#���2���$
3 ��� ����#���� #����� ��������
� 1�� � ���01��"��� 4��5���� �$%&�#��),
![Page 10: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/10.jpg)
Tcl VM Dispatch 10
$%&�%�����
6-7�8Instruction
Cache
L2Cache
add r6 += 4ld r1 = [r4]ld r2 = [fp+8]ld addr = [vpc]jmp addr???
� 9����)������������������� ����:������)4������������ ������� ,
![Page 11: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/11.jpg)
Tcl VM Dispatch 11
����������)���%��#����
0 add r6 += 44 ld addr = [r1]8 cmp r6, 12
12 bg 616 jmp addr20 ld r2 = [r3]24 sll r2 = r2, 228 jmp r2
pctargetpcjmp
1000
42
28
16
�����������������������
� %��#���(���������)���������� ��(�����
![Page 12: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/12.jpg)
Tcl VM Dispatch 12
���
…
targetpcjmp
$����'��%��(����-'�����
����
for
switch
add print …push
…
pushswitch
targetpcjmp
…
addswitch
targetpcjmp
…
printswitch
targetpcjmp
for
switch
add print …push
for
switch
add print …push
for
switch
add print …push
for
switch
add print …push
for
switch
add print …push
for
switch
add print …push
for
switch
add print …push
for
switch
add print …push
push 2push 3addprint
����������������������
![Page 13: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/13.jpg)
Tcl VM Dispatch 13
$����'��%��(���
� ��#����� �� �)�%$��������#����
3 ���"�����(����� ���� ��������$�����"
� ��� �� �)���
3 !���������������� ��"���� �������
3 ;-���<=>�?@A�� ���#�� B��� � �0<C��"���
� ������������#�� ���#����,
![Page 14: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/14.jpg)
Tcl VM Dispatch 14
+�(������������#�)
� ��#�#��4��2�����������#����$%&
� $�������� ���������������������
� D��"����# �����
0 push1 02 storeScalar1 04 pop5 loadScalar1 07 incrScalar1 09 pop
call push1call storeScalar1call popcall loadScalar1call incrScalar1call pop
E����$�#��.F$��G/�"����#�
![Page 15: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/15.jpg)
Tcl VM Dispatch 15
$����'�������#�)
� �������������������� �(������������#�)
� $2�H<@
� 9����("����#�������#�����������# B����4
� ����I���� ��'�����$��H ����'(��"
![Page 16: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/16.jpg)
Tcl VM Dispatch 16
!����) +���� ����#�
call pushpush
call storeScalarcall popcall incrScalarcall pop
pop
incrScalar
storeScalar
push
![Page 17: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/17.jpg)
Tcl VM Dispatch 17
�������������� �(������E���
• jump (����� ����������� �������
• jumpTrue � � ������(�����B�(����� ������
0 jump1 +72 loadScalar1 04 incrScalar1 06 pop7 loadScalar1 09 push1 1
11 lt12 jumpTrue1 -1014 loadScalar1 0
0 b 164 set vpc = 78 call loadScalar
12 call incrScalar16 call pop20 call loadScalar124 call push128 call lt32 call jumpTrue136 beq 840 call loadScalar1
![Page 18: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/18.jpg)
Tcl VM Dispatch 18
$��#�������������%�����������
� 5������������������������� jumpTrue
3 %�����J�����������#� ����#4�(������ ,
� gt, lt, tryConvertNumeric, foreachStep4
3 � �����!�������������������� gt
� ��� ?4@��� ��� ���������I����B�(���())�����"������������
� #��������$���
![Page 19: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/19.jpg)
Tcl VM Dispatch 19
$��#�������������%������������1
gt:c = do_compare…o = new_bool (c)push (o)vpc++return
jump_true: 91 insnso = pop ()coerce_bool (o)if (o.bool)
vpc = targetvelse
vpc = fall_thruv
asm (“cmp o.bool, 0”)return
gt_jump:c = do_compare…
vpc++return
gt_jump:c = do_compare…asm (“cmp o.bool, 0”)vpc++return
call gtcall jumpTruebeq targetn
call gt_jump
beq targetn
call gt_jumpset vpc = targetvbeq targetnset vpc = fall_thruv
call gtcall jumpTruebeq targetn
![Page 20: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/20.jpg)
Tcl VM Dispatch 20
$��������
� !��-�H<K
� !�������������
3 +�����I��������#
3 -�������vpc
� $��������#
� <��"����# ����� pop
storeScalar
push
push
add
![Page 21: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/21.jpg)
Tcl VM Dispatch 21
*� ���
� ���(����
3 ����(�������� B����"�01���������������0<<B<<<�# ������
3 #�:������ ���#��#
3 ���� ����D<�����L�0<B<<<�# ������
� &����+%�*$�!!!
� & �� ����������������� �(� ����
![Page 22: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/22.jpg)
Tcl VM Dispatch 22
%�����������+�����"
M=K4<$��������
%��&'(���)���������
??@4K$����'�������#�)
??A
*+ !����$�!���� �,��� ��� ��
K4=A�����������#�)
-��'� ��������+�
.���������
![Page 23: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/23.jpg)
23
Direct Threading
-5%
0%
5%
10%
15%
20%
25%
30%
Tclbench Speedup versus Switch
Catenation
Context Threading
-5%
0%
5%
10%
15%
20%
25%
30%
CT + peephole
![Page 24: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/24.jpg)
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4workcompileI-cache stall
MATRIXmul
20x20
FACT16
20000
LOOPforeach
LOOPwhile10000
MD51000
BASE64encode
2000
BASE64encode3
2000
MATRIXtranspose1
sw dir
cat ct
ct-p
switc
hdi
rect
cate
nct ct
-pee
p
sw dir
cat ct
ct-p sw dir
cat ct
ct-psw dir
cat ct
ct-p sw dir
cat ct
ct-psw dir
cat ct
ct-p sw dir
cat ct
ct-psw dir
cat ct
ct-p
Cyc
les
(rel
ativ
e to
Sw
itch)
Performance Detail
![Page 25: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/25.jpg)
Tcl VM Dispatch 25
Tcl Opcodes are Big
5%Tcl
37%Ocaml
25%Java
Context Threading Speedup
![Page 26: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/26.jpg)
Tcl VM Dispatch 26
$����� �� ���#�8������5���
� $����'�������#�)� � �����N��������
3 �� ��# ������.�������H ���(���/
3 �������� �����I����
3 ��������������#� B���������'?DB�%����%$
� 01A� ���#�������J���� 0<'� �����������$
3 ���������#� ��#��������O!�
![Page 27: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/27.jpg)
Tcl VM Dispatch 27
7���� ������������#
Tcl Opcodes
DISPATCH
Ocaml Opcodes
![Page 28: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/28.jpg)
Tcl VM Dispatch 28
����������#��������+����
� &�����0���#�FE8�G���� �����
� &����+%�*$ !!!�
3 5������#����(���������)������#����,
3 F�������:��:(�����G�� �������,
3 $�� #����������������)��� B����������'�� �#�J
![Page 29: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/29.jpg)
Tcl VM Dispatch 29
O��"�� ��#� "#��%��)��� �
start: Vop1Vop2Vop1Vop3Vop1Vop4Vop1Vop5Vop1goto start
Unpredictable
start: Vop1Vop1Vop1Vop1Vop1Vop1Vop1Vop1Vop1goto start
Predictable
![Page 30: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/30.jpg)
Tcl VM Dispatch 30
� ���# 4����#��
?4KD4= �(������
��'&
��'&
0K41
0K41
0M4=
&����+%�*$�!!!
��'/#�����������
�0'�#����� ������
004?�#��������#��
0?4D�#������ ���#
0P41 ����
%������K� �������"��
![Page 31: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/31.jpg)
Tcl VM Dispatch 31
$�B����B�+����
� �����������"�+���
� �)�����(�#� ������"����������������
3 $��� ����((���������) ����.o7/
3 5�� ���������) ���������� ���#���)
call bigopmov o7, save_ret…
bigop:call runtime…mov save_ret, o7retlinc vpc, 4
![Page 32: Department of Computer Science, University of Torontobv/tcl2005/tcl2005-slides.pdfTcl VM Dispatch 17 ˘ ( ˆ E †jump( ˆ ˙ †jumpTrue ( B ( 0 jump1 +7 2 loadScalar1 0 4 incrScalar1](https://reader035.fdocuments.in/reader035/viewer/2022071410/6104aedba317fe37787d6075/html5/thumbnails/32.jpg)
Tcl VM Dispatch 32
$������������
� 5������#������������������"��������
� ���(���������I�
=?$��C���������
=@$����'�������#�)
KK$��������
DA�����������#�)
*� ���� ������ ������ �����������.����������
� ���� � )�������"����� �(��������