Re: always use runtime checks for CRC-32C instructions

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org, Xiang(dot)Gao(at)arm(dot)com
Subject: Re: always use runtime checks for CRC-32C instructions
Date: 2023-10-31 19:53:31
Message-ID: 20231031195331.GA77436@nathanxps13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Oct 31, 2023 at 03:16:16PM -0400, Tom Lane wrote:
> Really this just reinforces my concern that doing a runtime check
> all the time is on the wrong side of history. I grant that we've
> got to do that for anything where the availability of the instruction
> is really in serious question, but I'm not very convinced that that's
> a majority situation on popular platforms.

Okay. With that in mind, I think the path forward for new instructions is
as follows:

* If the special CRC instructions can be used with the default compiler
flags, we can only use newer instructions if they can also be used with
the default compiler flags. (My M2 machine appears to add +crypto by
default, so I bet your buildfarm animals would fall into this bucket.)
* Otherwise, if the CRC instructions can be used with added flags (i.e.,
the runtime check path), we can do a runtime check for the new
instructions as well. (Most other buildfarm animals would fall into this
bucket.)

Any platform that can use the CRC instructions with default compiler flags
but not the new instructions wouldn't be able to take advantage of the
proposed optimization, but it also wouldn't be subject to the small
performance regression.

If we wanted to further eliminate runtime checks for SSE 4.2 and ARMv8,
then I think things become a little trickier, as having a compiler that
understands things like +crypto would mean that you're automatically
subject to the runtime check regression (assuming we proceed with the
proposed optimization). An alternate approach could be to only use newer
instructions if they are available with the default compiler flags, but
given the current state of the buildfarm, such optimizations might not get
much uptake for a while.

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2023-10-31 19:57:43 Re: always use runtime checks for CRC-32C instructions
Previous Message Tom Lane 2023-10-31 19:42:33 Re: always use runtime checks for CRC-32C instructions