source: tests/bitmanip1.cfa @ 8f2f185

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 8f2f185 was da36d25, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

first complete draft of bitmanip, performance problems with polymorphic functions

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