Re: [RFC,PATCH] Avoid manual shift-and-test logic in AllocSetFreeIndex - Mailing list pgsql-hackers

From Atsushi Ogawa
Subject Re: [RFC,PATCH] Avoid manual shift-and-test logic in AllocSetFreeIndex
Date
Msg-id 4A27C837.4060608@hi-ho.ne.jp
Whole thread Raw
In response to [RFC,PATCH] Avoid manual shift-and-test logic in AllocSetFreeIndex  (Jeremy Kerr <jk@ozlabs.org>)
Responses Re: [RFC,PATCH] Avoid manual shift-and-test logic in AllocSetFreeIndex
List pgsql-hackers
> +/*
> + * fls: find last set bit.
> + *
> + * Returns the 1-based index of the most-significant bit in x. The MSB
> + * is bit number 32, the LSB is bit number 1. If x is zero, the result is
> + * undefined.
> + */
> +static inline int
> +fls(unsigned int x)
...
> +        idx = fls((size - 1) >> ALLOC_MINBITS);

If size <= 8, fls((size - 1) >> ALLOC_MINBITS) is fls(0).
The result of fls(0) is undefined.

I think we have to never call fls(0) from AllocSetFreeIndex().
My proposal code:
    if (size > (1 << ALLOC_MINBITS))    {        idx = fls((size - 1) >> ALLOC_MINBITS);        Assert(idx <
ALLOCSET_NUM_FREELISTS);   }
 

Best regards,

---
Atsushi Ogawa


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: It's June 1; do you know where your release is?
Next
From: Magnus Hagander
Date:
Subject: Re: It's June 1; do you know where your release is?