netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Eric Dumazet <eric.dumazet@gmail.com>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, netdev <netdev@vger.kernel.org>,
	x86@kernel.org, Alexander Duyck <alexander.duyck@gmail.com>,
	amc96@srcf.net
Subject: Re: [RFC] x86/csum: rewrite csum_partial()
Date: Thu, 11 Nov 2021 11:02:48 -0800	[thread overview]
Message-ID: <CANn89iL9k8spkSGzty0g7C4FA1=pgtd-4zYranqvFywBFG6cZw@mail.gmail.com> (raw)
In-Reply-To: <2b36e547-f080-a1ee-f0f0-a9e5fe1e4693@citrix.com>

On Thu, Nov 11, 2021 at 10:18 AM Andrew Cooper
<andrew.cooper3@citrix.com> wrote:
>
> On 11/11/2021 16:52, Eric Dumazet wrote:
> > On Thu, Nov 11, 2021 at 8:02 AM Eric Dumazet <edumazet@google.com> wrote:
> >> Thanks Peter !
> >>
> >> This is more or less the first version I wrote. (I was doing tests for
> >> (len & 32), (len & 16) .. to not have to update len in these blocks.
> >>
> >> Then, I tried to add an inline version, a la ip_fast_csum() but for IPv6.
> >>
> >> Then I came up with the version I sent, for some reason my .config had
> >> temporarily disabled CONFIG_RETPOLINE,
> >> thanks for reminding me this !
> >>
> >> I also missed this warning anyway :
> >> arch/x86/lib/csum-partial_64.o: warning: objtool: csum_partial()+0x2f:
> >> unannotated intra-function call
> >>
> >> I will spend a bit more time on this before sending a V2, thanks again !
> > BTW, I could not understand why :
> >
> >                result = add32_with_carry(result, *(u32 *)buff);
> >
> > generates this code :
> >
> >  123: 41 8b 09              mov    (%r9),%ecx
> >  126: 89 4d f8              mov    %ecx,-0x8(%rbp)
> >  129: 03 45 f8              add    -0x8(%rbp),%eax
> >  12c: 83 d0 00              adc    $0x0,%eax
>
> Are you using Clang?  There is a long outstanding code generation bug
> where an "rm" constraint is converted to "m" internally.
>

Yes, this is what I realized later. This is a clang bug.

> https://bugs.llvm.org/show_bug.cgi?id=47530
>
> Even a stopgap of pretending "rm" means "r" would result in far better
> code, 99% of the time.

Agreed

>
> > Apparently add32_with_carry() forces the use of use of a temporary in memory
> >
> > While
> >                asm("   addl 0*4(%[src]),%[res]\n"
> >                    "   adcl $0,%[res]\n"
> >                        : [res] "=r" (result)
> >                        : [src] "r" (buff), "[res]" (result)
> >                         : "memory");
>
> Just as a minor note about the asm constraints here and elsewhere
>
>     : [res] "=r" (result)
>     : "res" (result)
>
> ought to be just [res] "+r" (result).  The result variable really is
> read and written by the asm fragments.

Thanks for the tip !

  reply	other threads:[~2021-11-11 19:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11  6:53 [RFC] x86/csum: rewrite csum_partial() Eric Dumazet
2021-11-11  9:10 ` Peter Zijlstra
2021-11-11  9:44   ` Peter Zijlstra
2021-11-11 16:02     ` Eric Dumazet
2021-11-11 16:52       ` Eric Dumazet
2021-11-11 18:17         ` Andrew Cooper
2021-11-11 19:02           ` Eric Dumazet [this message]
2021-11-11 16:51 ` Alexander Duyck
2021-11-14 13:07 ` David Laight
2021-11-14 14:12   ` David Laight
2021-11-15 10:23     ` 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='CANn89iL9k8spkSGzty0g7C4FA1=pgtd-4zYranqvFywBFG6cZw@mail.gmail.com' \
    --to=edumazet@google.com \
    --cc=alexander.duyck@gmail.com \
    --cc=amc96@srcf.net \
    --cc=andrew.cooper3@citrix.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).