The GCC version is just bananas. https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=sysde...
Compare the newer ERMS implementation: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86...
Edit: it's rolled into the erms version.
Here's some very interesting discussion about it: https://stackoverflow.com/questions/43343231/enhanced-rep-mo...
I remember it was actually quite common in early PC programs, but I don't remember well enough whether it was also generated by compilers, or just existed in hand-optimized assembly (which was of course extremely common back then).
There's also the fact that `rep` startup cost was higher in the past than it is now. I think it started to get really fast around Ivy Bridge.
This is all discussed in Intel's optimization manual, by the way.
https://software.intel.com/content/www/us/en/develop/downloa...
And if you want ALL THE THINGS:
https://software.intel.com/content/www/us/en/develop/article...