From: Al Viro <viro@zeniv.linux.org.uk>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Eric Dumazet <edumazet@google.com>
Subject: Re: [PATCH] x86/uaccess: small optimization in unsafe_copy_to_user()
Date: Fri, 16 Apr 2021 19:44:06 +0000 [thread overview]
Message-ID: <YHnpBm36PcIINhWi@zeniv-ca.linux.org.uk> (raw)
In-Reply-To: <20210416192413.1514419-1-eric.dumazet@gmail.com>
On Fri, Apr 16, 2021 at 12:24:13PM -0700, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> We have to loop only to copy u64 values.
> After this first loop, we copy at most one u32, one u16 and one byte.
Does it actually yield a better code?
FWIW, this
void bar(unsigned);
void foo(unsigned n)
{
while (n >= 8) {
bar(n);
n -= 8;
}
while (n >= 4) {
bar(n);
n -= 4;
}
while (n >= 2) {
bar(n);
n -= 2;
}
while (n >= 1) {
bar(n);
n -= 1;
}
}
will compile (with -O2) to
pushq %rbp
pushq %rbx
movl %edi, %ebx
subq $8, %rsp
cmpl $7, %edi
jbe .L2
movl %edi, %ebp
.L3:
movl %ebp, %edi
subl $8, %ebp
call bar@PLT
cmpl $7, %ebp
ja .L3
andl $7, %ebx
.L2:
cmpl $3, %ebx
jbe .L4
movl %ebx, %edi
andl $3, %ebx
call bar@PLT
.L4:
cmpl $1, %ebx
jbe .L5
movl %ebx, %edi
andl $1, %ebx
call bar@PLT
.L5:
testl %ebx, %ebx
je .L1
addq $8, %rsp
movl $1, %edi
popq %rbx
popq %rbp
jmp bar@PLT
.L1:
addq $8, %rsp
popq %rbx
popq %rbp
ret
i.e. loop + if + if + if...
next prev parent reply other threads:[~2021-04-16 19:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-16 19:24 [PATCH] x86/uaccess: small optimization in unsafe_copy_to_user() Eric Dumazet
2021-04-16 19:44 ` Al Viro [this message]
2021-04-16 20:11 ` Eric Dumazet
2021-04-16 20:57 ` Eric Dumazet
2021-04-17 13:59 ` David Laight
2021-04-17 16:03 ` Linus Torvalds
2021-04-17 16:08 ` Linus Torvalds
2021-04-17 16:27 ` Linus Torvalds
2021-04-17 18:09 ` Al Viro
2021-04-17 20:30 ` Al Viro
2021-04-17 20:35 ` Al Viro
2021-04-17 22:11 ` Linus Torvalds
2021-04-18 0:50 ` Al Viro
2021-04-17 19:44 ` Eric Dumazet
2021-04-17 19:51 ` Linus Torvalds
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=YHnpBm36PcIINhWi@zeniv-ca.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.