Mercurial > hg > CbC > old > device
annotate test/conv1.c @ 748:c2c709727221
i64 continue... basic.s assembled.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 13 Nov 2010 22:39:40 +0900 |
parents | 07dce42b67af |
children | 5313ed059cee |
rev | line source |
---|---|
155 | 1 #include "stdio.h" |
2 | |
3 static int loop; | |
725
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
4 #define __environment _CbC_environment |
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
5 #define __return _CbC_return |
155 | 6 |
720 | 7 #if 1 // def __micro_c__ |
155 | 8 #define CC_ONLY 0 |
9 #else | |
10 #define CC_ONLY 1 | |
11 #endif | |
12 | |
13 /* classical function call case (0) */ | |
14 | |
15 f0(int i) { | |
16 int k,j; | |
17 k = 3+i; | |
18 j = g0(i+3); | |
19 return k+4+j; | |
20 } | |
21 | |
22 g0(int i) { | |
23 return h0(i+4)+i; | |
24 } | |
25 | |
26 h0(int i) { | |
27 return i+4; | |
28 } | |
29 | |
30 #if !CC_ONLY | |
31 | |
32 /* straight conversion case (1) */ | |
33 | |
34 typedef char *stack; | |
35 | |
36 struct cont_interface { // General Return Continuation | |
622 | 37 __code (*ret)(); |
155 | 38 }; |
39 | |
729 | 40 __code f_g0(int i,int k,stack sp) ; |
41 | |
622 | 42 __code f(int i,stack sp) { |
155 | 43 int k,j; |
44 k = 3+i; | |
45 goto f_g0(i,k,sp); | |
46 } | |
47 | |
48 struct f_g0_interface { // Specialized Return Continuation | |
622 | 49 __code (*ret)(); |
155 | 50 int i_,k_,j_; |
51 }; | |
52 | |
622 | 53 __code f_g1(int j,stack sp); |
729 | 54 __code g(int i,stack sp) ; |
155 | 55 |
622 | 56 __code f_g0(int i,int k,stack sp) { // Caller |
155 | 57 struct f_g0_interface *c = |
58 (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); | |
59 | |
60 c->ret = f_g1; | |
61 c->k_ = k; | |
62 c->i_ = i; | |
63 | |
64 goto g(i+3,sp); | |
65 } | |
66 | |
622 | 67 __code f_g1(int j,stack sp) { // Continuation |
720 | 68 struct f_g0_interface *c = (struct f_g0_interface *)sp; |
155 | 69 int k = c->k_; |
158 | 70 sp+=sizeof(struct f_g0_interface); |
71 c = (struct f_g0_interface *)sp; | |
72 goto (c->ret)(k+4+j,sp); | |
155 | 73 } |
74 | |
622 | 75 __code g_h1(int j,stack sp); |
729 | 76 __code h(int i,stack sp) ; |
572 | 77 |
622 | 78 __code g(int i,stack sp) { // Caller |
155 | 79 struct f_g0_interface *c = |
80 (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); | |
81 | |
82 c->ret = g_h1; | |
83 c->i_ = i; | |
84 | |
85 goto h(i+3,sp); | |
86 } | |
87 | |
622 | 88 __code g_h1(int j,stack sp) { // Continuation |
720 | 89 struct f_g0_interface *c = (struct f_g0_interface *)sp; |
155 | 90 int i = c->i_; |
158 | 91 sp+=sizeof(struct f_g0_interface); |
92 c = (struct f_g0_interface *)sp; | |
93 goto (c->ret)(j+i,sp); | |
155 | 94 } |
95 | |
622 | 96 __code h(int i,stack sp) { |
720 | 97 struct f_g0_interface *c = (struct f_g0_interface *)sp; |
158 | 98 goto (c->ret)(i+4,sp); |
155 | 99 } |
100 | |
101 struct main_continuation { // General Return Continuation | |
622 | 102 __code (*ret)(); |
729 | 103 __code (*main_ret)(int,void *); |
155 | 104 void *env; |
105 }; | |
106 | |
622 | 107 __code main_return(int i,stack sp) { |
155 | 108 if (loop-->0) |
109 goto f(233,sp); | |
748
c2c709727221
i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
110 printf("#0109:%d\n",i); |
725
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
111 goto (( (struct main_continuation *)sp)->main_ret)(0, |
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
112 ((struct main_continuation *)sp)->env); |
155 | 113 } |
114 | |
115 /* little optimzation without stack continuation (2) */ | |
116 | |
729 | 117 __code g2(int i,int k,int j,char *sp) ; |
118 | |
622 | 119 __code f2(int i,char *sp) { |
155 | 120 int k,j; |
121 k = 3+i; | |
122 goto g2(i,k,i+3,sp); | |
123 } | |
124 | |
729 | 125 __code h2(int i,int k,char *sp) ; |
126 | |
622 | 127 __code g2(int i,int k,int j,char *sp) { |
155 | 128 j = j+4; |
129 goto h2(i,k+4+j,sp); | |
130 } | |
131 | |
729 | 132 __code main_return2(int i,stack sp) ; |
133 | |
622 | 134 __code h2_1(int i,int k,int j,char *sp) { |
155 | 135 goto main_return2(i+j,sp); |
136 } | |
137 | |
622 | 138 __code h2(int i,int k,char *sp) { |
155 | 139 goto h2_1(i,k,i+4,sp); |
140 } | |
141 | |
622 | 142 __code main_return2(int i,stack sp) { |
155 | 143 if (loop-->0) |
144 goto f2(233,sp); | |
748
c2c709727221
i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
145 printf("#0144:%d\n",i); |
725
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
146 goto (( (struct main_continuation *)sp)->main_ret)(0, |
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
147 ((struct main_continuation *)sp)->env); |
155 | 148 } |
149 | |
150 /* little optimizaed case (3) */ | |
151 | |
729 | 152 __code g2_1(int k,int i,char *sp) ; |
153 | |
622 | 154 __code f2_1(int i,char *sp) { |
155 | 155 int k,j; |
156 k = 3+i; | |
157 goto g2_1(k,i+3,sp); | |
158 } | |
159 | |
729 | 160 __code h2_11(int i,int k,char *sp) ; |
161 | |
622 | 162 __code g2_1(int k,int i,char *sp) { |
155 | 163 goto h2_11(k,i+4,sp); |
164 } | |
165 | |
622 | 166 __code f2_0_1(int k,int j,char *sp); |
167 __code h2_1_1(int i,int k,int j,char *sp) { | |
155 | 168 goto f2_0_1(k,i+j,sp); |
169 } | |
170 | |
622 | 171 __code h2_11(int i,int k,char *sp) { |
155 | 172 goto h2_1_1(i,k,i+4,sp); |
173 } | |
174 | |
622 | 175 __code f2_0_1(int k,int j,char *sp) { |
155 | 176 goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); |
177 } | |
178 | |
622 | 179 __code main_return2_1(int i,stack sp) { |
155 | 180 if (loop-->0) |
181 goto f2_1(233,sp); | |
748
c2c709727221
i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
182 printf("#0181:%d\n",i); |
725
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
183 goto (( (struct main_continuation *)sp)->main_ret)(0, |
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
184 ((struct main_continuation *)sp)->env); |
155 | 185 } |
186 | |
187 #define STACK_SIZE 2048 | |
720 | 188 char main_stack[STACK_SIZE]; |
189 #define stack_last (main_stack+STACK_SIZE) | |
155 | 190 |
191 #endif | |
192 | |
193 #define LOOP_COUNT 10000000 | |
194 | |
195 main(int ac,char *av[]) | |
196 { | |
197 #if !CC_ONLY | |
198 struct main_continuation *cont; | |
199 stack sp = stack_last; | |
200 #endif | |
201 int sw; | |
202 int j; | |
172 | 203 if (ac==2) sw = atoi(av[1]); |
204 else sw=3; | |
155 | 205 |
206 if (sw==0) { | |
207 for(loop=0;loop<LOOP_COUNT;loop++) { | |
208 j = f0(233); | |
209 } | |
748
c2c709727221
i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
210 printf("#0209:%d\n",j); |
155 | 211 #if !CC_ONLY |
212 } else if (sw==1) { | |
213 loop = LOOP_COUNT; | |
214 sp -= sizeof(*cont); | |
215 cont = (struct main_continuation *)sp; | |
216 cont->ret = main_return; | |
720 | 217 cont->main_ret = __return; |
218 cont->env = __environment; | |
155 | 219 goto f(233,sp); |
220 } else if (sw==2) { | |
221 loop = LOOP_COUNT; | |
222 sp -= sizeof(*cont); | |
223 cont = (struct main_continuation *)sp; | |
224 cont->ret = main_return2; | |
720 | 225 cont->main_ret = __return; |
226 cont->env = __environment; | |
155 | 227 goto f2(233,sp); |
228 } else if (sw==3) { | |
229 loop = LOOP_COUNT; | |
230 sp -= sizeof(*cont); | |
231 cont = (struct main_continuation *)sp; | |
232 cont->ret = main_return2_1; | |
720 | 233 cont->main_ret = __return; |
234 cont->env = __environment; | |
155 | 235 goto f2_1(233,sp); |
236 #endif | |
237 } | |
575 | 238 return 0; |
155 | 239 } |
240 | |
241 /* end */ |