测试下预取的效果,利用CPU始终查看效果。根据实验发现,预取地址在地址使用之前的十行左右代码处效果比较好!
复制代码 代码如下:
#include <stdio.h>
#define MAX_LEN 1000000
static inline void prefetchnta(void *addr) //预取部分
{
__asm__("movl %0, %%eax"::"a"(addr));
__asm__(".byte 0x0f, 0x18, 0x00");
}
inline unsigned long long GetCPUTickCount()
{
unsigned long high32 = 0;
unsigned long low32 = 0;
__asm__("RDTSC" : "=a"(low32), "=d"(high32));
unsigned long long counter = high32;
counter = (counter<<32) + low32;
return counter;
}
int main(int argc, char* argv[])
{
long long start, end;
long long array[MAX_LEN];
int i;
for(i = 0; i < MAX_LEN; i++) //让cache失效
array[i]++;
start = GetCPUTickCount();
array[0]++;
end = GetCPUTickCount();
printf("don't use prefetch time:%ld\n", end - start);
for(i = 0; i < MAX_LEN; i++)
array[i]++;
prefetchnta(array);
start = GetCPUTickCount();
array[0]++;
end = GetCPUTickCount();
printf("use prefetch time:%ld\n", end - start);
return 0;
}
cpu时钟预取
更新日志
- 班得瑞原装进口《第九张新世纪专辑:微风山谷》1CD[APE/CUE分轨][331MB]
- 陈慧琳.2008-Love.Fighters演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 米志宏.1994-HAPPY1994【波丽佳音】【WAV+CUE】
- 潘美辰.2006-最冷的夏天(引进版)【美梦辰真】【WAV+CUE】
- 班得瑞原装进口《第十张新世纪专辑:月光水岸》1CD[APE/CUE分轨][277.2MB]
- 班得瑞原装进口《第十一张新世纪专辑:雾色山脉》1CD[APE/CUE分轨][291.6MB]
- 班得瑞原装进口《第十二张新世纪专辑:翡翠谷》1CD[APE/CUE分轨][307.9MB]
- 高卿尘.2024-情绪商店【Hahahai】【FLAC分轨】
- 王恩喆.2024-黄沙【KOOD】【FLAC分轨】
- 邓丽君.1983-漫步人生路(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 陈容森.1996-情断【上华】【WAV+CUE】
- 裘海正.1994-爱我的人和我爱的人【上华】【WAV+CUE】
- 庾澄庆.1988-错过的爱【福茂】【WAV+CUE】
- 班得瑞原装进口《第十三张新世纪专辑:旭日之丘》1CD[APE/CUE分轨][329.6MB]
- 纯音入心系列纯音乐《古筝|佛蕴|境法禅心意法自然》1CD[MP3][350MB]