[Solved] Inline assembly memcpy

Programming, for all ages and all languages.
viki
Posts: 14
Joined: Tue May 08, 2007 11:57 am
Location: Poland

Re: [Solved] Inline assembly memcpy

Post 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);
} 
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: [Solved] Inline assembly memcpy

Post 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?
viki
Posts: 14
Joined: Tue May 08, 2007 11:57 am
Location: Poland

Re: [Solved] Inline assembly memcpy

Post 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.
Post Reply