Hi this is the memset in rep stos, qword aligned.
I had to use my inline proc to make it inline.
Code:
il void* SetMem(void* pMem, word To, dword Count)
{
asm volatile(
"cld\n\t"
"jecxz 1f\n\t"
"rep stosb\n\t"
"1:\n\t"
"movl %%edx, %%ecx\n\t"
"test %%edx, %%edx\n\t"
"jz 2f\n\t"
"rep stosq\n\t"
"2:\n\t"
:
:"D"(pMem),"c"(Count & 0xF),"d"(Count >> 4),"a"((((qword)To) << 0) | (((qword)To) << 8) | (((qword)To) << 16) | (((qword)To) << 24) | (((qword)To) << 32) | (((qword)To) << 40) | (((qword)To) << 48) | (((qword)To) << 56))
);
asm("": : :"%edi","%ecx","cc");
return pMem;
}
memset:
extern "C" void* memset(void * s, int c, size_t count)
{
return SetMem(s, c, count);
}
This is the assembly, I have put **** to show the memset code.
Code:
1000000: 41 57 push r15
1000002: 48 b8 41 41 41 41 41 movabs rax,0x4141414141414141 ****
1000009: 41 41 41
100000c: ba 00 03 00 00 mov edx,0x300 ****
1000011: 31 c9 xor ecx,ecx ****
1000013: 48 bf 00 f0 02 01 00 movabs rdi,0x102f000 ****
100001a: 00 00 00
100001d: 41 56 push r14
100001f: 41 55 push r13
1000021: 41 54 push r12
1000023: 55 push rbp
1000024: 53 push rbx
1000025: 48 81 ec 38 03 00 00 sub rsp,0x338
100002c: fc cld ****
100002d: 67 67 e3 02 addr64 jecxz 1000033 <_Z11StartKernelv+0x33> ****
1000031: f3 aa rep stos BYTE PTR es:[rdi],al ****
1000033: 89 d1 mov ecx,edx ****
1000035: 85 d2 test edx,edx ****
1000037: 74 03 je 100003c <_Z11StartKernelv+0x3c> ****
1000039: f3 48 ab rep stos QWORD PTR es:[rdi],rax ****
100003c: 50 push rax
100003d: 51 push rcx