lib: Add log2 ceiling function
Change-Id: Ifb41050e729a0ce314e4d4918e46f82bc7e16bed Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com> Reviewed-on: http://review.coreboot.org/4684 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
This commit is contained in:
@ -28,6 +28,7 @@
|
||||
/* Defined in src/lib/clog2.c */
|
||||
unsigned long log2(unsigned long x);
|
||||
#endif
|
||||
unsigned long log2_ceil(unsigned long x);
|
||||
|
||||
/* Defined in src/lib/lzma.c */
|
||||
unsigned long ulzma(unsigned char *src, unsigned char *dst);
|
||||
|
@ -27,3 +27,18 @@ unsigned long log2(unsigned long x)
|
||||
|
||||
return pow;
|
||||
}
|
||||
|
||||
unsigned long log2_ceil(unsigned long x)
|
||||
{
|
||||
unsigned long pow;
|
||||
|
||||
if (! x)
|
||||
return -1;
|
||||
|
||||
pow = log2(x);
|
||||
|
||||
if (x > (1ULL << pow))
|
||||
pow++;
|
||||
|
||||
return pow;
|
||||
}
|
||||
|
Reference in New Issue
Block a user