Re: [RFC PATCH v1 2/5] tools/nolibc: x86-64: Use `rep stosb` for `memset()`
From: Alviro Iskandar Setiawan
Date: Wed Aug 30 2023 - 15:16:47 EST
On Wed, Aug 30, 2023 at 8:57 PM Ammar Faizi wrote:
> 00000000000010b1 <memset>:
> 10b1: 48 89 f0 mov %rsi,%rax
> 10b4: 48 89 d1 mov %rdx,%rcx
> 10b7: 48 89 fa mov %rdi,%rdx
> 10ba: f3 aa rep stos %al,%es:(%rdi)
> 10bc: 48 89 d0 mov %rdx,%rax
> 10bf: c3 ret
Just a small idea to shrink this more, "mov %rdi, %rdx" and "mov %rdx,
%rax" can be replaced with "push %rdi" and "pop %rax" (they are just a
byte). So we can save 4 bytes more.
0000000000001500 <memset>:
1500: 48 89 f0 mov %rsi,%rax
1503: 48 89 d1 mov %rdx,%rcx
1506: 57 push %rdi
1507: f3 aa rep stos %al,%es:(%rdi)
1509: 58 pop %rax
150a: c3 ret
But I know you don't like it because it costs extra memory access.
-- Viro