Reputation: 11
Is there a way to know whether a data stored in cache is an address (i.e. pointer) or an actual value?
It seems one possible way is to drop a hint by software and compiler. But I don't know details how to achieve this or how feasible it is. Can anyone give me some advice or point me with some references?
Otherwise, is it possible to distinguish an address/value by their binary bit patterns? Is this a trustable approach?
Thanks a lot!!
Upvotes: 1
Views: 329
Reputation: 37214
A CPU's cache only caches data. A pointer is data (and that data happens to be interpreted as an address by code). Any assembly language programmer will probably tell you that (at least for most CPUs) the CPU is happy to treat integer or floating point data as an address too (types and type checking are mostly just an illusion created by compilers).
Now consider a cache line that contains 2 floating point values and 2 pointers' data. It would be infeasible for a CPU to only cache the parts of the cache line that contains floating point data while not caching the parts of the cache line that contain pointer data; even if the CPU knew what types of data were where within the cache line.
Upvotes: 1