Programming, for all ages and all languages.
viki
Posts: 14 Joined: Tue May 08, 2007 11:57 am
Location: Poland
Post
by viki » Fri May 22, 2009 7:04 am
Hi,
From ManRix OS I've found someting interesting:
Code: Select all
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);
}
whowhatwhere
Member
Posts: 199 Joined: Sat Jun 28, 2008 6:44 pm
Post
by whowhatwhere » Fri May 22, 2009 10:27 pm
viki wrote: Hi,
From ManRix OS I've found someting interesting:
Code: Select all
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);
}
Have you read
anything at all of this thread? These optimizations are BAD. As in the big ol', Bad Thing™, you know?
viki
Posts: 14 Joined: Tue May 08, 2007 11:57 am
Location: Poland
Post
by viki » Sat May 23, 2009 6:01 am
I know that optimalization is wrong. But. If you dont know how the result should looks like after compilation then you are not able to set correct flags for your compiler. GCC for example has not only -O2 option that improve our code speed.