Mercurial > hg > CbC > old > device
changeset 422:83a7f9426a55
bitfield continue...
author | kono |
---|---|
date | Fri, 29 Oct 2004 05:17:49 +0900 |
parents | ab58eea5e032 |
children | 8b9136a06f56 |
files | .gdbinit Changes mc-code-arm.c |
diffstat | 3 files changed, 69 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Fri Oct 29 04:18:39 2004 +0900 +++ b/.gdbinit Fri Oct 29 05:17:49 2004 +0900 @@ -1,5 +1,5 @@ tb main -run -s test/bitfield.c +run -s test/bitfield1.c # run -s mc-parse.c # run -s mc-codegen.c # run -s nkf203/nkf.c
--- a/Changes Fri Oct 29 04:18:39 2004 +0900 +++ b/Changes Fri Oct 29 05:17:49 2004 +0900 @@ -6342,6 +6342,17 @@ には、格納type を struct { int [3]; } として、一時領域に格納 する。実際には、アドレスが帰って来ることになる。で、code_bit_ replace_const などでは、アドレスに対して処理すれば良い。そう -すれば、codegen 側の変更はなくなる。 +すれば、codegen 側の変更は(ほとんど)なくなる。 でも、そうすると格納型と値型を区別しないとまずいね。 + +Fri Oct 29 04:19:58 JST 2004 + +code-* 側にはtypeの内部構造とかを渡すのは良くない。 + +あとは、格納型>値型の時のbitの値の修正だな。 + +この手のbit-field って、本来なら、inline で *C* で記述されるべき +ものだよね。 + +
--- a/mc-code-arm.c Fri Oct 29 04:18:39 2004 +0900 +++ b/mc-code-arm.c Fri Oct 29 05:17:49 2004 +0900 @@ -5858,30 +5858,30 @@ int sign=0,bitsz; int align,l=0; switch(cadr(type)) { /* value type */ - case INT: sign=1; align=4;break; - case UNSIGNED: align=4;break; - case CHAR: sign=1; align=1;break; - case UCHAR: align=1;break; - case SHORT: sign=1; align=2;break; - case USHORT: sign=1; align=2;break; - case LONGLONG: sign=1; align=4;l=1; break; - case ULONGLONG: align=4;l=1; break; + case INT: sign=1; break; + case UNSIGNED: break; + case CHAR: sign=1; break; + case UCHAR: break; + case SHORT: sign=1; break; + case USHORT: sign=1; break; + case LONGLONG: sign=1; l=1; break; + case ULONGLONG: l=1; break; default: error(-1); } if (car(caddr(type))>0) { /* store type */ if (car(car(caddr(type)))==STRUCT) { - bitsz=64+32; l=2; + bitsz=64+32; align=4; l=2; } else error(-1); } else { switch(car(caddr(type))) { - case INT: bitsz=32; break; - case UNSIGNED: bitsz=32; break; - case CHAR: bitsz= 8; break; - case UCHAR: bitsz= 8; break; - case SHORT: bitsz=16; break; - case USHORT: bitsz=16; break; - case LONGLONG: bitsz=64; l=1; break; - case ULONGLONG: bitsz=64; l=1; break; + case INT: bitsz=32; align=4; break; + case UNSIGNED: bitsz=32; align=4; break; + case CHAR: bitsz= 8; align=1; break; + case UCHAR: bitsz= 8; align=1; break; + case SHORT: bitsz=16; align=2; break; + case USHORT: bitsz=16; align=2; break; + case LONGLONG: bitsz=64; align=4; l=1; break; + case ULONGLONG: bitsz=64; align=4; l=1; break; default: error(-1); } } @@ -5918,14 +5918,14 @@ /* code for non-aligned non-hole bit-field */ if (bitpos!=bitsz && bitpos+bitsize > bitsz) { switch(car(caddr(type))) { - case INT: stype=ULONGLONG; break; - case UNSIGNED: stype=ULONGLONG; break; - case CHAR: stype=USHORT; break; - case UCHAR: stype=USHORT; break; - case SHORT: stype=UNSIGNED; break; - case USHORT: stype=UNSIGNED; break; - case LONGLONG: stype=list4(STRUCT,12,0,0); break; - case ULONGLONG: stype=list4(STRUCT,12,0,0); break; + case INT: stype=ULONGLONG; align=4; break; + case UNSIGNED: stype=ULONGLONG; align=4; break; + case CHAR: stype=USHORT; align=2; break; + case UCHAR: stype=USHORT; align=2; break; + case SHORT: stype=UNSIGNED; align=4; break; + case USHORT: stype=UNSIGNED; align=4; break; + case LONGLONG: stype=list4(STRUCT,12,0,0); align=4; break; + case ULONGLONG: stype=list4(STRUCT,12,0,0); align=4; break; default: error(-1); } bitsz = size(stype)*8; @@ -6009,20 +6009,22 @@ (64+32-bitsize -bitpos - (bitsz-bitsize)) = 64+32 -bitsz -bitbpos */ - /* shift left */ - if ((i=bitsz-SIZE_OF_LONGLONG*8-bitpos)) - oprtc(LSHIFT,reg,list2(CONST,i)); - if ((i=SIZE_OF_LONGLONG*8-bitsize-bitpos)) + if ((i=bitpos)) loprtc(LLSHIFT,lreg,list2(CONST,i)); - inc_inst(1); - printf("\tadd\t%s,%s,%s\n", - register_name(regv_l(lreg)), - register_name(regv_l(lreg)), - register_name(reg)); - set_lreg(lreg,1); + if (i<0||64<=i) error(-1); /* shift right */ if ((i=SIZE_OF_LONGLONG*8-bitsize)) loprtc(sign?LRSHIFT:LURSHIFT,lreg,list2(CONST,i)); + if (i<0||64<=i) error(-1); + if ((i=bitsz-bitsize-bitpos)) + oprtc(RSHIFT,reg,list2(CONST,i)); + if (i<0||32<=i) error(-1); + inc_inst(1); + printf("\tadd\t%s,%s,%s\n", + register_name(regv_h(lreg)), + register_name(regv_h(lreg)), + register_name(reg)); + set_lreg(lreg,1); } else { use_int(reg); /* shift left */ @@ -6055,7 +6057,7 @@ extern void code_bit_replace(int value,int lvalue,int type,int bitpos) { - int sign,bitsz,l,align; + int sign,bitsz,l,align,i; int bitsize = caddr(caddr(type)); int mask = 0; int tmp = -1; @@ -6090,8 +6092,10 @@ use_int(lvalue); lrn = register_name(tmp = get_register()); - if (bitsz-bitpos-bitsize) - oprtc(RSHIFT,regv_l(value),list2(CONST,bitsz-bitpos-bitsize)); + i=bitsz-bitpos-bitsize; + if (i) + oprtc(RSHIFT,regv_l(value),list2(CONST,i)); + if (i<0||32<=i) error(-1); crn = lregister_name_low(value); code_ld(cload(0,0),regv_l(value),0,lvalue,cext_at(0,0)); trn = lregister_name_high(value); @@ -6099,14 +6103,21 @@ make_mask_and_or(mask,regv_h(value),trn,crn,lrn); inc_inst(1); printf("\t%s\t%s, [%s, #0]\n",cstore(0),crn,register_name(lvalue)); - - code_lrlvar(list2(LVAR,tmpvar),value); - loprtc(LLSHIFT,value,list2(CONST,64-(bitsize-bitpos))); +/* + 111111 222222222222 1111111 + 0000000000 111111 222222222222 1111111 0000000 + |----------||------||------------||-------||-------| + */ + code_lrlvar(tmpvar,value); + i=bitsz-bitsize-bitpos; + if (i) + loprtc(LLSHIFT,value,list2(CONST,i)); + if (i<0||64<=i) error(-1); inc_inst(1); - printf("\t%s\t%s, [%s, #4]\n",cstore(0),crn,register_name(lvalue)); + printf("\t%s\t%s, [%s, #4]\n",cstore(0),trn,register_name(lvalue)); code_ld(cload(0,0),regv_h(value),SIZE_OF_INT*2,lvalue,cext_at(0,0)); - mask = make_mask(0,31-(bitsz-bitpos-bitsize)); + mask = make_mask(0,31-i); make_mask_and_or(mask,regv_h(value),trn,crn,lrn); inc_inst(1); printf("\t%s\t%s, [%s, #8]\n",cstore(0),crn,register_name(lvalue)); @@ -6203,7 +6214,7 @@ lc = lcadr(value); lc >>= 32-bitpos; /* make and-mask upper */ - code_ld(cload(0,0),tmp,0,value,cext_at(0,0)); + code_ld(cload(0,0),tmp,0,lvalue,cext_at(0,0)); mask = make_mask(bitsz-bitpos-bitsize,bitsz-bitpos); make_mask_and_or_const(mask,trn,(int)(lc>>32)); inc_inst(1); @@ -6215,7 +6226,7 @@ /* make and-mask lower */ lc = lcadr(value); lc <<= bitpos; - code_ld(cload(0,0),tmp,SIZE_OF_INT*2,value,cext_at(0,0)); + code_ld(cload(0,0),tmp,SIZE_OF_INT*2,lvalue,cext_at(0,0)); mask = make_mask(0,31-bitpos); make_mask_and_or_const(mask,trn,(int)lc); inc_inst(1);