Software Prefetcher
The Sapphire RV64 SoC software prefetcher is a mechanism that allows software to provide hints to the processor on future memory accesses, enabling proactive loading of data into the cache to reduce access latency. Unlike a hardware prefetcher, which monitors memory and instruction streams automatically, the software prefetcher relies on explicit prefetch instructions inserted by the compiler or programmer. These prefetch instructions do not modify the processor's architectural state; instead, they generate speculative memory requests that bring the specified cache lines into the appropriate cache before the CPU actually needs them.
When the processor executes a prefetch instruction, it interprets the target memory address and the intended level of caching as hints rather than as required loads or stores. The software prefetcher then issues a request to the memory subsystem, similar to a normal load, but without committing any data to a register. The request causes the cache hierarchy to fetch the corresponding line from main memory or from a higher-level cache if it is already present. Once the data is in the cache, subsequent accesses to that address hit the cache, avoiding the latency of main-memory fetches.
The software prefetcher in Sapphire RV64 SoC is flexible and can be configured to target different types of memory accesses. For example, prefetch instructions can be used for both sequential data streams, such as arrays in a loop, and irregular access patterns, such as pointer-based traversals in linked structures. The prefetcher supports specifying the caching behavior, including whether the prefetched line should be placed in the instruction cache or data cache, and whether it should be marked for high or low temporal locality depending on anticipated reuse.
There is no guarantee that the prefetched data will remain in the cache until it is used because the software prefetcher operates purely on hints; cache replacement policies may evict the line if other memory accesses require space. Also, each inflight cache refill will consume a refill slot in the cache, which are in limited amount. If all the slots are used, new prefetch request will be ignored. However, by carefully inserting prefetch instructions within performance-critical loops or routines, software can significantly reduce cache-miss penalties and improve the throughput of memory-bound applications.
The functional role of the software prefetcher is therefore to bridge the gap between software knowledge of upcoming memory accesses and hardware cache management. It allows programs to communicate expected access patterns to the CPU in advance, improving memory system utilization without affecting correctness. This capability complements the hardware prefetcher, as software can provide more precise hints for complex or irregular memory access patterns that hardware heuristics may not detect.
Overall, the Sapphire RV64 SoC software prefetcher enhances performance by enabling speculative memory fetches under software control. It provides a mechanism for latency hiding in memory-bound workloads, reduces pipeline stalls caused by cache misses, and allows software to exploit knowledge of program behavior to improve cache utilization, while remaining completely transparent to the CPU's architectural state.