comparison slides/2018/05/18/zip.txt @ 45:f5dac10540d7

auto-Update generated slides by script
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 29 May 2018 18:44:59 +0900
parents
children
comparison
equal deleted inserted replaced
44:8c7be076e6e6 45:f5dac10540d7
1 2018-05-14----
2 今日の進捗
3
4 # MoarVMのJIT
5 * [Docs](https://github.com/MoarVM/MoarVM/tree/master/docs)を見る
6
7 # Lego
8 * MoarMVのJITはLegoと呼ばれているらしい
9
10 # DynASM
11 * Dynamic Assemler
12 * http://luajit.org/dynasm.html
13 * [luajit](http://luajit.org/)プロジェクトで作られているもの
14 * MoarVMには `3rdparty`ディレクトリ以下に展開されている
15 * x86アーキテクチャのJITコンパイル用のアセンブラのようなものらしい
16 * luaが`dasc`と呼ばれるCに近いアセンブラをCを出力する前に実行
17 * Cのヘッダーの `#include` している部分を機械語にランタイムで翻訳
18 * [GitHubのcommit](https://github.com/MoarVM/MoarVM/commit/372d0582ab90d4ddfc43553bbebe4e553a42278d)
19
20 # DynASM
21
22
23 - To get you started, here is a simple code snippet to be pre-processed. The lines starting with '|' (the pipe symbol) are for DynASM:
24
25 ```
26 if (ptr != NULL) {
27 | mov eax, foo+17
28 | mov edx, [eax+esi*2+0x20]
29 | add ebx, [ecx+bar(ptr, 9)]
30 }
31 ```
32
33 - After pre-processing you get:
34
35 ```
36 if (ptr != NULL) {
37 dasm_put(Dst, 123, foo+17, bar(ptr, 9));
38 }
39 ```
40
41
42
43 ----------
44 2018-05-15----
45 # ゼミ
46
47 - 論文自体は昔のもの
48 - MoarVMどこが遅いのか? JITがアレ?
49 - 直接バイナリを吐かない理由は?
50
51 - Comon Lisp Cに変換して生成したオブジェクトを作る
52 - その他の最適化はCコンパイラに投げる
53 - 京都で開発された 京都CommonLisp
54 - Lisp中でread evalループを持っていた
55 - interpretするルーチンがLISPで書かれている
56 - -->普段はCコンパイラが呼ばれない
57 - stack をlistの管理で行う
58
59 - JITが遅いならCbCの入る場所がなさそう
60
61 - 直接アセンブラを書いても良さそう
62 - MoarVMからCbCを吐く
63
64 - 帯域脱出が問題
65 - スタックの管理ならCbCでいけるかもしれない
66 - MoarVMの
67
68 - 行き先を渡す
69 - 厳しいなら構造体にいれてあげる
70 - diコンテナ
71 - 見かけ上関数呼び出しっぽく書ける
72
73 - Cの再実装
74 - 比較して見る
75 - 頻度の高いif文を先に持っていって再構築
76
77 - CbC側を書き換えるのをどうするか
78
79 ----------
80 2018-05-16----
81 MVMSpeshFactsが主に使われている構造体
82
83 宣言元はfacts.h
84
85 ```c
86 struct MVMSpeshFacts {
87 /* Flags indicating things we know. */
88 MVMint32 flags;
89
90 /* The number of usages it has. */
91 MVMint32 usages;
92
93 /* Known type, if any. */
94 MVMObject *type;
95
96 /* Known type post-decontainerization, if any. */
97 MVMObject *decont_type;
98
99 /* Known value, if any. */
100 union {
101 MVMObject *o;
102 MVMint64 i;
103 MVMnum64 n;
104 MVMString *s;
105 } value;
106
107 /* The instruction that writes the register (noting we're in SSA form, so
108 * this is unique). */
109 MVMSpeshIns *writer;
110
111 /* The deoptimization index in effect at the point of declaration, or -1
112 * if none yet. */
113 MVMint32 deopt_idx;
114
115 /* The log guard the facts depend on, if any. */
116 MVMuint32 log_guard;
117
118 /* Has the instruction that wrote this value been deleted? */
119 MVMuint32 dead_writer;
120 };
121 ```
122
123 fact のflag一覧
124
125 ```c
126 /* Various fact flags. */
127 #define MVM_SPESH_FACT_KNOWN_TYPE 1 /* Has a known type. */
128 #define MVM_SPESH_FACT_KNOWN_VALUE 2 /* Has a known value. */
129 #define MVM_SPESH_FACT_DECONTED 4 /* Know it's decontainerized. */
130 #define MVM_SPESH_FACT_CONCRETE 8 /* Know it's a concrete object. */
131 #define MVM_SPESH_FACT_TYPEOBJ 16 /* Know it's a type object. */
132 #define MVM_SPESH_FACT_KNOWN_DECONT_TYPE 32 /* Has a known type after decont. */
133 #define MVM_SPESH_FACT_DECONT_CONCRETE 64 /* Is concrete after decont. */
134 #define MVM_SPESH_FACT_DECONT_TYPEOBJ 128 /* Is a type object after decont. */
135 #define MVM_SPESH_FACT_FROM_LOG_GUARD 256 /* Depends on a guard being met. */
136 #define MVM_SPESH_FACT_HASH_ITER 512 /* Is an iter over hashes. */
137 #define MVM_SPESH_FACT_ARRAY_ITER 1024 /* Is an iter over arrays
138 (mutually exclusive with HASH_ITER, but neither of them is nece ssarily set) */
139 #define MVM_SPESH_FACT_KNOWN_BOX_SRC 2048 /* We know what register this value was boxed from */
140 #define MVM_SPESH_FACT_MERGED_WITH_LOG_GUARD 4096 /* These facts were merged at a PHI node, but at least one of the incoming facts had a "from log guard" flag set, so we'll have to look for that fact and increment its uses if we u se this here fact. */
141 #define MVM_SPESH_FACT_RW_CONT 8192 /* Known to be an rw container */
142
143 void MVM_spesh_facts_discover(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshPlanned *p);
144 void MVM_spesh_facts_depend(MVMThreadContext *tc, MVMSpeshGraph *g,
145 MVMSpeshFacts *target, MVMSpeshFacts *source);
146
147 ```
148
149
150 `spesh/graph.h`の箇所
151
152 ```
153 /* An instruction in the spesh graph. */
154 struct MVMSpeshIns {
155 /* Instruction information. */
156 const MVMOpInfo *info;
157
158 /* Operand information. */
159 MVMSpeshOperand *operands;
160
161 /* Previous and next instructions, within a basic block boundary. */
162 MVMSpeshIns *prev;
163 MVMSpeshIns *next;
164
165 /* Any annotations on the instruction. */
166 MVMSpeshAnn *annotations;
167 };
168
169 ```
170
171 `core/interp.h`
172
173 ```
174 /* Information about an opcode. */
175 struct MVMOpInfo {
176 MVMuint16 opcode;
177 const char *name;
178 char mark[2];
179 MVMuint16 num_operands;
180 MVMuint8 pure;
181 MVMuint8 deopt_point;
182 MVMuint8 logged;
183 MVMuint8 no_inline;
184 MVMuint8 jittivity;
185 MVMuint8 uses_hll;
186 MVMuint8 operands[MVM_MAX_OPERANDS];
187 };
188
189
190 ```
191
192 ----------
193 2018-05-18----
194
195 moar.h
196
197
198 l.41あたり
199
200 ```c
201 /* Sized types. */
202 typedef int8_t MVMint8;
203 typedef uint8_t MVMuint8;
204 typedef int16_t MVMint16;
205 typedef uint16_t MVMuint16;
206 typedef int32_t MVMint32;
207 typedef uint32_t MVMuint32;
208 typedef int64_t MVMint64;
209 typedef uint64_t MVMuint64;
210 typedef float MVMnum32;
211 typedef double MVMnum64;
212 ```
213
214 ただのtypes のSizedのフラグ
215
216 src/core/ops.h でdefineされている
217
218
219 ただの変数
220
221 ```
222 /* This file is generated from src/core/oplist by tools/update_ops.p6. */
223
224 /* Op name defines. */
225 #define MVM_OP_no_op 0
226 #define MVM_OP_const_i8 1
227 #define MVM_OP_const_i16 2
228 #define MVM_OP_const_i32 3
229 #define MVM_OP_const_i64 4
230 #define MVM_OP_const_n32 5
231 #define MVM_OP_const_n64 6
232 #define MVM_OP_const_s 7
233 #define MVM_OP_set 8
234 #define MVM_OP_extend_u8 9
235 #define MVM_OP_extend_u16 10
236 #define MVM_OP_extend_u32 11
237 #define MVM_OP_extend_i8 12
238 #define MVM_OP_extend_i16 13
239 #define MVM_OP_extend_i32 14
240 #define MVM_OP_trunc_u8 15
241 #define MVM_OP_trunc_u16 16
242 ```
243
244 ----------