1 #include <ccan/ilog/ilog.h>
2 #include <ccan/ilog/ilog.c>
4 #include <ccan/tap/tap.h>
6 /*Dead simple (but slow) versions to compare against.*/
8 static int test_ilog32(uint32_t _v){
10 for(ret=0;_v;ret++)_v>>=1;
14 static int test_ilog64(uint64_t _v){
16 for(ret=0;_v;ret++)_v>>=1;
25 /*This is how many tests you plan to run.*/
26 plan_tests(33 * NTRIALS * 3 + 65 * NTRIALS * 3);
29 /*Test each bit in turn (and 0).*/
30 v=i?(uint32_t)1U<<(i-1):0;
31 for(j=0;j<NTRIALS;j++){
34 ok1(STATIC_ILOG_32(v)==l);
36 ok1(ilog32_nz(v) == l || v == 0);
37 /*Also try a few more pseudo-random values with at most the same number
39 v=(1103515245U*v+12345U)&0xFFFFFFFFU>>((33-i)>>1)>>((32-i)>>1);
45 /*Test each bit in turn (and 0).*/
46 v=i?(uint64_t)1U<<(i-1):0;
47 for(j=0;j<NTRIALS;j++){
50 ok1(STATIC_ILOG_64(v)==l);
52 ok1(ilog64_nz(v) == l || v == 0);
53 /*Also try a few more pseudo-random values with at most the same number
55 v=(uint64_t)((2862933555777941757ULL*v+3037000493ULL)
56 &0xFFFFFFFFFFFFFFFFULL>>((65-i)>>1)>>((64-i)>>1));