hw-cache-basic (libcache.la :: cache_component_library)


This component models a variety of memory cache designs. Many common parameter groups (size, associativity, line-size, etc.) are exposed as individual component types in this family, e.g., hw-cache-2way/16kb/32/random, hw-cache-direct/1kb/16. The hw-cache-buffer-8 type is a special case containing just one 8-byte cache line.



This component models a memory cache suitable for use at different levels of the memory hierarchy. It provides a bus interface and connects to another bus, providing a transparent pass-through. In this documentation, "CPU" and "main memory" are synonymous for "upstream bus" and "downstream bus", as this is the most common usage (but not the only possible).

The parameters of the cache are a matter of configuration. At instantiation time, the following parameters are specified:

For a 16KB cache with a line size of 32 bytes, 2-way set associativity and a "least recently used" (LRU) replacement policy, the component name is hw-cache-2way/16kb/32/lru. For direct mapped caches, replacement policies are not applicable and should be omitted from the component name, such as hw-cache-direct/64kb/16. This particular 64KB direct-mapped cache configuration is also known by the type name of hw-cache-basic.

tag calculation

The size of a tag is dynamically computed based on the line size. Unlike physical caches which economise on the number of tag bits to reduce hardware costs, the model uses a full address, but discards the redundant bits that can be inferred by a bytes position in the cache line. For example, a 32 (2^5) byte line uses 27 bits for the tag.

hash algorithm

A simple hashing algorithm is used to select a set from a target address. The algorithm uses values from hash-bit-mask and hash-shift-amount to compute: These two values must be chosen carefully to ensure good cache utilisation. In particular, the "all-ones" value of mask should not exceed the number of sets in the cache.

misaligned accesses

The component does not handle memory accesses that are not aligned on the natural boundary of the data being referenced. In such cases, the cache is bypassed and memory is accessed directly.

write strategy

When a write is made to the cache, the write-through? attribute determines if the data will be simultaneously written to the memory. Otherwise, writes will only be made to the cache and will not be synchronised with main memory until the line is flushed due to line replacement or an explicit flush (see Flushing).

In the case of a write miss, the write-allocate? attribute specifies the component's action. If this attribute is set to yes, then a miss will cause the missed line to be loaded into the cache in anticipation of future references.


The component supports prefetching of data into the cache by driving prefetch with an address. If, due to the line replacement policy, the prefetch cannot be performed, this operation has no effect.


If dirty lines are flushed from the cache, the component will ensure that their contents are synchronized with main memory. Some architectures provide a facility for explicitly flushing a line to memory. For this purpose, the component provides flush which can be driven with an address. If the address falls on a line that is present and dirty, it will be flushed to memory and marked as not dirty. A line can be flushed and invalidated in one atomic operation by driving the flush-and-invalidate pin. The entire cache can be flushed by driving flush-all.


Lines in the cache that contain accurate contents are marked as valid. Some architectures provide a facility for explicitly marking a line as invalid so that future accesses will cause a new memory access. For this purpose, the component provides invalidate that can be driven with an address. If the address falls on a line that is present, it will be invalidated. No consideration is made for dirty lines, so a line should be flushed before being invalidated. A line can be flushed and invalidated in one atomic operation by driving the flush-and-invalidate pin. The entire cache can be invalidated by driving invalidate-all.

line locking

The component supports locking lines in the cache to prevent them from being removed to accommodate more recently referenced lines. A line can be locked by driving lock with any address that falls on the line. Subsequently, a line can be unlocked by driving unlock.

memory latency

The component models the effects of memory latency. The hit-latency and miss-latency values specify the cumulative latencies for hit and missed cache operations. Any misaligned accesses are penalised as if they are a miss. Cache line refills incur an additional latency, specified by the refill-latency attribute.

statistics gathering

The component gathers statistics for a number of significant events and records them in read-only attributes. The collection of statistics may be disabled using collect-statistics?.

statistics reporting

The component will write a summary report of the statistics it collects to standard error when report! is driven. The report-heading value, prepended to the report, allows reports from multiple caches to be distinguished.

SID Conventions
functional supported -
latency supported -


Related components

Component Reference:

Component: hw-cache-basic

report!in-statistics reporting
flushin32-bit addressflushing
flush-setinset indexflushing
invalidatein32-bit addressinvalidating
invalidate-setinset indexinvalidating
flush-and-invalidatein32-bit addressflushing, invalidating
flush-and-invalidate-setinset indexflushing, invalidating
prefetchin32-bit addressprefetching
lockin32-bit addressline locking
unlockin32-bit addressline locking

upstreamunrestrictedunrestrictedbus traffic

namecategorylegal valuesdefault valuebehaviors
write-through?settingbooleanfalsewrite strategy
write-allocate?settingbooleanfalsewrite strategy
read-accessesregisternumeric0statistics gathering
write-accessesregisternumeric0statistics gathering
misaligned-readsregisternumeric0statistics gathering
misaligned-writesregisternumeric0statistics gathering
flushesregisternumeric0statistics gathering
replacementsregisternumeric0statistics gathering
read-hit-rateregisterpercentage string0%statistics gathering
write-hit-rateregisterpercentage string0%statistics gathering
collect-statistics?settingbooleantruestatistics reporting
report-headingsettingstringcache profile reportstatistics reporting
hit-latencysettingnumeric0memory latency
miss-latencysettingnumeric0memory latency
refill-latencysettingnumeric0memory latency
dump!settingempty stringemptyinternal diagnostics

downstreamunrestrictedbus traffic

Variant: hw-cache-buffer-8

Same as hw-cache-basic