I am sure I am doing something wrong and GCC 10.2.0 compiles it into something unexpected:
Code: Select all
void* memset(void* ptr, int value, size_t num)
{
for (unsigned char* p = ptr; num; --num)
{
*p++ = (unsigned char)value;
}
return ptr;
}
Code: Select all
ffffffff80006360 <memset>:
ffffffff80006360: 48 85 d2 test %rdx,%rdx
ffffffff80006363: 74 13 je ffffffff80006378 <memset+0x18>
ffffffff80006365: 55 push %rbp
ffffffff80006366: 40 0f b6 f6 movzbl %sil,%esi
ffffffff8000636a: 48 89 e5 mov %rsp,%rbp
ffffffff8000636d: e8 ee ff ff ff callq ffffffff80006360 <memset>
ffffffff80006372: 5d pop %rbp
ffffffff80006373: c3 retq
ffffffff80006374: 0f 1f 40 00 nopl 0x0(%rax)
ffffffff80006378: 48 89 f8 mov %rdi,%rax
ffffffff8000637b: c3 retq
ffffffff8000637c: 0f 1f 40 00 nopl 0x0(%rax)
Please help if you can. I refuse to believe the problem is with GCC, I must be missing something.