3 ms·
It’s a bit surprising to me that modern processors don’t have their own special handling for recognising and speeding up these copies. But maybe that’s too hard
by dan-robertson 6y ago
It’s a bit surprising to me that modern processors don’t have their own special handling for recognising and speeding up these copies. But maybe that’s too hard to do.
I’m also surprised that Linux can’t use a vector based copy function (at least for any moderately large copy) as it seems saving a few avx registers would be much cheaper than the copy.
- twoodfin 6y agoModern processors speed up large copies with SIMD instructions like AVX. The Linux kernel chooses not to use SIMD because the cost of copying & saving the relevant processor state (registers, in this case) would be borne by every syscall and consume precious CPU cache. This would be true for any similar copying mechanism that spanned multiple cycles; the state—however represented—must be preserved.
- dan-robertson 6y agoThat’s a statement about modern implementations of memcpy, whereas I was asking about what processors themselves do when they see a non-vector memcpy loop.
- loeg 6y agoThey do; 'rep movsb' uses very wide operations internally on any recent x86. https://news.ycombinator.com/item?id=24843364 https://news.ycombinator.com/item?id=24843364