mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 18:26:48 +00:00
🆕 新增内存拷贝函数memcpy
This commit is contained in:
parent
37e0334d62
commit
8ab02c496c
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user