source: tests/bitmanip3.cfa @ edf3ff1

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

move routines floor, ceiling, ceiling_div from bitmanip.hfa to math.hfa

  • Property mode set to 100644
File size: 11.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 : Mon Aug 24 09:53:26 2020
13// Update Count     : 66
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        printf( "signed char\n" );
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        } // for
140        printf( "\n" );
141
142        printf( "unsigned char\n" );
143        for ( uc = 1; uc != 0; uc <<= 1 ) {
144                ucr1 = floor2( uc, uc ); ucr2 = floor2( uc + 2hh, uc ); ucr3 = floor2( -uc - 2hh, uc );
145                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 );
146        } // for
147        printf( "\n" );
148
149        printf( "short int\n" );
150        for ( si = 1; si != 0; si <<= 1 ) {
151                sir1 = floor2( si, si ); sir2 = floor2( si + 2hh, si ); sir3 = floor2( -si - 2hh, si );
152                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 );
153        } // for
154        printf( "\n" );
155
156        printf( "unsigned short int\n" );
157        for ( usi = 1; usi != 0; usi <<= 1 ) {
158                usir1 = floor2( usi, usi ); usir2 = floor2( usi + 2hh, usi ); usir3 = floor2( -usi - 2hh, usi );
159                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 );
160        } // for
161        printf( "\n" );
162
163        printf( "int\n" );
164        for ( i = 1; i != 0; i <<= 1 ) {
165                ir1 = floor2( i, i ); ir2 = floor2( i + 2hh, i ); ir3 = floor2( -i - 2hh, i );
166                printf( "floor2(%d, %d) = %d, floor2(%d, %d) = %d, floor2(%d, %d) = %d\n", i, i, ir1, i + 2h, i, ir2, -i - 2h, i, ir3 );
167        } // for
168        printf( "\n" );
169
170        printf( "unsigned int\n" );
171        for ( ui = 1; ui != 0; ui <<= 1 ) {
172                uir1 = floor2( ui, ui ); uir2 = floor2( ui + 2hh, ui ); uir3 = floor2( -ui - 2hh, ui );
173                printf( "floor2(%u, %u) = %u, floor2(%u, %u) = %u, floor2(%u, %u) = %u\n", ui, ui, uir1, ui + 2h, ui, uir2, -ui - 2h, ui, uir3 );
174        } // for
175        printf( "\n" );
176
177        printf( "long int\n" );
178        for ( li = 1; li != 0; li <<= 1 ) {
179                lir1 = floor2( li, li ); lir2 = floor2( li + 2hh, li ); lir3 = floor2( -li - 2hh, li );
180                printf( "floor2(%ld, %ld) = %ld, floor2(%ld, %ld) = %ld, floor2(%ld, %ld) = %ld\n", li, li, lir1, li + 2h, li, lir2, -li - 2h, li, lir3 );
181        } // for
182        printf( "\n" );
183
184        printf( "unsigned long int\n" );
185        for ( uli = 1; uli != 0; uli <<= 1 ) {
186                ulir1 = floor2( uli, uli ); ulir2 = floor2( uli + 2hh, uli ); ulir3 = floor2( -uli - 2hh, uli );
187                printf( "floor2(%lu, %lu) = %lu, floor2(%lu, %lu) = %lu, floor2(%lu, %lu) = %lu\n", uli, uli, ulir1, uli + 2h, uli, ulir2, -uli - 2h, uli, ulir3 );
188        } // for
189        printf( "\n" );
190
191        printf( "long long int\n" );
192        for ( lli = 1; lli != 0; lli <<= 1 ) {
193                llir1 = floor2( lli, lli ); llir2 = floor2( lli + 2hh, lli ); llir3 = floor2( -lli - 2hh, lli );
194                printf( "floor2(%lld, %lld) = %lld, floor2(%lld, %lld) = %lld, floor2(%lld, %lld) = %lld\n", lli, lli, llir1, lli + 2h, lli, llir2, -lli - 2h, lli, llir3 );
195        } // for
196        printf( "\n" );
197
198        printf( "unsigned long long int\n" );
199        for ( ulli = 1; ulli != 0; ulli <<= 1 ) {
200                ullir1 = floor2( ulli, ulli ); ullir2 = floor2( ulli + 2hh, ulli ); ullir3 = floor2( -ulli - 2hh, ulli );
201                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 );
202        } // for
203        printf( "\n" );
204#endif // 0
205        //============================================================
206#if 1
207        sout | nl | "ceiling2" | nl | nl;
208
209        printf( "signed char\n" );
210        for ( sc = 1; sc != 0; sc <<= 1 ) {
211                scr1 = ceiling2( sc, sc ); scr2 = ceiling2( sc + 2hh, sc ); scr3 = ceiling2( -sc - 2hh, sc );
212                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 );
213        } // for
214        printf( "\n" );
215
216        printf( "unsigned char\n" );
217        for ( uc = 1; uc != 0; uc <<= 1 ) {
218                ucr1 = ceiling2( uc, uc ); ucr2 = ceiling2( uc + 2hh, uc ); ucr3 = ceiling2( -uc - 2hh, uc );
219                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 );
220        } // for
221        printf( "\n" );
222
223        printf( "short int\n" );
224        for ( si = 1; si != 0; si <<= 1 ) {
225                sir1 = ceiling2( si, si ); sir2 = ceiling2( si + 2hh, si ); sir3 = ceiling2( -si - 2hh, si );
226                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 );
227        } // for
228        printf( "\n" );
229
230        printf( "unsigned short int\n" );
231        for ( usi = 1; usi != 0; usi <<= 1 ) {
232                usir1 = ceiling2( usi, usi ); usir2 = ceiling2( usi + 2hh, usi ); usir3 = ceiling2( -usi - 2hh, usi );
233                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 );
234        } // for
235        printf( "\n" );
236
237        printf( "int\n" );
238        for ( i = 1; i != 0; i <<= 1 ) {
239                ir1 = ceiling2( i, i ); ir2 = ceiling2( i + 2hh, i ); ir3 = ceiling2( -i - 2hh, i );
240                printf( "ceiling2(%d, %d) = %d, ceiling2(%d, %d) = %d, ceiling2(%d, %d) = %d\n", i, i, ir1, i + 2h, i, ir2, -i - 2h, i, ir3 );
241        } // for
242        printf( "\n" );
243
244        printf( "unsigned int\n" );
245        for ( ui = 1; ui != 0; ui <<= 1 ) {
246                uir1 = ceiling2( ui, ui ); uir2 = ceiling2( ui + 2hh, ui ); uir3 = ceiling2( -ui - 2hh, ui );
247                printf( "ceiling2(%u, %u) = %u, ceiling2(%u, %u) = %u, ceiling2(%u, %u) = %u\n", ui, ui, uir1, ui + 2h, ui, uir2, -ui - 2h, ui, uir3 );
248        } // for
249        printf( "\n" );
250
251        printf( "long int\n" );
252        for ( li = 1; li != 0; li <<= 1 ) {
253                lir1 = ceiling2( li, li ); lir2 = ceiling2( li + 2hh, li ); lir3 = ceiling2( -li - 2hh, li );
254                printf( "ceiling2(%ld, %ld) = %ld, ceiling2(%ld, %ld) = %ld, ceiling2(%ld, %ld) = %ld\n", li, li, lir1, li + 2h, li, lir2, -li - 2h, li, lir3 );
255        } // for
256        printf( "\n" );
257
258        printf( "unsigned long int\n" );
259        for ( uli = 1; uli != 0; uli <<= 1 ) {
260                ulir1 = ceiling2( uli, uli ); ulir2 = ceiling2( uli + 2hh, uli ); ulir3 = ceiling2( -uli - 2hh, uli );
261                printf( "ceiling2(%lu, %lu) = %lu, ceiling2(%lu, %lu) = %lu, ceiling2(%lu, %lu) = %lu\n", uli, uli, ulir1, uli + 2h, uli, ulir2, -uli - 2h, uli, ulir3 );
262        } // for
263        printf( "\n" );
264
265        printf( "long long int\n" );
266        for ( lli = 1; lli != 0; lli <<= 1 ) {
267                llir1 = ceiling2( lli, lli ); llir2 = ceiling2( lli + 2hh, lli ); llir3 = ceiling2( -lli - 2hh, lli );
268                printf( "ceiling2(%lld, %lld) = %lld, ceiling2(%lld, %lld) = %lld, ceiling2(%lld, %lld) = %lld\n", lli, lli, llir1, lli + 2h, lli, llir2, -lli - 2h, lli, llir3 );
269        } // for
270        printf( "\n" );
271
272        printf( "unsigned long long int\n" );
273        for ( ulli = 1; ulli != 0; ulli <<= 1 ) {
274                ullir1 = ceiling2( ulli, ulli ); ullir2 = ceiling2( ulli + 2hh, ulli ); ullir3 = ceiling2( -ulli - 2hh, ulli );
275                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 );
276        } // for
277        printf( "\n" );
278#endif // 0
279} // main
280
281// Local Variables: //
282// tab-width: 4 //
283// compile-command: "cfa bitmanip3.cfa" //
284// End: //
Note: See TracBrowser for help on using the repository browser.