Mercurial > hg > Papers > 2011 > nobu-prosym
annotate presen/index.html @ 62:7087484574b0
update
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 26 Dec 2011 11:23:23 +0900 |
parents | 2c543a47737b |
children | 3cc4a8603489 |
rev | line source |
---|---|
54 | 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
3 | |
4 <html xmlns="http://www.w3.org/1999/xhtml"> | |
5 | |
6 <head> | |
7 <style> | |
8 .center { | |
9 margin-left: auto; | |
10 margin-right: auto; | |
11 text-align: center; | |
12 } | |
13 .textcenter { | |
14 text-align: center; | |
15 } | |
16 .taninaritop { | |
17 margin: auto; | |
18 width: 95%; | |
19 font-weight: bold; | |
20 } | |
21 </style> | |
22 <title>2012/ 1/ 7</title> | |
23 <!-- metadata --> | |
24 <meta name="generator" content="S5" /> | |
25 <meta name="version" content="S5 1.1" /> | |
26 <meta name="presdate" content="20120107" /> | |
27 <meta name="author" content="Nobuyasu Oshiro" /> | |
28 <meta name="company" content="University of the Ryukyu" /> | |
29 <!-- meta temporary --> | |
30 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
31 <meta http-equiv="Content-Script-Type" content="text/javascript" /> | |
32 <meta http-equiv="Content-Style-Type" content="text/css" /> | |
33 <!-- configuration parameters --> | |
34 <meta name="defaultView" content="slideshow" /> | |
35 <meta name="controlVis" content="hidden" /> | |
36 <!-- configuration extensions --> | |
37 <meta name="tranSitions" content="true" /> | |
38 <meta name="fadeDuration" content="500" /> | |
39 <meta name="incrDuration" content="250" /> | |
40 <!-- configuration autoplay extension --> | |
41 <meta name="autoMatic" content="false" /> | |
42 <meta name="playLoop" content="true" /> | |
43 <meta name="playDelay" content="10" /> | |
44 <!-- configuration audio extension --> | |
45 <meta name="audioSupport" content="false" /> | |
46 <meta name="audioVolume" content="100" /> | |
47 <meta name="audioError" content="false" /> | |
48 <!-- configuration audio debug --> | |
49 <meta name="audioDebug" content="false" /> | |
50 <!-- style sheet links --> | |
51 <link rel="stylesheet" href="ui/default_utf/slides.css" type="text/css" media="projection" id="slideProj" /> | |
52 <link rel="stylesheet" href="ui/default_utf/outline.css" type="text/css" media="screen" id="outlineStyle" /> | |
53 <link rel="stylesheet" href="ui/default_utf/print.css" type="text/css" media="print" id="slidePrint" /> | |
54 <link rel="stylesheet" href="ui/default_utf/opera.css" type="text/css" media="projection" id="operaFix" /> | |
55 <!-- embedded styles --> | |
56 <style type="text/css" media="all"> | |
57 .imgcon {width: 100%; margin: 0 auto; padding: 0; text-align: center;} | |
58 #anim {width: 33%; height: 320px; position: relative;} | |
59 #anim img {position: absolute; top: 0px; left: 0px;} | |
60 </style> | |
61 <!-- S5 JS --> | |
62 <script src="ui/default_utf/slides.js" type="text/javascript"></script> | |
63 </head> | |
64 <body> | |
65 | |
66 <div class="layout"> | |
67 <div id="controls"><!-- DO NOT EDIT --></div> | |
68 <div id="currentSlide"><!-- DO NOT EDIT --></div> | |
69 <div id="header"></div> | |
70 <div id="footer"> | |
71 <h1>プログラミングシンポジウム: 2012/ 1/ 7</h1> | |
72 <h2>並列信頼研</h2> | |
73 </div> | |
74 </div> | |
75 | |
76 <div class="presentation"> | |
77 | |
78 <div class="slide"> | |
79 <h1>Continuation based Cの GCC 4.6 上の実装について</li> | |
80 <h3></h3> | |
81 <li>大城 信康</li> | |
82 <h4><a href="http://ie.u-ryukyu.ac.jp/" rel="external">琉球大学 並列信頼研究室</a></h4> | |
83 <div class="handout"></div> | |
84 </div> | |
85 <!-- PAGE --> | |
86 <div class="slide"> | |
87 <h1>目的と背景(1)</h1> | |
88 <li>当研究室ではコードセグメント単位で記述するプログラミング言語Continuation based C (以下CbC)という言語を開発している。</li> | |
89 <li>コードセグメントは並列実行の単位として使うことができ、プログラムの正しさを示す単位としても使用することができる。</li> | |
58 | 90 <li>Many Core での並列実行を高い性能と高い信頼性で実現することができると考える。</li> |
54 | 91 </div> |
92 <!-- PAGE --> | |
93 <div class="slide"> | |
94 <h1>目的と背景(2)</h1> | |
58 | 95 <li>CbC のコンパイラは2001年に Micro-C 版、2008年には GCC 4.4 をベースとしたコンパイラが開発された。</li> |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
96 <li>GCC をベースとした CbC コンパイラは、修正・追加された最適化の機能を使用する為に、 GCC のアップデートに合わせ変更する必要がある。</li> |
58 | 97 <li>本研究ではCbC コンパイラを GCC-4.6 へとアップデートを行った。 </li> |
54 | 98 </div> |
99 <!-- PAGE --> | |
100 <div class="slide"> | |
101 <h1>発表内容</h1> | |
102 <ol> | |
103 <li>CbC の紹介</li> | |
104 <li>GCC でのコンパイルの流れ</li> | |
58 | 105 <font color="red"> |
106 <li>CbC の実装</li> | |
107 </font> | |
54 | 108 <!-- |
109 <ul> | |
110 <li>Tail Call Elimination</li> | |
111 <li>goto シンタックスの追加</li> | |
112 <li>環境付き継続</li> | |
113 </ul> | |
114 --> | |
115 <li>Micro-C との性能比較</li> | |
116 <li>mercurial を用いたアップデートの方法</li> | |
117 <li>まとめ</li> | |
118 <ol> | |
119 </div> | |
120 <!-- PAGE --> | |
121 <div class="slide"> | |
122 <h1>Continuation based C </h1> | |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
123 <h2>コードセグメント単位での記述と継続を基本としたプログラミング言語。</h2> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
124 <li>プログラムの記述は C の構文と同じだが、ループ制御や関数コールが取り除かれる。</li> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
125 <li>コードセグメント</li> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
126 <ul> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
127 <li>C の関数よりも細かい単位。</li> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
128 <li>コードセグメントの処理は最後に別のコードセグメントへ継続(goto)することで続いていく。</li> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
129 </ul> |
54 | 130 </div> |
131 <!-- PAGE --> | |
132 <div class="slide"> | |
58 | 133 <h1>Continuation Based C</h1> |
134 <h2>継続:現在の処理を実行していく為の情報</h2> | |
135 <!-- | |
136 <li>Cでは関数呼び出しの後、呼び出し元の環境に復帰する必要がある。</li> | |
137 --> | |
138 <li>Cにおいての継続</li> | |
139 <ul> | |
140 <li>続く命令のアドレス</li> | |
141 <li>命令に必要なデータ</li> | |
142 <li>スタックに積まれている値(環境)</li> | |
143 </ul> | |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
144 </div> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
145 <!-- PAGE --> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
146 <div class="slide"> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
147 <h1>Continuation Based C (軽量継続)</h1> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
148 <h2>CbCの継続(軽量継続)</h2> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
149 <li>関数コールが無い -> 呼び出し元への復帰がない</li> |
58 | 150 <ul> |
59
6ef99d3e66b2
modify light-weight continuation
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
151 <li>Cの継続から環境を除外</li> |
6ef99d3e66b2
modify light-weight continuation
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
152 <li>続く命令とその命令に必要なデータのみ</li> |
58 | 153 </ul> |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
154 <!-- <li>継続の際にスタックに載せるデータはコードセグメントへの引数だけとなる。</li> --> |
59
6ef99d3e66b2
modify light-weight continuation
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
155 <!-- <li>スタックポインタの位置を変えずにすむ。</li> --> |
6ef99d3e66b2
modify light-weight continuation
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
156 <p style=" margin-right:auto; margin-left:auto;"> |
6ef99d3e66b2
modify light-weight continuation
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
157 <img class="scale" src="./pix/cs_stack.png" style="height: 7em;"> |
6ef99d3e66b2
modify light-weight continuation
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
158 </p> |
6ef99d3e66b2
modify light-weight continuation
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
159 </div> |
6ef99d3e66b2
modify light-weight continuation
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
160 <!-- PAGE --> |
58 | 161 <div class="slide"> |
54 | 162 <h1>Continuation based C </h1> |
163 <small> | |
164 <table width=100% > | |
165 <tr> | |
166 <caption>階乗を求めるCbCのプログラム</caption> | |
167 <td width=50%> | |
168 <pre> | |
169 __code print_factorial(int prod) { | |
170 printf("factorial = %d\n",prod); | |
171 exit(0); | |
172 } | |
58 | 173 |
54 | 174 __code factorial0(int prod, int x) { |
175 if ( x >= 1) { | |
176 goto factorial0(prod*x, x-1); | |
177 }else{ | |
178 goto print_factorial(prod); | |
179 } | |
180 } | |
181 </pre> | |
182 </td> | |
183 <td> | |
184 <pre> | |
185 __code factorial(int x) { | |
186 goto factorial0(1, x); | |
187 } | |
58 | 188 |
54 | 189 int main(int argc, char **argv) { |
190 int i; | |
191 i = atoi(argv[1]); | |
192 goto factorial(i); | |
193 return 0; | |
194 } | |
195 </pre> | |
196 </td> | |
197 </tr> | |
198 </table> | |
199 </small> | |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
200 <li>__code キーワードによるコードセグメントの宣言</li> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
201 <li>goto によるコードセグメントへの継続(Cの関数呼び出しと同等)</li> |
54 | 202 </div> |
203 <!-- PAGE --> | |
204 <div class="slide"> | |
205 <h1>GCC によるコンパイル</h1> | |
206 <li>GCC についての簡単な説明を行う...</li> | |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
207 <li>TODO: NEXT_PASS() の把握</li> |
54 | 208 <img src="./pix/ir.png" style="height: 6em;"> |
209 <li>CbCの実装は主に Parser の部分と RTL を生成する部分に行われる。</li> | |
210 </div> | |
211 <!-- PAGE --> | |
212 <div class="slide"> | |
61
2c543a47737b
modify explanation of fastcall
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
213 <h1>CbCの実装</h1> |
54 | 214 <ul> |
215 <li>シンタックスの追加</li> | |
61
2c543a47737b
modify explanation of fastcall
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
216 <li>レジスタによる引数渡し(fastcall属性の付与)</li> |
54 | 217 <li>Tail Call Elimination</li> |
218 <li>環境付き継続</li> | |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
219 <li>__rectype の実装</li> |
54 | 220 </ul> |
221 </div> | |
222 <!-- PAGE --> | |
223 <div class="slide"> | |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
224 <h1>CbCの実装:シンタックスの追加</h1> |
54 | 225 <ul> |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
226 <li>__code キーワードでのコードセグメントの宣言</li> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
227 <ul> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
228 <li>__code 用idとkeywordを作成。</li> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
229 <li>戻り値が無い為、コードセグメントは void 型の関数で作成される木と同じ木が作られる。</li> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
230 </ul> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
231 <li>goto によるコードセグメントへの継続</li> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
232 <ul> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
233 <li>通常の goto に加え、コードセグメントを呼び出す処理を追加。</li> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
234 <li>コードセグメントへのgoto後は、 return の処理を自動で追加。</li> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
235 </ul> |
54 | 236 </ul> |
61
2c543a47737b
modify explanation of fastcall
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
237 <li class="incremental">追加したgotoシンタックスの実際のソースは次のようになる。</li> |
54 | 238 </div> |
239 <!-- PAGE --> | |
240 <div class="slide"> | |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
241 <h1>CbCの実装:シンタックスの追加</h1> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
242 <h2>gotoシンタックスの追加</h2> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
243 <small> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
244 <pre> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
245 expr = c_parser_expr_no_commas (parser, NULL); |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
246 if (TREE_CODE(expr.value) == CALL_EXPR ) |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
247 { |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
248 location_t loc = c_parser_peek_token (parser)->location; |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
249 cbc_replace_arguments (loc, expr.value); |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
250 |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
251 TREE_TYPE(expr.value) = void_type_node; |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
252 /*tree env = NULL_TREE;**/ |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
253 CbC_IS_CbC_GOTO (expr.value) = 1; |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
254 CALL_EXPR_TAILCALL (expr.value) = 1; |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
255 add_stmt(expr.value); |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
256 stmt = c_finish_return(loc, NULL_TREE, NULL_TREE); /* stmt = c_finish_return (0); */ |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
257 } |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
258 </pre> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
259 </small> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
260 <li>CALL_EXPR_TAILCALLマクロにより tail call フラグを立てている。</li> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
261 <li>cbc_replace_arguments関数は引数のデータを一時的な変数へと代入させる関数</li> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
262 <li>最後にc_finish_return関数によりreturn文を生成している。</li> |
54 | 263 </div> |
264 <!-- PAGE --> | |
265 <div class="slide"> | |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
266 <h1>CbCの実装:シンタックスの追加</h1> |
61
2c543a47737b
modify explanation of fastcall
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
267 <h2>gotoシンタックスの追加</h2> |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
268 <li>最後にリターン文を生成することにより、次へと制御を映させず。また末尾最適化がかかるようになる。</li> |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
269 <table border=1 width=100%> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
270 <tr class="center"> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
271 <small> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
272 <td>実際のコード </td> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
273 <td>GCC 内で処理されるコード</td> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
274 </small> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
275 </tr> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
276 <tr style="margin-top: auto;"> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
277 <td> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
278 <pre> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
279 goto factorial0(1, x); |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
280 </pre> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
281 </td> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
282 <td> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
283 <pre> |
58 | 284 factorial0(1, x); |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
285 return; |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
286 </pre> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
287 </td> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
288 </tr> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
289 </table> |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
290 <li>末尾最適化(末尾除去)については後ほど詳しく説明する。</li> |
54 | 291 </div> |
292 <!-- PAGE --> | |
293 <div class="slide"> | |
61
2c543a47737b
modify explanation of fastcall
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
294 <h1>CbCの実装:引数渡し</h1> |
58 | 295 <li>当初、GCCを使ってコンパイルしたCbCのプログラムはMicro-C版に速度面で勝てなかった。</li> |
296 <ul> | |
297 <li>Micro-Cでは関数呼び出しの際にできるだけレジスタを使うようにしていたため。</li> | |
298 </ul> | |
299 <li class="incremental">そこで、GCC版CbCコンパイラの引数渡しもできるだけレジスタで行うことに</li> | |
300 </div> | |
301 <!-- PAGE --> | |
302 <div class="slide"> | |
61
2c543a47737b
modify explanation of fastcall
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
303 <h1>CbCの実装:引数渡し(fastcall)</h1> |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
304 <li>i386 において関数呼び出しの際、引数渡しをできるだけレジスタを用いるGCCの拡張機能。</li> |
58 | 305 <li>__code で宣言された関数は自動でfastcall属性が付与される。</li> |
306 <small> | |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
307 <pre> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
308 if(!TARGET_64BIT) { |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
309 attrs = build_tree_list (get_identifier("fastcall"), NULL_TREE); |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
310 declspecs_add_attrs(specs, attrs); |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
311 } |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
312 </pre> |
58 | 313 </small> |
314 <p><small>Intel64 ではレジスタが増えている為、fastcallは標準でつくようになっている。</small></p> | |
315 </div> | |
316 <!-- PAGE --> | |
317 <div class="slide"> | |
61
2c543a47737b
modify explanation of fastcall
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
318 <h1>CbCの実装:TCE</h1> |
2c543a47737b
modify explanation of fastcall
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
319 <h2>Tail Call Elimination(TCE):末尾除去</h2> |
62 | 320 <li>関数呼び出しをcallではなくjmp命令で行ことでreturnを1度で済ませる最適化。</li> |
321 <img src="./pix/continuation.png" style="height: 7em;"> | |
322 <li>CbCにおけるコードセグメントへの継続はこのTCEにより実装されている。</li> | |
54 | 323 </div> |
324 <!-- PAGE --> | |
325 <div class="slide"> | |
61
2c543a47737b
modify explanation of fastcall
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
326 <h1>CbCの実装:TCE</h1> |
54 | 327 <li></li> |
328 </div> | |
329 <!-- PAGE --> | |
330 <div class="slide"> | |
62 | 331 <h1>環境付き継続</h1> |
332 <li>CbCにおけるCとの互換性を保つための機能。</li> | |
333 <li>コードセグメントを呼び出したCの関数に戻ることができる。</li> | |
54 | 334 <li></li> |
335 </div> | |
336 <!-- PAGE --> | |
337 <div class="slide"> | |
338 <h1>環境付き継続:クロージャでの実装について</h1> | |
339 <li>『GCC 4.6 と Lion の組合せでは Closure は正しく動作していないことが分かった.』<br>間違い</li> | |
340 <li>訂正</li> | |
341 <ul> | |
342 <li class="incremental">GCC 4.6 への CbC の実装のせいでクロージャがうまくできていなかったことが判明。</li> | |
343 <li class="incremental">GCC 4.6 と Lion でのクロージャは特に問題はない。</li> | |
344 </ul> | |
345 </div> | |
346 <!-- PAGE --> | |
347 <div class="slide"> | |
348 <h1>環境付き継続:クロージャでの実装の問題点</h1> | |
349 <li></li> | |
350 <li></li> | |
351 </div> | |
352 <!-- PAGE --> | |
353 <div class="slide"> | |
354 <h1>環境付き継続: setjmp での実装</h1> | |
355 <li>setjmp での実装</li> | |
356 <small> | |
357 <pre> | |
358 ({ | |
359 int a = setjmp(env); | |
360 int retval; | |
361 void _cbc_internal_return(int retval_, jmp_buf _envp){ | |
362 retval = retval_; | |
363 longjmp(_envp, retval); | |
364 } | |
365 if (a) { | |
366 return retval; | |
367 } | |
368 _cbc_internal_return; | |
369 }) | |
370 </pre> | |
371 </small> | |
372 <li></li> | |
373 </div> | |
374 <!-- PAGE --> | |
375 <div class="slide"> | |
376 <h1>環境付き継続: setjmp での実装の問題</h1> | |
377 <li>GCC 内で setjmp を生成する関数を作る必要がある。</li> | |
378 <li>戻値の型が int </li> | |
379 <ul> | |
380 <li>構造体等ポインタの場合使えない。</li> | |
381 </ul> | |
382 <li class="incremental">setjmp での実装はあまり実用的ではない。</li> | |
383 </div> | |
384 <!-- PAGE --> | |
385 <div class="slide"> | |
57
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
386 <h1>__rectype の実装</h1> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
387 <li>通常、関数の引数に関数ポインタを渡した際は以下の様に使われる。</li> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
388 <small> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
389 <pre> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
390 void factorial(int n, int result, void(*print)()){ |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
391 : |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
392 (*print)(n,result,print,exit1, envp); |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
393 } |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
394 </pre> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
395 </small> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
396 <li>以下の様に扱えるようにしたい。</li> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
397 <small> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
398 <pre> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
399 void factorial(int n, int result, void *print){ |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
400 : |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
401 (*print)(n,result,print,exit1, envp); |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
402 } |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
403 </pre> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
404 </small> |
54 | 405 </div> |
406 <!-- PAGE --> | |
407 <div class="slide"> | |
57
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
408 <h1>__rectype の実装</h1> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
409 <li>そこで、__rectype という予約後を作り、以下の宣言を行えるようにした。</li> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
410 <pre> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
411 __code factorial(int n, int result, __rectype *print) { |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
412 : |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
413 (*print)(n,result,print,exit1, envp); |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
414 } |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
415 </pre> |
54 | 416 </div> |
417 <!-- PAGE --> | |
418 <div class="slide"> | |
419 <h1></h1> | |
420 <li></li> | |
421 </div> | |
422 <!-- PAGE --> | |
423 </div> | |
424 </body> | |
425 </html> |