[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAOG64qNw+ZovcC4+5Sqsvi-m=wyoe47eb5K4KAdbO5hcp8ipAA@mail.gmail.com>
Date: Sat, 2 Sep 2023 13:07:50 +0700
From: Alviro Iskandar Setiawan <alviro.iskandar@...weeb.org>
To: Ammar Faizi <ammarfaizi2@...weeb.org>
Cc: Willy Tarreau <w@....eu>,
Thomas Weißschuh <linux@...ssschuh.net>,
David Laight <David.Laight@...lab.com>,
Nicholas Rosenberg <inori@...x.org>,
Michael William Jonathan <moe@...weeb.org>,
"GNU/Weeb Mailing List" <gwml@...r.gnuweeb.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [RFC PATCH v2 1/4] tools/nolibc: x86-64: Use `rep movsb` for
`memcpy()` and `memmove()`
On Sat, Sep 2, 2023 at 12:51 PM Ammar Faizi wrote:
> +__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"
> + "rep movsb\n"
> + "cld\n"
> + "retq\n"
> +".Lforward_copy:\n"
> + "rep movsb\n"
> + "retq\n"
> +
> +".section .text.nolibc_memcpy\n"
> +".weak memcpy\n"
> +"memcpy:\n"
> + "movq %rdi, %rax\n"
> + "movq %rdx, %rcx\n"
> + "rep movsb\n"
> + "retq\n"
> +);
Btw, sir, this can be simplified more by merging the forward copy
path, only using two "rep movsb" for both memmove() and memcpy()
should be enough?
```
__asm__ (
".section .text.nolibc_memmove_memcpy\n"
".weak memmove\n"
".weak memcpy\n"
"memmove:\n"
"movq %rdx, %rcx\n"
"movq %rdi, %rdx\n"
"movq %rdi, %rax\n"
"subq %rsi, %rdx\n"
"cmpq %rcx, %rdx\n"
"jnb __nolibc_forward_copy\n"
"leaq -1(%rdi, %rcx, 1), %rdi\n"
"leaq -1(%rsi, %rcx, 1), %rsi\n"
"std\n"
"rep movsb\n"
"cld\n"
"retq\n"
"memcpy:\n"
"movq %rdi, %rax\n"
"movq %rdx, %rcx\n"
"__nolibc_forward_copy:\n"
"rep movsb\n"
"retq\n"
);
```
Thought?
-- Viro
Powered by blists - more mailing lists