有关
Understanding `_mm_prefetch`
我明白了
_mm_prefetch()
将请求的值提取到处理器的缓存中,然后执行我的代码
虽然
一些预先获取的东西。
但是,我的VS2017 profiler指出,5.7%用于访问我的数据库的线路
cache
平均为8.63%
_mm_prefetch
线路。探查器搞错了吗?如果我在等待获取数据,我需要它做什么?我可以在下一个函数调用中等待,当我需要的时候。。。
另一方面,总体计时显示了预取调用的显著好处。
其他信息。
我有多个缓存,不同的密钥宽度,最多32位密钥(我目前正在分析)。对缓存和预取的访问被提取到单独的数据库中
__declspec(noinline)
uint8_t* cache[33];
__declspec(noinline)
uint8_t get_cached(uint8_t* address) {
return *address;
}
__declspec(noinline)
void prefetch(uint8_t* pcache) {
_mm_prefetch((const char*)pcache, _MM_HINT_T0);
}
int foo(const uint64_t seq64) {
uint64_t key = seq64 & 0xFFFFFFFF;
uint8_t* pcache = cache[32];
int x = get_cached(pcache + key);
key = (key * 2) & 0xFFFFFFFF;
pcache += key;
prefetch(pcache);
}
int x = get_cached(pcache + key);
生产线和8.97%
prefetch(pcache);
,而周围代码显示每行0.40-0.45%。