Mercurial > hg > CbC > old > device
changeset 734:d2d6b1ef2cb4
i64 continue...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 05 Nov 2010 22:36:39 +0900 |
parents | 116d4701d097 |
children | 31e5641bd7c7 |
files | Changes mc-code-i64.c mc-codegen.c test/code-gen.c |
diffstat | 4 files changed, 93 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Thu Nov 04 23:18:42 2010 +0900 +++ b/Changes Fri Nov 05 22:36:39 2010 +0900 @@ -9852,4 +9852,5 @@ LP64 だと、scalar の扱いをなんとかしないと。 - +INT/UNSIGNED の区別がない... +
--- a/mc-code-i64.c Thu Nov 04 23:18:42 2010 +0900 +++ b/mc-code-i64.c Fri Nov 05 22:36:39 2010 +0900 @@ -1217,6 +1217,10 @@ void code_rgvar(int e1,int creg) { use_int(creg); + if (car(e1)==URGVAR) { + code_crgvar(e1,creg,0,SIZE_OF_INT); + return; + } #ifdef __APPLE__ NMTBL nptr = ncaddr(e1); if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) { @@ -1242,8 +1246,9 @@ static char * cload(int sign,int sz) { - return sz==1?(sign?"movsbl":"movzbl"): - sz==SIZE_OF_SHORT?(sign?"movswl":"movzwl"):"movl"; + return sz==1?(sign?"movsbq":"movzbq"): + sz==SIZE_OF_SHORT?(sign?"movswq":"movzwq"): + sz==SIZE_OF_INT?(sign?"movslq":"movzlq"):"movq"; } void @@ -1252,7 +1257,7 @@ #ifdef __APPLE__ NMTBL nptr = ncaddr(e1); if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) { - printf("\t%s _%s+%d(%%rip),%s\n", cload(sign,sz),ntpr->nm,cadr(e1),register_name(creg,SIZE_OF_INT)); + printf("\t%s _%s+%d(%%rip),%s\n", cload(sign,sz),ntpr->nm,cadr(e1),register_name(creg,0)); return; } int r = get_ptr_cache(ncaddr(e1)); @@ -1261,15 +1266,15 @@ register_name(creg,SIZE_OF_INT)); } else { printf("\t%s (%s),%s\n", cload(sign,sz), - register_name(r,0), register_name(creg,SIZE_OF_INT)); + register_name(r,0), register_name(creg,0)); } #else if (cadr(e1)) { printf("\t%s %s+%d,%s\n",cload(sign,sz), - nptr->nm,cadr(e1),register_name(creg,SIZE_OF_INT)); + nptr->nm,cadr(e1),register_name(creg,0)); } else printf("\t%s %s,%s\n",cload(sign,sz), - nptr->nm,register_name(creg,SIZE_OF_INT)); + nptr->nm,register_name(creg,0)); #endif } @@ -1294,6 +1299,10 @@ void code_rlvar(int e2,int reg) { use_int(reg); + if (car(e1)==URLVAR) { + code_crlvar(e1,creg,0,SIZE_OF_INT); + return; + } printf("\tmovl "); lvar(e2); printf(",%s\n",register_name(reg,SIZE_OF_INT)); } @@ -3108,30 +3117,31 @@ #ifdef __APPLE__ int r = get_ptr_cache(ncaddr(e2)); if (cadr(e2)) - printf("\t%s %d(%s)\n",fstore(d),cadr(e2),register_name(r,0)); + printf("\t%s %s,%d(%s)\n",fstore(d),register_name(freg,0),cadr(e2),register_name(r,0)); else - printf("\t%s (%s)\n",fstore(d),register_name(r,0)); + printf("\t%s %s,(%s)\n",fstore(d),register_name(freg,0),register_name(r,0)); #else if (cadr(e2)) - printf("\t%s %s+%d\n",fstore(d),(ncaddr(e2))->nm,cadr(e2)); + printf("\t%s %s,%s+%d\n",fstore(d),register_name(freg,0),(ncaddr(e2))->nm,cadr(e2)); else - printf("\t%s %s\n",fstore(d),(ncaddr(e2))->nm); + printf("\t%s %s,%s\n",fstore(d),register_name(freg,0),(ncaddr(e2))->nm); #endif } void code_dassign_lvar(int e2,int freg,int d) { - printf("\t%s ",fstore(d)); lvar(e2); printf("\n"); + printf("\t%s %s,",fstore(d),register_name(freg,0)); lvar(e2); printf("\n"); } void code_dassign_dregister(int e,int d,int freg) { - error(-1); + int reg = cadr(e); + printf("\tmovapd %s,%s",register_name(freg,0),regsiter_name(reg,0)); } void code_dassign(int e2,int freg,int d) { - printf("\t%s (%s)\n",fstore(d),register_name(e2,0)); + printf("\t%s %s,(%s)\n",fstore(d),register_name(freg,0),register_name(e2,0)); } static double d0 = 1.0; @@ -3154,13 +3164,14 @@ { int lb; double value = dcadr(e2); - +#if 0 if (value==0.0) { printf("\tfldz\n"); return; } if (value==1.0) { printf("\tfld1\n"); return; } +#endif #ifdef __APPLE__ printf(" \t.literal8\n\t.align 3\n"); #else @@ -3177,9 +3188,9 @@ text_mode(0); } #ifdef __APPLE__ - printf("\tfldl _%d-_%d(%%ebx)\n",lb,goffset_label); + printf("\tmovsd _%d(%%rip),%s\n",lb,register_name(freg,0)); #else - printf("\tfldl _%d\n",lb); + printf("\tmovsd _%d,%s\n",lb,register_name(freg,0)); #endif } @@ -3202,29 +3213,29 @@ void code_dneg(int freg,int d) { - printf("\tfchs\n"); + int reg = get_dregister(); + if (d) { + printf("\txorpd %s,%s\n",register_name(freg,0),register_name(reg,0)); + printf("\tmovapd %s,%s\n",register_name(reg,0),register_name(freg,0)); + } else { + printf("\txorps %s,%s\n",register_name(freg,0),register_name(reg,0)); + printf("\tcvtss2sd %s,%s\n",register_name(reg,0),register_name(reg,0)); + } + free_register(reg); } void code_d2i(int reg) { + int f = reg; use_int(reg); - printf("\tlea -%d(%%esp),%%esp\n",SIZE_OF_INT*2); - printf("\tfnstcw (%%esp)\n"); - printf("\tmovl (%%esp), %s\n",register_name(creg,0)); - printf("\tmovb $12, 1(%%esp)\n"); - printf("\tfldcw (%%esp)\n"); - printf("\tfistpl %d(%%esp)\n",SIZE_OF_INT); - printf("\tmovl %s, (%%esp)\n",register_name(creg,0)); - printf("\tfldcw (%%esp)\n"); - printf("\tpopl %s\n",register_name(creg,0)); - printf("\tpopl %s\n",register_name(creg,0)); + printf("\tcvttsd2si %s,%s\n",register_name(f,0),register_name(creg,0)); } void code_i2d(int reg) { - printf("\tpushl %s\n",register_name(creg,0)); - printf("\tfildl (%%esp)\n"); - printf("\tlea %d(%%esp),%%esp\n",SIZE_OF_INT); + int c = reg; + use_double(reg); + printf("\tcvtsi2sd %s,%s\n",register_name(c,0),register_name(creg,0)); } void code_d2u(int reg)
--- a/mc-codegen.c Thu Nov 04 23:18:42 2010 +0900 +++ b/mc-codegen.c Fri Nov 05 22:36:39 2010 +0900 @@ -174,9 +174,12 @@ case GVAR: code_gvar(e1,USE_CREG); return ADDRESS; - case RGVAR: + case RGVAR: code_rgvar(e1,USE_CREG); return INT; + case URGVAR: + code_rgvar(e1,USE_CREG); + return UNSIGNED; case CRGVAR: code_crgvar(e1,USE_CREG,1,1); return CHAR; @@ -189,7 +192,7 @@ case SURGVAR: code_crgvar(e1,USE_CREG,0,size_of_short); return UCHAR; - case LVAR: + case LVAR: code_lvar(e2,USE_CREG); return ADDRESS; case REGISTER: @@ -211,6 +214,9 @@ case RLVAR: code_rlvar(e2,USE_CREG); return INT; + case URLVAR: + code_rlvar(e2,USE_CREG); + return UNSIGNED; case CRLVAR: code_crlvar(e2,USE_CREG,1,1); return CHAR; @@ -797,10 +803,12 @@ code_cmp_crlvar(e2,USE_CREG,size_of_short,l1,cond); return l1; case RGVAR: + case URGVAR: conv->bool_(e1); code_cmp_rgvar(e1,USE_CREG,l1,cond); return l1; case RLVAR: + case URLVAR: conv->bool_(e1); code_cmp_rlvar(e2,USE_CREG,l1,cond); return l1; @@ -1276,6 +1284,7 @@ case GVAR: case RGVAR: case RLVAR: case CRLVAR: case CRGVAR: case DRLVAR: case FRLVAR: case LRLVAR: case CURLVAR: case SURLVAR: case CURGVAR: case SURGVAR: + case URGVAR: case URLVAR: return 1; } return 0; @@ -1291,12 +1300,14 @@ switch(ce2) { case RLVAR: case CRLVAR: case FRLVAR: case DRLVAR: case SRLVAR: case SURLVAR: case CURLVAR: case LVAR: + case URLVAR: return 1; } } else if (ce2==LVAR) { switch(ce1) { case RLVAR: case CRLVAR: case FRLVAR: case DRLVAR: case SRLVAR: case SURLVAR: case CURLVAR: case LRLVAR: case LVAR: + case URLVAR: return 1; } } else if (ce1==GVAR) { @@ -1354,6 +1365,7 @@ case RGVAR: case SRGVAR : case SURGVAR: + case URGVAR: return list3n(GVAR,cadr(e1),ncaddr(e1)); case LVAR : case CRLVAR : @@ -1365,6 +1377,7 @@ case RLVAR: case SRLVAR : case SURLVAR : + case URLVAR: return list3n(LVAR,cadr(e1),ncaddr(e1)); case FREGISTER : case REGISTER: @@ -1396,6 +1409,7 @@ return size_of_short; // case GVAR : case RGVAR: + case URGVAR: *global=1; // case LVAR : case RLVAR: @@ -3072,8 +3086,8 @@ case ARROW: case PERIOD: return glist4(car(e),copy_expr(cadr(e)),caddr(e),cadddr(e)); - case LVAR: case RLVAR: - case GVAR: case RGVAR: + case LVAR: case RLVAR:case URLVAR: + case GVAR: case RGVAR:case URGVAR: return (e>gfree)?glist3(car(e),cadr(e),caddr(e)):e; case INDIRECT: case RINDIRECT: return glist2(car(e),copy_expr(cadr(e))); @@ -4209,8 +4223,10 @@ if (e==0) error(-1); op = 0; switch(type0) { - case INT: break; - case UNSIGNED: break; + case INT: + break; + case UNSIGNED: + break; case VOID: break; case CHAR: op=COP; type=set_type_with_attr(INT,type); break; case UCHAR: op=COP+US; type=set_type_with_attr(UNSIGNED,type); break;
--- a/test/code-gen.c Thu Nov 04 23:18:42 2010 +0900 +++ b/test/code-gen.c Fri Nov 05 22:36:39 2010 +0900 @@ -59,10 +59,15 @@ int i1,i2; short s1,s2; unsigned short us1,us2; + long l1,l2; + unsigned long ul1,ul2; + l1 = 1; l2 = -2; + ul1 = 1L<<(sizeof(long)*8-1); ul2 = 1L<<(sizeof(long)*8-1); i1 = 1; i2 = -2; s1 = -1; s2 = -3; us1 = 65535; us2 = 65535; printf("#0044:code_lvar %d %d %d %d %u %u\n",i1,i2,s1,s2,us1,us2); + printf("#0044:code_lvar %ld %ld %lu %lu\n",l1,l2,ul1,ul2); c1 = -1; c2 = -3; uc1 = 200; uc2 = 202; printf("#0046:code_lvar %d %d %u %u\n",c1,c2,uc1,uc2); } @@ -843,6 +848,8 @@ unsigned char ui1,ui2; char *pi1,*pi2; unsigned char *pui1,*pui2; + long l1,l2; + unsigned long ul1,ul2; i1 = -55; i2= 55; ui1 = 200; ui2= 128; @@ -851,6 +858,13 @@ pui1 = &ui1; pui2 = &ui2; printf("#0819:code_cindirect %d %d %u %u\n",*pi1,*pi2,*pui1,*pui2); + + l1 = *pi1; + l2 = *pi2; + ul1 = *pui1; + ul2 = *pui2; + printf("#0819:code_cindirect %ld %ld %lu %lu\n",l1,l2,ul1,ul2); + } // code_srindirect(int e1, int offset, int us); @@ -861,6 +875,8 @@ unsigned short ui1,ui2; short *pi1,*pi2; unsigned short *pui1,*pui2; + long l1,l2; + unsigned long ul1,ul2; i1 = -55; i2= 55; ui1 = 200; ui2= 128; @@ -869,6 +885,11 @@ pui1 = &ui1; pui2 = &ui2; printf("#0837:code_sindirect %d %d %u %u\n",*pi1,*pi2,*pui1,*pui2); + l1 = *pi1; + l2 = *pi2; + ul1 = *pui1; + ul2 = *pui2; + printf("#0819:code_cindirect %ld %ld %lu %lu\n",l1,l2,ul1,ul2); } #if FLOAT_CODE @@ -881,6 +902,8 @@ double di1,di2; float *pi1,*pi2; double *pui1,*pui2; + long l1,l2; + long ul1,ul2; #if LONG_DOUBLE_CODE long double *pdi1,*pdi2; #endif @@ -898,6 +921,11 @@ pdi2 = &di2; printf("#0856:code_dindirect %Lg %Lg\n",*pdi1,*pdi2); #endif + l1 = *pi1; + l2 = *pi2; + ul1 = *pui1; + ul2 = *pui2; + printf("#0819:code_cindirect %ld %ld %ld %ld\n",l1,l2,ul1,ul2); } #endif