source: tests/bitmanip3.cfa @ 305cd5c

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 305cd5c 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
RevLine 
[da36d25]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
[7cfef0d]12// Last Modified On : Mon Aug 24 09:53:26 2020
13// Update Count     : 66
[da36d25]14//
15
16#include <fstream.hfa>
17#include <bitmanip.hfa>
18
19int main() {
[21923bd]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;
[da36d25]31
32        //============================================================
33#if 1
34        sout | nl | "is_pow2" | nl | nl;
35
36        sout | "signed char";
37        sc = 0;
[21923bd]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;
[da36d25]40        for ( sc = 1; sc != 0; sc <<= 1 ) {
[21923bd]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;
[da36d25]43        } // for
44        sout | nl;
45        sout | "unsigned char";
[21923bd]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;
[da36d25]52        } // for
53        sout | nl;
54
55        sout | "short int";
56        si = 0;
[21923bd]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;
[da36d25]59        for ( si = 1; si != 0; si <<= 1 ) {
[21923bd]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;
[da36d25]62        } // for
63        sout | nl;
64        sout | "unsigned short int";
65        usi = 0;
[21923bd]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;
[da36d25]68        for ( usi = 1; usi != 0; usi <<= 1 ) {
[21923bd]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;
[da36d25]71        } // for
72        sout | nl;
73
74        sout | "int";
75        i = 0;
[21923bd]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;
[da36d25]78        for ( i = 1; i != 0; i <<= 1 ) {
[21923bd]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;
[da36d25]81        } // for
82        sout | nl;
83        sout | "unsigned int";
84        ui = 0;
[21923bd]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;
[da36d25]87        for ( ui = 1; ui != 0; ui <<= 1 ) {
[21923bd]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;
[da36d25]90        } // for
91        sout | nl;
92
93        sout | "long int";
94        li = 0;
[21923bd]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;
[da36d25]97        for ( li = 1; li != 0; li <<= 1 ) {
[21923bd]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;
[da36d25]100        } // for
101        sout | nl;
102        sout | "unsigned long int";
103        uli = 0;
[21923bd]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;
[da36d25]106        for ( uli = 1; uli != 0; uli <<= 1 ) {
[21923bd]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;
[da36d25]109        } // for
110        sout | nl;
111
112        sout | "long long int";
113        lli = 0;
[21923bd]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;
[da36d25]116        for ( lli = 1; lli != 0; lli <<= 1 ) {
[21923bd]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;
[da36d25]119        } // for
120        sout | nl;
121        sout | "unsigned long long int";
122        ulli = 0;
[21923bd]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;
[da36d25]125        for ( ulli = 1; ulli != 0; ulli <<= 1 ) {
[21923bd]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;
[da36d25]128        } // for
129        sout | nl;
130#endif // 0
131        //============================================================
132#if 1
133        sout | nl | "floor2" | nl | nl;
134
135        printf( "signed char\n" );
[a3fab47]136        for ( sc = 1; sc != 0; sc <<= 1 ) {
[21923bd]137                scr1 = floor2( sc, sc ); scr2 = floor2( sc + 2hh, sc ); scr3 = floor2( -sc - 2hh, sc );
[a3fab47]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 );
[da36d25]139        } // for
140        printf( "\n" );
141
142        printf( "unsigned char\n" );
[a3fab47]143        for ( uc = 1; uc != 0; uc <<= 1 ) {
[21923bd]144                ucr1 = floor2( uc, uc ); ucr2 = floor2( uc + 2hh, uc ); ucr3 = floor2( -uc - 2hh, uc );
[a3fab47]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 );
[da36d25]146        } // for
147        printf( "\n" );
148
149        printf( "short int\n" );
[a3fab47]150        for ( si = 1; si != 0; si <<= 1 ) {
[21923bd]151                sir1 = floor2( si, si ); sir2 = floor2( si + 2hh, si ); sir3 = floor2( -si - 2hh, si );
[a3fab47]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 );
[da36d25]153        } // for
154        printf( "\n" );
155
156        printf( "unsigned short int\n" );
[a3fab47]157        for ( usi = 1; usi != 0; usi <<= 1 ) {
[21923bd]158                usir1 = floor2( usi, usi ); usir2 = floor2( usi + 2hh, usi ); usir3 = floor2( -usi - 2hh, usi );
[a3fab47]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 );
[da36d25]160        } // for
161        printf( "\n" );
162
163        printf( "int\n" );
[a3fab47]164        for ( i = 1; i != 0; i <<= 1 ) {
[21923bd]165                ir1 = floor2( i, i ); ir2 = floor2( i + 2hh, i ); ir3 = floor2( -i - 2hh, i );
[a3fab47]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 );
[da36d25]167        } // for
168        printf( "\n" );
169
170        printf( "unsigned int\n" );
[a3fab47]171        for ( ui = 1; ui != 0; ui <<= 1 ) {
[21923bd]172                uir1 = floor2( ui, ui ); uir2 = floor2( ui + 2hh, ui ); uir3 = floor2( -ui - 2hh, ui );
[a3fab47]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 );
[da36d25]174        } // for
175        printf( "\n" );
176
177        printf( "long int\n" );
[a3fab47]178        for ( li = 1; li != 0; li <<= 1 ) {
[21923bd]179                lir1 = floor2( li, li ); lir2 = floor2( li + 2hh, li ); lir3 = floor2( -li - 2hh, li );
[a3fab47]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 );
[da36d25]181        } // for
182        printf( "\n" );
183
184        printf( "unsigned long int\n" );
[a3fab47]185        for ( uli = 1; uli != 0; uli <<= 1 ) {
[21923bd]186                ulir1 = floor2( uli, uli ); ulir2 = floor2( uli + 2hh, uli ); ulir3 = floor2( -uli - 2hh, uli );
[a3fab47]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 );
[da36d25]188        } // for
189        printf( "\n" );
190
191        printf( "long long int\n" );
[a3fab47]192        for ( lli = 1; lli != 0; lli <<= 1 ) {
[21923bd]193                llir1 = floor2( lli, lli ); llir2 = floor2( lli + 2hh, lli ); llir3 = floor2( -lli - 2hh, lli );
[a3fab47]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 );
[da36d25]195        } // for
196        printf( "\n" );
197
198        printf( "unsigned long long int\n" );
[a3fab47]199        for ( ulli = 1; ulli != 0; ulli <<= 1 ) {
[21923bd]200                ullir1 = floor2( ulli, ulli ); ullir2 = floor2( ulli + 2hh, ulli ); ullir3 = floor2( -ulli - 2hh, ulli );
[a3fab47]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 );
[da36d25]202        } // for
203        printf( "\n" );
204#endif // 0
205        //============================================================
206#if 1
207        sout | nl | "ceiling2" | nl | nl;
208
209        printf( "signed char\n" );
[a3fab47]210        for ( sc = 1; sc != 0; sc <<= 1 ) {
[21923bd]211                scr1 = ceiling2( sc, sc ); scr2 = ceiling2( sc + 2hh, sc ); scr3 = ceiling2( -sc - 2hh, sc );
[a3fab47]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 );
[da36d25]213        } // for
214        printf( "\n" );
215
216        printf( "unsigned char\n" );
[a3fab47]217        for ( uc = 1; uc != 0; uc <<= 1 ) {
[21923bd]218                ucr1 = ceiling2( uc, uc ); ucr2 = ceiling2( uc + 2hh, uc ); ucr3 = ceiling2( -uc - 2hh, uc );
[a3fab47]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 );
[da36d25]220        } // for
221        printf( "\n" );
222
223        printf( "short int\n" );
[a3fab47]224        for ( si = 1; si != 0; si <<= 1 ) {
[21923bd]225                sir1 = ceiling2( si, si ); sir2 = ceiling2( si + 2hh, si ); sir3 = ceiling2( -si - 2hh, si );
[a3fab47]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 );
[da36d25]227        } // for
228        printf( "\n" );
229
230        printf( "unsigned short int\n" );
[a3fab47]231        for ( usi = 1; usi != 0; usi <<= 1 ) {
[21923bd]232                usir1 = ceiling2( usi, usi ); usir2 = ceiling2( usi + 2hh, usi ); usir3 = ceiling2( -usi - 2hh, usi );
[a3fab47]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 );
[da36d25]234        } // for
235        printf( "\n" );
236
237        printf( "int\n" );
[a3fab47]238        for ( i = 1; i != 0; i <<= 1 ) {
[21923bd]239                ir1 = ceiling2( i, i ); ir2 = ceiling2( i + 2hh, i ); ir3 = ceiling2( -i - 2hh, i );
[a3fab47]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 );
[da36d25]241        } // for
242        printf( "\n" );
243
244        printf( "unsigned int\n" );
[a3fab47]245        for ( ui = 1; ui != 0; ui <<= 1 ) {
[21923bd]246                uir1 = ceiling2( ui, ui ); uir2 = ceiling2( ui + 2hh, ui ); uir3 = ceiling2( -ui - 2hh, ui );
[a3fab47]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 );
[da36d25]248        } // for
249        printf( "\n" );
250
251        printf( "long int\n" );
[a3fab47]252        for ( li = 1; li != 0; li <<= 1 ) {
[21923bd]253                lir1 = ceiling2( li, li ); lir2 = ceiling2( li + 2hh, li ); lir3 = ceiling2( -li - 2hh, li );
[a3fab47]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 );
[da36d25]255        } // for
256        printf( "\n" );
257
258        printf( "unsigned long int\n" );
[a3fab47]259        for ( uli = 1; uli != 0; uli <<= 1 ) {
[21923bd]260                ulir1 = ceiling2( uli, uli ); ulir2 = ceiling2( uli + 2hh, uli ); ulir3 = ceiling2( -uli - 2hh, uli );
[a3fab47]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 );
[da36d25]262        } // for
263        printf( "\n" );
264
265        printf( "long long int\n" );
[a3fab47]266        for ( lli = 1; lli != 0; lli <<= 1 ) {
[21923bd]267                llir1 = ceiling2( lli, lli ); llir2 = ceiling2( lli + 2hh, lli ); llir3 = ceiling2( -lli - 2hh, lli );
[a3fab47]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 );
[da36d25]269        } // for
270        printf( "\n" );
271
272        printf( "unsigned long long int\n" );
[a3fab47]273        for ( ulli = 1; ulli != 0; ulli <<= 1 ) {
[21923bd]274                ullir1 = ceiling2( ulli, ulli ); ullir2 = ceiling2( ulli + 2hh, ulli ); ullir3 = ceiling2( -ulli - 2hh, ulli );
[a3fab47]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 );
[da36d25]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.