Re: [RFC PATCH v1 0/5] nolibc x86-64 string functions

From: Ammar Faizi
Date: Fri Sep 01 2023 - 09:06:37 EST


On Fri, Sep 01, 2023 at 01:46:44PM +0200, Willy Tarreau wrote:
> On Fri, Sep 01, 2023 at 11:34:18AM +0000, David Laight wrote:
> > Isn't that completely broken?
> >
> > You need to select between forwards and backwards moves.
> > Since forwards moves are preferred it is best to do
> > if (dst - src < len)
> > backards_copy()
> > else
> > formwards_copy()
> >
> > David
>
> You're completely right indeed, reminds me about the copy_up/copy_down
> that were not used anymore :-)

I'm an idiot, will fix that. Another attempt as suggested below:

__asm__ (
".section .text.nolibc_memmove\n"
".weak memmove\n"
"memmove:\n"
" movq %rdx, %rcx\n"
" movq %rdi, %rdx\n"
" movq %rdi, %rax\n"
" subq %rsi, %rdx\n"
" cmpq %rcx, %rdx\n"
" jnb .Lforward_copy\n"
" leaq -1(%rdi, %rcx, 1), %rdi\n"
" leaq -1(%rsi, %rcx, 1), %rsi\n"
" std\n"
".Lforward_copy:\n"
" rep movsb\n"
" cld\n"
" ret\n"
);

--
Ammar Faizi