On 02/23/2015 06:59 AM, Markus Armbruster wrote: > Alexey Kardashevskiy <a...@ozlabs.ru> writes: > >> This adds a helper to get closest bigger power-of-two value. >>
> > Here's how I'd do these functions: > > int64_t pow2floor(int64_t value) > { > assert(value > 0); > return 0x8000000000000000u >> clz64(value); > } Needs to be 0x8000000000000000ull for 32-bit machines to compile correctly. Why is the parameter int64_t? Wouldn't it be more useful to have: uint64_t pow2floor(uint64_t value) > > int64_t pow2ceil(int64_t value) > { Again, why allow signed inputs? > assert(value <= 0x4000000000000000) > if (value <= 1) > return 1; In particular, this slams all negative values to a result of 1, which doesn't necessarily make sense. > return 0x8000000000000000u >> (clz64(value - 1) - 1); > } > > > -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature