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

From Jeremy Kerr
Subject Re: [RFC,PATCH] Avoid manual shift-and-test logic in AllocSetFreeIndex
Date
Msg-id 200906050918.25358.jk@ozlabs.org
Whole thread Raw
In response to Re: [RFC,PATCH] Avoid manual shift-and-test logic in AllocSetFreeIndex  (Atsushi Ogawa <a_ogawa@hi-ho.ne.jp>)
Responses [PATCH v2] Avoid manual shift-and-test logic in AllocSetFreeIndex  (Jeremy Kerr <jk@ozlabs.org>)
Re: [RFC,PATCH] Avoid manual shift-and-test logic in AllocSetFreeIndex  (Atsushi Ogawa <a_ogawa@hi-ho.ne.jp>)
List pgsql-hackers
Hi Atsushi,

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

Yep, got caught out by this because my previous fls() supported zero.

> 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);
>      }

Looks good, I'll send an updated patch.

Also, are you still seeing the same improvement with the __builtin_clz 
as your inline asm implementation?

Cheers,


Jeremy


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: User-facing aspects of serializable transactions
Next
From: "David E. Wheeler"
Date:
Subject: Re: It's June 1; do you know where your release is?