qxl: refactor rounding up to a nearest power of 2

We already have pow2floor, mirror it and use instead of a function with
similar results (same in used domain), to clarify our intent.

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Radim Krčmář 2015-02-17 17:30:52 +01:00 committed by Gerd Hoffmann
parent 876d516311
commit bb7443f6d6
3 changed files with 22 additions and 18 deletions

View file

@ -483,6 +483,20 @@ int64_t pow2floor(int64_t value)
return value;
}
/* round up to the nearest power of 2 (0 if overflow) */
uint64_t pow2ceil(uint64_t value)
{
uint8_t nlz = clz64(value);
if (is_power_of_2(value)) {
return value;
}
if (!nlz) {
return 0;
}
return 1ULL << (64 - nlz);
}
/*
* Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128)
* Input is limited to 14-bit numbers