Re: use CLZ instruction in AllocSetFreeIndex()

From: David Fetter <david(at)fetter(dot)org>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, John Naylor <john(dot)naylor(at)2ndquadrant(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: use CLZ instruction in AllocSetFreeIndex()
Date: 2019-12-27 16:37:28
Message-ID: 20191227163727.GJ32763@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Dec 27, 2019 at 01:29:47PM -0300, Alvaro Herrera wrote:
> On 2019-Dec-27, Tom Lane wrote:
>
> > This kind of leads me to wonder if we don't need to expend more
> > effort on the non-CLZ version of pg_leftmost_one_pos32; it seems
> > like it shouldn't be losing this badly to the only-slightly-
> > improved logic that's currently in AllocSetFreeIndex. On the
> > other hand, the buildfarm thinks that __builtin_clz is essentially
> > universal these days --- the only active non-MSVC critter that
> > reports not having it is anole. So maybe it's not worth sweating
> > over that. Perhaps what we really ought to be working on is
> > finding MSVC equivalents for __builtin_clz and friends.
>
> Apparently clz() can be written using _BitScanReverse(), per
> https://stackoverflow.com/a/20468180
> https://docs.microsoft.com/en-us/cpp/intrinsics/bitscanreverse-bitscanreverse64?view=vs-2015

There's also various flavors of lczntN for N in (16,32,64) on
(relatively) modern architectures.

https://docs.microsoft.com/en-us/cpp/intrinsics/lzcnt16-lzcnt-lzcnt64?redirectedfrom=MSDN&view=vs-2019

Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-12-27 16:43:18 Re: use CLZ instruction in AllocSetFreeIndex()
Previous Message Alvaro Herrera 2019-12-27 16:29:47 Re: use CLZ instruction in AllocSetFreeIndex()