annotate test/bitfield1.c @ 545:2f577690bcfb

*** empty log message ***
author kono
date Mon, 02 Jan 2006 14:38:51 +0900
parents 5640fb7a270d
children df60b120675d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
32737bad7489 fix list/tag interference
kono
parents: 428
diff changeset
1 int printf(const char *format, ...);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
2
d488b72254fb bit-field done.
kono
parents:
diff changeset
3 struct aho {
d488b72254fb bit-field done.
kono
parents:
diff changeset
4 int i:1,j:1;
d488b72254fb bit-field done.
kono
parents:
diff changeset
5 char a:7;
d488b72254fb bit-field done.
kono
parents:
diff changeset
6 char :7,k:1,:3;
d488b72254fb bit-field done.
kono
parents:
diff changeset
7 long long v:33;
d488b72254fb bit-field done.
kono
parents:
diff changeset
8 long long w:33;
d488b72254fb bit-field done.
kono
parents:
diff changeset
9 long long x:33;
d488b72254fb bit-field done.
kono
parents:
diff changeset
10 } a /* = {-1,3,3,3,3} */ ;
d488b72254fb bit-field done.
kono
parents:
diff changeset
11
d488b72254fb bit-field done.
kono
parents:
diff changeset
12 union aho1 {
d488b72254fb bit-field done.
kono
parents:
diff changeset
13 int i:1,j:1;
d488b72254fb bit-field done.
kono
parents:
diff changeset
14 char a:7;
d488b72254fb bit-field done.
kono
parents:
diff changeset
15 char :7,k:1,:3;
d488b72254fb bit-field done.
kono
parents:
diff changeset
16 long long v:33;
d488b72254fb bit-field done.
kono
parents:
diff changeset
17 long long w:33;
d488b72254fb bit-field done.
kono
parents:
diff changeset
18 long long x:33;
d488b72254fb bit-field done.
kono
parents:
diff changeset
19 } a11 ;
d488b72254fb bit-field done.
kono
parents:
diff changeset
20
d488b72254fb bit-field done.
kono
parents:
diff changeset
21 union ll1 {
337
694cdf15c5bd MIPS bit-field done.
kono
parents: 336
diff changeset
22 unsigned char a[32];
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
23 struct {
d488b72254fb bit-field done.
kono
parents:
diff changeset
24 char a:4;
d488b72254fb bit-field done.
kono
parents:
diff changeset
25 long long v:33;
d488b72254fb bit-field done.
kono
parents:
diff changeset
26 long long w:33;
d488b72254fb bit-field done.
kono
parents:
diff changeset
27 long long x:33;
d488b72254fb bit-field done.
kono
parents:
diff changeset
28 } b;
d488b72254fb bit-field done.
kono
parents:
diff changeset
29 } ll1;
d488b72254fb bit-field done.
kono
parents:
diff changeset
30
d488b72254fb bit-field done.
kono
parents:
diff changeset
31 union ll0 {
337
694cdf15c5bd MIPS bit-field done.
kono
parents: 336
diff changeset
32 unsigned char a[32];
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
33 struct {
d488b72254fb bit-field done.
kono
parents:
diff changeset
34 char a:4;
d488b72254fb bit-field done.
kono
parents:
diff changeset
35 long long v:48;
d488b72254fb bit-field done.
kono
parents:
diff changeset
36 long long w:48;
d488b72254fb bit-field done.
kono
parents:
diff changeset
37 long long x:48;
d488b72254fb bit-field done.
kono
parents:
diff changeset
38 } b;
d488b72254fb bit-field done.
kono
parents:
diff changeset
39 } ll0;
d488b72254fb bit-field done.
kono
parents:
diff changeset
40
d488b72254fb bit-field done.
kono
parents:
diff changeset
41
d488b72254fb bit-field done.
kono
parents:
diff changeset
42 union ll {
337
694cdf15c5bd MIPS bit-field done.
kono
parents: 336
diff changeset
43 unsigned char a[32];
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
44 struct {
d488b72254fb bit-field done.
kono
parents:
diff changeset
45 char a:4;
d488b72254fb bit-field done.
kono
parents:
diff changeset
46 long long v:56;
d488b72254fb bit-field done.
kono
parents:
diff changeset
47 long long w:56;
d488b72254fb bit-field done.
kono
parents:
diff changeset
48 long long x:56;
d488b72254fb bit-field done.
kono
parents:
diff changeset
49 } b;
d488b72254fb bit-field done.
kono
parents:
diff changeset
50 } ll;
d488b72254fb bit-field done.
kono
parents:
diff changeset
51
d488b72254fb bit-field done.
kono
parents:
diff changeset
52 union cc {
d488b72254fb bit-field done.
kono
parents:
diff changeset
53 int a;
d488b72254fb bit-field done.
kono
parents:
diff changeset
54 struct {
d488b72254fb bit-field done.
kono
parents:
diff changeset
55 char a:1;
d488b72254fb bit-field done.
kono
parents:
diff changeset
56 char b:4;
d488b72254fb bit-field done.
kono
parents:
diff changeset
57 char c:7;
d488b72254fb bit-field done.
kono
parents:
diff changeset
58 char d:4;
d488b72254fb bit-field done.
kono
parents:
diff changeset
59 char e:4;
d488b72254fb bit-field done.
kono
parents:
diff changeset
60 char f:4;
d488b72254fb bit-field done.
kono
parents:
diff changeset
61 } b;
d488b72254fb bit-field done.
kono
parents:
diff changeset
62 } cc;
d488b72254fb bit-field done.
kono
parents:
diff changeset
63
d488b72254fb bit-field done.
kono
parents:
diff changeset
64 union ii {
d488b72254fb bit-field done.
kono
parents:
diff changeset
65 int a;
d488b72254fb bit-field done.
kono
parents:
diff changeset
66 struct {
d488b72254fb bit-field done.
kono
parents:
diff changeset
67 int a:1;
d488b72254fb bit-field done.
kono
parents:
diff changeset
68 int b:4;
d488b72254fb bit-field done.
kono
parents:
diff changeset
69 int c:4;
d488b72254fb bit-field done.
kono
parents:
diff changeset
70 int d:4;
d488b72254fb bit-field done.
kono
parents:
diff changeset
71 int e:4;
d488b72254fb bit-field done.
kono
parents:
diff changeset
72 int f:4;
d488b72254fb bit-field done.
kono
parents:
diff changeset
73 } b;
d488b72254fb bit-field done.
kono
parents:
diff changeset
74 } ii;
545
2f577690bcfb *** empty log message ***
kono
parents: 496
diff changeset
75 void main5();
2f577690bcfb *** empty log message ***
kono
parents: 496
diff changeset
76 int
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
77 main()
d488b72254fb bit-field done.
kono
parents:
diff changeset
78 {
337
694cdf15c5bd MIPS bit-field done.
kono
parents: 336
diff changeset
79 int i;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
80 printf("#0078:%d\n",a.i);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
81
d488b72254fb bit-field done.
kono
parents:
diff changeset
82 ll1.b.v = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
83 printf("#0081:01:%llx\n",ll1.b.v);
496
5640fb7a270d more bugs...
kono
parents: 491
diff changeset
84 printf("#0082:02:"); for(i=0;i<32;i++) printf("#0082:%02x",ll1.a[i]); printf("#0082:\n");
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
85 ll1.b.v = 0;
d488b72254fb bit-field done.
kono
parents:
diff changeset
86 ll1.b.w = -1;
496
5640fb7a270d more bugs...
kono
parents: 491
diff changeset
87 printf("#0085:02:"); for(i=0;i<32;i++) printf("#0085:%02x",ll1.a[i]); printf("#0085:\n");
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
88 ll1.b.w = 0;
d488b72254fb bit-field done.
kono
parents:
diff changeset
89 ll1.b.x = -1;
496
5640fb7a270d more bugs...
kono
parents: 491
diff changeset
90 printf("#0088:02:"); for(i=0;i<32;i++) printf("#0088:%02x",ll1.a[i]); printf("#0088:\n");
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
91
d488b72254fb bit-field done.
kono
parents:
diff changeset
92 ll0.b.v = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
93 printf("#0091:01:%llx\n",ll0.b.v);
496
5640fb7a270d more bugs...
kono
parents: 491
diff changeset
94 printf("#0092:02:"); for(i=0;i<32;i++) printf("#0092:%02x",ll0.a[i]); printf("#0092:\n");
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
95 ll0.b.v = 0;
d488b72254fb bit-field done.
kono
parents:
diff changeset
96 ll0.b.w = -1;
496
5640fb7a270d more bugs...
kono
parents: 491
diff changeset
97 printf("#0095:02:"); for(i=0;i<32;i++) printf("#0095:%02x",ll0.a[i]); printf("#0095:\n");
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
98 ll0.b.w = 0;
d488b72254fb bit-field done.
kono
parents:
diff changeset
99 ll0.b.x = -1;
496
5640fb7a270d more bugs...
kono
parents: 491
diff changeset
100 printf("#0098:02:"); for(i=0;i<32;i++) printf("#0098:%02x",ll0.a[i]); printf("#0098:\n");
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
101
d488b72254fb bit-field done.
kono
parents:
diff changeset
102 ll.b.v = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
103 printf("#0101:1:%llx\n",ll.b.v);
496
5640fb7a270d more bugs...
kono
parents: 491
diff changeset
104 printf("#0102:02:"); for(i=0;i<32;i++) printf("#0102:%02x",ll.a[i]); printf("#0102:\n");
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
105 ll.b.v = 0;
d488b72254fb bit-field done.
kono
parents:
diff changeset
106 ll.b.w = -1;
496
5640fb7a270d more bugs...
kono
parents: 491
diff changeset
107 printf("#0105:02:"); for(i=0;i<32;i++) printf("#0105:%02x",ll.a[i]); printf("#0105:\n");
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
108 ll.b.w = 0;
d488b72254fb bit-field done.
kono
parents:
diff changeset
109 ll.b.x = -1;
496
5640fb7a270d more bugs...
kono
parents: 491
diff changeset
110 printf("#0108:02:"); for(i=0;i<32;i++) printf("#0108:%02x",ll.a[i]); printf("#0108:\n");
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
111
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
112 printf("#0110:char a:1; char b:4; char c:7; char d:4; char e:4; char f:4;\n");
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
113 cc.b.a = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
114 printf("#0112:a:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
115 cc.b.b = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
116 printf("#0114:b:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
117 cc.b.c = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
118 printf("#0116:c:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
119 cc.b.d = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
120 printf("#0118:d:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
121 cc.b.e = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
122 printf("#0120:e:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
123 cc.b.f = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
124 printf("#0122:f:%08x\n",cc.a);
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
125 printf("#0123:3:%d %d\n",cc.b.c,cc.b.d);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
126 cc.a = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
127 printf("#0125:f:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
128 cc.b.a = 0;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
129 printf("#0127:a:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
130 cc.b.b = 0;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
131 printf("#0129:b:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
132 cc.b.c = 0;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
133 printf("#0131:c:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
134 cc.b.d = 0;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
135 printf("#0133:d:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
136 cc.b.e = 0;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
137 printf("#0135:e:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
138 cc.b.f = 0;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
139 printf("#0137:f:%08x\n",cc.a);
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
140 printf("#0138:3:%d %d\n",cc.b.c,cc.b.d);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
141 cc.a = 0;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
142 printf("#0140:f:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
143 cc.b.a = 1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
144 printf("#0142:a:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
145 cc.b.b = 1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
146 printf("#0144:b:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
147 cc.b.c = 1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
148 printf("#0146:c:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
149 cc.b.d = 1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
150 printf("#0148:d:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
151 cc.b.e = 1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
152 printf("#0150:e:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
153 cc.b.f = 1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
154 printf("#0152:f:%08x\n",cc.a);
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
155 printf("#0153:3:%d %d\n",cc.b.c,cc.b.d);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
156 cc.a = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
157 printf("#0155:f:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
158 cc.b.a = 1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
159 printf("#0157:a:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
160 cc.b.b = 1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
161 printf("#0159:b:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
162 cc.b.c = 1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
163 printf("#0161:c:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
164 cc.b.d = 1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
165 printf("#0163:d:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
166 cc.b.e = 1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
167 printf("#0165:e:%08x\n",cc.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
168 cc.b.f = 1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
169 printf("#0167:f:%08x\n",cc.a);
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
170 printf("#0168:3:%d %d\n",cc.b.c,cc.b.d);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
171
d488b72254fb bit-field done.
kono
parents:
diff changeset
172 ii.b.a = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
173 printf("#0171:6:%08x\n",ii.a);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
174 ii.b.d = -1;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
175 printf("#0173:6:%08x\n",ii.a);
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
176 printf("#0174:5:%d %d\n",ii.b.a,ii.b.d);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
177
d488b72254fb bit-field done.
kono
parents:
diff changeset
178 main5();
d488b72254fb bit-field done.
kono
parents:
diff changeset
179 return 0;
d488b72254fb bit-field done.
kono
parents:
diff changeset
180 }
d488b72254fb bit-field done.
kono
parents:
diff changeset
181
545
2f577690bcfb *** empty log message ***
kono
parents: 496
diff changeset
182 void
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
183 main5()
d488b72254fb bit-field done.
kono
parents:
diff changeset
184 {
d488b72254fb bit-field done.
kono
parents:
diff changeset
185 int i,j,bit=1;
d488b72254fb bit-field done.
kono
parents:
diff changeset
186 for(i=0;i<32;i++,bit<<=1) {
d488b72254fb bit-field done.
kono
parents:
diff changeset
187 ii.a = bit;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
188 printf("#0186:%08x:ii.b.a=%d ii.b.b=%d ii.b.c=%d ii.b.d=%d ii.b.e=%d ii.b.f=%d\n",bit,
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
189 ii.b.a,ii.b.b,ii.b.c,ii.b.d,ii.b.e,ii.b.f);
d488b72254fb bit-field done.
kono
parents:
diff changeset
190 }
d488b72254fb bit-field done.
kono
parents:
diff changeset
191 bit=1;
d488b72254fb bit-field done.
kono
parents:
diff changeset
192 for(i=0;i<32;i++,bit<<=1) {
d488b72254fb bit-field done.
kono
parents:
diff changeset
193 cc.a = bit;
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
194 printf("#0192:%08x:cc.b.a=%d cc.b.b=%d cc.b.c=%d cc.b.d=%d cc.b.e=%d cc.b.f=%d\n",bit,
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
195 cc.b.a,cc.b.b,cc.b.c,cc.b.d,cc.b.e,cc.b.f);
d488b72254fb bit-field done.
kono
parents:
diff changeset
196 }
337
694cdf15c5bd MIPS bit-field done.
kono
parents: 336
diff changeset
197 ll.a[0]=ll.a[1]=ll.a[2]=ll.a[3]= ll.a[4]=ll.a[5]=ll.a[6]=ll.a[7]=0;
341
ca34f02b2056 ptr cache speed up
kono
parents: 337
diff changeset
198 ll.b.v=ll.b.w=ll.b.x = 0;
337
694cdf15c5bd MIPS bit-field done.
kono
parents: 336
diff changeset
199 for(i=7;i>=0;i--) {
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
200 bit=1;
d488b72254fb bit-field done.
kono
parents:
diff changeset
201 for(j=0;j<32;j++,bit<<=1) {
d488b72254fb bit-field done.
kono
parents:
diff changeset
202 ll.a[i] = bit;
545
2f577690bcfb *** empty log message ***
kono
parents: 496
diff changeset
203 printf("#0201:02:%02x %02x %02x %02x %02x %02x %02x %02x\n",
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
204 ll.a[0],ll.a[1],ll.a[2],ll.a[3],
d488b72254fb bit-field done.
kono
parents:
diff changeset
205 ll.a[4],ll.a[5],ll.a[6],ll.a[7]
d488b72254fb bit-field done.
kono
parents:
diff changeset
206 );
491
a379da780856 cond signed/unsigned
kono
parents: 467
diff changeset
207 printf("#0205: ll.b.v=%lld ll.b.w=%lld ll.b.x=%lld\n",ll.b.v,ll.b.w,ll.b.x);
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
208 }
337
694cdf15c5bd MIPS bit-field done.
kono
parents: 336
diff changeset
209 ll.a[i]=0;
336
d488b72254fb bit-field done.
kono
parents:
diff changeset
210 }
d488b72254fb bit-field done.
kono
parents:
diff changeset
211 }
d488b72254fb bit-field done.
kono
parents:
diff changeset
212