- void *
-
memcpy (void *to, const void *from, size_t n)
-
{
- asm volatile(
-
"shr $2, %2\n\t"
-
"cld \n\t"
-
"rep movsl \n\t"
-
"mov %3, %%ecx \n\t"
-
"and $3, %%ecx \n\t"
-
"rep movsb"
- /*输出参数*/
-
:
- /*输入参数 S->ESI D->EDI c->ecx m代表内存变量*/
-
:"S"(from), "D"(to), "c"(n), "m"(n)
- /*限定*/
- :"memory", "cc");
-
return to;
-
-
/*
-
asm volatile (
-
"rep ; movsl\n\t"
-
"testb $2,%b1\n\t"
-
"je 1f\n\t"
-
"movsw\n"
-
"1:\ttestb $1,%b1\n\t"
-
"je 2f\n\t"
-
"movsb\n"
-
"2:"
-
:
- :"c" (n/4), "q" (n),"D" ((long) to),"S" ((long) from)
-
: "memory");
-
return to;
- /* %b1 代表取输入参数%1 的低字节 */
-
*/
-
}
限定修饰
"merory"是一个常用的限定,它表示汇编代码以不可预知的方式改变了内存,这样gcc在优化时就不会让cache到寄存器的内存变量使用该寄存器通过汇编代码,否则可能会发生同步出错.
“cc”:你使用的指令会改变CPU的条件寄存器;
阅读(1360) | 评论(0) | 转发(0) |