Fully optimized memcpy/memmove for Core 2 or Core i7 architecture?

后端 未结 3 966
無奈伤痛
無奈伤痛 2021-01-02 06:05

The theoretical maximum of memory bandwidth for a Core 2 processor with DDR3 dual channel memory is impressive: According to the Wikipedia article on the architecture, 10+

3条回答
  •  情话喂你
    2021-01-02 06:47

    If you specify /ARCH:SSE2 to MSVC it should provide you with a tuned memcpy (at least, mine does).

    Failing that, use the SSE aligned load/store intrinsics yourself to copy the memory in large chunks, employing a Duff's Device of word reads where necessary to deal with the head and tail of data to get it to an aligned boundary. You'll need to use the cache management intrinsics as well to get good performance.

    Your limiting factor is probably cache misses and southbridge bandwidth, rather than CPU cycles. Given that there's always going to be lots of other traffic on the memory bus, I'm usually happy to get to about 90% of theoretical memory bandwidth throughput in such operations.

提交回复
热议问题