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

From: Atsushi Ogawa <a_ogawa(at)hi-ho(dot)ne(dot)jp>
To: Jeremy Kerr <jk(at)ozlabs(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Florian Weimer <fweimer(at)bfk(dot)de>
Subject: Re: [RFC, PATCH] Avoid manual shift-and-test logic in AllocSetFreeIndex
Date: 2009-06-04 13:12:23
Message-ID: 4A27C837.4060608@hi-ho.ne.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2009-06-04 13:39:56 Re: It's June 1; do you know where your release is?
Previous Message Andrew Dunstan 2009-06-04 12:44:43 Re: It's June 1; do you know where your release is?