mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 23:33:54 -06:00
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:
parent
876d516311
commit
bb7443f6d6
3 changed files with 22 additions and 18 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue