From: Noah Goldstein <goldstein.w.n@gmail.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: GNU C Library <libc-alpha@sourceware.org>,
"Carlos O'Donell" <carlos@systemhalted.org>
Subject: Re: [PATCH v1] x86: Add EVEX optimized memchr family not safe for RTM
Date: Wed, 5 May 2021 14:18:51 -0400 [thread overview]
Message-ID: <CAFUsyfLyja8JSEtw-McVQGATPx-gojiwTyGV0W8Qc+4MGJOigw@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOq1+k27Pxhg3eGeoU93sawm1-0bA7weu=bSj-vtas5yfg@mail.gmail.com>
On Wed, May 5, 2021 at 1:55 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Wed, May 5, 2021 at 9:25 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> >
> > On Wed, May 5, 2021 at 9:23 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > On Tue, May 4, 2021 at 4:34 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > > >
> > > > No bug.
> > > >
> > > > This commit adds a new implementation for EVEX memchr that is not safe
> > > > for RTM because it uses vzeroupper. The benefit is that by using
> > >
> > > EVEX memchr won't cause RTM abort if YMM16-YMM31 are used
> > > since there is no need to use vzeroupper. Please remove vzeroupper from
> > > EVEX memchr and remove EVEX RTM functions.
> >
> > That's impossible for this implementation.
> >
> > The reason ymm0-ymm15 are used is so that we can use vpcmpeq which is
> > not encodable with ymm16-ymm31.
> >
> > This implementation is optimized for CPUs which dont support RTM but
> > do support EVEX.
> >
>
> Are you seeing something along the line of Prefer_AVX2_STRCMP:
Yes.
For atleast some functions I think EVEX + AVX2 is probably the ideal
implementation unless you have to worry about RTM. And as of right now
there are a fair amount of x86_64 chips out there w/ avx512 but w/o
RTM (or intel might fix the issue where vzeroupper aborts transactions
in the future)
For small values even if EVEX costs an extra instruction (i.e strchr
vpxor + vpmin + vpcmp can be replace with vpcmpeq + vpcmp) the
overhead of vzeroupper make EVEX perform better. But once the main
loop is hit the overhead of vzeroupper isn't really a concern and
vpcmpeq isnt really replaceable with vpcmp from a logic perspective
(i.e 3x vpcmpeq + vptern isnt doable with vpcmp) and vpcmp is slower
for tput and latency. As a little tackon the EVEX instructions are all
larger code footprint than AVX2 so keeping instruction length <= 6byte
for the DSB isnt really doable.
I havent taken that long of a look at strcmp but would guess it would
benefit in a simliar way as memchr from EVEX for sizes [0..160] then
AVX2 for the loop (possibly augmented with vptern for 3way reduction)
>
> commit 1da50d4bda07f04135dca39f40e79fc9eabed1f8
> Author: H.J. Lu <hjl.tools@gmail.com>
> Date: Fri Feb 26 05:36:59 2021 -0800
>
> x86: Set Prefer_No_VZEROUPPER and add Prefer_AVX2_STRCMP
>
> 1. Set Prefer_No_VZEROUPPER if RTM is usable to avoid RTM abort triggered
> by VZEROUPPER inside a transactionally executing RTM region.
> 2. Since to compare 2 32-byte strings, 256-bit EVEX strcmp requires 2
> loads, 3 VPCMPs and 2 KORDs while AVX2 strcmp requires 1 load, 2 VPCMPEQs,
> 1 VPMINU and 1 VPMOVMSKB, AVX2 strcmp is faster than EVEX strcmp. Add
> Prefer_AVX2_STRCMP to prefer AVX2 strcmp family functions.
>
>
> --
> H.J.
next prev parent reply other threads:[~2021-05-05 18:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-04 23:32 Noah Goldstein
2021-05-05 13:22 ` H.J. Lu
2021-05-05 16:24 ` Noah Goldstein
2021-05-05 17:54 ` H.J. Lu
2021-05-05 18:18 ` Noah Goldstein [this message]
2021-05-05 18:29 ` H.J. Lu
2021-05-05 18:38 ` Noah Goldstein
2021-05-05 18:44 ` Noah Goldstein
2021-05-06 13:38 ` H.J. Lu
2021-05-06 18:14 ` Noah Goldstein
2021-05-06 19:06 ` H.J. Lu
2021-05-06 13:55 ` H.J. Lu
2021-05-06 18:01 ` Noah Goldstein
2021-05-06 19:09 ` H.J. Lu
2021-05-06 23:55 ` [PATCH v2] " Noah Goldstein
2021-05-07 13:22 ` H.J. Lu
2021-05-07 18:17 ` [PATCH v3] " Noah Goldstein
2021-05-07 18:24 ` H.J. Lu
2021-05-08 4:06 ` [PATCH v4] " Noah Goldstein
2021-05-08 12:58 ` H.J. Lu
2022-04-27 23:57 ` Sunil Pandey
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=CAFUsyfLyja8JSEtw-McVQGATPx-gojiwTyGV0W8Qc+4MGJOigw@mail.gmail.com \
--to=goldstein.w.n@gmail.com \
--cc=carlos@systemhalted.org \
--cc=hjl.tools@gmail.com \
--cc=libc-alpha@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).