From: Eric Biggers <ebiggers@kernel.org>
To: David Laight <david.laight.linux@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
linux-crypto@vger.kernel.org, x86@kernel.org,
linux-raid@vger.kernel.org
Subject: Re: [PATCH v2] lib/raid/xor: x86: Add AVX-512 optimized xor_gen()
Date: Mon, 15 Jun 2026 11:44:35 -0700 [thread overview]
Message-ID: <20260615184435.GA17731@quark> (raw)
In-Reply-To: <20260614111628.00af46b9@pumpkin>
On Sun, Jun 14, 2026 at 11:16:28AM +0100, David Laight wrote:
> On Sat, 13 Jun 2026 18:03:57 -0700
> Eric Biggers <ebiggers@kernel.org> wrote:
>
> > Add an implementation of xor_gen() using AVX-512.
> >
> > It uses 512-bit vectors, i.e. ZMM registers. It also uses the
> > vpternlogq instruction to do three-input XORs when applicable.
> >
> > It's enabled on x86_64 CPUs that have AVX512F && !PREFER_YMM. In
> > practice that means:
> >
> > - AMD Zen 4 and later (client and server)
>
> Doesn't zen4 only have a 256bit bus between the cpu and cache?
> So avx512 reads take two clocks.
> Since this is memory limited it is unlikely to run faster than the
> avx256 version.
On AMD Genoa (Zen 4 server processor), the AVX-512 code added by this
patch is indeed about the same speed as the existing AVX-2 code.
> OTOH if it doesn't cause down-clocking as well then it won't be slower.
Yes, as far as I know that's not an issue on AMD processors, even Zen 4.
The "avoid AVX-512 due to downclocking" rule is historical guidance for
Intel processors that had a bad implementation of AVX-512. There's no
reason to exclude Zen 4 from executing AVX-512 optimized code. At worst
it will just be the same, as we're seeing here.
> Since I suggested it :-)
>
> Reviewed-By: David Laight <david.laight.linux@gmail.com>
>
> Some 'not very important' comments:
>
> I did wonder whether moving the loop into the asm() would help.
> gcc has a nasty habit of pessimising loops when you try to be clever.
> It is certainly safer for tight loops like these.
I originally tried leaving the loops to the compiler, but gcc unrolled
the 1x ones by 2x, despite it having no visibility into the asm block.
That broke the intent with the indexed addressing, since to achieve the
unrolling it generated code that incremented the pointers.
So I just ended up moving the loop to the asm, which reliably gives us
the code we want.
> That does have the side effect of making p0 be %1 which doesn't improve
> readability. Either used named parameters or possibly just change p0 to p1 (etc)
> so they match.
>
> The code should be limited by the memory reads, so the 3-argument xor and
> the interleave of the unroll may make no difference.
The unroll by 2x in the 2 and 3-buffer cases helped a little bit on
Sapphire Rapids. I don't know exactly why, but it makes sense that
those cases are where the loop overhead is most likely to matter.
> Some cpu do have constraints on the cache alignment in order to do two
> reads per clock, but I've forgotten them and they got better before AVX-512.
> If that were affecting this code (on the tested cpu) then I'd expect the
> interleaved unroll would improve the _4 and -5 functions.
> So it probably doesn't affect this code.
The buffers are always 64-byte aligned here, as documented.
> Using the same loop for the avx-256 and sse (and even smaller) functions could
> well generate code that runs 'pretty much as fast as possible' on older cpu.
> Intel cpu (going back to Sandy bridge) are likely to execute the loop in the
> same number of clocks - but clearly copying half or a quarter of the data.
> But I've no experience of zen1.
>
> Might be worth doing for avx-256, does any care about anything older :-)
Yes, the existing AVX code is probably excessively unrolled. It
generates almost 4 KiB of code.
- Eric
next prev parent reply other threads:[~2026-06-15 18:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-14 1:03 [PATCH v2] lib/raid/xor: x86: Add AVX-512 optimized xor_gen() Eric Biggers
2026-06-14 1:23 ` sashiko-bot
2026-06-14 10:16 ` David Laight
2026-06-15 18:44 ` Eric Biggers [this message]
2026-06-15 22:57 ` David Laight
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260615184435.GA17731@quark \
--to=ebiggers@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=david.laight.linux@gmail.com \
--cc=hch@lst.de \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox