🆕 新增内存拷贝函数memcpy

This commit is contained in:
fslongjin 2022-01-29 15:11:33 +08:00
parent 37e0334d62
commit 8ab02c496c

View File

@ -134,6 +134,37 @@ void *memset(void *dst, unsigned char C, ul Count)
: "memory");
return dst;
}
/**
* @brief
*
* @param dst
* @param src
* @param Num
* @return void*
*/
void * memcpy(void *dst,void * src,long Num)
{
int d0,d1,d2;
__asm__ __volatile__ ( "cld \n\t"
"rep \n\t"
"movsq \n\t"
"testb $4,%b4 \n\t"
"je 1f \n\t"
"movsl \n\t"
"1:\ttestb $2,%b4 \n\t"
"je 2f \n\t"
"movsw \n\t"
"2:\ttestb $1,%b4 \n\t"
"je 3f \n\t"
"movsb \n\t"
"3: \n\t"
:"=&c"(d0),"=&D"(d1),"=&S"(d2)
:"0"(Num/8),"q"(Num),"1"(src),"2"(dst)
:"memory"
);
return dst;
}
void *memset_c(void *dst, unsigned char c, ul n)
{
unsigned char *s = (unsigned char *)dst;
@ -184,4 +215,5 @@ void io_out32(unsigned short port,unsigned int value)
:
:"a"(value),"d"(port)
:"memory");
}
}