Re: use CLZ instruction in AllocSetFreeIndex() - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: use CLZ instruction in AllocSetFreeIndex()
Date
Msg-id 20191227132150.GA22238@alvherre.pgsql
Whole thread Raw
In response to use CLZ instruction in AllocSetFreeIndex()  (John Naylor <john.naylor@2ndquadrant.com>)
Responses Re: use CLZ instruction in AllocSetFreeIndex()  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On 2019-Dec-26, John Naylor wrote:

> In commit ab5b4e2f9ed, we optimized AllocSetFreeIndex() using a lookup
> table. At the time, using CLZ was rejected because compiler/platform
> support was not widespread enough to justify it. For other reasons, we
> recently added bitutils.h which uses __builtin_clz() where available,
> so it makes sense to revisit this. I modified the test in [1] (C files
> attached), using two separate functions to test CLZ versus the
> open-coded algorithm of pg_leftmost_one_pos32().
> 
> These are typical results on a recent Intel platform:
> 
> HEAD        5.55s
> clz         4.51s
> open-coded  9.67s

I can confirm these results on my Intel laptop.  I ran it with a
repetition of 20, averages of 4 runs:

clz        1,614
bitutils    3,714
current        2,088
(stddevs are under 0,031).


-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Libpq support to connect to standby server as priority
Next
From: Tom Lane
Date:
Subject: Re: use CLZ instruction in AllocSetFreeIndex()