From: Nathan Bossart <nathandbossart@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Ants Aasma <ants.aasma@cybertec.at>
Cc: Amonson, Paul D <paul.d.amonson@intel.com>
Cc: David Rowley <dgrowleyml@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Shankaran, Akash <akash.shankaran@intel.com>
Cc: Noah Misch <noah@leadboat.com>
Cc: Matthias van de Meent <boekewurm+postgres@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
Subject: Re: Popcount optimization using AVX512
Date: Tue, 2 Apr 2024 13:40:21 -0500
Message-ID: <20240402184021.GA2802541@nathanxps13> (raw)
In-Reply-To: <1666732.1712079828@sss.pgh.pa.us>
References: <202404021734.635tuluozzn3@alvherre.pgsql>
<1666732.1712079828@sss.pgh.pa.us>
On Tue, Apr 02, 2024 at 01:43:48PM -0400, Tom Lane wrote:
> Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
>> On 2024-Apr-02, Nathan Bossart wrote:
>>> Another idea I had is to turn pg_popcount() into a macro that just uses the
>>> pg_number_of_ones array when called for few bytes:
>>>
>>> static inline uint64
>>> pg_popcount_inline(const char *buf, int bytes)
>>> {
>>> uint64 popcnt = 0;
>>>
>>> while (bytes--)
>>> popcnt += pg_number_of_ones[(unsigned char) *buf++];
>>>
>>> return popcnt;
>>> }
>>>
>>> #define pg_popcount(buf, bytes) \
>>> ((bytes < 64) ? \
>>> pg_popcount_inline(buf, bytes) : \
>>> pg_popcount_optimized(buf, bytes))
>>>
>>> But again, I'm not sure this is really worth it for the current use-cases.
>
>> Eh, that seems simple enough, and then you can forget about that case.
>
> I don't like the double evaluation of the macro argument. Seems like
> you could get the same results more safely with
>
> static inline uint64
> pg_popcount(const char *buf, int bytes)
> {
> if (bytes < 64)
> {
> uint64 popcnt = 0;
>
> while (bytes--)
> popcnt += pg_number_of_ones[(unsigned char) *buf++];
>
> return popcnt;
> }
> return pg_popcount_optimized(buf, bytes);
> }
Yeah, I like that better. I'll do some testing to see what the threshold
really should be before posting an actual patch.
--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: nathandbossart@gmail.com, tgl@sss.pgh.pa.us, alvherre@alvh.no-ip.org, ants.aasma@cybertec.at, paul.d.amonson@intel.com, dgrowleyml@gmail.com, andres@anarazel.de, akash.shankaran@intel.com, noah@leadboat.com, boekewurm+postgres@gmail.com, pgsql-hackers@lists.postgresql.org
Subject: Re: Popcount optimization using AVX512
In-Reply-To: <20240402184021.GA2802541@nathanxps13>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox