4 ms·
ERMS is extremely slow for small sizes. In my testing, rep stos wins over sse for sizes above ~1k, and over avx for sizes greater than l1. It also requires co
by moonchild 6y ago
ERMS is extremely slow for small sizes. In my testing, rep stos wins over sse for sizes above ~1k, and over avx for sizes greater than l1. It also requires correct alignment, and isn't fast on most AMD cpus.
For smaller sizes, rep stos can be as much as 20x slower than the alternative.
- jeffbee 6y agoYou can’t make a statement like that without mentioning which part you’re testing with.
- moonchild 6y agoNot sure what you mean by 'part'. I reproduced this across the following CPUs, which I think are fairly representative: - intel xeon e3-1246 - intel core i3-5005u - amd ryzen 3960X - amd epyc 7402p Comparing my own[0] memset implementation, glibc's, and bionic's. 0. https://github.com/moon-chilled/fancy-memset https://github.com/moon-chilled/fancy-memset
- jeffbee 6y agoIt seems that you do know what I mean by part. Only the latest Zen3 parts have ERMS and FSRM. I think that benchmarking memset by itself is folly, because you may end up with a very large function that is fast on its own, but which trashes your icache when run in a real application. That is the conclusion of the paper I linked elsewhere in this thread: that rep cmpsb, even on old CPUs where it is slow, beats glibc memcmp in real full-scale applications because glibc memcmp is 6KB long and has a tendency to evict dozens of lines of icache. memset, memcpy, and memmove have the same hazard.
- moonchild 6y agoThat is a good point, and I do intend to do full-scale application benchmarks; I just haven't gotten around to it yet. That being said, all the implementations of memset I tested except for glibc's are in the neighborhood of 100-300 bytes (also including the freebsd version, which doesn't use any simd), which is a fair sight smaller than 6k.