Search code examples
linuxssememcpy

Memcpy using SSE instructions


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


Solution

  • (*(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.