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:
Alexandru Gagniuc 2014-01-13 00:49:49 -06:00
parent 3dd0e72d3b
commit 594ef81326
2 changed files with 16 additions and 0 deletions

View File

@ -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);

View File

@ -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;
}