亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

cpu時鐘預取實例代碼分享

 更新時間:2013年12月19日 15:05:50   作者:  
cpu時鐘預取實例代碼分享,大家參考使用吧

測試下預取的效果,利用CPU始終查看效果。根據(jù)實驗發(fā)現(xiàn),預取地址在地址使用之前的十行左右代碼處效果比較好!

復制代碼 代碼如下:

#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;
}

相關文章

最新評論