🆕 增加了memset函数(汇编实现)

This commit is contained in:
fslongjin
2022-01-27 18:36:32 +08:00
parent 40a551d154
commit ecd78d08e9

View File

@ -112,3 +112,27 @@ static inline int strlen(char *s)
return __res;
}
inline void *memset(void *dst, unsigned char C, ul Count)
{
int d0, d1;
unsigned long tmp = C * 0x0101010101010101UL;
__asm__ __volatile__("cld \n\t"
"rep \n\t"
"stosq \n\t"
"testb $4, %b3 \n\t"
"je 1f \n\t"
"stosl \n\t"
"1:\ttestb $2, %b3 \n\t"
"je 2f\n\t"
"stosw \n\t"
"2:\ttestb $1, %b3 \n\t"
"je 3f \n\t"
"stosb \n\t"
"3: \n\t"
: "=&c"(d0), "=&D"(d1)
: "a"(tmp), "q"(Count), "0"(Count / 8), "1"(dst)
: "memory");
return dst;
}