2 ms·
In newer versions of glibc, memcpy() does take advantage of SIMD instructions if they are avaialble. It works something like this: The memcpy() function is mar
by ssp 16y ago
In newer versions of glibc, memcpy() does take advantage of SIMD instructions if they are avaialble. It works something like this:
The memcpy() function is marked specially in the ELF file. On the first invocation, the dynamic linker actually calls the function and then takes the return value and treats it as a function pointer. This function pointer is then used for linking, so that subsequent invocations will call that pointer instead.
The memcpy() function in glibc then simply checks which SIMD extensions are available and returns a pointer to the appropriate real memcpy to use.
- pmjordan 16y agoYep, except it still needs to check the alignment of the pointers passed into the function to see if it can use the aligned mov instructions. If you're that stuck for speed, you'll want to make sure all your buffers are already aligned, and then call a function that doesn't do any checking.