Monday, April 24, 2006

static inline void * __memcpy(void * to, const void * from, size_t n)
{
int d0, d1, d2;
__asm__ __volatile__(
"rep ; movsl\n\t"
"testb $2,%b4\n\t"
"je 1f\n\t"
"movsw\n"
"1:\ttestb $1,%b4\n\t"
"je 2f\n\t"
"movsb\n"
"2:"
: "=&c" (d0), "=&D" (d1), "=&S" (d2)
:"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
: "memory");
return (to);
}

%ecx = n/4
%edi = (long)to
%esi = (long)from

first move n/4 long bytes from %esi to %edi
then judge n can be divided exactly by 4 or not,
if the 2 least significant bit is 10, (test 2, n), then move 16 bits from %esi to %edi
if the 1 LSB is 1, (test 1, n ), then move 8 bits from %esi to %edi

0 Comments:

Post a Comment

<< Home