Mercurial > hg > CbC > old > device
changeset 789:9b1558a9151b
unsigend fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 21 Nov 2010 17:28:49 +0900 |
parents | fcb642ef08c9 |
children | a26d87f93c65 |
files | .gdbinit mc-code-i64.c mc-codegen.c mc-codegen.h |
diffstat | 4 files changed, 46 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Sun Nov 21 15:36:23 2010 +0900 +++ b/.gdbinit Sun Nov 21 17:28:49 2010 +0900 @@ -25,7 +25,8 @@ # r -s test/macro.c # r -s test/basic.c # r -s test/float.c -r -s test/strinit.c +# r -s test/strinit.c +r -s test/bitfield.c # r -s test/arg.c # r -s test/obsf2.c # r -s test/putenemy.c
--- a/mc-code-i64.c Sun Nov 21 15:36:23 2010 +0900 +++ b/mc-code-i64.c Sun Nov 21 17:28:49 2010 +0900 @@ -2719,8 +2719,12 @@ printf("\tandw $%ld,%s\n",orn,register_name(reg,2)); else if (sz<=SIZE_OF_INT||(datareg&&(orn & ~0xffffffffL)==~0xffffffffL)) printf("\tandl $%ld,%s\n",orn,register_name(reg,4)); - else - printf("\tandq $%ld,%s\n",orn,crn); + else { + int t = get_register(); char *trn = register_name(t,0); + printf("\tmovq $%ld,%s\n",orn,trn); + printf("\tandq %s,%s\n",trn,crn); + free_register(t); + } break; case EOR: printf("\txor%s $%ld,%s\n",q,orn,crn); @@ -2732,8 +2736,12 @@ printf("\tor $%ld,%s\n",orn,register_name(reg,2)); else if (sz<=SIZE_OF_INT||(datareg&&(orn & ~0xffffffffL)==0)) printf("\torl $%ld,%s\n",orn,register_name(reg,4)); - else - printf("\torq $%ld,%s\n",orn,crn); + else { + int t = get_register(); char *trn = register_name(t,0); + printf("\tmovq $%ld,%s\n",orn,trn); + printf("\torq %s,%s\n",trn,crn); + free_register(t); + } break; case MUL: case UMUL: @@ -4998,13 +5006,13 @@ make_mask_and_or(int mask,int reg) { printf("## mask 0x%08x ~0x%08x\n",mask,~mask); - printf("\tpushl %s\n",register_name(reg,SIZE_OF_INT)); + printf("\tpushq %s\n",register_name(reg,0)); /* make and-mask */ oprtc(BOR,reg,list2(CONST,~mask)); /* do conjunction */ printf("\tandl %s,%s\n",register_name(reg,SIZE_OF_INT),register_name(ireg,SIZE_OF_INT)); /* make or-mask */ - printf("\tpopl %s\n",register_name(reg,SIZE_OF_INT)); + printf("\tpopq %s\n",register_name(reg,0)); oprtc(BAND,reg,list2(CONST,mask)); /* do disjunction */ printf("\torl %s,%s\n",register_name(reg,SIZE_OF_INT),register_name(ireg,SIZE_OF_INT)); @@ -5047,8 +5055,8 @@ loprtc(LLSHIFT,value,list2(CONST,bitpos)); /* make and-mask */ printf("\tpushq %s\n",register_name(adr,0)); - printf("\t%s %d(%s),%s\n",cload(sign,size),4,register_name(adr,regu(sign,size,0)), - register_name(adr,0)); + printf("\t%s %d(%s),%s\n",cload(sign,size),4,register_name(adr,0), + register_name(adr,regu(sign,size,0))); mask = make_mask(64-bitpos-bitsize,63-bitpos); make_mask_and_or_l(mask,value); printf("\tpopq %s\n",register_name(adr,0)); @@ -5058,16 +5066,16 @@ } else { use_int(adr); use_int(value); - printf("\tpushl %s\n",register_name(adr,SIZE_OF_INT)); - printf("\t%s %d(%s),%s\n",cload(sign,size),0,register_name(adr,SIZE_OF_INT), - register_name(adr,SIZE_OF_INT)); + printf("\tpushq %s\n",register_name(adr,0)); + printf("\t%s %d(%s),%s\n",cload(sign,size),0,register_name(adr,0), + register_name(adr,regu(sign,size,0))); /* shift left */ if (bitpos) oprtc(LSHIFT,value,list2(CONST,bitpos)); /* make and-mask */ mask = make_mask(32-bitpos-bitsize,31-bitpos); make_mask_and_or(mask,value); - printf("\tpopl %s\n",register_name(adr,SIZE_OF_INT)); + printf("\tpopq %s\n",register_name(adr,0)); code_assign(adr,size==4?0:size,value); } if (use) { @@ -5080,6 +5088,8 @@ make_mask_and_or_const(long mask,int reg,long c) { long a; + int t = 0; + char *trn; // printf("## mask 0x%08x ~0x%08x\n",mask,~mask); a = ~mask|c; if (a!=-1) { @@ -5089,8 +5099,11 @@ printf("\tandb $%ld,%s\n",a&0xff,register_name(reg,1)); else printf("\tandw $%ld,%s\n",a&0xffff,register_name(reg,2)); - } else - printf("\tandq $%ld,%s\n",a,register_name(reg,0)); + } else { + t = get_register(); trn = register_name(t,0); + printf("\tmovq $%ld,%s\n",a,trn); + printf("\tandq %s,%s\n",trn,register_name(reg,0)); + } } /* make or-mask */ c = mask&c; @@ -5101,9 +5114,16 @@ printf("\torb $%ld,%s\n",c&0xff,register_name(reg,1)); else printf("\torw $%ld,%s\n",c&0xffff,register_name(reg,2)); - } else - printf("\torq $%ld,%s\n",c,register_name(reg,0)); + } else { + if (!t) { + t = get_register(); trn = register_name(t,0); + } + if (a!=c) + printf("\tmovq $%ld,%s\n",c,trn); + printf("\torq %s,%s\n",trn,register_name(reg,0)); + } } + free_register(t); } extern void
--- a/mc-codegen.c Sun Nov 21 15:36:23 2010 +0900 +++ b/mc-codegen.c Sun Nov 21 17:28:49 2010 +0900 @@ -2296,8 +2296,7 @@ if (t>0&&car(t)==BIT_FIELD) e2=rvalue(e2); if (0); else if (car(e2)==CONST) { - if (cadr(e2)<0) - e2 = llist2(LCONST,0); + // if (cadr(e2)<0) e2 = llist2(LCONST,0); e2 = llist2(LCONST,(unsigned long long)cadr(e2)); } else if (car(e2)==LCONST) ; @@ -5346,7 +5345,7 @@ } else { if (post) { n1 = list3n(LVAR,new_lvar(size_of_int),0); - code_assign_lvar(cadr(n1),USE_CREG,0); + code_assign_lvar(cadr(n1),USE_CREG,size_of_int); } emit_push(); g_expr(e3); @@ -5530,14 +5529,14 @@ make bit mask MSB 1 2 3 4 .... 29 30 31 LSB */ -extern int +extern unsigned long long make_mask(int from,int to) { - int mask = 0; - int bit = 1; + unsigned long long mask = 0; + unsigned long long bit = 1; int i; - if (from<0||from>32) error(-1); - for (i=31;from<=i;i--,bit<<=1) { + if (from<0||from>63) error(-1); + for (i=63;from<=i;i--,bit<<=1) { if (i<=to) { mask |= bit; }
--- a/mc-codegen.h Sun Nov 21 15:36:23 2010 +0900 +++ b/mc-codegen.h Sun Nov 21 17:28:49 2010 +0900 @@ -135,7 +135,7 @@ extern int is_function(NMTBL *fnptr); extern int is_inline(NMTBL *fnptr); extern int scalar(int t); -extern int make_mask(int from,int to); +extern unsigned long long make_mask(int from,int to); extern void free_register_var(int reg_arg_list); extern void init_ptr_cache();