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

From: Jeremy Kerr <jk(at)ozlabs(dot)org>
To: Atsushi Ogawa <a_ogawa(at)hi-ho(dot)ne(dot)jp>
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 23:18:24
Message-ID: 200906050918.25358.jk@ozlabs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David E. Wheeler 2009-06-04 23:25:40 Re: It's June 1; do you know where your release is?
Previous Message Bruce Momjian 2009-06-04 23:10:32 Re: User-facing aspects of serializable transactions