source: tests/bitmanip3.cfa @ 950c58e

Last change on this file since 950c58e was 4f89e7b, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

more change printf to sout

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