pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
To: John Naylor <johncnaylorls@gmail.com>
Cc: Devulapalli, Raghuveer <raghuveer.devulapalli@intel.com>
Cc: pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
Cc: Shankaran, Akash <akash.shankaran@intel.com>
Subject: Re: Improve CRC32C performance on SSE4.2
Date: Mon, 3 Mar 2025 13:11:15 -0600
Message-ID: <Z8X-0wg7wXztjMQ2@nathan> (raw)
In-Reply-To: <CANWCAZZEiTzhZcuwTiJ2=opiNpAUn1vuDRu1N02z61AthwRZLA@mail.gmail.com>
References: <PH8PR11MB82864AAC1EE7D3F7D4564858FBC42@PH8PR11MB8286.namprd11.prod.outlook.com>
	<CANWCAZY0EYXae33Zv5A4fnrd=D3F5DExv=9m51X2H1wAYfG=6g@mail.gmail.com>
	<PH8PR11MB828602D3AE9A19531E42A2DBFBC02@PH8PR11MB8286.namprd11.prod.outlook.com>
	<CANWCAZapv-=PcDBEd43AEiYZApweANpS=stOcSvaPowo6Ff1yw@mail.gmail.com>
	<PH8PR11MB82867CEDDECB60530DB96BD1FBC22@PH8PR11MB8286.namprd11.prod.outlook.com>
	<CANWCAZbG_pPFuLRaczYApBykaHCXQ-STAXO1=J6_4TRvy23Byg@mail.gmail.com>
	<PH8PR11MB8286B017901C2C30665B106CFBC22@PH8PR11MB8286.namprd11.prod.outlook.com>
	<CANWCAZZjuH8daxK-tcnYbK_sAQdq8R6d3T3iGfL43Dj6DkFv0g@mail.gmail.com>
	<PH8PR11MB82862B464609340FB0A4BA37FBCD2@PH8PR11MB8286.namprd11.prod.outlook.com>
	<CANWCAZZEiTzhZcuwTiJ2=opiNpAUn1vuDRu1N02z61AthwRZLA@mail.gmail.com>

On Fri, Feb 28, 2025 at 07:11:29PM +0700, John Naylor wrote:
> 0002: For SSE4.2 builds, arrange so that constant input uses an
> inlined path so that the compiler can emit unrolled loops anywhere.
> This is particularly important for the WAL insertion lock, so this is
> possibly committable on its own just for that.

Nice.

> 0004: the PCLMUL path for SSE4.2 builds. This uses a function pointer
> for long-ish input and the same above inlined path for short input
> (whether constant or not). So it gets the best of both worlds.

I spent some time staring at pg_crc32.h with all these patches applied, and
IIUC it leads to the following behavior:

* For compiled-in SSE 4.2 builds, we branch based on the length.  For
  smaller inputs, we are using an inlined version of the SSE 4.2 code.
  For larger inputs, we call a function pointer so that we can potentially
  use the PCLMUL version.  This could potentially lead to a small
  regression for machines with SSE 4.2 but not PCLMUL, but that may be
  uncommon enough at this point to not worry aobut.

* For runtime-check SSE 4.2 builds, we choose slicing-by-8, SSE 4.2, or
  SSE 4.2 with PCLMUL, and we always use a function pointer.

The main question I have is whether we can simplify this by always using a
runtime check and by inlining slicing-by-8 for small inputs.  That would be
dependent on the performance of slicing-by-8 and SSE 4.2 being comparable
for small inputs.

Overall, I wish we could avoid splitting things into separate files and
adding more header file gymnastics, but maybe there isn't much better we
can do without overhauling the CPU feature detection code.

-- 
nathan





view thread (82+ messages)  latest in thread

Message-ID: <Z8X-0wg7wXztjMQ2@nathan>
Permalink:  ../Z8X-0wg7wXztjMQ2@nathan/
Also on:    postgresql.org/message-id/Z8X-0wg7wXztjMQ2@nathan

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: nathandbossart@gmail.com, johncnaylorls@gmail.com, raghuveer.devulapalli@intel.com, akash.shankaran@intel.com
  Subject: Re: Improve CRC32C performance on SSE4.2
  In-Reply-To: <Z8X-0wg7wXztjMQ2@nathan>
  References: <PH8PR11MB82864AAC1EE7D3F7D4564858FBC42@PH8PR11MB8286.namprd11.prod.outlook.com> <CANWCAZY0EYXae33Zv5A4fnrd=D3F5DExv=9m51X2H1wAYfG=6g@mail.gmail.com> <PH8PR11MB828602D3AE9A19531E42A2DBFBC02@PH8PR11MB8286.namprd11.prod.outlook.com> <CANWCAZapv-=PcDBEd43AEiYZApweANpS=stOcSvaPowo6Ff1yw@mail.gmail.com> <PH8PR11MB82867CEDDECB60530DB96BD1FBC22@PH8PR11MB8286.namprd11.prod.outlook.com> <CANWCAZbG_pPFuLRaczYApBykaHCXQ-STAXO1=J6_4TRvy23Byg@mail.gmail.com> <PH8PR11MB8286B017901C2C30665B106CFBC22@PH8PR11MB8286.namprd11.prod.outlook.com> <CANWCAZZjuH8daxK-tcnYbK_sAQdq8R6d3T3iGfL43Dj6DkFv0g@mail.gmail.com> <PH8PR11MB82862B464609340FB0A4BA37FBCD2@PH8PR11MB8286.namprd11.prod.outlook.com> <CANWCAZZEiTzhZcuwTiJ2=opiNpAUn1vuDRu1N02z61AthwRZLA@mail.gmail.com> <Z8X-0wg7wXztjMQ2@nathan>

* 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