lkml.org 
[lkml]   [2018]   [Dec]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 01/12] x86_64: memset_user()
On Fri, Dec 21, 2018 at 11:05:46PM +0300, Cyrill Gorcunov wrote:
> On Fri, Dec 21, 2018 at 10:25:16AM -0800, Matthew Wilcox wrote:
> > On Fri, Dec 21, 2018 at 08:14:12PM +0200, Igor Stoppa wrote:
> > > +unsigned long __memset_user(void __user *addr, int c, unsigned long size)
> > > +{
> > > + long __d0;
> > > + unsigned long pattern = 0;
> > > + int i;
> > > +
> > > + for (i = 0; i < 8; i++)
> > > + pattern = (pattern << 8) | (0xFF & c);
> >
> > That's inefficient.
> >
> > pattern = (unsigned char)c;
> > pattern |= pattern << 8;
> > pattern |= pattern << 16;
> > pattern |= pattern << 32;
>
> Won't
>
> pattern = 0x0101010101010101 * c;
>
> do the same but faster?

Depends on your CPU. Some yes, some no.

(Also you need to cast 'c' to unsigned char to avoid someone passing in
0x1234 and getting 0x4646464646464634 instead of 0x3434343434343434)

\
 
 \ /
  Last update: 2018-12-21 21:31    [W:0.034 / U:0.656 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site