Page 2 of 2

Re: [Solved] Inline assembly memcpy

Posted: Fri May 22, 2009 7:04 am
by viki
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);
} 

Re: [Solved] Inline assembly memcpy

Posted: Fri May 22, 2009 10:27 pm
by whowhatwhere
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?

Re: [Solved] Inline assembly memcpy

Posted: Sat May 23, 2009 6:01 am
by viki
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.