Mercurial > hg > CbC > old > device
changeset 423:8b9136a06f56
bitfield continue...
author | kono |
---|---|
date | Fri, 29 Oct 2004 14:20:19 +0900 |
parents | 83a7f9426a55 |
children | 485bf7dde96a |
files | mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c test/bitfield.c |
diffstat | 5 files changed, 167 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-arm.c Fri Oct 29 05:17:49 2004 +0900 +++ b/mc-code-arm.c Fri Oct 29 14:20:19 2004 +0900 @@ -5913,39 +5913,46 @@ if (bitpos) { /* previous field is bit field and spaces may remain */ /* calc previsous offset */ + offset-=(bitpos+7)/8; #if 1 - int stype; /* code for non-aligned non-hole bit-field */ - if (bitpos!=bitsz && bitpos+bitsize > bitsz) { + while(bitpos>align*8) { + i = ((offset+(align))&~(align-1))-offset; + offset+=i; bitpos-=i*8; + } + if (bitpos+bitsize > bitsz) { + int stype; + bitpos = *bfd; offset=*poffset; + offset-=(bitpos+7)/8; switch(car(caddr(type))) { - 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; + case INT: case UNSIGNED: + stype=ULONGLONG; align=4; break; + case CHAR: case UCHAR: + stype=USHORT; align=2; break; + case SHORT: case USHORT: + stype=UNSIGNED; align=4; break; + case ULONGLONG: case LONGLONG: + stype=list4(STRUCT,12,0,0);align=4;break; default: error(-1); } + while(bitpos>align*8) { + i = ((offset+(align))&~(align-1))-offset; + offset+=i; bitpos-=i*8; + } bitsz = size(stype)*8; car(caddr(type)) = stype; } #endif - i= offset-(bitpos+7)/8; + i= offset; for(l = bitpos;l>0;l -= 8,i++) { if ((i & (align-1))==0 && l+bitsize <= bitsz) { /* alignment is correct and space remains */ *poffset=offset=i; i = l+bitsize; - if (i==bitsz) { - *bfd = 0; - } else { - *bfd = i; - } + *bfd = (i==bitsz)?0:i; *sz = (i+7)/8; - printf("# bitpos=%d bitsize=%d bitsz=%d offset=%d\n",l,bitsize,bitsz,*poffset); + printf("# %d: bitpos=%d bitsize=%d bitsz=%d offset=%d\n",lineno,bitpos,bitsize,bitsz,*poffset); return l; } } @@ -5957,10 +5964,10 @@ *poffset = (offset += (align-i)); } bitpos = 0; - *bfd = bitsize; + *bfd = (bitsize==bitsz)?0:bitsize; *sz = (bitsize+7)/8; - printf("# bitpos=%d bitsize=%d bitsz=%d offset=%d\n",bitpos,bitsize,bitsz,*poffset); + printf("# %d: bitpos=%d bitsize=%d bitsz=%d offset=%d\n",lineno,bitpos,bitsize,bitsz,*poffset); return bitpos; } @@ -6097,7 +6104,7 @@ 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)); + code_ld(cload(0,0),tmp,0,lvalue,cext_at(0,0)); trn = lregister_name_high(value); mask = make_mask(bitsz-bitpos-bitsize,31); make_mask_and_or(mask,regv_h(value),trn,crn,lrn); @@ -6116,7 +6123,7 @@ inc_inst(1); 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)); + code_ld(cload(0,0),tmp,SIZE_OF_INT*2,lvalue,cext_at(0,0)); mask = make_mask(0,31-i); make_mask_and_or(mask,regv_h(value),trn,crn,lrn); inc_inst(1);
--- a/mc-code-ia32.c Fri Oct 29 05:17:49 2004 +0900 +++ b/mc-code-ia32.c Fri Oct 29 14:20:19 2004 +0900 @@ -3431,7 +3431,7 @@ /* alignment is correct and space remains */ *poffset=offset=i; i = l+bitsize; - *bfd = i; + *bfd = (i==bitsz)?0:i; *sz = (i+7)/8; // printf("# bitpos=%d bitsize=%d bitsz=%d offset=%d\n",l,bitsize,bitsz,*poffset); return l;
--- a/mc-code-mips.c Fri Oct 29 05:17:49 2004 +0900 +++ b/mc-code-mips.c Fri Oct 29 14:20:19 2004 +0900 @@ -5503,7 +5503,7 @@ /* alignment is correct and space remains */ *poffset=offset=i; i = l+bitsize; - *bfd = i; + *bfd = (i==bitsz)?0:i; *sz = (i+7)/8; // printf("# bitpos=%d bitsize=%d bitsz=%d offset=%d\n",l,bitsize,bitsz,*poffset); return l;
--- a/mc-code-powerpc.c Fri Oct 29 05:17:49 2004 +0900 +++ b/mc-code-powerpc.c Fri Oct 29 14:20:19 2004 +0900 @@ -5265,7 +5265,7 @@ /* alignment is correct and space remains */ *poffset=offset=i; i = l+bitsize; - *bfd = i; + *bfd = (i==bitsz)?0:i; *sz = (i+7)/8; // printf("# bitpos=%d bitsize=%d bitsz=%d offset=%d\n",l,bitsize,bitsz,*poffset); return l;
--- a/test/bitfield.c Fri Oct 29 05:17:49 2004 +0900 +++ b/test/bitfield.c Fri Oct 29 14:20:19 2004 +0900 @@ -189,6 +189,7 @@ printf("%d %d %d\n",a.pte.pp,g.pte.pp,p->pte.pp); main2(); main5(); + main5c(); main3(); main4(); main6(); @@ -537,6 +538,138 @@ int p1 = 1; int zero = 0; +main5c() +{ + ii.b.a = -1; + printf("m5c-00:%d\n",ii.b.a); + + ll1.b.v = -1; + printf("m5c-01:%llx\n",ll1.b.v); + printf("m5c-02:%08x %08x %08x %08x %08x %08x %08x %08x\n", + ll1.a[0],ll1.a[1],ll1.a[2],ll1.a[3], + ll1.a[4],ll1.a[5],ll1.a[6],ll1.a[7] + ); + ll1.b.v = 0; + ll1.b.w = -1; + printf("m5c-02:%08x %08x %08x %08x %08x %08x %08x %08x\n", + ll1.a[0],ll1.a[1],ll1.a[2],ll1.a[3], + ll1.a[4],ll1.a[5],ll1.a[6],ll1.a[7] + ); + ll1.b.w = 0; + ll1.b.x = -1; + printf("m5c-02:%08x %08x %08x %08x %08x %08x %08x %08x\n", + ll1.a[0],ll1.a[1],ll1.a[2],ll1.a[3], + ll1.a[4],ll1.a[5],ll1.a[6],ll1.a[7] + ); + ll1.b.x = 0; + + ll0.b.v = -1; + printf("m5c-01:%llx\n",ll0.b.v); + printf("m5c-02:%08x %08x %08x %08x %08x %08x %08x %08x\n", + ll0.a[0],ll0.a[1],ll0.a[2],ll0.a[3], + ll0.a[4],ll0.a[5],ll0.a[6],ll0.a[7] + ); + ll0.b.v = 0; + ll0.b.w = -1; + printf("m5c-02:%08x %08x %08x %08x %08x %08x %08x %08x\n", + ll0.a[0],ll0.a[1],ll0.a[2],ll0.a[3], + ll0.a[4],ll0.a[5],ll0.a[6],ll0.a[7] + ); + ll0.b.w = 0; + ll0.b.x = -1; + printf("m5c-02:%08x %08x %08x %08x %08x %08x %08x %08x\n", + ll0.a[0],ll0.a[1],ll0.a[2],ll0.a[3], + ll0.a[4],ll0.a[5],ll0.a[6],ll0.a[7] + ); + ll0.b.x = 0; + + ll.b.v = -1; + printf("m5c-1:%llx\n",ll.b.v); + printf("m5c-2:%08x %08x %08x %08x %08x %08x %08x %08x\n", + ll.a[0],ll.a[1],ll.a[2],ll.a[3], + ll.a[4],ll.a[5],ll.a[6],ll.a[7] + ); + ll.b.v = 0; + ll.b.w = -1; + printf("m5c-2:%08x %08x %08x %08x %08x %08x %08x %08x\n", + ll.a[0],ll.a[1],ll.a[2],ll.a[3], + ll.a[4],ll.a[5],ll.a[6],ll.a[7] + ); + ll.b.w = 0; + ll.b.x = -1; + printf("m5c-2:%08x %08x %08x %08x %08x %08x %08x %08x\n", + ll.a[0],ll.a[1],ll.a[2],ll.a[3], + ll.a[4],ll.a[5],ll.a[6],ll.a[7] + ); + ll.b.x = 0; + + printf("m5c-char a:1; char b:4; char c:7; char d:4; char e:4; char f:4;\n"); + cc.b.a = -1; + printf("m5c-a:%08x\n",cc.a); + cc.b.b = -1; + printf("m5c-b:%08x\n",cc.a); + cc.b.c = -1; + printf("m5c-c:%08x\n",cc.a); + cc.b.d = -1; + printf("m5c-d:%08x\n",cc.a); + cc.b.e = -1; + printf("m5c-e:%08x\n",cc.a); + cc.b.f = -1; + printf("m5c-f:%08x\n",cc.a); + printf("m5c-3:%d %d\n",cc.b.c,cc.b.d); + cc.a = -1; + printf("m5c-f:%08x\n",cc.a); + cc.b.a = 0; + printf("m5c-a:%08x\n",cc.a); + cc.b.b = 0; + printf("m5c-b:%08x\n",cc.a); + cc.b.c = 0; + printf("m5c-c:%08x\n",cc.a); + cc.b.d = 0; + printf("m5c-d:%08x\n",cc.a); + cc.b.e = 0; + printf("m5c-e:%08x\n",cc.a); + cc.b.f = 0; + printf("m5c-f:%08x\n",cc.a); + printf("m5c-3:%d %d\n",cc.b.c,cc.b.d); + cc.a = 0; + printf("m5c-f:%08x\n",cc.a); + cc.b.a = 1; + printf("m5c-a:%08x\n",cc.a); + cc.b.b = 1; + printf("m5c-b:%08x\n",cc.a); + cc.b.c = 1; + printf("m5c-c:%08x\n",cc.a); + cc.b.d = 1; + printf("m5c-d:%08x\n",cc.a); + cc.b.e = 1; + printf("m5c-e:%08x\n",cc.a); + cc.b.f = 1; + printf("m5c-f:%08x\n",cc.a); + printf("m5c-3:%d %d\n",cc.b.c,cc.b.d); + cc.a = -1; + printf("m5c-f:%08x\n",cc.a); + cc.b.a = 1; + printf("m5c-a:%08x\n",cc.a); + cc.b.b = 1; + printf("m5c-b:%08x\n",cc.a); + cc.b.c = 1; + printf("m5c-c:%08x\n",cc.a); + cc.b.d = 1; + printf("m5c-d:%08x\n",cc.a); + cc.b.e = 1; + printf("m5c-e:%08x\n",cc.a); + cc.b.f = 1; + printf("m5c-f:%08x\n",cc.a); + printf("m5c-3:%d %d\n",cc.b.c,cc.b.d); + + ii.b.a = -1; + printf("m5c-6:%08x\n",ii.a); + ii.b.d = -1; + printf("m5c-6:%08x\n",ii.a); + printf("m5c-5:%d %d\n",ii.b.a,ii.b.d); +} + main5() { ii.b.a = -1; @@ -560,6 +693,7 @@ ll1.a[0],ll1.a[1],ll1.a[2],ll1.a[3], ll1.a[4],ll1.a[5],ll1.a[6],ll1.a[7] ); + ll1.b.x = zero; ll0.b.v = m1; printf("01:%llx\n",ll0.b.v); @@ -579,6 +713,7 @@ ll0.a[0],ll0.a[1],ll0.a[2],ll0.a[3], ll0.a[4],ll0.a[5],ll0.a[6],ll0.a[7] ); + ll0.b.x = zero; ll.b.v = m1; printf("1:%llx\n",ll.b.v); @@ -598,6 +733,7 @@ ll.a[0],ll.a[1],ll.a[2],ll.a[3], ll.a[4],ll.a[5],ll.a[6],ll.a[7] ); + ll.b.x = zero; printf("char a:1; char b:4; char c:7; char d:4; char e:4; char f:4;\n"); cc.b.a = m1;