Re: [RFC PATCH v1 2/5] tools/nolibc: x86-64: Use `rep stosb` for `memset()`

From: Alviro Iskandar Setiawan
Date: Wed Aug 30 2023 - 14:57:35 EST


On Wed, Aug 30, 2023 at 8:57 PM Ammar Faizi wrote:
> +".section .text.nolibc_memset\n"
> +".weak memset\n"
> +"memset:\n"
> + "movq %rsi, %rax\n"
> + "movq %rdx, %rcx\n"
> + "movq %rdi, %rdx\n"
> + "rep stosb\n"
> + "movq %rdx, %rax\n"
> + "retq\n"

The first instruction could be:

movl %esi, %eax

That's smaller. Also, the second argument of memset() is an int
anyway, so there is no need to have a full 64-bit copy of %rsi in
%rax.

-- Viro