Because DRAM is (relatively) so slow, avoiding the _reads_ is a big gain. If you zero a large range of memory the naive way, the first write to each cache line _reads_ a cache line of data that likely will be overwritten by zeroes.
Problem is: how does the CPU know it doesn't have to do that read? REP STOSB may, but it isn't trivial to implement, as neither start nor end of the range to be processed need to lie on a cache line boundary.
PowerPC has the dcbz and dcbzl instructions which zero a cache line without reading the to-be-zeroed data (dcbzl was invented because real-world code assumed dcbz always zeroed 32 bytes. See http://lists.apple.com/archives/darwin-drivers/2005/Apr/msg0...)
Re:A queue of page faults (2014)
by neopallium on Wednesday June 15, 2016 @05:21AM
(#11908059)
The processor will try to do write-combining to fill entire cache lines, so it doesn't need to do a memory read. GCC already has a number of intrinsics to help with streaming data directly to RAM (helps to keep from evicting more important data from the cache).
The cache can be bypassed when doing a lot of writes. See section "Bypassing the cache" of [0].
That article says that memset() already uses cache bypassing instructions for large blocks.
On newer Intel CPUs, REP STOSB is highly optimized, but you still have to do the writes.