swab函数 (#53)

* swab函数

Signed-off-by: Yuqia <15287042733@163.com>

* 修正格式

Signed-off-by: Yuqia <15287042733@163.com>
Co-authored-by: fslongjin <longjin@RinGoTek.cn>
This commit is contained in:
DaJiYuQia
2022-10-07 15:45:49 +08:00
committed by GitHub
parent 9300757779
commit e62bbf13e5
5 changed files with 95 additions and 9 deletions

View File

@ -48,4 +48,32 @@ char* strcpy(char* dst, const char* src);
*/
char *strcat(char *dest, const char *src);
#define memcpy(dst, src, n) __builtin_memcpy(dst, src, n)
/**
* @brief 内存拷贝函数
*
* @param dst 目标数组
* @param src 源数组
* @param Num 字节数
* @return void*
*/
static void *memcpy(void *dst, const void *src, long Num)
{
int d0 = 0, d1 = 0, d2 = 0;
__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"(dst), "2"(src)
: "memory");
return dst;
}