Mercurial > hg > CbC > old > device
changeset 155:ccb2002d8a31
*** empty log message ***
author | kono |
---|---|
date | Tue, 05 Aug 2003 13:00:16 +0900 |
parents | 3edd10355434 |
children | da529eab5618 |
files | Changes test/conv1.c |
diffstat | 2 files changed, 295 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Thu Jul 31 20:57:39 2003 +0900 +++ b/Changes Tue Aug 05 13:00:16 2003 +0900 @@ -3220,3 +3220,79 @@ それぞれの利点と欠点を考察すればCWは通るんじゃない? (本気?) + +Mon Aug 4 12:48:40 JST 2003 + +converted call +480 +8.070u 0.010s 0:08.22 98.2% 0+0k 0+2io 0pf+0w +call +480 +6.590u 0.000s 0:06.67 98.8% 0+0k 0+0io 0pf+0w + +だいたい10%ぐらい遅いなぁ。(なんで?) げ、-O6 だと十倍違う... + +げ、powerpc の subroutine 内のstaticが通らんじゃん。 + +サブルーチンを三段に直しました。 + +% time ./a.out 0 +720 +9.590u 0.010s 0:09.64 99.5% 0+0k 0+0io 0pf+0w +% time ./a.out 1 +719 +12.610u 0.020s 0:12.71 99.3% 0+0k 0+0io 0pf+0w +% time ./a.out 2 +720 +6.310u 0.020s 0:06.41 98.7% 0+0k 0+0io 0pf+0w +% vi test/conv1.c +% gcc -O6 test/conv1.c +% ./a.out 0 +720 +% time ./a.out 0 +720 +1.990u 0.020s 0:02.03 99.0% 0+0k 0+2io 0pf+0w +% gcc test/conv1.c +% time ./a.out 0 +720 +7.530u 0.000s 0:07.64 98.5% 0+0k 0+0io 0pf+0w +% gcc -O2 test/conv1.c +% time ./a.out 0 +720 +3.520u 0.010s 0:03.55 99.4% 0+0k 0+0io 0pf+0w +% + +ま、こんなものかな。-O2 に負けるなよって気もするが。 + +琉大は40Mbps + +Intel PC (on PowerPC) の場合 + +[root@localhost ~/device]# time ./a.out 2 +470 +0.660u 0.010s 0:02.37 28.2% 0+0k 0+0io 92pf+0w +[root@localhost ~/device]# time ./a.out 3 +720 +0.920u 0.020s 0:01.74 54.0% 0+0k 0+0io 92pf+0w +[root@localhost ~/device]# gcc test/conv1.c +[root@localhost ~/device]# ./a.out 0 + +[root@localhost ~/device]# time ./a.out 0 +720 +1.310u 0.030s 0:01.39 96.4% 0+0k 0+0io 92pf+0w +[root@localhost ~/device]# gcc -O test/conv1.c +[root@localhost ~/device]# time ./a.out 0 +720 +1.130u 0.030s 0:01.16 100.0% 0+0k 0+0io 92pf+0w +[root@localhost ~/device]# gcc -O4 test/conv1.c +[root@localhost ~/device]# time ./a.out 0 +720 +0.870u 0.000s 0:00.87 100.0% 0+0k 0+0io 92pf+0w +[root@localhost ~/device]# gcc -O6 test/conv1.c +[root@localhost ~/device]# time ./a.out 0 +720 +0.850u 0.020s 0:00.88 98.8% 0+0k 0+0io 92pf+0w +[root@localhost ~/device]# + +PowerPC の場合は、PIC symbol がやっぱり遅いね。 +こいつをなんとかするだけでだいぶ違うかも知れない。
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/conv1.c Tue Aug 05 13:00:16 2003 +0900 @@ -0,0 +1,219 @@ +#include "stdio.h" + +static int loop; + +#ifdef __micro_c__ +#define CC_ONLY 0 +#else +#define CC_ONLY 1 +#endif + +/* classical function call case (0) */ + +f0(int i) { + int k,j; + k = 3+i; + j = g0(i+3); + return k+4+j; +} + +g0(int i) { + return h0(i+4)+i; +} + +h0(int i) { + return i+4; +} + +#if !CC_ONLY + +/* straight conversion case (1) */ + +typedef char *stack; + +struct cont_interface { // General Return Continuation + code (*ret)(); +}; + +code f(int i,stack sp) { + int k,j; + k = 3+i; + goto f_g0(i,k,sp); +} + +struct f_g0_interface { // Specialized Return Continuation + code (*ret)(); + int i_,k_,j_; +}; + +code f_g1(int j,stack sp); + +code f_g0(int i,int k,stack sp) { // Caller + struct f_g0_interface *c = + (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); + + c->ret = f_g1; + c->k_ = k; + c->i_ = i; + + goto g(i+3,sp); +} + +code f_g1(int j,stack sp) { // Continuation + struct f_g0_interface *c = sp; + int k = c->k_; + sp += sizeof(struct f_g0_interface); + goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); +} + +code g(int i,stack sp) { // Caller + struct f_g0_interface *c = + (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); + + c->ret = g_h1; + c->i_ = i; + + goto h(i+3,sp); +} + +code g_h1(int j,stack sp) { // Continuation + struct f_g0_interface *c = sp; + int i = c->i_; + sp += sizeof(struct f_g0_interface); + goto (( (struct cont_interface *)sp)->ret)(j+i,sp); +} + +code h(int i,stack sp) { + goto (( (struct cont_interface *)sp)->ret)(i+4,sp); +} + +struct main_continuation { // General Return Continuation + code (*ret)(); + code (*main_ret)(); + void *env; +}; + +code main_return(int i,stack sp) { + if (loop-->0) + goto f(233,sp); + printf("%d\n",i); + goto (( (struct main_continuation *)sp)->main_ret)(0), + ((struct main_continuation *)sp)->env; +} + +/* little optimzation without stack continuation (2) */ + +code f2(int i,char *sp) { + int k,j; + k = 3+i; + goto g2(i,k,i+3,sp); +} + +code g2(int i,int k,int j,char *sp) { + j = j+4; + goto h2(i,k+4+j,sp); +} + +code h2_1(int i,int k,int j,char *sp) { + goto main_return2(i+j,sp); +} + +code h2(int i,int k,char *sp) { + goto h2_1(i,k,i+4,sp); +} + +code main_return2(int i,stack sp) { + if (loop-->0) + goto f2(233,sp); + printf("%d\n",i); + goto (( (struct main_continuation *)sp)->main_ret)(0), + ((struct main_continuation *)sp)->env; +} + +/* little optimizaed case (3) */ + +code f2_1(int i,char *sp) { + int k,j; + k = 3+i; + goto g2_1(k,i+3,sp); +} + +code g2_1(int k,int i,char *sp) { + goto h2_11(k,i+4,sp); +} + +code f2_0_1(int k,int j,char *sp); +code h2_1_1(int i,int k,int j,char *sp) { + goto f2_0_1(k,i+j,sp); +} + +code h2_11(int i,int k,char *sp) { + goto h2_1_1(i,k,i+4,sp); +} + +code f2_0_1(int k,int j,char *sp) { + goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); +} + +code main_return2_1(int i,stack sp) { + if (loop-->0) + goto f2_1(233,sp); + printf("%d\n",i); + goto (( (struct main_continuation *)sp)->main_ret)(0), + ((struct main_continuation *)sp)->env; +} + +#define STACK_SIZE 2048 +stack main_stack[STACK_SIZE]; +#define stack_last (&main_stack[STACK_SIZE]) + +#endif + +#define LOOP_COUNT 10000000 + +main(int ac,char *av[]) +{ +#if !CC_ONLY + struct main_continuation *cont; + stack sp = stack_last; +#endif + int sw; + int j; + if (ac!=2) exit(0); + sw = atoi(av[1]); + + if (sw==0) { + for(loop=0;loop<LOOP_COUNT;loop++) { + j = f0(233); + } + printf("%d\n",j); +#if !CC_ONLY + } else if (sw==1) { + loop = LOOP_COUNT; + sp -= sizeof(*cont); + cont = (struct main_continuation *)sp; + cont->ret = main_return; + cont->main_ret = return; + cont->env = environment; + goto f(233,sp); + } else if (sw==2) { + loop = LOOP_COUNT; + sp -= sizeof(*cont); + cont = (struct main_continuation *)sp; + cont->ret = main_return2; + cont->main_ret = return; + cont->env = environment; + goto f2(233,sp); + } else if (sw==3) { + loop = LOOP_COUNT; + sp -= sizeof(*cont); + cont = (struct main_continuation *)sp; + cont->ret = main_return2_1; + cont->main_ret = return; + cont->env = environment; + goto f2_1(233,sp); +#endif + } +} + +/* end */