Friday, April 28, 2006

Since C is not a safe language, some methods have proven invaluable to help build more reliable programs, which we’ll detail here.

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
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

Tuesday, April 18, 2006

emacs:
1. untabify, tabify: change tab to space (vice versa), M+X + untabify/tabify, this command work on a region. C+X M+X untabify can change tab in the whole atticle.
2. input special key: if you want to replace tab to space , u can M+% replace C+q TAB RET.