comparison slides/2018/05/15/slide.md @ 44:8c7be076e6e6

auto-Update generated slides by script
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 15 May 2018 19:22:22 +0900
parents
children
comparison
equal deleted inserted replaced
43:fc5259b6167e 44:8c7be076e6e6
1 title: CbCによるMoarVMの改良
2 author: Takahiro Shimizu
3 profile:
4 lang: Japanese
5
6
7 # 研究目的
8 - Perl5の後継言語として開発されているPerl6はMoarVMと呼ばれるVMを搭載している.
9 - Perl6はMoarVM,JVM,JavaScript上で動くRakudoと呼ばれる実装と,コンパイラ開発者用のサブセットであるNQPが主な実装となっている.
10 - 現在Perl6及びMoarVMは全体的な速度がPerl5と比較し低下しており,実務として利用できるレベルに達していない.
11 - さらにPerl6の実装自体巨大なcase-switch文など見通しが悪くなっている.
12 - この問題を解決するために現在当研究室で開発している継続を中心にしたContinuation based Cを用いて改良を行う
13 - CbCの設計理念からVMの実装と親和性が高い事も推測できる為,実際にCbCを用いてどのようにVMが実装できるかを検証する
14
15 # 今週の進捗
16
17 - MoarVMのJITのドキュメントを読み始めました
18
19 # MoarVMのJIT
20 * [Docs](https://github.com/MoarVM/MoarVM/tree/master/docs)を見る
21 * JitCompiler overview
22 * Expression 'Tree' Intermedite Representation
23 * Runtime Configuration
24 * JIT Todo
25
26
27 # Lego
28 * MoarMVのJITはLegoと呼ばれているらしい
29
30 # DynASM
31 * Dynamic Assemler
32 * http://luajit.org/dynasm.html
33 * [luajit](http://luajit.org/)プロジェクトで作られているもの
34 * MoarVMには `3rdparty`ディレクトリ以下に展開されている
35 * x86アーキテクチャのJITコンパイル用のアセンブラのようなものらしい
36 * luaが`dasc`と呼ばれるCに近いアセンブラをCを出力する前に実行
37 * Cのヘッダーの `#include` している部分を機械語にランタイムで翻訳
38 * [GitHubのcommit](https://github.com/MoarVM/MoarVM/commit/372d0582ab90d4ddfc43553bbebe4e553a42278d)
39
40
41 # DynASM
42
43
44 - To get you started, here is a simple code snippet to be pre-processed. The lines starting with '|' (the pipe symbol) are for DynASM:
45
46 ```
47 if (ptr != NULL) {
48 | mov eax, foo+17
49 | mov edx, [eax+esi*2+0x20]
50 | add ebx, [ecx+bar(ptr, 9)]
51 }
52 ```
53
54 - After pre-processing you get:
55
56 ```
57 if (ptr != NULL) {
58 dasm_put(Dst, 123, foo+17, bar(ptr, 9));
59 }
60 ```
61
62 # Expression Tree
63
64 - まだ翻訳出来てない...
65
66 ## syntax
67 - `(` と`)`で括っていくLISPスタイル
68 - wordはPerlの正規表現 `[^\s\(\)#:"']`で表現されるもの
69 - keywordは `:` が途中につく
70 - 先頭に`$`が来るとリファレンスであり,MoarVMのオペランドもしくは宣言済みの変数
71 - `^`が先頭に来るとマクロであり,`macro:`で宣言可能
72 - 先頭に`&`だと関数のマクロ
73
74 ```
75 (template: sp_p6oget_o
76 (let: (($val (load (add (^p6obody $1) $2) ptr_sz)))
77 (if (nz $val) $val (^vmnull))))
78 ```
79
80 # Instruction Selection
81
82 * シーケンスを実際にx86に変換する部分
83 * [Aho etal](https://dl.acm.org/citation.cfm?id=75700)の論文が基本となっているらしい
84
85
86 # 書き換え
87
88 - `spesh/facts.c`を書き換えていこうかなとしています
89 - case文で分岐した後の返り値をstackにどうやって積むかが問題
90 - 遷移を担当するテーブルの設計
91
92 # 書き換え地点
93
94 ```
95 case MVM_OP_const_i64_32:
96 case MVM_OP_const_i64_16:
97 case MVM_OP_const_s:
98 literal_facts(tc, g, ins);
99 //XXX 書き換え
100 goto literal_facts_cbc(tc,g,ins,__return);
101 goto literal_facts(tc, g, ins);
102 break;
103 ```
104
105 # target
106
107 ```
108 __code literal_facts_cbc(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins,__code(*exit)()) {
109 MVMSpeshFacts *tgt_facts = &g->facts[ins->operands[0].reg.orig][ins->operands[0].reg.i];
110 switch (ins->info->opcode) {
111 case MVM_OP_const_i64:
112 tgt_facts->value.i = ins->operands[1].lit_i64;
113 break;
114 case MVM_OP_const_i32:
115 tgt_facts->value.i = ins->operands[1].lit_i32;
116 break;
117 case MVM_OP_const_i16:
118 tgt_facts->value.i = ins->operands[1].lit_i16;
119 break;
120 case MVM_OP_const_i8:
121 tgt_facts->value.i = ins->operands[1].lit_i8;
122 break;
123 case MVM_OP_const_n32:
124 tgt_facts->value.n = ins->operands[1].lit_n32;
125 break;
126 case MVM_OP_const_n64:
127 tgt_facts->value.n = ins->operands[1].lit_n64;
128 break;
129 case MVM_OP_const_i64_32:
130 tgt_facts->value.i = ins->operands[1].lit_i32;
131 break;
132 case MVM_OP_const_i64_16:
133 tgt_facts->value.i = ins->operands[1].lit_i16;
134 break;
135 case MVM_OP_const_s:
136 tgt_facts->value.s = MVM_cu_string(tc, g->sf->body.cu,
137 ins->operands[1].lit_str_idx);
138 break;
139 default:
140 return;
141 }
142 tgt_facts->flags |= MVM_SPESH_FACT_KNOWN_VALUE;
143 goto (*exit1)();
144 }
145 ```
146
147 # 来週の予定
148
149 * JITもう少し読む
150 * JITから書き換える?