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

From Tom Lane
Subject Re: [PATCH v4] Avoid manual shift-and-test logic in AllocSetFreeIndex
Date
Msg-id 26046.1248118662@sss.pgh.pa.us
Whole thread Raw
In response to Re: [PATCH v4] Avoid manual shift-and-test logic in AllocSetFreeIndex  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [PATCH v4] Avoid manual shift-and-test logic in AllocSetFreeIndex  (Greg Stark <gsstark@mit.edu>)
List pgsql-hackers
I wrote:
> I'm still interested in the idea of doing a manual unroll instead of
> relying on a compiler-specific feature.  However, some quick testing
> didn't find an unrolling that helps much.

Hmm, actually this seems to work ok:
       idx++;       size >>= 1;       if (size != 0)       {           idx++;           size >>= 1;           if (size
!=0)           {               idx++;               size >>= 1;               if (size != 0)               {
      idx++;                   size >>= 1;                   while (size != 0)                   {
idx++;                       size >>= 1;                   }               }           }       }
 

(this is with the initial "if (size > (1 << ALLOC_MINBITS))" so that
we know the starting value is nonzero)

This seems to be about a wash or a small gain on x86_64, but on my
PPC Mac laptop it's very nearly identical in speed to the __builtin_clz
code.  I also see a speedup on HPPA, for which my gcc is too old to
know about __builtin_clz.

Anyone want to see if they can beat that?  Some testing on other
architectures would help too.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Ron Mayer
Date:
Subject: Re: [PATCH] SE-PgSQL/tiny rev.2193
Next
From: Joshua Brindle
Date:
Subject: Re: [PATCH] SE-PgSQL/tiny rev.2193