scoutfs-utils: add ilog2() helper

It's handy to use ilog2 in the format header for defining shifts based
on values.  Add a userspace helper that uses glibc's log2 functions.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2020-03-02 11:44:23 -08:00
committed by Zach Brown
parent ec782fff8d
commit 53f29d3f2a

View File

@@ -4,6 +4,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
/*
* Generate build warnings if the condition is false but generate no
@@ -79,6 +80,11 @@ do { \
(_x == 0 ? 0 : 64 - __builtin_clzll(_x)); \
})
#define ilog2(x) \
({ \
((unsigned long)log2l((long double)x)); \
})
/*
* return -1,0,+1 based on the memcmp comparison of the minimum of their
* two lengths. If their min shared bytes are equal but the lengths