ccan/ntdb: demote to junkcode.
[ccan] / junkcode / rusty@rustcorp.com.au-ntdb / test / run-001-fls.c
1 #include "ntdb-source.h"
2 #include "tap-interface.h"
3 #include "helprun-external-agent.h"
4
5 static unsigned int dumb_fls(uint64_t num)
6 {
7         int i;
8
9         for (i = 63; i >= 0; i--) {
10                 if (num & (1ULL << i))
11                         break;
12         }
13         return i + 1;
14 }
15
16 int main(int argc, char *argv[])
17 {
18         unsigned int i, j;
19
20         plan_tests(64 * 64 + 2);
21
22         ok1(fls64(0) == 0);
23         ok1(dumb_fls(0) == 0);
24
25         for (i = 0; i < 64; i++) {
26                 for (j = 0; j < 64; j++) {
27                         uint64_t val = (1ULL << i) | (1ULL << j);
28                         ok(fls64(val) == dumb_fls(val),
29                            "%llu -> %u should be %u", (long long)val,
30                            fls64(val), dumb_fls(val));
31                 }
32         }
33         return exit_status();
34 }