0

I am trying to use memcpy function using SSE instructions. I found this file on internet (ftp://ftp.acer.at/gpl/AS9100/GPL_AS9100/xine-lib/src/xine-utils/memcpy.c). Here it is the part of the code that I have problem with that:

__asm__ __volatile__ (
    "prefetchnta 320(%0)\n"
   "prefetchnta 352(%0)\n"
    "movups (%0), %%xmm0\n"
    "movups 16(%0), %%xmm1\n"
    "movups 32(%0), %%xmm2\n"
    "movups 48(%0), %%xmm3\n"
    "movntps %%xmm0, (%1)\n"
    "movntps %%xmm1, 16(%1)\n"
    "movntps %%xmm2, 32(%1)\n"
    "movntps %%xmm3, 48(%1)\n"
    :: "r" (from), "r" (to) : "memory");
    ((const unsigned char *)from)+=64;
    ((unsigned char *)to)+=64;

from and to are to void * pointers and On the last two lines, I've go this error:

error: lvalue required as left operand of assignment

If it is possible, please help me.

Thanks

  • BTW, you're copying from C source code, but are you compiling in C or C++ mode? – Ben Voigt Oct 20 '15 at 00:39
  • Non-temporal stores only make sense for copying large memory sizes. The rule of thumb as is to use them for memory sizes more than half the last level cache (usually L3). [But since Ivy Bridge you should use `REP MOVS ` instead of non-temporal stores](http://stackoverflow.com/a/26256216/2542702). In any case, writing your own general purpose optimized memcpy function is complicated. – Z boson Oct 20 '15 at 11:13

1 Answers1

3
(*(const unsigned char **)&from)

is the lvalue you are looking for.

But it might be more optimizer-friendly to write

from = ((const unsigned char *)from) + 64;

which avoids the address-of operator that requires a memory spill.

Another alternative is just to convert the arguments into local variables with the right type on entry to the function, and never touch the function arguments again.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720