[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ff0feb86ea63487f96f14fc9f8f9222f@AcuMS.aculab.com>
Date: Sat, 17 Apr 2021 13:59:32 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Al Viro' <viro@...iv.linux.org.uk>,
Eric Dumazet <eric.dumazet@...il.com>
CC: Thomas Gleixner <tglx@...utronix.de>,
Linus Torvalds <torvalds@...ux-foundation.org>,
linux-kernel <linux-kernel@...r.kernel.org>,
Eric Dumazet <edumazet@...gle.com>
Subject: RE: [PATCH] x86/uaccess: small optimization in unsafe_copy_to_user()
From: Al Viro <viro@....linux.org.uk> On Behalf Of Al Viro
> Sent: 16 April 2021 20:44
> On Fri, Apr 16, 2021 at 12:24:13PM -0700, Eric Dumazet wrote:
> > From: Eric Dumazet <edumazet@...gle.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;
> }
> }
This variant might be better:
void foo(unsigned n)
{
while (n >= 8) {
bar(8);
n -= 8;
}
if (likely(!n))
return;
if (n & 4)
bar(4);
if (n & 2)
bar(2);
if (n & 1)
bar(1);
}
I think Al's version might have optimised down to this,
but Eric's asm contains the n -= 4/2/1;
OTOH gcc can make a real pig's breakfast of code like this!
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists