Welcome to little lamb

Code » test-msb » next » tree

[next] / src / test-alt.c

#include <stdint.h>

typedef uint64_t u64;

extern int msb(u64 v);

int total = 0;

/* By David Howells */

#define PAGE_SHIFT 12
static int
get_msb(u64 v)
{
    int r;
    --v;
    v >>= PAGE_SHIFT;
    r = msb(v);
    return r;
}

int main(void)
{
    long rep, loop;
    u64 v;

    for (rep = 1000000; rep > 0; --rep) {
        for (loop = 0; loop <= 16384; loop += 4) {
            v = 1UL << loop;
            total += get_msb(v);
        }
    }

    return 0;
}