annotate presen/cbc.md @ 42:1d66e06ae2c2 draft

modify
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 28 Feb 2012 22:47:04 +0900
parents ad0ab1378ae6
children 8539cd84106e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
1 Continuation based C の <br> GCC 4.6による実装
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 =========
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 ---
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
6 研究目的
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 ---------
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
39
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
9 .notes:
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
11 <li><font color=red size=5em>状態遷移記述をベースとしたより細かい単位でのプログラミングを実現する</font></li>
38
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
12 - 本研究室ではコードセグメント単位で記述するプログラミング言語Continuation based C (以下CbC)という言語を提案している。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
13 - CbC のコンパイラは Micro-C 版 と GCC 版(以下 CbC-GCC) が開発されている。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
14 - しかし, CbC-GCC はいくつかのバグがあり機能に修正の余地があった。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
15 - また、GCC の最新の機能を利用するためにも CbC-GCC は GCC のアップデートに合わせていく必要がある。
34
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
16
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
17 <h2>本研究では CbC-GCC のアップデートを行い、より良いコードを生成する CbC の処理系を開発した。</h2>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 ---
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 Continuation based C
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 ========
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 コードセグメント単位での記述と継続を基本としたプログラミング言語
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 ---------
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 <li>コーセグメント:CbC におけるプログラムの基本単位</li>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 <ul>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 <li>C の関数よりも細かな単位</li>
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
29 <li>構文は C と同じだが、C から関数コールとループ制御が取り除かれた形</li>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 <li>コードセグメントの末尾処理で別のコードセグメントへ継続(goto)することで CbC のプログラムは続いていく。</li>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 </ul>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
33 <table width=100% border=1>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
34 <tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
35 <td style="margin-left:auto; margin-right: auto; text-align: center; width:50%" >
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
36 <img src="./pix/codesegment.png" style="width:100%">
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 </td>
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
38 <td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
39 <pre style="margin-left:5%">
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
40 __code cs_a(int num) {
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
41 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
42 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
43 goto cs_b();
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
44 }
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
45 </pre>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
46 </td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
47 </tr>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 </table>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 ---
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 Continuation based C
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 ========
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 継続:現在の処理を実行していく為の情報
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 ---------
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 <table width=100% border=1>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 <tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 <td><h2>Cの継続</h2></td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 <td><h2>CbCの継続(軽量継続)</h2></td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 </tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 <tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 <td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 <ul>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 <li>続く命令のアドレス</li>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 <li>命令に必要なデータ</li>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 <li>スタックに積まれている値(環境)</li>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 </ul>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 </td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 <td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 <ul>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 <li>Cの継続から環境を除外</li>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 <li>続く命令とその命令に必要なデータのみ</li>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 </ul>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 </td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 </tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 <t>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 <td style="margin-left:auto; margin-right: auto; text-align: center;">
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 <img class="scale" src="./pix/func_call.png" style="height: 18em;">
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 </td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 <td style="margin-left:auto; margin-right: auto; text-align: center;">
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 <img class="scale" src="./pix/cs_stack.png" style="height: 18em;">
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 </td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 </tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 </table>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 ---
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 Continuation based C
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 ========
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 <table width=100% border=1>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 <caption>階乗を求める CbC のプログラム</caption>
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
96 <td width=50%>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
97 <pre style="margin-left:5%">
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
98 \_\_code print_factorial(int prod)
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
99 {
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
100 printf("factorial = %d\n",prod);
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
101 exit(0);
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
102 }
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
103 \_\_code factorial0(int prod, int x)
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
104 {
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
105 if ( x >= 1) {
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
106 goto factorial0(prod\*x, x-1);
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
107 }else{
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
108 goto print_factorial(prod);
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
109 }
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
110 }
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
111 \_\_code factorial(int x)
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
112 {
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
113 goto factorial0(1, x);
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
114 }
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
115 int main(int argc, char \*\*argv)
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
116 {
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
117 int i;
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
118 i = atoi(argv[1]);
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
119 goto factorial(i);
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
120 }
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 </pre>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 </td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 <td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 <li>__code によるコードセグメントの宣言</li>
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
125 <li>引数付きの goto でコードセグメントを呼び出すことができる</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
126 <li>内部では call ではなく jmp 命令でコードセグメントの処理が遷移している</li>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 </td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 </table>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 ---
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
133 Gnu Compiler Collection (GCC)
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
134 ========
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
135 <li>GCC: オープンソースのコンパイラ群</li>
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
136 <li>ここで扱う GCC はソースコードをアセンブラに変換する『cc1』のことを指す。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
137 <li>GCC がソースコードを読み込みアセンブラ言語を出力するまでの流れは以下の図のようになる。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
138 <table width=100%>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
139 <caption>GCC のアセンブラ言語出力までの流れ</caption>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
140 <td style="margin:auto; text-align:center;">
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
141 <img src="./pix/ir.png" style="height:15em">
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
142 </td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
143 </table>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
144 <li>ソースコードはアセンブラに変換される間に 4 つのデータ構造に変換される。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
145 <li>この中でも CbC の実装では Parser と RTL の生成部分に手が加えられている。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
146
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
147 ---
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
148
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
149
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
150 CbC の実装 : 軽量継続
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 ========
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
152 <li>CbC-GCC の軽量継続は最適化の1つ, <font color=red>Tail Call Elimination(末尾除去)</font>により実装されている.</li>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 Tail Call Elimination
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 ---------
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 <li>関数呼び出しを call ではなく jmp 命令で行う最適化</li>
31
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
157 <li>例えば、以下の場合関数 g は jmp 命令で関数 f へと処理が移る</li>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158
31
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
159 <table width=100% border=1>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 <tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 <td width=50%>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 <pre>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 void f(int a, int b) {
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 printf("f: a=%d b=%d\n",a,b);
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 return ;
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 }
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 void g(int a, int b){
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 printf("g: a=%d b=%d\n",a,b);
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 f(a,b);
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 return;
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 }
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 int main() {
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 g(3,4);
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 return 0;
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
177 }</pre>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 </td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 <td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 <img src="./pix/continuation.png" style="height:80%;">
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 </td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 </tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 </table>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 ---
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188
40
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
189 CbC の実装: 末尾除去の強制
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 ========
40
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
191 末尾除去の条件をチェックする関数
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 ---------
40
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
193 - 関数が末尾除去にかかる為には幾つか条件があり、その条件はある関数によってチェックされる。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
194 - その関数を元に、『コードセグメントは末尾除去』にかける専用の関数を用意していた。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
195 - しかしこの方法は、元になった関数が修正に合わせて専用の関数も修正を行う必要があった。
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
196
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
197 実装の修正とその利点
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
198 ---------
40
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
199 - しかし, 今回の実装でその関数を無くし, 末尾除去のフラグを強制的に立たせる実装に変更。
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
200 - 専用関数がなくなったことで、今後より楽なアップデートを行なっていくことができるようになった。
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
201 - また、コードセグメントへの継続が jmp ではなく call 命令で行われるバグがあったが修正できた。
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 ---
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
208
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
209 GCC-4.5, GCC-4.6 の性能比較
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 ========
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
211 <li><font color=red size=5em>本研究では GCC-4.5 から GCC-4.6 へのアップデートを行った。</font></li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
212 <li>この 2 つのバージョンを用いて生成したプログラムの速度比較を行った。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
213 <li>conv1: 加算と継続を交互に繰り返すプログラム</li>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
215 <table width=100% border=1>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
216 <caption>各コンパイラにより生成されたプログラムの速度比較</caption>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
217 <tr>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 <td style="margin:auto; text-align:center;">
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 <img src="./pix/conv1_for_resume.png" style="height:15em">
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 </td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 <td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 <img src="./pix/conv1_mac_for_presen.png" style="height:15em">
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 </td>
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
224 </tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
225 <tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
226 <td style="text-align:center;">x86/Linux</td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
227 <td style="text-align:center;">x86/OS X (10.7)</td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
228 </tr>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 </table>
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
230 <li>Mac の GCC-4.5 では動かなかった 32bit のプログラムが GCC-4.6 では問題なく動いている。</li>
40
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
231 <li>引数 2、3 は手動で最適化をかけている。</li>
31
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
232 <li>引数 1 の結果では 32bit, 64bit 共に GCC-4.6 の方が 1.5倍以上早い</li>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233
34
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
234
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 ---
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
238
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
239 GCC-4.6 の最適化
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 ========
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
241 - GCC-4.6 では最適化の 1つ『インライン展開』が強化されている。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
242
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
243 インライン展開
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
244 ---------
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
245 - 関数の処理をそのまま関数呼び出し部に展開することで call を省略できる最適化
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
246
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 <table width=100% border=1>
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
248 <caption><h3>インライン展開の例</h3></caption>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
249 <tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
250 <td width=50%>
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
251 <pre style="margin-left:5%">
39
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
252 void func_b(){
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
253 A;
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
254 B;
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
255 }
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
256
39
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
257 void func_a() {
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
258 func_b();
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
259 func_b();
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
260 }
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
261 </pre>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
262 </td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
263 <td>
37
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
264 <pre style="margin-left:5%">
39
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
265 void func_a() {
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
266 A;
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
267 B;
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
268 A;
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
269 B;
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
270 }
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
271 </pre>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
272 </td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
273 </tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
274 </table>
39
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
275 <li>func_b の呼び出しがなくなっている。</li>
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
276
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
277
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
278 ---
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
279
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
280 <h1>最適化の比較</h1>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
281 <table width=100% border=1>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
282 <caption><h3>それぞれの最適化にかかった conv1プログラムの挙動(引数 1)</h3></caption>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 <tr>
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
284 <td width=30%>最適化なし</td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
285 <td width=30%>GCC-4.5の最適化(-O2)</td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
286 <td width=30%>GCC-4.6の最適化(-O2)</td>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 </tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 <tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 <td style="margin:auto; text-align:center;">
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
290 <img src="./pix/state_conv1_noopt.png" style="width:65%;">
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
291 </td>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 <td style="margin:auto; text-align:center;">
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
293 <img src="./pix/state_conv1_45.png" style="width:65%;">
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
294 </td>
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 <td style="margin:auto; text-align:center;">
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
296 <img src="./pix/state_conv1_46.png" style="width:65%;">
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 </td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 </tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 </table>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
301 - 最適化無しに比べると GCC-4.5、 GGC-4.6 共にコードセグメントの数が減っている。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
302 - GCC-4.5 でもインライン展開はされているが、GCC-4.6 はより良い最適化がかけられている。
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 ---
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306
38
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
307 最新バージョンに合わせる有用性
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
308 ========
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
310 - 今回の『インライン展開』のように GCC の最適化は日々改良されている。
29
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
311 - また、既存の最適化の改良だけでなく新たな最適化の追加等も行われていく。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
312 - それらの恩恵を受ける為にも GCC のアップデートに合わせていく事は今後も重要である。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
313
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
314 ---
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
315
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
316
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 まとめ
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 ========
29
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
320 - 今回 CbC-GCC を GCC-4.6 へとアップデートを行った。
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
321 - アップデートにより、よりよいコードを生成する CbC のコンパイラを用意することができた。
39
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
322 - また、最適化の強制付与といった実装の修正も行えた。
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
323 - 細かな実装を除けば, CbC-GCC は今後 GCC のアップデートに合わせていくだけとなる。
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 今後の課題
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 ---------
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 - LLVM ベースの CbC コンパイラの開発
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 - google Go 言語への実装の検討
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 ---
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
332
39
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
333
40
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
334 CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
335 ========
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
336 <li><font color=red size=5em>状態遷移記述をベースとしたより細かい単位でのプログラミングを実現する</font></li>
42
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
337 <li>組込みソフト、Real-time処理、通信プロトコル記述、どれも状態遷移ベース</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
338 <li>現存する記述言語は状態遷移の記述に向いていない</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
339 <li>スタックが状態を隠蔽するため、分割しにくい、検証が難しい</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
340 <li>以上の問題を解決する言語として CbC は提案されている。</li>
40
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
341
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
342 具体的な CbC の利用予定
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
343 ---------
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
344 - モデル検査
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
345 - Cerium の実装
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
346
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
347 ---
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
348
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
349 Tail Call Elimination
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
350 ========
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
351 関数が Tail Call Elimination にかかる条件
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
352 ---------
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
353 <ul>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
354 <li>関数を呼び出す側(caller)と呼び出される側(callee)の戻値の型が一致している。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
355 <li>関数呼び出しがリターン直前に行われている。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
356 <li>呼び出される関数(callee)の引数に用いられるスタックサイズが呼出元(caller)のそれより少ない。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
357 <li>引数の並びのコピーに上書きがない。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
358 </ul>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
359
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
360 条件回避の為の CbC の実装内容
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
361 ---------
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
362 <ul>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
363 <li>コードセグメントの型はvoid型で統一する。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
364 <li>gotoの直後に自動で return を置く。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
365 <li>スタックサイズは固定にする。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
366 <li>引数は一旦、一時変数にコピーする。</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
367 </ul>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
368
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
369 ---
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
370
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
371
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
372
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
373
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
374
34
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
375 jmp と call
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
376 ========
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
377 <table width=100%>
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
378 <caption>インライン展開無しの conv1 プログラム実行結果</caption>
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
379 <td style="text-align:center;">
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
380 <img src="./pix/fno_inline.png">
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
381 </td>
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
382 </table>
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
383
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
384 ---
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
385
39
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
386 conv1 プログラム
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
387 ========
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
388 <li>性能評価で用いた conv1 プログラムの C 版</li>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
389 <pre style="width:5%;" border=1>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
390 f0(int i) {
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
391 int k,j;
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
392 k = 3+i;
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
393 j = g0(i+3);
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
394 return k+4+j;
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
395 }
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
396 g0(int i) {
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
397 return h0(i+4)+i;
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
398 }
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
399 h0(int i) {
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
400 return i+4;
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
401 }</pre>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
402 <li>性能評価はこのプログラムを CbC へと書き換えて行なっている。</li>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
403
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
404 ---
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
405
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
406
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
407 CbC-GCC のアップデート手法
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
408 ========
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
409
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
410 <ol>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
411 <li>GCC のソースを入れるリポジトリを用意する。</li>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
412 <li>GCC のリポジトリの中身を全て消し、新しい GCC を入れて新しいファイルは追加、消えたファイルは削除する。</li>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
413 <li>コミット</li>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
414 </ol>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
415
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
416
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
417 CbC-GCC のリポジトリ
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
418 ---------
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
419 <ol>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
420 <li>GCC のソースから pull</li>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
421 <li>merge を行う</li>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
422 <li>衝突のあったファイルを手動でマージする</li>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
423 <li>コミット</li>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
424 </ol>
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
425
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
426 ---
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
427
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
428
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
429
a6540714dda9 modify presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
430
34
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
431
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
432 構文の追加
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
433 ========
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
434 リカーシブタイプの宣言に使う"__rectype"
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
435 ---------
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
436 - 関数宣言時、以下のように引数に自分自身を指す型を入れたい。
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
437 <pre>
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
438 \_\_code func(int, func*);
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
439 <pre>
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
440 - 上記の宣言ではエラーがでる。その為、以下のような宣言になる。
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
441 <pre>
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
442 \_\_code func(int, \_\_code (*)());
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
443 </pre>
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
444 - しかし、これでは正しい情報をコンパイラに渡せていない。関数ポインタの引数に型情報が入っていないからである。
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
445 <pre>
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
446 \_\_code func(int, \_\_code (*)(int, \_\_code(*)(int, \_\_code(*)(int, ...))))
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
447 </pre>
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
448 - だが、正しい情報を渡そうとすると上記のように再帰してしまい、宣言できない。
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
449 - そこで __rectype という構文を追加して宣言中の関数自身を指すようにした。
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
450 <pre>
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
451 \_\_code func(int, rectype*);
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
452 </pre>
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
453
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
454
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
455 ---
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
456
3922a95e99a8 commit presen
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
457
30
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
458 conv1 プログラム
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
459 ========
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
460 - conv1 プログラムでは計算と継続を交互に繰り返し行なう。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
461 - しかし状態のいくつかへは関数ポインタとして保存させておき継続を行う。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
462 <pre>
32
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
463 \_\_code g(int i,stack sp) { // Caller
30
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
464 struct f_g0_interface *c =
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
465 (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface));
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
466 c->ret = g_h1;
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
467 c->i_ = i;
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
468 goto h(i+3,sp);
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
469 }
32
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
470 \_\_code h(int i,stack sp) {
30
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
471 struct f_g0_interface *c = (struct f_g0_interface *)sp;
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
472 goto (c->ret)(i+4,sp);
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
473 }
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
474 </pre>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
475
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
476 - 関数ポインタへの継続はインライン展開されない。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
477
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
478 ---
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
479
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
480
28
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
481 CbC の実装: 環境付き継続
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
482 ========
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
483 - 環境付き継続: C との互換を取るための機能。継続を行った C の関数に戻ることができる。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
484 - _CbC_return、 _CbC_environment キーワードを使うことで使える。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
485 - 以下の使い方の場合、戻値 1 を返す。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
486 <pre>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
487 __code c1(__code ret(int,void *),void *env) {
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
488 goto ret(1,env);
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
489 }
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
490 int main() {
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
491 goto c1(__return, __environment);
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
492 }
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
493 </pre>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
494
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
495 - 今回この環境付き継続をスレッドセーフの実装へと修正した。
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
496
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
497
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
498 ---
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
499
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 CbC 引数渡し
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 ========
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 <li>CbC では引数渡しにできるだけレジスタを用いるようにしている.</li>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 <table border=1 width=100%>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 <caption><small>fastcall属性有・無の実行速度</small></caption>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 <tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 <td width=50% style="text-align:center;">fastcall無し</td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 </tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 <tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 <td style="margin:auto; text-align:center;">
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 <img src="./pix/linux_conv_nofastcall.png" style="height:15em;">
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 </td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 </tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 <tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 <td width=50% style="text-align:center;">fastcall有り</td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 <tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 <td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 <img src="./pix/linux_conv_fastcall.png" style="height:15em;">
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 </td>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 </tr>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 </table>
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 ---
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527
32
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
528 引数の並びに上書きコピー
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
529 ========
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
530 <li>以下の呼び出しを行うと、スタックの書き換えがおこる</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
531 <pre>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
532 void funcA(int a, int b) {
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
533 funcB(b, a);
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
534 }
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
535 </pre>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
536
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
537 <table width=100%>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
538 <tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
539 <td style="margin:auto; text-align:center;">
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
540 <img src="./pix/cs_prog.png">
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
541 </td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
542 </tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
543 </table>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
544
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
545
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
546 ---
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
547
29
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
548 最適化の比較
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
549 ========
32
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
550
29
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
551 <table width=100% border=1>
35
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
552 <caption>各コンパイラにより生成されたコードの速度比較</caption>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
553 <tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
554 <td style="margin:auto; text-align:center;">
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
555 <img src="./pix/O3_conv1_linux.png" style="height:15em">
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
556 </td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
557 <td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
558 <img src="./pix/O3_conv1_mac.png" style="height:15em">
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
559 </td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
560 </tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
561 <tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
562 <td style="text-align:center;">x86/Linux</td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
563 <td style="text-align:center;">x86/OS X (10.7)</td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
564 </tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
565 </table>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
566
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
567
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
568
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
569 ---
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
570
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
571
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
572
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
573 最適化の比較
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
574 ========
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
575
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
576 <table width=100% border=1>
29
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
577 <caption>それぞれの最適化により吐かれたアセンブラコード</caption>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
578 <tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
579 <td width=50% style="text-align:center;">CbC-GCC-4.5</td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
580 <td width=50% style="text-align:center;">CbC-GCC-4.6</td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
581 </tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
582
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
583 <tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
584 <td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
585 <pre>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
586 main:
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
587 call f
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
588 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
589 jmp f_g0
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
590 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
591 movq $f_g1, -24(%rdx)
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
592 addl $10, %edi
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
593 movq $g_h1, -48(%rdx)
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
594 jmp g_h1
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
595 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
596 movq 24(%rsi), %rdx
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
597 movq %rax, %rsi
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
598 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
599 jmp *%rdx
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
600 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
601 movq 24(%rsi), %rdx
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
602 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
603 jmp *%rdx
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
604 </pre>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
605 </td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
606 <td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
607 <pre>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
608 main:
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
609 movq $f_g1, main_stack+2000(%rip)
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
610 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
611 call g_h1
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
612 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
613 movq 24(%rax), %rdx
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
614 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
615 jmp *%rdx
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
616 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
617 movq 24(%rax), %rdx
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
618 :
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
619 jmp *%rdx
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
620 </pre>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
621 </td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
622 </tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
623 <!--
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
624 <tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
625 <td></td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
626 <td></td>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
627 </tr>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
628 -->
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
629
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
630 </table>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
631 <li>関数を展開してその場で計算する『インライン展開』がより強力になっているのが確認できる</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
632 <!--
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
633 <li>保存していた関数ポインタへの継続はインライン展開は行われない</li>
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
634 -->
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
635
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
636 ---
26
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
637
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
638
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
639
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
640
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
642
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
643
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646
6b5277a9bc0f add cbc.md
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647