x86-64: Cache load and eviction instruction

谁说我不能喝 提交于 2019-11-28 09:34:09

问题


For x86-64 architecture, is there an instruction that can load data at a given memory address to the cache? Similarly, is there an instruction that can evict a cache line given a memory address corresponding to that cache line (or something like a cache line identifier)?


回答1:


prefetch data into cache (without loading it into a register):

PREFETCHT0 [address]
PREFETCHT1 [address]
PREFETCHT2 [address]

intrinsic: void _mm_prefetch (char const* p, int hint)

See the insn ref manual and other guides for what the different nearness hints mean. (Other links at the x86 tag wiki).

The famous What Every Programmer Should Know About Memory article was written when P4 was current. Current CPUs have smarter hardware prefetchers, and hyperthreading is useful for much more than just running prefetch threads. AFAIK, prefetch threads are mostly a dead idea. Other than that, excellent article about caching. Search for other SO posts and stuff to decide when to actually prefetch.

Do not overdo it with software prefetch on Intel IvyBridge. That specific microarchitecture has a performance bug, and can only retire one prefetch per 43 clocks.


Flush the cache line containing a given address:

clflush [address]
clflushopt [address]   ; Newer CPUs only.  Weakly ordered, with higher throughput.

intrinsic: void _mm_clflushopt (void const * p)

There was a recent question about its performance.



来源:https://stackoverflow.com/questions/36563277/x86-64-cache-load-and-eviction-instruction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!