source: tests/bitmanip2.cfa @ 76bf23c

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 76bf23c was 76bf23c, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

second attempt at bit manipulation operations

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