memcpy.c

来自「国产CPU-龙芯(loongson)BIOS源代码」· C语言 代码 · 共 54 行

C
54
字号
/* simple memory copy function */#if 1void memcpy(void *to, void *from, int size){    int i = 0;    for(i=0;i<size;i+=4)    {	*(unsigned char *)(to++) = *(unsigned char *)(from++);	*(unsigned char *)(to++) = *(unsigned char *)(from++);	*(unsigned char *)(to++) = *(unsigned char *)(from++);	*(unsigned char *)(to++) = *(unsigned char *)(from++);	/*	*(unsigned short *)(to)=*(unsigned short *)(from);	to+=2;	from+=2;	*(unsigned short *)(to)=*(unsigned short *)(from);	to+=2;	from+=2;	*/	/* why in simos the below code does not work properly	 * Maybe the address not aligned 	*(unsigned long *)(to) = *(unsigned long *)(from);	to+=4;	from+=4;	*/    }    switch (size%4)    {	case 1:	    *(unsigned char *)(to)=*(unsigned char *)(from);	    break;	case 2:	    *(unsigned short *)(to)=*(unsigned short *)(from);	    break;	case 3:	    *(unsigned char *)(to++)=*(unsigned char *)(from++);	    *(unsigned short *)(to)=*(unsigned short *)(from);	    break;	case 0:	default:	    break;    }}#elsevoid memcpy(void *to, void *from, int size){    int i = 0;    for (i=0;i<size;i++)	*(unsigned char *)(to++) = *(unsigned char *)(from++);}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?