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

From: Ammar Faizi
Date: Wed Aug 30 2023 - 15:16:43 EST


On Wed, Aug 30, 2023 at 05:23:22PM +0200, Willy Tarreau wrote:
> Then "xchg %esi, %eax" is just one byte with no memory access ;-)

Perfect!

Now I got this, shorter than "movl %esi, %eax":
```
0000000000001500 <memset>:
1500: 96 xchg %eax,%esi
1501: 48 89 d1 mov %rdx,%rcx
1504: 57 push %rdi
1505: f3 aa rep stos %al,%es:(%rdi)
1507: 58 pop %rax
1508: c3 ret
```

Unfortunately, the xchg trick doesn't yield smaller machine code for
%rdx, %rcx. Lol.

--
Ammar Faizi