4 #if defined(__GNUC_PREREQ)
5 # if __GNUC_PREREQ(4,2)
6 # pragma GCC diagnostic ignored "-Wparentheses"
10 /*Dead simple (but slow) versions to compare against.*/
12 static int test_ilog32(uint32_t _v){
14 for(ret=0;_v;ret++)_v>>=1;
18 static int test_ilog64(uint64_t _v){
20 for(ret=0;_v;ret++)_v>>=1;
26 int main(int _argc,const char *_argv[]){
30 /*This is how many tests you plan to run.*/
35 /*Test each bit in turn (and 0).*/
36 v=i?(uint32_t)1U<<i-1:0;
37 for(j=0;j<NTRIALS;j++){
41 fprintf(stderr,"ILOG_32(0x%08lX): %i != %i\n",(long)v,ILOG_32(v),l);
45 fprintf(stderr,"ilog32(0x%08lX): %i != %i\n",(long)v,ilog32(v),l);
48 if(STATIC_ILOG_32(v)!=l){
49 fprintf(stderr,"STATIC_ILOG_32(0x%08lX): %i != %i\n",
50 (long)v,STATIC_ILOG_32(v),l);
53 /*Also try a few more pseudo-random values with at most the same number
55 v=1103515245U*v+12345U&0xFFFFFFFFU>>(33-i>>1)>>(32-i>>1);
58 ok1(nmatches==3*(32+1)*NTRIALS);
62 /*Test each bit in turn (and 0).*/
63 v=i?(uint64_t)1U<<i-1:0;
64 for(j=0;j<NTRIALS;j++){
68 fprintf(stderr,"ILOG_64(0x%016llX): %i != %i\n",
69 (long long)v,ILOG_64(v),l);
73 fprintf(stderr,"ilog64(0x%016llX): %i != %i\n",
74 (long long)v,ilog64(v),l);
77 if(STATIC_ILOG_64(v)!=l){
78 fprintf(stderr,"STATIC_ILOG_64(0x%016llX): %i != %i\n",
79 (long long)v,STATIC_ILOG_64(v),l);
82 /*Also try a few more pseudo-random values with at most the same number
84 v=(uint64_t)(2862933555777941757ULL*v+3037000493ULL
85 &0xFFFFFFFFFFFFFFFFULL>>(65-i>>1)>>(64-i>>1));
88 ok1(nmatches==3*(64+1)*NTRIALS);