[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] bitops: unify bitops_flsl with host-utils.h, ca
From: |
Peter Maydell |
Subject: |
Re: [Qemu-devel] [PATCH] bitops: unify bitops_flsl with host-utils.h, call it bitops_clzl |
Date: |
Mon, 4 Feb 2013 18:34:34 +0000 |
On 4 February 2013 18:26, Richard Henderson <address@hidden> wrote:
> /**
> - * bitops_fls - find last (most-significant) set bit in a long word
> + * bitops_clzl - find last (most-significant) set bit in a long word
Should probably change the descriptive text to say "count leading
zeros"...
> * @word: the word to search
> *
> * Undefined if no set bit exists, so code should check against 0 first.
Should we change this to match clz32()/clz64()/bitops_ctzl() in not
having an undefined-behaviour case?
> */
> -static inline unsigned long bitops_flsl(unsigned long word)
> +static inline unsigned long bitops_clzl(unsigned long word)
> {
> - int num = BITS_PER_LONG - 1;
> -
> -#if LONG_MAX > 0x7FFFFFFF
> - if (!(word & (~0ul << 32))) {
> - num -= 32;
> - word <<= 32;
> - }
> + /* Both this function and the gcc builtin are undefined at 0, whereas
> + the host-utils functions return word-size at 0. Thus we prefer the
> + gcc builtin as the closer match. */
I think we should just fix the inconsistency rather than
retaining several similarly-named functions which have differing
corner-case behaviour.
-- PMM