Mercurial > hg > CbC > old > device
changeset 716:21f770a3b298
*** empty log message ***
author | kono |
---|---|
date | Fri, 16 Nov 2007 21:46:20 +0900 |
parents | 83e18db76c96 |
children | c1542a2482b1 |
files | Changes mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code-spu.c mc-code.h mc-codegen.c mc-codegen.h mc-parse.c mc.h |
diffstat | 11 files changed, 93 insertions(+), 77 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Wed Nov 14 19:36:55 2007 +0900 +++ b/Changes Fri Nov 16 21:46:20 2007 +0900 @@ -9694,6 +9694,26 @@ parallel assign でレジスタをsaveしているけど、size_of_int だと 足りない。なので、get_register_var に変えるべきでしょう。 (もったいないけどね) +memmove との干渉があるので、get_register は使えない。 target のsize_of_int と compiler の size_of_int も別にしないと。 なるほど。 + +new_lvar 自体を直した方がよさそうだな〜 たくさん使われているし。 + +get resiter var すると、save code が出ちゃうので、微妙に +痛しかゆしなんだよな。まぁ、それに文句言うなら、もっと、 +ちゃんと、register assignment しないといけないわけだけど。 + +データ型を拡張しやすくするのは重要だよね。C++ じゃないけどさ。 + +#define FASS (FOP+ASS) +#define FCMPGE (FOP+CMPGE) +#define FCMPEQ (FOP+CMPEQ) +#define FCMPNEQ (FOP+CMPNEQ) +#define FASSOP (FOP+ASSOP) +#define FCMP (FOP+CMP) +#define FMINUS (FOP+MINUS) + +とか、かっこわるいし。type 自体に、処理メソッドへのポインタを +儲けるんだろうなぁ。 ちょっと修正が多いけど。少し考えてみないと。
--- a/mc-code-arm.c Wed Nov 14 19:36:55 2007 +0900 +++ b/mc-code-arm.c Fri Nov 16 21:46:20 2007 +0900 @@ -364,8 +364,6 @@ #define ARG_LVAR_OFFSET 0x10000000 -#define round16(i) ((i+0xf)&~0xf) -#define round4(i) ((i+3)&~3) /* @@ -443,16 +441,16 @@ // printf(" @ args = %d, pretend = %d, frame = %d\n", -// max_func_args,0,round16(-disp)); +// max_func_args,0,align(-disp,16)); // printf(" @ frame_needed = 1, current_function_anonymous_args = 0\n"); #if 0 printf("## vars= %d, regs= %d/%d, args= %d, extra= %d\n", - round16(-disp), + align(-disp,16), max_reg_var+2, max_freg_var, - round16(max_func_args*SIZE_OF_INT), + align(max_func_args*SIZE_OF_INT,16), 0 ); printf("## callee arg top=\t%d\n",CALLEE_ARG(0)); @@ -464,7 +462,7 @@ printf("## min local var=\t%d\n",FUNC_LVAR(0)+lvar_offsetv); printf("## max local var=\t%d\n",FUNC_LVAR(disp)+lvar_offsetv); printf("## min caller arg var=\t%d\n", - CALLER_ARG(round16(max_func_args*SIZE_OF_INT))); + CALLER_ARG(align(max_func_args*SIZE_OF_INT,16))); printf("## max caller arg var=\t%d\n",CALLER_ARG(0)); printf("##\n"); #endif @@ -570,6 +568,7 @@ size_of_double = SIZE_OF_DOUBLE; size_of_longlong = SIZE_OF_LONGLONG; endian = ENDIAN; + struct_align = 16; init_src = init_src0; reg=RET_LREGISTER; @@ -2241,7 +2240,7 @@ if (reg_var<MAX_INPUT_REGISTER_VAR) { n->dsp = offset; n->sc = LVAR; - len = size(n->ty); len = round4(len); + len = size(n->ty); len = align(len,4); for(;len>0 && reg_var<MAX_INPUT_REGISTER_VAR;len-=SIZE_OF_INT) { reg_var++; g_expr_u(assign_expr0(list3n(LVAR,offset,0), @@ -2442,7 +2441,7 @@ reg_arg ++ ; freg_arg++; nargs += size(t)/SIZE_OF_INT; } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { - nargs += round4(size(t))/SIZE_OF_INT; + nargs += align(size(t),4)/SIZE_OF_INT; } else { error(TYERR); nargs ++ ; @@ -2692,13 +2691,7 @@ } clear_ptr_cache(); code_call(e2,fn,jmp); - for(;reg_arg_list;reg_arg_list=cadr(reg_arg_list)) { - arg = car(reg_arg_list); - if (car(arg)==REGISTER||car(arg)==DREGISTER||car(arg)==FREGISTER - ||car(arg)==LREGISTER) - free_register(cadr(arg)); - else if (car(arg)==LVAR&&cadr(arg)<0) free_lvar(cadr(arg)); - } + free_register_var(reg_arg_list); for(i=1;i<MAX_INPUT_REGISTER_VAR;i++) { free_register(i); } @@ -3597,7 +3590,7 @@ } void -align(int t) +code_align(int t) { int d; switch(t) { @@ -3666,7 +3659,7 @@ cstring_mode(); } else data_mode(n->nm); - align(a); + code_align(a); if (n && n->sc!=STATIC) printf("\t.globl\t%s\n",n->nm); printf("%s:\n",n->nm); @@ -3697,7 +3690,7 @@ emit_int(int d) { data_mode(0); - align(0); + code_align(0); printf("\t.word %d\n",d); }
--- a/mc-code-ia32.c Wed Nov 14 19:36:55 2007 +0900 +++ b/mc-code-ia32.c Fri Nov 16 21:46:20 2007 +0900 @@ -404,8 +404,8 @@ static int code_l2(long long d); #endif -#define round16(i) ((i+0xf)&~0xf) -#define round4(i) ((i+0x3)&~0x3) +#define round16(i) align(i,16) +#define round4(i) align(i,4) #define func_disp_offset (16) @@ -672,6 +672,7 @@ size_of_double = SIZE_OF_DOUBLE; size_of_longlong = SIZE_OF_LONGLONG; endian = ENDIAN; + struct_align = 16; // MAX_REGISTER=6; @@ -1958,13 +1959,7 @@ } clear_ptr_cache(); code_call(e2,fn,jmp); - for(;reg_arg_list;reg_arg_list=cadr(reg_arg_list)) { - arg = car(reg_arg_list); - if (car(arg)==REGISTER||car(arg)==DREGISTER||car(arg)==FREGISTER - ||car(arg)==LREGISTER) - free_register(cadr(arg)); - else if (car(arg)==LVAR&&cadr(arg)<0) free_lvar(cadr(arg)); - } + free_register_var(reg_arg_list); if (ret_type==DOUBLE||ret_type==FLOAT) { } else if (ret_type==LONGLONG||ret_type==ULONGLONG) { use_longlong0(USE_CREG); @@ -2713,7 +2708,7 @@ } void -align(int t) +code_align(int t) { int d; switch(t) { @@ -2736,7 +2731,7 @@ cstring_mode(); } else data_mode(n->nm); - align(a); + code_align(a); #ifdef __APPLE__ if (n && n->sc!=STATIC) printf(".globl\t_%s\n",n->nm);
--- a/mc-code-mips.c Wed Nov 14 19:36:55 2007 +0900 +++ b/mc-code-mips.c Fri Nov 16 21:46:20 2007 +0900 @@ -346,8 +346,8 @@ #define ARG_LVAR_OFFSET 0x10000000 -#define round16(i) ((i+0xf)&~0xf) -#define round4(i) ((i+3)&~3) +#define round16(i) align(i,16) +#define round4(i) align(i,4) /* @@ -526,6 +526,7 @@ size_of_double = SIZE_OF_DOUBLE; size_of_longlong = SIZE_OF_LONGLONG; endian = ENDIAN; + struct_align = 16; init_src = init_src0; reg=RET_LREGISTER; @@ -2280,13 +2281,7 @@ } clear_ptr_cache(); code_call(e2,fn,jmp); - for(;reg_arg_list;reg_arg_list=cadr(reg_arg_list)) { - arg = car(reg_arg_list); - if (car(arg)==REGISTER||car(arg)==DREGISTER||car(arg)==FREGISTER - ||car(arg)==LREGISTER) - free_register(cadr(arg)); - else if (car(arg)==LVAR&&cadr(arg)<0) free_lvar(cadr(arg)); - } + free_register_var(reg_arg_list); if (ret_type==DOUBLE) { set_dreg(RET_DREGISTER,0); use_reg(RET_DREGISTER); @@ -3271,7 +3266,7 @@ } void -align(int t) +code_align(int t) { int d; switch(t) { @@ -3339,7 +3334,7 @@ cstring_mode(); } else data_mode(n->nm); - align(a); + code_align(a); if (n && n->sc!=STATIC) printf("\t.globl\t%s\n",n->nm); printf("%s:\n",n->nm); @@ -5521,7 +5516,7 @@ if (car(e1)==GVAR) { e1=list3n(FNAME,0,ncaddr(e1)); } else if (car(e1)==FNAME) { - e1=list3(FNAME,0,ncaddr(e1)); + e1=list3n(FNAME,0,ncaddr(e1)); } else if (car(e1)==STRING) { val = emit_string_label(); ascii(ncaddr(e1)->nm);
--- a/mc-code-powerpc.c Wed Nov 14 19:36:55 2007 +0900 +++ b/mc-code-powerpc.c Fri Nov 16 21:46:20 2007 +0900 @@ -305,7 +305,8 @@ }; #endif -#define round4(i) ((i+(SIZE_OF_INT-1))&~(SIZE_OF_INT-1)) +#define round4(i) align(i,4) +#define round16(i) align(i,16) #define register_name(i) reg_name[i] #define fregister_name(i) reg_name[i] @@ -509,7 +510,6 @@ #endif #define CALLER_ARG(l) ((l)+arg_offset1) -#define round16(a) ((a+0xf)&~0xf) void code_offset_set() @@ -742,6 +742,7 @@ size_of_double = SIZE_OF_DOUBLE; size_of_longlong = SIZE_OF_LONGLONG; endian = ENDIAN; + struct_align = 16; regv_l(RET_LREGISTER) = RET_LREGISTER_L; regv_h(RET_LREGISTER) = RET_LREGISTER_H; @@ -2684,15 +2685,7 @@ printf("\tmtctr %s\n",jrn); printf("\tbctrl\n"); } - for(;reg_arg_list;reg_arg_list=cadr(reg_arg_list)) { - arg = car(reg_arg_list); - if (car(arg)==REGISTER||car(arg)==DREGISTER||car(arg)==FREGISTER - ||car(arg)==LREGISTER) { -// if (car(arg)==LREGISTER) -// printf("## lreg freeing %d %s %s\n",cadr(arg), lregister_name_high(cadr(arg)), lregister_name_low(cadr(arg))); - free_register(cadr(arg)); - } else if (car(arg)==LVAR&&cadr(arg)<0) free_lvar(cadr(arg)); - } + free_register_var(reg_arg_list); if (ret_type==DOUBLE||ret_type==FLOAT) { set_freg(RET_FREGISTER,0); } else if (ret_type==ULONGLONG||ret_type==LONGLONG) { @@ -3746,7 +3739,7 @@ } void -align(int t) +code_align(int t) { int d; switch(t) {
--- a/mc-code-spu.c Wed Nov 14 19:36:55 2007 +0900 +++ b/mc-code-spu.c Fri Nov 16 21:46:20 2007 +0900 @@ -250,8 +250,8 @@ #define ARG_LVAR_OFFSET 0x10000000 -#define round16(i) ((i+0xf)&~0xf) -#define round4(i) ((i+3)&~3) +#define round16(i) align(i,16) +#define round4(i) align(i,4) /* @@ -452,6 +452,7 @@ size_of_double = SIZE_OF_DOUBLE; size_of_longlong = SIZE_OF_LONGLONG; endian = ENDIAN; + struct_align = 16; init_src = init_src0; } @@ -2491,13 +2492,7 @@ } clear_ptr_cache(); code_call(e2,fn,jmp); - for(;reg_arg_list;reg_arg_list=cadr(reg_arg_list)) { - arg = car(reg_arg_list); - if (car(arg)==REGISTER||car(arg)==DREGISTER||car(arg)==FREGISTER - ||car(arg)==LREGISTER) - free_register(cadr(arg)); - else if (car(arg)==LVAR&&cadr(arg)<0) free_lvar(cadr(arg)); - } + free_register_var(reg_arg_list); for(i=1;i<MAX_INPUT_REGISTER_VAR;i++) { free_register(i); } @@ -3378,7 +3373,7 @@ } void -align(int t) +code_align(int t) { int d; switch(t) {
--- a/mc-code.h Wed Nov 14 19:36:55 2007 +0900 +++ b/mc-code.h Fri Nov 16 21:46:20 2007 +0900 @@ -168,7 +168,7 @@ extern int code_const_op_p(int op,int v); extern void oprtc(int op,int reg,int v); -extern void align(int t); +extern void code_align(int t); extern void emit_global(NMTBL *n,int t,int e); extern void emit_space(int sp); extern void emit_char(int d);
--- a/mc-codegen.c Wed Nov 14 19:36:55 2007 +0900 +++ b/mc-codegen.c Fri Nov 16 21:46:20 2007 +0900 @@ -43,6 +43,7 @@ int size_of_longlong; int bit_of_byte; int endian; +int struct_align; #define STRUCT_ALIGN 1 @@ -3224,7 +3225,7 @@ extern NMTBL * def(NMTBL *n,int ctmode) { - int sz,nsc,ndsp,align; + int sz,nsc,ndsp,align0; int sbit_f = bit_field_disp; int type0 = type_value(type); int attr = attribute; @@ -3275,17 +3276,17 @@ strtype=1; sz = size(type0); if ((sz%size_of_int==0)||strtype) { - disp = ((disp+(size_of_int-1))&~(size_of_int-1)); + disp = align(disp,struct_align); } #endif - if ((align=attr_value_in_list(attr,ALIGNED))) { + if ((align0=attr_value_in_list(attr,ALIGNED))) { int hoge = disp; - if (car(align)!=CONST) error(-1); + if (car(align0)!=CONST) error(-1); // align have to be 2^n - align = caddr(align); - disp = ((disp+(align-1))&~(align-1)); + align0 = caddr(align0); + disp = align(disp,align0); if (lsrc && hoge!=disp) -printf("# field %s %d->%d (align %d)\n",n->nm,hoge,disp,align); +printf("# field %s %d->%d (align %d)\n",n->nm,hoge,disp,align0); } } @@ -3445,6 +3446,8 @@ return n; } +// standard 32bit alignment + extern int code_arg_alignment0(int args,NMTBL *n, int type0,int sz) { @@ -3465,7 +3468,7 @@ /* should be GCD of member alignment */ /* __attribute(alignment(16)) is ignored in argments */ n->dsp = args; - args += ((sz+(size_of_int-1))&~(size_of_int-1)); + args += align(sz,size_of_int); } else { /* if (n->dsp==0) (argument list in ADECL is useless, type list can be found in type ) */ @@ -3475,6 +3478,8 @@ return args; } +// standard 32bit alignment for local variable + extern int code_lvar_alignment0(int disp0,NMTBL *n,int type0,int sz) { int align; @@ -3493,7 +3498,7 @@ // for mc-parse.c extern int -arg_alignment0(int args,NMTBL *n, int type0,int sz) +arg_alignment(int args,NMTBL *n, int type0,int sz) { return code_arg_alignment(args,n, type0,sz); } @@ -3770,7 +3775,7 @@ nptr0->sc = LVAR; nptr0->attr = 0; nptr0->ty = t; - nptr0->dsp = new_lvar_align(sz,16); + nptr0->dsp = new_lvar_align(sz,16); // ?! e1 = list3(RSTRUCT,list3n( nptr0->sc,nptr0->dsp,nptr0),sz); v = list3n(nptr0->sc,nptr0->dsp,nptr0); @@ -3806,7 +3811,7 @@ strtype=1; sz = size(t); if (sz%size_of_int==0||strtype) { - offset = ((offset+(size_of_int-1))&~(size_of_int-1)); + offset = align(offset,struct_align); } } #endif @@ -5179,7 +5184,7 @@ } extern int -new_lvar(int size) { +new_lvar(int size) { // system dependent? return new_lvar_align(size,0); } @@ -5188,6 +5193,20 @@ */ extern void +free_register_var(int reg_arg_list) +{ + int arg; + for(;reg_arg_list;reg_arg_list=cadr(reg_arg_list)) { + arg = car(reg_arg_list); + if (car(arg)==REGISTER||car(arg)==DREGISTER||car(arg)==FREGISTER + ||car(arg)==LREGISTER) { + free_register(cadr(arg)); + } else if (car(arg)==LVAR&&cadr(arg)<0) free_lvar(cadr(arg)); + } +} + + +extern void free_lvar(int disp) { int lvar,plvar;
--- a/mc-codegen.h Wed Nov 14 19:36:55 2007 +0900 +++ b/mc-codegen.h Fri Nov 16 21:46:20 2007 +0900 @@ -34,6 +34,8 @@ extern int size_of_longlong; extern int bit_of_byte; extern int endian; +extern int struct_align; + #define USE_CREG (-1) #define ASM_INPUT 1 @@ -132,6 +134,7 @@ extern int is_inline(NMTBL *fnptr); extern int scalar(int t); extern int make_mask(int from,int to); +extern void free_register_var(int reg_arg_list); extern void init_ptr_cache(); extern void clear_ptr_cache_reg(int r);
--- a/mc-parse.c Wed Nov 14 19:36:55 2007 +0900 +++ b/mc-parse.c Fri Nov 16 21:46:20 2007 +0900 @@ -2239,7 +2239,7 @@ t = type_value(n1->ty); sz = size(t); - offset = code_arg_alignment(offset,n1,t,sz); + offset = arg_alignment(offset,n1,t,sz); nargs=list4n(car(arg),nargs,caddr(arg),n1); }
--- a/mc.h Wed Nov 14 19:36:55 2007 +0900 +++ b/mc.h Fri Nov 16 21:46:20 2007 +0900 @@ -585,10 +585,13 @@ extern void free_nptr(NMTBL *n); extern NMTBL *get_nptr(); +#define align(x,alig) ((x+(alig-1))&~(alig-1)) + // mc-tree.c extern void print_expr(int e, FILE *vout); + #if 1 extern int heapsize; #define CHECK_HEAP(b) ({int _k=(int)(b);if(_k>heapsize||_k<=0)error(-1);_k;})