source: tests/bitmanip1.cfa@ 7df014f

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 7df014f was 76bf23c, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

second attempt at bit manipulation operations

  • Property mode set to 100644
File size: 9.5 KB
RevLine 
[76bf23c]1#include <fstream.hfa>
2#include <bitmanip.hfa>
3
4int main() {
5 signed char sc;
6 unsigned char usc;
7 short int si;
8 unsigned short int usi;
9 int i;
10 unsigned int ui;
11 long int li;
12 unsigned long int uli;
13 long long int lli;
14 unsigned long long int ulli;
15
16 //============================================================
17#if 1
18 sout | "leading0s" | nl | nl;
19
20 sout | "signed char";
21 sc = 0;
22 sout | wd(__bitsizeof(sc)+2, pad0(bin(sc))) | leading0s( sc );
23 for ( sc = 1; sc != 0; sc <<= 1 ) {
24 sout | wd(__bitsizeof(sc)+2, pad0(bin(sc))) | leading0s( sc );
25 } // for
26 sout | nl;
27 sout | "unsigned char";
28 usc = 0;
29 sout | wd(__bitsizeof(usc)+2, pad0(bin(usc))) | leading0s( usc );
30 for ( usc = 1; usc != 0; usc <<= 1 ) {
31 sout | wd(__bitsizeof(usc)+2, pad0(bin(usc))) | leading0s( usc );
32 } // for
33 sout | nl;
34
35 sout | "short int";
36 si = 0;
37 sout | wd(__bitsizeof(si)+2, pad0(bin(si))) | leading0s( si );
38 for ( si = 1; si != 0; si <<= 1 ) {
39 sout | wd(__bitsizeof(si)+2, pad0(bin(si))) | leading0s( si );
40 } // for
41 sout | nl;
42 sout | "unsigned short int";
43 usi = 0;
44 sout | wd(__bitsizeof(usi)+2, pad0(bin(usi))) | leading0s( usi );
45 for ( usi = 1; usi != 0; usi <<= 1 ) {
46 sout | wd(__bitsizeof(usi)+2, pad0(bin(usi))) | leading0s( usi );
47 } // for
48 sout | nl;
49
50 sout | "int";
51 i = 0;
52 sout | wd(__bitsizeof(i)+2, pad0(bin(i))) | leading0s( i );
53 for ( i = 1; i != 0; i <<= 1 ) {
54 sout | wd(__bitsizeof(i)+2, pad0(bin(i))) | leading0s( i );
55 } // for
56 sout | nl;
57 sout | "unsigned int";
58 ui = 0;
59 sout | wd(__bitsizeof(ui)+2, pad0(bin(ui))) | leading0s( ui );
60 for ( ui = 1; ui != 0; ui <<= 1 ) {
61 sout | wd(__bitsizeof(ui)+2, pad0(bin(ui))) | leading0s( ui );
62 } // for
63 sout | nl;
64
65 sout | "long int";
66 li = 0;
67 sout | wd(__bitsizeof(li)+2, pad0(bin(li))) | leading0s( li );
68 for ( li = 1; li != 0; li <<= 1 ) {
69 sout | wd(__bitsizeof(li)+2, pad0(bin(li))) | leading0s( li );
70 } // for
71 sout | nl;
72 sout | "unsigned long int";
73 uli = 0;
74 sout | wd(__bitsizeof(uli)+2, pad0(bin(uli))) | leading0s( uli );
75 for ( uli = 1; uli != 0; uli <<= 1 ) {
76 sout | wd(__bitsizeof(uli)+2, pad0(bin(uli))) | leading0s( uli );
77 } // for
78 sout | nl;
79
80 sout | "long long int";
81 lli = 0;
82 sout | wd(__bitsizeof(lli)+2, pad0(bin(lli))) | leading0s( lli );
83 for ( lli = 1; lli != 0; lli <<= 1 ) {
84 sout | wd(__bitsizeof(lli)+2, pad0(bin(lli))) | leading0s( lli );
85 } // for
86 sout | nl;
87 ulli = 0;
88 sout | wd(__bitsizeof(ulli)+2, pad0(bin(ulli))) | leading0s( ulli );
89 sout | "unsigned long long int";
90 for ( ulli = 1; ulli != 0; ulli <<= 1 ) {
91 sout | wd(__bitsizeof(ulli)+2, pad0(bin(ulli))) | leading0s( ulli );
92 } // for
93 sout | nl;
94#endif // 0
95 //============================================================
96#if 1
97 sout | nl | "trailing0s" | nl | nl;
98
99 sout | "signed char";
100 for ( sc = 1; sc != 0; sc <<= 1 ) {
101 sout | wd(__bitsizeof(sc)+2, pad0(bin(sc))) | trailing0s( sc );
102 } // for
103 sout | wd(__bitsizeof(sc)+2, pad0(bin(sc))) | trailing0s( sc );
104 sout | nl;
105 sout | "unsigned char";
106 for ( usc = 1; usc != 0; usc <<= 1 ) {
107 sout | wd(__bitsizeof(usc)+2, pad0(bin(usc))) | trailing0s( usc );
108 } // for
109 sout | wd(__bitsizeof(usc)+2, pad0(bin(usc))) | trailing0s( usc );
110 sout | nl;
111
112 sout | "short int";
113 for ( si = 1; si != 0; si <<= 1 ) {
114 sout | wd(__bitsizeof(si)+2, pad0(bin(si))) | trailing0s( si );
115 } // for
116 sout | wd(__bitsizeof(si)+2, pad0(bin(si))) | trailing0s( si );
117 sout | nl;
118 sout | "unsigned short int";
119 for ( usi = 1; usi != 0; usi <<= 1 ) {
120 sout | wd(__bitsizeof(usi)+2, pad0(bin(usi))) | trailing0s( usi );
121 } // for
122 sout | wd(__bitsizeof(usi)+2, pad0(bin(usi))) | trailing0s( usi );
123 sout | nl;
124
125 sout | "int";
126 for ( i = 1; i != 0; i <<= 1 ) {
127 sout | wd(__bitsizeof(i)+2, pad0(bin(i))) | trailing0s( i );
128 } // for
129 sout | wd(__bitsizeof(i)+2, pad0(bin(i))) | trailing0s( i );
130 sout | nl;
131 sout | "unsigned int";
132 for ( ui = 1; ui != 0; ui <<= 1 ) {
133 sout | wd(__bitsizeof(ui)+2, pad0(bin(ui))) | trailing0s( ui );
134 } // for
135 sout | wd(__bitsizeof(ui)+2, pad0(bin(ui))) | trailing0s( ui );
136 sout | nl;
137
138 sout | "long int";
139 for ( li = 1; li != 0; li <<= 1 ) {
140 sout | wd(__bitsizeof(li)+2, pad0(bin(li))) | trailing0s( li );
141 } // for
142 sout | wd(__bitsizeof(li)+2, pad0(bin(li))) | trailing0s( li );
143 sout | nl;
144 sout | "unsigned long int";
145 for ( uli = 1; uli != 0; uli <<= 1 ) {
146 sout | wd(__bitsizeof(uli)+2, pad0(bin(uli))) | trailing0s( uli );
147 } // for
148 sout | wd(__bitsizeof(uli)+2, pad0(bin(uli))) | trailing0s( uli );
149 sout | nl;
150
151 sout | "long long int";
152 for ( lli = 1; lli != 0; lli <<= 1 ) {
153 sout | wd(__bitsizeof(lli)+2, pad0(bin(lli))) | trailing0s( lli );
154 } // for
155 sout | wd(__bitsizeof(lli)+2, pad0(bin(lli))) | trailing0s( lli );
156 sout | nl;
157 sout | "unsigned long long int";
158 for ( ulli = 1; ulli != 0; ulli <<= 1 ) {
159 sout | wd(__bitsizeof(ulli)+2, pad0(bin(ulli))) | trailing0s( ulli );
160 } // for
161 sout | wd(__bitsizeof(ulli)+2, pad0(bin(ulli))) | trailing0s( ulli );
162 sout | nl;
163#endif // 0
164 //============================================================
165#if 1
166 sout | nl | "all0s" | nl | nl;
167
168 sout | "signed char";
169 for ( sc = 0; sc != -1hh; sc = (sc << 1) + 1 ) {
170 sout | wd(__bitsizeof(sc)+2, pad0(bin(sc))) | all0s( sc );
171 } // for
172 sout | wd(__bitsizeof(sc)+2, pad0(bin(sc))) | all0s( sc );
173 sout | nl;
174 sout | "unsigned char";
175 for ( usc = 0; usc != -1hh; usc = (usc << 1) + 1 ) {
176 sout | wd(__bitsizeof(usc)+2, pad0(bin(usc))) | all0s( usc );
177 } // for
178 sout | wd(__bitsizeof(usc)+2, pad0(bin(usc))) | all0s( usc );
179 sout | nl;
180
181 sout | "short int";
182 for ( si = 0; si != -1h; si = (si << 1) + 1 ) {
183 sout | wd(__bitsizeof(si)+2, pad0(bin(si))) | all0s( si );
184 } // for
185 sout | wd(__bitsizeof(si)+2, pad0(bin(si))) | all0s( si );
186 sout | nl;
187 sout | "unsigned short int";
188 for ( usi = 0; usi != -1h; usi = (usi << 1) + 1 ) {
189 sout | wd(__bitsizeof(usi)+2, pad0(bin(usi))) | all0s( usi );
190 } // for
191 sout | wd(__bitsizeof(usi)+2, pad0(bin(usi))) | all0s( usi );
192 sout | nl;
193
194 sout | "int";
195 for ( i = 0; i != -1; i = (i << 1) + 1 ) {
196 sout | wd(__bitsizeof(i)+2, pad0(bin(i))) | all0s( i );
197 } // for
198 sout | wd(__bitsizeof(i)+2, pad0(bin(i))) | all0s( i );
199 sout | nl;
200 sout | "unsigned int";
201 for ( ui = 0; ui != -1; ui = (ui << 1) + 1 ) {
202 sout | wd(__bitsizeof(ui)+2, pad0(bin(ui))) | all0s( ui );
203 } // for
204 sout | wd(__bitsizeof(ui)+2, pad0(bin(ui))) | all0s( ui );
205 sout | nl;
206
207 sout | "long int";
208 for ( li = 0; li != -1; li = (li << 1) + 1 ) {
209 sout | wd(__bitsizeof(li)+2, pad0(bin(li))) | all0s( li );
210 } // for
211 sout | wd(__bitsizeof(li)+2, pad0(bin(li))) | all0s( li );
212 sout | nl;
213 sout | "unsigned long int";
214 for ( uli = 0; uli != -1; uli = (uli << 1) + 1 ) {
215 sout | wd(__bitsizeof(uli)+2, pad0(bin(uli))) | all0s( uli );
216 } // for
217 sout | wd(__bitsizeof(uli)+2, pad0(bin(uli))) | all0s( uli );
218 sout | nl;
219
220 sout | "long long int";
221 for ( lli = 0; lli != -1; lli = (lli << 1) + 1 ) {
222 sout | wd(__bitsizeof(lli)+2, pad0(bin(lli))) | all0s( lli );
223 } // for
224 sout | wd(__bitsizeof(lli)+2, pad0(bin(lli))) | all0s( lli );
225 sout | nl;
226 sout | "unsigned long long int";
227 for ( ulli = 0; ulli != -1; ulli = (ulli << 1) + 1 ) {
228 sout | wd(__bitsizeof(ulli)+2, pad0(bin(ulli))) | all0s( ulli );
229 } // for
230 sout | wd(__bitsizeof(ulli)+2, pad0(bin(ulli))) | all0s( ulli );
231 sout | nl;
232#endif // 0
233 //============================================================
234#if 1
235 sout | nl | "all1s" | nl | nl;
236
237 sout | "signed char";
238 for ( sc = 0; sc != -1hh; sc = (sc << 1) + 1 ) {
239 sout | wd(__bitsizeof(sc)+2, pad0(bin(sc))) | all1s( sc );
240 } // for
241 sout | wd(__bitsizeof(sc)+2, pad0(bin(sc))) | all1s( sc );
242 sout | nl;
243 sout | "unsigned char";
244 for ( usc = 0; usc != -1hh; usc = (usc << 1) + 1 ) {
245 sout | wd(__bitsizeof(usc)+2, pad0(bin(usc))) | all1s( usc );
246 } // for
247 sout | wd(__bitsizeof(usc)+2, pad0(bin(usc))) | all1s( usc );
248 sout | nl;
249
250 sout | "short int";
251 for ( si = 0; si != -1h; si = (si << 1) + 1 ) {
252 sout | wd(__bitsizeof(si)+2, pad0(bin(si))) | all1s( si );
253 } // for
254 sout | wd(__bitsizeof(si)+2, pad0(bin(si))) | all1s( si );
255 sout | nl;
256 sout | "unsigned short int";
257 for ( usi = 0; usi != -1h; usi = (usi << 1) + 1 ) {
258 sout | wd(__bitsizeof(usi)+2, pad0(bin(usi))) | all1s( usi );
259 } // for
260 sout | wd(__bitsizeof(usi)+2, pad0(bin(usi))) | all1s( usi );
261 sout | nl;
262
263 sout | "int";
264 for ( i = 0; i != -1; i = (i << 1) + 1 ) {
265 sout | wd(__bitsizeof(i)+2, pad0(bin(i))) | all1s( i );
266 } // for
267 sout | wd(__bitsizeof(i)+2, pad0(bin(i))) | all1s( i );
268 sout | nl;
269 sout | "unsigned int";
270 for ( ui = 0; ui != -1; ui = (ui << 1) + 1 ) {
271 sout | wd(__bitsizeof(ui)+2, pad0(bin(ui))) | all1s( ui );
272 } // for
273 sout | wd(__bitsizeof(ui)+2, pad0(bin(ui))) | all1s( ui );
274 sout | nl;
275
276 sout | "long int";
277 for ( li = 0; li != -1; li = (li << 1) + 1 ) {
278 sout | wd(__bitsizeof(li)+2, pad0(bin(li))) | all1s( li );
279 } // for
280 sout | wd(__bitsizeof(li)+2, pad0(bin(li))) | all1s( li );
281 sout | nl;
282 sout | "unsigned long int";
283 for ( uli = 0; uli != -1; uli = (uli << 1) + 1 ) {
284 sout | wd(__bitsizeof(uli)+2, pad0(bin(uli))) | all1s( uli );
285 } // for
286 sout | wd(__bitsizeof(uli)+2, pad0(bin(uli))) | all1s( uli );
287 sout | nl;
288
289 sout | "long long int";
290 for ( lli = 0; lli != -1; lli = (lli << 1) + 1 ) {
291 sout | wd(__bitsizeof(lli)+2, pad0(bin(lli))) | all1s( lli );
292 } // for
293 sout | wd(__bitsizeof(lli)+2, pad0(bin(lli))) | all1s( lli );
294 sout | nl;
295 sout | "unsigned long long int";
296 for ( ulli = 0; ulli != -1; ulli = (ulli << 1) + 1 ) {
297 sout | wd(__bitsizeof(ulli)+2, pad0(bin(ulli))) | all1s( ulli );
298 } // for
299 sout | wd(__bitsizeof(ulli)+2, pad0(bin(ulli))) | all1s( ulli );
300 sout | nl;
301#endif // 0
302} // main
303
304// Local Variables: //
305// tab-width: 4 //
306// compile-command: "cfa bitmanip1.cfa" //
307// End: //
Note: See TracBrowser for help on using the repository browser.