svn commit: r333324 - in head/sys: amd64/amd64 conf

Mateusz Guzik mjguzik at gmail.com
Mon May 7 20:57:15 UTC 2018


On Mon, May 7, 2018 at 9:03 PM, Oliver Pinter <oliver.pinter at hardenedbsd.org
> wrote:

> On 5/7/18, Mateusz Guzik <mjg at freebsd.org> wrote:
> > Author: mjg
> > Date: Mon May  7 15:07:28 2018
> > New Revision: 333324
> > URL: https://svnweb.freebsd.org/changeset/base/333324
> >
> > Log:
> >   amd64: replace libkern's memset and memmove with assembly variants
> >
> >   memmove is repurposed bcopy (arguments swapped, return value added)
> >   The libkern variant is a wrapper around bcopy, so this is a big
> >   improvement.
> >
> >   memset is repurposed memcpy. The librkern variant is doing fishy stuff,
> >   including branching on 0 and calling bzero.
> >
> >   Both functions are rather crude and subject to partial depessimization.
> >
> >   This is a soft prerequisite to adding variants utilizing the
> >   'Enhanced REP MOVSB/STOSB' bit and let the kernel patch at runtime.
> >
> > +
> > +/*
> > + * memset(dst, c,   len)
> > + *        rdi, rsi, rdx
> > + */
> > +ENTRY(memset)
> > +     PUSH_FRAME_POINTER
> > +     movq    %rdi,%r9
> > +     movq    %rdx,%rcx
> > +     movq    %rsi,%rax
> > +     shrq    $3,%rcx
> > +     rep
> > +     stosq
>
> According to Intel SDM stosq stores the whole RAX into destination,
> and then increments the destination register with 8. This
> implementation is wrong, since the c is a char, and the The RAX looks
> like 000000CC, so the stored patter would be 000000CC * SIZE / 8 * 8 +
> CC * SIZE % 8 in destination buffer.
>

Ye, my bad. Forgot to expand the arg with the multiplication trick. Fixed:
https://svnweb.freebsd.org/base?view=revision&revision=333332

-- 
Mateusz Guzik <mjguzik gmail.com>


More information about the svn-src-all mailing list