mirror of
https://github.com/versity/scoutfs.git
synced 2026-01-06 20:16:25 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user