Hi,
xmm15 wrote:
Anyone has an opinion on this?
A good generic "memcpy()" is impossible. You need a "memcpy_small()" designed for tiny copies (where the start-up overhead is more significant than the actual copy so you just do a "one byte at a time" loop); a "memcpy_medium()" designed for medium sized copies that just uses (e.g.) "rep movsb"; plus a "memcpy_large()" just in case.
The best possible code for "memcpy_large()" is something like this:
Code:
void *memcpy_large(void *dest, const void *src, size_t n) {
if(n > 65536) {
fprintf(stderr, "ERROR: Some noob failed to avoid a huge memory copy!\n");
exit(EXIT_FAILURE);
}
return memcpy_medium(dest, src, n);
}
Basically; if you think SSE or AVX is going to help then you're solving the wrong problem.
Cheers,
Brendan